ropes.js (1713B)
1 print("Stress test of ropes"); 2 3 if (typeof newRope === "undefined") { 4 var newRope = SpecialPowers.Cu.getJSTestingFunctions().newRope; 5 } 6 if (typeof ensureLinearString === "undefined") { 7 var ensureLinearString = SpecialPowers.Cu.getJSTestingFunctions().ensureLinearString; 8 } 9 10 function createRopes() { 11 const ropes = {}; 12 13 let j = 88; 14 function advance() { 15 // This is totally made up and probably stupid. 16 j = ((((j * 7) >> 2) + j) + (j << 3)) | 0; 17 return j; 18 } 19 20 function randomBalancedRope(height) { 21 if (height == 0) 22 return "abcdefghij" + j; 23 24 const left = randomBalancedRope(height - 1); 25 advance(); 26 const right = randomBalancedRope(height - 1); 27 advance(); 28 return newRope(left, right, {nursery:(j & 1)}); 29 } 30 31 // Construct a fairly big random rope first. If we did it later, then the 32 // chances of it all ending up tenured are higher. 33 ropes.balanced = randomBalancedRope(10); 34 35 ropes.simple = newRope("abcdefghijklm", "nopqrstuvwxyz"); 36 ropes.simple_tenured = newRope("abcdefghijklm", "nopqrstuvwxyz", {nursery:false}); 37 ropes.tenured_nursery = newRope("a", newRope("bcdefghijklm", "nopqrstuvwxyz", {nursery:true}), {nursery:false}); 38 ropes.nursery_tenured = newRope("a", newRope("bcdefghijklm", "nopqrstuvwxyz", {nursery:false}), {nursery:true}); 39 40 return ropes; 41 } 42 43 const ropes = createRopes(); 44 45 // Flatten them all. 46 for (const [name, rope] of Object.entries(ropes)) 47 ensureLinearString(rope); 48 49 // GC with them all live. 50 let ropes2 = createRopes(); 51 gc(); 52 53 // GC with them all dead. 54 ropes2 = null; 55 gc(); 56 57 if (typeof reportCompare === "function") 58 reportCompare(true, true);