зеркало из https://github.com/mozilla/gecko-dev.git
Bug 961288 - Add an object metadata callback for tracking object allocation sites. r=ejpbruel
This commit is contained in:
Родитель
2e714cf592
Коммит
04f819c1a5
|
@ -870,6 +870,20 @@ SaveStack(JSContext *cx, unsigned argc, jsval *vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
EnableTrackAllocations(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
SetObjectMetadataCallback(cx, SavedStacksMetadataCallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
DisableTrackAllocations(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
SetObjectMetadataCallback(cx, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
||||
static bool
|
||||
OOMAfterAllocations(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
@ -1631,6 +1645,16 @@ static const JSFunctionSpecWithHelp TestingFunctions[] = {
|
|||
"saveStack()",
|
||||
" Capture a stack.\n"),
|
||||
|
||||
JS_FN_HELP("enableTrackAllocations", EnableTrackAllocations, 0, 0,
|
||||
"enableTrackAllocations()",
|
||||
" Start capturing the JS stack at every allocation. Note that this sets an "
|
||||
" object metadata callback that will override any other object metadata "
|
||||
" callback that may be set."),
|
||||
|
||||
JS_FN_HELP("disableTrackAllocations", DisableTrackAllocations, 0, 0,
|
||||
"disableTrackAllocations()",
|
||||
" Stop capturing the JS stack at every allocation."),
|
||||
|
||||
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
||||
JS_FN_HELP("oomAfterAllocations", OOMAfterAllocations, 1, 0,
|
||||
"oomAfterAllocations(count)",
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Test that we can track allocation sites.
|
||||
|
||||
enableTrackAllocations();
|
||||
|
||||
const tests = [
|
||||
{ name: "object literal", object: {}, line: Error().lineNumber },
|
||||
{ name: "array literal", object: [], line: Error().lineNumber },
|
||||
{ name: "regexp literal", object: /(two|2)\s*problems/, line: Error().lineNumber },
|
||||
{ name: "new constructor", object: new function Ctor(){}, line: Error().lineNumber },
|
||||
{ name: "new Object", object: new Object(), line: Error().lineNumber },
|
||||
{ name: "new Array", object: new Array(), line: Error().lineNumber },
|
||||
{ name: "new Date", object: new Date(), line: Error().lineNumber }
|
||||
];
|
||||
|
||||
disableTrackAllocations();
|
||||
|
||||
for (let { name, object, line } of tests) {
|
||||
print("Entering test: " + name);
|
||||
|
||||
let allocationSite = getObjectMetadata(object);
|
||||
print(allocationSite);
|
||||
|
||||
assertEq(allocationSite.line, line);
|
||||
}
|
|
@ -509,4 +509,14 @@ SavedStacks::createFrameFromLookup(JSContext *cx, SavedFrame::Lookup &lookup)
|
|||
return &f;
|
||||
}
|
||||
|
||||
bool
|
||||
SavedStacksMetadataCallback(JSContext *cx, JSObject **pmetadata)
|
||||
{
|
||||
Rooted<SavedFrame *> frame(cx);
|
||||
if (!cx->compartment()->savedStacks().saveCurrentStack(cx, &frame))
|
||||
return false;
|
||||
*pmetadata = frame;
|
||||
return true;
|
||||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
|
|
@ -139,6 +139,8 @@ class SavedStacks {
|
|||
SavedFrame *createFrameFromLookup(JSContext *cx, SavedFrame::Lookup &lookup);
|
||||
};
|
||||
|
||||
bool SavedStacksMetadataCallback(JSContext *cx, JSObject **pmetadata);
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
#endif /* vm_SavedStacks_h */
|
||||
|
|
Загрузка…
Ссылка в новой задаче