From 3f2037f66bcc3e6f37b8175a747fe43fd85bf3d9 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sun, 28 Jun 2015 13:11:06 -0700 Subject: [PATCH] Bug 1061909: Define a testing function to introduce easily traceable objects. r=fitzgen --- js/src/builtin/TestingFunctions.cpp | 21 +++++++++++++++++++ .../tests/debug/Memory-takeCensus-04.js | 18 ++++++++-------- .../tests/debug/Memory-takeCensus-05.js | 12 +++++------ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 92fd49a34a7..65eca2f204d 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -2494,6 +2494,20 @@ GetConstructorName(JSContext* cx, unsigned argc, Value* vp) return true; } +static bool +AllocationMarker(JSContext* cx, unsigned argc, jsval* vp) +{ + CallArgs args = CallArgsFromVp(argc, vp); + + static const JSClass cls = { "AllocationMarker" }; + + RootedObject obj(cx, JS_NewObject(cx, &cls)); + if (!obj) + return false; + args.rval().setObject(*obj); + return true; +} + static const JSFunctionSpecWithHelp TestingFunctions[] = { JS_FN_HELP("gc", ::GC, 0, 0, "gc([obj] | 'compartment' [, 'shrinking'])", @@ -2911,6 +2925,13 @@ gc::ZealModeHelpText), " If the given object was created with `new Ctor`, return the constructor's display name. " " Otherwise, return null."), + JS_FN_HELP("allocationMarker", AllocationMarker, 0, 0, +"allocationMarker()", +" Return a freshly allocated object whose [[Class]] name is\n" +" \"AllocationMarker\". Such objects are allocated only by calls\n" +" to this function, never implicitly by the system, making them\n" +" suitable for use in allocation tooling tests.\n"), + JS_FS_HELP_END }; diff --git a/js/src/jit-test/tests/debug/Memory-takeCensus-04.js b/js/src/jit-test/tests/debug/Memory-takeCensus-04.js index ac6593f56ac..daef676dd72 100644 --- a/js/src/jit-test/tests/debug/Memory-takeCensus-04.js +++ b/js/src/jit-test/tests/debug/Memory-takeCensus-04.js @@ -5,22 +5,22 @@ var g = newGlobal(); var dbg = new Debugger(g); g.eval(` - function withTypedArrayOnStack(f) { + function withAllocationMarkerOnStack(f) { (function () { - var onStack = new Int8Array(); + var onStack = allocationMarker(); f(); }()) } `); -assertEq("Int8Array" in dbg.memory.takeCensus().objects, false, - "There shouldn't exist any typed arrays in the census."); +assertEq("AllocationMarker" in dbg.memory.takeCensus().objects, false, + "There shouldn't exist any allocation markers in the census."); -var typedArrayCount; -g.withTypedArrayOnStack(() => { - typedArrayCount = dbg.memory.takeCensus().objects.Int8Array.count; +var allocationMarkerCount; +g.withAllocationMarkerOnStack(() => { + allocationMarkerCount = dbg.memory.takeCensus().objects.AllocationMarker.count; }); -assertEq(typedArrayCount, 1, - "Should have one typed array in the census, because there " + +assertEq(allocationMarkerCount, 1, + "Should have one allocation marker in the census, because there " + "was one on the stack."); diff --git a/js/src/jit-test/tests/debug/Memory-takeCensus-05.js b/js/src/jit-test/tests/debug/Memory-takeCensus-05.js index c03cae182e2..e83425ad06f 100644 --- a/js/src/jit-test/tests/debug/Memory-takeCensus-05.js +++ b/js/src/jit-test/tests/debug/Memory-takeCensus-05.js @@ -4,11 +4,11 @@ var g = newGlobal(); var dbg = new Debugger(g); -assertEq("Int8Array" in dbg.memory.takeCensus().objects, false, - "There shouldn't exist any typed arrays in the census."); +assertEq("AllocationMarker" in dbg.memory.takeCensus().objects, false, + "There shouldn't exist any allocation markers in the census."); -this.ccw = g.eval("new Int8Array()"); +this.ccw = g.allocationMarker(); -assertEq(dbg.memory.takeCensus().objects.Int8Array.count, 1, - "Should have one typed array in the census, because there " + - "is one cross-compartment wrapper."); +assertEq(dbg.memory.takeCensus().objects.AllocationMarker.count, 1, + "Should have one allocation marker in the census, because there " + + "is one cross-compartment wrapper referring to it.");