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) {
HandlerTable::CatchPrediction outer_catch_prediction = 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
// when the handler is entered by the stack-unwinding machinery.
......@@ -1677,17 +1678,15 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
builder()->LoadAccumulatorWithRegister(context);
// Evaluate the catch-block.
BuildIncrementBlockCoverageCounterIfEnabled(stmt, SourceRangeKind::kCatch);
VisitInScope(stmt->catch_block(), stmt->scope());
try_control_builder.EndCatch();
BuildIncrementBlockCoverageCounterIfEnabled(stmt,
SourceRangeKind::kContinuation);
}
void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
// 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.
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
// dispatch to the correct continuation point after the statements in the
......@@ -1738,7 +1737,6 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
message);
// Evaluate the finally-block.
BuildIncrementBlockCoverageCounterIfEnabled(stmt, SourceRangeKind::kFinally);
Visit(stmt->finally_block());
try_control_builder.EndFinally();
......@@ -1747,8 +1745,6 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
// Dynamic dispatch after the finally-block.
commands.ApplyDeferredCommands();
BuildIncrementBlockCoverageCounterIfEnabled(stmt,
SourceRangeKind::kContinuation);
}
void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
......
......@@ -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) {
builder()->MarkTryBegin(handler_id_, context);
......@@ -128,11 +134,21 @@ void TryCatchBuilder::EndTry() {
builder()->Jump(&exit_);
builder()->Bind(&handler_);
builder()->MarkHandler(handler_id_, catch_prediction_);
}
if (block_coverage_builder_ != nullptr) {
block_coverage_builder_->IncrementBlockCounter(statement_,
SourceRangeKind::kCatch);
}
}
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) {
builder()->MarkTryBegin(handler_id_, context);
......@@ -154,7 +170,14 @@ void TryFinallyBuilder::BeginHandler() {
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() {
// Nothing to be done here.
......
......@@ -188,10 +188,16 @@ class V8_EXPORT_PRIVATE SwitchBuilder final
class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder {
public:
TryCatchBuilder(BytecodeArrayBuilder* builder,
BlockCoverageBuilder* block_coverage_builder,
TryCatchStatement* statement,
HandlerTable::CatchPrediction catch_prediction)
: ControlFlowBuilder(builder),
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 EndTry();
......@@ -202,6 +208,9 @@ class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder {
HandlerTable::CatchPrediction catch_prediction_;
BytecodeLabel handler_;
BytecodeLabel exit_;
BlockCoverageBuilder* block_coverage_builder_;
TryCatchStatement* statement_;
};
......@@ -209,11 +218,17 @@ class V8_EXPORT_PRIVATE TryCatchBuilder final : public ControlFlowBuilder {
class V8_EXPORT_PRIVATE TryFinallyBuilder final : public ControlFlowBuilder {
public:
TryFinallyBuilder(BytecodeArrayBuilder* builder,
BlockCoverageBuilder* block_coverage_builder,
TryFinallyStatement* statement,
HandlerTable::CatchPrediction catch_prediction)
: ControlFlowBuilder(builder),
handler_id_(builder->NewHandlerEntry()),
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 LeaveTry();
......@@ -229,6 +244,9 @@ class V8_EXPORT_PRIVATE TryFinallyBuilder final : public ControlFlowBuilder {
// Unbound labels that identify jumps to the finally block in the code.
BytecodeLabels finalization_sites_;
BlockCoverageBuilder* block_coverage_builder_;
TryFinallyStatement* statement_;
};
class V8_EXPORT_PRIVATE ConditionalControlFlowBuilder final
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --block-coverage
// Flags: --harmony-async-iteration --no-opt
// Flags: --allow-natives-syntax --no-always-opt --harmony-async-iteration
// Flags: --no-opt
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
......
......@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --block-coverage
// Flags: --harmony-async-iteration --opt
// Flags: --allow-natives-syntax --no-always-opt --harmony-async-iteration --opt
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
......
......@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --block-coverage
// Flags: --harmony-async-iteration
// Flags: --allow-natives-syntax --no-always-opt --harmony-async-iteration
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
......
......@@ -284,7 +284,8 @@ TEST_F(BytecodeAnalysisTest, TryCatch) {
builder.StoreAccumulatorInRegister(reg_0);
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);
{
// 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