Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / wasm / WasmInstanceData.h
blob98aa097deee693cc47821c6743957ee2806b75ba
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
4 * Copyright 2021 Mozilla Foundation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef wasm_instance_data_h
20 #define wasm_instance_data_h
22 #include <stdint.h>
24 #include "NamespaceImports.h"
26 #include "gc/Pretenuring.h"
27 #include "js/Utility.h"
28 #include "wasm/WasmInstance.h"
29 #include "wasm/WasmMemory.h"
30 #include "wasm/WasmTypeDecls.h"
32 namespace js {
33 namespace wasm {
35 // ExportArg holds the unboxed operands to the wasm entry trampoline which can
36 // be called through an ExportFuncPtr.
38 struct ExportArg {
39 uint64_t lo;
40 uint64_t hi;
43 using ExportFuncPtr = int32_t (*)(ExportArg*, Instance*);
45 // TypeDefInstanceData describes the runtime information associated with a
46 // module's type definition. This is accessed directly from JIT code and the
47 // Instance.
49 struct TypeDefInstanceData {
50 TypeDefInstanceData()
51 : typeDef(nullptr),
52 superTypeVector(nullptr),
53 shape(nullptr),
54 clasp(nullptr),
55 allocKind(gc::AllocKind::LIMIT),
56 unused(0) {}
58 // The canonicalized pointer to this type definition. This is kept alive by
59 // the type context associated with the instance.
60 const wasm::TypeDef* typeDef;
62 // The supertype vector for this type definition. This is also kept alive
63 // by the type context associated with the instance.
65 const wasm::SuperTypeVector* superTypeVector;
67 // The next four fields are only meaningful for, and used by, structs and
68 // arrays.
69 GCPtr<Shape*> shape;
70 const JSClass* clasp;
71 // The allocation site for GC types. This is used for pre-tenuring.
72 alignas(8) gc::AllocSite allocSite;
73 // Only valid for structs.
74 gc::AllocKind allocKind;
76 // This union is only meaningful for structs and arrays, and should
77 // otherwise be set to zero:
79 // * if `typeDef` refers to a struct type, then it caches the value of
80 // `typeDef->structType().size_` (a size in bytes)
82 // * if `typeDef` refers to an array type, then it caches the value of
83 // `typeDef->arrayType().elementType_.size()` (also a size in bytes)
85 // This is so that allocators of structs and arrays don't need to chase from
86 // this TypeDefInstanceData through `typeDef` to find the value.
87 union {
88 uint32_t structTypeSize;
89 uint32_t arrayElemSize;
90 uint32_t unused;
93 static constexpr size_t offsetOfShape() {
94 return offsetof(TypeDefInstanceData, shape);
96 static constexpr size_t offsetOfSuperTypeVector() {
97 return offsetof(TypeDefInstanceData, superTypeVector);
99 static constexpr size_t offsetOfAllocSite() {
100 return offsetof(TypeDefInstanceData, allocSite);
102 static constexpr size_t offsetOfArrayElemSize() {
103 return offsetof(TypeDefInstanceData, arrayElemSize);
107 // FuncImportInstanceData describes the region of wasm global memory allocated
108 // in the instance's thread-local storage for a function import. This is
109 // accessed directly from JIT code and mutated by Instance as exits become
110 // optimized and deoptimized.
112 struct FuncImportInstanceData {
113 // The code to call at an import site: a wasm callee, a thunk into C++, or a
114 // thunk into JIT code.
115 void* code;
117 // The callee's Instance pointer, which must be loaded to InstanceReg
118 // (along with any pinned registers) before calling 'code'.
119 Instance* instance;
121 // The callee function's realm.
122 JS::Realm* realm;
124 // A GC pointer which keeps the callee alive and is used to recover import
125 // values for lazy table initialization.
126 GCPtr<JSObject*> callable;
127 static_assert(sizeof(GCPtr<JSObject*>) == sizeof(void*), "for JIT access");
130 struct MemoryInstanceData {
131 // Pointer the memory object.
132 GCPtr<WasmMemoryObject*> memory;
134 // Pointer to the base of the memory.
135 uint8_t* base;
137 // Bounds check limit in bytes (or zero if there is no memory). This is
138 // 64-bits on 64-bit systems so as to allow for heap lengths up to and beyond
139 // 4GB, and 32-bits on 32-bit systems, where heaps are limited to 2GB.
141 // See "Linear memory addresses and bounds checking" in WasmMemory.cpp.
142 uintptr_t boundsCheckLimit;
144 // Whether this memory is shared or not.
145 bool isShared;
148 // TableInstanceData describes the region of wasm global memory allocated in the
149 // instance's thread-local storage which is accessed directly from JIT code
150 // to bounds-check and index the table.
152 struct TableInstanceData {
153 // Length of the table in number of elements (not bytes).
154 uint32_t length;
156 // Pointer to the array of elements (which can have various representations).
157 // For tables of anyref this is null.
158 // For tables of functions, this is a pointer to the array of code pointers.
159 void* elements;
162 // TagInstanceData describes the instance state associated with a tag.
164 struct TagInstanceData {
165 GCPtr<WasmTagObject*> object;
168 // Table element for TableRepr::Func which carries both the code pointer and
169 // a instance pointer (and thus anything reachable through the instance).
171 struct FunctionTableElem {
172 // The code to call when calling this element. The table ABI is the system
173 // ABI with the additional ABI requirements that:
174 // - InstanceReg and any pinned registers have been loaded appropriately
175 // - if this is a heterogeneous table that requires a signature check,
176 // WasmTableCallSigReg holds the signature id.
177 void* code;
179 // The pointer to the callee's instance's Instance. This must be loaded into
180 // InstanceReg before calling 'code'.
181 Instance* instance;
184 } // namespace wasm
185 } // namespace js
187 #endif // wasm_instance_data_h