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 3670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3681 code = scope.CloseAndEscape(Handle<Code>(bar->code())); | 3681 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
3682 } | 3682 } |
3683 | 3683 |
3684 // Now make sure that a gc should get rid of the function | 3684 // Now make sure that a gc should get rid of the function |
3685 for (int i = 0; i < 4; i++) { | 3685 for (int i = 0; i < 4; i++) { |
3686 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3686 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
3687 } | 3687 } |
3688 | 3688 |
3689 ASSERT(code->marked_for_deoptimization()); | 3689 ASSERT(code->marked_for_deoptimization()); |
3690 } | 3690 } |
3691 | |
3692 | |
3693 static Handle<JSFunction> OptimizeDummyFunction(const char* name) { | |
3694 char source[256]; | |
3695 snprintf(source, sizeof(source), | |
3696 "function %s() { return 0; }" | |
3697 "%s(); %s();" | |
3698 "%%OptimizeFunctionOnNextCall(%s);" | |
3699 "%s();", name, name, name, name, name); | |
3700 CompileRun(source); | |
3701 Handle<JSFunction> fun = | |
3702 v8::Utils::OpenHandle( | |
3703 *v8::Handle<v8::Function>::Cast( | |
3704 CcTest::global()->Get(v8_str(name)))); | |
3705 return fun; | |
3706 } | |
3707 | |
3708 | |
3709 static int GetCodeChainLength(Code* code) { | |
3710 int result = 0; | |
3711 while (code->next_code_link()->IsCode()) { | |
3712 result++; | |
3713 code = Code::cast(code->next_code_link()); | |
3714 } | |
3715 return result; | |
3716 } | |
3717 | |
3718 | |
3719 TEST(NextCodeLinkIsWeak) { | |
titzer
2014/03/05 08:58:02
Why not make a test case that creates optimized co
ulan
2014/03/06 11:13:32
It assumes two things:
- next_code_link is used fo
| |
3720 if (!i::FLAG_crankshaft) return; | |
3721 i::FLAG_allow_natives_syntax = true; | |
3722 CcTest::InitializeVM(); | |
3723 Isolate* isolate = CcTest::i_isolate(); | |
3724 v8::internal::Heap* heap = CcTest::heap(); | |
3725 | |
3726 if (!isolate->use_crankshaft()) return; | |
3727 HandleScope outer_scope(heap->isolate()); | |
3728 Handle<Code> code; | |
3729 heap->CollectAllAvailableGarbage(); | |
3730 int code_chain_length_before, code_chain_length_after; | |
3731 { | |
3732 HandleScope scope(heap->isolate()); | |
3733 Handle<JSFunction> mortal = OptimizeDummyFunction("mortal"); | |
3734 Handle<JSFunction> immortal = OptimizeDummyFunction("immortal"); | |
3735 CHECK_EQ(immortal->code()->next_code_link(), mortal->code()); | |
3736 code_chain_length_before = GetCodeChainLength(immortal->code()); | |
3737 // Keep the immortal code and let the mortal code die. | |
3738 code = scope.CloseAndEscape(Handle<Code>(immortal->code())); | |
3739 CompileRun("mortal = null; immortal = null;"); | |
3740 } | |
3741 heap->CollectAllAvailableGarbage(); | |
3742 // Now mortal code should be dead. | |
3743 code_chain_length_after = GetCodeChainLength(*code); | |
3744 CHECK_EQ(code_chain_length_before - 1, code_chain_length_after); | |
3745 } | |
OLD | NEW |