镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 9c61d81

Browse files
committed
test(jit): race property assumption mutations
Overlap optimized own and inherited reads with delete/re-add, data-accessor redefinition, and same-shape prototype replacement in a shared no-GIL realm. Reject torn/stale values while allowing the documented ordinary-object program-race states. Focused race: 5/5 Debug runs and 1/1 suppression-free TSan, with zero failures or leaks. Full-suite validation follows on the integrated main tree before push. Test262 flips are not applicable because the race uses the nonstandard parallel_js Thread bridge.
1 parent 27db7d8 commit 9c61d81

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

‎src/context.zig‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16933,6 +16933,81 @@ test "parallel_js: delete and descriptor changes retire only affected artifacts"
1693316933
try std.testing.expect(stats.shape_survivor_artifacts >= 7);
1693416934
}
1693516935

16936+
test "parallel_js: optimized reads race delete redefine and prototype replacement" {
16937+
if (builtin.single_threaded) return error.SkipZigTest;
16938+
if (!jit.supported or builtin.cpu.arch != .aarch64) return error.SkipZigTest;
16939+
16940+
const ctx = try Context.createWithTestingOptions(std.testing.allocator, .{
16941+
.enable_threads = true,
16942+
.enable_gc = true,
16943+
.enable_jit = true,
16944+
.parallel_gc = true,
16945+
.parallel_js = true,
16946+
});
16947+
defer ctx.destroy();
16948+
16949+
const result = ctx.evaluate(
16950+
\\const deleteTarget = { value: 1, deleteMarker: 0 };
16951+
\\const redefineTarget = { value: 2, redefineMarker: 0 };
16952+
\\const protoA = { inherited: 3 };
16953+
\\const protoB = { inherited: 4 };
16954+
\\const protoTarget = Object.create(protoA);
16955+
\\const gate = { ready: 0, stop: 0 };
16956+
\\function deleteRead(o) { return o.value; }
16957+
\\function redefineRead(o) { return o.value; }
16958+
\\function inheritedRead(o) { return o.inherited; }
16959+
\\function six() { return 6; }
16960+
\\for (let warm = 0; warm < 64; ++warm) {
16961+
\\ deleteRead(deleteTarget);
16962+
\\ redefineRead(redefineTarget);
16963+
\\ inheritedRead(protoTarget);
16964+
\\}
16965+
\\const reader = new Thread(() => {
16966+
\\ let checks = 0;
16967+
\\ Atomics.store(gate, "ready", 1);
16968+
\\ while (Atomics.load(gate, "stop") === 0) {
16969+
\\ const deleted = deleteRead(deleteTarget);
16970+
\\ if (deleted !== undefined && deleted !== 1)
16971+
\\ throw new Error("stale delete read: " + deleted);
16972+
\\ const redefined = redefineRead(redefineTarget);
16973+
\\ if (redefined !== undefined && redefined !== 2 && redefined !== 6)
16974+
\\ throw new Error("stale redefine read: " + redefined);
16975+
\\ const inherited = inheritedRead(protoTarget);
16976+
\\ if (inherited !== 3 && inherited !== 4)
16977+
\\ throw new Error("stale prototype read: " + inherited);
16978+
\\ ++checks;
16979+
\\ }
16980+
\\ return checks;
16981+
\\});
16982+
\\while (Atomics.load(gate, "ready") === 0) {}
16983+
\\for (let round = 0; round < 64; ++round) {
16984+
\\ delete deleteTarget.value;
16985+
\\ deleteTarget.value = 1;
16986+
\\ Object.defineProperty(redefineTarget, "value", {
16987+
\\ get: six, enumerable: true, configurable: true
16988+
\\ });
16989+
\\ Object.defineProperty(redefineTarget, "value", {
16990+
\\ value: 2, writable: true, enumerable: true, configurable: true
16991+
\\ });
16992+
\\ Object.setPrototypeOf(protoTarget, (round & 1) === 0 ? protoB : protoA);
16993+
\\}
16994+
\\Atomics.store(gate, "stop", 1);
16995+
\\reader.join();
16996+
) catch |err| {
16997+
if (ctx.exception) |exception| {
16998+
if (exception.isObject()) {
16999+
const message = exception.asObj().getOwn("message") orelse Value.undef();
17000+
if (message.isString()) std.debug.print("property mutation race: {s}: {s}\n", .{
17001+
exception.asObj().errorName(), message.asStr(),
17002+
});
17003+
}
17004+
}
17005+
return err;
17006+
};
17007+
try std.testing.expect(result.isNumber());
17008+
try std.testing.expect(result.asNum() > 0);
17009+
}
17010+
1693617011
test "inherited value mutation preserves optimized artifacts" {
1693717012
try verifyInheritedValueMutation(.{
1693817013
.enable_gc = true,

0 commit comments

Comments
 (0)