Commit 217b4cd6 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Check for the termination request in STACK_CHECK

Bug: v8:9877
Change-Id: I55cedfd2748f00f989172d804eec735aa6c19365
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2742618Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73290}
parent 16175b15
......@@ -2188,13 +2188,21 @@ class StackLimitCheck {
Isolate* isolate_;
};
#define STACK_CHECK(isolate, result_value) \
do { \
StackLimitCheck stack_check(isolate); \
if (stack_check.HasOverflowed()) { \
isolate->StackOverflow(); \
return result_value; \
} \
// This macro may be used in context that disallows JS execution.
// That is why it checks only for a stack overflow and termination.
#define STACK_CHECK(isolate, result_value) \
do { \
StackLimitCheck stack_check(isolate); \
if (stack_check.InterruptRequested()) { \
if (stack_check.HasOverflowed()) { \
isolate->StackOverflow(); \
return result_value; \
} \
if (isolate->stack_guard()->HasTerminationRequest()) { \
isolate->TerminateExecution(); \
return result_value; \
} \
} \
} while (false)
class StackTraceFailureMessage {
......
......@@ -21832,7 +21832,6 @@ class RequestInterruptTestWithMathAbs
}
};
TEST(RequestInterruptTestWithFunctionCall) {
RequestInterruptTestWithFunctionCall().RunTest();
}
......@@ -21862,7 +21861,6 @@ TEST(RequestInterruptTestWithMathAbs) {
RequestInterruptTestWithMathAbs().RunTest();
}
class RequestMultipleInterrupts : public RequestInterruptTestBase {
public:
RequestMultipleInterrupts() : i_thread(this), counter_(0) {}
......@@ -25159,10 +25157,10 @@ THREADED_TEST(ReceiverConversionForAccessors) {
CHECK(CompileRun("acc.call(undefined) == 42")->BooleanValue(isolate));
}
class FutexInterruptionThread : public v8::base::Thread {
class TerminateExecutionThread : public v8::base::Thread {
public:
explicit FutexInterruptionThread(v8::Isolate* isolate)
: Thread(Options("FutexInterruptionThread")), isolate_(isolate) {}
explicit TerminateExecutionThread(v8::Isolate* isolate)
: Thread(Options("TerminateExecutionThread")), isolate_(isolate) {}
void Run() override {
// Wait a bit before terminating.
......@@ -25174,14 +25172,13 @@ class FutexInterruptionThread : public v8::base::Thread {
v8::Isolate* isolate_;
};
TEST(FutexInterruption) {
i::FLAG_harmony_sharedarraybuffer = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
FutexInterruptionThread timeout_thread(isolate);
TerminateExecutionThread timeout_thread(isolate);
v8::TryCatch try_catch(CcTest::isolate());
CHECK(timeout_thread.Start());
......@@ -25194,6 +25191,28 @@ TEST(FutexInterruption) {
timeout_thread.Join();
}
TEST(StackCheckTermination) {
v8::Isolate* isolate = CcTest::isolate();
i::Isolate* i_isolate = CcTest::i_isolate();
v8::HandleScope scope(isolate);
LocalContext env;
TerminateExecutionThread timeout_thread(isolate);
v8::TryCatch try_catch(isolate);
CHECK(timeout_thread.Start());
auto should_continue = [i_isolate]() {
using StackLimitCheck = i::StackLimitCheck;
STACK_CHECK(i_isolate, false);
return true;
};
while (should_continue()) {
}
if (i_isolate->has_pending_exception()) i_isolate->ReportPendingMessages();
CHECK(try_catch.HasTerminated());
timeout_thread.Join();
}
static int nb_uncaught_exception_callback_calls = 0;
......@@ -5541,39 +5541,44 @@ TEST(TerminateOnResumeFromMicrotask) {
class FutexInterruptionThread : public v8::base::Thread {
public:
FutexInterruptionThread(v8::Isolate* isolate, v8::base::Semaphore* sem)
FutexInterruptionThread(v8::Isolate* isolate, v8::base::Semaphore* enter,
v8::base::Semaphore* exit)
: Thread(Options("FutexInterruptionThread")),
isolate_(isolate),
sem_(sem) {}
enter_(enter),
exit_(exit) {}
void Run() override {
// Wait a bit before terminating.
v8::base::OS::Sleep(v8::base::TimeDelta::FromMilliseconds(100));
sem_->Wait();
enter_->Wait();
v8::debug::SetTerminateOnResume(isolate_);
exit_->Signal();
}
private:
v8::Isolate* isolate_;
v8::base::Semaphore* sem_;
v8::base::Semaphore* enter_;
v8::base::Semaphore* exit_;
};
namespace {
class SemaphoreTriggerOnBreak : public v8::debug::DebugDelegate {
public:
SemaphoreTriggerOnBreak() : sem_(0) {}
SemaphoreTriggerOnBreak() : enter_(0), exit_(0) {}
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
const std::vector<v8::debug::BreakpointId>&
inspector_break_points_hit) override {
break_count_++;
sem_.Signal();
enter_.Signal();
exit_.Wait();
}
v8::base::Semaphore* semaphore() { return &sem_; }
v8::base::Semaphore* enter() { return &enter_; }
v8::base::Semaphore* exit() { return &exit_; }
int break_count() const { return break_count_; }
private:
v8::base::Semaphore sem_;
v8::base::Semaphore enter_;
v8::base::Semaphore exit_;
int break_count_ = 0;
};
} // anonymous namespace
......@@ -5586,8 +5591,8 @@ TEST(TerminateOnResumeFromOtherThread) {
SemaphoreTriggerOnBreak delegate;
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
FutexInterruptionThread timeout_thread(env->GetIsolate(),
delegate.semaphore());
FutexInterruptionThread timeout_thread(env->GetIsolate(), delegate.enter(),
delegate.exit());
CHECK(timeout_thread.Start());
v8::Local<v8::Context> context = env.local();
......@@ -5618,7 +5623,7 @@ namespace {
class InterruptionBreakRightNow : public v8::base::Thread {
public:
explicit InterruptionBreakRightNow(v8::Isolate* isolate)
: Thread(Options("FutexInterruptionThread")), isolate_(isolate) {}
: Thread(Options("InterruptionBreakRightNow")), isolate_(isolate) {}
void Run() override {
// Wait a bit before terminating.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment