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

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

Issue 794583003: Retain maps for several garbage collections (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 6 years 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-api.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 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 return count; 1492 return count;
1493 } 1493 }
1494 1494
1495 1495
1496 TEST(TestInternalWeakLists) { 1496 TEST(TestInternalWeakLists) {
1497 v8::V8::Initialize(); 1497 v8::V8::Initialize();
1498 1498
1499 // Some flags turn Scavenge collections into Mark-sweep collections 1499 // Some flags turn Scavenge collections into Mark-sweep collections
1500 // and hence are incompatible with this test case. 1500 // and hence are incompatible with this test case.
1501 if (FLAG_gc_global || FLAG_stress_compaction) return; 1501 if (FLAG_gc_global || FLAG_stress_compaction) return;
1502 FLAG_retain_maps_for_n_gc = 0;
1502 1503
1503 static const int kNumTestContexts = 10; 1504 static const int kNumTestContexts = 10;
1504 1505
1505 Isolate* isolate = CcTest::i_isolate(); 1506 Isolate* isolate = CcTest::i_isolate();
1506 Heap* heap = isolate->heap(); 1507 Heap* heap = isolate->heap();
1507 HandleScope scope(isolate); 1508 HandleScope scope(isolate);
1508 v8::Handle<v8::Context> ctx[kNumTestContexts]; 1509 v8::Handle<v8::Context> ctx[kNumTestContexts];
1509 1510
1510 CHECK_EQ(0, CountNativeContexts()); 1511 CHECK_EQ(0, CountNativeContexts());
1511 1512
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 return map->transitions()->number_of_transitions(); 2915 return map->transitions()->number_of_transitions();
2915 } 2916 }
2916 2917
2917 2918
2918 // Test that map transitions are cleared and maps are collected with 2919 // Test that map transitions are cleared and maps are collected with
2919 // incremental marking as well. 2920 // incremental marking as well.
2920 TEST(Regress1465) { 2921 TEST(Regress1465) {
2921 i::FLAG_stress_compaction = false; 2922 i::FLAG_stress_compaction = false;
2922 i::FLAG_allow_natives_syntax = true; 2923 i::FLAG_allow_natives_syntax = true;
2923 i::FLAG_trace_incremental_marking = true; 2924 i::FLAG_trace_incremental_marking = true;
2925 i::FLAG_retain_maps_for_n_gc = 0;
2924 CcTest::InitializeVM(); 2926 CcTest::InitializeVM();
2925 v8::HandleScope scope(CcTest::isolate()); 2927 v8::HandleScope scope(CcTest::isolate());
2926 static const int transitions_count = 256; 2928 static const int transitions_count = 256;
2927 2929
2928 CompileRun("function F() {}"); 2930 CompileRun("function F() {}");
2929 { 2931 {
2930 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 2932 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
2931 for (int i = 0; i < transitions_count; i++) { 2933 for (int i = 0; i < transitions_count; i++) {
2932 EmbeddedVector<char, 64> buffer; 2934 EmbeddedVector<char, 64> buffer;
2933 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); 2935 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 2978
2977 2979
2978 static void AddPropertyTo( 2980 static void AddPropertyTo(
2979 int gc_count, Handle<JSObject> object, const char* property_name) { 2981 int gc_count, Handle<JSObject> object, const char* property_name) {
2980 Isolate* isolate = CcTest::i_isolate(); 2982 Isolate* isolate = CcTest::i_isolate();
2981 Factory* factory = isolate->factory(); 2983 Factory* factory = isolate->factory();
2982 Handle<String> prop_name = factory->InternalizeUtf8String(property_name); 2984 Handle<String> prop_name = factory->InternalizeUtf8String(property_name);
2983 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 2985 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
2984 i::FLAG_gc_interval = gc_count; 2986 i::FLAG_gc_interval = gc_count;
2985 i::FLAG_gc_global = true; 2987 i::FLAG_gc_global = true;
2988 i::FLAG_retain_maps_for_n_gc = 0;
2986 CcTest::heap()->set_allocation_timeout(gc_count); 2989 CcTest::heap()->set_allocation_timeout(gc_count);
2987 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check(); 2990 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check();
2988 } 2991 }
2989 2992
2990 2993
2991 TEST(TransitionArrayShrinksDuringAllocToZero) { 2994 TEST(TransitionArrayShrinksDuringAllocToZero) {
2992 i::FLAG_stress_compaction = false; 2995 i::FLAG_stress_compaction = false;
2993 i::FLAG_allow_natives_syntax = true; 2996 i::FLAG_allow_natives_syntax = true;
2994 CcTest::InitializeVM(); 2997 CcTest::InitializeVM();
2995 v8::HandleScope scope(CcTest::isolate()); 2998 v8::HandleScope scope(CcTest::isolate());
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4198 Handle<JSFunction> bar_handle = 4201 Handle<JSFunction> bar_handle =
4199 v8::Utils::OpenHandle( 4202 v8::Utils::OpenHandle(
4200 *v8::Handle<v8::Function>::Cast( 4203 *v8::Handle<v8::Function>::Cast(
4201 CcTest::global()->Get(v8_str("bar")))); 4204 CcTest::global()->Get(v8_str("bar"))));
4202 CHECK_EQ(bar_handle->code(), function_bar); 4205 CHECK_EQ(bar_handle->code(), function_bar);
4203 } 4206 }
4204 4207
4205 // Now make sure that a gc should get rid of the function, even though we 4208 // Now make sure that a gc should get rid of the function, even though we
4206 // still have the allocation site alive. 4209 // still have the allocation site alive.
4207 for (int i = 0; i < 4; i++) { 4210 for (int i = 0; i < 4; i++) {
4208 heap->CollectAllGarbage(Heap::kNoGCFlags); 4211 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
4209 } 4212 }
4210 4213
4211 // TODO(mvstanton): this test fails when FLAG_vector_ics is true because 4214 // TODO(mvstanton): this test fails when FLAG_vector_ics is true because
4212 // monomorphic load ics are preserved, but also strongly walked. They 4215 // monomorphic load ics are preserved, but also strongly walked. They
4213 // end up keeping function bar alive. 4216 // end up keeping function bar alive.
4214 4217
4215 // The site still exists because of our global handle, but the code is no 4218 // The site still exists because of our global handle, but the code is no
4216 // longer referred to by dependent_code(). 4219 // longer referred to by dependent_code().
4217 DependentCode::GroupStartIndexes starts(site->dependent_code()); 4220 DependentCode::GroupStartIndexes starts(site->dependent_code());
4218 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); 4221 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
4309 4312
4310 4313
4311 TEST(NoWeakHashTableLeakWithIncrementalMarking) { 4314 TEST(NoWeakHashTableLeakWithIncrementalMarking) {
4312 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; 4315 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return;
4313 if (!i::FLAG_incremental_marking) return; 4316 if (!i::FLAG_incremental_marking) return;
4314 // TODO(mvstanton): vector ics need weak support. 4317 // TODO(mvstanton): vector ics need weak support.
4315 if (FLAG_vector_ics) return; 4318 if (FLAG_vector_ics) return;
4316 i::FLAG_weak_embedded_objects_in_optimized_code = true; 4319 i::FLAG_weak_embedded_objects_in_optimized_code = true;
4317 i::FLAG_allow_natives_syntax = true; 4320 i::FLAG_allow_natives_syntax = true;
4318 i::FLAG_compilation_cache = false; 4321 i::FLAG_compilation_cache = false;
4322 i::FLAG_retain_maps_for_n_gc = 0;
4319 CcTest::InitializeVM(); 4323 CcTest::InitializeVM();
4320 Isolate* isolate = CcTest::i_isolate(); 4324 Isolate* isolate = CcTest::i_isolate();
4321 v8::internal::Heap* heap = CcTest::heap(); 4325 v8::internal::Heap* heap = CcTest::heap();
4322 4326
4323 if (!isolate->use_crankshaft()) return; 4327 if (!isolate->use_crankshaft()) return;
4324 HandleScope outer_scope(heap->isolate()); 4328 HandleScope outer_scope(heap->isolate());
4325 for (int i = 0; i < 3; i++) { 4329 for (int i = 0; i < 3; i++) {
4326 SimulateIncrementalMarking(heap); 4330 SimulateIncrementalMarking(heap);
4327 { 4331 {
4328 LocalContext context; 4332 LocalContext context;
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
5104 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); 5108 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
5105 Handle<JSArray> array = factory->NewJSArray(2); 5109 Handle<JSArray> array = factory->NewJSArray(2);
5106 5110
5107 Handle<String> name = factory->InternalizeUtf8String("testArray"); 5111 Handle<String> name = factory->InternalizeUtf8String("testArray");
5108 JSReceiver::SetProperty(global, name, array, SLOPPY).Check(); 5112 JSReceiver::SetProperty(global, name, array, SLOPPY).Check();
5109 CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();"); 5113 CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();");
5110 heap->CollectGarbage(OLD_POINTER_SPACE); 5114 heap->CollectGarbage(OLD_POINTER_SPACE);
5111 } 5115 }
5112 5116
5113 5117
5118 void CheckMapRetainingFor(int n) {
5119 FLAG_retain_maps_for_n_gc = n;
5120 Isolate* isolate = CcTest::i_isolate();
5121 Heap* heap = isolate->heap();
5122 Handle<WeakCell> weak_cell;
5123 {
5124 HandleScope inner_scope(isolate);
5125 Handle<Map> map = Map::Create(isolate, 1);
5126 weak_cell = inner_scope.CloseAndEscape(Map::WeakCellForMap(map));
5127 }
5128 CHECK(!weak_cell->cleared());
5129 int retaining_count =
5130 Min(FLAG_retain_maps_for_n_gc,
5131 Map::kRetainingCounterStart - Map::kRetainingCounterEnd);
5132 for (int i = 0; i < retaining_count; i++) {
5133 heap->CollectGarbage(OLD_POINTER_SPACE);
5134 }
5135 CHECK(!weak_cell->cleared());
5136 heap->CollectGarbage(OLD_POINTER_SPACE);
5137 CHECK(weak_cell->cleared());
5138 }
5139
5140
5141 TEST(MapRetaining) {
5142 CcTest::InitializeVM();
5143 v8::HandleScope scope(CcTest::isolate());
5144 CheckMapRetainingFor(FLAG_retain_maps_for_n_gc);
5145 CheckMapRetainingFor(0);
5146 CheckMapRetainingFor(Map::kRetainingCounterStart - Map::kRetainingCounterEnd);
5147 CheckMapRetainingFor(Map::kRetainingCounterStart - Map::kRetainingCounterEnd +
5148 1);
5149 }
5150
5151
5114 #ifdef DEBUG 5152 #ifdef DEBUG
5115 TEST(PathTracer) { 5153 TEST(PathTracer) {
5116 CcTest::InitializeVM(); 5154 CcTest::InitializeVM();
5117 v8::HandleScope scope(CcTest::isolate()); 5155 v8::HandleScope scope(CcTest::isolate());
5118 5156
5119 v8::Local<v8::Value> result = CompileRun("'abc'"); 5157 v8::Local<v8::Value> result = CompileRun("'abc'");
5120 Handle<Object> o = v8::Utils::OpenHandle(*result); 5158 Handle<Object> o = v8::Utils::OpenHandle(*result);
5121 CcTest::i_isolate()->heap()->TracePathToObject(*o); 5159 CcTest::i_isolate()->heap()->TracePathToObject(*o);
5122 } 5160 }
5123 #endif // DEBUG 5161 #endif // DEBUG
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698