Commit 15623183 authored by franzih's avatar franzih Committed by Commit bot

[test] Check object literal backing store size.

Property backing store size for object literals is
the number of constant and named properties (possibly
over-allocating for the same names).

We do not reserve space in the backing store for __proto__.

We do not reserve space in the backing store for index keys.
Currently, we account for index keys in the runtime when iterating
over the boilerplate properties. Since the boilerplate properties
only include the properties up to the first computed property
name, the property backing store size includes space for index keys
if seen after the first computed property.

R=verwaest@chromium.org

BUG=v8:5625

Review-Url: https://codereview.chromium.org/2650593002
Cr-Commit-Position: refs/heads/master@{#42584}
parent d840ed11
......@@ -724,6 +724,112 @@ TEST(InobjectPropetiesCountOverflowInSubclass) {
TestClassHierarchy(hierarchy_desc, kNoOverflowCount);
}
static void CheckExpectedProperties(int expected, std::ostringstream& os) {
Handle<HeapObject> obj = Handle<HeapObject>::cast(
v8::Utils::OpenHandle(*CompileRun(os.str().c_str())));
CHECK_EQ(expected, obj->map()->GetInObjectProperties());
}
TEST(ObjectLiteralPropertyBackingStoreSize) {
v8::HandleScope scope(CcTest::isolate());
LocalContext env;
std::ostringstream os;
// An index key does not require space in the property backing store.
os << "(function() {\n"
" function f() {\n"
" var o = {\n"
" '-1': 42,\n" // Allocate for non-index key.
" 1: 42,\n" // Do not allocate for index key.
" '2': 42\n" // Do not allocate for index key.
" };\n"
" return o;\n"
" }\n"
"\n"
" return f();\n"
"} )();";
CheckExpectedProperties(1, os);
// Avoid over-/under-allocation for computed property names.
os << "(function() {\n"
" function f(x) {\n"
" var o = {\n"
" 1: 42,\n" // Do not allocate for index key.
" '2': 42,\n" // Do not allocate for index key.
" [x]: 42,\n" // Allocate for property with computed name.
" 3: 42\n" // Allocate for index key because we have seen a
// computed property.
" };\n"
" return o;\n"
" }\n"
"\n"
" var x = 'hello'\n"
"\n"
" return f(x);\n"
"} )();";
CheckExpectedProperties(2, os);
os << "(function() {\n"
" function f() {\n"
" var o = {};\n"
" return o;\n"
" }\n"
"\n"
" return f();\n"
"} )();";
// Empty objects have slack for 4 properties.
CheckExpectedProperties(4, os);
os << "(function() {\n"
" function f(x) {\n"
" var o = {\n"
" a: 42,\n" // Allocate for constant property.
" [x]: 42,\n" // Allocate for property with computed name.
" b: 42\n" // Allocate for constant property.
" };\n"
" return o;\n"
" }\n"
"\n"
" var x = 'hello'\n"
"\n"
" return f(x);\n"
"} )();";
CheckExpectedProperties(3, os);
os << "(function() {\n"
" function f(x) {\n"
" var o = {\n"
" a: 42,\n" // Allocate for constant property.
" __proto__: 42,\n" // Do not allocate for __proto__.
" [x]: 42\n" // Allocate for property with computed name.
" };\n"
" return o;\n"
" }\n"
"\n"
" var x = 'hello'\n"
"\n"
" return f(x);\n"
"} )();";
// __proto__ is not allocated in the backing store.
CheckExpectedProperties(2, os);
os << "(function() {\n"
" function f(x) {\n"
" var o = {\n"
" a: 42,\n" // Allocate for constant property.
" [x]: 42,\n" // Allocate for property with computed name.
" __proto__: 42\n" // Do not allocate for __proto__.
" };\n"
" return o;\n"
" }\n"
"\n"
" var x = 'hello'\n"
"\n"
" return f(x);\n"
"} )();";
CheckExpectedProperties(2, os);
}
TEST(SlowModeSubclass) {
// Avoid eventual completion of in-object slack tracking.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment