Created attachment 598060 [details]
Test case for shell (run with -n -m)
The attached test asserts/crashes on mozilla-central revision 78fde7e54d92 (options -m -n).
Stepping through the assert crashes:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000412598 in js::gc::ArenaHeader::allocated (this=0x7fff00000000) at ../../jsgc.h:447
447 JS_ASSERT(allocKind <= size_t(FINALIZE_LIMIT));
(gdb) bt 8
#0 0x0000000000412598 in js::gc::ArenaHeader::allocated (this=0x7fff00000000) at ../../jsgc.h:447
#1 0x00000000004125e0 in js::gc::ArenaHeader::getAllocKind (this=0x7fff00000000) at ../../jsgc.h:478
#2 0x00000000004126f6 in js::gc::Cell::getAllocKind (this=0x7fff00000001) at ../../jsgc.h:869
#3 0x000000000047da08 in js::gc::GetGCThingTraceKind (thing=0x7fff00000001) at ../jsgcinlines.h:63
#4 0x00000000004c654a in js::gc::MarkKind (trc=0x7fffffffb230, thing=0x7fff00000001, kind=JSTRACE_STRING) at /srv/repos/mozilla-central/js/src/jsgcmark.cpp:219
#5 0x00000000004c6930 in js::gc::MarkValueInternal (trc=0x7fffffffb230, v=...) at /srv/repos/mozilla-central/js/src/jsgcmark.cpp:306
#6 0x00000000004c6ac2 in js::gc::MarkValueRootRange (trc=0x7fffffffb230, len=9, vec=0x7ffff63fb270, name=0x7d37e6 "vm_stack")
#7 0x000000000061e893 in js::gc::MarkValueRootRange (trc=0x7fffffffb230, begin=0x7ffff63fb270, end=0x7ffff63fb2b8, name=0x7d37e6 "vm_stack") at ../jsgcmark.h:114
(More stack frames follow...)
(gdb) x /4i $pc
=> 0x412598 <js::gc::ArenaHeader::allocated() const+16>: movzbl 0x18(%rax),%eax
0x41259c <js::gc::ArenaHeader::allocated() const+20>: cmp $0x14,%al
0x41259e <js::gc::ArenaHeader::allocated() const+22>: jbe 0x4125b8 <js::gc::ArenaHeader::allocated() const+48>
0x4125a0 <js::gc::ArenaHeader::allocated() const+24>: mov $0x1bf,%edx
(gdb) info register rax
rax 0x7fff00000000 140733193388032
S-s and sg:critical due to GC related crash.
This is a regression from the non-conservative VM stack scanning. Here's what seems to be the problem. We call a native. It pushes space for some native CallArgs via ContextStack::pushInvokeArgs. Those args never get initialized with anything. Then we run a GC. It will scan the stack up to StackSpace::firstUnused(), which includes the uninitialized CallArgs. We crash.
I don't know this code well, but I'm kinda thinking that we don't need to scan those native CallArgs. I thought they were only there for the debugger. Luke? If we do have to scan them, is there a way to tell whether they've been initialized or not? If there's no way, how much would it cost us to just initialize them no matter what?
The native args definitely need to be marked (they are assumed to be rooted memory from within the native). I think pushInvokeArgs should simply MakeValueRangeGCSafe on the pushed range (again... I definitely used to do this but I guess it was removed b/c of the conservative stack scanner...).
Created attachment 598407 [details] [diff] [review]
This patch adds the MakeRangeGCSafe. I benchmarked SunSpider, V8, and Kraken. I didn't observe any effect.
I also added some stack poisoning. It turned up another problem where we were reading outside of seg_->end(). I think it was safe, because we wouldn't have GCed in between the pop and the read. But still worth fixing.
Luke, since I'm not so familiar with the stack invariants, it may be possible to strengthen the poisoning stuff by putting it in more places or making it cover more memory. Any suggestions?
Comment on attachment 598407 [details] [diff] [review]
Nice debug additions.
Backed out because it turned Windows builds purple (purple??):
(In reply to Bill McCloskey (:billm) from comment #1)
> This is a regression from the non-conservative VM stack scanning.
What's the bug for that, or the affected versions?
Tracking for 12 onwards. Bill, if this is not a problem in 12 let me know and I'll untrack this.
This is a regression from bug 723313. 12 is unaffected.
I'm trying again without the assertions. Hopefully that should avoid the terrifying purpleness.
Test committed with fix, marking verified based on that.
A testcase for this bug was automatically identified at js/src/jit-test/tests/basic/bug728086.js.