forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocate-and-check-limits.js
34 lines (30 loc) · 1.1 KB
/
allocate-and-check-limits.js
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
'use strict';
const assert = require('assert');
const v8 = require('v8');
function allocateUntilCrash(resourceLimits) {
const array = [];
while (true) {
const usedMB = v8.getHeapStatistics().used_heap_size / 1024 / 1024;
const maxReservedSize = resourceLimits.maxOldGenerationSizeMb +
resourceLimits.maxYoungGenerationSizeMb;
assert(usedMB < maxReservedSize);
let seenSpaces = 0;
for (const { space_name, space_size } of v8.getHeapSpaceStatistics()) {
if (space_name === 'new_space') {
seenSpaces++;
assert(
space_size / 1024 / 1024 < resourceLimits.maxYoungGenerationSizeMb * 2);
} else if (space_name === 'old_space') {
seenSpaces++;
assert(space_size / 1024 / 1024 < resourceLimits.maxOldGenerationSizeMb);
} else if (space_name === 'code_space') {
seenSpaces++;
assert(space_size / 1024 / 1024 < resourceLimits.codeRangeSizeMb);
}
}
assert.strictEqual(seenSpaces, 3);
for (let i = 0; i < 100; i++)
array.push([array]);
}
}
module.exports = { allocateUntilCrash };