#include "src/wasm/module-instantiate.h"
#include "src/api/api-inl.h"
#include "src/asmjs/asm-js.h"
#include "src/base/atomicops.h"
#include "src/codegen/compiler.h"
#include "src/compiler/wasm-compiler.h"
#include "src/logging/counters-scopes.h"
#include "src/logging/metrics.h"
#include "src/numbers/conversions-inl.h"
#include "src/objects/descriptor-array-inl.h"
#include "src/objects/property-descriptor.h"
#include "src/objects/torque-defined-classes.h"
#include "src/tracing/trace-event.h"
#include "src/utils/utils.h"
#include "src/wasm/code-space-access.h"
#include "src/wasm/compilation-environment-inl.h"
#include "src/wasm/constant-expression-interface.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/module-decoder-impl.h"
#include "src/wasm/pgo.h"
#include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-external-refs.h"
#include "src/wasm/wasm-import-wrapper-cache.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-opcodes-inl.h"
#include "src/wasm/wasm-subtyping.h"
#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
#include "src/execution/simulator-base.h"
#endif
#define TRACE …
namespace v8::internal::wasm {
namespace {
uint8_t* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) { … }
Handle<Map> CreateStructMap(Isolate* isolate, const WasmModule* module,
int struct_index, Handle<Map> opt_rtt_parent,
DirectHandle<WasmTrustedInstanceData> trusted_data,
Handle<WasmInstanceObject> instance) { … }
Handle<Map> CreateArrayMap(Isolate* isolate, const WasmModule* module,
int array_index, Handle<Map> opt_rtt_parent,
DirectHandle<WasmTrustedInstanceData> trusted_data,
Handle<WasmInstanceObject> instance) { … }
}
void CreateMapForType(Isolate* isolate, const WasmModule* module,
int type_index,
Handle<WasmTrustedInstanceData> trusted_data,
Handle<WasmInstanceObject> instance,
Handle<FixedArray> maybe_shared_maps) { … }
namespace {
bool CompareWithNormalizedCType(const CTypeInfo& info, ValueType expected,
CFunctionInfo::Int64Representation int64_rep) { … }
enum class ReceiverKind { … };
bool IsSupportedWasmFastApiFunction(Isolate* isolate,
const wasm::FunctionSig* expected_sig,
Tagged<SharedFunctionInfo> shared,
ReceiverKind receiver_kind,
int* out_index) { … }
bool ResolveBoundJSFastApiFunction(const wasm::FunctionSig* expected_sig,
DirectHandle<JSReceiver> callable) { … }
bool IsStringRef(wasm::ValueType type) { … }
bool IsExternRef(wasm::ValueType type) { … }
bool IsStringOrExternRef(wasm::ValueType type) { … }
bool IsDataViewGetterSig(const wasm::FunctionSig* sig,
wasm::ValueType return_type) { … }
bool IsDataViewSetterSig(const wasm::FunctionSig* sig,
wasm::ValueType value_type) { … }
const MachineSignature* GetFunctionSigForFastApiImport(
Zone* zone, const CFunctionInfo* info) { … }
WellKnownImport CheckForWellKnownImport(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data, int func_index,
DirectHandle<JSReceiver> callable, const wasm::FunctionSig* sig) { … }
}
ResolvedWasmImport::ResolvedWasmImport(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data, int func_index,
Handle<JSReceiver> callable, const wasm::FunctionSig* expected_sig,
uint32_t expected_canonical_type_index, WellKnownImport preknown_import) { … }
void ResolvedWasmImport::SetCallable(Isolate* isolate,
Tagged<JSReceiver> callable) { … }
void ResolvedWasmImport::SetCallable(Isolate* isolate,
Handle<JSReceiver> callable) { … }
ImportCallKind ResolvedWasmImport::ComputeKind(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data, int func_index,
const wasm::FunctionSig* expected_sig,
uint32_t expected_canonical_type_index, WellKnownImport preknown_import) { … }
class InstanceBuilder { … };
namespace {
class WriteOutPGOTask : public v8::Task { … };
}
MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject(
Isolate* isolate, ErrorThrower* thrower,
Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports,
MaybeHandle<JSArrayBuffer> memory_buffer) { … }
InstanceBuilder::InstanceBuilder(Isolate* isolate,
v8::metrics::Recorder::ContextId context_id,
ErrorThrower* thrower,
Handle<WasmModuleObject> module_object,
MaybeHandle<JSReceiver> ffi,
MaybeHandle<JSArrayBuffer> asmjs_memory_buffer)
: … { … }
MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { … }
bool InstanceBuilder::ExecuteStartFunction() { … }
MaybeHandle<Object> InstanceBuilder::LookupImport(uint32_t index,
Handle<String> module_name,
Handle<String> import_name) { … }
namespace {
bool HasDefaultToNumberBehaviour(Isolate* isolate,
Handle<JSFunction> function) { … }
bool MaybeMarkError(ValueOrError value, ErrorThrower* thrower) { … }
}
MaybeHandle<Object> InstanceBuilder::LookupImportAsm(
uint32_t index, Handle<String> import_name) { … }
void InstanceBuilder::LoadDataSegments(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) { … }
void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global,
const WasmValue& value) { … }
std::tuple<const char*, Builtin, int> NameBuiltinLength(WellKnownImport wki) { … }
Handle<JSFunction> CreateFunctionForCompileTimeImport(Isolate* isolate,
WellKnownImport wki) { … }
void InstanceBuilder::SanitizeImports() { … }
bool InstanceBuilder::ProcessImportedFunction(
Handle<WasmTrustedInstanceData> trusted_instance_data, int import_index,
int func_index, Handle<Object> value, WellKnownImport preknown_import) { … }
bool InstanceBuilder::InitializeImportedIndirectFunctionTable(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
int table_index, int import_index,
DirectHandle<WasmTableObject> table_object) { … }
bool InstanceBuilder::ProcessImportedTable(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
int import_index, int table_index, Handle<Object> value) { … }
bool InstanceBuilder::ProcessImportedWasmGlobalObject(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
int import_index, const WasmGlobal& global,
DirectHandle<WasmGlobalObject> global_object) { … }
bool InstanceBuilder::ProcessImportedGlobal(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
int import_index, int global_index, Handle<Object> value) { … }
int InstanceBuilder::ProcessImports(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) { … }
bool InstanceBuilder::ProcessImportedMemories(
DirectHandle<FixedArray> imported_memory_objects) { … }
template <typename T>
T* InstanceBuilder::GetRawUntaggedGlobalPtr(const WasmGlobal& global) { … }
void InstanceBuilder::InitGlobals(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) { … }
MaybeHandle<WasmMemoryObject> InstanceBuilder::AllocateMemory(
uint32_t memory_index) { … }
void InstanceBuilder::ProcessExports(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) { … }
namespace {
V8_INLINE void SetFunctionTablePlaceholder(
Isolate* isolate,
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
DirectHandle<WasmTableObject> table_object, uint32_t entry_index,
uint32_t func_index) { … }
V8_INLINE void SetFunctionTableNullEntry(
Isolate* isolate, DirectHandle<WasmTableObject> table_object,
uint32_t entry_index) { … }
}
void InstanceBuilder::SetTableInitialValues(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) { … }
namespace {
enum FunctionComputationMode { … };
ValueOrError ConsumeElementSegmentEntry(
Zone* zone, Isolate* isolate,
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data,
const WasmElemSegment& segment, Decoder& decoder,
FunctionComputationMode function_mode) { … }
}
std::optional<MessageTemplate> InitializeElementSegment(
Zone* zone, Isolate* isolate,
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data,
uint32_t segment_index) { … }
void InstanceBuilder::LoadTableSegments(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) { … }
void InstanceBuilder::InitializeTags(
DirectHandle<WasmTrustedInstanceData> trusted_instance_data) { … }
}
#undef TRACE