Reviewers: titzer,
Description:
Simplify computation of environment stack delta.
[email protected]
TEST=cctest/test-run-jsexceptions/CatchCall
Please review this at https://codereview.chromium.org/936343002/
Base URL: https://chromium.googlesource.com/v8/v8.git@local_trycatch-3
Affected files (+24, -25 lines):
M src/compiler/ast-graph-builder.h
M src/compiler/ast-graph-builder.cc
M test/cctest/compiler/test-run-jsexceptions.cc
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc
b/src/compiler/ast-graph-builder.cc
index
8591c956ff9435707d4ddb29dae8325381415562..bd9bf166e76daac379bc3e1fcb03f56504e01ae1
100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -139,10 +139,10 @@ class AstGraphBuilder::ContextScope BASE_EMBEDDED {
// - TryFinallyStatement: Intercepts 'break', 'continue', 'throw'
and 'return'.
class AstGraphBuilder::ControlScope BASE_EMBEDDED {
public:
- ControlScope(AstGraphBuilder* builder, int stack_delta)
+ explicit ControlScope(AstGraphBuilder* builder)
: builder_(builder),
outer_(builder->execution_control()),
- stack_delta_(stack_delta) {
+ stack_height_(builder->environment()->stack_height()) {
builder_->set_execution_control(this); // Push.
}
@@ -189,12 +189,12 @@ class AstGraphBuilder::ControlScope BASE_EMBEDDED {
Environment* environment() { return builder_->environment(); }
AstGraphBuilder* builder() const { return builder_; }
- int stack_delta() const { return stack_delta_; }
+ int stack_height() const { return stack_height_; }
private:
AstGraphBuilder* builder_;
ControlScope* outer_;
- int stack_delta_;
+ int stack_height_;
};
@@ -270,7 +270,7 @@ class AstGraphBuilder::ControlScopeForBreakable :
public ControlScope {
public:
ControlScopeForBreakable(AstGraphBuilder* owner, BreakableStatement*
target,
ControlBuilder* control)
- : ControlScope(owner, 0), target_(target), control_(control) {}
+ : ControlScope(owner), target_(target), control_(control) {}
protected:
virtual bool Execute(Command cmd, Statement* target, Node* value)
OVERRIDE {
@@ -297,8 +297,8 @@ class AstGraphBuilder::ControlScopeForBreakable :
public ControlScope {
class AstGraphBuilder::ControlScopeForIteration : public ControlScope {
public:
ControlScopeForIteration(AstGraphBuilder* owner, IterationStatement*
target,
- LoopBuilder* control, int stack_delta)
- : ControlScope(owner, stack_delta), target_(target),
control_(control) {}
+ LoopBuilder* control)
+ : ControlScope(owner), target_(target), control_(control) {}
protected:
virtual bool Execute(Command cmd, Statement* target, Node* value)
OVERRIDE {
@@ -327,7 +327,7 @@ class AstGraphBuilder::ControlScopeForIteration :
public ControlScope {
class AstGraphBuilder::ControlScopeForCatch : public ControlScope {
public:
ControlScopeForCatch(AstGraphBuilder* owner, TryCatchBuilder* control)
- : ControlScope(owner, 0), control_(control) {
+ : ControlScope(owner), control_(control) {
builder()->try_nesting_level_++; // Increment nesting.
}
~ControlScopeForCatch() {
@@ -358,7 +358,7 @@ class AstGraphBuilder::ControlScopeForFinally : public
ControlScope {
public:
ControlScopeForFinally(AstGraphBuilder* owner, DeferredCommands*
commands,
TryFinallyBuilder* control)
- : ControlScope(owner, 0), commands_(commands), control_(control) {
+ : ControlScope(owner), commands_(commands), control_(control) {
builder()->try_nesting_level_++; // Increment nesting.
}
~ControlScopeForFinally() {
@@ -427,13 +427,13 @@ bool AstGraphBuilder::CreateGraph() {
int parameter_count = info()->num_parameters();
graph()->SetStart(graph()->NewNode(common()->Start(parameter_count)));
- // Initialize control scope.
- ControlScope control(this, 0);
-
// Initialize the top-level environment.
Environment env(this, scope, graph()->start());
set_environment(&env);
+ // Initialize control scope.
+ ControlScope control(this);
+
if (info()->is_osr()) {
// Use OSR normal entry as the start of the top-level environment.
// It will be replaced with {Dead} after typing and optimizations.
@@ -680,8 +680,9 @@ void
AstGraphBuilder::ControlScope::PerformCommand(Command command,
Environment* env = environment()->CopyAsUnreachable();
ControlScope* current = this;
while (current != NULL) {
+ int stack_delta = environment()->stack_height() -
current->stack_height();
+ if (stack_delta > 0) environment()->Drop(stack_delta);
if (current->Execute(command, target, value)) break;
- environment()->Drop(current->stack_delta());
current = current->outer_;
}
builder()->set_environment(env);
@@ -995,7 +996,7 @@ void
AstGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
void AstGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
LoopBuilder while_loop(this);
while_loop.BeginLoop(GetVariablesAssignedInLoop(stmt),
CheckOsrEntry(stmt));
- VisitIterationBody(stmt, &while_loop, 0);
+ VisitIterationBody(stmt, &while_loop);
while_loop.EndBody();
VisitForTest(stmt->cond());
Node* condition = environment()->Pop();
@@ -1010,7 +1011,7 @@ void
AstGraphBuilder::VisitWhileStatement(WhileStatement* stmt) {
VisitForTest(stmt->cond());
Node* condition = environment()->Pop();
while_loop.BreakUnless(condition);
- VisitIterationBody(stmt, &while_loop, 0);
+ VisitIterationBody(stmt, &while_loop);
while_loop.EndBody();
while_loop.EndLoop();
}
@@ -1027,7 +1028,7 @@ void AstGraphBuilder::VisitForStatement(ForStatement*
stmt) {
} else {
for_loop.BreakUnless(jsgraph()->TrueConstant());
}
- VisitIterationBody(stmt, &for_loop, 0);
+ VisitIterationBody(stmt, &for_loop);
for_loop.EndBody();
VisitIfNotNull(stmt->next());
for_loop.EndLoop();
@@ -1166,7 +1167,7 @@ void AstGraphBuilder::VisitForInBody(ForInStatement*
stmt) {
value = environment()->Pop();
// Bind value and do loop body.
VisitForInAssignment(stmt->each(), value, stmt->AssignmentId());
- VisitIterationBody(stmt, &for_loop, 5);
+ VisitIterationBody(stmt, &for_loop);
for_loop.EndBody();
// Inc counter and continue.
Node* index_inc =
@@ -1189,7 +1190,7 @@ void
AstGraphBuilder::VisitForOfStatement(ForOfStatement* stmt) {
Node* condition = environment()->Pop();
for_loop.BreakWhen(condition);
VisitForEffect(stmt->assign_each());
- VisitIterationBody(stmt, &for_loop, 0);
+ VisitIterationBody(stmt, &for_loop);
for_loop.EndBody();
for_loop.EndLoop();
}
@@ -2279,8 +2280,8 @@ void AstGraphBuilder::VisitIfNotNull(Statement* stmt)
{
void AstGraphBuilder::VisitIterationBody(IterationStatement* stmt,
- LoopBuilder* loop, int
stack_delta) {
- ControlScopeForIteration scope(this, stmt, loop, stack_delta);
+ LoopBuilder* loop) {
+ ControlScopeForIteration scope(this, stmt, loop);
Visit(stmt->body());
}
@@ -3001,9 +3002,7 @@ Node* AstGraphBuilder::MakeNode(const Operator* op,
int value_input_count,
if (!result->op()->HasProperty(Operator::kNoThrow) &&
inside_try_scope) {
Node* on_exception = graph()->NewNode(common()->IfException(),
result);
environment_->UpdateControlDependency(on_exception);
- if (FLAG_turbo_exceptions) {
- execution_control()->ThrowValue(jsgraph()->UndefinedConstant());
- }
+ execution_control()->ThrowValue(jsgraph()->UndefinedConstant());
}
// Add implicit success continuation for throwing nodes.
if (!result->op()->HasProperty(Operator::kNoThrow)) {
Index: src/compiler/ast-graph-builder.h
diff --git a/src/compiler/ast-graph-builder.h
b/src/compiler/ast-graph-builder.h
index
661626d97d41b05549d770596929fb679f716f71..d38457186b2c6fd136a24cb52ac3a60a40fa1b7f
100644
--- a/src/compiler/ast-graph-builder.h
+++ b/src/compiler/ast-graph-builder.h
@@ -284,7 +284,7 @@ class AstGraphBuilder : public AstVisitor {
void VisitForValues(ZoneList<Expression*>* exprs);
// Common for all IterationStatement bodies.
- void VisitIterationBody(IterationStatement* stmt, LoopBuilder* loop,
int);
+ void VisitIterationBody(IterationStatement* stmt, LoopBuilder* loop);
// Dispatched from VisitCallRuntime.
void VisitCallJSRuntime(CallRuntime* expr);
Index: test/cctest/compiler/test-run-jsexceptions.cc
diff --git a/test/cctest/compiler/test-run-jsexceptions.cc
b/test/cctest/compiler/test-run-jsexceptions.cc
index
7610962aa2a219bb17a0740a776674746772e293..e41aad413df8361a2d3266370008e4d42ebea8d1
100644
--- a/test/cctest/compiler/test-run-jsexceptions.cc
+++ b/test/cctest/compiler/test-run-jsexceptions.cc
@@ -125,7 +125,7 @@ TEST(CatchCall) {
" var r = '-';"
" try {"
" r += 'A-';"
- " fun();"
+ " return 23 + fun();"
" } catch (e) {"
" r += e;"
" }"
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.