Commit 8acae9be authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Support mutable imported anyref globals in interpreter.

This adds support for loading and storing mutable imported globals
having a reference type in the interpreter. It expands existing test
coverage to the interpreter.

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

Change-Id: I78e0c5c73664a183e1d92ec91eadf8b9a93e4787
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1559743Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60701}
parent 0a569ea9
......@@ -2039,6 +2039,7 @@ class ThreadImpl {
}
byte* GetGlobalPtr(const WasmGlobal* global) {
DCHECK(!ValueTypes::IsReferenceType(global->type));
if (global->mutability && global->imported) {
return reinterpret_cast<byte*>(
instance_object_->imported_mutable_globals()[global->index]);
......@@ -2047,6 +2048,24 @@ class ThreadImpl {
}
}
void GetGlobalBufferAndIndex(const WasmGlobal* global,
Handle<FixedArray>* buffer, uint32_t* index) {
DCHECK(ValueTypes::IsReferenceType(global->type));
if (global->mutability && global->imported) {
*buffer =
handle(FixedArray::cast(
instance_object_->imported_mutable_globals_buffers()->get(
global->index)),
isolate_);
Address idx = instance_object_->imported_mutable_globals()[global->index];
DCHECK_LE(idx, std::numeric_limits<uint32_t>::max());
*index = static_cast<uint32_t>(idx);
} else {
*buffer = handle(instance_object_->tagged_globals_buffer(), isolate_);
*index = global->offset;
}
}
bool ExecuteSimdOp(WasmOpcode opcode, Decoder* decoder, InterpreterCode* code,
pc_t pc, int& len) {
switch (opcode) {
......@@ -3046,11 +3065,11 @@ class ThreadImpl {
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_)));
Handle<FixedArray> global_buffer; // The buffer of the global.
uint32_t global_index = 0; // The index into the buffer.
GetGlobalBufferAndIndex(global, &global_buffer, &global_index);
Handle<Object> value(global_buffer->get(global_index), isolate_);
Push(WasmValue(value));
break;
}
default:
......@@ -3077,9 +3096,10 @@ class ThreadImpl {
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());
Handle<FixedArray> global_buffer; // The buffer of the global.
uint32_t global_index = 0; // The index into the buffer.
GetGlobalBufferAndIndex(global, &global_buffer, &global_index);
global_buffer->set(global_index, *Pop().to_anyref());
break;
}
default:
......
// 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: --experimental-wasm-anyref --expose-gc
// Flags: --wasm-interpret-all
// This is just a wrapper for an existing reference types test case 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/anyref-globals.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