Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/runtime.cc

Issue 110203002: Refactor the compiling pipeline. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.h ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2939 matching lines...) Expand 10 before | Expand all | Expand 10 after
2950 2950
2951 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0); 2951 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
2952 Handle<Object> code = args.at<Object>(1); 2952 Handle<Object> code = args.at<Object>(1);
2953 2953
2954 if (code->IsNull()) return *target; 2954 if (code->IsNull()) return *target;
2955 RUNTIME_ASSERT(code->IsJSFunction()); 2955 RUNTIME_ASSERT(code->IsJSFunction());
2956 Handle<JSFunction> source = Handle<JSFunction>::cast(code); 2956 Handle<JSFunction> source = Handle<JSFunction>::cast(code);
2957 Handle<SharedFunctionInfo> target_shared(target->shared()); 2957 Handle<SharedFunctionInfo> target_shared(target->shared());
2958 Handle<SharedFunctionInfo> source_shared(source->shared()); 2958 Handle<SharedFunctionInfo> source_shared(source->shared());
2959 2959
2960 if (!JSFunction::EnsureCompiled(source, KEEP_EXCEPTION)) { 2960 if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) {
2961 return Failure::Exception(); 2961 return Failure::Exception();
2962 } 2962 }
2963 2963
2964 // Mark both, the source and the target, as un-flushable because the 2964 // Mark both, the source and the target, as un-flushable because the
2965 // shared unoptimized code makes them impossible to enqueue in a list. 2965 // shared unoptimized code makes them impossible to enqueue in a list.
2966 ASSERT(target_shared->code()->gc_metadata() == NULL); 2966 ASSERT(target_shared->code()->gc_metadata() == NULL);
2967 ASSERT(source_shared->code()->gc_metadata() == NULL); 2967 ASSERT(source_shared->code()->gc_metadata() == NULL);
2968 target_shared->set_dont_flush(true); 2968 target_shared->set_dont_flush(true);
2969 source_shared->set_dont_flush(true); 2969 source_shared->set_dont_flush(true);
2970 2970
(...skipping 5287 matching lines...) Expand 10 before | Expand all | Expand 10 after
8258 // ignored anyway, we use the global object as the receiver 8258 // ignored anyway, we use the global object as the receiver
8259 // instead of a new JSFunction object. This way, errors are 8259 // instead of a new JSFunction object. This way, errors are
8260 // reported the same way whether or not 'Function' is called 8260 // reported the same way whether or not 'Function' is called
8261 // using 'new'. 8261 // using 'new'.
8262 return isolate->context()->global_object(); 8262 return isolate->context()->global_object();
8263 } 8263 }
8264 } 8264 }
8265 8265
8266 // The function should be compiled for the optimization hints to be 8266 // The function should be compiled for the optimization hints to be
8267 // available. 8267 // available.
8268 JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION); 8268 Compiler::EnsureCompiled(function, CLEAR_EXCEPTION);
8269 8269
8270 Handle<SharedFunctionInfo> shared(function->shared(), isolate); 8270 Handle<SharedFunctionInfo> shared(function->shared(), isolate);
8271 if (!function->has_initial_map() && 8271 if (!function->has_initial_map() &&
8272 shared->IsInobjectSlackTrackingInProgress()) { 8272 shared->IsInobjectSlackTrackingInProgress()) {
8273 // The tracking is already in progress for another function. We can only 8273 // The tracking is already in progress for another function. We can only
8274 // track one initial_map at a time, so we force the completion before the 8274 // track one initial_map at a time, so we force the completion before the
8275 // function is called as a constructor for the first time. 8275 // function is called as a constructor for the first time.
8276 shared->CompleteInobjectSlackTracking(); 8276 shared->CompleteInobjectSlackTracking();
8277 } 8277 }
8278 8278
(...skipping 11 matching lines...) Expand all
8290 HandleScope scope(isolate); 8290 HandleScope scope(isolate);
8291 ASSERT(args.length() == 1); 8291 ASSERT(args.length() == 1);
8292 8292
8293 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8293 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8294 function->shared()->CompleteInobjectSlackTracking(); 8294 function->shared()->CompleteInobjectSlackTracking();
8295 8295
8296 return isolate->heap()->undefined_value(); 8296 return isolate->heap()->undefined_value();
8297 } 8297 }
8298 8298
8299 8299
8300 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyCompile) { 8300 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileUnoptimized) {
8301 HandleScope scope(isolate); 8301 HandleScope scope(isolate);
8302 ASSERT(args.length() == 1); 8302 ASSERT(args.length() == 1);
8303 8303
8304 Handle<JSFunction> function = args.at<JSFunction>(0); 8304 Handle<JSFunction> function = args.at<JSFunction>(0);
8305 #ifdef DEBUG 8305 #ifdef DEBUG
8306 if (FLAG_trace_lazy && !function->shared()->is_compiled()) { 8306 if (FLAG_trace_lazy && !function->shared()->is_compiled()) {
8307 PrintF("[lazy: "); 8307 PrintF("[unoptimized: ");
8308 function->PrintName(); 8308 function->PrintName();
8309 PrintF("]\n"); 8309 PrintF("]\n");
8310 } 8310 }
8311 #endif 8311 #endif
8312 8312
8313 // Compile the target function. 8313 // Compile the target function.
8314 ASSERT(!function->is_compiled()); 8314 ASSERT(function->shared()->allows_lazy_compilation());
8315 if (!JSFunction::CompileLazy(function, KEEP_EXCEPTION)) { 8315
8316 return Failure::Exception(); 8316 Handle<Code> code = Compiler::GetUnoptimizedCode(function);
8317 } 8317 RETURN_IF_EMPTY_HANDLE(isolate, code);
8318 function->ReplaceCode(*code);
8318 8319
8319 // All done. Return the compiled code. 8320 // All done. Return the compiled code.
8320 ASSERT(function->is_compiled()); 8321 ASSERT(function->is_compiled());
8321 return function->code(); 8322 ASSERT(function->code()->kind() == Code::FUNCTION ||
8323 (FLAG_always_opt &&
8324 function->code()->kind() == Code::OPTIMIZED_FUNCTION));
8325 return *code;
8322 } 8326 }
8323 8327
8324 8328
8325 bool AllowOptimization(Isolate* isolate, Handle<JSFunction> function) { 8329 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileOptimized) {
8326 // If the function is not compiled ignore the lazy 8330 HandleScope scope(isolate);
8327 // recompilation. This can happen if the debugger is activated and 8331 ASSERT(args.length() == 2);
8328 // the function is returned to the not compiled state. 8332 Handle<JSFunction> function = args.at<JSFunction>(0);
8329 if (!function->shared()->is_compiled()) return false; 8333 CONVERT_BOOLEAN_ARG_CHECKED(concurrent, 1);
8330 8334
8331 // If the function is not optimizable or debugger is active continue using the 8335 Handle<Code> unoptimized(function->shared()->code());
8332 // code from the full compiler. 8336 if (!function->shared()->is_compiled()) {
8333 if (!isolate->use_crankshaft() || 8337 // If the function is not compiled, do not optimize.
8334 function->shared()->optimization_disabled() || 8338 // This can happen if the debugger is activated and
8335 isolate->DebuggerHasBreakPoints()) { 8339 // the function is returned to the not compiled state.
8340 // TODO(yangguo): reconsider this.
8341 function->ReplaceCode(function->shared()->code());
8342 } else if (!isolate->use_crankshaft() ||
8343 function->shared()->optimization_disabled() ||
8344 isolate->DebuggerHasBreakPoints()) {
8345 // If the function is not optimizable or debugger is active continue
8346 // using the code from the full compiler.
8336 if (FLAG_trace_opt) { 8347 if (FLAG_trace_opt) {
8337 PrintF("[failed to optimize "); 8348 PrintF("[failed to optimize ");
8338 function->PrintName(); 8349 function->PrintName();
8339 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", 8350 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n",
8340 function->shared()->optimization_disabled() ? "F" : "T", 8351 function->shared()->optimization_disabled() ? "F" : "T",
8341 isolate->DebuggerHasBreakPoints() ? "T" : "F"); 8352 isolate->DebuggerHasBreakPoints() ? "T" : "F");
8342 } 8353 }
8343 return false; 8354 function->ReplaceCode(*unoptimized);
8355 } else {
8356 Compiler::ConcurrencyMode mode = concurrent ? Compiler::CONCURRENT
8357 : Compiler::NOT_CONCURRENT;
8358 Handle<Code> code = Compiler::GetOptimizedCode(function, unoptimized, mode);
8359 function->ReplaceCode(code.is_null() ? *unoptimized : *code);
8344 } 8360 }
8345 return true;
8346 }
8347 8361
8348 8362 ASSERT(function->code()->kind() == Code::FUNCTION ||
8349 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyRecompile) { 8363 function->code()->kind() == Code::OPTIMIZED_FUNCTION ||
8350 HandleScope scope(isolate); 8364 function->IsInOptimizationQueue());
8351 ASSERT(args.length() == 1);
8352 Handle<JSFunction> function = args.at<JSFunction>(0);
8353
8354 if (!AllowOptimization(isolate, function)) {
8355 function->ReplaceCode(function->shared()->code());
8356 return function->code();
8357 }
8358 function->shared()->code()->set_profiler_ticks(0);
8359 if (JSFunction::CompileOptimized(function, CLEAR_EXCEPTION)) {
8360 return function->code();
8361 }
8362 if (FLAG_trace_opt) {
8363 PrintF("[failed to optimize ");
8364 function->PrintName();
8365 PrintF(": optimized compilation failed]\n");
8366 }
8367 function->ReplaceCode(function->shared()->code());
8368 return function->code(); 8365 return function->code();
8369 } 8366 }
8370 8367
8371 8368
8372 RUNTIME_FUNCTION(MaybeObject*, Runtime_ConcurrentRecompile) {
8373 HandleScope handle_scope(isolate);
8374 ASSERT(args.length() == 1);
8375 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8376 if (!AllowOptimization(isolate, function)) {
8377 function->ReplaceCode(function->shared()->code());
8378 return isolate->heap()->undefined_value();
8379 }
8380 Handle<Code> shared_code(function->shared()->code());
8381 shared_code->set_profiler_ticks(0);
8382 ASSERT(isolate->concurrent_recompilation_enabled());
8383 if (!Compiler::RecompileConcurrent(function, shared_code)) {
8384 function->ReplaceCode(*shared_code);
8385 }
8386 return isolate->heap()->undefined_value();
8387 }
8388
8389
8390 class ActivationsFinder : public ThreadVisitor { 8369 class ActivationsFinder : public ThreadVisitor {
8391 public: 8370 public:
8392 Code* code_; 8371 Code* code_;
8393 bool has_code_activations_; 8372 bool has_code_activations_;
8394 8373
8395 explicit ActivationsFinder(Code* code) 8374 explicit ActivationsFinder(Code* code)
8396 : code_(code), 8375 : code_(code),
8397 has_code_activations_(false) { } 8376 has_code_activations_(false) { }
8398 8377
8399 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { 8378 void VisitThread(Isolate* isolate, ThreadLocalTop* top) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
8520 ? isolate->heap()->true_value() : isolate->heap()->false_value(); 8499 ? isolate->heap()->true_value() : isolate->heap()->false_value();
8521 } 8500 }
8522 8501
8523 8502
8524 RUNTIME_FUNCTION(MaybeObject*, Runtime_OptimizeFunctionOnNextCall) { 8503 RUNTIME_FUNCTION(MaybeObject*, Runtime_OptimizeFunctionOnNextCall) {
8525 HandleScope scope(isolate); 8504 HandleScope scope(isolate);
8526 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2); 8505 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2);
8527 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8506 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8528 8507
8529 if (!function->IsOptimizable()) return isolate->heap()->undefined_value(); 8508 if (!function->IsOptimizable()) return isolate->heap()->undefined_value();
8530 function->MarkForLazyRecompilation(); 8509 function->MarkForOptimization();
8531 8510
8532 Code* unoptimized = function->shared()->code(); 8511 Code* unoptimized = function->shared()->code();
8533 if (args.length() == 2 && 8512 if (args.length() == 2 &&
8534 unoptimized->kind() == Code::FUNCTION) { 8513 unoptimized->kind() == Code::FUNCTION) {
8535 CONVERT_ARG_HANDLE_CHECKED(String, type, 1); 8514 CONVERT_ARG_HANDLE_CHECKED(String, type, 1);
8536 if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr"))) { 8515 if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr"))) {
8537 // Start patching from the currently patched loop nesting level. 8516 // Start patching from the currently patched loop nesting level.
8538 int current_level = unoptimized->allow_osr_at_loop_nesting_level(); 8517 int current_level = unoptimized->allow_osr_at_loop_nesting_level();
8539 ASSERT(BackEdgeTable::Verify(isolate, unoptimized, current_level)); 8518 ASSERT(BackEdgeTable::Verify(isolate, unoptimized, current_level));
8540 for (int i = current_level + 1; i <= Code::kMaxLoopNestingMarker; i++) { 8519 for (int i = current_level + 1; i <= Code::kMaxLoopNestingMarker; i++) {
8541 unoptimized->set_allow_osr_at_loop_nesting_level(i); 8520 unoptimized->set_allow_osr_at_loop_nesting_level(i);
8542 isolate->runtime_profiler()->AttemptOnStackReplacement(*function); 8521 isolate->runtime_profiler()->AttemptOnStackReplacement(*function);
8543 } 8522 }
8544 } else if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("concurrent"))) { 8523 } else if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("concurrent"))) {
8545 function->MarkForConcurrentRecompilation(); 8524 function->MarkForConcurrentOptimization();
8546 } 8525 }
8547 } 8526 }
8548 8527
8549 return isolate->heap()->undefined_value(); 8528 return isolate->heap()->undefined_value();
8550 } 8529 }
8551 8530
8552 8531
8553 RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimizeFunction) { 8532 RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimizeFunction) {
8554 HandleScope scope(isolate); 8533 HandleScope scope(isolate);
8555 ASSERT(args.length() == 1); 8534 ASSERT(args.length() == 1);
(...skipping 13 matching lines...) Expand all
8569 bool sync_with_compiler_thread = true; 8548 bool sync_with_compiler_thread = true;
8570 if (args.length() == 2) { 8549 if (args.length() == 2) {
8571 CONVERT_ARG_HANDLE_CHECKED(String, sync, 1); 8550 CONVERT_ARG_HANDLE_CHECKED(String, sync, 1);
8572 if (sync->IsOneByteEqualTo(STATIC_ASCII_VECTOR("no sync"))) { 8551 if (sync->IsOneByteEqualTo(STATIC_ASCII_VECTOR("no sync"))) {
8573 sync_with_compiler_thread = false; 8552 sync_with_compiler_thread = false;
8574 } 8553 }
8575 } 8554 }
8576 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8555 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8577 if (isolate->concurrent_recompilation_enabled() && 8556 if (isolate->concurrent_recompilation_enabled() &&
8578 sync_with_compiler_thread) { 8557 sync_with_compiler_thread) {
8579 while (function->IsInRecompileQueue()) { 8558 while (function->IsInOptimizationQueue()) {
8580 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions(); 8559 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions();
8581 OS::Sleep(50); 8560 OS::Sleep(50);
8582 } 8561 }
8583 } 8562 }
8584 if (FLAG_always_opt) { 8563 if (FLAG_always_opt) {
8585 // We may have always opt, but that is more best-effort than a real 8564 // We may have always opt, but that is more best-effort than a real
8586 // promise, so we still say "no" if it is not optimized. 8565 // promise, so we still say "no" if it is not optimized.
8587 return function->IsOptimized() ? Smi::FromInt(3) // 3 == "always". 8566 return function->IsOptimized() ? Smi::FromInt(3) // 3 == "always".
8588 : Smi::FromInt(2); // 2 == "no". 8567 : Smi::FromInt(2); // 2 == "no".
8589 } 8568 }
(...skipping 15 matching lines...) Expand all
8605 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationCount) { 8584 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationCount) {
8606 HandleScope scope(isolate); 8585 HandleScope scope(isolate);
8607 ASSERT(args.length() == 1); 8586 ASSERT(args.length() == 1);
8608 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8587 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8609 return Smi::FromInt(function->shared()->opt_count()); 8588 return Smi::FromInt(function->shared()->opt_count());
8610 } 8589 }
8611 8590
8612 8591
8613 static bool IsSuitableForOnStackReplacement(Isolate* isolate, 8592 static bool IsSuitableForOnStackReplacement(Isolate* isolate,
8614 Handle<JSFunction> function, 8593 Handle<JSFunction> function,
8615 Handle<Code> unoptimized) { 8594 Handle<Code> current_code) {
8616 // Keep track of whether we've succeeded in optimizing. 8595 // Keep track of whether we've succeeded in optimizing.
8617 if (!isolate->use_crankshaft() || !unoptimized->optimizable()) return false; 8596 if (!isolate->use_crankshaft() || !current_code->optimizable()) return false;
8618 // If we are trying to do OSR when there are already optimized 8597 // If we are trying to do OSR when there are already optimized
8619 // activations of the function, it means (a) the function is directly or 8598 // activations of the function, it means (a) the function is directly or
8620 // indirectly recursive and (b) an optimized invocation has been 8599 // indirectly recursive and (b) an optimized invocation has been
8621 // deoptimized so that we are currently in an unoptimized activation. 8600 // deoptimized so that we are currently in an unoptimized activation.
8622 // Check for optimized activations of this function. 8601 // Check for optimized activations of this function.
8623 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { 8602 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
8624 JavaScriptFrame* frame = it.frame(); 8603 JavaScriptFrame* frame = it.frame();
8625 if (frame->is_optimized() && frame->function() == *function) return false; 8604 if (frame->is_optimized() && frame->function() == *function) return false;
8626 } 8605 }
8627 8606
8628 return true; 8607 return true;
8629 } 8608 }
8630 8609
8631 8610
8632 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileForOnStackReplacement) { 8611 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileForOnStackReplacement) {
8633 HandleScope scope(isolate); 8612 HandleScope scope(isolate);
8634 ASSERT(args.length() == 1); 8613 ASSERT(args.length() == 1);
8635 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8614 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8636 Handle<Code> unoptimized(function->shared()->code(), isolate); 8615 Handle<Code> caller_code(function->shared()->code());
8616
8617 // We're not prepared to handle a function with arguments object.
8618 ASSERT(!function->shared()->uses_arguments());
8637 8619
8638 // Passing the PC in the javascript frame from the caller directly is 8620 // Passing the PC in the javascript frame from the caller directly is
8639 // not GC safe, so we walk the stack to get it. 8621 // not GC safe, so we walk the stack to get it.
8640 JavaScriptFrameIterator it(isolate); 8622 JavaScriptFrameIterator it(isolate);
8641 JavaScriptFrame* frame = it.frame(); 8623 JavaScriptFrame* frame = it.frame();
8642 if (!unoptimized->contains(frame->pc())) { 8624 if (!caller_code->contains(frame->pc())) {
8643 // Code on the stack may not be the code object referenced by the shared 8625 // Code on the stack may not be the code object referenced by the shared
8644 // function info. It may have been replaced to include deoptimization data. 8626 // function info. It may have been replaced to include deoptimization data.
8645 unoptimized = Handle<Code>(frame->LookupCode()); 8627 caller_code = Handle<Code>(frame->LookupCode());
8646 } 8628 }
8647 8629
8648 uint32_t pc_offset = static_cast<uint32_t>(frame->pc() - 8630 uint32_t pc_offset = static_cast<uint32_t>(
8649 unoptimized->instruction_start()); 8631 frame->pc() - caller_code->instruction_start());
8650 8632
8651 #ifdef DEBUG 8633 #ifdef DEBUG
8652 ASSERT_EQ(frame->function(), *function); 8634 ASSERT_EQ(frame->function(), *function);
8653 ASSERT_EQ(frame->LookupCode(), *unoptimized); 8635 ASSERT_EQ(frame->LookupCode(), *caller_code);
8654 ASSERT(unoptimized->contains(frame->pc())); 8636 ASSERT(caller_code->contains(frame->pc()));
8655 #endif // DEBUG 8637 #endif // DEBUG
8656 8638
8657 // We're not prepared to handle a function with arguments object.
8658 ASSERT(!function->shared()->uses_arguments());
8659 8639
8640 BailoutId ast_id = caller_code->TranslatePcOffsetToAstId(pc_offset);
8641 ASSERT(!ast_id.IsNone());
8642
8643 Compiler::ConcurrencyMode mode = isolate->concurrent_osr_enabled()
8644 ? Compiler::CONCURRENT : Compiler::NOT_CONCURRENT;
8660 Handle<Code> result = Handle<Code>::null(); 8645 Handle<Code> result = Handle<Code>::null();
8661 BailoutId ast_id = BailoutId::None();
8662 8646
8663 if (isolate->concurrent_osr_enabled()) { 8647 OptimizedCompileJob* job = NULL;
8664 if (isolate->optimizing_compiler_thread()-> 8648 if (mode == Compiler::CONCURRENT) {
8665 IsQueuedForOSR(function, pc_offset)) { 8649 // Gate the OSR entry with a stack check.
8666 // Still waiting for the optimizing compiler thread to finish. Carry on. 8650 BackEdgeTable::AddStackCheck(caller_code, pc_offset);
8651 // Poll already queued compilation jobs.
8652 OptimizingCompilerThread* thread = isolate->optimizing_compiler_thread();
8653 if (thread->IsQueuedForOSR(function, ast_id)) {
8667 if (FLAG_trace_osr) { 8654 if (FLAG_trace_osr) {
8668 PrintF("[COSR - polling recompile tasks for "); 8655 PrintF("[OSR - Still waiting for queued: ");
8669 function->PrintName(); 8656 function->PrintName();
8670 PrintF("]\n"); 8657 PrintF(" at AST id %d]\n", ast_id.ToInt());
8671 } 8658 }
8672 return NULL; 8659 return NULL;
8673 } 8660 }
8674 8661
8675 RecompileJob* job = isolate->optimizing_compiler_thread()-> 8662 job = thread->FindReadyOSRCandidate(function, ast_id);
8676 FindReadyOSRCandidate(function, pc_offset); 8663 }
8677 8664
8678 if (job == NULL) { 8665 if (job != NULL) {
8679 if (IsSuitableForOnStackReplacement(isolate, function, unoptimized) && 8666 if (FLAG_trace_osr) {
8680 Compiler::RecompileConcurrent(function, unoptimized, pc_offset)) { 8667 PrintF("[OSR - Found ready: ");
8681 if (function->IsMarkedForLazyRecompilation() || 8668 function->PrintName();
8682 function->IsMarkedForConcurrentRecompilation()) { 8669 PrintF(" at AST id %d]\n", ast_id.ToInt());
8683 // Prevent regular recompilation if we queue this for OSR.
8684 // TODO(yangguo): remove this as soon as OSR becomes one-shot.
8685 function->ReplaceCode(function->shared()->code());
8686 }
8687 return NULL;
8688 }
8689 // Fall through to the end in case of failure.
8690 } else {
8691 // TODO(titzer): don't install the OSR code into the function.
8692 ast_id = job->info()->osr_ast_id();
8693 result = Compiler::InstallOptimizedCode(job);
8694 } 8670 }
8695 } else if (IsSuitableForOnStackReplacement(isolate, function, unoptimized)) { 8671 result = Compiler::GetConcurrentlyOptimizedCode(job);
8696 ast_id = unoptimized->TranslatePcOffsetToAstId(pc_offset); 8672 } else if (result.is_null() &&
8697 ASSERT(!ast_id.IsNone()); 8673 IsSuitableForOnStackReplacement(isolate, function, caller_code)) {
8698 if (FLAG_trace_osr) { 8674 if (FLAG_trace_osr) {
8699 PrintF("[OSR - replacing at AST id %d in ", ast_id.ToInt()); 8675 PrintF("[OSR - Compiling: ");
8700 function->PrintName(); 8676 function->PrintName();
8701 PrintF("]\n"); 8677 PrintF(" at AST id %d]\n", ast_id.ToInt());
8702 } 8678 }
8703 // Attempt OSR compilation. 8679 result = Compiler::GetOptimizedCode(function, caller_code, mode, ast_id);
8704 result = JSFunction::CompileOsr(function, ast_id, CLEAR_EXCEPTION); 8680 if (result.is_identical_to(isolate->builtins()->InOptimizationQueue())) {
8681 // Optimization is queued. Return to check later.
8682 return NULL;
8683 }
8705 } 8684 }
8706 8685
8707 // Revert the patched back edge table, regardless of whether OSR succeeds. 8686 // Revert the patched back edge table, regardless of whether OSR succeeds.
8708 BackEdgeTable::Revert(isolate, *unoptimized); 8687 BackEdgeTable::Revert(isolate, *caller_code);
8709 8688
8710 // Check whether we ended up with usable optimized code. 8689 // Check whether we ended up with usable optimized code.
8711 if (!result.is_null() && result->kind() == Code::OPTIMIZED_FUNCTION) { 8690 if (!result.is_null() && result->kind() == Code::OPTIMIZED_FUNCTION) {
8712 DeoptimizationInputData* data = 8691 DeoptimizationInputData* data =
8713 DeoptimizationInputData::cast(result->deoptimization_data()); 8692 DeoptimizationInputData::cast(result->deoptimization_data());
8714 8693
8715 if (data->OsrPcOffset()->value() >= 0) { 8694 if (data->OsrPcOffset()->value() >= 0) {
8716 ASSERT(BailoutId(data->OsrAstId()->value()) == ast_id); 8695 ASSERT(BailoutId(data->OsrAstId()->value()) == ast_id);
8717 if (FLAG_trace_osr) { 8696 if (FLAG_trace_osr) {
8718 PrintF("[OSR - entry at AST id %d, offset %d in optimized code]\n", 8697 PrintF("[OSR - Entry at AST id %d, offset %d in optimized code]\n",
8719 ast_id.ToInt(), data->OsrPcOffset()->value()); 8698 ast_id.ToInt(), data->OsrPcOffset()->value());
8720 } 8699 }
8721 // TODO(titzer): this is a massive hack to make the deopt counts 8700 // TODO(titzer): this is a massive hack to make the deopt counts
8722 // match. Fix heuristics for reenabling optimizations! 8701 // match. Fix heuristics for reenabling optimizations!
8723 function->shared()->increment_deopt_count(); 8702 function->shared()->increment_deopt_count();
8703
8704 // TODO(titzer): Do not install code into the function.
8705 function->ReplaceCode(*result);
8724 return *result; 8706 return *result;
8725 } 8707 }
8726 } 8708 }
8727 8709
8710 // Failed.
8728 if (FLAG_trace_osr) { 8711 if (FLAG_trace_osr) {
8729 PrintF("[OSR - optimization failed for "); 8712 PrintF("[OSR - Failed: ");
8730 function->PrintName(); 8713 function->PrintName();
8731 PrintF("]\n"); 8714 PrintF(" at AST id %d]\n", ast_id.ToInt());
8732 } 8715 }
8733 8716
8734 if (function->IsMarkedForLazyRecompilation() || 8717 function->ReplaceCode(function->shared()->code());
8735 function->IsMarkedForConcurrentRecompilation()) {
8736 function->ReplaceCode(function->shared()->code());
8737 }
8738 return NULL; 8718 return NULL;
8739 } 8719 }
8740 8720
8741 8721
8742 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) { 8722 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) {
8743 SealHandleScope shs(isolate); 8723 SealHandleScope shs(isolate);
8744 ASSERT(args.length() == 2); 8724 ASSERT(args.length() == 2);
8745 #ifdef DEBUG 8725 #ifdef DEBUG
8746 CONVERT_SMI_ARG_CHECKED(interval, 0); 8726 CONVERT_SMI_ARG_CHECKED(interval, 0);
8747 CONVERT_SMI_ARG_CHECKED(timeout, 1); 8727 CONVERT_SMI_ARG_CHECKED(timeout, 1);
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
9429 9409
9430 // First check if this is a real stack overflow. 9410 // First check if this is a real stack overflow.
9431 if (isolate->stack_guard()->IsStackOverflow()) { 9411 if (isolate->stack_guard()->IsStackOverflow()) {
9432 return isolate->StackOverflow(); 9412 return isolate->StackOverflow();
9433 } 9413 }
9434 9414
9435 return Execution::HandleStackGuardInterrupt(isolate); 9415 return Execution::HandleStackGuardInterrupt(isolate);
9436 } 9416 }
9437 9417
9438 9418
9439 RUNTIME_FUNCTION(MaybeObject*, Runtime_TryInstallRecompiledCode) { 9419 RUNTIME_FUNCTION(MaybeObject*, Runtime_TryInstallOptimizedCode) {
9440 HandleScope scope(isolate); 9420 HandleScope scope(isolate);
9441 ASSERT(args.length() == 1); 9421 ASSERT(args.length() == 1);
9442 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 9422 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
9443 9423
9444 // First check if this is a real stack overflow. 9424 // First check if this is a real stack overflow.
9445 if (isolate->stack_guard()->IsStackOverflow()) { 9425 if (isolate->stack_guard()->IsStackOverflow()) {
9446 SealHandleScope shs(isolate); 9426 SealHandleScope shs(isolate);
9447 return isolate->StackOverflow(); 9427 return isolate->StackOverflow();
9448 } 9428 }
9449 9429
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
9678 !CodeGenerationFromStringsAllowed(isolate, context)) { 9658 !CodeGenerationFromStringsAllowed(isolate, context)) {
9679 Handle<Object> error_message = 9659 Handle<Object> error_message =
9680 context->ErrorMessageForCodeGenerationFromStrings(); 9660 context->ErrorMessageForCodeGenerationFromStrings();
9681 return isolate->Throw(*isolate->factory()->NewEvalError( 9661 return isolate->Throw(*isolate->factory()->NewEvalError(
9682 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); 9662 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)));
9683 } 9663 }
9684 9664
9685 // Compile source string in the native context. 9665 // Compile source string in the native context.
9686 ParseRestriction restriction = function_literal_only 9666 ParseRestriction restriction = function_literal_only
9687 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; 9667 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION;
9688 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 9668 Handle<JSFunction> fun = Compiler::GetFunctionFromEval(
9689 source, context, true, CLASSIC_MODE, restriction, RelocInfo::kNoPosition); 9669 source, context, CLASSIC_MODE, restriction, RelocInfo::kNoPosition);
9690 RETURN_IF_EMPTY_HANDLE(isolate, shared); 9670 RETURN_IF_EMPTY_HANDLE(isolate, fun);
9691 Handle<JSFunction> fun =
9692 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
9693 context,
9694 NOT_TENURED);
9695 return *fun; 9671 return *fun;
9696 } 9672 }
9697 9673
9698 9674
9699 static ObjectPair CompileGlobalEval(Isolate* isolate, 9675 static ObjectPair CompileGlobalEval(Isolate* isolate,
9700 Handle<String> source, 9676 Handle<String> source,
9701 Handle<Object> receiver, 9677 Handle<Object> receiver,
9702 LanguageMode language_mode, 9678 LanguageMode language_mode,
9703 int scope_position) { 9679 int scope_position) {
9704 Handle<Context> context = Handle<Context>(isolate->context()); 9680 Handle<Context> context = Handle<Context>(isolate->context());
9705 Handle<Context> native_context = Handle<Context>(context->native_context()); 9681 Handle<Context> native_context = Handle<Context>(context->native_context());
9706 9682
9707 // Check if native context allows code generation from 9683 // Check if native context allows code generation from
9708 // strings. Throw an exception if it doesn't. 9684 // strings. Throw an exception if it doesn't.
9709 if (native_context->allow_code_gen_from_strings()->IsFalse() && 9685 if (native_context->allow_code_gen_from_strings()->IsFalse() &&
9710 !CodeGenerationFromStringsAllowed(isolate, native_context)) { 9686 !CodeGenerationFromStringsAllowed(isolate, native_context)) {
9711 Handle<Object> error_message = 9687 Handle<Object> error_message =
9712 native_context->ErrorMessageForCodeGenerationFromStrings(); 9688 native_context->ErrorMessageForCodeGenerationFromStrings();
9713 isolate->Throw(*isolate->factory()->NewEvalError( 9689 isolate->Throw(*isolate->factory()->NewEvalError(
9714 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); 9690 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)));
9715 return MakePair(Failure::Exception(), NULL); 9691 return MakePair(Failure::Exception(), NULL);
9716 } 9692 }
9717 9693
9718 // Deal with a normal eval call with a string argument. Compile it 9694 // Deal with a normal eval call with a string argument. Compile it
9719 // and return the compiled function bound in the local context. 9695 // and return the compiled function bound in the local context.
9720 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 9696 static const ParseRestriction restriction = NO_PARSE_RESTRICTION;
9721 source, 9697 Handle<JSFunction> compiled = Compiler::GetFunctionFromEval(
9722 context, 9698 source, context, language_mode, restriction, scope_position);
9723 context->IsNativeContext(), 9699 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, compiled,
9724 language_mode,
9725 NO_PARSE_RESTRICTION,
9726 scope_position);
9727 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, shared,
9728 MakePair(Failure::Exception(), NULL)); 9700 MakePair(Failure::Exception(), NULL));
9729 Handle<JSFunction> compiled =
9730 isolate->factory()->NewFunctionFromSharedFunctionInfo(
9731 shared, context, NOT_TENURED);
9732 return MakePair(*compiled, *receiver); 9701 return MakePair(*compiled, *receiver);
9733 } 9702 }
9734 9703
9735 9704
9736 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { 9705 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) {
9737 HandleScope scope(isolate); 9706 HandleScope scope(isolate);
9738 ASSERT(args.length() == 5); 9707 ASSERT(args.length() == 5);
9739 9708
9740 Handle<Object> callee = args.at<Object>(0); 9709 Handle<Object> callee = args.at<Object>(0);
9741 9710
(...skipping 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after
12556 static_cast<BreakPositionAlignment>(statement_aligned_code); 12525 static_cast<BreakPositionAlignment>(statement_aligned_code);
12557 12526
12558 // Get the script from the script wrapper. 12527 // Get the script from the script wrapper.
12559 RUNTIME_ASSERT(wrapper->value()->IsScript()); 12528 RUNTIME_ASSERT(wrapper->value()->IsScript());
12560 Handle<Script> script(Script::cast(wrapper->value())); 12529 Handle<Script> script(Script::cast(wrapper->value()));
12561 12530
12562 // Set break point. 12531 // Set break point.
12563 if (!isolate->debug()->SetBreakPointForScript(script, break_point_object_arg, 12532 if (!isolate->debug()->SetBreakPointForScript(script, break_point_object_arg,
12564 &source_position, 12533 &source_position,
12565 alignment)) { 12534 alignment)) {
12566 return isolate->heap()->undefined_value(); 12535 return isolate->heap()->undefined_value();
12567 } 12536 }
12568 12537
12569 return Smi::FromInt(source_position); 12538 return Smi::FromInt(source_position);
12570 } 12539 }
12571 12540
12572 12541
12573 // Clear a break point 12542 // Clear a break point
12574 // args[0]: number: break point object 12543 // args[0]: number: break point object
12575 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearBreakPoint) { 12544 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearBreakPoint) {
12576 HandleScope scope(isolate); 12545 HandleScope scope(isolate);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
12716 Handle<Context> context, 12685 Handle<Context> context,
12717 Handle<Object> context_extension, 12686 Handle<Object> context_extension,
12718 Handle<Object> receiver, 12687 Handle<Object> receiver,
12719 Handle<String> source) { 12688 Handle<String> source) {
12720 if (context_extension->IsJSObject()) { 12689 if (context_extension->IsJSObject()) {
12721 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); 12690 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension);
12722 Handle<JSFunction> closure(context->closure(), isolate); 12691 Handle<JSFunction> closure(context->closure(), isolate);
12723 context = isolate->factory()->NewWithContext(closure, context, extension); 12692 context = isolate->factory()->NewWithContext(closure, context, extension);
12724 } 12693 }
12725 12694
12726 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 12695 Handle<JSFunction> eval_fun =
12727 source, 12696 Compiler::GetFunctionFromEval(source,
12728 context, 12697 context,
12729 context->IsNativeContext(), 12698 CLASSIC_MODE,
12730 CLASSIC_MODE, 12699 NO_PARSE_RESTRICTION,
12731 NO_PARSE_RESTRICTION, 12700 RelocInfo::kNoPosition);
12732 RelocInfo::kNoPosition); 12701 RETURN_IF_EMPTY_HANDLE(isolate, eval_fun);
12733 RETURN_IF_EMPTY_HANDLE(isolate, shared);
12734 12702
12735 Handle<JSFunction> eval_fun =
12736 isolate->factory()->NewFunctionFromSharedFunctionInfo(
12737 shared, context, NOT_TENURED);
12738 bool pending_exception; 12703 bool pending_exception;
12739 Handle<Object> result = Execution::Call( 12704 Handle<Object> result = Execution::Call(
12740 isolate, eval_fun, receiver, 0, NULL, &pending_exception); 12705 isolate, eval_fun, receiver, 0, NULL, &pending_exception);
12741 12706
12742 if (pending_exception) return Failure::Exception(); 12707 if (pending_exception) return Failure::Exception();
12743 12708
12744 // Skip the global proxy as it has no properties and always delegates to the 12709 // Skip the global proxy as it has no properties and always delegates to the
12745 // real global object. 12710 // real global object.
12746 if (result->IsJSGlobalProxy()) { 12711 if (result->IsJSGlobalProxy()) {
12747 result = Handle<JSObject>(JSObject::cast(result->GetPrototype(isolate))); 12712 result = Handle<JSObject>(JSObject::cast(result->GetPrototype(isolate)));
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
13143 return isolate->heap()->undefined_value(); 13108 return isolate->heap()->undefined_value();
13144 } 13109 }
13145 13110
13146 13111
13147 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugDisassembleFunction) { 13112 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugDisassembleFunction) {
13148 HandleScope scope(isolate); 13113 HandleScope scope(isolate);
13149 #ifdef DEBUG 13114 #ifdef DEBUG
13150 ASSERT(args.length() == 1); 13115 ASSERT(args.length() == 1);
13151 // Get the function and make sure it is compiled. 13116 // Get the function and make sure it is compiled.
13152 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0); 13117 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0);
13153 if (!JSFunction::EnsureCompiled(func, KEEP_EXCEPTION)) { 13118 if (!Compiler::EnsureCompiled(func, KEEP_EXCEPTION)) {
13154 return Failure::Exception(); 13119 return Failure::Exception();
13155 } 13120 }
13156 func->code()->PrintLn(); 13121 func->code()->PrintLn();
13157 #endif // DEBUG 13122 #endif // DEBUG
13158 return isolate->heap()->undefined_value(); 13123 return isolate->heap()->undefined_value();
13159 } 13124 }
13160 13125
13161 13126
13162 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugDisassembleConstructor) { 13127 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugDisassembleConstructor) {
13163 HandleScope scope(isolate); 13128 HandleScope scope(isolate);
13164 #ifdef DEBUG 13129 #ifdef DEBUG
13165 ASSERT(args.length() == 1); 13130 ASSERT(args.length() == 1);
13166 // Get the function and make sure it is compiled. 13131 // Get the function and make sure it is compiled.
13167 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0); 13132 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0);
13168 if (!JSFunction::EnsureCompiled(func, KEEP_EXCEPTION)) { 13133 if (!Compiler::EnsureCompiled(func, KEEP_EXCEPTION)) {
13169 return Failure::Exception(); 13134 return Failure::Exception();
13170 } 13135 }
13171 func->shared()->construct_stub()->PrintLn(); 13136 func->shared()->construct_stub()->PrintLn();
13172 #endif // DEBUG 13137 #endif // DEBUG
13173 return isolate->heap()->undefined_value(); 13138 return isolate->heap()->undefined_value();
13174 } 13139 }
13175 13140
13176 13141
13177 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionGetInferredName) { 13142 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionGetInferredName) {
13178 SealHandleScope shs(isolate); 13143 SealHandleScope shs(isolate);
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
14893 // Handle last resort GC and make sure to allow future allocations 14858 // Handle last resort GC and make sure to allow future allocations
14894 // to grow the heap without causing GCs (if possible). 14859 // to grow the heap without causing GCs (if possible).
14895 isolate->counters()->gc_last_resort_from_js()->Increment(); 14860 isolate->counters()->gc_last_resort_from_js()->Increment();
14896 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14861 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14897 "Runtime::PerformGC"); 14862 "Runtime::PerformGC");
14898 } 14863 }
14899 } 14864 }
14900 14865
14901 14866
14902 } } // namespace v8::internal 14867 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698