Created attachment 533372 [details]
shell testcase, unpack, chdir and run main.js with options "-j -m -a"
The attached testcase crashes on TI revision 97f9e3274bd5 (run main.js with -j -m -a), tested on 64 bit.
==12185== Invalid read of size 8
==12185== at 0x46ED10: JSString::isStaticAtom() const (jsstr.h:367)
==12185== by 0x4CCF38: js::gc::MarkId(JSTracer*, jsid) (jsgcmark.cpp:252)
==12185== by 0x4CCFDA: js::gc::MarkId(JSTracer*, jsid, char const*) (jsgcmark.cpp:263)
==12185== by 0x4CE33F: js::gc::MarkChildren(JSTracer*, js::Shape const*) (jsgcmark.cpp:653)
==12185== by 0x4CE62C: JS_TraceChildren (jsgcmark.cpp:719)
==12185== by 0x42D8E5: JS_DumpHeap (jsapi.cpp:2554)
==12185== by 0x40C21D: DumpHeap(JSContext*, unsigned int, jsval_layout*) (js.cpp:2730)
==12185== by 0x4F342D: js::CallJSNative(JSContext*, int (*)(JSContext*, unsigned int, js::Value*), unsigned int, js::Value*) (jscntxtinlines.h:293)
==12185== by 0x716966: CallCompiler::generateNativeStub() (MonoIC.cpp:839)
==12185== by 0x7114FE: js::mjit::ic::NativeCall(js::VMFrame&, js::mjit::ic::CallICInfo*) (MonoIC.cpp:1108)
==12185== by 0x41B3F82: ???
==12185== by 0x691BC0: js::mjit::EnterMethodJIT(JSContext*, js::StackFrame*, void*, js::Value*) (MethodJIT.cpp:882)
==12185== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==12185== Process terminating with default action of signal 11 (SIGSEGV)
TM bug, JS_DumpHeap calls TraceRuntime which invokes the conservative GC without first purging the compartment's freelists. This causes the conservative GC to think an object is live when it has not been allocated yet, and we crash.
This is I think a regression from bug 601234. Igor, do you mind looking at this?
That sounds vaguely like Bug 652985, though that was before bug 601234, so it couldn't have been caused by that.
Created attachment 533853 [details] [diff] [review]
The patch adds a helper class that temporary copies the free list to the arena and then clears the arenas again in the destructor. Its instance in TraceRuntime ensures that the conservative scanner can safely access the free list when dumping the arenas.
Another fix is the call to gcHelperThread.waitBackgroundSweepEnd before tracing the heap. Without that the conservative scanner may access just finalized things.
Created attachment 534004 [details] [diff] [review]
Here is an update in view of bug 658137 landing. The new patch uses AutoCopyFreeListToArenas in IterateCells to remove the free list checks in IterateArenaCells.
IterateCells also has a bug with missing RecordNativeStackTopForGC. This is important if AutoSession would wait for another GC to finish. To make sure that this would not happen in future I have added the call to LetOtherGCFinish where it should have been put long time ago.
Comment on attachment 534004 [details] [diff] [review]
Review of attachment 534004 [details] [diff] [review]:
Now I understand the reason for RecordNativeStackTopForGC. Thanks.
@@ -2717,5 @@
> - /* -16k because it is possible to perform a GC during an overrecursion report. */
> - JS_ASSERT_IF(cx->stackLimit, JS_CHECK_STACK_SIZE(cx->stackLimit - (1 << 14), &stackDummy));
> -# endif
I'm glad to see this go.
@@ +750,5 @@
> + }
> + }
> + /*
> + * Copy temporary the free list heads to the arenas so the code can see
@@ +764,5 @@
> + }
> + }
> + /*
> + * Clear the free lists in arenas that were temporary set there using
Christian: could you test that the landed patch fixes the test case? I cannot reproduce it on my box even if the problem from the comment 1 is real.
It looks like non-THREADSAFE builds are burning, TraceRuntime uses 'rt' without defining it first.
http://hg.mozilla.org/tracemonkey/rev/57412df720cf - followup to fix !JS_THREADSAFE builds.
Igor: The original test in comment 1 is for the JM branch. So to verify this fix, I need the changes pushed on the JM branch as well. It's likely that the test will not repro on TM at all, even if the underlying problem is in TM.
cdleary-bot mozilla-central merge info:
I retested this on TI tip and it does no longer reproduce now :)
(In reply to comment #13)
> I retested this on TI tip and it does no longer reproduce now :)