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

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: 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
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 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 return map->transitions()->number_of_transitions(); 2857 return map->transitions()->number_of_transitions();
2857 } 2858 }
2858 2859
2859 2860
2860 // Test that map transitions are cleared and maps are collected with 2861 // Test that map transitions are cleared and maps are collected with
2861 // incremental marking as well. 2862 // incremental marking as well.
2862 TEST(Regress1465) { 2863 TEST(Regress1465) {
2863 i::FLAG_stress_compaction = false; 2864 i::FLAG_stress_compaction = false;
2864 i::FLAG_allow_natives_syntax = true; 2865 i::FLAG_allow_natives_syntax = true;
2865 i::FLAG_trace_incremental_marking = true; 2866 i::FLAG_trace_incremental_marking = true;
2867 i::FLAG_retain_maps_for_n_gc = 0;
2866 CcTest::InitializeVM(); 2868 CcTest::InitializeVM();
2867 v8::HandleScope scope(CcTest::isolate()); 2869 v8::HandleScope scope(CcTest::isolate());
2868 static const int transitions_count = 256; 2870 static const int transitions_count = 256;
2869 2871
2870 CompileRun("function F() {}"); 2872 CompileRun("function F() {}");
2871 { 2873 {
2872 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 2874 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
2873 for (int i = 0; i < transitions_count; i++) { 2875 for (int i = 0; i < transitions_count; i++) {
2874 EmbeddedVector<char, 64> buffer; 2876 EmbeddedVector<char, 64> buffer;
2875 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); 2877 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 2920
2919 2921
2920 static void AddPropertyTo( 2922 static void AddPropertyTo(
2921 int gc_count, Handle<JSObject> object, const char* property_name) { 2923 int gc_count, Handle<JSObject> object, const char* property_name) {
2922 Isolate* isolate = CcTest::i_isolate(); 2924 Isolate* isolate = CcTest::i_isolate();
2923 Factory* factory = isolate->factory(); 2925 Factory* factory = isolate->factory();
2924 Handle<String> prop_name = factory->InternalizeUtf8String(property_name); 2926 Handle<String> prop_name = factory->InternalizeUtf8String(property_name);
2925 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 2927 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
2926 i::FLAG_gc_interval = gc_count; 2928 i::FLAG_gc_interval = gc_count;
2927 i::FLAG_gc_global = true; 2929 i::FLAG_gc_global = true;
2930 i::FLAG_retain_maps_for_n_gc = 0;
2928 CcTest::heap()->set_allocation_timeout(gc_count); 2931 CcTest::heap()->set_allocation_timeout(gc_count);
2929 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check(); 2932 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check();
2930 } 2933 }
2931 2934
2932 2935
2933 TEST(TransitionArrayShrinksDuringAllocToZero) { 2936 TEST(TransitionArrayShrinksDuringAllocToZero) {
2934 i::FLAG_stress_compaction = false; 2937 i::FLAG_stress_compaction = false;
2935 i::FLAG_allow_natives_syntax = true; 2938 i::FLAG_allow_natives_syntax = true;
2936 CcTest::InitializeVM(); 2939 CcTest::InitializeVM();
2937 v8::HandleScope scope(CcTest::isolate()); 2940 v8::HandleScope scope(CcTest::isolate());
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4140 Handle<JSFunction> bar_handle = 4143 Handle<JSFunction> bar_handle =
4141 v8::Utils::OpenHandle( 4144 v8::Utils::OpenHandle(
4142 *v8::Handle<v8::Function>::Cast( 4145 *v8::Handle<v8::Function>::Cast(
4143 CcTest::global()->Get(v8_str("bar")))); 4146 CcTest::global()->Get(v8_str("bar"))));
4144 CHECK_EQ(bar_handle->code(), function_bar); 4147 CHECK_EQ(bar_handle->code(), function_bar);
4145 } 4148 }
4146 4149
4147 // Now make sure that a gc should get rid of the function, even though we 4150 // Now make sure that a gc should get rid of the function, even though we
4148 // still have the allocation site alive. 4151 // still have the allocation site alive.
4149 for (int i = 0; i < 4; i++) { 4152 for (int i = 0; i < 4; i++) {
4150 heap->CollectAllGarbage(Heap::kNoGCFlags); 4153 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
4151 } 4154 }
4152 4155
4153 // TODO(mvstanton): this test fails when FLAG_vector_ics is true because 4156 // TODO(mvstanton): this test fails when FLAG_vector_ics is true because
4154 // monomorphic load ics are preserved, but also strongly walked. They 4157 // monomorphic load ics are preserved, but also strongly walked. They
4155 // end up keeping function bar alive. 4158 // end up keeping function bar alive.
4156 4159
4157 // The site still exists because of our global handle, but the code is no 4160 // The site still exists because of our global handle, but the code is no
4158 // longer referred to by dependent_code(). 4161 // longer referred to by dependent_code().
4159 DependentCode::GroupStartIndexes starts(site->dependent_code()); 4162 DependentCode::GroupStartIndexes starts(site->dependent_code());
4160 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); 4163 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
4251 4254
4252 4255
4253 TEST(NoWeakHashTableLeakWithIncrementalMarking) { 4256 TEST(NoWeakHashTableLeakWithIncrementalMarking) {
4254 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; 4257 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return;
4255 if (!i::FLAG_incremental_marking) return; 4258 if (!i::FLAG_incremental_marking) return;
4256 // TODO(mvstanton): vector ics need weak support. 4259 // TODO(mvstanton): vector ics need weak support.
4257 if (FLAG_vector_ics) return; 4260 if (FLAG_vector_ics) return;
4258 i::FLAG_weak_embedded_objects_in_optimized_code = true; 4261 i::FLAG_weak_embedded_objects_in_optimized_code = true;
4259 i::FLAG_allow_natives_syntax = true; 4262 i::FLAG_allow_natives_syntax = true;
4260 i::FLAG_compilation_cache = false; 4263 i::FLAG_compilation_cache = false;
4264 i::FLAG_retain_maps_for_n_gc = 0;
4261 CcTest::InitializeVM(); 4265 CcTest::InitializeVM();
4262 Isolate* isolate = CcTest::i_isolate(); 4266 Isolate* isolate = CcTest::i_isolate();
4263 v8::internal::Heap* heap = CcTest::heap(); 4267 v8::internal::Heap* heap = CcTest::heap();
4264 4268
4265 if (!isolate->use_crankshaft()) return; 4269 if (!isolate->use_crankshaft()) return;
4266 HandleScope outer_scope(heap->isolate()); 4270 HandleScope outer_scope(heap->isolate());
4267 for (int i = 0; i < 3; i++) { 4271 for (int i = 0; i < 3; i++) {
4268 SimulateIncrementalMarking(heap); 4272 SimulateIncrementalMarking(heap);
4269 { 4273 {
4270 LocalContext context; 4274 LocalContext context;
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
4941 // The following line will update the backing store. 4945 // The following line will update the backing store.
4942 CompileRun( 4946 CompileRun(
4943 "for (var i = 0; i < 50; i++) {" 4947 "for (var i = 0; i < 50; i++) {"
4944 " weak_map.set(future_keys[i], i);" 4948 " weak_map.set(future_keys[i], i);"
4945 "}"); 4949 "}");
4946 heap->incremental_marking()->set_should_hurry(true); 4950 heap->incremental_marking()->set_should_hurry(true);
4947 heap->CollectGarbage(OLD_POINTER_SPACE); 4951 heap->CollectGarbage(OLD_POINTER_SPACE);
4948 } 4952 }
4949 4953
4950 4954
4955 TEST(MapRetaining) {
Hannes Payer (out of office) 2014/12/16 17:15:35 Please also test the flag for n == 0, n in between
ulan 2014/12/17 11:13:34 Done.
4956 CcTest::InitializeVM();
4957 v8::HandleScope scope(CcTest::isolate());
4958 Isolate* isolate = CcTest::i_isolate();
4959 Heap* heap = isolate->heap();
4960 Handle<WeakCell> weak_cell;
4961 {
4962 HandleScope inner_scope(isolate);
4963 Handle<Map> map = Map::Create(isolate, 1);
4964 weak_cell = inner_scope.CloseAndEscape(Map::WeakCellForMap(map));
4965 }
4966 CHECK(!weak_cell->cleared());
4967 for (int i = 0; i < FLAG_retain_maps_for_n_gc; i++) {
4968 heap->CollectGarbage(OLD_POINTER_SPACE);
4969 }
4970 CHECK(!weak_cell->cleared());
4971 heap->CollectGarbage(OLD_POINTER_SPACE);
4972 CHECK(weak_cell->cleared());
4973 }
4974
4975
4951 #ifdef DEBUG 4976 #ifdef DEBUG
4952 TEST(PathTracer) { 4977 TEST(PathTracer) {
4953 CcTest::InitializeVM(); 4978 CcTest::InitializeVM();
4954 v8::HandleScope scope(CcTest::isolate()); 4979 v8::HandleScope scope(CcTest::isolate());
4955 4980
4956 v8::Local<v8::Value> result = CompileRun("'abc'"); 4981 v8::Local<v8::Value> result = CompileRun("'abc'");
4957 Handle<Object> o = v8::Utils::OpenHandle(*result); 4982 Handle<Object> o = v8::Utils::OpenHandle(*result);
4958 CcTest::i_isolate()->heap()->TracePathToObject(*o); 4983 CcTest::i_isolate()->heap()->TracePathToObject(*o);
4959 } 4984 }
4960 #endif // DEBUG 4985 #endif // DEBUG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698