Commit 2d06b834 authored by jgruber's avatar jgruber Committed by Commit Bot

[coverage] Move try-catch-finally logic into builders

Move block coverage logic for TryCatchStatement and TryFinallyStatement
nodes into builder classes.

Bug: v8:6000
Change-Id: I0402ef78a54d6ba1bae62214f16aabfebbd7c581
Reviewed-on: https://chromium-review.googlesource.com/758645
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49268}
parent 2328e4d1
...@@ -1646,7 +1646,8 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { ...@@ -1646,7 +1646,8 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
HandlerTable::CatchPrediction outer_catch_prediction = catch_prediction(); HandlerTable::CatchPrediction outer_catch_prediction = catch_prediction();
set_catch_prediction(stmt->GetCatchPrediction(outer_catch_prediction)); set_catch_prediction(stmt->GetCatchPrediction(outer_catch_prediction));
TryCatchBuilder try_control_builder(builder(), catch_prediction()); TryCatchBuilder try_control_builder(builder(), block_coverage_builder_, stmt,
catch_prediction());
// Preserve the context in a dedicated register, so that it can be restored // Preserve the context in a dedicated register, so that it can be restored
// when the handler is entered by the stack-unwinding machinery. // when the handler is entered by the stack-unwinding machinery.
...@@ -1677,17 +1678,15 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { ...@@ -1677,17 +1678,15 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
builder()->LoadAccumulatorWithRegister(context); builder()->LoadAccumulatorWithRegister(context);
// Evaluate the catch-block. // Evaluate the catch-block.
BuildIncrementBlockCoverageCounterIfEnabled(stmt, SourceRangeKind::kCatch);
VisitInScope(stmt->catch_block(), stmt->scope()); VisitInScope(stmt->catch_block(), stmt->scope());
try_control_builder.EndCatch(); try_control_builder.EndCatch();
BuildIncrementBlockCoverageCounterIfEnabled(stmt,
SourceRangeKind::kContinuation);
} }
void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
// We can't know whether the finally block will override ("catch") an // We can't know whether the finally block will override ("catch") an
// exception thrown in the try block, so we just adopt the outer prediction. // exception thrown in the try block, so we just adopt the outer prediction.
TryFinallyBuilder try_control_builder(builder(), catch_prediction()); TryFinallyBuilder try_control_builder(builder(), block_coverage_builder_,
stmt, catch_prediction());
// We keep a record of all paths that enter the finally-block to be able to // We keep a record of all paths that enter the finally-block to be able to
// dispatch to the correct continuation point after the statements in the // dispatch to the correct continuation point after the statements in the
...@@ -1738,7 +1737,6 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { ...@@ -1738,7 +1737,6 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
message); message);
// Evaluate the finally-block. // Evaluate the finally-block.
BuildIncrementBlockCoverageCounterIfEnabled(stmt, SourceRangeKind::kFinally);
Visit(stmt->finally_block()); Visit(stmt->finally_block());
try_control_builder.EndFinally(); try_control_builder.EndFinally();
...@@ -1747,8 +1745,6 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { ...@@ -1747,8 +1745,6 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
// Dynamic dispatch after the finally-block. // Dynamic dispatch after the finally-block.
commands.ApplyDeferredCommands(); commands.ApplyDeferredCommands();
BuildIncrementBlockCoverageCounterIfEnabled(stmt,
SourceRangeKind::kContinuation);
} }
void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
......
...@@ -117,6 +117,12 @@ void SwitchBuilder::SetCaseTarget(int index, CaseClause* clause) { ...@@ -117,6 +117,12 @@ void SwitchBuilder::SetCaseTarget(int index, CaseClause* clause) {
} }
} }
TryCatchBuilder::~TryCatchBuilder() {
if (block_coverage_builder_ != nullptr) {
block_coverage_builder_->IncrementBlockCounter(
statement_, SourceRangeKind::kContinuation);
}
}
void TryCatchBuilder::BeginTry(Register context) { void TryCatchBuilder::BeginTry(Register context) {
builder()->MarkTryBegin(handler_id_, context); builder()->MarkTryBegin(handler_id_, context);
...@@ -128,11 +134,21 @@ void TryCatchBuilder::EndTry() { ...@@ -128,11 +134,21 @@ void TryCatchBuilder::EndTry() {
builder()->Jump(&exit_); builder()->Jump(&exit_);
builder()->Bind(&handler_); builder()->Bind(&handler_);
builder()->MarkHandler(handler_id_, catch_prediction_); builder()->MarkHandler(handler_id_, catch_prediction_);
}
if (block_coverage_builder_ != nullptr) {
block_coverage_builder_->IncrementBlockCounter(statement_,
SourceRangeKind::kCatch);
}
}
void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); } void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); }
TryFinallyBuilder::~TryFinallyBuilder() {
if (block_coverage_builder_ != nullptr) {
block_coverage_builder_->IncrementBlockCounter(
statement_, SourceRangeKind::kContinuation);
}
}
void TryFinallyBuilder::BeginTry(Register context) { void TryFinallyBuilder::BeginTry(Register context) {
builder()->MarkTryBegin(handler_id_, context); builder()->MarkTryBegin(handler_id_, context);
...@@ -154,7 +170,14 @@ void TryFinallyBuilder::BeginHandler() { ...@@ -154,7 +170,14 @@ void TryFinallyBuilder::BeginHandler() {
builder()->MarkHandler(handler_id_, catch_prediction_); builder()->MarkHandler(handler_id_, catch_prediction_);
} }
void TryFinallyBuilder::BeginFinally() { finalization_sites_.Bind(builder()); } void TryFinallyBuilder::BeginFinally() {
finalization_sites_.Bind(builder());
if (block_coverage_builder_ != nullptr) {
block_coverage_builder_->IncrementBlockCounter(statement_,
SourceRangeKind::kFinally);
}
}
void TryFinallyBuilder::EndFinally() { void TryFinallyBuilder::EndFinally() {
// Nothing to be done here. // Nothing to be done here.
......
...@@ -188,10 +188,16 @@ class V8_EXPORT_PRIVATE SwitchBuilder final ...@@ -188,10 +188,16 @@ class V8_EXPORT_PRIVATE SwitchBuilder final
class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder { class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder {
public: public:
TryCatchBuilder(BytecodeArrayBuilder* builder, TryCatchBuilder(BytecodeArrayBuilder* builder,
BlockCoverageBuilder* block_coverage_builder,
TryCatchStatement* statement,
HandlerTable::CatchPrediction catch_prediction) HandlerTable::CatchPrediction catch_prediction)
: ControlFlowBuilder(builder), : ControlFlowBuilder(builder),
handler_id_(builder->NewHandlerEntry()), handler_id_(builder->NewHandlerEntry()),
catch_prediction_(catch_prediction) {} catch_prediction_(catch_prediction),
block_coverage_builder_(block_coverage_builder),
statement_(statement) {}
~TryCatchBuilder();
void BeginTry(Register context); void BeginTry(Register context);
void EndTry(); void EndTry();
...@@ -202,6 +208,9 @@ class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder { ...@@ -202,6 +208,9 @@ class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder {
HandlerTable::CatchPrediction catch_prediction_; HandlerTable::CatchPrediction catch_prediction_;
BytecodeLabel handler_; BytecodeLabel handler_;
BytecodeLabel exit_; BytecodeLabel exit_;
BlockCoverageBuilder* block_coverage_builder_;
TryCatchStatement* statement_;
}; };
...@@ -209,11 +218,17 @@ class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder { ...@@ -209,11 +218,17 @@ class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder {
class V8_EXPORT_PRIVATE TryFinallyBuilder final : public ControlFlowBuilder { class V8_EXPORT_PRIVATE TryFinallyBuilder final : public ControlFlowBuilder {
public: public:
TryFinallyBuilder(BytecodeArrayBuilder* builder, TryFinallyBuilder(BytecodeArrayBuilder* builder,
BlockCoverageBuilder* block_coverage_builder,
TryFinallyStatement* statement,
HandlerTable::CatchPrediction catch_prediction) HandlerTable::CatchPrediction catch_prediction)
: ControlFlowBuilder(builder), : ControlFlowBuilder(builder),
handler_id_(builder->NewHandlerEntry()), handler_id_(builder->NewHandlerEntry()),
catch_prediction_(catch_prediction), catch_prediction_(catch_prediction),
finalization_sites_(builder->zone()) {} finalization_sites_(builder->zone()),
block_coverage_builder_(block_coverage_builder),
statement_(statement) {}
~TryFinallyBuilder();
void BeginTry(Register context); void BeginTry(Register context);
void LeaveTry(); void LeaveTry();
...@@ -229,6 +244,9 @@ class V8_EXPORT_PRIVATE TryFinallyBuilder final : public ControlFlowBuilder { ...@@ -229,6 +244,9 @@ class V8_EXPORT_PRIVATE TryFinallyBuilder final : public ControlFlowBuilder {
// Unbound labels that identify jumps to the finally block in the code. // Unbound labels that identify jumps to the finally block in the code.
BytecodeLabels finalization_sites_; BytecodeLabels finalization_sites_;
BlockCoverageBuilder* block_coverage_builder_;
TryFinallyStatement* statement_;
}; };
class V8_EXPORT_PRIVATE ConditionalControlFlowBuilder final class V8_EXPORT_PRIVATE ConditionalControlFlowBuilder final
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --block-coverage // Flags: --allow-natives-syntax --no-always-opt --harmony-async-iteration
// Flags: --harmony-async-iteration --no-opt // Flags: --no-opt
// Files: test/mjsunit/code-coverage-utils.js // Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true); %DebugToggleBlockCoverage(true);
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --block-coverage // Flags: --allow-natives-syntax --no-always-opt --harmony-async-iteration --opt
// Flags: --harmony-async-iteration --opt
// Files: test/mjsunit/code-coverage-utils.js // Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true); %DebugToggleBlockCoverage(true);
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --block-coverage // Flags: --allow-natives-syntax --no-always-opt --harmony-async-iteration
// Flags: --harmony-async-iteration
// Files: test/mjsunit/code-coverage-utils.js // Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true); %DebugToggleBlockCoverage(true);
......
...@@ -284,7 +284,8 @@ TEST_F(BytecodeAnalysisTest, TryCatch) { ...@@ -284,7 +284,8 @@ TEST_F(BytecodeAnalysisTest, TryCatch) {
builder.StoreAccumulatorInRegister(reg_0); builder.StoreAccumulatorInRegister(reg_0);
expected_liveness.emplace_back(".LLL", "LLL."); expected_liveness.emplace_back(".LLL", "LLL.");
interpreter::TryCatchBuilder try_builder(&builder, HandlerTable::CAUGHT); interpreter::TryCatchBuilder try_builder(&builder, nullptr, nullptr,
HandlerTable::CAUGHT);
try_builder.BeginTry(reg_context); try_builder.BeginTry(reg_context);
{ {
// Gen r0. // Gen r0.
......
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