Fix issue 974.
When entering a finally block in unoptimized code, we unconditionally save the accumulator register in the stack in case it holds a return value or an exception. In the case of a break, continue, or falling off the end of the try or catch block, this value is unpredictable and not necessarily safe for GC. Review URL: http://codereview.chromium.org/5883003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6035 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
c03c71a937
commit
ace6290452
@ -206,6 +206,11 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::ClearAccumulator() {
|
||||
__ mov(r0, Operand(Smi::FromInt(0)));
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) {
|
||||
Comment cmnt(masm_, "[ Stack check");
|
||||
Label ok;
|
||||
|
@ -946,6 +946,11 @@ void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
|
||||
SetStatementPosition(stmt);
|
||||
NestedStatement* current = nesting_stack_;
|
||||
int stack_depth = 0;
|
||||
// When continuing, we clobber the unpredictable value in the accumulator
|
||||
// with one that's safe for GC. If we hit an exit from the try block of
|
||||
// try...finally on our way out, we will unconditionally preserve the
|
||||
// accumulator on the stack.
|
||||
ClearAccumulator();
|
||||
while (!current->IsContinueTarget(stmt->target())) {
|
||||
stack_depth = current->Exit(stack_depth);
|
||||
current = current->outer();
|
||||
@ -962,6 +967,11 @@ void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
|
||||
SetStatementPosition(stmt);
|
||||
NestedStatement* current = nesting_stack_;
|
||||
int stack_depth = 0;
|
||||
// When breaking, we clobber the unpredictable value in the accumulator
|
||||
// with one that's safe for GC. If we hit an exit from the try block of
|
||||
// try...finally on our way out, we will unconditionally preserve the
|
||||
// accumulator on the stack.
|
||||
ClearAccumulator();
|
||||
while (!current->IsBreakTarget(stmt->target())) {
|
||||
stack_depth = current->Exit(stack_depth);
|
||||
current = current->outer();
|
||||
@ -1235,7 +1245,10 @@ void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
|
||||
Visit(stmt->try_block());
|
||||
__ PopTryHandler();
|
||||
}
|
||||
// Execute the finally block on the way out.
|
||||
// Execute the finally block on the way out. Clobber the unpredictable
|
||||
// value in the accumulator with one that's safe for GC. The finally
|
||||
// block will unconditionally preserve the accumulator on the stack.
|
||||
ClearAccumulator();
|
||||
__ Call(&finally_entry);
|
||||
}
|
||||
|
||||
|
@ -286,6 +286,10 @@ class FullCodeGenerator: public AstVisitor {
|
||||
|
||||
static const InlineFunctionGenerator kInlineFunctionGenerators[];
|
||||
|
||||
// A platform-specific utility to overwrite the accumulator register
|
||||
// with a GC-safe value.
|
||||
void ClearAccumulator();
|
||||
|
||||
// Compute the frame pointer relative offset for a given local or
|
||||
// parameter slot.
|
||||
int SlotOffset(Slot* slot);
|
||||
|
@ -251,6 +251,11 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::ClearAccumulator() {
|
||||
__ Set(eax, Immediate(Smi::FromInt(0)));
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) {
|
||||
Comment cmnt(masm_, "[ Stack check");
|
||||
NearLabel ok;
|
||||
|
@ -198,6 +198,11 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::ClearAccumulator() {
|
||||
__ xor(rax, rax);
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) {
|
||||
Comment cmnt(masm_, "[ Stack check");
|
||||
NearLabel ok;
|
||||
|
32
test/mjsunit/regress/regress-974.js
Normal file
32
test/mjsunit/regress/regress-974.js
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2010 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Flags: --expose-gc
|
||||
|
||||
// Verify that GC is safe in a finally block entered by falling off the try
|
||||
// block.
|
||||
eval("(function(){try { } catch(x) { } finally { gc() }})")();
|
Loading…
Reference in New Issue
Block a user