Bug 1129769 - Handle more kinds when resolving tracked type names. (r=djvj)

This commit is contained in:
Shu-yu Guo 2015-02-22 20:05:34 -08:00
parent 285d84d141
commit b0462b3639
3 changed files with 53 additions and 9 deletions

View File

@ -293,15 +293,25 @@ struct ForEachTrackedOptimizationTypeInfoOp
// function.
// - "alloc site" for object types tied to an allocation site.
// - "prototype" for object types tied neither to a constructor nor
// to an allocation site.
// to an allocation site, but to a prototype.
// - "singleton" for object types which only has a single value.
// - "function" for object types referring to scripted functions.
// - "native" for object types referring to native functions.
//
// The name parameter is the string representation of the type. If the
// type is keyed by "constructor", or if the type itself refers to a
// scripted function, the name is the function's displayAtom.
// scripted function, the name is the function's displayAtom. If the type
// is keyed by "native", this is nullptr.
//
// If the type is keyed by "constructor", "alloc site", or if the type
// itself refers to a scripted function, the location and lineno
// parameters will be respectively non-nullptr and non-0.
// The location parameter is the filename if the type is keyed by
// "constructor", "alloc site", or if the type itself refers to a scripted
// function. If the type is keyed by "native", it is the offset of the
// native function, suitable for use with addr2line on Linux or atos on OS
// X. Otherwise it is nullptr.
//
// The lineno parameter is the line number if the type is keyed by
// "constructor", "alloc site", or if the type itself refers to a scripted
// function. Otherwise it is UINT32_MAX.
virtual void readType(const char *keyedBy, const char *name,
const char *location, unsigned lineno) = 0;

View File

@ -1147,7 +1147,7 @@ InterpretedFunctionFilenameAndLineNumber(JSFunction *fun, const char **filename,
}
static JSFunction *
InterpretedFunctionFromTrackedType(const IonTrackedTypeWithAddendum &tracked)
FunctionFromTrackedType(const IonTrackedTypeWithAddendum &tracked)
{
if (tracked.hasConstructor())
return tracked.constructor;
@ -1184,7 +1184,32 @@ class ForEachTypeInfoAdapter : public IonTrackedOptimizationsTypeInfo::ForEachOp
char buf[512];
const uint32_t bufsize = mozilla::ArrayLength(buf);
if (JSFunction *fun = InterpretedFunctionFromTrackedType(tracked)) {
if (JSFunction *fun = FunctionFromTrackedType(tracked)) {
if (fun->isNative()) {
//
// Print out the absolute address of the function pointer.
//
// Note that this address is not usable without knowing the
// starting address at which our shared library is loaded. Shared
// library information is exposed by the profiler. If this address
// needs to be symbolicated manually (e.g., when it is gotten via
// debug spewing of all optimization information), it needs to be
// converted to an offset from the beginning of the shared library
// for use with utilities like `addr2line` on Linux and `atos` on
// OS X. Converting to an offset may be done via dladdr():
//
// void *addr = JS_FUNC_TO_DATA_PTR(void *, fun->native());
// uintptr_t offset;
// Dl_info info;
// if (dladdr(addr, &info) != 0)
// offset = uintptr_t(addr) - uintptr_t(info.dli_fbase);
//
uintptr_t addr = JS_FUNC_TO_DATA_PTR(uintptr_t, fun->native());
JS_snprintf(buf, bufsize, "%llx", addr);
op_.readType("native", nullptr, buf, UINT32_MAX);
return;
}
PutEscapedString(buf, bufsize, fun->displayAtom(), 0);
const char *filename;
unsigned lineno;
@ -1204,7 +1229,12 @@ class ForEachTypeInfoAdapter : public IonTrackedOptimizationsTypeInfo::ForEachOp
return;
}
op_.readType("prototype", buf, nullptr, 0);
if (ty.isGroup()) {
op_.readType("prototype", buf, nullptr, UINT32_MAX);
return;
}
op_.readType("singleton", buf, nullptr, UINT32_MAX);
}
void operator()(JS::TrackedTypeSite site, MIRType mirType) MOZ_OVERRIDE {

View File

@ -222,9 +222,13 @@ public:
mWriter.BeginObject();
mWriter.NameValue("keyedBy", keyedBy);
mWriter.NameValue("name", name);
if (name) {
mWriter.NameValue("name", name);
}
if (location) {
mWriter.NameValue("location", location);
}
if (lineno != UINT32_MAX) {
mWriter.NameValue("line", lineno);
}
mWriter.EndObject();