test_HeapSnapshot_takeCensus_02.js (1862B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // HeapSnapshot.prototype.takeCensus behaves plausibly as we allocate objects. 6 // 7 // Exact object counts vary in ways we can't predict. For example, 8 // BaselineScripts can hold onto "template objects", which exist only to hold 9 // the shape and type for newly created objects. When BaselineScripts are 10 // discarded, these template objects go with them. 11 // 12 // So instead of expecting precise counts, we expect counts that are at least as 13 // many as we would expect given the object graph we've built. 14 // 15 // Ported from js/src/jit-tests/debug/Memory-takeCensus-02.js 16 17 function run_test() { 18 // A Debugger with no debuggees had better not find anything. 19 const dbg = new Debugger(); 20 const census0 = saveHeapSnapshotAndTakeCensus(dbg); 21 Census.walkCensus(census0, "census0", Census.assertAllZeros); 22 23 function newGlobalWithDefs() { 24 const g = newGlobal(); 25 g.eval(` 26 function times(n, fn) { 27 var a=[]; 28 for (var i = 0; i<n; i++) 29 a.push(fn()); 30 return a; 31 } 32 `); 33 return g; 34 } 35 36 // Allocate a large number of various types of objects, and check that census 37 // finds them. 38 const g = newGlobalWithDefs(); 39 dbg.addDebuggee(g); 40 41 g.eval("var objs = times(100, () => ({}));"); 42 g.eval("var rxs = times(200, () => /foo/);"); 43 g.eval("var ars = times(400, () => []);"); 44 g.eval("var fns = times(800, () => () => {});"); 45 46 const census1 = dbg.memory.takeCensus(dbg); 47 Census.walkCensus( 48 census1, 49 "census1", 50 Census.assertAllNotLessThan({ 51 objects: { 52 Object: { count: 100 }, 53 RegExp: { count: 200 }, 54 Array: { count: 400 }, 55 Function: { count: 800 }, 56 }, 57 }) 58 ); 59 60 do_test_finished(); 61 }