Reviewers: titzer,

Description:
[turbofan] Add JSStackCheck into loop bodies.

This allows loopy TurboFan code to be interrupted by placing a stack
check (i.e. JSStackCheck node) into each loop. Note that we currently
limit this to non-asm.js code. Also note that stack checks are actually
placed after loop headers and not at back-branches, which allows us to
reuse existing BailoutIds from Crankshaft.

[email protected]

Please review this at https://codereview.chromium.org/1065923002/

Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-compiler-toplevel

Affected files (+6, -19 lines):
  M src/compiler.cc
  M src/compiler/ast-graph-builder.cc
  M test/cctest/test-api.cc
  M test/cctest/test-debug.cc
  M test/cctest/test-thread-termination.cc


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index a95fe866d99f8e73170e4fee8740c7cbe616e471..00a228238f98574a0949ba396a29ac32c3d2d220 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1484,12 +1484,6 @@ MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
     return MaybeHandle<Code>();
   }

- // TODO(titzer): Some top-level code times out because of missing interrupt - // checks at back-branches, these are currently marked with --no-turbo-osr.
-  if (shared->is_toplevel() && !FLAG_turbo_osr) {
-    return MaybeHandle<Code>();
-  }
-
   info->SetOptimizing(osr_ast_id, current_code);

   if (mode == CONCURRENT) {
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index 306afb6c12b14b1fe1cc1735a03394ac24210e0b..36f684070cbb9dab81bd91adbbe6283e55669584 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -2487,6 +2487,12 @@ void AstGraphBuilder::VisitIfNotNull(Statement* stmt) {
 void AstGraphBuilder::VisitIterationBody(IterationStatement* stmt,
                                          LoopBuilder* loop) {
   ControlScopeForIteration scope(this, stmt, loop);
+  // TODO(mstarzinger): For now we only allow to interrupt non-asm.js code,
+ // which is a gigantic hack and should be extended to all code at some point.
+  if (!info()->shared_info()->asm_function()) {
+    Node* node = NewNode(javascript()->StackCheck());
+    PrepareFrameState(node, stmt->StackCheckId());
+  }
   Visit(stmt->body());
 }

Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a4587c7a997358d1858e8b962861aad1d923ddcc..b246f16858a18a2e560289c92161f5ff60db322e 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -20031,7 +20031,6 @@ class RequestInterruptTestWithFunctionCall
isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
     env_->Global()->Set(v8_str("ShouldContinue"), func);

-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("while (ShouldContinue()) { }");
   }
 };
@@ -20047,7 +20046,6 @@ class RequestInterruptTestWithMethodCall
isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)));
     env_->Global()->Set(v8_str("Klass"), t->GetFunction());

-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
   }
 };
@@ -20063,7 +20061,6 @@ class RequestInterruptTestWithAccessor
isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)));
     env_->Global()->Set(v8_str("Klass"), t->GetFunction());

-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("var obj = new Klass; while (obj.shouldContinue) { }");
   }
 };
@@ -20081,7 +20078,6 @@ class RequestInterruptTestWithNativeAccessor
         v8::External::New(isolate_, this));
     env_->Global()->Set(v8_str("Klass"), t->GetFunction());

-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("var obj = new Klass; while (obj.shouldContinue) { }");
   }

@@ -20111,7 +20107,6 @@ class RequestInterruptTestWithMethodCallAndInterceptor

     env_->Global()->Set(v8_str("Klass"), t->GetFunction());

-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
   }

@@ -20136,7 +20131,6 @@ class RequestInterruptTestWithMathAbs
         v8::External::New(isolate_, this)));

     i::FLAG_allow_natives_syntax = true;
-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("function loopish(o) {"
                "  var pre = 10;"
                "  while (o.abs(1) > 0) {"
@@ -20220,7 +20214,6 @@ class RequestMultipleInterrupts : public RequestInterruptTestBase { isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
     env_->Global()->Set(v8_str("ShouldContinue"), func);

-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("while (ShouldContinue()) { }");
   }

Index: test/cctest/test-debug.cc
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index 6569942c6168c21195770fb470d248e5f4dc2d70..4f864f63a8917a6887757876b61c140019a4bf54 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -6697,7 +6697,6 @@ TEST(ProcessDebugMessagesThreaded) {
       v8::FunctionTemplate::New(isolate, StartSendingCommands);
   env->Global()->Set(v8_str("start"), start->GetFunction());

-  i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
   CompileRun("start(); while (true) { }");

   CHECK_EQ(20, counting_message_handler_counter);
Index: test/cctest/test-thread-termination.cc
diff --git a/test/cctest/test-thread-termination.cc b/test/cctest/test-thread-termination.cc index e1f218ced7d4f72bfa6d9890df875ba2e5eb5a3e..250e9a344ada7b818c635dc2ce78f1c926e92649 100644
--- a/test/cctest/test-thread-termination.cc
+++ b/test/cctest/test-thread-termination.cc
@@ -152,7 +152,6 @@ TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) {
   // Run a loop that will be infinite if thread termination does not work.
   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
       CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
-  i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
   v8::Script::Compile(source)->Run();
   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
   // Test that we can run the code again after thread termination.
@@ -193,7 +192,6 @@ TEST(TerminateOnlyV8ThreadFromOtherThread) {
   // Run a loop that will be infinite if thread termination does not work.
   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
       CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
-  i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
   v8::Script::Compile(source)->Run();

   thread.Join();
@@ -362,7 +360,6 @@ TEST(TerminateCancelTerminateFromThreadItself) {
   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
       isolate, "try { doloop(); } catch(e) { fail(); } 'completed';");
-  i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
   // Check that execution completed with correct return value.
   CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
 }
@@ -379,7 +376,6 @@ void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) {
   // Enqueue another should-not-run task to ensure we clean out the queue
   // when we terminate.
isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
-  i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
   CompileRun("terminate(); while (true) { }");
   CHECK(v8::V8::IsExecutionTerminating());
 }
@@ -509,7 +505,6 @@ TEST(TerminationInInnerTryCall) {
   v8::Context::Scope context_scope(context);
   {
     v8::TryCatch try_catch;
-    i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
     CompileRun("inner_try_call_terminate()");
     CHECK(try_catch.HasTerminated());
   }


--
--
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