summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Memory-takeCensus-06.js
blob: 9a49140638dee616dd8d26b52d7e007f95c429e8 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Check Debugger.Memory.prototype.takeCensus handling of 'breakdown' argument.

load(libdir + 'match.js');
var Pattern = Match.Pattern;

var g = newGlobal({newCompartment: true});
var dbg = new Debugger(g);

Pattern({ count: Pattern.NATURAL,
          bytes: Pattern.NATURAL })
  .assert(dbg.memory.takeCensus({ breakdown: { by: 'count' } }));

let census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: false, bytes: false } });
assertEq('count' in census, false);
assertEq('bytes' in census, false);

census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: true,  bytes: false } });
assertEq('count' in census, true);
assertEq('bytes' in census, false);

census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: false, bytes: true } });
assertEq('count' in census, false);
assertEq('bytes' in census, true);

census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: true,  bytes: true } });
assertEq('count' in census, true);
assertEq('bytes' in census, true);


// Pattern doesn't mind objects with extra properties, so we'll restrict this
// list to the object classes we're pretty sure are going to stick around for
// the forseeable future.
Pattern({
          Function:          { count: Pattern.NATURAL },
          Object:            { count: Pattern.NATURAL },
          DebuggerPrototype: { count: Pattern.NATURAL },
          global:            { count: Pattern.NATURAL },
        })
  .assert(dbg.memory.takeCensus({ breakdown: { by: 'objectClass' } }));

Pattern({
          objects:        { count: Pattern.NATURAL },
          scripts:        { count: Pattern.NATURAL },
          strings:        { count: Pattern.NATURAL },
          other:          { count: Pattern.NATURAL }
        })
  .assert(dbg.memory.takeCensus({ breakdown: { by: 'coarseType' } }));

// As for { by: 'objectClass' }, restrict our pattern to the types
// we predict will stick around for a long time.
Pattern({
          JSString:             { count: Pattern.NATURAL },
          'js::Shape':          { count: Pattern.NATURAL },
          JSObject:             { count: Pattern.NATURAL },
        })
  .assert(dbg.memory.takeCensus({ breakdown: { by: 'internalType' } }));


// Nested breakdowns.

let coarse_type_pattern = {
  objects:        { count: Pattern.NATURAL },
  scripts:        { count: Pattern.NATURAL },
  strings:        { count: Pattern.NATURAL },
  other:          { count: Pattern.NATURAL }
};

Pattern({
          JSString:    coarse_type_pattern,
          'js::Shape': coarse_type_pattern,
          JSObject:    coarse_type_pattern,
        })
  .assert(dbg.memory.takeCensus({
    breakdown: { by: 'internalType',
                 then: { by: 'coarseType' }
    }
  }));

Pattern({
          Function:          { count: Pattern.NATURAL },
          Object:            { count: Pattern.NATURAL },
          DebuggerPrototype: { count: Pattern.NATURAL },
          global:            { count: Pattern.NATURAL },
          other:             coarse_type_pattern
        })
  .assert(dbg.memory.takeCensus({
    breakdown: {
      by: 'objectClass',
      then:  { by: 'count' },
      other: { by: 'coarseType' }
    }
  }));

Pattern({
          objects: { count: Pattern.NATURAL, label: "object" },
          scripts: { count: Pattern.NATURAL, label: "scripts" },
          strings: { count: Pattern.NATURAL, label: "strings" },
          other:   { count: Pattern.NATURAL, label: "other" }
        })
  .assert(dbg.memory.takeCensus({
    breakdown: {
      by: 'coarseType',
      objects: { by: 'count', label: 'object' },
      scripts: { by: 'count', label: 'scripts' },
      strings: { by: 'count', label: 'strings' },
      other:   { by: 'count', label: 'other' }
    }
  }));

try {
  const breakdown = { by: "objectClass" };
  breakdown.then = breakdown;
  dbg.memory.takeCensus({ breakdown });
  assertEq(true, false, "should not reach here");
} catch (e) {
  assertEq(e.message, "takeCensus breakdown 'by' value nested within itself: \"objectClass\"");
}

try {
  const breakdown = { by: "objectClass", then: { by: "objectClass" } };
  dbg.memory.takeCensus({ breakdown });
  assertEq(true, false, "should not reach here");
} catch (e) {
  assertEq(e.message, "takeCensus breakdown 'by' value nested within itself: \"objectClass\"");
}

try {
  const breakdown = { by: "coarseType", scripts: { by: "filename" } };
  breakdown.scripts.noFilename = breakdown;
  dbg.memory.takeCensus({ breakdown });
  assertEq(true, false, "should not reach here");
} catch (e) {
  assertEq(e.message, "takeCensus breakdown 'by' value nested within itself: \"coarseType\"");
}