Commit 8db8b6c2 authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[ext-code-space][wasm] Migrate code entries to CodeT in Wasm engine

Namely,
- WasmFunctionData::wrapper_code
- WasmJSFunctionData::wasm_to_js_wrapper_code
- exported JS-to-Wasm wrappers

Bug: v8:11880
Change-Id: I85f60daea22b8b1270f813f903ebdea1249b4de1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2969826Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75226}
parent 39c1f718
......@@ -3209,9 +3209,19 @@ Node* WasmGraphBuilder::BuildCallRef(uint32_t sig_index, Vector<Node*> args,
MachineType::TaggedPointer(), function_data,
wasm::ObjectAccess::ToTagged(
WasmJSFunctionData::kWasmToJsWrapperCodeOffset));
Node* call_target = gasm_->IntAdd(
wrapper_code,
gasm_->IntPtrConstant(wasm::ObjectAccess::ToTagged(Code::kHeaderSize)));
Node* call_target;
if (V8_EXTERNAL_CODE_SPACE_BOOL) {
CHECK(!V8_HEAP_SANDBOX_BOOL); // Not supported yet.
call_target =
gasm_->LoadFromObject(MachineType::Pointer(), wrapper_code,
wasm::ObjectAccess::ToTagged(
CodeDataContainer::kCodeEntryPointOffset));
} else {
call_target = gasm_->IntAdd(
wrapper_code, gasm_->IntPtrConstant(
wasm::ObjectAccess::ToTagged(Code::kHeaderSize)));
}
gasm_->Goto(&end_label, call_target);
}
......
......@@ -1999,7 +1999,7 @@ void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) {
void WasmFunctionData::WasmFunctionDataPrint(std::ostream& os) {
os << "\n - target: " << reinterpret_cast<void*>(foreign_address());
os << "\n - ref: " << Brief(ref());
os << "\n - wrapper_code: " << Brief(wrapper_code());
os << "\n - wrapper_code: " << Brief(TorqueGeneratedClass::wrapper_code());
}
void WasmExportedFunctionData::WasmExportedFunctionDataPrint(std::ostream& os) {
......@@ -2015,7 +2015,8 @@ void WasmExportedFunctionData::WasmExportedFunctionDataPrint(std::ostream& os) {
void WasmJSFunctionData::WasmJSFunctionDataPrint(std::ostream& os) {
PrintHeader(os, "WasmJSFunctionData");
WasmFunctionDataPrint(os);
os << "\n - wasm_to_js_wrapper_code: " << Brief(wasm_to_js_wrapper_code());
os << "\n - wasm_to_js_wrapper_code: "
<< Brief(raw_wasm_to_js_wrapper_code());
os << "\n - serialized_return_count: " << serialized_return_count();
os << "\n - serialized_parameter_count: " << serialized_parameter_count();
os << "\n - serialized_signature: " << Brief(serialized_signature());
......
......@@ -171,9 +171,8 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) {
}
shared->set_is_asm_wasm_broken(true);
#endif
DCHECK(function->code() ==
isolate->builtins()->code(Builtin::kInstantiateAsmJs));
function->set_code(isolate->builtins()->code(Builtin::kCompileLazy));
DCHECK_EQ(function->code(), *BUILTIN_CODE(isolate, InstantiateAsmJs));
function->set_code(*BUILTIN_CODE(isolate, CompileLazy));
DCHECK(!isolate->has_pending_exception());
return Smi::zero();
}
......
......@@ -268,10 +268,9 @@ RUNTIME_FUNCTION(Runtime_IsWasmCode) {
SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(JSFunction, function, 0);
bool is_js_to_wasm =
function.code().kind() == CodeKind::JS_TO_WASM_FUNCTION ||
(function.code().is_builtin() &&
function.code().builtin_id() == Builtin::kGenericJSToWasmWrapper);
Code code = function.code();
bool is_js_to_wasm = code.kind() == CodeKind::JS_TO_WASM_FUNCTION ||
(code.builtin_id() == Builtin::kGenericJSToWasmWrapper);
return isolate->heap()->ToBoolean(is_js_to_wasm);
}
......
......@@ -5909,8 +5909,12 @@ class LiftoffCompiler {
wasm::ObjectAccess::ToTagged(
WasmJSFunctionData::kWasmToJsWrapperCodeOffset),
pinned);
#ifdef V8_EXTERNAL_CODE_SPACE
__ LoadCodeDataContainerEntry(target.gp(), target.gp());
#else
__ emit_ptrsize_addi(target.gp(), target.gp(),
wasm::ObjectAccess::ToTagged(Code::kHeaderSize));
#endif
// Fall through to {perform_call}.
__ bind(&perform_call);
......
......@@ -3101,7 +3101,7 @@ void CompilationStateImpl::FinalizeJSToWasmWrappers(
Handle<Code> code = unit->Finalize();
int wrapper_index =
GetExportWrapperIndex(module, unit->sig(), unit->is_import());
(*export_wrappers_out)->set(wrapper_index, *code);
(*export_wrappers_out)->set(wrapper_index, ToCodeT(*code));
RecordStats(*code, isolate->counters());
}
}
......@@ -3511,7 +3511,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
DCHECK_EQ(isolate, unit->isolate());
Handle<Code> code = unit->Finalize();
int wrapper_index = GetExportWrapperIndex(module, &key.second, key.first);
(*export_wrappers_out)->set(wrapper_index, *code);
(*export_wrappers_out)->set(wrapper_index, ToCodeT(*code));
RecordStats(*code, isolate->counters());
}
}
......
......@@ -341,7 +341,13 @@ CAST_ACCESSOR(WasmExportedFunction)
// WasmFunctionData
ACCESSORS(WasmFunctionData, ref, Object, kRefOffset)
ACCESSORS(WasmFunctionData, wrapper_code, Code, kWrapperCodeOffset)
DEF_GETTER(WasmFunctionData, wrapper_code, Code) {
return FromCodeT(TorqueGeneratedClass::wrapper_code(cage_base));
}
void WasmFunctionData::set_wrapper_code(Code code, WriteBarrierMode mode) {
TorqueGeneratedClass::set_wrapper_code(ToCodeT(code), mode);
}
// WasmExportedFunctionData
ACCESSORS(WasmExportedFunctionData, instance, WasmInstanceObject,
......@@ -371,9 +377,17 @@ SMI_ACCESSORS(WasmJSFunctionData, serialized_parameter_count,
kSerializedParameterCountOffset)
ACCESSORS(WasmJSFunctionData, serialized_signature, PodArray<wasm::ValueType>,
kSerializedSignatureOffset)
ACCESSORS(WasmJSFunctionData, wasm_to_js_wrapper_code, Code,
ACCESSORS(WasmJSFunctionData, raw_wasm_to_js_wrapper_code, CodeT,
kWasmToJsWrapperCodeOffset)
DEF_GETTER(WasmJSFunctionData, wasm_to_js_wrapper_code, Code) {
return FromCodeT(raw_wasm_to_js_wrapper_code(cage_base));
}
void WasmJSFunctionData::set_wasm_to_js_wrapper_code(Code code,
WriteBarrierMode mode) {
set_raw_wasm_to_js_wrapper_code(ToCodeT(code), mode);
}
// WasmCapiFunction
WasmCapiFunction::WasmCapiFunction(Address ptr) : JSFunction(ptr) {
SLOW_DCHECK(IsWasmCapiFunction(*this));
......
......@@ -1481,7 +1481,7 @@ WasmInstanceObject::GetOrCreateWasmExternalFunction(
// later use.
wrapper = wasm::JSToWasmWrapperCompilationUnit::CompileJSToWasmWrapper(
isolate, function.sig, instance->module(), function.imported);
module_object->export_wrappers().set(wrapper_index, *wrapper);
module_object->export_wrappers().set(wrapper_index, ToCodeT(*wrapper));
}
result = Handle<WasmExternalFunction>::cast(WasmExportedFunction::New(
isolate, instance, function_index,
......@@ -1857,8 +1857,9 @@ uint32_t WasmExceptionPackage::GetEncodedSize(
bool WasmExportedFunction::IsWasmExportedFunction(Object object) {
if (!object.IsJSFunction()) return false;
JSFunction js_function = JSFunction::cast(object);
if (CodeKind::JS_TO_WASM_FUNCTION != js_function.code().kind() &&
js_function.code().builtin_id() != Builtin::kGenericJSToWasmWrapper) {
Code code = js_function.code();
if (CodeKind::JS_TO_WASM_FUNCTION != code.kind() &&
code.builtin_id() != Builtin::kGenericJSToWasmWrapper) {
return false;
}
DCHECK(js_function.shared().HasWasmExportedFunctionData());
......
......@@ -808,6 +808,9 @@ class WasmJSFunctionData : public WasmFunctionData {
class BodyDescriptor;
private:
DECL_ACCESSORS(raw_wasm_to_js_wrapper_code, CodeT)
OBJECT_CONSTRUCTORS(WasmJSFunctionData, WasmFunctionData);
};
......
......@@ -22,7 +22,8 @@ extern class WasmFunctionData extends Foreign {
// the module's imported_function_refs array.
ref: WasmInstanceObject|Tuple2;
// Used for calling this function from JavaScript.
wrapper_code: Code;
@if(V8_EXTERNAL_CODE_SPACE) wrapper_code: CodeDataContainer;
@ifnot(V8_EXTERNAL_CODE_SPACE) wrapper_code: Code;
}
extern class WasmExportedFunctionData extends WasmFunctionData {
......@@ -37,7 +38,8 @@ extern class WasmExportedFunctionData extends WasmFunctionData {
}
extern class WasmJSFunctionData extends WasmFunctionData {
wasm_to_js_wrapper_code: Code;
@if(V8_EXTERNAL_CODE_SPACE) wasm_to_js_wrapper_code: CodeDataContainer;
@ifnot(V8_EXTERNAL_CODE_SPACE) wasm_to_js_wrapper_code: Code;
serialized_return_count: Smi;
serialized_parameter_count: Smi;
serialized_signature: PodArrayOfWasmValueType;
......
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