From 73d8bb13e2a9cd08dd23eaad27f44bb161fb375d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Crelier?= Date: Fri, 31 Aug 2018 23:10:30 +0000 Subject: [PATCH] [VM interpreter] Consider scheduled interrupts when checking for stack overflow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Minor cleanup (not a bug): do not share result slot with passed argument in runtime call. Change-Id: Ib4565b692b03d485de75cc519b98b5ad6f2c8026 Reviewed-on: https://dart-review.googlesource.com/72548 Commit-Queue: Régis Crelier Reviewed-by: Alexander Markov Reviewed-by: Ryan Macnak --- runtime/vm/interpreter.cc | 25 ++++++++++++++----------- runtime/vm/thread.h | 3 +++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/runtime/vm/interpreter.cc b/runtime/vm/interpreter.cc index 610b79d3117..a12afa7c0a8 100644 --- a/runtime/vm/interpreter.cc +++ b/runtime/vm/interpreter.cc @@ -1695,15 +1695,16 @@ bool Interpreter::AssertAssignable(Thread* thread, AssertAssignableCallRuntime: // TODO(regis): Modify AssertAssignable bytecode to expect arguments in same // order as the TypeCheck runtime call, so this copying can be avoided. - call_top[1] = args[0]; // instance - call_top[2] = args[3]; // type - call_top[3] = args[1]; // instantiator type args - call_top[4] = args[2]; // function type args - call_top[5] = args[4]; // name - call_top[6] = cache; - call_top[7] = Smi::New(kTypeCheckFromInline); - Exit(thread, FP, call_top + 8, pc); - NativeArguments native_args(thread, 7, call_top + 1, call_top + 1); + call_top[1] = 0; // Unused result. + call_top[2] = args[0]; // Instance. + call_top[3] = args[3]; // Type. + call_top[4] = args[1]; // Instantiator type args. + call_top[5] = args[2]; // Function type args. + call_top[6] = args[4]; // Name. + call_top[7] = cache; + call_top[8] = Smi::New(kTypeCheckFromInline); + Exit(thread, FP, call_top + 9, pc); + NativeArguments native_args(thread, 7, call_top + 2, call_top + 1); return InvokeRuntime(thread, this, DRT_TypeCheck, native_args); } @@ -2086,8 +2087,10 @@ RawObject* Interpreter::Call(RawFunction* function, { BYTECODE(CheckStack, A); { - // Using the interpreter stack limit and not the thread stack limit. - if (reinterpret_cast(SP) >= stack_limit()) { + // Check the interpreter's own stack limit for actual interpreter's stack + // overflows, and also the thread's stack limit for scheduled interrupts. + if (reinterpret_cast(SP) >= stack_limit() || + thread->HasScheduledInterrupts()) { Exit(thread, FP, SP + 1, pc); NativeArguments args(thread, 0, NULL, NULL); INVOKE_RUNTIME(DRT_StackOverflow, args); diff --git a/runtime/vm/thread.h b/runtime/vm/thread.h index 5ad3d6e38c5..608c165e0a3 100644 --- a/runtime/vm/thread.h +++ b/runtime/vm/thread.h @@ -304,6 +304,9 @@ class Thread : public BaseThread { void ScheduleInterruptsLocked(uword interrupt_bits); RawError* HandleInterrupts(); uword GetAndClearInterrupts(); + bool HasScheduledInterrupts() const { + return (stack_limit_ & kInterruptsMask) != 0; + } // OSThread corresponding to this thread. OSThread* os_thread() const { return os_thread_; }