From 87dfaa895170f692f433d7d2daa812be2a1f0e6a Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 3 Jul 2014 14:03:10 +0000 Subject: [PATCH] Remove unnecessary check in RegExpExecStub. R=ulan@chromium.org BUG=v8:592 LOG=N Review URL: https://codereview.chromium.org/363313002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22202 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/code-stubs-arm.cc | 9 ++------- src/arm64/code-stubs-arm64.cc | 7 +------ src/ia32/code-stubs-ia32.cc | 11 +++-------- src/x64/code-stubs-x64.cc | 11 +++-------- test/mjsunit/regexp-stack-overflow.js | 22 ++++++++++++++++++++++ 5 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 test/mjsunit/regexp-stack-overflow.js diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 3870015..fa8f807 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -2516,17 +2516,12 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); // If not exception it can only be retry. Handle that in the runtime system. __ b(ne, &runtime); - // Result must now be exception. If there is no pending exception already a - // stack overflow (on the backtrack stack) was detected in RegExp code but - // haven't created the exception yet. Handle that in the runtime system. - // TODO(592): Rerunning the RegExp to get the stack overflow exception. + + // Result must now be exception. __ mov(r1, Operand(isolate()->factory()->the_hole_value())); __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, isolate()))); __ ldr(r0, MemOperand(r2, 0)); - __ cmp(r0, r1); - __ b(eq, &runtime); - __ str(r1, MemOperand(r2, 0)); // Clear pending exception. // Check if the exception is a termination. If so, throw as uncatchable. diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc index 6dc564d..70eae43 100644 --- a/src/arm64/code-stubs-arm64.cc +++ b/src/arm64/code-stubs-arm64.cc @@ -2855,17 +2855,12 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { __ Bind(&exception); Register exception_value = x0; - // A stack overflow (on the backtrack stack) may have occured - // in the RegExp code but no exception has been created yet. - // If there is no pending exception, handle that in the runtime system. + // Result must now be exception. __ Mov(x10, Operand(isolate()->factory()->the_hole_value())); __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress, isolate()))); __ Ldr(exception_value, MemOperand(x11)); - __ Cmp(x10, exception_value); - __ B(eq, &runtime); - __ Str(x10, MemOperand(x11)); // Clear pending exception. // Check if the exception is a termination. If so, throw as uncatchable. diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index 8a05e00..0590ad4 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -1596,19 +1596,14 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); // If not exception it can only be retry. Handle that in the runtime system. __ j(not_equal, &runtime); - // Result must now be exception. If there is no pending exception already a - // stack overflow (on the backtrack stack) was detected in RegExp code but - // haven't created the exception yet. Handle that in the runtime system. - // TODO(592): Rerunning the RegExp to get the stack overflow exception. + + // Result must now be exception. ExternalReference pending_exception(Isolate::kPendingExceptionAddress, isolate()); __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); __ mov(eax, Operand::StaticVariable(pending_exception)); - __ cmp(edx, eax); - __ j(equal, &runtime); - // For exception, throw the exception again. - // Clear the pending exception variable. + // Clear pending exception. __ mov(Operand::StaticVariable(pending_exception), edx); // Special handling of termination exceptions which are uncatchable diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index c08e38b..62ce31c 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -1574,19 +1574,14 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { __ ret(REG_EXP_EXEC_ARGUMENT_COUNT * kPointerSize); __ bind(&exception); - // Result must now be exception. If there is no pending exception already a - // stack overflow (on the backtrack stack) was detected in RegExp code but - // haven't created the exception yet. Handle that in the runtime system. - // TODO(592): Rerunning the RegExp to get the stack overflow exception. + // Result must now be exception. ExternalReference pending_exception_address( Isolate::kPendingExceptionAddress, isolate()); Operand pending_exception_operand = masm->ExternalOperand(pending_exception_address, rbx); - __ movp(rax, pending_exception_operand); __ LoadRoot(rdx, Heap::kTheHoleValueRootIndex); - __ cmpp(rax, rdx); - __ j(equal, &runtime); - __ movp(pending_exception_operand, rdx); + __ movp(rax, pending_exception_operand); + __ movp(pending_exception_operand, rdx); // Clear pending exception. __ CompareRoot(rax, Heap::kTerminationExceptionRootIndex); Label termination_exception; diff --git a/test/mjsunit/regexp-stack-overflow.js b/test/mjsunit/regexp-stack-overflow.js new file mode 100644 index 0000000..b6232a8 --- /dev/null +++ b/test/mjsunit/regexp-stack-overflow.js @@ -0,0 +1,22 @@ +// 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: --stack-size=100 + +var result = null; +var type = true; +var re = /\w/; +re.test("a"); // Trigger regexp compile. + +function rec() { + try { + return rec(); + } catch (e) { + if (!(e instanceof RangeError)) type = false; + return re.test("b"); + } +} + +assertTrue(rec()); +assertTrue(type); -- 2.7.4