Assertion failure: !tc->isMarkedGray(), at src/js/src/gc/GC.cpp:5359
Categories
(Core :: JavaScript: GC, defect, P1)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox135 | --- | fixed |
People
(Reporter: sm-bugs, Assigned: jonco)
References
(Blocks 2 open bugs)
Details
(Keywords: reporter-external)
Attachments
(1 external file)
Steps to reproduce:
Version: ff95c781c335e83ba8f5be401e479201fe28a3f5
Args: js --fuzzing-safe --gc-zeal=17,250 <test-case>
Input:
function a() {
b = "".startsWith("")
function c() {
return newGlobal(c)
}
c.newCompartment = b
const d = c()
d.grayRoot()
with (d) {
function e() { }
const f = new FinalizationRegistry(e)
f.register(c)
}
}
new a
new a
nukeAllCCWs()
Actual results:
Assertion failure: !tc->isMarkedGray(), at src/js/src/gc/GC.cpp:5359
#0 0x55ce55a69ac0 in js::gc::detail::AssertCellIsNotGray(js::gc::Cell const*) src/js/src/gc/GC.cpp:5359:3
#1 0x55ce54d13a57 in js::HeapSlot::post(js::NativeObject*, js::HeapSlot::Kind, unsigned int, JS::Value const&) src/js/src/gc/Barrier.h:991:5
#2 0x55ce54d13a57 in js::HeapSlot::set(js::NativeObject*, js::HeapSlot::Kind, unsigned int, JS::Value const&) src/js/src/gc/Barrier.h:984:5
#3 0x55ce54e875ac in js::NativeObject::setReservedSlot(unsigned int, JS::Value const&) src/js/src/vm/NativeObject.h:1331:31
#4 0x55ce54e875ac in js::FinalizationRecordObject::clear() src/js/src/builtin/FinalizationRegistryObject.cpp:80:3
#5 0x55ce54e8d747 in js::FinalizationRegistryObject::unregisterRecord(js::FinalizationRecordObject*) src/js/src/builtin/FinalizationRegistryObject.cpp:600:11
#6 0x55ce55a45793 in js::gc::GCRuntime::nukeFinalizationRecordWrapper(JSObject*, js::FinalizationRecordObject*) src/js/src/gc/FinalizationObservers.cpp:288:5
#7 0x55ce556fa3b0 in js::NukeRemovedCrossCompartmentWrapper(JSContext*, JSObject*) src/js/src/proxy/BaseProxyHandler.cpp:414:3
#8 0x55ce556fa3b0 in js::NukeCrossCompartmentWrappers(JSContext*, js::CompartmentFilter const&, JS::Realm*, js::NukeReferencesToWindow, js::NukeReferencesFromTarget) src/js/src/proxy/CrossCompartmentWrapper.cpp:461:7
#9 0x55ce54ceef87 in NukeAllCCWs(JSContext*, unsigned int, JS::Value*) src/js/src/shell/js.cpp:7262:3
#10 0x55ce54db3f6e in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) src/js/src/vm/Interpreter.cpp:528:13
#11 0x55ce54db31cf in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) src/js/src/vm/Interpreter.cpp:624:12
#12 0x55ce54dcb3c4 in js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason) src/js/src/vm/Interpreter.cpp:696:10
#13 0x55ce54dcb3c4 in js::Interpret(JSContext*, js::RunState&) src/js/src/vm/Interpreter.cpp:3326:16
#14 0x55ce54db2000 in js::RunScript(JSContext*, js::RunState&) src/js/src/vm/Interpreter.cpp:498:13
#15 0x55ce54db73b1 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>) src/js/src/vm/Interpreter.cpp:889:13
#16 0x55ce54db7bbc in js::Execute(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>) src/js/src/vm/Interpreter.cpp:922:10
#17 0x55ce55006ab9 in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::MutableHandle<JS::Value>) src/js/src/vm/CompilationAndEvaluation.cpp:496:10
#18 0x55ce55006d37 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>) src/js/src/vm/CompilationAndEvaluation.cpp:520:10
#19 0x55ce54d0eb3e in RunFile(JSContext*, char const*, _IO_FILE*, CompileUtf8, bool, bool) src/js/src/shell/js.cpp:1324:10
#20 0x55ce54d0dbe5 in Process(JSContext*, char const*, bool, FileKind) src/js/src/shell/js.cpp
#21 0x55ce54cc6ef9 in ProcessArgs(JSContext*, js::cli::OptionParser*) src/js/src/shell/js.cpp:11861:10
#22 0x55ce54cc6ef9 in Shell(JSContext*, js::cli::OptionParser*) src/js/src/shell/js.cpp:12128:12
#23 0x55ce54cbdd5d in main src/js/src/shell/js.cpp:12690:12
#24 0x7f851729dd8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#25 0x7f851729de3f in __libc_start_main csu/../csu/libc-start.c:392:3
#26 0x55ce54c87278 in _start (src/reproducebuild/dist/bin/js+0x1bd3278) (BuildId: 5d99258d19828e08dce328574edaec05)
Updated•2 years ago
|
Comment 1•2 years ago
|
||
Jon, could you help to investigate this GC fuzz bug and comment on what you find. This will help with triaging this bug.
Comment 2•2 years ago
|
||
Somewhat simplified test case:
var c = {};
function a() {
const d = newGlobal({ newCompartment: true });
d.grayRoot();
with (d) {
const f = new FinalizationRegistry(v => { });
f.register(c);
}
}
a();
a();
nukeAllCCWs();
Comment 3•2 years ago
|
||
Yeah, I think this one is for jonco.
The crash happens when running a post barrier while clearing the QueueSlot (setting it to undefined) on a gray FinalizationRecordObject while nuking a CCW wrapper to a FinalizationRecord:
NukeAllCCWs()
js::NukeCrossCompartmentWrappers ()
js::NukeRemovedCrossCompartmentWrapper(wrapper=0x12c935db5040)
js::gc::GCRuntime::nukeFinalizationRecordWrapper(cx, wrapper=0x12c935db5040, record=0x12c935db6040)
js::FinalizationRegistryObject::unregisterRecord(record=0x7fc99d3faa60)
js::FinalizationRecordObject::clear(this=0x12c935db6040)
js::NativeObject::setReservedSlot(this=0x12c935db6040, index=0, v=...)
js::HeapSlot::set(this=0x12c935db6058, owner=0x12c935db6040, kind=js::HeapSlot::Slot, slot=0, v=...)
js::gc::detail::AssertCellIsNotGray(cell=0x12c935db6040)
In the test, when nukeAllCCWs is called, we are in the sweep phase of an incremental GC. The FinalizationRecord is gray. nukeFinalizationRecordWrapper calls FinalizationRegistryObject::unregisterRecord, which asserts when it finds that the record is gray.
The record is gray because the shell's TraceRootsArrays traces d.grayRoot() as gray which makes the whole global gray, and there are edges global -> GlobalObjectData -> FinalizationRegistryGlobalData::recordSet -> ... -> record.
How should this be handled? Normally, I'd think that the FinalizationRecordObject should be doing an unmark gray on its contents before manipulating them, but here we know we're nuking (this is in GCRuntime::nukeFinalizationRecordWrapper) and I think we try to avoid keeping things alive in order to nuke them? Is there a "let me touch gray things" mode we can turn on?
I haven't compared to other runs to see why it doesn't crash in the same way if you modify the test case in various ways.
I did some more tracing through an rr session and found this somewhat surprising path, but I think it might actually be irrelevant now but I'll put it here in case it helps explains why all of the CCWs are needed for this to reproduce:
The tracing goes from Zone::traceRootsInMajorGC -> FinalizationObservers::traceRoots() -> crossZoneRecords weakmap -> gcEphemeronEdges[(gray) FinalizationRecord] -> FinalizationRecord CCW -> empty Array -> Array Shape -> BaseShape -> global (d in the code) -> GlobalObjectData -> hashset -> FinalizationRecord (in d).
Updated•2 years ago
|
| Assignee | ||
Comment 5•2 years ago
|
||
This is an over-zealous assertion. It's OK to touch gray things when nuking CCWs.
Updated•2 years ago
|
| Assignee | ||
Comment 6•2 years ago
|
||
The main purpose of this assertion is to stop callers passing gray GC things
though the API. In this case we know when are sometimes going to see gray
wrappers and finalization records when nuking CCWs and that's OK.
Updated•2 years ago
|
Description
•