summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/gc/dedupe-02.js
blob: 72b2f97f9cfd591d9aa389eec21302bb40f8e1df (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
// AutoStableStringChars needs to prevent the owner of its chars from being
// deduplicated, even if they are held by a different string.

gczeal(0);

function makeExtensibleStrFrom(str) {
  var left = str.substr(0, str.length/2);
  var right = str.substr(str.length/2, str.length);
  var ropeStr = left + right;
  return ensureLinearString(ropeStr);
}

// Make a string to deduplicate to.
var original = makeExtensibleStrFrom('{ "phbbbbbbbbbbbbbbttt!!!!??": [1] }\n\n');

// Construct D2 -> D1 -> base
var D2 = makeExtensibleStrFrom('{ "phbbbbbbbbbbbbbbttt!!!!??": [1] }');
var D1 = newRope(D2, '\n', {nursery: true});
ensureLinearString(D1);
var base = newRope(D1, '\n', {nursery: true});
ensureLinearString(base);

// Make an AutoStableStringChars(D2) and do a minor GC within it. (This will do
// a major GC, but it'll start out with a minor GC.) `base` would get
// deduplicated to `original`, if it weren't for AutoStableStringChars marking
// all of D2, D1, and base non-deduplicatable.

// The first time JSON.parse runs, it will create several (14 in my test) GC
// things before getting to the point where it does an allocation while holding
// the chars pointer. Get them out of the way now.
JSON.parse(D2);

// Cause a minor GC to happen during JSON.parse after AutoStableStringChars
// gives up its pointer.
schedulegc(1);
JSON.parse(D2);

// Access `D2` to verify that it is not using the deduplicated chars.
print(D2);