| OLD | NEW |
| 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 Loading... |
| 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; | |
| 1503 | 1502 |
| 1504 static const int kNumTestContexts = 10; | 1503 static const int kNumTestContexts = 10; |
| 1505 | 1504 |
| 1506 Isolate* isolate = CcTest::i_isolate(); | 1505 Isolate* isolate = CcTest::i_isolate(); |
| 1507 Heap* heap = isolate->heap(); | 1506 Heap* heap = isolate->heap(); |
| 1508 HandleScope scope(isolate); | 1507 HandleScope scope(isolate); |
| 1509 v8::Handle<v8::Context> ctx[kNumTestContexts]; | 1508 v8::Handle<v8::Context> ctx[kNumTestContexts]; |
| 1510 | 1509 |
| 1511 CHECK_EQ(0, CountNativeContexts()); | 1510 CHECK_EQ(0, CountNativeContexts()); |
| 1512 | 1511 |
| (...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2915 return map->transitions()->number_of_transitions(); | 2914 return map->transitions()->number_of_transitions(); |
| 2916 } | 2915 } |
| 2917 | 2916 |
| 2918 | 2917 |
| 2919 // Test that map transitions are cleared and maps are collected with | 2918 // Test that map transitions are cleared and maps are collected with |
| 2920 // incremental marking as well. | 2919 // incremental marking as well. |
| 2921 TEST(Regress1465) { | 2920 TEST(Regress1465) { |
| 2922 i::FLAG_stress_compaction = false; | 2921 i::FLAG_stress_compaction = false; |
| 2923 i::FLAG_allow_natives_syntax = true; | 2922 i::FLAG_allow_natives_syntax = true; |
| 2924 i::FLAG_trace_incremental_marking = true; | 2923 i::FLAG_trace_incremental_marking = true; |
| 2925 i::FLAG_retain_maps_for_n_gc = 0; | |
| 2926 CcTest::InitializeVM(); | 2924 CcTest::InitializeVM(); |
| 2927 v8::HandleScope scope(CcTest::isolate()); | 2925 v8::HandleScope scope(CcTest::isolate()); |
| 2928 static const int transitions_count = 256; | 2926 static const int transitions_count = 256; |
| 2929 | 2927 |
| 2930 CompileRun("function F() {}"); | 2928 CompileRun("function F() {}"); |
| 2931 { | 2929 { |
| 2932 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 2930 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
| 2933 for (int i = 0; i < transitions_count; i++) { | 2931 for (int i = 0; i < transitions_count; i++) { |
| 2934 EmbeddedVector<char, 64> buffer; | 2932 EmbeddedVector<char, 64> buffer; |
| 2935 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); | 2933 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2978 | 2976 |
| 2979 | 2977 |
| 2980 static void AddPropertyTo( | 2978 static void AddPropertyTo( |
| 2981 int gc_count, Handle<JSObject> object, const char* property_name) { | 2979 int gc_count, Handle<JSObject> object, const char* property_name) { |
| 2982 Isolate* isolate = CcTest::i_isolate(); | 2980 Isolate* isolate = CcTest::i_isolate(); |
| 2983 Factory* factory = isolate->factory(); | 2981 Factory* factory = isolate->factory(); |
| 2984 Handle<String> prop_name = factory->InternalizeUtf8String(property_name); | 2982 Handle<String> prop_name = factory->InternalizeUtf8String(property_name); |
| 2985 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 2983 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
| 2986 i::FLAG_gc_interval = gc_count; | 2984 i::FLAG_gc_interval = gc_count; |
| 2987 i::FLAG_gc_global = true; | 2985 i::FLAG_gc_global = true; |
| 2988 i::FLAG_retain_maps_for_n_gc = 0; | |
| 2989 CcTest::heap()->set_allocation_timeout(gc_count); | 2986 CcTest::heap()->set_allocation_timeout(gc_count); |
| 2990 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check(); | 2987 JSReceiver::SetProperty(object, prop_name, twenty_three, SLOPPY).Check(); |
| 2991 } | 2988 } |
| 2992 | 2989 |
| 2993 | 2990 |
| 2994 TEST(TransitionArrayShrinksDuringAllocToZero) { | 2991 TEST(TransitionArrayShrinksDuringAllocToZero) { |
| 2995 i::FLAG_stress_compaction = false; | 2992 i::FLAG_stress_compaction = false; |
| 2996 i::FLAG_allow_natives_syntax = true; | 2993 i::FLAG_allow_natives_syntax = true; |
| 2997 CcTest::InitializeVM(); | 2994 CcTest::InitializeVM(); |
| 2998 v8::HandleScope scope(CcTest::isolate()); | 2995 v8::HandleScope scope(CcTest::isolate()); |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4195 Handle<JSFunction> bar_handle = | 4192 Handle<JSFunction> bar_handle = |
| 4196 v8::Utils::OpenHandle( | 4193 v8::Utils::OpenHandle( |
| 4197 *v8::Handle<v8::Function>::Cast( | 4194 *v8::Handle<v8::Function>::Cast( |
| 4198 CcTest::global()->Get(v8_str("bar")))); | 4195 CcTest::global()->Get(v8_str("bar")))); |
| 4199 CHECK_EQ(bar_handle->code(), function_bar); | 4196 CHECK_EQ(bar_handle->code(), function_bar); |
| 4200 } | 4197 } |
| 4201 | 4198 |
| 4202 // Now make sure that a gc should get rid of the function, even though we | 4199 // Now make sure that a gc should get rid of the function, even though we |
| 4203 // still have the allocation site alive. | 4200 // still have the allocation site alive. |
| 4204 for (int i = 0; i < 4; i++) { | 4201 for (int i = 0; i < 4; i++) { |
| 4205 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 4202 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 4206 } | 4203 } |
| 4207 | 4204 |
| 4208 // The site still exists because of our global handle, but the code is no | 4205 // The site still exists because of our global handle, but the code is no |
| 4209 // longer referred to by dependent_code(). | 4206 // longer referred to by dependent_code(). |
| 4210 DependentCode::GroupStartIndexes starts(site->dependent_code()); | 4207 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
| 4211 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); | 4208 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
| 4212 CHECK(!(site->dependent_code()->is_code_at(index))); | 4209 CHECK(!(site->dependent_code()->is_code_at(index))); |
| 4213 } | 4210 } |
| 4214 | 4211 |
| 4215 | 4212 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4296 DCHECK(code->marked_for_deoptimization()); | 4293 DCHECK(code->marked_for_deoptimization()); |
| 4297 } | 4294 } |
| 4298 | 4295 |
| 4299 | 4296 |
| 4300 TEST(NoWeakHashTableLeakWithIncrementalMarking) { | 4297 TEST(NoWeakHashTableLeakWithIncrementalMarking) { |
| 4301 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; | 4298 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
| 4302 if (!i::FLAG_incremental_marking) return; | 4299 if (!i::FLAG_incremental_marking) return; |
| 4303 i::FLAG_weak_embedded_objects_in_optimized_code = true; | 4300 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
| 4304 i::FLAG_allow_natives_syntax = true; | 4301 i::FLAG_allow_natives_syntax = true; |
| 4305 i::FLAG_compilation_cache = false; | 4302 i::FLAG_compilation_cache = false; |
| 4306 i::FLAG_retain_maps_for_n_gc = 0; | |
| 4307 CcTest::InitializeVM(); | 4303 CcTest::InitializeVM(); |
| 4308 Isolate* isolate = CcTest::i_isolate(); | 4304 Isolate* isolate = CcTest::i_isolate(); |
| 4309 v8::internal::Heap* heap = CcTest::heap(); | 4305 v8::internal::Heap* heap = CcTest::heap(); |
| 4310 | 4306 |
| 4311 if (!isolate->use_crankshaft()) return; | 4307 if (!isolate->use_crankshaft()) return; |
| 4312 HandleScope outer_scope(heap->isolate()); | 4308 HandleScope outer_scope(heap->isolate()); |
| 4313 for (int i = 0; i < 3; i++) { | 4309 for (int i = 0; i < 3; i++) { |
| 4314 SimulateIncrementalMarking(heap); | 4310 SimulateIncrementalMarking(heap); |
| 4315 { | 4311 { |
| 4316 LocalContext context; | 4312 LocalContext context; |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5086 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); | 5082 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); |
| 5087 Handle<JSArray> array = factory->NewJSArray(2); | 5083 Handle<JSArray> array = factory->NewJSArray(2); |
| 5088 | 5084 |
| 5089 Handle<String> name = factory->InternalizeUtf8String("testArray"); | 5085 Handle<String> name = factory->InternalizeUtf8String("testArray"); |
| 5090 JSReceiver::SetProperty(global, name, array, SLOPPY).Check(); | 5086 JSReceiver::SetProperty(global, name, array, SLOPPY).Check(); |
| 5091 CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();"); | 5087 CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();"); |
| 5092 heap->CollectGarbage(OLD_POINTER_SPACE); | 5088 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 5093 } | 5089 } |
| 5094 | 5090 |
| 5095 | 5091 |
| 5096 void CheckMapRetainingFor(int n) { | |
| 5097 FLAG_retain_maps_for_n_gc = n; | |
| 5098 Isolate* isolate = CcTest::i_isolate(); | |
| 5099 Heap* heap = isolate->heap(); | |
| 5100 Handle<WeakCell> weak_cell; | |
| 5101 { | |
| 5102 HandleScope inner_scope(isolate); | |
| 5103 Handle<Map> map = Map::Create(isolate, 1); | |
| 5104 weak_cell = inner_scope.CloseAndEscape(Map::WeakCellForMap(map)); | |
| 5105 } | |
| 5106 CHECK(!weak_cell->cleared()); | |
| 5107 int retaining_count = | |
| 5108 Min(FLAG_retain_maps_for_n_gc, | |
| 5109 Map::kRetainingCounterStart - Map::kRetainingCounterEnd); | |
| 5110 for (int i = 0; i < retaining_count; i++) { | |
| 5111 heap->CollectGarbage(OLD_POINTER_SPACE); | |
| 5112 } | |
| 5113 CHECK(!weak_cell->cleared()); | |
| 5114 heap->CollectGarbage(OLD_POINTER_SPACE); | |
| 5115 CHECK(weak_cell->cleared()); | |
| 5116 } | |
| 5117 | |
| 5118 | |
| 5119 TEST(MapRetaining) { | |
| 5120 CcTest::InitializeVM(); | |
| 5121 v8::HandleScope scope(CcTest::isolate()); | |
| 5122 CheckMapRetainingFor(FLAG_retain_maps_for_n_gc); | |
| 5123 CheckMapRetainingFor(0); | |
| 5124 CheckMapRetainingFor(Map::kRetainingCounterStart - Map::kRetainingCounterEnd); | |
| 5125 CheckMapRetainingFor(Map::kRetainingCounterStart - Map::kRetainingCounterEnd + | |
| 5126 1); | |
| 5127 } | |
| 5128 | |
| 5129 | |
| 5130 #ifdef DEBUG | 5092 #ifdef DEBUG |
| 5131 TEST(PathTracer) { | 5093 TEST(PathTracer) { |
| 5132 CcTest::InitializeVM(); | 5094 CcTest::InitializeVM(); |
| 5133 v8::HandleScope scope(CcTest::isolate()); | 5095 v8::HandleScope scope(CcTest::isolate()); |
| 5134 | 5096 |
| 5135 v8::Local<v8::Value> result = CompileRun("'abc'"); | 5097 v8::Local<v8::Value> result = CompileRun("'abc'"); |
| 5136 Handle<Object> o = v8::Utils::OpenHandle(*result); | 5098 Handle<Object> o = v8::Utils::OpenHandle(*result); |
| 5137 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 5099 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
| 5138 } | 5100 } |
| 5139 #endif // DEBUG | 5101 #endif // DEBUG |
| OLD | NEW |