| 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include <utility> | 29 #include <utility> |
| 30 | 30 |
| 31 #include "src/v8.h" | 31 #include "src/v8.h" |
| 32 | 32 |
| 33 #include "src/compilation-cache.h" | 33 #include "src/compilation-cache.h" |
| 34 #include "src/deoptimizer.h" |
| 34 #include "src/execution.h" | 35 #include "src/execution.h" |
| 35 #include "src/factory.h" | 36 #include "src/factory.h" |
| 36 #include "src/global-handles.h" | 37 #include "src/global-handles.h" |
| 37 #include "src/ic/ic.h" | 38 #include "src/ic/ic.h" |
| 38 #include "src/macro-assembler.h" | 39 #include "src/macro-assembler.h" |
| 39 #include "test/cctest/cctest.h" | 40 #include "test/cctest/cctest.h" |
| 40 | 41 |
| 41 using namespace v8::internal; | 42 using namespace v8::internal; |
| 42 | 43 |
| 43 static void CheckMap(Map* map, int type, int instance_size) { | 44 static void CheckMap(Map* map, int type, int instance_size) { |
| (...skipping 4557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4601 marking->Abort(); | 4602 marking->Abort(); |
| 4602 marking->Start(); | 4603 marking->Start(); |
| 4603 CHECK(marking->IsMarking()); | 4604 CHECK(marking->IsMarking()); |
| 4604 | 4605 |
| 4605 // Now everything is set up for crashing in JSObject::MigrateFastToFast() | 4606 // Now everything is set up for crashing in JSObject::MigrateFastToFast() |
| 4606 // when it calls heap->AdjustLiveBytes(...). | 4607 // when it calls heap->AdjustLiveBytes(...). |
| 4607 JSObject::MigrateToMap(o, map2); | 4608 JSObject::MigrateToMap(o, map2); |
| 4608 } | 4609 } |
| 4609 | 4610 |
| 4610 | 4611 |
| 4612 TEST(ConstantPoolICUpdateDeopt) { |
| 4613 i::FLAG_allow_natives_syntax = true; |
| 4614 #ifdef VERIFY_HEAP |
| 4615 i::FLAG_verify_heap = true; |
| 4616 #endif |
| 4617 |
| 4618 CcTest::InitializeVM(); |
| 4619 if (!CcTest::i_isolate()->use_crankshaft()) return; |
| 4620 if (i::FLAG_force_marking_deque_overflows) return; |
| 4621 v8::HandleScope outer_scope(CcTest::isolate()); |
| 4622 |
| 4623 { |
| 4624 v8::HandleScope scope(CcTest::isolate()); |
| 4625 CompileRun( |
| 4626 "function f(o) { return o.x; }" |
| 4627 // Call the function with different classes |
| 4628 // to force Crankshaft to generate LoadIC. |
| 4629 "f({a1 : 1});" |
| 4630 "f({a2 : 1});" |
| 4631 "f({a3 : 1});" |
| 4632 "f({a4 : 1});" |
| 4633 "f({a5 : 1});" |
| 4634 "f({a6 : 1});" |
| 4635 "f({a7 : 1});" |
| 4636 "f({a8 : 1});" |
| 4637 "f({a9 : 1});" |
| 4638 "f({a0 : 1});" |
| 4639 // Optimize the function with LoadIC. |
| 4640 "%OptimizeFunctionOnNextCall(f);" |
| 4641 "function g() { f({x : 1}); }" |
| 4642 "g();"); |
| 4643 } |
| 4644 |
| 4645 SimulateIncrementalMarking(CcTest::heap()); |
| 4646 // On ARM, this marks function f, its constant pool and the (pre-monomorphic) |
| 4647 // IC inside it. |
| 4648 |
| 4649 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 4650 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 4651 |
| 4652 // Code* ic_before = FindFirstIC(f->code(), Code::LOAD_IC); |
| 4653 // printf("Marked code: %i\n", |
| 4654 // Marking::IsBlack(Marking::MarkBitFrom(f->code()))); |
| 4655 // printf("Marked IC: %i\n", |
| 4656 // Marking::IsBlack(Marking::MarkBitFrom(ic_before))); |
| 4657 // printf("Marked CP: %i\n", |
| 4658 // Marking::IsBlack(Marking::MarkBitFrom(f->code()->constant_pool()))); |
| 4659 |
| 4660 // Call the function g to transition the IC to monomorphic. |
| 4661 v8::Handle<v8::Function> g = |
| 4662 v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("g"))); |
| 4663 g->Call(CcTest::global(), 0, NULL); |
| 4664 |
| 4665 // Now we have the marked (black) constant pool pointing to an unmarked |
| 4666 // (white) IC. However, the code for function f goes gray and it will |
| 4667 // be visited again. |
| 4668 |
| 4669 // Code* ic_after = FindFirstIC(f->code(), Code::LOAD_IC); |
| 4670 // printf("IC 0x%x white: %i\n", (int)ic_after, |
| 4671 // Marking::IsWhite(Marking::MarkBitFrom(ic_after))); |
| 4672 // printf("CP black: %i\n", |
| 4673 // Marking::IsBlack(Marking::MarkBitFrom(f->code()->constant_pool()))); |
| 4674 // f->code()->constant_pool()->Print(); |
| 4675 |
| 4676 // Invoke lazy deoptimization on f. This will invalidate the relocation table |
| 4677 // of f's code. As a result, marking of f will not mark the IC (since the |
| 4678 // relocation info no longer refers to the IC. |
| 4679 Deoptimizer::DeoptimizeFunction(*f); |
| 4680 |
| 4681 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
| 4682 } |
| 4683 |
| 4684 |
| 4611 #ifdef DEBUG | 4685 #ifdef DEBUG |
| 4612 TEST(PathTracer) { | 4686 TEST(PathTracer) { |
| 4613 CcTest::InitializeVM(); | 4687 CcTest::InitializeVM(); |
| 4614 v8::HandleScope scope(CcTest::isolate()); | 4688 v8::HandleScope scope(CcTest::isolate()); |
| 4615 | 4689 |
| 4616 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4690 v8::Local<v8::Value> result = CompileRun("'abc'"); |
| 4617 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4691 Handle<Object> o = v8::Utils::OpenHandle(*result); |
| 4618 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4692 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
| 4619 } | 4693 } |
| 4620 #endif // DEBUG | 4694 #endif // DEBUG |
| OLD | NEW |