Fix %OptimizeFunctionOnNextCall to actually work when the function has not yet been compiled.
R=yangguo@chromium.org BUG= Review URL: https://codereview.chromium.org/543643002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23687 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
7712ed28e8
commit
67b89f9db6
@ -1246,7 +1246,14 @@ MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
|
||||
PostponeInterruptsScope postpone(isolate);
|
||||
|
||||
Handle<SharedFunctionInfo> shared = info->shared_info();
|
||||
DCHECK_NE(ScopeInfo::Empty(isolate), shared->scope_info());
|
||||
if (ScopeInfo::Empty(isolate) == shared->scope_info()) {
|
||||
// The function was never compiled. Compile it unoptimized first.
|
||||
CompilationInfoWithZone nested(function);
|
||||
nested.EnableDeoptimizationSupport();
|
||||
if (!GetUnoptimizedCodeCommon(&nested).ToHandle(¤t_code)) {
|
||||
return MaybeHandle<Code>();
|
||||
}
|
||||
}
|
||||
int compiled_size = shared->end_position() - shared->start_position();
|
||||
isolate->counters()->total_compile_size()->Increment(compiled_size);
|
||||
current_code->set_profiler_ticks(0);
|
||||
|
@ -4777,9 +4777,10 @@ int Code::profiler_ticks() {
|
||||
|
||||
|
||||
void Code::set_profiler_ticks(int ticks) {
|
||||
DCHECK_EQ(FUNCTION, kind());
|
||||
DCHECK(ticks < 256);
|
||||
WRITE_BYTE_FIELD(this, kProfilerTicksOffset, ticks);
|
||||
if (kind() == FUNCTION) {
|
||||
WRITE_BYTE_FIELD(this, kProfilerTicksOffset, ticks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -9144,7 +9144,6 @@ void JSFunction::JSFunctionIterateBody(int object_size, ObjectVisitor* v) {
|
||||
|
||||
|
||||
void JSFunction::MarkForOptimization() {
|
||||
DCHECK(is_compiled() || GetIsolate()->DebuggerHasBreakPoints());
|
||||
DCHECK(!IsOptimized());
|
||||
DCHECK(shared()->allows_lazy_compilation() ||
|
||||
code()->optimizable());
|
||||
|
@ -8457,15 +8457,9 @@ RUNTIME_FUNCTION(Runtime_CompileOptimized) {
|
||||
CONVERT_BOOLEAN_ARG_CHECKED(concurrent, 1);
|
||||
|
||||
Handle<Code> unoptimized(function->shared()->code());
|
||||
if (!function->shared()->is_compiled()) {
|
||||
// If the function is not compiled, do not optimize.
|
||||
// This can happen if the debugger is activated and
|
||||
// the function is returned to the not compiled state.
|
||||
// TODO(yangguo): reconsider this.
|
||||
function->ReplaceCode(function->shared()->code());
|
||||
} else if (!isolate->use_crankshaft() ||
|
||||
function->shared()->optimization_disabled() ||
|
||||
isolate->DebuggerHasBreakPoints()) {
|
||||
if (!isolate->use_crankshaft() ||
|
||||
function->shared()->optimization_disabled() ||
|
||||
isolate->DebuggerHasBreakPoints()) {
|
||||
// If the function is not optimizable or debugger is active continue
|
||||
// using the code from the full compiler.
|
||||
if (FLAG_trace_opt) {
|
||||
@ -8476,16 +8470,16 @@ RUNTIME_FUNCTION(Runtime_CompileOptimized) {
|
||||
isolate->DebuggerHasBreakPoints() ? "T" : "F");
|
||||
}
|
||||
function->ReplaceCode(*unoptimized);
|
||||
return function->code();
|
||||
}
|
||||
|
||||
Compiler::ConcurrencyMode mode =
|
||||
concurrent ? Compiler::CONCURRENT : Compiler::NOT_CONCURRENT;
|
||||
Handle<Code> code;
|
||||
if (Compiler::GetOptimizedCode(function, unoptimized, mode).ToHandle(&code)) {
|
||||
function->ReplaceCode(*code);
|
||||
} else {
|
||||
Compiler::ConcurrencyMode mode = concurrent ? Compiler::CONCURRENT
|
||||
: Compiler::NOT_CONCURRENT;
|
||||
Handle<Code> code;
|
||||
if (Compiler::GetOptimizedCode(
|
||||
function, unoptimized, mode).ToHandle(&code)) {
|
||||
function->ReplaceCode(*code);
|
||||
} else {
|
||||
function->ReplaceCode(*unoptimized);
|
||||
}
|
||||
function->ReplaceCode(*unoptimized);
|
||||
}
|
||||
|
||||
DCHECK(function->code()->kind() == Code::FUNCTION ||
|
||||
@ -8641,11 +8635,7 @@ RUNTIME_FUNCTION(Runtime_OptimizeFunctionOnNextCall) {
|
||||
RUNTIME_ASSERT(args.length() == 1 || args.length() == 2);
|
||||
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
|
||||
|
||||
if (!function->IsOptimizable() &&
|
||||
!function->IsMarkedForConcurrentOptimization() &&
|
||||
!function->IsInOptimizationQueue()) {
|
||||
return isolate->heap()->undefined_value();
|
||||
}
|
||||
if (function->IsOptimized()) return isolate->heap()->undefined_value();
|
||||
|
||||
function->MarkForOptimization();
|
||||
|
||||
|
13
test/mjsunit/compiler/opt-next-call.js
Normal file
13
test/mjsunit/compiler/opt-next-call.js
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2014 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --allow-natives-syntax
|
||||
|
||||
function foo() {
|
||||
return "fooed";
|
||||
}
|
||||
|
||||
%OptimizeFunctionOnNextCall(foo);
|
||||
assertEquals("fooed", foo());
|
||||
assertOptimized(foo);
|
Loading…
Reference in New Issue
Block a user