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

[no-wasm] Remove wasm engine from isolate

This removes the {wasm_engine_} field from the isolate if
v8_enable_webassembly=false. This avoids any includes from src/wasm in
isolate.{h,cc}.
Unconditional access to the wasm engine in other parts are also #if'ed
out to avoid nullptr accesses.
Long-term, the {Isolate::wasm_engine()} method will be fully removed,
but this can only be done once src/wasm is excluded from compilation.

R=jkummerow@chromium.org, petermarshall@chromium.org

Bug: v8:11238
Change-Id: Ie3738884ec17ccc0a3027b91a2415c2c633ca774
Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2737298Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73230}
parent c1908c13
......@@ -23,8 +23,11 @@
#include "src/snapshot/embedded/embedded-data.h"
#include "src/strings/string-stream.h"
#include "src/utils/vector.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h"
#endif // V8_ENABLE_WEBASSEMBLY
namespace v8 {
namespace internal {
......@@ -94,6 +97,7 @@ const char* V8NameConverter::NameOfAddress(byte* pc) const {
return v8_buffer_.begin();
}
#if V8_ENABLE_WEBASSEMBLY
wasm::WasmCodeRefScope wasm_code_ref_scope;
wasm::WasmCode* wasm_code =
isolate_ ? isolate_->wasm_engine()->code_manager()->LookupCode(
......@@ -104,6 +108,7 @@ const char* V8NameConverter::NameOfAddress(byte* pc) const {
wasm::GetWasmCodeKindAsString(wasm_code->kind()));
return v8_buffer_.begin();
}
#endif // V8_ENABLE_WEBASSEMBLY
}
return disasm::NameConverter::NameOfAddress(pc);
......@@ -247,12 +252,14 @@ static void PrintRelocInfo(StringBuilder* out, Isolate* isolate,
} else {
out->AddFormatted(" %s", CodeKindToString(kind));
}
#if V8_ENABLE_WEBASSEMBLY
} else if (RelocInfo::IsWasmStubCall(rmode) && host.is_wasm_code()) {
// Host is isolate-independent, try wasm native module instead.
const char* runtime_stub_name = GetRuntimeStubName(
host.as_wasm_code()->native_module()->GetRuntimeStubId(
relocinfo->wasm_stub_call_address()));
out->AddFormatted(" ;; wasm stub: %s", runtime_stub_name);
#endif // V8_ENABLE_WEBASSEMBLY
} else if (RelocInfo::IsRuntimeEntry(rmode) && isolate != nullptr) {
// A runtime entry relocinfo might be a deoptimization bailout.
Address addr = relocinfo->target_address();
......
......@@ -561,12 +561,13 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
}
}
} else {
#if V8_ENABLE_WEBASSEMBLY
// If the {pc} does not point into WebAssembly code we can rely on the
// returned {wasm_code} to be null and fall back to {GetContainingCode}.
wasm::WasmCodeRefScope code_ref_scope;
wasm::WasmCode* wasm_code =
iterator->isolate()->wasm_engine()->code_manager()->LookupCode(pc);
if (wasm_code != nullptr) {
if (wasm::WasmCode* wasm_code =
iterator->isolate()->wasm_engine()->code_manager()->LookupCode(
pc)) {
switch (wasm_code->kind()) {
case wasm::WasmCode::kFunction:
return WASM;
......@@ -577,52 +578,53 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
default:
UNREACHABLE();
}
} else {
// Look up the code object to figure out the type of the stack frame.
Code code_obj = GetContainingCode(iterator->isolate(), pc);
if (!code_obj.is_null()) {
switch (code_obj.kind()) {
case CodeKind::BUILTIN:
if (StackFrame::IsTypeMarker(marker)) break;
if (code_obj.is_interpreter_trampoline_builtin()) {
return INTERPRETED;
}
if (code_obj.is_baseline_leave_frame_builtin()) {
return BASELINE;
}
if (code_obj.is_turbofanned()) {
// TODO(bmeurer): We treat frames for BUILTIN Code objects as
// OptimizedFrame for now (all the builtins with JavaScript
// linkage are actually generated with TurboFan currently, so
// this is sound).
return OPTIMIZED;
}
return BUILTIN;
case CodeKind::TURBOFAN:
case CodeKind::NATIVE_CONTEXT_INDEPENDENT:
case CodeKind::TURBOPROP:
}
#endif // V8_ENABLE_WEBASSEMBLY
// Look up the code object to figure out the type of the stack frame.
Code code_obj = GetContainingCode(iterator->isolate(), pc);
if (!code_obj.is_null()) {
switch (code_obj.kind()) {
case CodeKind::BUILTIN:
if (StackFrame::IsTypeMarker(marker)) break;
if (code_obj.is_interpreter_trampoline_builtin()) {
return INTERPRETED;
}
if (code_obj.is_baseline_leave_frame_builtin()) {
return BASELINE;
}
if (code_obj.is_turbofanned()) {
// TODO(bmeurer): We treat frames for BUILTIN Code objects as
// OptimizedFrame for now (all the builtins with JavaScript
// linkage are actually generated with TurboFan currently, so
// this is sound).
return OPTIMIZED;
case CodeKind::BASELINE:
return Type::BASELINE;
case CodeKind::JS_TO_WASM_FUNCTION:
return JS_TO_WASM;
case CodeKind::JS_TO_JS_FUNCTION:
return STUB;
case CodeKind::C_WASM_ENTRY:
return C_WASM_ENTRY;
case CodeKind::WASM_TO_JS_FUNCTION:
return WASM_TO_JS;
case CodeKind::WASM_FUNCTION:
case CodeKind::WASM_TO_CAPI_FUNCTION:
// Never appear as on-heap {Code} objects.
UNREACHABLE();
default:
// All other types should have an explicit marker
break;
}
} else {
return NATIVE;
}
return BUILTIN;
case CodeKind::TURBOFAN:
case CodeKind::NATIVE_CONTEXT_INDEPENDENT:
case CodeKind::TURBOPROP:
return OPTIMIZED;
case CodeKind::BASELINE:
return Type::BASELINE;
case CodeKind::JS_TO_WASM_FUNCTION:
return JS_TO_WASM;
case CodeKind::JS_TO_JS_FUNCTION:
return STUB;
case CodeKind::C_WASM_ENTRY:
return C_WASM_ENTRY;
case CodeKind::WASM_TO_JS_FUNCTION:
return WASM_TO_JS;
case CodeKind::WASM_FUNCTION:
case CodeKind::WASM_TO_CAPI_FUNCTION:
// Never appear as on-heap {Code} objects.
UNREACHABLE();
default:
// All other types should have an explicit marker
break;
}
} else {
return NATIVE;
}
}
DCHECK(StackFrame::IsTypeMarker(marker));
......@@ -911,14 +913,17 @@ void CommonFrame::IterateCompiledFrame(RootVisitor* v) const {
// Find the code and compute the safepoint information.
Address inner_pointer = pc();
const wasm::WasmCode* wasm_code =
isolate()->wasm_engine()->code_manager()->LookupCode(inner_pointer);
SafepointEntry safepoint_entry;
uint32_t stack_slots;
uint32_t stack_slots = 0;
Code code;
bool has_tagged_outgoing_params = false;
uint32_t tagged_parameter_slots = 0;
if (wasm_code != nullptr) {
bool is_wasm = false;
#if V8_ENABLE_WEBASSEMBLY
if (auto* wasm_code =
isolate()->wasm_engine()->code_manager()->LookupCode(inner_pointer)) {
is_wasm = true;
SafepointTable table(wasm_code);
safepoint_entry = table.FindEntry(inner_pointer);
stack_slots = wasm_code->stack_slots();
......@@ -926,7 +931,10 @@ void CommonFrame::IterateCompiledFrame(RootVisitor* v) const {
wasm_code->kind() != wasm::WasmCode::kFunction &&
wasm_code->kind() != wasm::WasmCode::kWasmToCapiWrapper;
tagged_parameter_slots = wasm_code->tagged_parameter_slots();
} else {
}
#endif // V8_ENABLE_WEBASSEMBLY
if (!is_wasm) {
InnerPointerToCodeCache::InnerPointerToCodeCacheEntry* entry =
isolate()->inner_pointer_to_code_cache()->GetCacheEntry(inner_pointer);
if (!entry->safepoint_entry.is_valid()) {
......@@ -941,15 +949,17 @@ void CommonFrame::IterateCompiledFrame(RootVisitor* v) const {
safepoint_entry = entry->safepoint_entry;
stack_slots = code.stack_slots();
has_tagged_outgoing_params = code.has_tagged_outgoing_params();
#if V8_ENABLE_WEBASSEMBLY
// With inlined JS-to-Wasm calls, we can be in an OptimizedFrame and
// directly call a Wasm function from JavaScript. In this case the
// parameters we pass to the callee are not tagged.
wasm::WasmCode* wasm_callee =
isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc());
bool is_wasm_call = (wasm_callee != nullptr);
has_tagged_outgoing_params =
!is_wasm_call && code.has_tagged_outgoing_params();
if (is_wasm_call) has_tagged_outgoing_params = false;
#endif // V8_ENABLE_WEBASSEMBLY
}
uint32_t slot_space = stack_slots * kSystemPointerSize;
......@@ -1808,6 +1818,7 @@ int BuiltinFrame::ComputeParametersCount() const {
void WasmFrame::Print(StringStream* accumulator, PrintMode mode,
int index) const {
wasm::WasmCodeRefScope code_ref_scope;
PrintIndex(accumulator, mode, index);
accumulator->Add("WASM [");
accumulator->PrintName(script().name());
......
......@@ -90,16 +90,19 @@
#include "src/utils/address-map.h"
#include "src/utils/ostreams.h"
#include "src/utils/version.h"
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/zone/accounting-allocator.h"
#include "src/zone/type-stats.h"
#ifdef V8_INTL_SUPPORT
#include "unicode/uobject.h"
#endif // V8_INTL_SUPPORT
#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#endif // V8_ENABLE_WEBASSEMBLY
#if defined(V8_OS_WIN64)
#include "src/diagnostics/unwinding-info-win64.h"
#endif // V8_OS_WIN64
......@@ -527,7 +530,9 @@ void Isolate::Iterate(RootVisitor* v, ThreadLocalTop* thread) {
#endif
// Iterate over pointers on native execution stack.
#if V8_ENABLE_WEBASSEMBLY
wasm::WasmCodeRefScope wasm_code_ref_scope;
#endif // V8_ENABLE_WEBASSEMBLY
for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) {
it.frame()->Iterate(v);
}
......@@ -694,6 +699,7 @@ class StackTraceBuilder {
summary.code_offset(), flags, summary.parameters());
}
#if V8_ENABLE_WEBASSEMBLY
void AppendWasmFrame(FrameSummary::WasmFrameSummary const& summary) {
if (summary.code()->kind() != wasm::WasmCode::kFunction) return;
Handle<WasmInstanceObject> instance = summary.wasm_instance();
......@@ -713,6 +719,7 @@ class StackTraceBuilder {
summary.code_offset(), flags,
isolate_->factory()->empty_fixed_array());
}
#endif // V8_ENABLE_WEBASSEMBLY
void AppendBuiltinExitFrame(BuiltinExitFrame* exit_frame) {
Handle<JSFunction> function(exit_frame->function(), isolate_);
......@@ -1000,7 +1007,10 @@ Handle<FixedArray> CaptureStackTrace(Isolate* isolate, Handle<Object> caller,
TRACE_EVENT_BEGIN1(TRACE_DISABLED_BY_DEFAULT("v8.stack_trace"),
"CaptureStackTrace", "maxFrameCount", options.limit);
#if V8_ENABLE_WEBASSEMBLY
wasm::WasmCodeRefScope code_ref_scope;
#endif // V8_ENABLE_WEBASSEMBLY
StackTraceBuilder builder(isolate, options.skip_mode, options.limit, caller,
options.filter_mode);
......@@ -1017,7 +1027,10 @@ Handle<FixedArray> CaptureStackTrace(Isolate* isolate, Handle<Object> caller,
case StackFrame::INTERPRETED:
case StackFrame::BASELINE:
case StackFrame::BUILTIN:
case StackFrame::WASM: {
#if V8_ENABLE_WEBASSEMBLY
case StackFrame::WASM:
#endif // V8_ENABLE_WEBASSEMBLY
{
// A standard frame may include many summarized frames (due to
// inlining).
std::vector<FrameSummary> frames;
......@@ -1035,12 +1048,14 @@ Handle<FixedArray> CaptureStackTrace(Isolate* isolate, Handle<Object> caller,
//=========================================================
auto const& java_script = summary.AsJavaScript();
builder.AppendJavaScriptFrame(java_script);
#if V8_ENABLE_WEBASSEMBLY
} else if (summary.IsWasm()) {
//=========================================================
// Handle a Wasm frame.
//=========================================================
auto const& wasm = summary.AsWasm();
builder.AppendWasmFrame(wasm);
#endif // V8_ENABLE_WEBASSEMBLY
}
}
break;
......@@ -1275,7 +1290,6 @@ static void PrintFrames(Isolate* isolate, StringStream* accumulator,
void Isolate::PrintStack(StringStream* accumulator, PrintStackMode mode) {
HandleScope scope(this);
wasm::WasmCodeRefScope wasm_code_ref_scope;
DCHECK(accumulator->IsMentionedObjectCacheClear(this));
// Avoid printing anything if there are no frames.
......@@ -1688,7 +1702,6 @@ Object Isolate::UnwindAndFindHandler() {
// Special handling of termination exceptions, uncatchable by JavaScript and
// Wasm code, we unwind the handlers until the top ENTRY handler is found.
bool catchable_by_js = is_catchable_by_javascript(exception);
bool catchable_by_wasm = is_catchable_by_wasm(exception);
// Compute handler and stack unwinding information by performing a full walk
// over the stack and dispatching according to the frame type.
......@@ -1716,6 +1729,7 @@ Object Isolate::UnwindAndFindHandler() {
0);
}
#if V8_ENABLE_WEBASSEMBLY
case StackFrame::C_WASM_ENTRY: {
StackHandler* handler = frame->top_handler();
thread_local_top()->handler_ = handler->next_address();
......@@ -1735,7 +1749,7 @@ Object Isolate::UnwindAndFindHandler() {
}
case StackFrame::WASM: {
if (!catchable_by_wasm) break;
if (!is_catchable_by_wasm(exception)) break;
// For WebAssembly frames we perform a lookup in the handler table.
// This code ref scope is here to avoid a check failure when looking up
......@@ -1767,6 +1781,7 @@ Object Isolate::UnwindAndFindHandler() {
DCHECK(FLAG_wasm_lazy_validation);
break;
}
#endif // V8_ENABLE_WEBASSEMBLY
case StackFrame::OPTIMIZED: {
// For optimized frames we perform a lookup in the handler table.
......@@ -1800,10 +1815,10 @@ Object Isolate::UnwindAndFindHandler() {
// Some stubs are able to handle exceptions.
if (!catchable_by_js) break;
StubFrame* stub_frame = static_cast<StubFrame*>(frame);
#ifdef DEBUG
#if defined(DEBUG) && V8_ENABLE_WEBASSEMBLY
wasm::WasmCodeRefScope code_ref_scope;
DCHECK_NULL(wasm_engine()->code_manager()->LookupCode(frame->pc()));
#endif // DEBUG
#endif // defined(DEBUG) && V8_ENABLE_WEBASSEMBLY
Code code = stub_frame->LookupCode();
if (!code.IsCode() || code.kind() != CodeKind::BUILTIN ||
!code.has_handler_table() || !code.is_turbofanned()) {
......@@ -2112,7 +2127,9 @@ bool Isolate::ComputeLocation(MessageLocation* target) {
// baseline code. For optimized code this will use the deoptimization
// information to get canonical location information.
std::vector<FrameSummary> frames;
#if V8_ENABLE_WEBASSEMBLY
wasm::WasmCodeRefScope code_ref_scope;
#endif // V8_ENABLE_WEBASSEMBLY
frame->Summarize(&frames);
FrameSummary& summary = frames.back();
Handle<SharedFunctionInfo> shared;
......@@ -2635,11 +2652,13 @@ void Isolate::UnregisterManagedPtrDestructor(ManagedPtrDestructor* destructor) {
destructor->next_ = nullptr;
}
#if V8_ENABLE_WEBASSEMBLY
void Isolate::SetWasmEngine(std::shared_ptr<wasm::WasmEngine> engine) {
DCHECK_NULL(wasm_engine_); // Only call once before {Init}.
wasm_engine_ = std::move(engine);
wasm_engine_->AddIsolate(this);
}
#endif // V8_ENABLE_WEBASSEMBLY
// NOLINTNEXTLINE
Isolate::PerIsolateThreadData::~PerIsolateThreadData() {
......@@ -2988,7 +3007,9 @@ void Isolate::Deinit() {
debug()->Unload();
#if V8_ENABLE_WEBASSEMBLY
wasm_engine()->DeleteCompileJobsOnIsolate(this);
#endif // V8_ENABLE_WEBASSEMBLY
if (concurrent_recompilation_enabled()) {
optimizing_compile_dispatcher_->Stop();
......@@ -3051,10 +3072,12 @@ void Isolate::Deinit() {
FILE* logfile = logger_->TearDownAndGetLogFile();
if (logfile != nullptr) base::Fclose(logfile);
#if V8_ENABLE_WEBASSEMBLY
if (wasm_engine_) {
wasm_engine_->RemoveIsolate(this);
wasm_engine_.reset();
}
#endif // V8_ENABLE_WEBASSEMBLY
TearDownEmbeddedBlob();
......@@ -3484,11 +3507,13 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
isolate_data_.external_reference_table()->Init(this);
#if V8_ENABLE_WEBASSEMBLY
// Setup the wasm engine.
if (wasm_engine_ == nullptr) {
SetWasmEngine(wasm::WasmEngine::GetWasmEngine());
}
DCHECK_NOT_NULL(wasm_engine_);
#endif // V8_ENABLE_WEBASSEMBLY
if (setup_delegate_ == nullptr) {
setup_delegate_ = new SetupIsolateDelegate(create_heap_objects);
......@@ -3761,11 +3786,13 @@ void Isolate::DumpAndResetStats() {
delete turbo_statistics_;
turbo_statistics_ = nullptr;
}
#if V8_ENABLE_WEBASSEMBLY
// TODO(7424): There is no public API for the {WasmEngine} yet. So for now we
// just dump and reset the engines statistics together with the Isolate.
if (FLAG_turbo_stats_wasm) {
wasm_engine()->DumpAndResetTurboStatistics();
}
#endif // V8_ENABLE_WEBASSEMBLY
if (V8_UNLIKELY(TracingFlags::runtime_stats.load(std::memory_order_relaxed) ==
v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) {
counters()->worker_thread_runtime_call_stats()->AddToMainTable(
......
......@@ -1631,8 +1631,13 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
elements_deletion_counter_ = value;
}
#if V8_ENABLE_WEBASSEMBLY
wasm::WasmEngine* wasm_engine() const { return wasm_engine_.get(); }
void SetWasmEngine(std::shared_ptr<wasm::WasmEngine> engine);
#else
// TODO(clemensb): Remove this method.
wasm::WasmEngine* wasm_engine() const { return nullptr; }
#endif // V8_ENABLE_WEBASSEMBLY
const v8::Context::BackupIncumbentScope* top_backup_incumbent_scope() const {
return top_backup_incumbent_scope_;
......@@ -2037,7 +2042,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
size_t elements_deletion_counter_ = 0;
#if V8_ENABLE_WEBASSEMBLY
std::shared_ptr<wasm::WasmEngine> wasm_engine_;
#endif // V8_ENABLE_WEBASSEMBLY
std::unique_ptr<TracingCpuProfilerImpl> tracing_cpu_profiler_;
......
......@@ -20,7 +20,10 @@
#include "src/profiler/profiler-stats.h"
#include "src/profiler/symbolizer.h"
#include "src/utils/locked-queue-inl.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-engine.h"
#endif // V8_ENABLE_WEBASSEMBLY
namespace v8 {
namespace internal {
......@@ -72,7 +75,9 @@ ProfilingScope::ProfilingScope(Isolate* isolate, ProfilerListener* listener)
profiler_count++;
isolate_->set_num_cpu_profilers(profiler_count);
isolate_->set_is_profiling(true);
#if V8_ENABLE_WEBASSEMBLY
isolate_->wasm_engine()->EnableCodeLogging(isolate_);
#endif // V8_ENABLE_WEBASSEMBLY
Logger* logger = isolate_->logger();
logger->AddCodeEventListener(listener_);
......
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