Commit 919fa266 authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[ext-code-space] Migrate WasmExportedFunctionData code field to CodeT

In order to avoid unnecessary conversions to CodeT and back this CL:
- makes compiler::CompileCWasmEntry() return CodeT,
- makes Execution::CallWasm() accept CodeT.

Bug: v8:11880
Change-Id: Ic4b7b5f476c6efcfca4bc116ecd45cdee9f0c6c3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2971743Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75247}
parent c0db5dc8
......@@ -34,7 +34,7 @@ static constexpr T FirstFromVarArgs(T x, ...) noexcept {
// Convenience macro to avoid generating named accessors for all builtins.
#define BUILTIN_CODE(isolate, name) \
(isolate)->builtins()->code_handle(Builtin::k##name)
(isolate)->builtins()->code_handle(i::Builtin::k##name)
enum class Builtin : int32_t {
kNoBuiltinId = -1,
......
......@@ -7756,8 +7756,8 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate,
return code;
}
Handle<Code> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig,
const wasm::WasmModule* module) {
Handle<CodeT> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig,
const wasm::WasmModule* module) {
std::unique_ptr<Zone> zone = std::make_unique<Zone>(
isolate->allocator(), ZONE_NAME, kCompressGraphZone);
Graph* graph = zone->New<Graph>(zone.get());
......@@ -7805,7 +7805,11 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig,
CompilationJob::FAILED);
CHECK_NE(job->FinalizeJob(isolate), CompilationJob::FAILED);
#ifdef V8_EXTERNAL_CODE_SPACE
return handle(ToCodeT(*job->compilation_info()->code()), isolate);
#else
return job->compilation_info()->code();
#endif
}
namespace {
......
......@@ -152,7 +152,7 @@ enum CWasmEntryParameters {
// Compiles a stub with C++ linkage, to be called from Execution::CallWasm,
// which knows how to feed it its parameters.
V8_EXPORT_PRIVATE Handle<Code> CompileCWasmEntry(
V8_EXPORT_PRIVATE Handle<CodeT> CompileCWasmEntry(
Isolate*, const wasm::FunctionSig*, const wasm::WasmModule* module);
class JSWasmCallData {
......
......@@ -526,7 +526,7 @@ STATIC_ASSERT(offsetof(StackHandlerMarker, padding) ==
STATIC_ASSERT(sizeof(StackHandlerMarker) == StackHandlerConstants::kSize);
#if V8_ENABLE_WEBASSEMBLY
void Execution::CallWasm(Isolate* isolate, Handle<Code> wrapper_code,
void Execution::CallWasm(Isolate* isolate, Handle<CodeT> wrapper_code,
Address wasm_call_target, Handle<Object> object_ref,
Address packed_args) {
using WasmEntryStub = GeneratedCode<Address(
......
......@@ -66,7 +66,7 @@ class Execution final : public AllStatic {
// Upon return, either isolate->has_pending_exception() is true, or
// the function's return values are in {packed_args}.
V8_EXPORT_PRIVATE static void CallWasm(Isolate* isolate,
Handle<Code> wrapper_code,
Handle<CodeT> wrapper_code,
Address wasm_call_target,
Handle<Object> object_ref,
Address packed_args);
......
......@@ -1442,7 +1442,8 @@ Handle<WasmExportedFunctionData> Factory::NewWasmExportedFunctionData(
result.set_function_index(func_index);
result.set_signature(*sig_foreign);
result.set_wrapper_budget(wrapper_budget);
result.set_c_wrapper_code(Smi::zero(), SKIP_WRITE_BARRIER);
result.set_c_wrapper_code(ToCodeT(*BUILTIN_CODE(isolate(), Illegal)),
SKIP_WRITE_BARRIER);
result.set_packed_args_size(0);
return handle(result, isolate());
}
......
......@@ -812,6 +812,10 @@ void CodeDataContainer::UpdateCodeEntryPoint(Isolate* isolate_for_sandbox,
set_code_entry_point(isolate_for_sandbox, code.InstructionStart());
}
Address CodeDataContainer::InstructionStart() const {
return code_entry_point();
}
void CodeDataContainer::clear_padding() {
memset(reinterpret_cast<void*>(address() + kUnalignedSize), 0,
kSize - kUnalignedSize);
......
......@@ -64,6 +64,9 @@ class CodeDataContainer : public HeapObject {
inline void AllocateExternalPointerEntries(Isolate* isolate);
// Alias for code_entry_point to make it API compatible with Code.
inline Address InstructionStart() const;
DECL_CAST(CodeDataContainer)
// Dispatched behavior.
......
......@@ -28,6 +28,7 @@
#include "include/libplatform/libplatform.h"
#include "src/api/api-inl.h"
#include "src/base/platform/wrappers.h"
#include "src/builtins/builtins.h"
#include "src/compiler/wasm-compiler.h"
#include "src/objects/js-collection-inl.h"
#include "src/objects/managed.h"
......@@ -1516,9 +1517,13 @@ void PrepareFunctionData(i::Isolate* isolate,
const i::wasm::FunctionSig* sig,
const i::wasm::WasmModule* module) {
// If the data is already populated, return immediately.
if (!function_data->c_wrapper_code().IsSmi()) return;
// TODO(v8:11880): avoid roundtrips between cdc and code.
if (function_data->c_wrapper_code() !=
ToCodeT(*BUILTIN_CODE(isolate, Illegal))) {
return;
}
// Compile wrapper code.
i::Handle<i::Code> wrapper_code =
i::Handle<i::CodeT> wrapper_code =
i::compiler::CompileCWasmEntry(isolate, sig, module);
function_data->set_c_wrapper_code(*wrapper_code);
// Compute packed args size.
......@@ -1658,8 +1663,9 @@ auto Func::call(const Val args[], Val results[]) const -> own<Trap> {
const i::wasm::FunctionSig* sig =
instance->module()->functions[function_index].sig;
PrepareFunctionData(isolate, function_data, sig, instance->module());
i::Handle<i::Code> wrapper_code = i::Handle<i::Code>(
i::Code::cast(function_data->c_wrapper_code()), isolate);
// TODO(v8:11880): avoid roundtrips between cdc and code.
i::Handle<i::CodeT> wrapper_code = i::Handle<i::CodeT>(
i::CodeT::cast(function_data->c_wrapper_code()), isolate);
i::Address call_target = function_data->foreign_address();
i::wasm::CWasmArgumentsPacker packer(function_data->packed_args_size());
......
......@@ -355,7 +355,7 @@ ACCESSORS(WasmExportedFunctionData, instance, WasmInstanceObject,
SMI_ACCESSORS(WasmExportedFunctionData, function_index, kFunctionIndexOffset)
ACCESSORS(WasmExportedFunctionData, signature, Foreign, kSignatureOffset)
SMI_ACCESSORS(WasmExportedFunctionData, wrapper_budget, kWrapperBudgetOffset)
ACCESSORS(WasmExportedFunctionData, c_wrapper_code, Object, kCWrapperCodeOffset)
ACCESSORS(WasmExportedFunctionData, c_wrapper_code, CodeT, kCWrapperCodeOffset)
SMI_ACCESSORS(WasmExportedFunctionData, packed_args_size, kPackedArgsSizeOffset)
wasm::FunctionSig* WasmExportedFunctionData::sig() const {
......
......@@ -765,7 +765,7 @@ class WasmExportedFunctionData : public WasmFunctionData {
DECL_INT_ACCESSORS(function_index)
DECL_ACCESSORS(signature, Foreign)
DECL_INT_ACCESSORS(wrapper_budget)
DECL_ACCESSORS(c_wrapper_code, Object)
DECL_ACCESSORS(c_wrapper_code, CodeT)
DECL_INT_ACCESSORS(packed_args_size)
inline wasm::FunctionSig* sig() const;
......
......@@ -33,7 +33,8 @@ extern class WasmExportedFunctionData extends WasmFunctionData {
wrapper_budget: Smi;
// The remaining fields are for fast calling from C++. The contract is
// that they are lazily populated, and either all will be present or none.
c_wrapper_code: Object;
@if(V8_EXTERNAL_CODE_SPACE) c_wrapper_code: CodeDataContainer;
@ifnot(V8_EXTERNAL_CODE_SPACE) c_wrapper_code: Code;
packed_args_size: Smi;
}
......
......@@ -80,7 +80,7 @@ class CWasmEntryArgTester {
Isolate* isolate_;
std::function<ReturnType(Args...)> expected_fn_;
const FunctionSig* sig_;
Handle<Code> c_wasm_entry_;
Handle<CodeT> c_wasm_entry_;
WasmCode* wasm_code_;
};
......
......@@ -216,7 +216,7 @@ class WasmGCTester {
WasmCode* code = native_module->GetCode(function_index);
Address wasm_call_target = code->instruction_start();
Handle<Object> object_ref = instance_;
Handle<Code> c_wasm_entry =
Handle<CodeT> c_wasm_entry =
compiler::CompileCWasmEntry(isolate_, sig, native_module->module());
Execution::CallWasm(isolate_, c_wasm_entry, wasm_call_target, object_ref,
packer->argv());
......
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