summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Memory-trackingAllocationSites-03.js
blob: 4770537cc2751e4eaf1a8a5bd46bd13d4b239fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Test that multiple Debuggers behave reasonably.

load(libdir + "asserts.js");

let dbg1, dbg2, root1, root2;

function isTrackingAllocations(global, dbgObj) {
  const site = dbgObj.makeDebuggeeValue(global.eval("({})")).allocationSite;
  if (site) {
    assertEq(typeof site, "object");
  }
  return !!site;
}

function test(name, fn) {
  print();
  print(name);

  // Reset state.
  root1 = newGlobal();
  root2 = newGlobal();
  dbg1 = new Debugger;
  dbg2 = new Debugger;

  // Run the test.
  fn();

  print("  OK");
}

test("Can track allocations even if a different debugger is already tracking " +
     "them.",
     () => {
       let d1r1 = dbg1.addDebuggee(root1);
       let d2r1 = dbg2.addDebuggee(root1);
       dbg1.memory.trackingAllocationSites = true;
       dbg2.memory.trackingAllocationSites = true;
       assertEq(isTrackingAllocations(root1, d1r1), true);
       assertEq(isTrackingAllocations(root1, d2r1), true);
     });

test("Removing root1 as a debuggee from all debuggers should disable the " +
     "allocation hook.",
     () => {
       dbg1.memory.trackingAllocationSites = true;
       let d1r1 = dbg1.addDebuggee(root1);
       dbg1.removeAllDebuggees();
       assertEq(isTrackingAllocations(root1, d1r1), false);
     });

test("Adding a new debuggee to a debugger that is tracking allocations should " +
     "enable the hook for the new debuggee.",
     () => {
       dbg1.memory.trackingAllocationSites = true;
       let d1r1 = dbg1.addDebuggee(root1);
       assertEq(isTrackingAllocations(root1, d1r1), true);
     });

test("Setting trackingAllocationSites to true should throw if the debugger " +
     "cannot install the allocation hooks for *every* debuggee.",
     () => {
       let d1r1 = dbg1.addDebuggee(root1);
       let d1r2 = dbg1.addDebuggee(root2);

       // Can't install allocation hooks for root2 with this set.
       root2.enableShellAllocationMetadataBuilder();

       assertThrowsInstanceOf(() => dbg1.memory.trackingAllocationSites = true,
                              Error);

       // And after it throws, its trackingAllocationSites accessor should reflect that
       // allocation site tracking is still disabled in that Debugger.
       assertEq(dbg1.memory.trackingAllocationSites, false);
       assertEq(isTrackingAllocations(root1, d1r1), false);
       assertEq(isTrackingAllocations(root2, d1r2), false);
     });

test("A Debugger isn't tracking allocation sites when disabled.",
     () => {
       dbg1.memory.trackingAllocationSites = true;
       let d1r1 = dbg1.addDebuggee(root1);

       assertEq(isTrackingAllocations(root1, d1r1), true);
       dbg1.enabled = false;
       assertEq(isTrackingAllocations(root1, d1r1), false);
     });

test("Re-enabling throws an error if we can't reinstall allocations tracking " +
     "for all debuggees.",
     () => {
       dbg1.enabled = false
       dbg1.memory.trackingAllocationSites = true;
       let d1r1 = dbg1.addDebuggee(root1);
       let d1r2 = dbg1.addDebuggee(root2);

       // Can't install allocation hooks for root2 with this set.
       root2.enableShellAllocationMetadataBuilder();

       assertThrowsInstanceOf(() => dbg1.enabled = true,
                              Error);

       assertEq(dbg1.enabled, false);
       assertEq(isTrackingAllocations(root1, d1r1), false);
       assertEq(isTrackingAllocations(root2, d1r2), false);
     });