| 1 |
// |jit-test| skip-if: !getBuildConfiguration("moz-memory") |
| 2 |
// Run this test only if we're using jemalloc. Other malloc implementations |
| 3 |
// exhibit surprising behaviors. For example, 32-bit Fedora builds have |
| 4 |
// non-deterministic allocation sizes. |
| 5 |
|
| 6 |
// Check that JS::ubi::Node::size returns reasonable results for objects. |
| 7 |
|
| 8 |
// We actually hard-code specific sizes into this test, even though they're |
| 9 |
// implementation details, because in practice there are only two architecture |
| 10 |
// variants to consider (32-bit and 64-bit), and if these sizes change, that's |
| 11 |
// something SpiderMonkey hackers really want to know; they're supposed to be |
| 12 |
// stable. |
| 13 |
|
| 14 |
if (getBuildConfiguration("pointer-byte-size") == 4) |
| 15 |
var s = (s32, s64) => s32 |
| 16 |
else |
| 17 |
var s = (s32, s64) => s64 |
| 18 |
|
| 19 |
// Return the byte size of |obj|, ensuring that the size is not affected by |
| 20 |
// being tenured. (We use 'survives a GC' as an approximation for 'tenuring'.) |
| 21 |
function tByteSize(obj) { |
| 22 |
var size = byteSize(obj); |
| 23 |
minorgc(); |
| 24 |
if (size != byteSize(obj)) |
| 25 |
return 0; |
| 26 |
return size; |
| 27 |
} |
| 28 |
|
| 29 |
assertEq(tByteSize({}), s(48, 56)); |
| 30 |
|
| 31 |
// Try objects with only named properties. |
| 32 |
assertEq(tByteSize({ w: 1 }), s(32, 40)); |
| 33 |
assertEq(tByteSize({ w: 1, x: 2 }), s(32, 40)); |
| 34 |
assertEq(tByteSize({ w: 1, x: 2, y: 3 }), s(48, 56)); |
| 35 |
assertEq(tByteSize({ w: 1, x: 2, y: 3, z:4 }), s(48, 56)); |
| 36 |
assertEq(tByteSize({ w: 1, x: 2, y: 3, z:4, a: 5 }), s(80, 88)); |
| 37 |
|
| 38 |
// Try objects with only indexed properties. |
| 39 |
assertEq(tByteSize({ 0:0 }), s(80, 88)); |
| 40 |
assertEq(tByteSize({ 0:0, 1:1 }), s(80, 88)); |
| 41 |
assertEq(tByteSize({ 0:0, 1:1, 2:2 }), s(80, 88)); |
| 42 |
assertEq(tByteSize({ 0:0, 1:1, 2:2, 3:3 }), s(80, 88)); |
| 43 |
assertEq(tByteSize({ 0:0, 1:1, 2:2, 3:3, 4:4 }), s(80, 88)); |
| 44 |
|
| 45 |
// Mix indexed and named properties, exploring each combination of the size |
| 46 |
// classes above. |
| 47 |
assertEq(tByteSize({ w:1, 0:0 }), s(96, 104)); |
| 48 |
assertEq(tByteSize({ w:1, 0:0, 1:1, 2:2 }), s(96, 104)); |
| 49 |
assertEq(tByteSize({ w:1, 0:0, 1:1, 2:2, 3:3, 4:4 }), s(96, 104)); |
| 50 |
assertEq(tByteSize({ w:1, x:2, y:3, 0:0 }), s(112, 120)); |
| 51 |
assertEq(tByteSize({ w:1, x:2, y:3, 0:0, 1:1, 2:2 }), s(112, 120)); |
| 52 |
assertEq(tByteSize({ w:1, x:2, y:3, 0:0, 1:1, 2:2, 3:3, 4:4 }), s(112, 120)); |
| 53 |
assertEq(tByteSize({ w:1, x:2, y:3, z:4, a:6, 0:0 }), s(144, 152)); |
| 54 |
assertEq(tByteSize({ w:1, x:2, y:3, z:4, a:6, 0:0, 1:1, 2:2 }), s(144, 152)); |
| 55 |
assertEq(tByteSize({ w:1, x:2, y:3, z:4, a:6, 0:0, 1:1, 2:2, 3:3, 4:4 }), s(144, 152)); |
| 56 |
|
| 57 |
// Check various lengths of array. |
| 58 |
assertEq(tByteSize([]), s(80, 88)); |
| 59 |
assertEq(tByteSize([1]), s(48, 56)); |
| 60 |
assertEq(tByteSize([1, 2]), s(48, 56)); |
| 61 |
assertEq(tByteSize([1, 2, 3]), s(80, 88)); |
| 62 |
assertEq(tByteSize([1, 2, 3, 4]), s(80, 88)); |
| 63 |
assertEq(tByteSize([1, 2, 3, 4, 5]), s(80, 88)); |
| 64 |
assertEq(tByteSize([1, 2, 3, 4, 5, 6]), s(80, 88)); |
| 65 |
assertEq(tByteSize([1, 2, 3, 4, 5, 6, 7]), s(112, 120)); |
| 66 |
assertEq(tByteSize([1, 2, 3, 4, 5, 6, 7, 8]), s(112, 120)); |
| 67 |
|
| 68 |
// Various forms of functions. |
| 69 |
assertEq(tByteSize(function () {}), s(48, 56)); |
| 70 |
assertEq(tByteSize(function () {}.bind()), s(80, 88)); |
| 71 |
assertEq(tByteSize(() => 1), s(48, 56)); |
| 72 |
assertEq(tByteSize(Math.sin), s(48, 56)); |