Commit 8adb94fc authored by Ben Titzer's avatar Ben Titzer Committed by Commit Bot

Revert "[wasm] Merge the WasmContext into WasmInstanceObject"

This reverts commit 57bf0bfe.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> [wasm] Merge the WasmContext into WasmInstanceObject
> 
> This change makes lifetime management of WasmCode much simpler.
> By using the WasmInstanceObject as the context for WASM code execution,
> including the pointer to the memory base and indirect function tables,
> this keeps the instance alive when WASM code is on the stack, since
> the instance object is passed as a parameter and spilled onto the stack.
> This is in preparation of sharing the code between instances and
> isolates.
> 
> Bug: v8:7424
> 
> Change-Id: Ic2e4b7bcc2feb20001d0553a615a8a9dff36317e
> Reviewed-on: https://chromium-review.googlesource.com/958520
> Commit-Queue: Ben Titzer <titzer@chromium.org>
> Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#52361}

TBR=mstarzinger@chromium.org,titzer@chromium.org,ahaas@chromium.org,clemensh@chromium.org

Change-Id: I653e27b46dbc43ad773eda4292d521a508f42d79
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7424
Reviewed-on: https://chromium-review.googlesource.com/995418Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52364}
parent b6021b98
...@@ -213,6 +213,12 @@ bool RelocInfo::OffHeapTargetIsCodedSpecially() { ...@@ -213,6 +213,12 @@ bool RelocInfo::OffHeapTargetIsCodedSpecially() {
#endif #endif
} }
void RelocInfo::set_wasm_context_reference(Address address,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmContextReference(rmode_));
set_embedded_address(address, icache_flush_mode);
}
void RelocInfo::set_global_handle(Address address, void RelocInfo::set_global_handle(Address address,
ICacheFlushMode icache_flush_mode) { ICacheFlushMode icache_flush_mode) {
DCHECK_EQ(rmode_, WASM_GLOBAL_HANDLE); DCHECK_EQ(rmode_, WASM_GLOBAL_HANDLE);
...@@ -236,6 +242,11 @@ Address RelocInfo::global_handle() const { ...@@ -236,6 +242,11 @@ Address RelocInfo::global_handle() const {
return embedded_address(); return embedded_address();
} }
Address RelocInfo::wasm_context_reference() const {
DCHECK(IsWasmContextReference(rmode_));
return embedded_address();
}
void RelocInfo::set_target_address(Address target, void RelocInfo::set_target_address(Address target,
WriteBarrierMode write_barrier_mode, WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) { ICacheFlushMode icache_flush_mode) {
...@@ -535,6 +546,8 @@ const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { ...@@ -535,6 +546,8 @@ const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
return "constant pool"; return "constant pool";
case VENEER_POOL: case VENEER_POOL:
return "veneer pool"; return "veneer pool";
case WASM_CONTEXT_REFERENCE:
return "wasm context reference";
case WASM_GLOBAL_HANDLE: case WASM_GLOBAL_HANDLE:
return "global handle"; return "global handle";
case WASM_CALL: case WASM_CALL:
...@@ -637,6 +650,7 @@ void RelocInfo::Verify(Isolate* isolate) { ...@@ -637,6 +650,7 @@ void RelocInfo::Verify(Isolate* isolate) {
case DEOPT_ID: case DEOPT_ID:
case CONST_POOL: case CONST_POOL:
case VENEER_POOL: case VENEER_POOL:
case WASM_CONTEXT_REFERENCE:
case WASM_GLOBAL_HANDLE: case WASM_GLOBAL_HANDLE:
case WASM_CALL: case WASM_CALL:
case JS_TO_WASM_CALL: case JS_TO_WASM_CALL:
......
...@@ -366,6 +366,10 @@ class RelocInfo { ...@@ -366,6 +366,10 @@ class RelocInfo {
// Please note the order is important (see IsCodeTarget, IsGCRelocMode). // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
CODE_TARGET, CODE_TARGET,
EMBEDDED_OBJECT, EMBEDDED_OBJECT,
// Wasm entries are to relocate pointers into the wasm memory embedded in
// wasm code. Everything after WASM_CONTEXT_REFERENCE (inclusive) is not
// GC'ed.
WASM_CONTEXT_REFERENCE,
WASM_GLOBAL_HANDLE, WASM_GLOBAL_HANDLE,
WASM_CALL, WASM_CALL,
JS_TO_WASM_CALL, JS_TO_WASM_CALL,
...@@ -462,12 +466,15 @@ class RelocInfo { ...@@ -462,12 +466,15 @@ class RelocInfo {
return mode == OFF_HEAP_TARGET; return mode == OFF_HEAP_TARGET;
} }
static inline bool IsNone(Mode mode) { return mode == NONE; } static inline bool IsNone(Mode mode) { return mode == NONE; }
static inline bool IsWasmContextReference(Mode mode) {
return mode == WASM_CONTEXT_REFERENCE;
}
static inline bool IsWasmReference(Mode mode) { static inline bool IsWasmReference(Mode mode) {
return IsWasmPtrReference(mode); return IsWasmPtrReference(mode);
} }
static inline bool IsWasmPtrReference(Mode mode) { static inline bool IsWasmPtrReference(Mode mode) {
return mode == WASM_GLOBAL_HANDLE || mode == WASM_CALL || return mode == WASM_CONTEXT_REFERENCE || mode == WASM_GLOBAL_HANDLE ||
mode == JS_TO_WASM_CALL; mode == WASM_CALL || mode == JS_TO_WASM_CALL;
} }
static constexpr int ModeMask(Mode mode) { return 1 << mode; } static constexpr int ModeMask(Mode mode) { return 1 << mode; }
...@@ -502,10 +509,14 @@ class RelocInfo { ...@@ -502,10 +509,14 @@ class RelocInfo {
// constant pool, otherwise the pointer is embedded in the instruction stream. // constant pool, otherwise the pointer is embedded in the instruction stream.
bool IsInConstantPool(); bool IsInConstantPool();
Address wasm_context_reference() const;
Address global_handle() const; Address global_handle() const;
Address js_to_wasm_address() const; Address js_to_wasm_address() const;
Address wasm_call_address() const; Address wasm_call_address() const;
void set_wasm_context_reference(
Address address,
ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
void set_target_address( void set_target_address(
Address target, Address target,
WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER, WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
......
...@@ -281,15 +281,15 @@ void Int64Lowering::LowerNode(Node* node) { ...@@ -281,15 +281,15 @@ void Int64Lowering::LowerNode(Node* node) {
static_cast<int>(signature()->parameter_count())) { static_cast<int>(signature()->parameter_count())) {
int old_index = ParameterIndexOf(node->op()); int old_index = ParameterIndexOf(node->op());
// TODO(wasm): Make this part not wasm specific. // TODO(wasm): Make this part not wasm specific.
// Prevent special lowering of the instance parameter. // Prevent special lowering of the WasmContext parameter.
if (old_index == kWasmInstanceParameterIndex) { if (old_index == kWasmContextParameterIndex) {
DefaultLowering(node); DefaultLowering(node);
break; break;
} }
// Adjust old_index to be compliant with the signature. // Adjust old_index to be compliant with the signature.
--old_index; --old_index;
int new_index = GetParameterIndexAfterLowering(signature(), old_index); int new_index = GetParameterIndexAfterLowering(signature(), old_index);
// Adjust new_index to consider the instance parameter. // Adjust new_index to consider the WasmContext parameter.
++new_index; ++new_index;
NodeProperties::ChangeOp(node, common()->Parameter(new_index)); NodeProperties::ChangeOp(node, common()->Parameter(new_index));
......
This diff is collapsed.
This diff is collapsed.
...@@ -32,8 +32,6 @@ MachineType MachineTypeFor(ValueType type) { ...@@ -32,8 +32,6 @@ MachineType MachineTypeFor(ValueType type) {
return MachineType::Float32(); return MachineType::Float32();
case wasm::kWasmS128: case wasm::kWasmS128:
return MachineType::Simd128(); return MachineType::Simd128();
case wasm::kWasmAnyRef:
return MachineType::TaggedPointer();
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -227,15 +225,15 @@ static constexpr Allocator parameter_registers(kGPParamRegisters, ...@@ -227,15 +225,15 @@ static constexpr Allocator parameter_registers(kGPParamRegisters,
// General code uses the above configuration data. // General code uses the above configuration data.
CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig, CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig,
bool use_retpoline) { bool use_retpoline) {
// The '+ 1' here is to accomodate the instance object as first parameter. // The '+ 1' here is to accomodate the wasm_context as first parameter.
LocationSignature::Builder locations(zone, fsig->return_count(), LocationSignature::Builder locations(zone, fsig->return_count(),
fsig->parameter_count() + 1); fsig->parameter_count() + 1);
// Add register and/or stack parameter(s). // Add register and/or stack parameter(s).
Allocator params = parameter_registers; Allocator params = parameter_registers;
// The instance object. // The wasm_context.
locations.AddParam(params.Next(MachineRepresentation::kTaggedPointer)); locations.AddParam(params.Next(MachineType::PointerRepresentation()));
const int parameter_count = static_cast<int>(fsig->parameter_count()); const int parameter_count = static_cast<int>(fsig->parameter_count());
for (int i = 0; i < parameter_count; i++) { for (int i = 0; i < parameter_count; i++) {
......
...@@ -137,8 +137,8 @@ class ElementsAccessor { ...@@ -137,8 +137,8 @@ class ElementsAccessor {
virtual uint32_t Push(Handle<JSArray> receiver, Arguments* args, virtual uint32_t Push(Handle<JSArray> receiver, Arguments* args,
uint32_t push_size) = 0; uint32_t push_size) = 0;
virtual uint32_t Unshift(Handle<JSArray> receiver, Arguments* args, virtual uint32_t Unshift(Handle<JSArray> receiver,
uint32_t unshift_size) = 0; Arguments* args, uint32_t unshift_size) = 0;
virtual Handle<JSObject> Slice(Handle<JSObject> receiver, uint32_t start, virtual Handle<JSObject> Slice(Handle<JSObject> receiver, uint32_t start,
uint32_t end) = 0; uint32_t end) = 0;
......
...@@ -1140,6 +1140,8 @@ void JSFunction::JSFunctionPrint(std::ostream& os) { // NOLINT ...@@ -1140,6 +1140,8 @@ void JSFunction::JSFunctionPrint(std::ostream& os) { // NOLINT
WasmExportedFunction* function = WasmExportedFunction::cast(this); WasmExportedFunction* function = WasmExportedFunction::cast(this);
os << "\n - WASM instance " os << "\n - WASM instance "
<< reinterpret_cast<void*>(function->instance()); << reinterpret_cast<void*>(function->instance());
os << "\n context "
<< reinterpret_cast<void*>(function->instance()->wasm_context()->get());
os << "\n - WASM function index " << function->function_index(); os << "\n - WASM function index " << function->function_index();
} }
shared()->PrintSourceCode(os); shared()->PrintSourceCode(os);
......
...@@ -14228,6 +14228,7 @@ bool Code::IsProcessIndependent() { ...@@ -14228,6 +14228,7 @@ bool Code::IsProcessIndependent() {
mode_mask == mode_mask ==
(RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | (RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::WASM_CONTEXT_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_HANDLE) | RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_HANDLE) |
RelocInfo::ModeMask(RelocInfo::WASM_CALL) | RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL) | RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL) |
......
...@@ -37,7 +37,6 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) { ...@@ -37,7 +37,6 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
return owning_instance; return owning_instance;
} }
// TODO(titzer): rename to GetNativeContextFromWasmInstanceOnStackTop()
Context* GetWasmContextOnStackTop(Isolate* isolate) { Context* GetWasmContextOnStackTop(Isolate* isolate) {
return GetWasmInstanceOnStackTop(isolate) return GetWasmInstanceOnStackTop(isolate)
->compiled_module() ->compiled_module()
......
...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
BAILOUT("LoadConstant"); BAILOUT("LoadConstant");
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
BAILOUT("LoadFromInstance"); BAILOUT("LoadFromContext");
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
BAILOUT("SpillInstance"); BAILOUT("SpillContext");
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
BAILOUT("FillInstanceInto"); BAILOUT("FillContextInto");
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
......
...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
BAILOUT("LoadConstant"); BAILOUT("LoadConstant");
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
BAILOUT("LoadFromInstance"); BAILOUT("LoadFromContext");
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
BAILOUT("SpillInstance"); BAILOUT("SpillContext");
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
BAILOUT("FillInstanceInto"); BAILOUT("FillContextInto");
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
......
...@@ -16,8 +16,8 @@ namespace wasm { ...@@ -16,8 +16,8 @@ namespace wasm {
namespace liftoff { namespace liftoff {
// ebp-8 holds the stack marker, ebp-16 is the instance parameter, first stack // ebp-8 holds the stack marker, ebp-16 is the wasm context, first stack slot
// slot is located at ebp-24. // is located at ebp-24.
constexpr int32_t kConstantStackSpace = 16; constexpr int32_t kConstantStackSpace = 16;
constexpr int32_t kFirstStackSlotOffset = constexpr int32_t kFirstStackSlotOffset =
kConstantStackSpace + LiftoffAssembler::kStackSlotSize; kConstantStackSpace + LiftoffAssembler::kStackSlotSize;
...@@ -33,7 +33,7 @@ inline Operand GetHalfStackSlot(uint32_t half_index) { ...@@ -33,7 +33,7 @@ inline Operand GetHalfStackSlot(uint32_t half_index) {
} }
// TODO(clemensh): Make this a constexpr variable once Operand is constexpr. // TODO(clemensh): Make this a constexpr variable once Operand is constexpr.
inline Operand GetInstanceOperand() { return Operand(ebp, -16); } inline Operand GetContextOperand() { return Operand(ebp, -16); }
static constexpr LiftoffRegList kByteRegs = static constexpr LiftoffRegList kByteRegs =
LiftoffRegList::FromBits<Register::ListOf<eax, ecx, edx, ebx>()>(); LiftoffRegList::FromBits<Register::ListOf<eax, ecx, edx, ebx>()>();
...@@ -133,20 +133,20 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -133,20 +133,20 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
} }
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
DCHECK_LE(offset, kMaxInt); DCHECK_LE(offset, kMaxInt);
mov(dst, liftoff::GetInstanceOperand()); mov(dst, liftoff::GetContextOperand());
DCHECK_EQ(4, size); DCHECK_EQ(4, size);
mov(dst, Operand(dst, offset)); mov(dst, Operand(dst, offset));
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
mov(liftoff::GetInstanceOperand(), instance); mov(liftoff::GetContextOperand(), context);
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
mov(dst, liftoff::GetInstanceOperand()); mov(dst, liftoff::GetContextOperand());
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
...@@ -1182,7 +1182,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) { ...@@ -1182,7 +1182,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) {
} }
void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) { void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) {
// Set instance to zero. // Set context to zero.
xor_(esi, esi); xor_(esi, esi);
CallRuntimeDelayed(zone, fid); CallRuntimeDelayed(zone, fid);
} }
......
...@@ -437,7 +437,7 @@ void LiftoffAssembler::SpillAllRegisters() { ...@@ -437,7 +437,7 @@ void LiftoffAssembler::SpillAllRegisters() {
void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig, void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig,
compiler::CallDescriptor* call_descriptor, compiler::CallDescriptor* call_descriptor,
Register* target, Register* target,
LiftoffRegister* target_instance) { LiftoffRegister* explicit_context) {
uint32_t num_params = static_cast<uint32_t>(sig->parameter_count()); uint32_t num_params = static_cast<uint32_t>(sig->parameter_count());
// Input 0 is the call target. // Input 0 is the call target.
constexpr size_t kInputShift = 1; constexpr size_t kInputShift = 1;
...@@ -455,14 +455,14 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig, ...@@ -455,14 +455,14 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig,
StackTransferRecipe stack_transfers(this); StackTransferRecipe stack_transfers(this);
LiftoffRegList param_regs; LiftoffRegList param_regs;
// Move the target instance (if supplied) into the correct instance register. // Move the explicit context (if any) into the correct context register.
compiler::LinkageLocation instance_loc = compiler::LinkageLocation context_loc =
call_descriptor->GetInputLocation(kInputShift); call_descriptor->GetInputLocation(kInputShift);
DCHECK(instance_loc.IsRegister() && !instance_loc.IsAnyRegister()); DCHECK(context_loc.IsRegister() && !context_loc.IsAnyRegister());
LiftoffRegister instance_reg(Register::from_code(instance_loc.AsRegister())); LiftoffRegister context_reg(Register::from_code(context_loc.AsRegister()));
param_regs.set(instance_reg); param_regs.set(context_reg);
if (target_instance && *target_instance != instance_reg) { if (explicit_context && *explicit_context != context_reg) {
stack_transfers.MoveRegister(instance_reg, *target_instance, kWasmIntPtr); stack_transfers.MoveRegister(context_reg, *explicit_context, kWasmIntPtr);
} }
// Now move all parameter values into the right slot for the call. // Now move all parameter values into the right slot for the call.
...@@ -504,7 +504,7 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig, ...@@ -504,7 +504,7 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig,
} }
} }
} }
// {call_desc_input_idx} should point after the instance parameter now. // {call_desc_input_idx} should point after the context parameter now.
DCHECK_EQ(call_desc_input_idx, kInputShift + 1); DCHECK_EQ(call_desc_input_idx, kInputShift + 1);
// If the target register overlaps with a parameter register, then move the // If the target register overlaps with a parameter register, then move the
...@@ -523,7 +523,7 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig, ...@@ -523,7 +523,7 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig,
} }
} }
// Execute the stack transfers before filling the instance register. // Execute the stack transfers before filling the context register.
stack_transfers.Execute(); stack_transfers.Execute();
// Pop parameters from the value stack. // Pop parameters from the value stack.
...@@ -533,9 +533,9 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig, ...@@ -533,9 +533,9 @@ void LiftoffAssembler::PrepareCall(wasm::FunctionSig* sig,
// Reset register use counters. // Reset register use counters.
cache_state_.reset_used_registers(); cache_state_.reset_used_registers();
// Reload the instance from the stack. // Reload the context from the stack.
if (!target_instance) { if (!explicit_context) {
FillInstanceInto(instance_reg.gp()); FillContextInto(context_reg.gp());
} }
} }
......
...@@ -322,7 +322,7 @@ class LiftoffAssembler : public TurboAssembler { ...@@ -322,7 +322,7 @@ class LiftoffAssembler : public TurboAssembler {
// register, or {no_reg} if target was spilled to the stack. // register, or {no_reg} if target was spilled to the stack.
void PrepareCall(wasm::FunctionSig*, compiler::CallDescriptor*, void PrepareCall(wasm::FunctionSig*, compiler::CallDescriptor*,
Register* target = nullptr, Register* target = nullptr,
LiftoffRegister* target_instance = nullptr); LiftoffRegister* explicit_context = nullptr);
// Process return values of the call. // Process return values of the call.
void FinishCall(wasm::FunctionSig*, compiler::CallDescriptor*); void FinishCall(wasm::FunctionSig*, compiler::CallDescriptor*);
...@@ -352,9 +352,9 @@ class LiftoffAssembler : public TurboAssembler { ...@@ -352,9 +352,9 @@ class LiftoffAssembler : public TurboAssembler {
inline void LoadConstant(LiftoffRegister, WasmValue, inline void LoadConstant(LiftoffRegister, WasmValue,
RelocInfo::Mode rmode = RelocInfo::NONE); RelocInfo::Mode rmode = RelocInfo::NONE);
inline void LoadFromInstance(Register dst, uint32_t offset, int size); inline void LoadFromContext(Register dst, uint32_t offset, int size);
inline void SpillInstance(Register instance); inline void SpillContext(Register context);
inline void FillInstanceInto(Register dst); inline void FillContextInto(Register dst);
inline void Load(LiftoffRegister dst, Register src_addr, Register offset_reg, inline void Load(LiftoffRegister dst, Register src_addr, Register offset_reg,
uint32_t offset_imm, LoadType type, LiftoffRegList pinned, uint32_t offset_imm, LoadType type, LiftoffRegList pinned,
uint32_t* protected_load_pc = nullptr); uint32_t* protected_load_pc = nullptr);
......
This diff is collapsed.
...@@ -15,8 +15,8 @@ namespace wasm { ...@@ -15,8 +15,8 @@ namespace wasm {
namespace liftoff { namespace liftoff {
// fp-8 holds the stack marker, fp-16 is the instance parameter, first stack // fp-8 holds the stack marker, fp-16 is the wasm context, first stack slot
// slot is located at fp-24. // is located at fp-24.
constexpr int32_t kConstantStackSpace = 16; constexpr int32_t kConstantStackSpace = 16;
constexpr int32_t kFirstStackSlotOffset = constexpr int32_t kFirstStackSlotOffset =
kConstantStackSpace + LiftoffAssembler::kStackSlotSize; kConstantStackSpace + LiftoffAssembler::kStackSlotSize;
...@@ -31,7 +31,7 @@ inline MemOperand GetHalfStackSlot(uint32_t half_index) { ...@@ -31,7 +31,7 @@ inline MemOperand GetHalfStackSlot(uint32_t half_index) {
return MemOperand(fp, -kFirstStackSlotOffset - offset); return MemOperand(fp, -kFirstStackSlotOffset - offset);
} }
inline MemOperand GetInstanceOperand() { return MemOperand(fp, -16); } inline MemOperand GetContextOperand() { return MemOperand(fp, -16); }
// Use this register to store the address of the last argument pushed on the // Use this register to store the address of the last argument pushed on the
// stack for a call to C. This register must be callee saved according to the c // stack for a call to C. This register must be callee saved according to the c
...@@ -129,20 +129,20 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -129,20 +129,20 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
} }
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
DCHECK_LE(offset, kMaxInt); DCHECK_LE(offset, kMaxInt);
lw(dst, liftoff::GetInstanceOperand()); lw(dst, liftoff::GetContextOperand());
DCHECK_EQ(4, size); DCHECK_EQ(4, size);
lw(dst, MemOperand(dst, offset)); lw(dst, MemOperand(dst, offset));
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
sw(instance, liftoff::GetInstanceOperand()); sw(context, liftoff::GetContextOperand());
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
lw(dst, liftoff::GetInstanceOperand()); lw(dst, liftoff::GetContextOperand());
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
...@@ -880,7 +880,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) { ...@@ -880,7 +880,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) {
} }
void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) { void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) {
// Set instance to zero. // Set context to zero.
TurboAssembler::Move(cp, zero_reg); TurboAssembler::Move(cp, zero_reg);
CallRuntimeDelayed(zone, fid); CallRuntimeDelayed(zone, fid);
} }
......
...@@ -15,8 +15,8 @@ namespace wasm { ...@@ -15,8 +15,8 @@ namespace wasm {
namespace liftoff { namespace liftoff {
// fp-8 holds the stack marker, fp-16 is the instance parameter, first stack // fp-8 holds the stack marker, fp-16 is the wasm context, first stack slot
// slot is located at fp-24. // is located at fp-24.
constexpr int32_t kConstantStackSpace = 16; constexpr int32_t kConstantStackSpace = 16;
constexpr int32_t kFirstStackSlotOffset = constexpr int32_t kFirstStackSlotOffset =
kConstantStackSpace + LiftoffAssembler::kStackSlotSize; kConstantStackSpace + LiftoffAssembler::kStackSlotSize;
...@@ -26,7 +26,7 @@ inline MemOperand GetStackSlot(uint32_t index) { ...@@ -26,7 +26,7 @@ inline MemOperand GetStackSlot(uint32_t index) {
return MemOperand(fp, -kFirstStackSlotOffset - offset); return MemOperand(fp, -kFirstStackSlotOffset - offset);
} }
inline MemOperand GetInstanceOperand() { return MemOperand(fp, -16); } inline MemOperand GetContextOperand() { return MemOperand(fp, -16); }
// Use this register to store the address of the last argument pushed on the // Use this register to store the address of the last argument pushed on the
// stack for a call to C. This register must be callee saved according to the c // stack for a call to C. This register must be callee saved according to the c
...@@ -120,10 +120,10 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -120,10 +120,10 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
} }
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
DCHECK_LE(offset, kMaxInt); DCHECK_LE(offset, kMaxInt);
ld(dst, liftoff::GetInstanceOperand()); ld(dst, liftoff::GetContextOperand());
DCHECK(size == 4 || size == 8); DCHECK(size == 4 || size == 8);
if (size == 4) { if (size == 4) {
lw(dst, MemOperand(dst, offset)); lw(dst, MemOperand(dst, offset));
...@@ -132,12 +132,12 @@ void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, ...@@ -132,12 +132,12 @@ void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset,
} }
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
sd(instance, liftoff::GetInstanceOperand()); sd(context, liftoff::GetContextOperand());
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
ld(dst, liftoff::GetInstanceOperand()); ld(dst, liftoff::GetContextOperand());
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
...@@ -707,7 +707,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) { ...@@ -707,7 +707,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) {
} }
void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) { void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) {
// Set instance to zero. // Set context to zero.
TurboAssembler::Move(cp, zero_reg); TurboAssembler::Move(cp, zero_reg);
CallRuntimeDelayed(zone, fid); CallRuntimeDelayed(zone, fid);
} }
......
...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
BAILOUT("LoadConstant"); BAILOUT("LoadConstant");
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
BAILOUT("LoadFromInstance"); BAILOUT("LoadFromContext");
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
BAILOUT("SpillInstance"); BAILOUT("SpillContext");
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
BAILOUT("FillInstanceInto"); BAILOUT("FillContextInto");
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
......
...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -28,17 +28,17 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
BAILOUT("LoadConstant"); BAILOUT("LoadConstant");
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
BAILOUT("LoadFromInstance"); BAILOUT("LoadFromContext");
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
BAILOUT("SpillInstance"); BAILOUT("SpillContext");
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
BAILOUT("FillInstanceInto"); BAILOUT("FillContextInto");
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
......
...@@ -16,8 +16,8 @@ namespace wasm { ...@@ -16,8 +16,8 @@ namespace wasm {
namespace liftoff { namespace liftoff {
// rbp-8 holds the stack marker, rbp-16 is the instance parameter, first stack // rbp-8 holds the stack marker, rbp-16 is the wasm context, first stack slot
// slot is located at rbp-24. // is located at rbp-24.
constexpr int32_t kConstantStackSpace = 16; constexpr int32_t kConstantStackSpace = 16;
constexpr int32_t kFirstStackSlotOffset = constexpr int32_t kFirstStackSlotOffset =
kConstantStackSpace + LiftoffAssembler::kStackSlotSize; kConstantStackSpace + LiftoffAssembler::kStackSlotSize;
...@@ -28,7 +28,7 @@ inline Operand GetStackSlot(uint32_t index) { ...@@ -28,7 +28,7 @@ inline Operand GetStackSlot(uint32_t index) {
} }
// TODO(clemensh): Make this a constexpr variable once Operand is constexpr. // TODO(clemensh): Make this a constexpr variable once Operand is constexpr.
inline Operand GetInstanceOperand() { return Operand(rbp, -16); } inline Operand GetContextOperand() { return Operand(rbp, -16); }
// Use this register to store the address of the last argument pushed on the // Use this register to store the address of the last argument pushed on the
// stack for a call to C. This register must be callee saved according to the c // stack for a call to C. This register must be callee saved according to the c
...@@ -131,10 +131,10 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value, ...@@ -131,10 +131,10 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
} }
} }
void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
int size) { int size) {
DCHECK_LE(offset, kMaxInt); DCHECK_LE(offset, kMaxInt);
movp(dst, liftoff::GetInstanceOperand()); movp(dst, liftoff::GetContextOperand());
DCHECK(size == 4 || size == 8); DCHECK(size == 4 || size == 8);
if (size == 4) { if (size == 4) {
movl(dst, Operand(dst, offset)); movl(dst, Operand(dst, offset));
...@@ -143,12 +143,12 @@ void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset, ...@@ -143,12 +143,12 @@ void LiftoffAssembler::LoadFromInstance(Register dst, uint32_t offset,
} }
} }
void LiftoffAssembler::SpillInstance(Register instance) { void LiftoffAssembler::SpillContext(Register context) {
movp(liftoff::GetInstanceOperand(), instance); movp(liftoff::GetContextOperand(), context);
} }
void LiftoffAssembler::FillInstanceInto(Register dst) { void LiftoffAssembler::FillContextInto(Register dst) {
movp(dst, liftoff::GetInstanceOperand()); movp(dst, liftoff::GetContextOperand());
} }
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
...@@ -972,7 +972,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) { ...@@ -972,7 +972,7 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) {
} }
void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) { void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) {
// Set instance to zero. // Set context to zero.
xorp(rsi, rsi); xorp(rsi, rsi);
CallRuntimeDelayed(zone, fid); CallRuntimeDelayed(zone, fid);
} }
......
...@@ -774,7 +774,7 @@ class WasmDecoder : public Decoder { ...@@ -774,7 +774,7 @@ class WasmDecoder : public Decoder {
case kExprGrowMemory: case kExprGrowMemory:
case kExprCallFunction: case kExprCallFunction:
case kExprCallIndirect: case kExprCallIndirect:
// Add instance cache nodes to the assigned set. // Add context cache nodes to the assigned set.
// TODO(titzer): make this more clear. // TODO(titzer): make this more clear.
assigned->Add(locals_count - 1); assigned->Add(locals_count - 1);
length = OpcodeLength(decoder, pc); length = OpcodeLength(decoder, pc);
......
...@@ -37,7 +37,7 @@ struct SsaEnv { ...@@ -37,7 +37,7 @@ struct SsaEnv {
State state; State state;
TFNode* control; TFNode* control;
TFNode* effect; TFNode* effect;
compiler::WasmInstanceCacheNodes instance_cache; compiler::WasmContextCacheNodes context_cache;
TFNode** locals; TFNode** locals;
bool go() { return state >= kReached; } bool go() { return state >= kReached; }
...@@ -46,7 +46,7 @@ struct SsaEnv { ...@@ -46,7 +46,7 @@ struct SsaEnv {
locals = nullptr; locals = nullptr;
control = nullptr; control = nullptr;
effect = nullptr; effect = nullptr;
instance_cache = {}; context_cache = {};
} }
void SetNotMerged() { void SetNotMerged() {
if (state == kMerged) state = kReached; if (state == kMerged) state = kReached;
...@@ -100,14 +100,14 @@ class WasmGraphBuildingInterface { ...@@ -100,14 +100,14 @@ class WasmGraphBuildingInterface {
: nullptr; : nullptr;
// The first '+ 1' is needed by TF Start node, the second '+ 1' is for the // The first '+ 1' is needed by TF Start node, the second '+ 1' is for the
// instance parameter. // wasm_context parameter.
TFNode* start = builder_->Start( TFNode* start = builder_->Start(
static_cast<int>(decoder->sig_->parameter_count() + 1 + 1)); static_cast<int>(decoder->sig_->parameter_count() + 1 + 1));
// Initialize the instance parameter (index 0). // Initialize the wasm_context (the paramater at index 0).
builder_->set_instance_node( builder_->set_wasm_context(
builder_->Param(compiler::kWasmInstanceParameterIndex)); builder_->Param(compiler::kWasmContextParameterIndex));
// Initialize local variables. Parameters are shifted by 1 because of the // Initialize local variables. Parameters are shifted by 1 because of the
// the instance parameter. // the wasm_context.
uint32_t index = 0; uint32_t index = 0;
for (; index < decoder->sig_->parameter_count(); ++index) { for (; index < decoder->sig_->parameter_count(); ++index) {
ssa_env->locals[index] = builder_->Param(index + 1); ssa_env->locals[index] = builder_->Param(index + 1);
...@@ -129,10 +129,11 @@ class WasmGraphBuildingInterface { ...@@ -129,10 +129,11 @@ class WasmGraphBuildingInterface {
SetEnv(ssa_env); SetEnv(ssa_env);
} }
// Reload the instance cache entries into the Ssa Environment. // Reload the wasm context variables from the WasmContext structure attached
// to the memory object into the Ssa Environment.
void LoadContextIntoSsa(SsaEnv* ssa_env) { void LoadContextIntoSsa(SsaEnv* ssa_env) {
if (!ssa_env || !ssa_env->go()) return; if (!ssa_env || !ssa_env->go()) return;
builder_->InitInstanceCache(&ssa_env->instance_cache); builder_->InitContextCache(&ssa_env->context_cache);
} }
void StartFunctionBody(Decoder* decoder, Control* block) { void StartFunctionBody(Decoder* decoder, Control* block) {
...@@ -365,7 +366,7 @@ class WasmGraphBuildingInterface { ...@@ -365,7 +366,7 @@ class WasmGraphBuildingInterface {
void GrowMemory(Decoder* decoder, const Value& value, Value* result) { void GrowMemory(Decoder* decoder, const Value& value, Value* result) {
result->node = BUILD(GrowMemory, value.node); result->node = BUILD(GrowMemory, value.node);
// Always reload the instance cache after growing memory. // Always reload the context cache after growing memory.
LoadContextIntoSsa(ssa_env_); LoadContextIntoSsa(ssa_env_);
} }
...@@ -548,10 +549,10 @@ class WasmGraphBuildingInterface { ...@@ -548,10 +549,10 @@ class WasmGraphBuildingInterface {
} }
#endif #endif
ssa_env_ = env; ssa_env_ = env;
// TODO(wasm): combine the control and effect pointers with instance cache. // TODO(wasm): combine the control and effect pointers with context cache.
builder_->set_control_ptr(&env->control); builder_->set_control_ptr(&env->control);
builder_->set_effect_ptr(&env->effect); builder_->set_effect_ptr(&env->effect);
builder_->set_instance_cache(&env->instance_cache); builder_->set_context_cache(&env->context_cache);
} }
TFNode* CheckForException(Decoder* decoder, TFNode* node) { TFNode* CheckForException(Decoder* decoder, TFNode* node) {
...@@ -637,7 +638,7 @@ class WasmGraphBuildingInterface { ...@@ -637,7 +638,7 @@ class WasmGraphBuildingInterface {
to->locals = from->locals; to->locals = from->locals;
to->control = from->control; to->control = from->control;
to->effect = from->effect; to->effect = from->effect;
to->instance_cache = from->instance_cache; to->context_cache = from->context_cache;
break; break;
} }
case SsaEnv::kReached: { // Create a new merge. case SsaEnv::kReached: { // Create a new merge.
...@@ -661,9 +662,9 @@ class WasmGraphBuildingInterface { ...@@ -661,9 +662,9 @@ class WasmGraphBuildingInterface {
builder_->Phi(decoder->GetLocalType(i), 2, vals, merge); builder_->Phi(decoder->GetLocalType(i), 2, vals, merge);
} }
} }
// Start a new merge from the instance cache. // Start a new merge from the context cache.
builder_->NewInstanceCacheMerge(&to->instance_cache, builder_->NewContextCacheMerge(&to->context_cache, &from->context_cache,
&from->instance_cache, merge); merge);
break; break;
} }
case SsaEnv::kMerged: { case SsaEnv::kMerged: {
...@@ -678,9 +679,9 @@ class WasmGraphBuildingInterface { ...@@ -678,9 +679,9 @@ class WasmGraphBuildingInterface {
to->locals[i] = builder_->CreateOrMergeIntoPhi( to->locals[i] = builder_->CreateOrMergeIntoPhi(
decoder->GetLocalType(i), merge, to->locals[i], from->locals[i]); decoder->GetLocalType(i), merge, to->locals[i], from->locals[i]);
} }
// Merge the instance caches. // Merge the context caches.
builder_->MergeInstanceCacheInto(&to->instance_cache, builder_->MergeContextCacheInto(&to->context_cache,
&from->instance_cache, merge); &from->context_cache, merge);
break; break;
} }
default: default:
...@@ -696,22 +697,21 @@ class WasmGraphBuildingInterface { ...@@ -696,22 +697,21 @@ class WasmGraphBuildingInterface {
env->control = builder_->Loop(env->control); env->control = builder_->Loop(env->control);
env->effect = builder_->EffectPhi(1, &env->effect, env->control); env->effect = builder_->EffectPhi(1, &env->effect, env->control);
builder_->Terminate(env->effect, env->control); builder_->Terminate(env->effect, env->control);
// The '+ 1' here is to be able to set the instance cache as assigned. // The '+ 1' here is to be able to set the context cache as assigned.
BitVector* assigned = WasmDecoder<validate>::AnalyzeLoopAssignment( BitVector* assigned = WasmDecoder<validate>::AnalyzeLoopAssignment(
decoder, decoder->pc(), decoder->total_locals() + 1, decoder->zone()); decoder, decoder->pc(), decoder->total_locals() + 1, decoder->zone());
if (decoder->failed()) return env; if (decoder->failed()) return env;
if (assigned != nullptr) { if (assigned != nullptr) {
// Only introduce phis for variables assigned in this loop. // Only introduce phis for variables assigned in this loop.
int instance_cache_index = decoder->total_locals(); int context_cache_index = decoder->total_locals();
for (int i = decoder->NumLocals() - 1; i >= 0; i--) { for (int i = decoder->NumLocals() - 1; i >= 0; i--) {
if (!assigned->Contains(i)) continue; if (!assigned->Contains(i)) continue;
env->locals[i] = builder_->Phi(decoder->GetLocalType(i), 1, env->locals[i] = builder_->Phi(decoder->GetLocalType(i), 1,
&env->locals[i], env->control); &env->locals[i], env->control);
} }
// Introduce phis for instance cache pointers if necessary. // Introduce phis for context cache pointers if necessary.
if (assigned->Contains(instance_cache_index)) { if (assigned->Contains(context_cache_index)) {
builder_->PrepareInstanceCacheForLoop(&env->instance_cache, builder_->PrepareContextCacheForLoop(&env->context_cache, env->control);
env->control);
} }
SsaEnv* loop_body_env = Split(decoder, env); SsaEnv* loop_body_env = Split(decoder, env);
...@@ -726,8 +726,8 @@ class WasmGraphBuildingInterface { ...@@ -726,8 +726,8 @@ class WasmGraphBuildingInterface {
&env->locals[i], env->control); &env->locals[i], env->control);
} }
// Conservatively introduce phis for instance cache. // Conservatively introduce phis for context cache.
builder_->PrepareInstanceCacheForLoop(&env->instance_cache, env->control); builder_->PrepareContextCacheForLoop(&env->context_cache, env->control);
SsaEnv* loop_body_env = Split(decoder, env); SsaEnv* loop_body_env = Split(decoder, env);
builder_->StackCheck(decoder->position(), &loop_body_env->effect, builder_->StackCheck(decoder->position(), &loop_body_env->effect,
...@@ -750,11 +750,11 @@ class WasmGraphBuildingInterface { ...@@ -750,11 +750,11 @@ class WasmGraphBuildingInterface {
size > 0 ? reinterpret_cast<TFNode**>(decoder->zone()->New(size)) size > 0 ? reinterpret_cast<TFNode**>(decoder->zone()->New(size))
: nullptr; : nullptr;
memcpy(result->locals, from->locals, size); memcpy(result->locals, from->locals, size);
result->instance_cache = from->instance_cache; result->context_cache = from->context_cache;
} else { } else {
result->state = SsaEnv::kUnreachable; result->state = SsaEnv::kUnreachable;
result->locals = nullptr; result->locals = nullptr;
result->instance_cache = {}; result->context_cache = {};
} }
return result; return result;
...@@ -770,7 +770,7 @@ class WasmGraphBuildingInterface { ...@@ -770,7 +770,7 @@ class WasmGraphBuildingInterface {
result->locals = from->locals; result->locals = from->locals;
result->control = from->control; result->control = from->control;
result->effect = from->effect; result->effect = from->effect;
result->instance_cache = from->instance_cache; result->context_cache = from->context_cache;
from->Kill(SsaEnv::kUnreachable); from->Kill(SsaEnv::kUnreachable);
return result; return result;
} }
...@@ -782,7 +782,7 @@ class WasmGraphBuildingInterface { ...@@ -782,7 +782,7 @@ class WasmGraphBuildingInterface {
result->control = nullptr; result->control = nullptr;
result->effect = nullptr; result->effect = nullptr;
result->locals = nullptr; result->locals = nullptr;
result->instance_cache = {}; result->context_cache = {};
return result; return result;
} }
......
This diff is collapsed.
...@@ -70,7 +70,7 @@ Address CompileLazy(Isolate* isolate); ...@@ -70,7 +70,7 @@ Address CompileLazy(Isolate* isolate);
// logic to actually orchestrate parallel execution of wasm compilation jobs. // logic to actually orchestrate parallel execution of wasm compilation jobs.
// TODO(clemensh): Implement concurrent lazy compilation. // TODO(clemensh): Implement concurrent lazy compilation.
class LazyCompilationOrchestrator { class LazyCompilationOrchestrator {
const WasmCode* CompileFunction(Isolate*, Handle<WasmCompiledModule>, const WasmCode* CompileFunction(Isolate*, Handle<WasmInstanceObject>,
int func_index); int func_index);
public: public:
...@@ -79,8 +79,9 @@ class LazyCompilationOrchestrator { ...@@ -79,8 +79,9 @@ class LazyCompilationOrchestrator {
Handle<Code> caller, Handle<Code> caller,
uint32_t exported_func_index); uint32_t exported_func_index);
const wasm::WasmCode* CompileDirectCall(Isolate*, Handle<WasmInstanceObject>, const wasm::WasmCode* CompileDirectCall(Isolate*, Handle<WasmInstanceObject>,
Maybe<uint32_t>,
const WasmCode* caller, const WasmCode* caller,
int caller_ret_offset); int call_offset);
const wasm::WasmCode* CompileIndirectCall(Isolate*, const wasm::WasmCode* CompileIndirectCall(Isolate*,
Handle<WasmInstanceObject>, Handle<WasmInstanceObject>,
uint32_t func_index); uint32_t func_index);
......
...@@ -449,15 +449,9 @@ void NativeModule::ResizeCodeTableForTest(size_t last_index) { ...@@ -449,15 +449,9 @@ void NativeModule::ResizeCodeTableForTest(size_t last_index) {
} }
WasmCode* NativeModule::GetCode(uint32_t index) const { WasmCode* NativeModule::GetCode(uint32_t index) const {
DCHECK_LT(index, FunctionCount());
return code_table_[index]; return code_table_[index];
} }
void NativeModule::SetCode(uint32_t index, WasmCode* wasm_code) {
DCHECK_LT(index, FunctionCount());
code_table_[index] = wasm_code;
}
uint32_t NativeModule::FunctionCount() const { uint32_t NativeModule::FunctionCount() const {
DCHECK_LE(code_table_.size(), std::numeric_limits<uint32_t>::max()); DCHECK_LE(code_table_.size(), std::numeric_limits<uint32_t>::max());
return static_cast<uint32_t>(code_table_.size()); return static_cast<uint32_t>(code_table_.size());
...@@ -600,10 +594,6 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code, ...@@ -600,10 +594,6 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
// made while iterating over the RelocInfo above. // made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(), Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size()); ret->instructions().size());
if (FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here.
ret->Print(code->GetIsolate());
}
return ret; return ret;
} }
......
...@@ -258,7 +258,6 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -258,7 +258,6 @@ class V8_EXPORT_PRIVATE NativeModule final {
// FunctionCount is WasmModule::functions.size(). // FunctionCount is WasmModule::functions.size().
uint32_t FunctionCount() const; uint32_t FunctionCount() const;
WasmCode* GetCode(uint32_t index) const; WasmCode* GetCode(uint32_t index) const;
void SetCode(uint32_t index, WasmCode* wasm_code);
// We special-case lazy cloning because we currently rely on making copies // We special-case lazy cloning because we currently rely on making copies
// of the lazy builtin, to be able to identify, in the runtime, which function // of the lazy builtin, to be able to identify, in the runtime, which function
......
...@@ -63,12 +63,10 @@ CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone) {} ...@@ -63,12 +63,10 @@ CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone) {}
CodeSpecialization::~CodeSpecialization() {} CodeSpecialization::~CodeSpecialization() {}
void CodeSpecialization::UpdateInstanceReferences( void CodeSpecialization::RelocateWasmContextReferences(Address new_context) {
Handle<WeakCell> old_weak_instance, Handle<WeakCell> new_weak_instance) { DCHECK_NOT_NULL(new_context);
DCHECK(!old_weak_instance.is_null()); DCHECK_NULL(new_wasm_context_address_);
DCHECK(!new_weak_instance.is_null()); new_wasm_context_address_ = new_context;
old_weak_instance_ = old_weak_instance;
new_weak_instance_ = new_weak_instance;
} }
void CodeSpecialization::RelocateDirectCalls(NativeModule* native_module) { void CodeSpecialization::RelocateDirectCalls(NativeModule* native_module) {
...@@ -102,11 +100,12 @@ bool CodeSpecialization::ApplyToWholeModule(NativeModule* native_module, ...@@ -102,11 +100,12 @@ bool CodeSpecialization::ApplyToWholeModule(NativeModule* native_module,
changed |= ApplyToWasmCode(wasm_function, icache_flush_mode); changed |= ApplyToWasmCode(wasm_function, icache_flush_mode);
} }
bool patch_wasm_weak_instances =
!old_weak_instance_.is_identical_to(new_weak_instance_);
// Patch all exported functions (JS_TO_WASM_FUNCTION). // Patch all exported functions (JS_TO_WASM_FUNCTION).
int reloc_mode = 0; int reloc_mode = 0;
// We need to patch WASM_CONTEXT_REFERENCE to put the correct address.
if (new_wasm_context_address_) {
reloc_mode |= RelocInfo::ModeMask(RelocInfo::WASM_CONTEXT_REFERENCE);
}
// Patch CODE_TARGET if we shall relocate direct calls. If we patch direct // Patch CODE_TARGET if we shall relocate direct calls. If we patch direct
// calls, the instance registered for that (relocate_direct_calls_module_) // calls, the instance registered for that (relocate_direct_calls_module_)
// should match the instance we currently patch (instance). // should match the instance we currently patch (instance).
...@@ -114,10 +113,6 @@ bool CodeSpecialization::ApplyToWholeModule(NativeModule* native_module, ...@@ -114,10 +113,6 @@ bool CodeSpecialization::ApplyToWholeModule(NativeModule* native_module,
DCHECK_EQ(native_module, relocate_direct_calls_module_); DCHECK_EQ(native_module, relocate_direct_calls_module_);
reloc_mode |= RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL); reloc_mode |= RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL);
} }
// Instance references are simply embedded objects.
if (patch_wasm_weak_instances) {
reloc_mode |= RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
}
if (!reloc_mode) return changed; if (!reloc_mode) return changed;
int wrapper_index = 0; int wrapper_index = 0;
for (auto exp : module->export_table) { for (auto exp : module->export_table) {
...@@ -128,25 +123,20 @@ bool CodeSpecialization::ApplyToWholeModule(NativeModule* native_module, ...@@ -128,25 +123,20 @@ bool CodeSpecialization::ApplyToWholeModule(NativeModule* native_module,
for (RelocIterator it(export_wrapper, reloc_mode); !it.done(); it.next()) { for (RelocIterator it(export_wrapper, reloc_mode); !it.done(); it.next()) {
RelocInfo::Mode mode = it.rinfo()->rmode(); RelocInfo::Mode mode = it.rinfo()->rmode();
switch (mode) { switch (mode) {
case RelocInfo::WASM_CONTEXT_REFERENCE:
it.rinfo()->set_wasm_context_reference(new_wasm_context_address_,
icache_flush_mode);
break;
case RelocInfo::JS_TO_WASM_CALL: { case RelocInfo::JS_TO_WASM_CALL: {
changed = true;
const WasmCode* new_code = native_module->GetCode(exp.index); const WasmCode* new_code = native_module->GetCode(exp.index);
it.rinfo()->set_js_to_wasm_address(new_code->instructions().start(), it.rinfo()->set_js_to_wasm_address(new_code->instructions().start(),
icache_flush_mode); icache_flush_mode);
} break; } break;
case RelocInfo::EMBEDDED_OBJECT: {
changed = true;
const HeapObject* old = it.rinfo()->target_object();
if (*old_weak_instance_ == old) {
it.rinfo()->set_target_object(
*new_weak_instance_, WriteBarrierMode::UPDATE_WRITE_BARRIER,
icache_flush_mode);
}
} break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
changed = true;
} }
DCHECK_EQ(module->functions.size(), func_index); DCHECK_EQ(module->functions.size(), func_index);
DCHECK_EQ(compiled_module->export_wrappers()->length(), wrapper_index); DCHECK_EQ(compiled_module->export_wrappers()->length(), wrapper_index);
......
...@@ -28,10 +28,8 @@ class CodeSpecialization { ...@@ -28,10 +28,8 @@ class CodeSpecialization {
CodeSpecialization(Isolate*, Zone*); CodeSpecialization(Isolate*, Zone*);
~CodeSpecialization(); ~CodeSpecialization();
// Update instance references in code. Instance references should only // Update WasmContext references.
// appear in export wrappers. void RelocateWasmContextReferences(Address new_context);
void UpdateInstanceReferences(Handle<WeakCell> old_weak_instance,
Handle<WeakCell> new_weak_instance);
// Update all direct call sites based on the code table in the given instance. // Update all direct call sites based on the code table in the given instance.
void RelocateDirectCalls(NativeModule* module); void RelocateDirectCalls(NativeModule* module);
// Apply all relocations and patching to all code in the instance (wasm code // Apply all relocations and patching to all code in the instance (wasm code
...@@ -43,8 +41,8 @@ class CodeSpecialization { ...@@ -43,8 +41,8 @@ class CodeSpecialization {
ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED); ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED);
private: private:
Handle<WeakCell> old_weak_instance_; Address new_wasm_context_address_ = 0;
Handle<WeakCell> new_weak_instance_;
NativeModule* relocate_direct_calls_module_ = nullptr; NativeModule* relocate_direct_calls_module_ = nullptr;
}; };
......
...@@ -140,13 +140,12 @@ class InterpreterHandle { ...@@ -140,13 +140,12 @@ class InterpreterHandle {
} }
public: public:
// TODO(wasm): properly handlify this constructor.
InterpreterHandle(Isolate* isolate, WasmDebugInfo* debug_info) InterpreterHandle(Isolate* isolate, WasmDebugInfo* debug_info)
: isolate_(isolate), : isolate_(isolate),
module_( module_(
debug_info->wasm_instance()->compiled_module()->shared()->module()), debug_info->wasm_instance()->compiled_module()->shared()->module()),
interpreter_(isolate, module_, GetBytes(debug_info), interpreter_(isolate, module_, GetBytes(debug_info),
handle(debug_info->wasm_instance())) {} debug_info->wasm_instance()->wasm_context()->get()) {}
~InterpreterHandle() { DCHECK_EQ(0, activations_.size()); } ~InterpreterHandle() { DCHECK_EQ(0, activations_.size()); }
...@@ -198,6 +197,8 @@ class InterpreterHandle { ...@@ -198,6 +197,8 @@ class InterpreterHandle {
uint32_t activation_id = StartActivation(frame_pointer); uint32_t activation_id = StartActivation(frame_pointer);
WasmInterpreter::HeapObjectsScope heap_objects_scope(&interpreter_,
instance_object);
WasmInterpreter::Thread* thread = interpreter_.GetThread(0); WasmInterpreter::Thread* thread = interpreter_.GetThread(0);
thread->InitFrame(&module()->functions[func_index], wasm_args.start()); thread->InitFrame(&module()->functions[func_index], wasm_args.start());
bool finished = false; bool finished = false;
...@@ -680,7 +681,7 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info, ...@@ -680,7 +681,7 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
if (!interpreted_functions->get(func_index)->IsUndefined(isolate)) continue; if (!interpreted_functions->get(func_index)->IsUndefined(isolate)) continue;
Handle<Code> new_code = compiler::CompileWasmInterpreterEntry( Handle<Code> new_code = compiler::CompileWasmInterpreterEntry(
isolate, func_index, module->functions[func_index].sig); isolate, func_index, module->functions[func_index].sig, instance);
const wasm::WasmCode* wasm_new_code = const wasm::WasmCode* wasm_new_code =
native_module->AddInterpreterWrapper(new_code, func_index); native_module->AddInterpreterWrapper(new_code, func_index);
const wasm::WasmCode* old_code = const wasm::WasmCode* old_code =
......
This diff is collapsed.
...@@ -16,6 +16,7 @@ class AccountingAllocator; ...@@ -16,6 +16,7 @@ class AccountingAllocator;
namespace internal { namespace internal {
class WasmInstanceObject; class WasmInstanceObject;
struct WasmContext;
namespace wasm { namespace wasm {
...@@ -87,6 +88,19 @@ class InterpretedFrame { ...@@ -87,6 +88,19 @@ class InterpretedFrame {
// An interpreter capable of executing WebAssembly. // An interpreter capable of executing WebAssembly.
class V8_EXPORT_PRIVATE WasmInterpreter { class V8_EXPORT_PRIVATE WasmInterpreter {
public: public:
// Open a HeapObjectsScope before running any code in the interpreter which
// needs access to the instance object or needs to call to JS functions.
class V8_EXPORT_PRIVATE HeapObjectsScope {
public:
HeapObjectsScope(WasmInterpreter* interpreter,
Handle<WasmInstanceObject> instance);
~HeapObjectsScope();
private:
char data[3 * sizeof(void*)]; // must match sizeof(HeapObjectsScopeImpl).
DISALLOW_COPY_AND_ASSIGN(HeapObjectsScope);
};
// State machine for a Thread: // State machine for a Thread:
// +---------Run()/Step()--------+ // +---------Run()/Step()--------+
// V | // V |
...@@ -167,8 +181,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter { ...@@ -167,8 +181,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
}; };
WasmInterpreter(Isolate* isolate, const WasmModule* module, WasmInterpreter(Isolate* isolate, const WasmModule* module,
const ModuleWireBytes& wire_bytes, const ModuleWireBytes& wire_bytes, WasmContext* wasm_context);
Handle<WasmInstanceObject> instance);
~WasmInterpreter(); ~WasmInterpreter();
//========================================================================== //==========================================================================
......
...@@ -65,21 +65,19 @@ SMI_ACCESSORS(WasmGlobalObject, offset, kOffsetOffset) ...@@ -65,21 +65,19 @@ SMI_ACCESSORS(WasmGlobalObject, offset, kOffsetOffset)
SMI_ACCESSORS(WasmGlobalObject, is_mutable, kIsMutableOffset) SMI_ACCESSORS(WasmGlobalObject, is_mutable, kIsMutableOffset)
// WasmInstanceObject // WasmInstanceObject
ACCESSORS(WasmInstanceObject, wasm_context, Managed<WasmContext>,
kWasmContextOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_start, byte*, kMemoryStartOffset) PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_start, byte*, kMemoryStartOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_size, uintptr_t, PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_size, uintptr_t,
kMemorySizeOffset) kMemorySizeOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_mask, uintptr_t, PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_mask, uintptr_t,
kMemoryMaskOffset) kMemoryMaskOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, imported_function_targets, Address*,
kImportedFunctionTargetsOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, globals_start, byte*, PRIMITIVE_ACCESSORS(WasmInstanceObject, globals_start, byte*,
kGlobalsStartOffset) kGlobalsStartOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table,
IndirectFunctionTableEntry*, kIndirectFunctionTableOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_size, uintptr_t, PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_size, uintptr_t,
kIndirectFunctionTableSizeOffset) kIndirectFunctionTableSizeOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids,
uint32_t*, kIndirectFunctionTableSigIdsOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
Address*, kIndirectFunctionTableTargetsOffset)
ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule, ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset) kCompiledModuleOffset)
...@@ -92,18 +90,12 @@ OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo, ...@@ -92,18 +90,12 @@ OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo,
kDebugInfoOffset) kDebugInfoOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, table_object, WasmTableObject, OPTIONAL_ACCESSORS(WasmInstanceObject, table_object, WasmTableObject,
kTableObjectOffset) kTableObjectOffset)
ACCESSORS(WasmInstanceObject, imported_function_instances, FixedArray, OPTIONAL_ACCESSORS(WasmInstanceObject, function_tables, FixedArray,
kImportedFunctionInstancesOffset) kFunctionTablesOffset)
ACCESSORS(WasmInstanceObject, imported_function_callables, FixedArray, ACCESSORS(WasmInstanceObject, directly_called_instances, FixedArray,
kImportedFunctionCallablesOffset) kDirectlyCalledInstancesOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, indirect_function_table_instances, ACCESSORS(WasmInstanceObject, js_imports_table, FixedArray,
FixedArray, kIndirectFunctionTableInstancesOffset) kJsImportsTableOffset)
ACCESSORS(WasmInstanceObject, managed_native_allocations, Foreign,
kManagedNativeAllocationsOffset)
inline bool WasmInstanceObject::has_indirect_function_table() {
return indirect_function_table_sig_ids() != nullptr;
}
// WasmSharedModuleData // WasmSharedModuleData
ACCESSORS(WasmSharedModuleData, module_wrapper, Object, kModuleWrapperOffset) ACCESSORS(WasmSharedModuleData, module_wrapper, Object, kModuleWrapperOffset)
...@@ -176,6 +168,7 @@ WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset) ...@@ -176,6 +168,7 @@ WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset) WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset)
WCM_WEAK_LINK(WasmModuleObject, wasm_module, kWasmModuleOffset) WCM_WEAK_LINK(WasmModuleObject, wasm_module, kWasmModuleOffset)
WCM_OBJECT(Foreign, native_module, kNativeModuleOffset) WCM_OBJECT(Foreign, native_module, kNativeModuleOffset)
WCM_OBJECT(FixedArray, lazy_compile_data, kLazyCompileDataOffset)
WCM_SMALL_CONST_NUMBER(bool, use_trap_handler, kUseTrapHandlerOffset) WCM_SMALL_CONST_NUMBER(bool, use_trap_handler, kUseTrapHandlerOffset)
ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset); ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset);
ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset); ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset);
...@@ -192,10 +185,6 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); } ...@@ -192,10 +185,6 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); }
bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; } bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
inline bool WasmCompiledModule::has_instance() const {
return !weak_owning_instance()->cleared();
}
#include "src/objects/object-macros-undef.h" #include "src/objects/object-macros-undef.h"
} // namespace internal } // namespace internal
......
This diff is collapsed.
This diff is collapsed.
...@@ -23,8 +23,8 @@ constexpr ValueType kWasmI32 = MachineRepresentation::kWord32; ...@@ -23,8 +23,8 @@ constexpr ValueType kWasmI32 = MachineRepresentation::kWord32;
constexpr ValueType kWasmI64 = MachineRepresentation::kWord64; constexpr ValueType kWasmI64 = MachineRepresentation::kWord64;
constexpr ValueType kWasmF32 = MachineRepresentation::kFloat32; constexpr ValueType kWasmF32 = MachineRepresentation::kFloat32;
constexpr ValueType kWasmF64 = MachineRepresentation::kFloat64; constexpr ValueType kWasmF64 = MachineRepresentation::kFloat64;
constexpr ValueType kWasmS128 = MachineRepresentation::kSimd128;
constexpr ValueType kWasmAnyRef = MachineRepresentation::kTaggedPointer; constexpr ValueType kWasmAnyRef = MachineRepresentation::kTaggedPointer;
constexpr ValueType kWasmS128 = MachineRepresentation::kSimd128;
constexpr ValueType kWasmVar = MachineRepresentation::kTagged; constexpr ValueType kWasmVar = MachineRepresentation::kTagged;
using FunctionSig = Signature<ValueType>; using FunctionSig = Signature<ValueType>;
......
...@@ -682,6 +682,7 @@ MaybeHandle<WasmCompiledModule> DeserializeNativeModule( ...@@ -682,6 +682,7 @@ MaybeHandle<WasmCompiledModule> DeserializeNativeModule(
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate, shared->module(), export_wrappers, WasmCompiledModule::New(isolate, shared->module(), export_wrappers,
std::vector<wasm::GlobalHandleAddress>(),
trap_handler::IsTrapHandlerEnabled()); trap_handler::IsTrapHandlerEnabled());
compiled_module->set_shared(*shared); compiled_module->set_shared(*shared);
script->set_wasm_compiled_module(*compiled_module); script->set_wasm_compiled_module(*compiled_module);
......
...@@ -100,6 +100,7 @@ v8_source_set("cctest_sources") { ...@@ -100,6 +100,7 @@ v8_source_set("cctest_sources") {
"compiler/test-run-tail-calls.cc", "compiler/test-run-tail-calls.cc",
"compiler/test-run-unwinding-info.cc", "compiler/test-run-unwinding-info.cc",
"compiler/test-run-variables.cc", "compiler/test-run-variables.cc",
"compiler/test-run-wasm-machops.cc",
"compiler/value-helper.cc", "compiler/value-helper.cc",
"compiler/value-helper.h", "compiler/value-helper.h",
"expression-type-collector-macros.h", "expression-type-collector-macros.h",
...@@ -239,6 +240,7 @@ v8_source_set("cctest_sources") { ...@@ -239,6 +240,7 @@ v8_source_set("cctest_sources") {
"wasm/test-run-wasm-interpreter.cc", "wasm/test-run-wasm-interpreter.cc",
"wasm/test-run-wasm-js.cc", "wasm/test-run-wasm-js.cc",
"wasm/test-run-wasm-module.cc", "wasm/test-run-wasm-module.cc",
"wasm/test-run-wasm-relocation.cc",
"wasm/test-run-wasm-sign-extension.cc", "wasm/test-run-wasm-sign-extension.cc",
"wasm/test-run-wasm-simd.cc", "wasm/test-run-wasm-simd.cc",
"wasm/test-run-wasm.cc", "wasm/test-run-wasm.cc",
...@@ -275,6 +277,7 @@ v8_source_set("cctest_sources") { ...@@ -275,6 +277,7 @@ v8_source_set("cctest_sources") {
"test-code-stubs.h", "test-code-stubs.h",
"test-disasm-arm.cc", "test-disasm-arm.cc",
"test-macro-assembler-arm.cc", "test-macro-assembler-arm.cc",
"test-run-wasm-relocation-arm.cc",
"test-sync-primitives-arm.cc", "test-sync-primitives-arm.cc",
] ]
} else if (v8_current_cpu == "arm64") { } else if (v8_current_cpu == "arm64") {
...@@ -287,6 +290,7 @@ v8_source_set("cctest_sources") { ...@@ -287,6 +290,7 @@ v8_source_set("cctest_sources") {
"test-fuzz-arm64.cc", "test-fuzz-arm64.cc",
"test-javascript-arm64.cc", "test-javascript-arm64.cc",
"test-js-arm64-variables.cc", "test-js-arm64-variables.cc",
"test-run-wasm-relocation-arm64.cc",
"test-sync-primitives-arm64.cc", "test-sync-primitives-arm64.cc",
"test-utils-arm64.cc", "test-utils-arm64.cc",
"test-utils-arm64.h", "test-utils-arm64.h",
...@@ -299,6 +303,7 @@ v8_source_set("cctest_sources") { ...@@ -299,6 +303,7 @@ v8_source_set("cctest_sources") {
"test-code-stubs.h", "test-code-stubs.h",
"test-disasm-ia32.cc", "test-disasm-ia32.cc",
"test-log-stack-tracer.cc", "test-log-stack-tracer.cc",
"test-run-wasm-relocation-ia32.cc",
] ]
} else if (v8_current_cpu == "mips") { } else if (v8_current_cpu == "mips") {
sources += [ ### gcmole(arch:mips) ### sources += [ ### gcmole(arch:mips) ###
...@@ -345,6 +350,7 @@ v8_source_set("cctest_sources") { ...@@ -345,6 +350,7 @@ v8_source_set("cctest_sources") {
"test-disasm-x64.cc", "test-disasm-x64.cc",
"test-log-stack-tracer.cc", "test-log-stack-tracer.cc",
"test-macro-assembler-x64.cc", "test-macro-assembler-x64.cc",
"test-run-wasm-relocation-x64.cc",
"wasm/test-run-wasm-atomics64.cc", "wasm/test-run-wasm-atomics64.cc",
] ]
} else if (v8_current_cpu == "ppc" || v8_current_cpu == "ppc64") { } else if (v8_current_cpu == "ppc" || v8_current_cpu == "ppc64") {
......
This diff is collapsed.
...@@ -61,6 +61,7 @@ UNINITIALIZED_TEST(VerifyBuiltinsIsolateIndependence) { ...@@ -61,6 +61,7 @@ UNINITIALIZED_TEST(VerifyBuiltinsIsolateIndependence) {
mode_mask == mode_mask ==
(RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | (RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::WASM_CONTEXT_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_HANDLE) | RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_HANDLE) |
RelocInfo::ModeMask(RelocInfo::WASM_CALL) | RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL) | RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL) |
......
// Copyright 2015 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.
#include <iostream> // NOLINT(readability/streams)
#include "src/v8.h"
#include "test/cctest/cctest.h"
#include "src/arm/assembler-arm-inl.h"
#include "src/arm/simulator-arm.h"
#include "src/disassembler.h"
#include "src/factory.h"
#include "src/ostreams.h"
#include "test/cctest/compiler/c-signature.h"
#include "test/cctest/compiler/call-tester.h"
namespace v8 {
namespace internal {
namespace wasm {
#define __ assm.
static int32_t DummyStaticFunction(Object* result) { return 1; }
TEST(WasmRelocationArmContextReference) {
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
v8::internal::byte buffer[4096];
DummyStaticFunction(nullptr);
int32_t imm = 1234567;
Assembler assm(isolate, buffer, sizeof buffer);
__ mov(r0, Operand(imm, RelocInfo::WASM_CONTEXT_REFERENCE));
__ mov(pc, Operand(lr));
CodeDesc desc;
assm.GetCode(isolate, &desc);
Handle<Code> code =
isolate->factory()->NewCode(desc, Code::STUB, Handle<Code>());
compiler::CSignatureOf<int32_t> csig;
compiler::CodeRunner<int32_t> runnable(isolate, code, &csig);
int32_t ret_value = runnable.Call();
CHECK_EQ(ret_value, imm);
#ifdef DEBUG
OFStream os(stdout);
code->Print(os);
::printf("f() = %d\n\n", ret_value);
#endif
int offset = 1234;
// Relocating references by offset
int mode_mask = (1 << RelocInfo::WASM_CONTEXT_REFERENCE);
for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
// TODO(6792): No longer needed once WebAssembly code is off heap.
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
DCHECK(RelocInfo::IsWasmContextReference(it.rinfo()->rmode()));
it.rinfo()->set_wasm_context_reference(
it.rinfo()->wasm_context_reference() + offset, SKIP_ICACHE_FLUSH);
}
// Call into relocated code object
ret_value = runnable.Call();
CHECK_EQ((imm + offset), ret_value);
#ifdef DEBUG
code->Print(os);
::printf("f() = %d\n\n", ret_value);
#endif
}
#undef __
} // namespace wasm
} // namespace internal
} // namespace v8
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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