| 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 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 // Simulate incremental marking so that the functions are enqueued as | 2568 // Simulate incremental marking so that the functions are enqueued as |
| 2569 // code flushing candidates. Then optimize one function. Finally | 2569 // code flushing candidates. Then optimize one function. Finally |
| 2570 // finish the GC to complete code flushing. | 2570 // finish the GC to complete code flushing. |
| 2571 SimulateIncrementalMarking(); | 2571 SimulateIncrementalMarking(); |
| 2572 CompileRun("%OptimizeFunctionOnNextCall(g); g(3);"); | 2572 CompileRun("%OptimizeFunctionOnNextCall(g); g(3);"); |
| 2573 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2573 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 2574 | 2574 |
| 2575 // Unoptimized code is missing and the deoptimizer will go ballistic. | 2575 // Unoptimized code is missing and the deoptimizer will go ballistic. |
| 2576 CompileRun("g('bozo');"); | 2576 CompileRun("g('bozo');"); |
| 2577 } | 2577 } |
| 2578 |
| 2579 |
| 2580 TEST(Regress169209) { |
| 2581 i::FLAG_allow_natives_syntax = true; |
| 2582 i::FLAG_flush_code_incrementally = true; |
| 2583 InitializeVM(); |
| 2584 v8::HandleScope scope; |
| 2585 |
| 2586 // Perform one initial GC to enable code flushing. |
| 2587 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 2588 |
| 2589 // Prepare a shared function info eligible for code flushing for which |
| 2590 // the unoptimized code will be replaced during optimization. |
| 2591 Handle<SharedFunctionInfo> shared1; |
| 2592 { |
| 2593 HandleScope inner_scope; |
| 2594 CompileRun("function f() { return 'foobar'; }" |
| 2595 "function g(x) { if (x) f(); }" |
| 2596 "f();" |
| 2597 "g(false);" |
| 2598 "g(false);"); |
| 2599 |
| 2600 Handle<JSFunction> f = |
| 2601 v8::Utils::OpenHandle( |
| 2602 *v8::Handle<v8::Function>::Cast( |
| 2603 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); |
| 2604 CHECK(f->is_compiled()); |
| 2605 const int kAgingThreshold = 6; |
| 2606 for (int i = 0; i < kAgingThreshold; i++) { |
| 2607 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
| 2608 } |
| 2609 |
| 2610 shared1 = inner_scope.CloseAndEscape(handle(f->shared(), ISOLATE)); |
| 2611 } |
| 2612 |
| 2613 // Prepare a shared function info eligible for code flushing that will |
| 2614 // represent the dangling tail of the candidate list. |
| 2615 Handle<SharedFunctionInfo> shared2; |
| 2616 { |
| 2617 HandleScope inner_scope; |
| 2618 CompileRun("function flushMe() { return 0; }" |
| 2619 "flushMe(1);"); |
| 2620 |
| 2621 Handle<JSFunction> f = |
| 2622 v8::Utils::OpenHandle( |
| 2623 *v8::Handle<v8::Function>::Cast( |
| 2624 v8::Context::GetCurrent()->Global()->Get(v8_str("flushMe")))); |
| 2625 CHECK(f->is_compiled()); |
| 2626 const int kAgingThreshold = 6; |
| 2627 for (int i = 0; i < kAgingThreshold; i++) { |
| 2628 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
| 2629 } |
| 2630 |
| 2631 shared2 = inner_scope.CloseAndEscape(handle(f->shared(), ISOLATE)); |
| 2632 } |
| 2633 |
| 2634 // Simulate incremental marking and collect code flushing candidates. |
| 2635 SimulateIncrementalMarking(); |
| 2636 CHECK(shared1->code()->gc_metadata() != NULL); |
| 2637 |
| 2638 // Optimize function and make sure the unoptimized code is replaced. |
| 2639 #ifdef DEBUG |
| 2640 FLAG_stop_at = "f"; |
| 2641 #endif |
| 2642 CompileRun("%OptimizeFunctionOnNextCall(g);" |
| 2643 "g(false);"); |
| 2644 |
| 2645 // Finish garbage collection cycle. |
| 2646 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 2647 CHECK(shared1->code()->gc_metadata() == NULL); |
| 2648 } |
| 2649 |
| 2650 |
| 2651 TEST(Regress168801) { |
| 2652 i::FLAG_always_compact = true; |
| 2653 i::FLAG_cache_optimized_code = false; |
| 2654 i::FLAG_allow_natives_syntax = true; |
| 2655 i::FLAG_flush_code_incrementally = true; |
| 2656 InitializeVM(); |
| 2657 v8::HandleScope scope; |
| 2658 |
| 2659 // Perform one initial GC to enable code flushing. |
| 2660 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 2661 |
| 2662 // Ensure the code ends up on an evacuation candidate. |
| 2663 SimulateFullSpace(HEAP->code_space()); |
| 2664 |
| 2665 // Prepare an unoptimized function that is eligible for code flushing. |
| 2666 Handle<JSFunction> function; |
| 2667 { |
| 2668 HandleScope inner_scope; |
| 2669 CompileRun("function mkClosure() {" |
| 2670 " return function(x) { return x + 1; };" |
| 2671 "}" |
| 2672 "var f = mkClosure();" |
| 2673 "f(1); f(2);"); |
| 2674 |
| 2675 Handle<JSFunction> f = |
| 2676 v8::Utils::OpenHandle( |
| 2677 *v8::Handle<v8::Function>::Cast( |
| 2678 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); |
| 2679 CHECK(f->is_compiled()); |
| 2680 const int kAgingThreshold = 6; |
| 2681 for (int i = 0; i < kAgingThreshold; i++) { |
| 2682 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
| 2683 } |
| 2684 |
| 2685 function = inner_scope.CloseAndEscape(handle(*f, ISOLATE)); |
| 2686 } |
| 2687 |
| 2688 // Simulate incremental marking so that unoptimized function is enqueued as a |
| 2689 // candidate for code flushing. The shared function info however will not be |
| 2690 // explicitly enqueued. |
| 2691 SimulateIncrementalMarking(); |
| 2692 |
| 2693 // Now optimize the function so that it is taken off the candidate list. |
| 2694 { |
| 2695 HandleScope inner_scope; |
| 2696 CompileRun("%OptimizeFunctionOnNextCall(f); f(3);"); |
| 2697 } |
| 2698 |
| 2699 // This cycle will bust the heap and subsequent cycles will go ballistic. |
| 2700 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 2701 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 2702 } |
| OLD | NEW |