Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/wasm/module-instantiate.cc')
-rw-r--r--deps/v8/src/wasm/module-instantiate.cc66
1 files changed, 61 insertions, 5 deletions
diff --git a/deps/v8/src/wasm/module-instantiate.cc b/deps/v8/src/wasm/module-instantiate.cc
index 08bd8ff8718..9dfc1e16081 100644
--- a/deps/v8/src/wasm/module-instantiate.cc
+++ b/deps/v8/src/wasm/module-instantiate.cc
@@ -11,6 +11,7 @@
#include "src/tracing/trace-event.h"
#include "src/utils/utils.h"
#include "src/wasm/module-compiler.h"
+#include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-external-refs.h"
#include "src/wasm/wasm-import-wrapper-cache.h"
#include "src/wasm/wasm-module.h"
@@ -84,6 +85,39 @@ class CompileImportWrapperTask final : public CancelableTask {
WasmImportWrapperCache::ModificationScope* const cache_scope_;
};
+Handle<Map> CreateStructMap(Isolate* isolate, const WasmModule* module,
+ int struct_index) {
+ const wasm::StructType* type = module->struct_type(struct_index);
+ int inobject_properties = 0;
+ DCHECK_LE(type->total_fields_size(), kMaxInt - WasmStruct::kHeaderSize);
+ int instance_size =
+ WasmStruct::kHeaderSize + static_cast<int>(type->total_fields_size());
+ InstanceType instance_type = WASM_STRUCT_TYPE;
+ // TODO(jkummerow): If NO_ELEMENTS were supported, we could use that here.
+ ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND;
+ Handle<Foreign> type_info =
+ isolate->factory()->NewForeign(reinterpret_cast<Address>(type));
+ Handle<Map> map = isolate->factory()->NewMap(
+ instance_type, instance_size, elements_kind, inobject_properties);
+ map->set_wasm_type_info(*type_info);
+ return map;
+}
+
+Handle<Map> CreateArrayMap(Isolate* isolate, const WasmModule* module,
+ int array_index) {
+ const wasm::ArrayType* type = module->array_type(array_index);
+ int inobject_properties = 0;
+ int instance_size = kVariableSizeSentinel;
+ InstanceType instance_type = WASM_ARRAY_TYPE;
+ ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND;
+ Handle<Foreign> type_info =
+ isolate->factory()->NewForeign(reinterpret_cast<Address>(type));
+ Handle<Map> map = isolate->factory()->NewMap(
+ instance_type, instance_size, elements_kind, inobject_properties);
+ map->set_wasm_type_info(*type_info);
+ return map;
+}
+
} // namespace
// A helper class to simplify instantiating a module from a module object.
@@ -534,11 +568,30 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
}
//--------------------------------------------------------------------------
- // Debugging support.
+ // Create maps for managed objects (GC proposal).
//--------------------------------------------------------------------------
- // Set all breakpoints that were set on the shared module.
- WasmScript::SetBreakpointsOnNewInstance(
- handle(module_object_->script(), isolate_), instance);
+ if (enabled_.has_gc()) {
+ int count = 0;
+ for (uint8_t type_kind : module_->type_kinds) {
+ if (type_kind == kWasmStructTypeCode || type_kind == kWasmArrayTypeCode) {
+ count++;
+ }
+ }
+ Handle<FixedArray> maps =
+ isolate_->factory()->NewUninitializedFixedArray(count);
+ for (int i = 0; i < static_cast<int>(module_->type_kinds.size()); i++) {
+ int index = 0;
+ if (module_->type_kinds[i] == kWasmStructTypeCode) {
+ Handle<Map> map = CreateStructMap(isolate_, module_, i);
+ maps->set(index++, *map);
+ }
+ if (module_->type_kinds[i] == kWasmArrayTypeCode) {
+ Handle<Map> map = CreateArrayMap(isolate_, module_, i);
+ maps->set(index++, *map);
+ }
+ }
+ instance->set_managed_object_maps(*maps);
+ }
//--------------------------------------------------------------------------
// Create a wrapper for the start function.
@@ -751,7 +804,10 @@ void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global,
case ValueType::kAnyRef:
case ValueType::kFuncRef:
case ValueType::kNullRef:
- case ValueType::kExnRef: {
+ case ValueType::kExnRef:
+ case ValueType::kRef:
+ case ValueType::kOptRef:
+ case ValueType::kEqRef: {
DCHECK_IMPLIES(global.type == kWasmNullRef, value->GetRef()->IsNull());
tagged_globals_->set(global.offset, *value->GetRef());
break;