summaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/wasm-objects.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/wasm/wasm-objects.h')
-rw-r--r--deps/v8/src/wasm/wasm-objects.h146
1 files changed, 83 insertions, 63 deletions
diff --git a/deps/v8/src/wasm/wasm-objects.h b/deps/v8/src/wasm/wasm-objects.h
index 86a7913d7a..ec53b8ac2a 100644
--- a/deps/v8/src/wasm/wasm-objects.h
+++ b/deps/v8/src/wasm/wasm-objects.h
@@ -5,14 +5,15 @@
#ifndef V8_WASM_OBJECTS_H_
#define V8_WASM_OBJECTS_H_
+#include "src/base/bits.h"
#include "src/debug/debug.h"
#include "src/debug/interface-types.h"
#include "src/managed.h"
#include "src/objects.h"
#include "src/objects/script.h"
-#include "src/trap-handler/trap-handler.h"
#include "src/wasm/decoder.h"
#include "src/wasm/wasm-limits.h"
+#include "src/wasm/wasm-module.h"
#include "src/heap/heap.h"
@@ -23,6 +24,8 @@ namespace v8 {
namespace internal {
namespace wasm {
class InterpretedFrame;
+class NativeModule;
+class WasmCode;
class WasmInterpreter;
struct WasmModule;
class SignatureMap;
@@ -58,9 +61,22 @@ class WasmInstanceObject;
// grow_memory). The address of the WasmContext is provided to the wasm entry
// functions using a RelocatableIntPtrConstant, then the address is passed as
// parameter to the other wasm functions.
+// Note that generated code can directly read from instances of this struct.
struct WasmContext {
- byte* mem_start;
- uint32_t mem_size;
+ byte* mem_start = nullptr;
+ uint32_t mem_size = 0; // TODO(titzer): uintptr_t?
+ uint32_t mem_mask = 0; // TODO(titzer): uintptr_t?
+ byte* globals_start = nullptr;
+
+ inline void SetRawMemory(void* mem_start, size_t mem_size) {
+ DCHECK_LE(mem_size, std::min(wasm::kV8MaxWasmMemoryPages,
+ wasm::kSpecMaxWasmMemoryPages) *
+ wasm::WasmModule::kPageSize);
+ this->mem_start = static_cast<byte*>(mem_start);
+ this->mem_size = static_cast<uint32_t>(mem_size);
+ this->mem_mask = base::bits::RoundUpToPowerOfTwo32(this->mem_size) - 1;
+ DCHECK_LE(mem_size, this->mem_mask + 1);
+ }
};
// Representation of a WebAssembly.Module JavaScript-level object.
@@ -157,9 +173,8 @@ class WasmMemoryObject : public JSObject {
uint32_t current_pages();
inline bool has_maximum_pages();
- static Handle<WasmMemoryObject> New(Isolate* isolate,
- Handle<JSArrayBuffer> buffer,
- int32_t maximum);
+ V8_EXPORT_PRIVATE static Handle<WasmMemoryObject> New(
+ Isolate* isolate, MaybeHandle<JSArrayBuffer> buffer, int32_t maximum);
static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages);
static void SetupNewBufferWithSameBackingStore(
@@ -171,12 +186,13 @@ class WasmInstanceObject : public JSObject {
public:
DECL_CAST(WasmInstanceObject)
+ DECL_ACCESSORS(wasm_context, Managed<WasmContext>)
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(exports_object, JSObject)
DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
- DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
+ DECL_OPTIONAL_ACCESSORS(table_object, WasmTableObject)
DECL_OPTIONAL_ACCESSORS(function_tables, FixedArray)
DECL_OPTIONAL_ACCESSORS(signature_tables, FixedArray)
@@ -185,12 +201,13 @@ class WasmInstanceObject : public JSObject {
DECL_ACCESSORS(js_imports_table, FixedArray)
enum { // --
+ kWasmContextIndex,
kCompiledModuleIndex,
kExportsObjectIndex,
kMemoryObjectIndex,
- kMemoryBufferIndex,
kGlobalsBufferIndex,
kDebugInfoIndex,
+ kTableObjectIndex,
kFunctionTablesIndex,
kSignatureTablesIndex,
kDirectlyCalledInstancesIndex,
@@ -199,19 +216,19 @@ class WasmInstanceObject : public JSObject {
};
DEF_SIZE(JSObject)
+ DEF_OFFSET(WasmContext)
DEF_OFFSET(CompiledModule)
DEF_OFFSET(ExportsObject)
DEF_OFFSET(MemoryObject)
- DEF_OFFSET(MemoryBuffer)
DEF_OFFSET(GlobalsBuffer)
DEF_OFFSET(DebugInfo)
+ DEF_OFFSET(TableObject)
DEF_OFFSET(FunctionTables)
DEF_OFFSET(SignatureTables)
DEF_OFFSET(DirectlyCalledInstances)
DEF_OFFSET(JsImportsTable)
WasmModuleObject* module_object();
- WasmContext* wasm_context();
V8_EXPORT_PRIVATE wasm::WasmModule* module();
// Get the debug info associated with the given wasm object.
@@ -230,7 +247,8 @@ class WasmInstanceObject : public JSObject {
// Assumed to be called with a code object associated to a wasm module
// instance. Intended to be called from runtime functions. Returns nullptr on
// failing to get owning instance.
- static WasmInstanceObject* GetOwningInstance(Code* code);
+ static WasmInstanceObject* GetOwningInstance(const wasm::WasmCode* code);
+ static WasmInstanceObject* GetOwningInstanceGC(Code* code);
static void ValidateInstancesChainForTesting(
Isolate* isolate, Handle<WasmModuleObject> module_obj,
@@ -255,7 +273,7 @@ class WasmExportedFunction : public JSFunction {
int func_index, int arity,
Handle<Code> export_wrapper);
- Handle<Code> GetWasmCode();
+ WasmCodeWrapper GetWasmCode();
};
// Information shared by all WasmCompiledModule objects for the same module.
@@ -307,9 +325,7 @@ class WasmSharedModuleData : public FixedArray {
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
- private:
DECL_OPTIONAL_ACCESSORS(lazy_compilation_orchestrator, Foreign)
- friend class WasmCompiledModule;
};
// This represents the set of wasm compiled functions, together
@@ -321,10 +337,7 @@ class WasmSharedModuleData : public FixedArray {
// used as memory of a particular WebAssembly.Instance object. This
// information are then used at runtime to access memory / verify bounds
// check limits.
-// - bounds check limits, computed at compile time, relative to the
-// size of the memory.
// - the objects representing the function tables and signature tables
-// - raw pointer to the globals buffer.
//
// Even without instantiating, we need values for all of these parameters.
// We need to track these values to be able to create new instances and
@@ -332,11 +345,6 @@ class WasmSharedModuleData : public FixedArray {
// The design decisions for how we track these values is not too immediate,
// and it deserves a summary. The "tricky" ones are: memory, globals, and
// the tables (signature and functions).
-// The first 2 (memory & globals) are embedded as raw pointers to native
-// buffers. All we need to track them is the start addresses and, in the
-// case of memory, the size. We model all of them as HeapNumbers, because
-// we need to store size_t values (for addresses), and potentially full
-// 32 bit unsigned values for the size. Smis are 31 bits.
// For tables, we need to hold a reference to the JS Heap object, because
// we embed them as objects, and they may move.
class WasmCompiledModule : public FixedArray {
@@ -386,36 +394,35 @@ class WasmCompiledModule : public FixedArray {
public: \
inline Handle<TYPE> NAME() const;
-#define WCM_LARGE_NUMBER(TYPE, NAME) \
- public: \
- inline TYPE NAME() const; \
- inline void set_##NAME(TYPE value); \
- inline static void recreate_##NAME(Handle<WasmCompiledModule> obj, \
- Factory* factory, TYPE init_val); \
- inline bool has_##NAME() const;
-
// Add values here if they are required for creating new instances or
// for deserialization, and if they are serializable.
// By default, instance values go to WasmInstanceObject, however, if
// we embed the generated code with a value, then we track that value here.
-#define CORE_WCM_PROPERTY_TABLE(MACRO) \
- MACRO(WASM_OBJECT, WasmSharedModuleData, shared) \
- MACRO(OBJECT, Context, native_context) \
+#define CORE_WCM_PROPERTY_TABLE(MACRO) \
+ MACRO(WASM_OBJECT, WasmSharedModuleData, shared) \
+ MACRO(OBJECT, Context, native_context) \
+ MACRO(CONST_OBJECT, FixedArray, export_wrappers) \
+ MACRO(OBJECT, FixedArray, weak_exported_functions) \
+ MACRO(WASM_OBJECT, WasmCompiledModule, next_instance) \
+ MACRO(WASM_OBJECT, WasmCompiledModule, prev_instance) \
+ MACRO(WEAK_LINK, WasmInstanceObject, owning_instance) \
+ MACRO(WEAK_LINK, WasmModuleObject, wasm_module) \
+ MACRO(OBJECT, FixedArray, handler_table) \
+ MACRO(OBJECT, FixedArray, source_positions) \
+ MACRO(OBJECT, Foreign, native_module) \
+ MACRO(OBJECT, FixedArray, lazy_compile_data)
+
+#define GC_WCM_PROPERTY_TABLE(MACRO) \
MACRO(SMALL_CONST_NUMBER, uint32_t, num_imported_functions) \
MACRO(CONST_OBJECT, FixedArray, code_table) \
- MACRO(CONST_OBJECT, FixedArray, export_wrappers) \
- MACRO(OBJECT, FixedArray, weak_exported_functions) \
MACRO(OBJECT, FixedArray, function_tables) \
MACRO(OBJECT, FixedArray, signature_tables) \
MACRO(CONST_OBJECT, FixedArray, empty_function_tables) \
MACRO(CONST_OBJECT, FixedArray, empty_signature_tables) \
- MACRO(LARGE_NUMBER, size_t, globals_start) \
- MACRO(SMALL_CONST_NUMBER, uint32_t, initial_pages) \
- MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
- MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
- MACRO(WEAK_LINK, JSObject, owning_instance) \
- MACRO(WEAK_LINK, WasmModuleObject, wasm_module)
+ MACRO(SMALL_CONST_NUMBER, uint32_t, initial_pages)
+// TODO(mtrofin): this is unnecessary when we stop needing
+// FLAG_wasm_jit_to_native, because we have instance_id on NativeModule.
#if DEBUG
#define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_CONST_NUMBER, uint32_t, instance_id)
#else
@@ -427,6 +434,7 @@ class WasmCompiledModule : public FixedArray {
#define WCM_PROPERTY_TABLE(MACRO) \
CORE_WCM_PROPERTY_TABLE(MACRO) \
+ GC_WCM_PROPERTY_TABLE(MACRO) \
DEBUG_ONLY_TABLE(MACRO)
private:
@@ -438,8 +446,8 @@ class WasmCompiledModule : public FixedArray {
public:
static Handle<WasmCompiledModule> New(
- Isolate* isolate, Handle<WasmSharedModuleData> shared,
- Handle<FixedArray> code_table, Handle<FixedArray> export_wrappers,
+ Isolate* isolate, wasm::WasmModule* module, Handle<FixedArray> code_table,
+ Handle<FixedArray> export_wrappers,
const std::vector<wasm::GlobalHandleAddress>& function_tables,
const std::vector<wasm::GlobalHandleAddress>& signature_tables);
@@ -447,13 +455,15 @@ class WasmCompiledModule : public FixedArray {
Handle<WasmCompiledModule> module);
static void Reset(Isolate* isolate, WasmCompiledModule* module);
- inline Address GetGlobalsStartOrNull() const;
+ // TODO(mtrofin): delete this when we don't need FLAG_wasm_jit_to_native
+ static void ResetGCModel(Isolate* isolate, WasmCompiledModule* module);
uint32_t default_mem_size() const;
- static void SetGlobalsStartAddressFrom(
- Factory* factory, Handle<WasmCompiledModule> compiled_module,
- Handle<JSArrayBuffer> buffer);
+ wasm::NativeModule* GetNativeModule() const;
+ void InsertInChain(WasmModuleObject*);
+ void RemoveFromChain();
+ void OnWasmModuleDecodingComplete(Handle<WasmSharedModuleData>);
#define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
WCM_PROPERTY_TABLE(DECLARATION)
@@ -555,23 +565,16 @@ class WasmCompiledModule : public FixedArray {
// FixedArray with all hit breakpoint objects.
MaybeHandle<FixedArray> CheckBreakPoints(int position);
- // Compile lazily the function called in the given caller code object at the
- // given offset.
- // If the called function cannot be determined from the caller (indirect
- // call / exported function), func_index must be set. Otherwise it can be -1.
- // If patch_caller is set, then all direct calls to functions which were
- // already lazily compiled are patched (at least the given call site).
- // Returns the Code to be called at the given call site.
- static Handle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>,
- Handle<Code> caller, int offset,
- int func_index, bool patch_caller);
-
- inline void ReplaceCodeTableForTesting(Handle<FixedArray> testing_table);
+ inline void ReplaceCodeTableForTesting(
+ std::vector<wasm::WasmCode*>&& testing_table);
+ // TODO(mtrofin): following 4 unnecessary after we're done with
+ // FLAG_wasm_jit_to_native
static void SetTableValue(Isolate* isolate, Handle<FixedArray> table,
int index, Address value);
static void UpdateTableValue(FixedArray* table, int index, Address value);
static Address GetTableValue(FixedArray* table, int index);
+ inline void ReplaceCodeTableForTesting(Handle<FixedArray> testing_table);
private:
void InitId();
@@ -652,10 +655,6 @@ class WasmDebugInfo : public FixedArray {
// Returns the number of calls / function frames executed in the interpreter.
uint64_t NumInterpretedCalls();
- // Update the memory view of the interpreter after executing GrowMemory in
- // compiled code.
- void UpdateMemory(JSArrayBuffer* new_memory);
-
// Get scope details for a specific interpreted frame.
// This returns a JSArray of length two: One entry for the global scope, one
// for the local scope. Both elements are JSArrays of size
@@ -677,6 +676,27 @@ class WasmDebugInfo : public FixedArray {
wasm::FunctionSig*);
};
+// Attach function information in the form of deoptimization data to the given
+// code object. This information will be used for generating stack traces,
+// calling imported functions in the interpreter, knowing which function to
+// compile in a lazy compile stub, and more. The deopt data will be a newly
+// allocated FixedArray of length 2, where the first element is a WeakCell
+// containing the WasmInstanceObject, and the second element is the function
+// index.
+// If calling this method repeatedly for the same instance, pass a WeakCell
+// directly in order to avoid creating many cells pointing to the same instance.
+void AttachWasmFunctionInfo(Isolate*, Handle<Code>,
+ MaybeHandle<WeakCell> weak_instance,
+ int func_index);
+void AttachWasmFunctionInfo(Isolate*, Handle<Code>,
+ MaybeHandle<WasmInstanceObject>, int func_index);
+
+struct WasmFunctionInfo {
+ MaybeHandle<WasmInstanceObject> instance;
+ int func_index;
+};
+WasmFunctionInfo GetWasmFunctionInfo(Isolate*, Handle<Code>);
+
#undef DECL_OOL_QUERY
#undef DECL_OOL_CAST
#undef DECL_GETTER