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 3531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3542 CompileRun("run()"); | 3542 CompileRun("run()"); |
3543 | 3543 |
3544 // Run test with inline allocation disabled and pretenuring. | 3544 // Run test with inline allocation disabled and pretenuring. |
3545 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); | 3545 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); |
3546 CompileRun("run()"); | 3546 CompileRun("run()"); |
3547 | 3547 |
3548 // Run test with inline allocation re-enabled. | 3548 // Run test with inline allocation re-enabled. |
3549 CcTest::heap()->EnableInlineAllocation(); | 3549 CcTest::heap()->EnableInlineAllocation(); |
3550 CompileRun("run()"); | 3550 CompileRun("run()"); |
3551 } | 3551 } |
| 3552 |
| 3553 |
| 3554 static int AllocationSitesCount(Heap* heap) { |
| 3555 int count = 0; |
| 3556 for (Object* site = heap->allocation_sites_list(); |
| 3557 !(site->IsUndefined()); |
| 3558 site = AllocationSite::cast(site)->weak_next()) { |
| 3559 count++; |
| 3560 } |
| 3561 return count; |
| 3562 } |
| 3563 |
| 3564 |
| 3565 TEST(EnsureAllocationSiteDependentCodesProcessed) { |
| 3566 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
| 3567 i::FLAG_allow_natives_syntax = true; |
| 3568 CcTest::InitializeVM(); |
| 3569 Isolate* isolate = CcTest::i_isolate(); |
| 3570 v8::internal::Heap* heap = CcTest::heap(); |
| 3571 GlobalHandles* global_handles = isolate->global_handles(); |
| 3572 |
| 3573 // The allocation site at the head of the list is ours. |
| 3574 Handle<AllocationSite> site; |
| 3575 { |
| 3576 LocalContext context; |
| 3577 v8::HandleScope scope(context->GetIsolate()); |
| 3578 |
| 3579 int count = AllocationSitesCount(heap); |
| 3580 CompileRun("var bar = function() { return (new Array()); };" |
| 3581 "var a = bar();" |
| 3582 "bar();" |
| 3583 "bar();"); |
| 3584 |
| 3585 // One allocation site should have been created. |
| 3586 int new_count = AllocationSitesCount(heap); |
| 3587 ASSERT(new_count == (count + 1)); |
| 3588 site = Handle<AllocationSite>::cast( |
| 3589 global_handles->Create( |
| 3590 AllocationSite::cast(heap->allocation_sites_list()))); |
| 3591 |
| 3592 CompileRun("%OptimizeFunctionOnNextCall(bar); bar();"); |
| 3593 |
| 3594 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
| 3595 ASSERT(starts.number_of_entries() >= 1); |
| 3596 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
| 3597 ASSERT(site->dependent_code()->is_code_at(index)); |
| 3598 Code* function_bar = site->dependent_code()->code_at(index); |
| 3599 Handle<JSFunction> bar_handle = |
| 3600 v8::Utils::OpenHandle( |
| 3601 *v8::Handle<v8::Function>::Cast( |
| 3602 CcTest::global()->Get(v8_str("bar")))); |
| 3603 ASSERT(bar_handle->code() == function_bar); |
| 3604 } |
| 3605 |
| 3606 // Now make sure that a gc should get rid of the function, even though we |
| 3607 // still have the allocation site alive. |
| 3608 for (int i = 0; i < 4; i++) { |
| 3609 heap->CollectAllGarbage(false); |
| 3610 } |
| 3611 |
| 3612 // The site still exists because of our global handle, but the code is no |
| 3613 // longer referred to by dependent_code(). |
| 3614 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
| 3615 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
| 3616 ASSERT(!(site->dependent_code()->is_code_at(index))); |
| 3617 } |
OLD | NEW |