| Index: test/cctest/test-heap.cc
|
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
|
| index 1f3fa318b28f29e16264b917b54ca08b2e4cf49f..61e29bbf2a34ef684371f7dbbd9c86acaa1c5396 100644
|
| --- a/test/cctest/test-heap.cc
|
| +++ b/test/cctest/test-heap.cc
|
| @@ -2666,6 +2666,143 @@ TEST(Regress1465) {
|
| }
|
|
|
|
|
| +static void AddTransitions(int transitions_count) {
|
| + AlwaysAllocateScope always_allocate(CcTest::i_isolate());
|
| + for (int i = 0; i < transitions_count; i++) {
|
| + EmbeddedVector<char, 64> buffer;
|
| + OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i);
|
| + CompileRun(buffer.start());
|
| + }
|
| +}
|
| +
|
| +
|
| +static Handle<JSObject> GetByName(const char* name) {
|
| + return v8::Utils::OpenHandle(
|
| + *v8::Handle<v8::Object>::Cast(
|
| + CcTest::global()->Get(v8_str(name))));
|
| +}
|
| +
|
| +
|
| +static void AddPropertyTo(
|
| + int gc_count, Handle<JSObject> object, const char* property_name) {
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Factory* factory = isolate->factory();
|
| + Handle<String> prop_name = factory->InternalizeUtf8String(property_name);
|
| + Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
| + i::FLAG_gc_interval = gc_count;
|
| + i::FLAG_gc_global = true;
|
| + CcTest::heap()->set_allocation_timeout(gc_count);
|
| + JSReceiver::SetProperty(
|
| + object, prop_name, twenty_three, NONE, SLOPPY).Check();
|
| +}
|
| +
|
| +
|
| +TEST(TransitionArrayShrinksDuringAllocToZero) {
|
| + i::FLAG_stress_compaction = false;
|
| + i::FLAG_allow_natives_syntax = true;
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + static const int transitions_count = 10;
|
| + AddTransitions(transitions_count);
|
| + CompileRun("var root = new Object;");
|
| + Handle<JSObject> root = GetByName("root");
|
| +
|
| + // Count number of live transitions before marking.
|
| + int transitions_before = CountMapTransitions(root->map());
|
| + CHECK_EQ(transitions_count, transitions_before);
|
| +
|
| + // Get rid of o
|
| + CompileRun("o = new Object;"
|
| + "root = new Object");
|
| + root = GetByName("root");
|
| + AddPropertyTo(2, root, "funny");
|
| +
|
| + // Count number of live transitions after marking. Note that one transition
|
| + // is left, because 'o' still holds an instance of one transition target.
|
| + int transitions_after = CountMapTransitions(
|
| + Map::cast(root->map()->GetBackPointer()));
|
| + CHECK_EQ(1, transitions_after);
|
| +}
|
| +
|
| +
|
| +TEST(TransitionArrayShrinksDuringAllocToOne) {
|
| + i::FLAG_stress_compaction = false;
|
| + i::FLAG_allow_natives_syntax = true;
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + static const int transitions_count = 10;
|
| + AddTransitions(transitions_count);
|
| + CompileRun("var root = new Object;");
|
| + Handle<JSObject> root = GetByName("root");
|
| +
|
| + // Count number of live transitions before marking.
|
| + int transitions_before = CountMapTransitions(root->map());
|
| + CHECK_EQ(transitions_count, transitions_before);
|
| +
|
| + root = GetByName("root");
|
| + AddPropertyTo(2, root, "funny");
|
| +
|
| + // Count number of live transitions after marking. Note that one transition
|
| + // is left, because 'o' still holds an instance of one transition target.
|
| + int transitions_after = CountMapTransitions(
|
| + Map::cast(root->map()->GetBackPointer()));
|
| + CHECK_EQ(2, transitions_after);
|
| +}
|
| +
|
| +
|
| +TEST(TransitionArrayShrinksDuringAllocToOnePropertyFound) {
|
| + i::FLAG_stress_compaction = false;
|
| + i::FLAG_allow_natives_syntax = true;
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + static const int transitions_count = 10;
|
| + AddTransitions(transitions_count);
|
| + CompileRun("var root = new Object;");
|
| + Handle<JSObject> root = GetByName("root");
|
| +
|
| + // Count number of live transitions before marking.
|
| + int transitions_before = CountMapTransitions(root->map());
|
| + CHECK_EQ(transitions_count, transitions_before);
|
| +
|
| + root = GetByName("root");
|
| + AddPropertyTo(0, root, "prop9");
|
| +
|
| + // Count number of live transitions after marking. Note that one transition
|
| + // is left, because 'o' still holds an instance of one transition target.
|
| + int transitions_after = CountMapTransitions(
|
| + Map::cast(root->map()->GetBackPointer()));
|
| + CHECK_EQ(1, transitions_after);
|
| +}
|
| +
|
| +
|
| +TEST(TransitionArraySimpleToFull) {
|
| + i::FLAG_stress_compaction = false;
|
| + i::FLAG_allow_natives_syntax = true;
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + static const int transitions_count = 1;
|
| + AddTransitions(transitions_count);
|
| + CompileRun("var root = new Object;");
|
| + Handle<JSObject> root = GetByName("root");
|
| +
|
| + // Count number of live transitions before marking.
|
| + int transitions_before = CountMapTransitions(root->map());
|
| + CHECK_EQ(transitions_count, transitions_before);
|
| +
|
| + CompileRun("o = new Object;"
|
| + "root = new Object");
|
| + root = GetByName("root");
|
| + ASSERT(root->map()->transitions()->IsSimpleTransition());
|
| + AddPropertyTo(2, root, "happy");
|
| +
|
| + // Count number of live transitions after marking. Note that one transition
|
| + // is left, because 'o' still holds an instance of one transition target.
|
| + int transitions_after = CountMapTransitions(
|
| + Map::cast(root->map()->GetBackPointer()));
|
| + CHECK_EQ(1, transitions_after);
|
| +}
|
| +
|
| +
|
| TEST(Regress2143a) {
|
| i::FLAG_collect_maps = true;
|
| i::FLAG_incremental_marking = true;
|
|
|