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 4538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4549 heap->set_allocation_timeout(5); | 4549 heap->set_allocation_timeout(5); |
4550 FLAG_gc_interval = 1000; | 4550 FLAG_gc_interval = 1000; |
4551 for (int i = 0; i < 10; ++i) { | 4551 for (int i = 0; i < 10; ++i) { |
4552 BailoutId id = BailoutId(i); | 4552 BailoutId id = BailoutId(i); |
4553 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); | 4553 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); |
4554 } | 4554 } |
4555 } | 4555 } |
4556 #endif // DEBUG | 4556 #endif // DEBUG |
4557 | 4557 |
4558 | 4558 |
| 4559 TEST(Regress514122) { |
| 4560 i::FLAG_flush_optimized_code_cache = false; |
| 4561 i::FLAG_allow_natives_syntax = true; |
| 4562 CcTest::InitializeVM(); |
| 4563 Isolate* isolate = CcTest::i_isolate(); |
| 4564 Heap* heap = isolate->heap(); |
| 4565 HandleScope scope(isolate); |
| 4566 |
| 4567 // Perfrom one initial GC to enable code flushing. |
| 4568 CcTest::heap()->CollectAllGarbage(); |
| 4569 |
| 4570 // Prepare function whose optimized code map we can use. |
| 4571 Handle<SharedFunctionInfo> shared; |
| 4572 { |
| 4573 HandleScope inner_scope(isolate); |
| 4574 CompileRun("function f() { return 1 }" |
| 4575 "f(); %OptimizeFunctionOnNextCall(f); f();"); |
| 4576 |
| 4577 Handle<JSFunction> f = |
| 4578 v8::Utils::OpenHandle( |
| 4579 *v8::Handle<v8::Function>::Cast( |
| 4580 CcTest::global()->Get(v8_str("f")))); |
| 4581 shared = inner_scope.CloseAndEscape(handle(f->shared(), isolate)); |
| 4582 CompileRun("f = null"); |
| 4583 } |
| 4584 |
| 4585 // Prepare optimized code that we can use. |
| 4586 Handle<Code> code; |
| 4587 { |
| 4588 HandleScope inner_scope(isolate); |
| 4589 CompileRun("function g() { return 2 }" |
| 4590 "g(); %OptimizeFunctionOnNextCall(g); g();"); |
| 4591 |
| 4592 Handle<JSFunction> g = |
| 4593 v8::Utils::OpenHandle( |
| 4594 *v8::Handle<v8::Function>::Cast( |
| 4595 CcTest::global()->Get(v8_str("g")))); |
| 4596 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); |
| 4597 if (!code->is_optimized_code()) return; |
| 4598 } |
| 4599 |
| 4600 Handle<FixedArray> lit = isolate->factory()->empty_fixed_array(); |
| 4601 Handle<Context> context(isolate->context()); |
| 4602 |
| 4603 // Add the code several times to the optimized code map. |
| 4604 for (int i = 0; i < 3; ++i) { |
| 4605 HandleScope inner_scope(isolate); |
| 4606 BailoutId id = BailoutId(i); |
| 4607 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); |
| 4608 } |
| 4609 shared->optimized_code_map()->Print(); |
| 4610 |
| 4611 // Add the code with a literals array to be evacuated. |
| 4612 Page* evac_page; |
| 4613 { |
| 4614 HandleScope inner_scope(isolate); |
| 4615 AlwaysAllocateScope always_allocate(isolate); |
| 4616 // Make sure literal is placed on an old-space evacuation candidate. |
| 4617 SimulateFullSpace(heap->old_space()); |
| 4618 Handle<FixedArray> lit = isolate->factory()->NewFixedArray(23, TENURED); |
| 4619 evac_page = Page::FromAddress(lit->address()); |
| 4620 BailoutId id = BailoutId(100); |
| 4621 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); |
| 4622 } |
| 4623 |
| 4624 // Heap is ready, force {lit_page} to become an evacuation candidate and |
| 4625 // simulate incremental marking to enqueue optimized code map. |
| 4626 FLAG_manual_evacuation_candidates_selection = true; |
| 4627 evac_page->SetFlag(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING); |
| 4628 SimulateIncrementalMarking(heap); |
| 4629 |
| 4630 // No matter whether reachable or not, {boomer} is doomed. |
| 4631 Handle<Object> boomer(shared->optimized_code_map(), isolate); |
| 4632 |
| 4633 // Add the code several times to the optimized code map. This will leave old |
| 4634 // copies of the optimized code map unreachable but still marked. |
| 4635 for (int i = 3; i < 6; ++i) { |
| 4636 HandleScope inner_scope(isolate); |
| 4637 BailoutId id = BailoutId(i); |
| 4638 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); |
| 4639 } |
| 4640 |
| 4641 // Trigger a GC to flush out the bug. |
| 4642 heap->CollectGarbage(i::OLD_SPACE, "fire in the hole"); |
| 4643 boomer->Print(); |
| 4644 } |
| 4645 |
| 4646 |
4559 class DummyVisitor : public ObjectVisitor { | 4647 class DummyVisitor : public ObjectVisitor { |
4560 public: | 4648 public: |
4561 void VisitPointers(Object** start, Object** end) { } | 4649 void VisitPointers(Object** start, Object** end) { } |
4562 }; | 4650 }; |
4563 | 4651 |
4564 | 4652 |
4565 TEST(DeferredHandles) { | 4653 TEST(DeferredHandles) { |
4566 CcTest::InitializeVM(); | 4654 CcTest::InitializeVM(); |
4567 Isolate* isolate = CcTest::i_isolate(); | 4655 Isolate* isolate = CcTest::i_isolate(); |
4568 Heap* heap = isolate->heap(); | 4656 Heap* heap = isolate->heap(); |
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6261 array->address(), | 6349 array->address(), |
6262 array->address() + array->Size()); | 6350 array->address() + array->Size()); |
6263 CHECK(reinterpret_cast<void*>(buffer->Get(1)) == | 6351 CHECK(reinterpret_cast<void*>(buffer->Get(1)) == |
6264 HeapObject::RawField(heap->empty_fixed_array(), | 6352 HeapObject::RawField(heap->empty_fixed_array(), |
6265 FixedArrayBase::kLengthOffset)); | 6353 FixedArrayBase::kLengthOffset)); |
6266 CHECK(reinterpret_cast<void*>(buffer->Get(2)) == | 6354 CHECK(reinterpret_cast<void*>(buffer->Get(2)) == |
6267 HeapObject::RawField(heap->empty_fixed_array(), | 6355 HeapObject::RawField(heap->empty_fixed_array(), |
6268 FixedArrayBase::kLengthOffset)); | 6356 FixedArrayBase::kLengthOffset)); |
6269 delete buffer; | 6357 delete buffer; |
6270 } | 6358 } |
OLD | NEW |