From 16ff37db4a416523e54c473640ccf52b53c6655e Mon Sep 17 00:00:00 2001 From: ulan Date: Fri, 20 Mar 2015 02:52:17 -0700 Subject: [PATCH] Check for GC interrupt in JSON parser. BUG=v8:3974 LOG=NO Review URL: https://codereview.chromium.org/1021523002 Cr-Commit-Position: refs/heads/master@{#27334} --- src/execution.cc | 7 +++++++ src/execution.h | 4 ++++ src/json-parser.h | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/src/execution.cc b/src/execution.cc index d480daa47..7ae67410e 100644 --- a/src/execution.cc +++ b/src/execution.cc @@ -651,6 +651,13 @@ Handle Execution::GetStackTraceLine(Handle recv, } +void StackGuard::CheckAndHandleGCInterrupt() { + if (CheckAndClearInterrupt(GC_REQUEST)) { + isolate_->heap()->HandleGCRequest(); + } +} + + Object* StackGuard::HandleInterrupts() { if (CheckAndClearInterrupt(GC_REQUEST)) { isolate_->heap()->HandleGCRequest(); diff --git a/src/execution.h b/src/execution.h index 47cbb08f0..870bb9118 100644 --- a/src/execution.h +++ b/src/execution.h @@ -197,6 +197,10 @@ class StackGuard FINAL { // stack overflow, then handle the interruption accordingly. Object* HandleInterrupts(); + bool InterruptRequested() { return GetCurrentStackPosition() < climit(); } + + void CheckAndHandleGCInterrupt(); + private: StackGuard(); diff --git a/src/json-parser.h b/src/json-parser.h index 0cfe44640..7cf80966d 100644 --- a/src/json-parser.h +++ b/src/json-parser.h @@ -261,6 +261,11 @@ Handle JsonParser::ParseJsonValue() { return Handle::null(); } + if (isolate_->stack_guard()->InterruptRequested()) { + // Avoid blocking GC in long running parser (v8:3974). + isolate_->stack_guard()->CheckAndHandleGCInterrupt(); + } + if (c0_ == '"') return ParseJsonString(); if ((c0_ >= '0' && c0_ <= '9') || c0_ == '-') return ParseJsonNumber(); if (c0_ == '{') return ParseJsonObject(); -- 2.34.1