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 3389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3400 Handle<TypeFeedbackVector> vector = | 3400 Handle<TypeFeedbackVector> vector = |
3401 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); | 3401 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
3402 FeedbackVectorICSlot slot(ic_slot_index); | 3402 FeedbackVectorICSlot slot(ic_slot_index); |
3403 LoadICNexus nexus(vector, slot); | 3403 LoadICNexus nexus(vector, slot); |
3404 CHECK(IC::IsCleared(&nexus)); | 3404 CHECK(IC::IsCleared(&nexus)); |
3405 } | 3405 } |
3406 | 3406 |
3407 | 3407 |
3408 TEST(IncrementalMarkingPreservesMonomorphicIC) { | 3408 TEST(IncrementalMarkingPreservesMonomorphicIC) { |
3409 if (i::FLAG_always_opt) return; | 3409 if (i::FLAG_always_opt) return; |
3410 // TODO(mvstanton): vector-ics need to treat maps weakly. | |
3411 if (i::FLAG_vector_ics) return; | |
3412 CcTest::InitializeVM(); | 3410 CcTest::InitializeVM(); |
3413 v8::HandleScope scope(CcTest::isolate()); | 3411 v8::HandleScope scope(CcTest::isolate()); |
3414 | 3412 |
3415 // Prepare function f that contains a monomorphic IC for object | 3413 // Prepare function f that contains a monomorphic IC for object |
3416 // originating from the same native context. | 3414 // originating from the same native context. |
3417 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3415 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
3418 "function f(o) { return o.x; } f(obj); f(obj);"); | 3416 "function f(o) { return o.x; } f(obj); f(obj);"); |
3419 Handle<JSFunction> f = | 3417 Handle<JSFunction> f = |
3420 v8::Utils::OpenHandle( | 3418 v8::Utils::OpenHandle( |
3421 *v8::Handle<v8::Function>::Cast( | 3419 *v8::Handle<v8::Function>::Cast( |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3799 // Make a new closure that will get code installed from the code map. | 3797 // Make a new closure that will get code installed from the code map. |
3800 // Unoptimized code is missing and the deoptimizer will go ballistic. | 3798 // Unoptimized code is missing and the deoptimizer will go ballistic. |
3801 CompileRun("var g = mkClosure(); g('bozo');"); | 3799 CompileRun("var g = mkClosure(); g('bozo');"); |
3802 } | 3800 } |
3803 | 3801 |
3804 | 3802 |
3805 TEST(Regress169209) { | 3803 TEST(Regress169209) { |
3806 i::FLAG_stress_compaction = false; | 3804 i::FLAG_stress_compaction = false; |
3807 i::FLAG_allow_natives_syntax = true; | 3805 i::FLAG_allow_natives_syntax = true; |
3808 i::FLAG_flush_code_incrementally = true; | 3806 i::FLAG_flush_code_incrementally = true; |
3809 // TODO(mvstanton): vector ics need weak support. | |
3810 if (i::FLAG_vector_ics) return; | |
3811 | 3807 |
3812 CcTest::InitializeVM(); | 3808 CcTest::InitializeVM(); |
3813 Isolate* isolate = CcTest::i_isolate(); | 3809 Isolate* isolate = CcTest::i_isolate(); |
3814 Heap* heap = isolate->heap(); | 3810 Heap* heap = isolate->heap(); |
3815 HandleScope scope(isolate); | 3811 HandleScope scope(isolate); |
3816 | 3812 |
3817 // Perform one initial GC to enable code flushing. | 3813 // Perform one initial GC to enable code flushing. |
3818 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3814 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
3819 | 3815 |
3820 // Prepare a shared function info eligible for code flushing for which | 3816 // Prepare a shared function info eligible for code flushing for which |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4154 for (Object* site = heap->allocation_sites_list(); | 4150 for (Object* site = heap->allocation_sites_list(); |
4155 !(site->IsUndefined()); | 4151 !(site->IsUndefined()); |
4156 site = AllocationSite::cast(site)->weak_next()) { | 4152 site = AllocationSite::cast(site)->weak_next()) { |
4157 count++; | 4153 count++; |
4158 } | 4154 } |
4159 return count; | 4155 return count; |
4160 } | 4156 } |
4161 | 4157 |
4162 | 4158 |
4163 TEST(EnsureAllocationSiteDependentCodesProcessed) { | 4159 TEST(EnsureAllocationSiteDependentCodesProcessed) { |
4164 // TODO(mvstanton): vector ics need weak support! | |
4165 if (FLAG_vector_ics) return; | |
4166 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; | 4160 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
4167 i::FLAG_allow_natives_syntax = true; | 4161 i::FLAG_allow_natives_syntax = true; |
4168 CcTest::InitializeVM(); | 4162 CcTest::InitializeVM(); |
4169 Isolate* isolate = CcTest::i_isolate(); | 4163 Isolate* isolate = CcTest::i_isolate(); |
4170 v8::internal::Heap* heap = CcTest::heap(); | 4164 v8::internal::Heap* heap = CcTest::heap(); |
4171 GlobalHandles* global_handles = isolate->global_handles(); | 4165 GlobalHandles* global_handles = isolate->global_handles(); |
4172 | 4166 |
4173 if (!isolate->use_crankshaft()) return; | 4167 if (!isolate->use_crankshaft()) return; |
4174 | 4168 |
4175 // The allocation site at the head of the list is ours. | 4169 // The allocation site at the head of the list is ours. |
(...skipping 28 matching lines...) Expand all Loading... |
4204 CcTest::global()->Get(v8_str("bar")))); | 4198 CcTest::global()->Get(v8_str("bar")))); |
4205 CHECK_EQ(bar_handle->code(), function_bar); | 4199 CHECK_EQ(bar_handle->code(), function_bar); |
4206 } | 4200 } |
4207 | 4201 |
4208 // Now make sure that a gc should get rid of the function, even though we | 4202 // Now make sure that a gc should get rid of the function, even though we |
4209 // still have the allocation site alive. | 4203 // still have the allocation site alive. |
4210 for (int i = 0; i < 4; i++) { | 4204 for (int i = 0; i < 4; i++) { |
4211 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 4205 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
4212 } | 4206 } |
4213 | 4207 |
4214 // TODO(mvstanton): this test fails when FLAG_vector_ics is true because | |
4215 // monomorphic load ics are preserved, but also strongly walked. They | |
4216 // end up keeping function bar alive. | |
4217 | |
4218 // The site still exists because of our global handle, but the code is no | 4208 // The site still exists because of our global handle, but the code is no |
4219 // longer referred to by dependent_code(). | 4209 // longer referred to by dependent_code(). |
4220 DependentCode::GroupStartIndexes starts(site->dependent_code()); | 4210 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
4221 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); | 4211 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
4222 CHECK(!(site->dependent_code()->is_code_at(index))); | 4212 CHECK(!(site->dependent_code()->is_code_at(index))); |
4223 } | 4213 } |
4224 | 4214 |
4225 | 4215 |
4226 TEST(CellsInOptimizedCodeAreWeak) { | 4216 TEST(CellsInOptimizedCodeAreWeak) { |
4227 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; | 4217 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
4228 // TODO(mvstanton): vector-ics need to treat maps weakly. | |
4229 if (i::FLAG_vector_ics) return; | |
4230 i::FLAG_weak_embedded_objects_in_optimized_code = true; | 4218 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
4231 i::FLAG_allow_natives_syntax = true; | 4219 i::FLAG_allow_natives_syntax = true; |
4232 CcTest::InitializeVM(); | 4220 CcTest::InitializeVM(); |
4233 Isolate* isolate = CcTest::i_isolate(); | 4221 Isolate* isolate = CcTest::i_isolate(); |
4234 v8::internal::Heap* heap = CcTest::heap(); | 4222 v8::internal::Heap* heap = CcTest::heap(); |
4235 | 4223 |
4236 if (!isolate->use_crankshaft()) return; | 4224 if (!isolate->use_crankshaft()) return; |
4237 HandleScope outer_scope(heap->isolate()); | 4225 HandleScope outer_scope(heap->isolate()); |
4238 Handle<Code> code; | 4226 Handle<Code> code; |
4239 { | 4227 { |
(...skipping 22 matching lines...) Expand all Loading... |
4262 // Now make sure that a gc should get rid of the function | 4250 // Now make sure that a gc should get rid of the function |
4263 for (int i = 0; i < 4; i++) { | 4251 for (int i = 0; i < 4; i++) { |
4264 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 4252 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
4265 } | 4253 } |
4266 | 4254 |
4267 DCHECK(code->marked_for_deoptimization()); | 4255 DCHECK(code->marked_for_deoptimization()); |
4268 } | 4256 } |
4269 | 4257 |
4270 | 4258 |
4271 TEST(ObjectsInOptimizedCodeAreWeak) { | 4259 TEST(ObjectsInOptimizedCodeAreWeak) { |
4272 // TODO(mvstanton): vector ics need weak support! | |
4273 if (FLAG_vector_ics) return; | |
4274 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; | 4260 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
4275 i::FLAG_weak_embedded_objects_in_optimized_code = true; | 4261 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
4276 i::FLAG_allow_natives_syntax = true; | 4262 i::FLAG_allow_natives_syntax = true; |
4277 CcTest::InitializeVM(); | 4263 CcTest::InitializeVM(); |
4278 Isolate* isolate = CcTest::i_isolate(); | 4264 Isolate* isolate = CcTest::i_isolate(); |
4279 v8::internal::Heap* heap = CcTest::heap(); | 4265 v8::internal::Heap* heap = CcTest::heap(); |
4280 | 4266 |
4281 if (!isolate->use_crankshaft()) return; | 4267 if (!isolate->use_crankshaft()) return; |
4282 HandleScope outer_scope(heap->isolate()); | 4268 HandleScope outer_scope(heap->isolate()); |
4283 Handle<Code> code; | 4269 Handle<Code> code; |
(...skipping 23 matching lines...) Expand all Loading... |
4307 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 4293 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
4308 } | 4294 } |
4309 | 4295 |
4310 DCHECK(code->marked_for_deoptimization()); | 4296 DCHECK(code->marked_for_deoptimization()); |
4311 } | 4297 } |
4312 | 4298 |
4313 | 4299 |
4314 TEST(NoWeakHashTableLeakWithIncrementalMarking) { | 4300 TEST(NoWeakHashTableLeakWithIncrementalMarking) { |
4315 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; | 4301 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
4316 if (!i::FLAG_incremental_marking) return; | 4302 if (!i::FLAG_incremental_marking) return; |
4317 // TODO(mvstanton): vector ics need weak support. | |
4318 if (FLAG_vector_ics) return; | |
4319 i::FLAG_weak_embedded_objects_in_optimized_code = true; | 4303 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
4320 i::FLAG_allow_natives_syntax = true; | 4304 i::FLAG_allow_natives_syntax = true; |
4321 i::FLAG_compilation_cache = false; | 4305 i::FLAG_compilation_cache = false; |
4322 i::FLAG_retain_maps_for_n_gc = 0; | 4306 i::FLAG_retain_maps_for_n_gc = 0; |
4323 CcTest::InitializeVM(); | 4307 CcTest::InitializeVM(); |
4324 Isolate* isolate = CcTest::i_isolate(); | 4308 Isolate* isolate = CcTest::i_isolate(); |
4325 v8::internal::Heap* heap = CcTest::heap(); | 4309 v8::internal::Heap* heap = CcTest::heap(); |
4326 | 4310 |
4327 if (!isolate->use_crankshaft()) return; | 4311 if (!isolate->use_crankshaft()) return; |
4328 HandleScope outer_scope(heap->isolate()); | 4312 HandleScope outer_scope(heap->isolate()); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4480 garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC); | 4464 garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC); |
4481 Heap* heap = CcTest::i_isolate()->heap(); | 4465 Heap* heap = CcTest::i_isolate()->heap(); |
4482 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 4466 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
4483 CHECK(weak_ic_cleared); | 4467 CHECK(weak_ic_cleared); |
4484 } | 4468 } |
4485 | 4469 |
4486 | 4470 |
4487 // Each of the following "weak IC" tests creates an IC that embeds a map with | 4471 // Each of the following "weak IC" tests creates an IC that embeds a map with |
4488 // the prototype pointing to _proto_ and checks that the _proto_ dies on GC. | 4472 // the prototype pointing to _proto_ and checks that the _proto_ dies on GC. |
4489 TEST(WeakMapInMonomorphicLoadIC) { | 4473 TEST(WeakMapInMonomorphicLoadIC) { |
4490 // TODO(mvstanton): vector ics need weak support! | |
4491 if (FLAG_vector_ics) return; | |
4492 CheckWeakness("function loadIC(obj) {" | 4474 CheckWeakness("function loadIC(obj) {" |
4493 " return obj.name;" | 4475 " return obj.name;" |
4494 "}" | 4476 "}" |
4495 " (function() {" | 4477 " (function() {" |
4496 " var proto = {'name' : 'weak'};" | 4478 " var proto = {'name' : 'weak'};" |
4497 " var obj = Object.create(proto);" | 4479 " var obj = Object.create(proto);" |
4498 " loadIC(obj);" | 4480 " loadIC(obj);" |
4499 " loadIC(obj);" | 4481 " loadIC(obj);" |
4500 " loadIC(obj);" | 4482 " loadIC(obj);" |
4501 " return proto;" | 4483 " return proto;" |
4502 " })();"); | 4484 " })();"); |
4503 } | 4485 } |
4504 | 4486 |
4505 | 4487 |
4506 TEST(WeakMapInPolymorphicLoadIC) { | 4488 TEST(WeakMapInPolymorphicLoadIC) { |
4507 // TODO(mvstanton): vector-ics need to treat maps weakly. | |
4508 if (i::FLAG_vector_ics) return; | |
4509 CheckWeakness( | 4489 CheckWeakness( |
4510 "function loadIC(obj) {" | 4490 "function loadIC(obj) {" |
4511 " return obj.name;" | 4491 " return obj.name;" |
4512 "}" | 4492 "}" |
4513 " (function() {" | 4493 " (function() {" |
4514 " var proto = {'name' : 'weak'};" | 4494 " var proto = {'name' : 'weak'};" |
4515 " var obj = Object.create(proto);" | 4495 " var obj = Object.create(proto);" |
4516 " loadIC(obj);" | 4496 " loadIC(obj);" |
4517 " loadIC(obj);" | 4497 " loadIC(obj);" |
4518 " loadIC(obj);" | 4498 " loadIC(obj);" |
4519 " var poly = Object.create(proto);" | 4499 " var poly = Object.create(proto);" |
4520 " poly.x = true;" | 4500 " poly.x = true;" |
4521 " loadIC(poly);" | 4501 " loadIC(poly);" |
4522 " return proto;" | 4502 " return proto;" |
4523 " })();"); | 4503 " })();"); |
4524 } | 4504 } |
4525 | 4505 |
4526 | 4506 |
4527 TEST(WeakMapInMonomorphicKeyedLoadIC) { | 4507 TEST(WeakMapInMonomorphicKeyedLoadIC) { |
4528 // TODO(mvstanton): vector ics need weak support! | |
4529 if (FLAG_vector_ics) return; | |
4530 CheckWeakness("function keyedLoadIC(obj, field) {" | 4508 CheckWeakness("function keyedLoadIC(obj, field) {" |
4531 " return obj[field];" | 4509 " return obj[field];" |
4532 "}" | 4510 "}" |
4533 " (function() {" | 4511 " (function() {" |
4534 " var proto = {'name' : 'weak'};" | 4512 " var proto = {'name' : 'weak'};" |
4535 " var obj = Object.create(proto);" | 4513 " var obj = Object.create(proto);" |
4536 " keyedLoadIC(obj, 'name');" | 4514 " keyedLoadIC(obj, 'name');" |
4537 " keyedLoadIC(obj, 'name');" | 4515 " keyedLoadIC(obj, 'name');" |
4538 " keyedLoadIC(obj, 'name');" | 4516 " keyedLoadIC(obj, 'name');" |
4539 " return proto;" | 4517 " return proto;" |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5152 #ifdef DEBUG | 5130 #ifdef DEBUG |
5153 TEST(PathTracer) { | 5131 TEST(PathTracer) { |
5154 CcTest::InitializeVM(); | 5132 CcTest::InitializeVM(); |
5155 v8::HandleScope scope(CcTest::isolate()); | 5133 v8::HandleScope scope(CcTest::isolate()); |
5156 | 5134 |
5157 v8::Local<v8::Value> result = CompileRun("'abc'"); | 5135 v8::Local<v8::Value> result = CompileRun("'abc'"); |
5158 Handle<Object> o = v8::Utils::OpenHandle(*result); | 5136 Handle<Object> o = v8::Utils::OpenHandle(*result); |
5159 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 5137 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
5160 } | 5138 } |
5161 #endif // DEBUG | 5139 #endif // DEBUG |
OLD | NEW |