| 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 7664 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 7675   if (!JSFunction::CompileLazy(function, KEEP_EXCEPTION)) { | 7675   if (!JSFunction::CompileLazy(function, KEEP_EXCEPTION)) { | 
| 7676     return Failure::Exception(); | 7676     return Failure::Exception(); | 
| 7677   } | 7677   } | 
| 7678 | 7678 | 
| 7679   // All done. Return the compiled code. | 7679   // All done. Return the compiled code. | 
| 7680   ASSERT(function->is_compiled()); | 7680   ASSERT(function->is_compiled()); | 
| 7681   return function->code(); | 7681   return function->code(); | 
| 7682 } | 7682 } | 
| 7683 | 7683 | 
| 7684 | 7684 | 
|  | 7685 bool AllowOptimization(Isolate* isolate, Handle<JSFunction> function) { | 
|  | 7686   // If the function is not compiled ignore the lazy | 
|  | 7687   // recompilation. This can happen if the debugger is activated and | 
|  | 7688   // the function is returned to the not compiled state. | 
|  | 7689   if (!function->shared()->is_compiled()) return false; | 
|  | 7690 | 
|  | 7691   // If the function is not optimizable or debugger is active continue using the | 
|  | 7692   // code from the full compiler. | 
|  | 7693   if (!FLAG_crankshaft || | 
|  | 7694       function->shared()->optimization_disabled() || | 
|  | 7695       isolate->DebuggerHasBreakPoints()) { | 
|  | 7696     if (FLAG_trace_opt) { | 
|  | 7697       PrintF("[failed to optimize "); | 
|  | 7698       function->PrintName(); | 
|  | 7699       PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", | 
|  | 7700           function->shared()->optimization_disabled() ? "F" : "T", | 
|  | 7701           isolate->DebuggerHasBreakPoints() ? "T" : "F"); | 
|  | 7702     } | 
|  | 7703     return false; | 
|  | 7704   } | 
|  | 7705   return true; | 
|  | 7706 } | 
|  | 7707 | 
|  | 7708 | 
| 7685 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyRecompile) { | 7709 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyRecompile) { | 
| 7686   HandleScope scope(isolate); | 7710   HandleScope scope(isolate); | 
| 7687   ASSERT(args.length() == 1); | 7711   ASSERT(args.length() == 1); | 
| 7688   Handle<JSFunction> function = args.at<JSFunction>(0); | 7712   Handle<JSFunction> function = args.at<JSFunction>(0); | 
| 7689 | 7713 | 
| 7690   // If the function is not compiled ignore the lazy | 7714   if (!AllowOptimization(isolate, function)) { | 
| 7691   // recompilation. This can happen if the debugger is activated and |  | 
| 7692   // the function is returned to the not compiled state. |  | 
| 7693   if (!function->shared()->is_compiled()) { |  | 
| 7694     function->ReplaceCode(function->shared()->code()); | 7715     function->ReplaceCode(function->shared()->code()); | 
| 7695     return function->code(); | 7716     return function->code(); | 
| 7696   } | 7717   } | 
| 7697 |  | 
| 7698   // If the function is not optimizable or debugger is active continue using the |  | 
| 7699   // code from the full compiler. |  | 
| 7700   if (!FLAG_crankshaft || |  | 
| 7701       !function->shared()->code()->optimizable() || |  | 
| 7702       isolate->DebuggerHasBreakPoints()) { |  | 
| 7703     if (FLAG_trace_opt) { |  | 
| 7704       PrintF("[failed to optimize "); |  | 
| 7705       function->PrintName(); |  | 
| 7706       PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", |  | 
| 7707           function->shared()->code()->optimizable() ? "T" : "F", |  | 
| 7708           isolate->DebuggerHasBreakPoints() ? "T" : "F"); |  | 
| 7709     } |  | 
| 7710     function->ReplaceCode(function->shared()->code()); |  | 
| 7711     return function->code(); |  | 
| 7712   } |  | 
| 7713   function->shared()->code()->set_profiler_ticks(0); | 7718   function->shared()->code()->set_profiler_ticks(0); | 
| 7714   if (JSFunction::CompileOptimized(function, | 7719   if (JSFunction::CompileOptimized(function, | 
| 7715                                    BailoutId::None(), | 7720                                    BailoutId::None(), | 
| 7716                                    CLEAR_EXCEPTION)) { | 7721                                    CLEAR_EXCEPTION)) { | 
| 7717     return function->code(); | 7722     return function->code(); | 
| 7718   } | 7723   } | 
| 7719   if (FLAG_trace_opt) { | 7724   if (FLAG_trace_opt) { | 
| 7720     PrintF("[failed to optimize "); | 7725     PrintF("[failed to optimize "); | 
| 7721     function->PrintName(); | 7726     function->PrintName(); | 
| 7722     PrintF(": optimized compilation failed]\n"); | 7727     PrintF(": optimized compilation failed]\n"); | 
| 7723   } | 7728   } | 
| 7724   function->ReplaceCode(function->shared()->code()); | 7729   function->ReplaceCode(function->shared()->code()); | 
| 7725   return function->code(); | 7730   return function->code(); | 
| 7726 } | 7731 } | 
| 7727 | 7732 | 
| 7728 | 7733 | 
| 7729 RUNTIME_FUNCTION(MaybeObject*, Runtime_ParallelRecompile) { | 7734 RUNTIME_FUNCTION(MaybeObject*, Runtime_ParallelRecompile) { | 
| 7730   HandleScope handle_scope(isolate); | 7735   HandleScope handle_scope(isolate); | 
|  | 7736   Handle<JSFunction> function = args.at<JSFunction>(0); | 
|  | 7737   if (!AllowOptimization(isolate, function)) { | 
|  | 7738     function->ReplaceCode(function->shared()->code()); | 
|  | 7739     return function->code(); | 
|  | 7740   } | 
|  | 7741   function->shared()->code()->set_profiler_ticks(0); | 
| 7731   ASSERT(FLAG_parallel_recompilation); | 7742   ASSERT(FLAG_parallel_recompilation); | 
| 7732   Compiler::RecompileParallel(args.at<JSFunction>(0)); | 7743   Compiler::RecompileParallel(function); | 
| 7733   return isolate->heap()->undefined_value(); | 7744   return isolate->heap()->undefined_value(); | 
| 7734 } | 7745 } | 
| 7735 | 7746 | 
| 7736 | 7747 | 
| 7737 RUNTIME_FUNCTION(MaybeObject*, Runtime_ForceParallelRecompile) { | 7748 RUNTIME_FUNCTION(MaybeObject*, Runtime_ForceParallelRecompile) { | 
| 7738   if (!V8::UseCrankshaft()) return isolate->heap()->undefined_value(); | 7749   if (!V8::UseCrankshaft()) return isolate->heap()->undefined_value(); | 
| 7739   HandleScope handle_scope(isolate); | 7750   HandleScope handle_scope(isolate); | 
| 7740   ASSERT(FLAG_parallel_recompilation && FLAG_manual_parallel_recompilation); | 7751   ASSERT(FLAG_parallel_recompilation && FLAG_manual_parallel_recompilation); | 
| 7741   if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 7752   if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 
| 7742     return isolate->Throw(*isolate->factory()->InternalizeOneByteString( | 7753     return isolate->Throw(*isolate->factory()->InternalizeOneByteString( | 
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 7906   RUNTIME_ASSERT(args.length() == 1 || args.length() == 2); | 7917   RUNTIME_ASSERT(args.length() == 1 || args.length() == 2); | 
| 7907   CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 7918   CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 
| 7908 | 7919 | 
| 7909   if (!function->IsOptimizable()) return isolate->heap()->undefined_value(); | 7920   if (!function->IsOptimizable()) return isolate->heap()->undefined_value(); | 
| 7910   function->MarkForLazyRecompilation(); | 7921   function->MarkForLazyRecompilation(); | 
| 7911 | 7922 | 
| 7912   Code* unoptimized = function->shared()->code(); | 7923   Code* unoptimized = function->shared()->code(); | 
| 7913   if (args.length() == 2 && | 7924   if (args.length() == 2 && | 
| 7914       unoptimized->kind() == Code::FUNCTION) { | 7925       unoptimized->kind() == Code::FUNCTION) { | 
| 7915     CONVERT_ARG_HANDLE_CHECKED(String, type, 1); | 7926     CONVERT_ARG_HANDLE_CHECKED(String, type, 1); | 
| 7916     CHECK(type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr"))); | 7927     if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr"))) { | 
| 7917     isolate->runtime_profiler()->AttemptOnStackReplacement(*function); | 7928       isolate->runtime_profiler()->AttemptOnStackReplacement(*function); | 
| 7918     unoptimized->set_allow_osr_at_loop_nesting_level( | 7929       unoptimized->set_allow_osr_at_loop_nesting_level( | 
| 7919         Code::kMaxLoopNestingMarker); | 7930           Code::kMaxLoopNestingMarker); | 
|  | 7931     } else if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("parallel"))) { | 
|  | 7932       function->MarkForParallelRecompilation(); | 
|  | 7933     } | 
| 7920   } | 7934   } | 
| 7921 | 7935 | 
| 7922   return isolate->heap()->undefined_value(); | 7936   return isolate->heap()->undefined_value(); | 
| 7923 } | 7937 } | 
| 7924 | 7938 | 
| 7925 | 7939 | 
| 7926 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationStatus) { | 7940 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationStatus) { | 
| 7927   HandleScope scope(isolate); | 7941   HandleScope scope(isolate); | 
| 7928   ASSERT(args.length() == 1); | 7942   ASSERT(args.length() == 1); | 
| 7929   // The least significant bit (after untagging) indicates whether the | 7943   // The least significant bit (after untagging) indicates whether the | 
| (...skipping 5401 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 13331     // Handle last resort GC and make sure to allow future allocations | 13345     // Handle last resort GC and make sure to allow future allocations | 
| 13332     // to grow the heap without causing GCs (if possible). | 13346     // to grow the heap without causing GCs (if possible). | 
| 13333     isolate->counters()->gc_last_resort_from_js()->Increment(); | 13347     isolate->counters()->gc_last_resort_from_js()->Increment(); | 
| 13334     isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13348     isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 
| 13335                                        "Runtime::PerformGC"); | 13349                                        "Runtime::PerformGC"); | 
| 13336   } | 13350   } | 
| 13337 } | 13351 } | 
| 13338 | 13352 | 
| 13339 | 13353 | 
| 13340 } }  // namespace v8::internal | 13354 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|