Commit 5df2f65d authored by Arnaud Robin's avatar Arnaud Robin Committed by Commit Bot

[wasm] Implement tracing of function calls

Added --trace-wasm flag which prints function entry in wasm.

R=clemensb@chromium.org

Bug: v8:10559
Change-Id: I049efeadb0149f4f58ce34a29fd53fbf5688bd4b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2215052
Commit-Queue: Arnaud Robin <arobin@google.com>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67998}
parent 03ba73e4
......@@ -21,6 +21,7 @@ extern runtime ReThrow(Context, Object): JSAny;
extern runtime WasmStackGuard(Context): JSAny;
extern runtime ThrowWasmStackOverflow(Context): JSAny;
extern runtime WasmTraceMemory(Context, Smi): JSAny;
extern runtime WasmTraceEnter(Context): JSAny;
extern runtime WasmAtomicNotify(
Context, WasmInstanceObject, Number, Number): Smi;
extern runtime WasmI32AtomicWait(
......@@ -210,6 +211,10 @@ builtin WasmTraceMemory(info: Smi): JSAny {
tail runtime::WasmTraceMemory(LoadContextFromFrame(), info);
}
builtin WasmTraceEnter(): JSAny {
tail runtime::WasmTraceEnter(LoadContextFromFrame());
}
builtin WasmAllocateJSArray(implicit context: Context)(size: Smi): JSArray {
const map: Map = GetFastPackedElementsJSArrayMap();
return AllocateJSArray(ElementsKind::PACKED_ELEMENTS, map, size, size);
......
......@@ -1149,7 +1149,8 @@ DEFINE_BOOL(inline_new, true, "use fast inline allocation")
DEFINE_NEG_NEG_IMPLICATION(inline_new, turbo_allocation_folding)
// codegen-ia32.cc / codegen-arm.cc
DEFINE_BOOL(trace, false, "trace function calls")
DEFINE_BOOL(trace, false, "trace javascript function calls")
DEFINE_BOOL(trace_wasm, false, "trace wasm function calls")
// codegen.cc
DEFINE_BOOL(lazy, true, "use lazy compilation")
......
......@@ -952,7 +952,6 @@ RUNTIME_FUNCTION(Runtime_TraceEnter) {
return ReadOnlyRoots(isolate).undefined_value();
}
RUNTIME_FUNCTION(Runtime_TraceExit) {
SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length());
......@@ -964,6 +963,14 @@ RUNTIME_FUNCTION(Runtime_TraceExit) {
return obj; // return TOS
}
RUNTIME_FUNCTION(Runtime_WasmTraceEnter) {
SealHandleScope shs(isolate);
DCHECK_EQ(0, args.length());
// TODO(10559): Print more useful info here.
PrintF("Enter function\n");
return ReadOnlyRoots(isolate).undefined_value();
}
RUNTIME_FUNCTION(Runtime_HaveSameMap) {
SealHandleScope shs(isolate);
DCHECK_EQ(2, args.length());
......
......@@ -542,6 +542,7 @@ namespace internal {
F(WasmTierDownModule, 1, 1) \
F(WasmTierUpFunction, 2, 1) \
F(WasmTierUpModule, 1, 1) \
F(WasmTraceEnter, 0, 1) \
F(WasmTraceMemory, 1, 1) \
I(DeoptimizeNow, 0, 1)
......
......@@ -520,6 +520,14 @@ class LiftoffCompiler {
return false;
}
void TraceFunctionEntry(FullDecoder* decoder) {
DEBUG_CODE_COMMENT("trace function entry");
source_position_table_builder_.AddPosition(
__ pc_offset(), SourcePosition(decoder->position()), false);
__ CallRuntimeStub(WasmCode::kWasmTraceEnter);
safepoint_table_builder_.DefineSafepoint(&asm_, Safepoint::kNoLazyDeopt);
}
void StartFunctionBody(FullDecoder* decoder, Control* block) {
for (uint32_t i = 0; i < __ num_locals(); ++i) {
if (!CheckSupportedType(decoder, kSupportedTypes, __ local_type(i),
......@@ -594,6 +602,8 @@ class LiftoffCompiler {
// is never a position of any instruction in the function.
StackCheck(0);
if (FLAG_trace_wasm) TraceFunctionEntry(decoder);
// If we are generating debug code, do check the "hook on function call"
// flag. If set, trigger a break.
if (V8_UNLIKELY(for_debugging_)) {
......
......@@ -71,6 +71,7 @@ struct WasmModule;
V(WasmStackOverflow) \
V(WasmThrow) \
V(WasmRethrow) \
V(WasmTraceEnter) \
V(WasmTraceMemory) \
V(ArgumentsAdaptorTrampoline) \
V(BigIntToI32Pair) \
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --trace-wasm --no-wasm-tier-up --liftoff --no-stress-opt
load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
let kRet23Function = builder.addFunction('ret_23', kSig_i_v)
.addBody([kExprI32Const, 23])
.exportFunc()
.index;
builder.addFunction('main', kSig_v_v)
.addBody([kExprCallFunction, kRet23Function, kExprDrop])
.exportAs('main');
let instance = builder.instantiate();
instance.exports.main();
Enter function
Enter function
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