OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "compilation-cache.h" | 7 #include "compilation-cache.h" |
8 #include "execution.h" | 8 #include "execution.h" |
9 #include "factory.h" | 9 #include "factory.h" |
10 #include "macro-assembler.h" | 10 #include "macro-assembler.h" |
(...skipping 2609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2620 | 2620 |
2621 // Simulate incremental marking so that unoptimized code is flushed | 2621 // Simulate incremental marking so that unoptimized code is flushed |
2622 // even though it still is cached in the optimized code map. | 2622 // even though it still is cached in the optimized code map. |
2623 SimulateIncrementalMarking(); | 2623 SimulateIncrementalMarking(); |
2624 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2624 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2625 | 2625 |
2626 // Make a new closure that will get code installed from the code map. | 2626 // Make a new closure that will get code installed from the code map. |
2627 // Unoptimized code is missing and the deoptimizer will go ballistic. | 2627 // Unoptimized code is missing and the deoptimizer will go ballistic. |
2628 CompileRun("var g = mkClosure(); g('bozo');"); | 2628 CompileRun("var g = mkClosure(); g('bozo');"); |
2629 } | 2629 } |
| 2630 |
| 2631 |
| 2632 TEST(Regress169209) { |
| 2633 i::FLAG_allow_natives_syntax = true; |
| 2634 i::FLAG_flush_code_incrementally = true; |
| 2635 InitializeVM(); |
| 2636 v8::HandleScope scope; |
| 2637 |
| 2638 // Perform one initial GC to enable code flushing. |
| 2639 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 2640 |
| 2641 // Prepare a shared function info eligible for code flushing for which |
| 2642 // the unoptimized code will be replaced during optimization. |
| 2643 Handle<SharedFunctionInfo> shared1; |
| 2644 { |
| 2645 HandleScope inner_scope; |
| 2646 CompileRun("function f() { return 'foobar'; }" |
| 2647 "function g(x) { if (x) f(); }" |
| 2648 "f();" |
| 2649 "g(false);" |
| 2650 "g(false);"); |
| 2651 |
| 2652 Handle<JSFunction> f = |
| 2653 v8::Utils::OpenHandle( |
| 2654 *v8::Handle<v8::Function>::Cast( |
| 2655 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); |
| 2656 CHECK(f->is_compiled()); |
| 2657 const int kAgingThreshold = 6; |
| 2658 for (int i = 0; i < kAgingThreshold; i++) { |
| 2659 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
| 2660 } |
| 2661 |
| 2662 shared1 = inner_scope.CloseAndEscape(handle(f->shared(), ISOLATE)); |
| 2663 } |
| 2664 |
| 2665 // Prepare a shared function info eligible for code flushing that will |
| 2666 // represent the dangling tail of the candidate list. |
| 2667 Handle<SharedFunctionInfo> shared2; |
| 2668 { |
| 2669 HandleScope inner_scope; |
| 2670 CompileRun("function flushMe() { return 0; }" |
| 2671 "flushMe(1);"); |
| 2672 |
| 2673 Handle<JSFunction> f = |
| 2674 v8::Utils::OpenHandle( |
| 2675 *v8::Handle<v8::Function>::Cast( |
| 2676 v8::Context::GetCurrent()->Global()->Get(v8_str("flushMe")))); |
| 2677 CHECK(f->is_compiled()); |
| 2678 const int kAgingThreshold = 6; |
| 2679 for (int i = 0; i < kAgingThreshold; i++) { |
| 2680 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
| 2681 } |
| 2682 |
| 2683 shared2 = inner_scope.CloseAndEscape(handle(f->shared(), ISOLATE)); |
| 2684 } |
| 2685 |
| 2686 // Simulate incremental marking and collect code flushing candidates. |
| 2687 SimulateIncrementalMarking(); |
| 2688 CHECK(shared1->code()->gc_metadata() != NULL); |
| 2689 |
| 2690 // Optimize function and make sure the unoptimized code is replaced. |
| 2691 FLAG_stop_at = "f"; |
| 2692 CompileRun("%OptimizeFunctionOnNextCall(g);" |
| 2693 "g(false);"); |
| 2694 |
| 2695 // Finish garbage collection cycle. |
| 2696 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 2697 CHECK(shared1->code()->gc_metadata() == NULL); |
| 2698 } |
OLD | NEW |