Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: test/cctest/test-heap.cc

Issue 980523004: Retain maps embedded in optimized code for several garbage collections. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Check constructor. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-array-list.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 return count; 1460 return count;
1461 } 1461 }
1462 1462
1463 1463
1464 TEST(TestInternalWeakLists) { 1464 TEST(TestInternalWeakLists) {
1465 v8::V8::Initialize(); 1465 v8::V8::Initialize();
1466 1466
1467 // Some flags turn Scavenge collections into Mark-sweep collections 1467 // Some flags turn Scavenge collections into Mark-sweep collections
1468 // and hence are incompatible with this test case. 1468 // and hence are incompatible with this test case.
1469 if (FLAG_gc_global || FLAG_stress_compaction) return; 1469 if (FLAG_gc_global || FLAG_stress_compaction) return;
1470 FLAG_retain_maps_for_n_gc = 0;
1470 1471
1471 static const int kNumTestContexts = 10; 1472 static const int kNumTestContexts = 10;
1472 1473
1473 Isolate* isolate = CcTest::i_isolate(); 1474 Isolate* isolate = CcTest::i_isolate();
1474 Heap* heap = isolate->heap(); 1475 Heap* heap = isolate->heap();
1475 HandleScope scope(isolate); 1476 HandleScope scope(isolate);
1476 v8::Handle<v8::Context> ctx[kNumTestContexts]; 1477 v8::Handle<v8::Context> ctx[kNumTestContexts];
1477 1478
1478 CHECK_EQ(0, CountNativeContexts()); 1479 CHECK_EQ(0, CountNativeContexts());
1479 1480
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after
2879 return map->transitions()->number_of_transitions(); 2880 return map->transitions()->number_of_transitions();
2880 } 2881 }
2881 2882
2882 2883
2883 // Test that map transitions are cleared and maps are collected with 2884 // Test that map transitions are cleared and maps are collected with
2884 // incremental marking as well. 2885 // incremental marking as well.
2885 TEST(Regress1465) { 2886 TEST(Regress1465) {
2886 i::FLAG_stress_compaction = false; 2887 i::FLAG_stress_compaction = false;
2887 i::FLAG_allow_natives_syntax = true; 2888 i::FLAG_allow_natives_syntax = true;
2888 i::FLAG_trace_incremental_marking = true; 2889 i::FLAG_trace_incremental_marking = true;
2890 i::FLAG_retain_maps_for_n_gc = 0;
2889 CcTest::InitializeVM(); 2891 CcTest::InitializeVM();
2890 v8::HandleScope scope(CcTest::isolate()); 2892 v8::HandleScope scope(CcTest::isolate());
2891 static const int transitions_count = 256; 2893 static const int transitions_count = 256;
2892 2894
2893 CompileRun("function F() {}"); 2895 CompileRun("function F() {}");
2894 { 2896 {
2895 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 2897 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
2896 for (int i = 0; i < transitions_count; i++) { 2898 for (int i = 0; i < transitions_count; i++) {
2897 EmbeddedVector<char, 64> buffer; 2899 EmbeddedVector<char, 64> buffer;
2898 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); 2900 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 2943
2942 2944
2943 static void AddPropertyTo( 2945 static void AddPropertyTo(
2944 int gc_count, Handle<JSObject> object, const char* property_name) { 2946 int gc_count, Handle<JSObject> object, const char* property_name) {
2945 Isolate* isolate = CcTest::i_isolate(); 2947 Isolate* isolate = CcTest::i_isolate();
2946 Factory* factory = isolate->factory(); 2948 Factory* factory = isolate->factory();
2947 Handle<String> prop_name = factory->InternalizeUtf8String(property_name); 2949 Handle<String> prop_name = factory->InternalizeUtf8String(property_name);
2948 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 2950 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
2949 i::FLAG_gc_interval = gc_count; 2951 i::FLAG_gc_interval = gc_count;
2950 i::FLAG_gc_global = true; 2952 i::FLAG_gc_global = true;
2953 i::FLAG_retain_maps_for_n_gc = 0;
2951 CcTest::heap()->set_allocation_timeout(gc_count); 2954 CcTest::heap()->set_allocation_timeout(gc_count);
2952 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check(); 2955 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check();
2953 } 2956 }
2954 2957
2955 2958
2956 TEST(TransitionArrayShrinksDuringAllocToZero) { 2959 TEST(TransitionArrayShrinksDuringAllocToZero) {
2957 i::FLAG_stress_compaction = false; 2960 i::FLAG_stress_compaction = false;
2958 i::FLAG_allow_natives_syntax = true; 2961 i::FLAG_allow_natives_syntax = true;
2959 CcTest::InitializeVM(); 2962 CcTest::InitializeVM();
2960 v8::HandleScope scope(CcTest::isolate()); 2963 v8::HandleScope scope(CcTest::isolate());
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4139 Handle<JSFunction> bar_handle = 4142 Handle<JSFunction> bar_handle =
4140 v8::Utils::OpenHandle( 4143 v8::Utils::OpenHandle(
4141 *v8::Handle<v8::Function>::Cast( 4144 *v8::Handle<v8::Function>::Cast(
4142 CcTest::global()->Get(v8_str("bar")))); 4145 CcTest::global()->Get(v8_str("bar"))));
4143 CHECK_EQ(bar_handle->code(), function_bar); 4146 CHECK_EQ(bar_handle->code(), function_bar);
4144 } 4147 }
4145 4148
4146 // Now make sure that a gc should get rid of the function, even though we 4149 // Now make sure that a gc should get rid of the function, even though we
4147 // still have the allocation site alive. 4150 // still have the allocation site alive.
4148 for (int i = 0; i < 4; i++) { 4151 for (int i = 0; i < 4; i++) {
4149 heap->CollectAllGarbage(Heap::kNoGCFlags); 4152 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
4150 } 4153 }
4151 4154
4152 // The site still exists because of our global handle, but the code is no 4155 // The site still exists because of our global handle, but the code is no
4153 // longer referred to by dependent_code(). 4156 // longer referred to by dependent_code().
4154 DependentCode::GroupStartIndexes starts(site->dependent_code()); 4157 DependentCode::GroupStartIndexes starts(site->dependent_code());
4155 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); 4158 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
4156 CHECK(site->dependent_code()->object_at(index)->IsWeakCell() && 4159 CHECK(site->dependent_code()->object_at(index)->IsWeakCell() &&
4157 WeakCell::cast(site->dependent_code()->object_at(index))->cleared()); 4160 WeakCell::cast(site->dependent_code()->object_at(index))->cleared());
4158 } 4161 }
4159 4162
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4241 DCHECK(code->marked_for_deoptimization()); 4244 DCHECK(code->marked_for_deoptimization());
4242 } 4245 }
4243 4246
4244 4247
4245 TEST(NoWeakHashTableLeakWithIncrementalMarking) { 4248 TEST(NoWeakHashTableLeakWithIncrementalMarking) {
4246 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; 4249 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return;
4247 if (!i::FLAG_incremental_marking) return; 4250 if (!i::FLAG_incremental_marking) return;
4248 i::FLAG_weak_embedded_objects_in_optimized_code = true; 4251 i::FLAG_weak_embedded_objects_in_optimized_code = true;
4249 i::FLAG_allow_natives_syntax = true; 4252 i::FLAG_allow_natives_syntax = true;
4250 i::FLAG_compilation_cache = false; 4253 i::FLAG_compilation_cache = false;
4254 i::FLAG_retain_maps_for_n_gc = 0;
4251 CcTest::InitializeVM(); 4255 CcTest::InitializeVM();
4252 Isolate* isolate = CcTest::i_isolate(); 4256 Isolate* isolate = CcTest::i_isolate();
4253 v8::internal::Heap* heap = CcTest::heap(); 4257 v8::internal::Heap* heap = CcTest::heap();
4254 4258
4255 if (!isolate->use_crankshaft()) return; 4259 if (!isolate->use_crankshaft()) return;
4256 HandleScope outer_scope(heap->isolate()); 4260 HandleScope outer_scope(heap->isolate());
4257 for (int i = 0; i < 3; i++) { 4261 for (int i = 0; i < 3; i++) {
4258 SimulateIncrementalMarking(heap); 4262 SimulateIncrementalMarking(heap);
4259 { 4263 {
4260 LocalContext context; 4264 LocalContext context;
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
5075 CHECK(!weak_prototype->cleared()); 5079 CHECK(!weak_prototype->cleared());
5076 // Change the map of a.x and make the previous map garbage collectable. 5080 // Change the map of a.x and make the previous map garbage collectable.
5077 CompileRun("a.x.__proto__ = {};"); 5081 CompileRun("a.x.__proto__ = {};");
5078 for (int i = 0; i < 4; i++) { 5082 for (int i = 0; i < 4; i++) {
5079 heap->CollectAllGarbage(Heap::kNoGCFlags); 5083 heap->CollectAllGarbage(Heap::kNoGCFlags);
5080 } 5084 }
5081 CHECK(weak_prototype->cleared()); 5085 CHECK(weak_prototype->cleared());
5082 } 5086 }
5083 5087
5084 5088
5089 void CheckMapRetainingFor(int n) {
5090 FLAG_retain_maps_for_n_gc = n;
5091 Isolate* isolate = CcTest::i_isolate();
5092 Heap* heap = isolate->heap();
5093 Handle<WeakCell> weak_cell;
5094 {
5095 HandleScope inner_scope(isolate);
5096 Handle<Map> map = Map::Create(isolate, 1);
5097 heap->AddRetainedMap(map);
5098 weak_cell = inner_scope.CloseAndEscape(Map::WeakCellForMap(map));
5099 }
5100 CHECK(!weak_cell->cleared());
5101 for (int i = 0; i < n; i++) {
5102 heap->CollectGarbage(OLD_POINTER_SPACE);
5103 }
5104 CHECK(!weak_cell->cleared());
5105 heap->CollectGarbage(OLD_POINTER_SPACE);
5106 CHECK(weak_cell->cleared());
5107 }
5108
5109
5110 TEST(MapRetaining) {
5111 CcTest::InitializeVM();
5112 v8::HandleScope scope(CcTest::isolate());
5113 CheckMapRetainingFor(FLAG_retain_maps_for_n_gc);
5114 CheckMapRetainingFor(0);
5115 CheckMapRetainingFor(1);
5116 CheckMapRetainingFor(7);
5117 }
5118
5119
5085 #ifdef DEBUG 5120 #ifdef DEBUG
5086 TEST(PathTracer) { 5121 TEST(PathTracer) {
5087 CcTest::InitializeVM(); 5122 CcTest::InitializeVM();
5088 v8::HandleScope scope(CcTest::isolate()); 5123 v8::HandleScope scope(CcTest::isolate());
5089 5124
5090 v8::Local<v8::Value> result = CompileRun("'abc'"); 5125 v8::Local<v8::Value> result = CompileRun("'abc'");
5091 Handle<Object> o = v8::Utils::OpenHandle(*result); 5126 Handle<Object> o = v8::Utils::OpenHandle(*result);
5092 CcTest::i_isolate()->heap()->TracePathToObject(*o); 5127 CcTest::i_isolate()->heap()->TracePathToObject(*o);
5093 } 5128 }
5094 #endif // DEBUG 5129 #endif // DEBUG
5095 5130
5096 5131
5097 TEST(WritableVsImmortalRoots) { 5132 TEST(WritableVsImmortalRoots) {
5098 for (int i = 0; i < Heap::kStrongRootListLength; ++i) { 5133 for (int i = 0; i < Heap::kStrongRootListLength; ++i) {
5099 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); 5134 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
5100 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index); 5135 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index);
5101 bool immortal = Heap::RootIsImmortalImmovable(root_index); 5136 bool immortal = Heap::RootIsImmortalImmovable(root_index);
5102 // A root value can be writable, immortal, or neither, but not both. 5137 // A root value can be writable, immortal, or neither, but not both.
5103 CHECK(!immortal || !writable); 5138 CHECK(!immortal || !writable);
5104 } 5139 }
5105 } 5140 }
OLDNEW
« no previous file with comments | « test/cctest/test-array-list.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698