bug-1505622.js (1278B)
1 // Test that we don't repeatedly trigger last-ditch GCs. 2 3 // Turn of any zeal which will disrupt GC number checks. 4 gczeal(0); 5 6 function allocUntilFail() { 7 gc(null, 'shrinking'); 8 9 const initialSize = gcparam("gcBytes"); 10 const initialMaxSize = gcparam("maxBytes"); 11 const initGCNumber = gcparam("majorGCNumber"); 12 13 // Set a small heap limit. 14 gcparam("maxBytes", initialSize + 16 * 1024); 15 16 let error; 17 try { 18 let a = []; 19 while (true) { 20 a.push(Symbol()); // Symbols are tenured. 21 } 22 } catch(err) { 23 error = err; 24 } 25 26 const finalGCNumber = gcparam("majorGCNumber"); 27 28 // Resetore heap limit. 29 gcparam("maxBytes", initialMaxSize); 30 31 gc(); 32 assertEq(error, "out of memory"); 33 return finalGCNumber - initGCNumber; 34 } 35 36 // Set the time limit for skipping last ditch GCs to 5 seconds. 37 gcparam("minLastDitchGCPeriod", 5); 38 assertEq(gcparam("minLastDitchGCPeriod"), 5); 39 40 // Allocate up to the heap limit. This triggers a last ditch GC. 41 let gcCount = allocUntilFail(); 42 assertEq(gcCount, 1) 43 44 // Allocate up to the limit again. The second time we fail without 45 // triggering a GC. 46 gcCount = allocUntilFail(); 47 assertEq(gcCount, 0) 48 49 // Wait for time limit to expire. 50 sleep(6); 51 52 // Check we trigger a GC again. 53 gcCount = allocUntilFail(); 54 assertEq(gcCount, 1)