Commit 802a2d03 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Support reference type globals in interpreter.

This adds support for handling reference types when loading/storing
globals. Support for imported mutable globals is still missing and will
be done in a follow-up change.

R=clemensh@chromium.org
TEST=mjsunit/wasm/exceptions-global-interpreter
BUG=v8:8091,v8:7581

Change-Id: I0d14919b1ce7f49c4a0541e3d6a99ee203cfb311
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1558086
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60695}
parent 787bd978
......@@ -222,7 +222,9 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
CASE_ARG_TYPE(kWasmF32, float)
CASE_ARG_TYPE(kWasmF64, double)
#undef CASE_ARG_TYPE
case wasm::kWasmAnyRef: {
case wasm::kWasmAnyRef:
case wasm::kWasmAnyFunc:
case wasm::kWasmExceptRef: {
DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetParam(i)),
kSystemPointerSize);
Handle<Object> ref(ReadUnalignedValue<Object>(arg_buf_ptr), isolate);
......@@ -270,7 +272,9 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
CASE_RET_TYPE(kWasmF32, float)
CASE_RET_TYPE(kWasmF64, double)
#undef CASE_RET_TYPE
case wasm::kWasmAnyRef: {
case wasm::kWasmAnyRef:
case wasm::kWasmAnyFunc:
case wasm::kWasmExceptRef: {
DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetReturn(i)),
kSystemPointerSize);
WriteUnalignedValue<Object>(arg_buf_ptr, *wasm_rets[i].to_anyref());
......
......@@ -214,6 +214,8 @@ class V8_EXPORT_PRIVATE ValueTypes {
case kWasmS128:
return 16;
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef:
return kSystemPointerSize;
default:
UNREACHABLE();
......@@ -272,8 +274,9 @@ class V8_EXPORT_PRIVATE ValueTypes {
return MachineType::Float32();
case kWasmF64:
return MachineType::Float64();
case kWasmAnyFunc:
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef:
return MachineType::TaggedPointer();
case kWasmS128:
return MachineType::Simd128();
......
......@@ -3032,20 +3032,30 @@ class ThreadImpl {
GlobalIndexImmediate<Decoder::kNoValidate> imm(&decoder,
code->at(pc));
const WasmGlobal* global = &module()->globals[imm.index];
byte* ptr = GetGlobalPtr(global);
WasmValue val;
switch (global->type) {
#define CASE_TYPE(wasm, ctype) \
case kWasm##wasm: \
val = WasmValue( \
ReadLittleEndianValue<ctype>(reinterpret_cast<Address>(ptr))); \
break;
#define CASE_TYPE(wasm, ctype) \
case kWasm##wasm: { \
byte* ptr = GetGlobalPtr(global); \
Push(WasmValue( \
ReadLittleEndianValue<ctype>(reinterpret_cast<Address>(ptr)))); \
break; \
}
WASM_CTYPES(CASE_TYPE)
#undef CASE_TYPE
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef: {
HandleScope handle_scope(isolate_); // Avoid leaking handles.
DCHECK(!global->mutability || !global->imported);
Push(WasmValue(
handle(instance_object_->tagged_globals_buffer()->get(
global->offset),
isolate_)));
break;
}
default:
UNREACHABLE();
}
Push(val);
len = 1 + imm.length;
break;
}
......@@ -3053,16 +3063,25 @@ class ThreadImpl {
GlobalIndexImmediate<Decoder::kNoValidate> imm(&decoder,
code->at(pc));
const WasmGlobal* global = &module()->globals[imm.index];
byte* ptr = GetGlobalPtr(global);
WasmValue val = Pop();
switch (global->type) {
#define CASE_TYPE(wasm, ctype) \
case kWasm##wasm: \
case kWasm##wasm: { \
byte* ptr = GetGlobalPtr(global); \
WriteLittleEndianValue<ctype>(reinterpret_cast<Address>(ptr), \
val.to<ctype>()); \
break;
Pop().to<ctype>()); \
break; \
}
WASM_CTYPES(CASE_TYPE)
#undef CASE_TYPE
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef: {
HandleScope handle_scope(isolate_); // Avoid leaking handles.
DCHECK(!global->mutability || !global->imported);
instance_object_->tagged_globals_buffer()->set(
global->offset, *Pop().to_anyref());
break;
}
default:
UNREACHABLE();
}
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm --experimental-wasm-eh --allow-natives-syntax
// Flags: --wasm-interpret-all
// This is just a wrapper for existing exception handling test cases that runs
// with the --wasm-interpret-all flag added. If we ever decide to add a test
// variant for this, then we can remove this file.
load("test/mjsunit/wasm/exceptions-global.js");
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