Revision: 23687
Author:   [email protected]
Date:     Thu Sep  4 11:27:20 2014 UTC
Log: Fix %OptimizeFunctionOnNextCall to actually work when the function has not yet been compiled.

[email protected]
BUG=

Review URL: https://codereview.chromium.org/543643002
https://code.google.com/p/v8/source/detail?r=23687

Added:
 /branches/bleeding_edge/test/mjsunit/compiler/opt-next-call.js
Modified:
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/runtime.cc

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/compiler/opt-next-call.js Thu Sep 4 11:27:20 2014 UTC
@@ -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);
=======================================
--- /branches/bleeding_edge/src/compiler.cc     Tue Sep  2 07:07:52 2014 UTC
+++ /branches/bleeding_edge/src/compiler.cc     Thu Sep  4 11:27:20 2014 UTC
@@ -1246,7 +1246,14 @@
   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(&current_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);
=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Tue Sep  2 13:36:35 2014 UTC
+++ /branches/bleeding_edge/src/objects-inl.h   Thu Sep  4 11:27:20 2014 UTC
@@ -4777,9 +4777,10 @@


 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);
+  }
 }


=======================================
--- /branches/bleeding_edge/src/objects.cc      Wed Sep  3 14:05:55 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Thu Sep  4 11:27:20 2014 UTC
@@ -9144,7 +9144,6 @@


 void JSFunction::MarkForOptimization() {
-  DCHECK(is_compiled() || GetIsolate()->DebuggerHasBreakPoints());
   DCHECK(!IsOptimized());
   DCHECK(shared()->allows_lazy_compilation() ||
          code()->optimizable());
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Wed Sep  3 14:05:55 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Thu Sep  4 11:27:20 2014 UTC
@@ -8457,15 +8457,9 @@
   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 @@
           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_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();

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to