Debian Codegraph @

js/src/jit-test/tests/debug/Memory-takeCensus-09.js

raw
1 // Debugger.Memory.prototype.takeCensus: by: allocationStack breakdown
2
3 var g = newGlobal({newCompartment: true});
4 var dbg = new Debugger(g);
5
6 g.evaluate(`
7 var log = [];
8 function f() { log.push(allocationMarker()); }
9 function g() { f(); }
10 function h() { f(); }
11 `,
12 { fileName: "Rockford", lineNumber: 1000 });
13
14 // Create one allocationMarker with tracking turned off,
15 // so it will have no associated stack.
16 g.f();
17
18 dbg.memory.allocationSamplingProbability = 1;
19 dbg.memory.trackingAllocationSites = true;
20
21 for ([f, n] of [[g.f, 20], [g.g, 10], [g.h, 5]])
22 for (let i = 0; i < n; i++)
23 f(); // all allocations of allocationMarker occur with this line as the
24 // oldest stack frame.
25
26 let census = dbg.memory.takeCensus({ breakdown: { by: 'objectClass',
27 then: { by: 'allocationStack',
28 then: { by: 'count',
29 label: 'haz stack'
30 },
31 noStack: { by: 'count',
32 label: 'no haz stack'
33 }
34 }
35 }
36 });
37
38 let map = census.AllocationMarker;
39 assertEq(map instanceof Map, true);
40
41 // Gather the stacks we are expecting to appear as keys, and
42 // check that there are no unexpected keys.
43 let stacks = { };
44
45 map.forEach((v, k) => {
46 if (k === 'noStack') {
47 // No need to save this key.
48 } else if (k.functionDisplayName === 'f' &&
49 k.parent.functionDisplayName === null) {
50 stacks.f = k;
51 } else if (k.functionDisplayName === 'f' &&
52 k.parent.functionDisplayName === 'g' &&
53 k.parent.parent.functionDisplayName === null) {
54 stacks.fg = k;
55 } else if (k.functionDisplayName === 'f' &&
56 k.parent.functionDisplayName === 'h' &&
57 k.parent.parent.functionDisplayName === null) {
58 stacks.fh = k;
59 } else {
60 assertEq(true, false);
61 }
62 });
63
64 assertEq(map.get('noStack').label, 'no haz stack');
65 assertEq(map.get('noStack').count, 1);
66
67 assertEq(map.get(stacks.f).label, 'haz stack');
68 assertEq(map.get(stacks.f).count, 20);
69
70 assertEq(map.get(stacks.fg).label, 'haz stack');
71 assertEq(map.get(stacks.fg).count, 10);
72
73 assertEq(map.get(stacks.fh).label, 'haz stack');
74 assertEq(map.get(stacks.fh).count, 5);