Debian Codegraph @

js/src/jit-test/tests/gc/weak-marking-varying.js

raw
1 // |jit-test| allow-unhandlable-oom
2
3 // Crash test. Try lots of different combinations of mark colors and
4 // sequencing, and rely on the in-code asserts to detect problems.
5
6 // This test requires precise control over GC timing. The SM(cgc) job will fail
7 // without this, because startgc() asserts if an incremental GC is already in
8 // progress.
9 gczeal(0);
10
11 function global(where) {
12 if (where == 'same-realm')
13 return globalThis;
14 if (where == 'same-compartment')
15 return newGlobal();
16 if (where == 'same-zone')
17 newGlobal({sameZoneAs: {}});
18 return newGlobal({newCompartment: true});
19 }
20
21 function varying(mapColor, keyColor, delegateColor, order, where) {
22 const vals = {};
23 const g = global(where);
24
25 vals.m = new WeakMap();
26 vals.key = g.eval("Object.create(null)");
27 vals.val = Object.create(null);
28 vals.m.set(vals.key, vals.val);
29
30 addMarkObservers([vals.m, vals.key]);
31 g.delegate = vals.key;
32 g.eval('addMarkObservers([delegate])');
33 g.delegate = null;
34 addMarkObservers([vals.val]);
35
36 for (const action of order) {
37 if (action == 'key' && ['black', 'gray'].includes(keyColor)) {
38 enqueueMark(`set-color-${keyColor}`);
39 enqueueMark(vals.key);
40 enqueueMark("unset-color");
41 enqueueMark("yield");
42 } else if (action == 'map' && ['black', 'gray'].includes(mapColor)) {
43 enqueueMark(`set-color-${mapColor}`);
44 enqueueMark(vals.m);
45 enqueueMark("drain");
46 enqueueMark("unset-color");
47 enqueueMark("yield");
48 } else if (action == 'delegate' && ['black', 'gray'].includes(delegateColor)) {
49 g.delegate = vals.key;
50 g.eval(`enqueueMark("set-color-${delegateColor}")`);
51 g.eval('enqueueMark(delegate)');
52 g.eval('enqueueMark("unset-color")');
53 g.eval('enqueueMark("yield")');
54 g.delegate = null;
55 }
56 }
57
58 vals.m = vals.key = vals.val = null;
59
60 if (delegateColor == 'uncollected')
61 schedulezone({});
62 startgc(100000);
63 print(' ' + getMarks().join("/"));
64 gcslice(100000);
65 print(' ' + getMarks().join("/"));
66 finishgc();
67 print(' ' + getMarks().join("/"));
68
69 clearMarkQueue();
70 clearMarkObservers();
71 }
72
73 if (this.enqueueMark) {
74 for (const mapColor of ['gray', 'black']) {
75 for (const keyColor of ['gray', 'black', 'unmarked']) {
76 for (const delegateColor of ['gray', 'black', 'unmarked', 'uncollected']) {
77 for (const order of [['map', 'key'],
78 ['key', 'map'],
79 ['map', 'delegate'],
80 ['delegate', 'map']])
81 {
82 for (const where of ['same-realm', 'same-compartment', 'same-zone', 'other-zone']) {
83 print(`\nRunning variant map/key/delegate=${mapColor}/${keyColor}/${delegateColor}, key is ${where}, order: ${order.join(" ")}`);
84 varying(mapColor, keyColor, delegateColor, order, where);
85 }
86 }
87 }
88 }
89 }
90 }