Commit 0fc6c35c authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Remove deprecated --wasm-jit-to-native flag.

The feature in question has been enabled by default for a while and we
no longer need to maintain a configuration without it enabled. Note that
this change only removes the mechanical pieces. Further cleanup enabled
by this will be done as follow-ups.

R=clemensh@chromium.org
BUG=v8:7549

Change-Id: I90e5bcddabe74a18a4d2a88132e8dc93317bcff4
Reviewed-on: https://chromium-review.googlesource.com/958424
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarMichael Hablich <hablich@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51883}
parent 388579bd
......@@ -992,23 +992,18 @@ size_t PipelineWasmCompilationJob::AllocatedMemory() const {
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
Isolate* isolate) {
if (!FLAG_wasm_jit_to_native) {
pipeline_.FinalizeCode();
ValidateImmovableEmbeddedObjects();
} else {
CodeGenerator* code_generator = pipeline_.data_->code_generator();
CompilationInfo::WasmCodeDesc* wasm_code_desc =
compilation_info()->wasm_code_desc();
code_generator->tasm()->GetCode(isolate, &wasm_code_desc->code_desc);
wasm_code_desc->safepoint_table_offset =
code_generator->GetSafepointTableOffset();
wasm_code_desc->handler_table_offset =
code_generator->GetHandlerTableOffset();
wasm_code_desc->frame_slot_count =
code_generator->frame()->GetTotalFrameSlotCount();
wasm_code_desc->source_positions_table =
code_generator->GetSourcePositionTable();
}
CodeGenerator* code_generator = pipeline_.data_->code_generator();
CompilationInfo::WasmCodeDesc* wasm_code_desc =
compilation_info()->wasm_code_desc();
code_generator->tasm()->GetCode(isolate, &wasm_code_desc->code_desc);
wasm_code_desc->safepoint_table_offset =
code_generator->GetSafepointTableOffset();
wasm_code_desc->handler_table_offset =
code_generator->GetHandlerTableOffset();
wasm_code_desc->frame_slot_count =
code_generator->frame()->GetTotalFrameSlotCount();
wasm_code_desc->source_positions_table =
code_generator->GetSourcePositionTable();
return SUCCEEDED;
}
......
This diff is collapsed.
......@@ -72,7 +72,8 @@ struct ModuleEnv {
// FixedArray.
const std::vector<Address> function_tables;
// TODO(mtrofin): remove these 2 once we don't need FLAG_wasm_jit_to_native
// TODO(mstarzinger): remove these 2 once we don't need
// FLAG_wasm_jit_to_native
// Contains the code objects to call for each direct call.
// (the same length as module.functions)
const std::vector<Handle<Code>> function_code;
......@@ -138,8 +139,6 @@ class WasmCompilationUnit final {
size_t memory_cost() const { return memory_cost_; }
private:
void PackProtectedInstructions(Handle<Code> code) const;
struct LiftoffData {
wasm::LiftoffAssembler asm_;
int safepoint_table_offset_;
......
......@@ -257,13 +257,10 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig,
const RegList kCalleeSaveFPRegisters = 0;
// The target for wasm calls is always a code object.
MachineType target_type = FLAG_wasm_jit_to_native ? MachineType::Pointer()
: MachineType::AnyTagged();
MachineType target_type = MachineType::Pointer();
LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
CallDescriptor::Kind kind = FLAG_wasm_jit_to_native
? CallDescriptor::kCallWasmFunction
: CallDescriptor::kCallCodeObject;
CallDescriptor::Kind kind = CallDescriptor::kCallWasmFunction;
return new (zone) CallDescriptor( // --
kind, // kind
......
......@@ -522,11 +522,8 @@ DEFINE_INT(wasm_num_compilation_tasks, 10,
"number of parallel compilation tasks for wasm")
DEFINE_DEBUG_BOOL(wasm_trace_native_heap, false,
"trace wasm native heap events")
DEFINE_BOOL(wasm_jit_to_native, true,
"JIT wasm code to native (not JS GC) memory")
DEFINE_BOOL(wasm_write_protect_code_memory, false,
"write protect code memory on the wasm native heap")
DEFINE_IMPLICATION(future, wasm_jit_to_native)
DEFINE_BOOL(wasm_trace_serialization, false,
"trace serialization/deserialization")
DEFINE_BOOL(wasm_async_compilation, true,
......
......@@ -192,12 +192,8 @@ DISABLE_ASAN Address ReadMemoryAt(Address address) {
WasmInstanceObject* LookupWasmInstanceObjectFromStandardFrame(
const StandardFrame* frame) {
// TODO(titzer): WASM instances cannot be found from the code in the future.
WasmInstanceObject* ret =
FLAG_wasm_jit_to_native
? WasmInstanceObject::GetOwningInstance(
frame->isolate()->wasm_engine()->code_manager()->LookupCode(
frame->pc()))
: WasmInstanceObject::GetOwningInstanceGC(frame->LookupCode());
WasmInstanceObject* ret = WasmInstanceObject::GetOwningInstance(
frame->isolate()->wasm_engine()->code_manager()->LookupCode(frame->pc()));
// This is a live stack frame, there must be a live wasm instance available.
DCHECK_NOT_NULL(ret);
return ret;
......@@ -819,9 +815,7 @@ void StandardFrame::IterateCompiledFrame(RootVisitor* v) const {
// Find the code and compute the safepoint information.
Address inner_pointer = pc();
const wasm::WasmCode* wasm_code =
FLAG_wasm_jit_to_native
? isolate()->wasm_engine()->code_manager()->LookupCode(inner_pointer)
: nullptr;
isolate()->wasm_engine()->code_manager()->LookupCode(inner_pointer);
SafepointEntry safepoint_entry;
uint32_t stack_slots;
Code* code = nullptr;
......@@ -1738,14 +1732,12 @@ void WasmCompiledFrame::Print(StringStream* accumulator, PrintMode mode,
accumulator->Add("WASM [");
Script* script = this->script();
accumulator->PrintName(script->name());
Address instruction_start = FLAG_wasm_jit_to_native
? isolate()
->wasm_engine()
->code_manager()
->LookupCode(pc())
->instructions()
.start()
: LookupCode()->instruction_start();
Address instruction_start = isolate()
->wasm_engine()
->code_manager()
->LookupCode(pc())
->instructions()
.start();
int pc = static_cast<int>(this->pc() - instruction_start);
Vector<const uint8_t> raw_func_name =
shared()->GetRawFunctionName(this->function_index());
......@@ -1772,10 +1764,8 @@ Address WasmCompiledFrame::GetCallerStackPointer() const {
}
WasmCodeWrapper WasmCompiledFrame::wasm_code() const {
return FLAG_wasm_jit_to_native
? WasmCodeWrapper(
isolate()->wasm_engine()->code_manager()->LookupCode(pc()))
: WasmCodeWrapper(Handle<Code>(LookupCode(), isolate()));
return WasmCodeWrapper(
isolate()->wasm_engine()->code_manager()->LookupCode(pc()));
}
WasmInstanceObject* WasmCompiledFrame::wasm_instance() const {
......@@ -1818,21 +1808,14 @@ bool WasmCompiledFrame::at_to_number_conversion() const {
// ToNumber conversion call.
Address callee_pc = reinterpret_cast<Address>(this->callee_pc());
int pos = -1;
if (FLAG_wasm_jit_to_native) {
wasm::WasmCode* code =
callee_pc
? isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc)
: nullptr;
if (!code || code->kind() != wasm::WasmCode::kWasmToJsWrapper) return false;
int offset = static_cast<int>(callee_pc - code->instructions().start());
pos = FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code,
offset);
} else {
Code* code = callee_pc ? isolate()->FindCodeObject(callee_pc) : nullptr;
if (!code || code->kind() != Code::WASM_TO_JS_FUNCTION) return false;
int offset = static_cast<int>(callee_pc - code->instruction_start());
pos = AbstractCode::cast(code)->SourcePosition(offset);
}
wasm::WasmCode* code =
callee_pc
? isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc)
: nullptr;
if (!code || code->kind() != wasm::WasmCode::kWasmToJsWrapper) return false;
int offset = static_cast<int>(callee_pc - code->instructions().start());
pos = FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code,
offset);
DCHECK(pos == 0 || pos == 1);
// The imported call has position 0, ToNumber has position 1.
return !!pos;
......@@ -1840,13 +1823,6 @@ bool WasmCompiledFrame::at_to_number_conversion() const {
int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) {
DCHECK_NOT_NULL(stack_slots);
if (!FLAG_wasm_jit_to_native) {
Code* code = LookupCode();
HandlerTable table(code);
int pc_offset = static_cast<int>(pc() - code->entry());
*stack_slots = code->stack_slots();
return table.LookupReturn(pc_offset);
}
wasm::WasmCode* code =
isolate()->wasm_engine()->code_manager()->LookupCode(pc());
if (!code->IsAnonymous() && code->handler_table_offset() > 0) {
......@@ -1887,13 +1863,7 @@ void WasmInterpreterEntryFrame::Summarize(
}
}
Code* WasmInterpreterEntryFrame::unchecked_code() const {
if (FLAG_wasm_jit_to_native) {
UNIMPLEMENTED();
} else {
return isolate()->FindCodeObject(pc());
}
}
Code* WasmInterpreterEntryFrame::unchecked_code() const { UNREACHABLE(); }
// TODO(titzer): deprecate this method.
WasmInstanceObject* WasmInterpreterEntryFrame::wasm_instance() const {
......@@ -2132,9 +2102,7 @@ void JavaScriptFrame::Iterate(RootVisitor* v) const {
void InternalFrame::Iterate(RootVisitor* v) const {
wasm::WasmCode* wasm_code =
FLAG_wasm_jit_to_native
? isolate()->wasm_engine()->code_manager()->LookupCode(pc())
: nullptr;
isolate()->wasm_engine()->code_manager()->LookupCode(pc());
if (wasm_code != nullptr) {
DCHECK(wasm_code->kind() == wasm::WasmCode::kLazyStub);
} else {
......
......@@ -1305,17 +1305,10 @@ Object* Isolate::UnwindAndFindHandler() {
trap_handler::SetThreadInWasm();
set_wasm_caught_exception(exception);
if (FLAG_wasm_jit_to_native) {
wasm::WasmCode* wasm_code =
wasm_engine()->code_manager()->LookupCode(frame->pc());
return FoundHandler(nullptr, wasm_code->instructions().start(),
offset, wasm_code->constant_pool(), return_sp,
frame->fp());
} else {
Code* code = frame->LookupCode();
return FoundHandler(nullptr, code->instruction_start(), offset,
code->constant_pool(), return_sp, frame->fp());
}
wasm::WasmCode* wasm_code =
wasm_engine()->code_manager()->LookupCode(frame->pc());
return FoundHandler(nullptr, wasm_code->instructions().start(), offset,
wasm_code->constant_pool(), return_sp, frame->fp());
}
case StackFrame::OPTIMIZED: {
......@@ -1696,11 +1689,9 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
// TODO(titzer): store a reference to the code object in FrameArray;
// a second lookup here could lead to inconsistency.
int byte_offset =
FLAG_wasm_jit_to_native
? FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
compiled_module->GetNativeModule()->GetCode(func_index),
code_offset)
: elements->Code(i)->SourcePosition(code_offset);
FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
compiled_module->GetNativeModule()->GetCode(func_index),
code_offset);
bool is_at_number_conversion =
elements->IsAsmJsWasmFrame(i) &&
......
......@@ -650,16 +650,9 @@ void WasmStackFrame::FromFrameArray(Isolate* isolate, Handle<FrameArray> array,
if (array->IsWasmInterpretedFrame(frame_ix)) {
code_ = {};
} else {
code_ =
FLAG_wasm_jit_to_native
? WasmCodeWrapper(
wasm_instance_->compiled_module()->GetNativeModule()->GetCode(
wasm_func_index_))
: WasmCodeWrapper(handle(
Code::cast(
wasm_instance_->compiled_module()->code_table()->get(
wasm_func_index_)),
isolate));
code_ = WasmCodeWrapper(
wasm_instance_->compiled_module()->GetNativeModule()->GetCode(
wasm_func_index_));
}
offset_ = array->Offset(frame_ix)->value();
}
......
......@@ -1490,7 +1490,6 @@ void WasmCompiledModule::WasmCompiledModuleVerify() {
VerifyObjectField(kCodeTableOffset);
VerifyObjectField(kFunctionTablesOffset);
VerifyObjectField(kEmptyFunctionTablesOffset);
VerifyObjectField(kInstanceIdOffset);
}
void WasmDebugInfo::WasmDebugInfoVerify() {
......
......@@ -80,7 +80,7 @@ class Code : public HeapObject {
DECL_ACCESSORS(source_position_table, Object)
inline ByteArray* SourcePositionTable() const;
// TODO(mtrofin): remove when we don't need FLAG_wasm_jit_to_native
// TODO(mstarzinger): remove when we don't need FLAG_wasm_jit_to_native
// [protected instructions]: Array containing list of protected
// instructions and corresponding landing pad offset.
DECL_ACCESSORS(protected_instructions, FixedArray)
......
......@@ -31,14 +31,8 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
const Address entry = Isolate::c_entry_fp(isolate->thread_local_top());
Address pc =
Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset);
WasmInstanceObject* owning_instance = nullptr;
if (FLAG_wasm_jit_to_native) {
owning_instance = WasmInstanceObject::GetOwningInstance(
isolate->wasm_engine()->code_manager()->LookupCode(pc));
} else {
owning_instance = WasmInstanceObject::GetOwningInstanceGC(
isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code);
}
WasmInstanceObject* owning_instance = WasmInstanceObject::GetOwningInstance(
isolate->wasm_engine()->code_manager()->LookupCode(pc));
CHECK_NOT_NULL(owning_instance);
return owning_instance;
}
......@@ -296,15 +290,11 @@ RUNTIME_FUNCTION(Runtime_WasmCompileLazy) {
DCHECK_EQ(0, args.length());
HandleScope scope(isolate);
if (FLAG_wasm_jit_to_native) {
Address new_func = wasm::CompileLazy(isolate);
// The alternative to this is having 2 lazy compile builtins. The builtins
// are part of the snapshot, so the flag has no impact on the codegen there.
return reinterpret_cast<Object*>(new_func - Code::kHeaderSize +
kHeapObjectTag);
} else {
return *wasm::CompileLazyOnGCHeap(isolate);
}
Address new_func = wasm::CompileLazy(isolate);
// The alternative to this is having 2 lazy compile builtins. The builtins
// are part of the snapshot, so the flag has no impact on the codegen there.
return reinterpret_cast<Object*>(new_func - Code::kHeaderSize +
kHeapObjectTag);
}
} // namespace internal
......
......@@ -1236,16 +1236,9 @@ class LiftoffCompiler {
source_position_table_builder_->AddPosition(
__ pc_offset(), SourcePosition(decoder->position()), false);
if (FLAG_wasm_jit_to_native) {
// Just encode the function index. This will be patched at instantiation.
Address addr = reinterpret_cast<Address>(operand.index);
__ CallNativeWasmCode(addr);
} else {
Handle<Code> target = operand.index < env_->function_code.size()
? env_->function_code[operand.index]
: env_->default_function_code;
__ Call(target, RelocInfo::CODE_TARGET);
}
// Just encode the function index. This will be patched at instantiation.
Address addr = reinterpret_cast<Address>(operand.index);
__ CallNativeWasmCode(addr);
safepoint_table_builder_.DefineSafepoint(asm_, Safepoint::kSimple, 0,
Safepoint::kNoLazyDeopt);
......
This diff is collapsed.
......@@ -51,7 +51,6 @@ V8_EXPORT_PRIVATE Handle<Script> CreateWasmScript(
// which will be triggered when returning from the runtime function, i.e. the
// Illegal builtin will never be called.
Address CompileLazy(Isolate* isolate);
Handle<Code> CompileLazyOnGCHeap(Isolate* isolate);
// This class orchestrates the lazy compilation of wasm functions. It is
// triggered by the WasmCompileLazy builtin.
......
......@@ -70,17 +70,6 @@ class PatchDirectCallsHelper {
const byte* func_bytes;
};
bool IsAtWasmDirectCallTarget(RelocIterator& it) {
DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode()));
Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address());
return code->kind() == Code::WASM_FUNCTION ||
code->kind() == Code::WASM_TO_JS_FUNCTION ||
code->kind() == Code::WASM_TO_WASM_FUNCTION ||
code->kind() == Code::WASM_INTERPRETER_ENTRY ||
code->builtin_index() == Builtins::kIllegal ||
code->builtin_index() == Builtins::kWasmCompileLazy;
}
} // namespace
CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone) {}
......@@ -117,7 +106,6 @@ bool CodeSpecialization::ApplyToWholeInstance(
DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = instance->compiled_module();
NativeModule* native_module = compiled_module->GetNativeModule();
FixedArray* code_table = compiled_module->code_table();
WasmSharedModuleData* shared = compiled_module->shared();
WasmModule* module = shared->module();
std::vector<WasmFunction>* wasm_functions = &shared->module()->functions;
......@@ -130,18 +118,11 @@ bool CodeSpecialization::ApplyToWholeInstance(
// Patch all wasm functions.
for (int num_wasm_functions = static_cast<int>(wasm_functions->size());
func_index < num_wasm_functions; ++func_index) {
WasmCodeWrapper wrapper;
if (FLAG_wasm_jit_to_native) {
const WasmCode* wasm_function = native_module->GetCode(func_index);
if (wasm_function->kind() != WasmCode::kFunction) {
continue;
}
wrapper = WasmCodeWrapper(wasm_function);
} else {
Code* wasm_function = Code::cast(code_table->get(func_index));
if (wasm_function->kind() != Code::WASM_FUNCTION) continue;
wrapper = WasmCodeWrapper(handle(wasm_function));
const WasmCode* wasm_function = native_module->GetCode(func_index);
if (wasm_function->kind() != WasmCode::kFunction) {
continue;
}
WasmCodeWrapper wrapper = WasmCodeWrapper(wasm_function);
changed |= ApplyToWasmCode(wrapper, icache_flush_mode);
}
......@@ -156,9 +137,7 @@ bool CodeSpecialization::ApplyToWholeInstance(
// should match the instance we currently patch (instance).
if (!relocate_direct_calls_instance_.is_null()) {
DCHECK_EQ(instance, *relocate_direct_calls_instance_);
reloc_mode |=
RelocInfo::ModeMask(FLAG_wasm_jit_to_native ? RelocInfo::JS_TO_WASM_CALL
: RelocInfo::CODE_TARGET);
reloc_mode |= RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL);
}
if (!reloc_mode) return changed;
int wrapper_index = 0;
......@@ -175,20 +154,10 @@ bool CodeSpecialization::ApplyToWholeInstance(
icache_flush_mode);
break;
case RelocInfo::JS_TO_WASM_CALL: {
DCHECK(FLAG_wasm_jit_to_native);
const WasmCode* new_code = native_module->GetCode(exp.index);
it.rinfo()->set_js_to_wasm_address(new_code->instructions().start(),
SKIP_ICACHE_FLUSH);
} break;
case RelocInfo::CODE_TARGET: {
DCHECK(!FLAG_wasm_jit_to_native);
// Ignore calls to other builtins like ToNumber.
if (!IsAtWasmDirectCallTarget(it)) continue;
Code* new_code = Code::cast(code_table->get(exp.index));
it.rinfo()->set_target_address(new_code->instruction_start(),
UPDATE_WRITE_BARRIER,
SKIP_ICACHE_FLUSH);
} break;
default:
UNREACHABLE();
}
......@@ -241,35 +210,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
for (; !it.done(); it.next()) {
RelocInfo::Mode mode = it.rinfo()->rmode();
switch (mode) {
case RelocInfo::CODE_TARGET: {
DCHECK(!FLAG_wasm_jit_to_native);
DCHECK(reloc_direct_calls);
// Skip everything which is not a wasm call (stack checks, traps, ...).
if (!IsAtWasmDirectCallTarget(it)) continue;
// Iterate simultaneously over the relocation information and the source
// position table. For each call in the reloc info, move the source
// position iterator forward to that position to find the byte offset of
// the respective call. Then extract the call index from the module wire
// bytes to find the new compiled function.
size_t offset = it.rinfo()->pc() - code.GetCode()->instruction_start();
if (!patch_direct_calls_helper) {
patch_direct_calls_helper.emplace(*relocate_direct_calls_instance_,
*code.GetCode());
}
int byte_pos = AdvanceSourcePositionTableIterator(
patch_direct_calls_helper->source_pos_it, offset);
int called_func_index = ExtractDirectCallIndex(
patch_direct_calls_helper->decoder,
patch_direct_calls_helper->func_bytes + byte_pos);
FixedArray* code_table =
relocate_direct_calls_instance_->compiled_module()->code_table();
Code* new_code = Code::cast(code_table->get(called_func_index));
it.rinfo()->set_target_address(new_code->instruction_start(),
UPDATE_WRITE_BARRIER, icache_flush_mode);
changed = true;
} break;
case RelocInfo::WASM_CALL: {
DCHECK(FLAG_wasm_jit_to_native);
DCHECK(reloc_direct_calls);
// Iterate simultaneously over the relocation information and the source
// position table. For each call in the reloc info, move the source
......
......@@ -15,12 +15,11 @@ namespace internal {
// When constructing, we check the flag. After that, we just
// check using the member.
WasmCodeWrapper::WasmCodeWrapper(Handle<Code> code) {
DCHECK(!FLAG_wasm_jit_to_native);
code_ptr_.code_handle_ = code.location();
UNREACHABLE(); // TODO(mstarzinger): This whole class will be deprecated!
}
WasmCodeWrapper::WasmCodeWrapper(const wasm::WasmCode* code) {
DCHECK(FLAG_wasm_jit_to_native);
code_ptr_.wasm_code_ = code;
}
......@@ -34,7 +33,7 @@ const wasm::WasmCode* WasmCodeWrapper::GetWasmCode() const {
return code_ptr_.wasm_code_;
}
bool WasmCodeWrapper::IsCodeObject() const { return !FLAG_wasm_jit_to_native; }
bool WasmCodeWrapper::IsCodeObject() const { return false; }
#ifdef ENABLE_DISASSEMBLER
void WasmCodeWrapper::Disassemble(const char* name, Isolate* isolate,
......
......@@ -16,7 +16,7 @@ class Code;
struct WasmContext;
class WasmInstanceObject;
// TODO(mtrofin): remove once we remove FLAG_wasm_jit_to_native
// TODO(mstarzinger): remove once we remove FLAG_wasm_jit_to_native
class WasmCodeWrapper {
public:
WasmCodeWrapper() {}
......
......@@ -574,20 +574,6 @@ Handle<FixedArray> GetOrCreateInterpretedFunctions(
}
using CodeRelocationMap = std::map<Address, Address>;
using CodeRelocationMapGC =
IdentityMap<Handle<Code>, FreeStoreAllocationPolicy>;
void RedirectCallsitesInCodeGC(Code* code, CodeRelocationMapGC& map) {
DisallowHeapAllocation no_gc;
for (RelocIterator it(code, RelocInfo::kCodeTargetMask); !it.done();
it.next()) {
DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode()));
Code* target = Code::GetCodeFromTargetAddress(it.rinfo()->target_address());
Handle<Code>* new_target = map.Find(target);
if (!new_target) continue;
it.rinfo()->set_target_address((*new_target)->instruction_start());
}
}
void RedirectCallsitesInCode(Isolate* isolate, const wasm::WasmCode* code,
CodeRelocationMap* map) {
......@@ -615,28 +601,6 @@ void RedirectCallsitesInJSWrapperCode(Isolate* isolate, Code* code,
}
}
void RedirectCallsitesInInstanceGC(Isolate* isolate,
WasmInstanceObject* instance,
CodeRelocationMapGC& map) {
DisallowHeapAllocation no_gc;
// Redirect all calls in wasm functions.
FixedArray* code_table = instance->compiled_module()->code_table();
for (int i = 0, e = GetNumFunctions(instance); i < e; ++i) {
RedirectCallsitesInCodeGC(Code::cast(code_table->get(i)), map);
}
// TODO(6668): Find instances that imported our code and also patch those.
// Redirect all calls in exported functions.
FixedArray* weak_exported_functions =
instance->compiled_module()->weak_exported_functions();
for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) {
WeakCell* weak_function = WeakCell::cast(weak_exported_functions->get(i));
if (weak_function->cleared()) continue;
Code* code = JSFunction::cast(weak_function->value())->code();
RedirectCallsitesInCodeGC(code, map);
}
}
void RedirectCallsitesInInstance(Isolate* isolate, WasmInstanceObject* instance,
CodeRelocationMap* map) {
DisallowHeapAllocation no_gc;
......@@ -707,7 +671,6 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
Handle<FixedArray> code_table(instance->compiled_module()->code_table(),
isolate);
CodeRelocationMapGC code_to_relocate_gc(isolate->heap());
// We may modify js wrappers, as well as wasm functions. Hence the 2
// modification scopes.
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
......@@ -721,30 +684,19 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
Handle<Code> new_code = compiler::CompileWasmInterpreterEntry(
isolate, func_index, module->functions[func_index].sig, instance);
if (FLAG_wasm_jit_to_native) {
const wasm::WasmCode* wasm_new_code =
native_module->AddInterpreterWrapper(new_code, func_index);
const wasm::WasmCode* old_code =
native_module->GetCode(static_cast<uint32_t>(func_index));
Handle<Foreign> foreign_holder = isolate->factory()->NewForeign(
wasm_new_code->instructions().start(), TENURED);
interpreted_functions->set(func_index, *foreign_holder);
DCHECK_EQ(0, code_to_relocate.count(old_code->instructions().start()));
code_to_relocate.insert(
std::make_pair(old_code->instructions().start(),
wasm_new_code->instructions().start()));
} else {
Code* old_code = Code::cast(code_table->get(func_index));
interpreted_functions->set(func_index, *new_code);
DCHECK_NULL(code_to_relocate_gc.Find(old_code));
code_to_relocate_gc.Set(old_code, new_code);
}
}
if (FLAG_wasm_jit_to_native) {
RedirectCallsitesInInstance(isolate, *instance, &code_to_relocate);
} else {
RedirectCallsitesInInstanceGC(isolate, *instance, code_to_relocate_gc);
}
const wasm::WasmCode* wasm_new_code =
native_module->AddInterpreterWrapper(new_code, func_index);
const wasm::WasmCode* old_code =
native_module->GetCode(static_cast<uint32_t>(func_index));
Handle<Foreign> foreign_holder = isolate->factory()->NewForeign(
wasm_new_code->instructions().start(), TENURED);
interpreted_functions->set(func_index, *foreign_holder);
DCHECK_EQ(0, code_to_relocate.count(old_code->instructions().start()));
code_to_relocate.insert(
std::make_pair(old_code->instructions().start(),
wasm_new_code->instructions().start()));
}
RedirectCallsitesInInstance(isolate, *instance, &code_to_relocate);
}
void WasmDebugInfo::PrepareStep(StepAction step_action) {
......
......@@ -2587,17 +2587,10 @@ class ThreadImpl {
Isolate* isolate = codemap()->instance()->GetIsolate();
HandleScope handle_scope(isolate);
if (FLAG_wasm_jit_to_native) {
const wasm::WasmCode* target =
codemap()->GetImportedFunction(function_index);
return CallWasmCode(isolate, target,
codemap()->module()->functions[function_index].sig);
} else {
Handle<Code> target(codemap()->GetImportedFunctionGC(function_index),
isolate);
return CallCodeObject(isolate, target,
codemap()->module()->functions[function_index].sig);
}
const wasm::WasmCode* target =
codemap()->GetImportedFunction(function_index);
return CallWasmCode(isolate, target,
codemap()->module()->functions[function_index].sig);
}
ExternalCallResult CallIndirectFunction(uint32_t table_index,
......@@ -2627,7 +2620,6 @@ class ThreadImpl {
Isolate* isolate = compiled_module->GetIsolate();
const wasm::WasmCode* target = nullptr;
Code* target_gc = nullptr;
{
DisallowHeapAllocation no_gc;
// Get function to be called directly from the live instance to see latest
......@@ -2660,10 +2652,6 @@ class ThreadImpl {
if (static_cast<uint32_t>(found_sig) != canonical_sig_index) {
return {ExternalCallResult::SIGNATURE_MISMATCH};
}
// Get code object.
target_gc = Code::cast(fun_table->get(
compiler::FunctionTableCodeOffset(static_cast<int>(entry_index))));
} else {
// The function table is stored in the wasm context.
// TODO(wasm): the wasm interpreter currently supports only one table.
......@@ -2692,11 +2680,7 @@ class ThreadImpl {
// accumulating handles in the outer scope.
HandleScope handle_scope(isolate);
FunctionSig* signature = module()->signatures[sig_index];
if (FLAG_wasm_jit_to_native) {
return CallWasmCode(isolate, target, signature);
} else {
return CallCodeObject(isolate, handle(target_gc, isolate), signature);
}
return CallWasmCode(isolate, target, signature);
}
inline Activation current_activation() {
......
......@@ -39,60 +39,6 @@ constexpr const char* WasmException::kRuntimeIdStr;
// static
constexpr const char* WasmException::kRuntimeValuesStr;
void UnpackAndRegisterProtectedInstructionsGC(Isolate* isolate,
Handle<FixedArray> code_table) {
DisallowHeapAllocation no_gc;
std::vector<trap_handler::ProtectedInstructionData> unpacked;
for (int i = 0; i < code_table->length(); ++i) {
Object* maybe_code = code_table->get(i);
// This is sometimes undefined when we're called from cctests.
if (maybe_code->IsUndefined(isolate)) continue;
Code* code = Code::cast(maybe_code);
if (code->kind() != Code::WASM_FUNCTION) {
continue;
}
if (code->trap_handler_index()->value() != trap_handler::kInvalidIndex) {
// This function has already been registered.
continue;
}
byte* base = code->entry();
FixedArray* protected_instructions = code->protected_instructions();
DCHECK(protected_instructions != nullptr);
for (int i = 0; i < protected_instructions->length();
i += Code::kTrapDataSize) {
trap_handler::ProtectedInstructionData data;
data.instr_offset =
protected_instructions
->GetValueChecked<Smi>(isolate, i + Code::kTrapCodeOffset)
->value();
data.landing_offset =
protected_instructions
->GetValueChecked<Smi>(isolate, i + Code::kTrapLandingOffset)
->value();
unpacked.emplace_back(data);
}
if (unpacked.empty()) continue;
const int index = RegisterHandlerData(base, code->instruction_size(),
unpacked.size(), &unpacked[0]);
unpacked.clear();
// TODO(6792): No longer needed once WebAssembly code is off heap.
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
// TODO(eholk): if index is negative, fail.
DCHECK_LE(0, index);
code->set_trap_handler_index(Smi::FromInt(index));
}
}
void UnpackAndRegisterProtectedInstructions(
Isolate* isolate, const wasm::NativeModule* native_module) {
DisallowHeapAllocation no_gc;
......
......@@ -277,9 +277,6 @@ Handle<Object> GetOrCreateIndirectCallWrapper(
Isolate* isolate, Handle<WasmInstanceObject> owning_instance,
WasmCodeWrapper wasm_code, uint32_t func_index, FunctionSig* sig);
void UnpackAndRegisterProtectedInstructionsGC(Isolate* isolate,
Handle<FixedArray> code_table);
void UnpackAndRegisterProtectedInstructions(
Isolate* isolate, const wasm::NativeModule* native_module);
......
......@@ -143,9 +143,6 @@ WCM_OBJECT(FixedArray, function_tables, kFunctionTablesOffset)
WCM_OBJECT(FixedArray, empty_function_tables, kEmptyFunctionTablesOffset)
ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset);
ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset);
#ifdef DEBUG
WCM_SMALL_CONST_NUMBER(uint32_t, instance_id, kInstanceIdOffset);
#endif
#undef WCM_OBJECT_OR_WEAK
#undef WCM_OBJECT
......
This diff is collapsed.
......@@ -38,7 +38,8 @@ class WasmCompiledModule;
class WasmDebugInfo;
class WasmInstanceObject;
#define WASM_CONTEXT_TABLES FLAG_wasm_jit_to_native
// TODO(mstarzinger): Remove this macro!
#define WASM_CONTEXT_TABLES true
#define DECL_OPTIONAL_ACCESSORS(name, type) \
INLINE(bool has_##name()); \
......@@ -244,7 +245,6 @@ class WasmInstanceObject : public JSObject {
// instance. Intended to be called from runtime functions. Returns nullptr on
// failing to get owning instance.
static WasmInstanceObject* GetOwningInstance(const wasm::WasmCode* code);
static WasmInstanceObject* GetOwningInstanceGC(Code* code);
static void ValidateInstancesChainForTesting(
Isolate* isolate, Handle<WasmModuleObject> module_obj,
......@@ -309,9 +309,6 @@ class WasmSharedModuleData : public Struct {
// Check whether this module was generated from asm.js source.
bool is_asm_js();
static void ReinitializeAfterDeserialization(Isolate*,
Handle<WasmSharedModuleData>);
static void AddBreakpoint(Handle<WasmSharedModuleData>, int position,
Handle<BreakPoint> break_point);
......@@ -443,7 +440,6 @@ class WasmCompiledModule : public Struct {
V(kCodeTableOffset, kPointerSize) \
V(kFunctionTablesOffset, kPointerSize) \
V(kEmptyFunctionTablesOffset, kPointerSize) \
V(kInstanceIdOffset, kPointerSize) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
......@@ -498,15 +494,6 @@ class WasmCompiledModule : public Struct {
WCM_OBJECT(FixedArray, function_tables)
WCM_CONST_OBJECT(FixedArray, empty_function_tables)
public:
// TODO(mtrofin): this is unnecessary when we stop needing
// FLAG_wasm_jit_to_native, because we have instance_id on NativeModule.
#if DEBUG
WCM_SMALL_CONST_NUMBER(uint32_t, instance_id)
#else
uint32_t instance_id() const { return static_cast<uint32_t>(-1); }
#endif
public:
static Handle<WasmCompiledModule> New(
Isolate* isolate, wasm::WasmModule* module, Handle<FixedArray> code_table,
......@@ -543,7 +530,7 @@ class WasmCompiledModule : public Struct {
inline void ReplaceCodeTableForTesting(
std::vector<wasm::WasmCode*>&& testing_table);
// TODO(mtrofin): following 4 unnecessary after we're done with
// TODO(mstarzinger): following 4 unnecessary after we're done with
// FLAG_wasm_jit_to_native
static void SetTableValue(Isolate* isolate, Handle<FixedArray> table,
int index, Address value);
......@@ -554,8 +541,6 @@ class WasmCompiledModule : public Struct {
void LogWasmCodes(Isolate* isolate);
private:
void InitId();
DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
};
......
......@@ -460,14 +460,6 @@ size_t NativeModuleSerializer::Write(Vector<byte> dest) {
// static
std::pair<std::unique_ptr<const byte[]>, size_t> SerializeNativeModule(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
if (!FLAG_wasm_jit_to_native) {
std::unique_ptr<ScriptData> script_data =
WasmCompiledModuleSerializer::SerializeWasmModule(isolate,
compiled_module);
script_data->ReleaseDataOwnership();
size_t size = static_cast<size_t>(script_data->length());
return {std::unique_ptr<const byte[]>(script_data->data()), size};
}
NativeModule* native_module = compiled_module->GetNativeModule();
NativeModuleSerializer serializer(isolate, native_module);
size_t version_size = kVersionSize;
......@@ -630,11 +622,6 @@ Address NativeModuleDeserializer::GetTrampolineOrStubFromTag(uint32_t tag) {
MaybeHandle<WasmCompiledModule> DeserializeNativeModule(
Isolate* isolate, Vector<const byte> data, Vector<const byte> wire_bytes) {
if (!FLAG_wasm_jit_to_native) {
ScriptData script_data(data.start(), data.length());
return WasmCompiledModuleSerializer::DeserializeWasmModule(
isolate, &script_data, wire_bytes);
}
if (!IsWasmCodegenAllowed(isolate, isolate->native_context())) {
return {};
}
......
......@@ -63,18 +63,14 @@ class CWasmEntryArgTester {
isolate_);
CHECK(!buffer_obj->IsHeapObject());
Handle<Object> call_args[]{
(FLAG_wasm_jit_to_native
? Handle<Object>::cast(isolate_->factory()->NewForeign(
wasm_code_.GetWasmCode()->instructions().start(), TENURED))
: Handle<Object>::cast(wasm_code_.GetCode())),
Handle<Object>::cast(isolate_->factory()->NewForeign(
wasm_code_.GetWasmCode()->instructions().start(), TENURED)),
handle(reinterpret_cast<Object*>(wasm_code_.wasm_context()), isolate_),
buffer_obj};
static_assert(
arraysize(call_args) == compiler::CWasmEntryParameters::kNumParameters,
"adapt this test");
if (FLAG_wasm_jit_to_native) {
wasm_code_.GetWasmCode()->owner()->SetExecutable(true);
}
wasm_code_.GetWasmCode()->owner()->SetExecutable(true);
MaybeHandle<Object> return_obj = Execution::Call(
isolate_, c_wasm_entry_fn_, receiver, arraysize(call_args), call_args);
CHECK(!return_obj.is_null());
......
......@@ -258,7 +258,7 @@ class WasmSerializationTest {
uint32_t* slot = reinterpret_cast<uint32_t*>(
const_cast<uint8_t*>(serialized_bytes_.first) +
SerializedCodeData::kPayloadLengthOffset);
*slot = FLAG_wasm_jit_to_native ? 0u : 0xFEFEFEFEu;
*slot = 0u;
}
v8::MaybeLocal<v8::WasmCompiledModule> Deserialize() {
......
......@@ -72,9 +72,7 @@ uint32_t TestingModuleBuilder::AddFunction(FunctionSig* sig, const char* name) {
test_module_.functions.reserve(kMaxFunctions);
}
uint32_t index = static_cast<uint32_t>(test_module_.functions.size());
if (FLAG_wasm_jit_to_native) {
native_module_->ResizeCodeTableForTest(index);
}
native_module_->ResizeCodeTableForTest(index);
test_module_.functions.push_back(
{sig, index, 0, {0, 0}, {0, 0}, false, false});
if (name) {
......@@ -101,21 +99,15 @@ uint32_t TestingModuleBuilder::AddJsFunction(
Handle<Code> code = compiler::CompileWasmToJSWrapper(
isolate_, jsfunc, sig, index, test_module_.origin(),
trap_handler::IsTrapHandlerEnabled(), js_imports_table);
if (FLAG_wasm_jit_to_native) {
native_module_->ResizeCodeTableForTest(index);
native_module_->AddCodeCopy(code, wasm::WasmCode::kWasmToJsWrapper, index);
} else {
function_code_[index] = code;
}
native_module_->ResizeCodeTableForTest(index);
native_module_->AddCodeCopy(code, wasm::WasmCode::kWasmToJsWrapper, index);
return index;
}
Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) {
// Wrap the code so it can be called as a JS function.
Link();
WasmCodeWrapper code = FLAG_wasm_jit_to_native
? WasmCodeWrapper(native_module_->GetCode(index))
: WasmCodeWrapper(function_code_[index]);
WasmCodeWrapper code = WasmCodeWrapper(native_module_->GetCode(index));
byte* context_address =
test_module_.has_memory
? reinterpret_cast<byte*>(instance_object_->wasm_context()->get())
......@@ -444,9 +436,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
Handle<WasmCompiledModule> compiled_module(
builder_->instance_object()->compiled_module(), isolate());
NativeModule* native_module = compiled_module->GetNativeModule();
if (FLAG_wasm_jit_to_native) {
native_module->ResizeCodeTableForTest(function_->func_index);
}
native_module->ResizeCodeTableForTest(function_->func_index);
Handle<SeqOneByteString> wire_bytes(compiled_module->shared()->module_bytes(),
isolate());
......@@ -472,47 +462,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
isolate()->counters(), builder_->runtime_exception_support(),
builder_->lower_simd());
unit.ExecuteCompilation();
WasmCodeWrapper code_wrapper = unit.FinishCompilation(&thrower);
unit.FinishCompilation(&thrower);
CHECK(!thrower.error());
if (!FLAG_wasm_jit_to_native) {
Handle<Code> code = code_wrapper.GetCode();
// TODO(6792): No longer needed once WebAssembly code is off heap.
CodeSpaceMemoryModificationScope modification_scope(isolate()->heap());
// Manually add the deoptimization info that would otherwise be added
// during instantiation. Deopt data holds <WeakCell<wasm_instance>,
// func_index>.
DCHECK_EQ(0, code->deoptimization_data()->length());
Handle<FixedArray> deopt_data =
isolate()->factory()->NewFixedArray(2, TENURED);
Handle<Object> weak_instance =
isolate()->factory()->NewWeakCell(builder_->instance_object());
deopt_data->set(0, *weak_instance);
deopt_data->set(1, Smi::FromInt(static_cast<int>(function_index())));
code->set_deoptimization_data(*deopt_data);
// Build the TurboFan graph.
builder_->SetFunctionCode(function_index(), code);
// Add to code table.
Handle<FixedArray> code_table(compiled_module->code_table(), isolate());
if (static_cast<int>(function_index()) >= code_table->length()) {
Handle<FixedArray> new_arr = isolate()->factory()->NewFixedArray(
static_cast<int>(function_index()) + 1);
code_table->CopyTo(0, *new_arr, 0, code_table->length());
code_table = new_arr;
compiled_module->ReplaceCodeTableForTesting(code_table);
}
DCHECK(code_table->get(static_cast<int>(function_index()))
->IsUndefined(isolate()));
code_table->set(static_cast<int>(function_index()), *code);
if (trap_handler::IsTrapHandlerEnabled()) {
UnpackAndRegisterProtectedInstructionsGC(isolate(), code_table);
}
} else {
if (trap_handler::IsTrapHandlerEnabled()) {
UnpackAndRegisterProtectedInstructions(isolate(), native_module);
}
if (trap_handler::IsTrapHandlerEnabled()) {
UnpackAndRegisterProtectedInstructions(isolate(), native_module);
}
}
......@@ -533,18 +486,7 @@ WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
function_ = builder_->GetFunctionAt(index);
}
WasmFunctionCompiler::~WasmFunctionCompiler() {
if (!FLAG_wasm_jit_to_native) {
if (trap_handler::IsTrapHandlerEnabled() &&
!builder_->GetFunctionCode(function_index()).is_null()) {
const int handler_index = builder_->GetFunctionCode(function_index())
.GetCode()
->trap_handler_index()
->value();
trap_handler::ReleaseHandlerData(handler_index);
}
}
}
WasmFunctionCompiler::~WasmFunctionCompiler() {}
FunctionSig* WasmRunnerBase::CreateSig(MachineType return_type,
Vector<MachineType> param_types) {
......
......@@ -91,13 +91,7 @@ class TestingModuleBuilder {
byte* AddMemory(uint32_t size);
size_t CodeTableLength() const {
if (FLAG_wasm_jit_to_native) {
return native_module_->FunctionCount();
} else {
return function_code_.size();
}
}
size_t CodeTableLength() const { return native_module_->FunctionCount(); }
template <typename T>
T* AddMemoryElems(uint32_t count) {
......@@ -208,18 +202,13 @@ class TestingModuleBuilder {
Isolate* isolate() { return isolate_; }
Handle<WasmInstanceObject> instance_object() { return instance_object_; }
WasmCodeWrapper GetFunctionCode(uint32_t index) {
if (FLAG_wasm_jit_to_native) {
return WasmCodeWrapper(native_module_->GetCode(index));
} else {
return WasmCodeWrapper(function_code_[index]);
}
return WasmCodeWrapper(native_module_->GetCode(index));
}
void SetFunctionCode(int index, Handle<Code> code) {
function_code_[index] = code;
}
Address globals_start() { return reinterpret_cast<Address>(globals_data_); }
void Link() {
if (!FLAG_wasm_jit_to_native) return;
if (!linked_) {
native_module_->LinkAll();
linked_ = true;
......@@ -281,20 +270,14 @@ class WasmFunctionWrapper : private compiler::GraphAndBuilders {
}
void SetInnerCode(WasmCodeWrapper code) {
if (FLAG_wasm_jit_to_native) {
intptr_t address = reinterpret_cast<intptr_t>(
code.GetWasmCode()->instructions().start());
compiler::NodeProperties::ChangeOp(
inner_code_node_,
kPointerSize == 8
? common()->RelocatableInt64Constant(address,
RelocInfo::WASM_CALL)
: common()->RelocatableInt32Constant(static_cast<int>(address),
RelocInfo::WASM_CALL));
} else {
compiler::NodeProperties::ChangeOp(
inner_code_node_, common()->HeapConstant(code.GetCode()));
}
intptr_t address =
reinterpret_cast<intptr_t>(code.GetWasmCode()->instructions().start());
compiler::NodeProperties::ChangeOp(
inner_code_node_,
kPointerSize == 8
? common()->RelocatableInt64Constant(address, RelocInfo::WASM_CALL)
: common()->RelocatableInt32Constant(static_cast<int>(address),
RelocInfo::WASM_CALL));
}
const compiler::Operator* IntPtrConstant(intptr_t value) {
......
......@@ -24,7 +24,6 @@ ALL_VARIANT_FLAGS = {
"stress_sampling": [["--stress-sampling-allocation-profiler=16384"]],
"trusted": [["--no-untrusted-code-mitigations"]],
"wasm_traps": [["--wasm-trap-handler", "--invoke-weak-callbacks"]],
"wasm_no_native": [["--no-wasm-jit-to-native"]],
}
SLOW_VARIANTS = set([
......
......@@ -44,7 +44,7 @@ VARIANT_ALIASES = {
# Shortcut for the two above ("more" first - it has the longer running tests).
"exhaustive": MORE_VARIANTS + VARIANTS,
# Additional variants, run on a subset of bots.
"extra": ["future", "liftoff", "trusted", "wasm_no_native"],
"extra": ["future", "liftoff", "trusted"],
}
GC_STRESS_FLAGS = ["--gc-interval=500", "--stress-compaction",
......
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