v8/test/mjsunit/shared-memory/shared-struct-workers-optimized-code.js
Shu-yu Guo 4266684c99 [shared-struct] Make publishing of shared objects safe
Currently there is nothing ensuring the internal VM state of shared
objects are in a coherent state and visible to other threads when the
shared object is published.

This CL adds a store-store memory barrier when returning from Factory methods that allocate shared JSObjects that are exposed to user JS code. For primitives, there is an additional store-store memory barrier in the shared value barrier.

Bug: v8:12547
Change-Id: I4833c7ebf02cc352da9b006d2732669d6d043172
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_isolates_rel_ng,v8_linux64_tsan_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3819041
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82596}
2022-08-19 15:14:32 +00:00

41 lines
1.1 KiB
JavaScript

// Copyright 2022 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: --shared-string-table --harmony-struct --allow-natives-syntax
// Flags: --verify-heap
"use strict";
if (this.Worker) {
(function TestSharedStructOptimizedCode() {
let workerScript =
`onmessage = function(struct) {
%PrepareFunctionForOptimization(writePayload);
for (let i = 0; i < 5; i++) writePayload(struct);
%OptimizeFunctionOnNextCall(writePayload);
writePayload(struct);
postMessage("done");
};
function writePayload(struct) {
for (let i = 0; i < 100; i++) {
struct.payload = struct.payload + 1;
}
}
postMessage("started");`;
let worker = new Worker(workerScript, { type: 'string' });
assertEquals("started", worker.getMessage());
let MyStruct = new SharedStructType(['payload']);
let struct = new MyStruct();
struct.payload = 0;
worker.postMessage(struct);
assertEquals("done", worker.getMessage());
worker.terminate();
})();
}