Commit fb403653 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][debug] Don't publish code compiled for stepping

This adds another enum value in the {ForDebugging} enum for stepping
code.
By not adding the code to the code table and jump table, we will never
execute this code via a wasm function call. The code will only be used
for the one frame where we want to step through.
This speeds up stepping over recursive calls enormously, since the
recursive calls don't run into the flooded breakpoints any more.
It also fixes issues with non-local control flow, i.e. catching a trap
and reentering the same wasm function.

R=thibaudm@chromium.org

Bug: v8:10235
Change-Id: Idb304dd465418f842016a20c21d68989bb78cf1d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2153205
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67205}
parent 3b60af86
......@@ -1064,14 +1064,15 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
ExecutionTier::kLiftoff < ExecutionTier::kTurbofan,
"Assume an order on execution tiers");
// Unless tier down to Liftoff: update code table but avoid to fall back to
// less optimized code. We use the new code if it was compiled with a higher
// tier.
uint32_t slot_idx = declared_function_index(module(), code->index());
WasmCode* prior_code = code_table_[slot_idx];
// If we are tiered down, install all debugging code (except for stepping
// code, which is only used for a single frame and never installed in the
// code table of jump table). Otherwise, install code if it was compiled
// with a higher tier.
const bool update_code_table =
tiering_state_ == kTieredDown
? !prior_code || code->for_debugging()
? !prior_code || code->for_debugging() == kForDebugging
: !prior_code || prior_code->tier() < code->tier();
if (update_code_table) {
code_table_[slot_idx] = code.get();
......
......@@ -226,8 +226,11 @@ class V8_EXPORT_PRIVATE WasmCode final {
int GetSourcePositionBefore(int offset);
// Returns whether this code was generated for debugging. If this returns
// true, but {tier()} is not {kLiftoff}, then Liftoff compilation bailed out.
bool for_debugging() const { return ForDebuggingField::decode(flags_); }
// {kForDebugging}, but {tier()} is not {kLiftoff}, then Liftoff compilation
// bailed out.
ForDebugging for_debugging() const {
return ForDebuggingField::decode(flags_);
}
enum FlushICache : bool { kFlushICache = true, kNoFlushICache = false };
......@@ -320,7 +323,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
// Bits encoded in {flags_}:
using KindField = base::BitField8<Kind, 0, 3>;
using ExecutionTierField = KindField::Next<ExecutionTier, 2>;
using ForDebuggingField = ExecutionTierField::Next<ForDebugging, 1>;
using ForDebuggingField = ExecutionTierField::Next<ForDebugging, 2>;
// WasmCode is ref counted. Counters are held by:
// 1) The jump table / code table.
......
......@@ -669,9 +669,11 @@ class DebugInfoImpl {
wire_bytes.begin() + function->code.end_offset()};
std::unique_ptr<DebugSideTable> debug_sidetable;
ForDebugging for_debugging =
offsets.size() == 1 && offsets[0] == 0 ? kForStepping : kForDebugging;
WasmCompilationResult result = ExecuteLiftoffCompilation(
native_module_->engine()->allocator(), &env, body, func_index,
kForDebugging, nullptr, nullptr, offsets, &debug_sidetable,
for_debugging, nullptr, nullptr, offsets, &debug_sidetable,
extra_source_positions);
// Liftoff compilation failure is a FATAL error. We rely on complete Liftoff
// support for debugging.
......
......@@ -32,7 +32,10 @@ inline const char* ExecutionTierToString(ExecutionTier tier) {
}
}
enum ForDebugging : bool { kForDebugging = true, kNoDebugging = false };
// {kForDebugging} is used for default tiered-down code (potentially with
// breakpoints), {kForStepping} is code that is flooded with breakpoints.
enum ForDebugging : int8_t { kNoDebugging = 0, kForDebugging, kForStepping };
enum TieringState : int8_t { kTieredUp, kTieredDown };
} // namespace wasm
......
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