Closed Bug 684575 Opened 13 years ago Closed 12 years ago

[jsdbg2] GC'ing a Debugger instance causes JSCompartment::updateForDebugMode to try to use CellIter during GC

Categories

(Core Graveyard :: Java to XPCOM Bridge, defect)

17 Branch
x86_64
Linux
defect
Not set
critical

Tracking

(Not tracked)

RESOLVED WORKSFORME
mozilla15

People

(Reporter: decoder, Assigned: jimb)

References

Details

(Keywords: assertion, testcase, Whiteboard: js-triage-needed)

The following test asserts on mozilla-central revision a351ae35f2c4 (options -m -n):

var g = newGlobal('new-compartment');
var dbg = Debugger(g);
(dbg) = function (f) {}
try {
  a = new Array();
  while (1) a = new Array(a);
} catch(e) {}


I assume this is jsdbg2 API only.
Note: The specified mozilla-central revision had a build problem with standalone shell, patch from http://hg.mozilla.org/integration/mozilla-inbound/rev/fff3dc9478ce fixes this.
This bug stopped appearing with the changeset below, but I really doubt that addressed the underlying issue.

changeset:   77155:9208ee94b012
user:        Bill McCloskey <wmccloskey@mozilla.com>
date:        Mon Sep 19 15:22:31 2011 -0700
summary:     Bug 604747 - Set GC max heap size to 4GB in JS shell (r=gregor)
Here's what's going on.

A Debugger is GC'd. Thus, each of its debuggees can be taken out of debug mode. However, JSCompartment::updateForDebugMode tries to use CellIter to search for affected scripts --- but the use of CellIter is forbidden during garbage collection.
Summary: [jsdbg2] Assertion failure: !comp->rt->gcRunning, at ../jsgcinlines.h:352 → [jsdbg2] GC'ing a Debugger instance causes JSCompartment::updateForDebugMode to try to use CellIter during GC
There are some debugger/script analysis interactions here I don't understand.

If we're in an activeAnalysis, and do a GC that collects Debuggers, compartments could come out of debug mode. That invalidates some script analyses, but activeAnalysis means that someone is actively using that information. Do we need to queue the debug mode change until the analysis is complete?
I was just looking at the CellIter/CellIterUnderGC code, and it seems pretty error-prone. Would it be possible to have a single class that works regardless of whether a GC is happening (by checking the gcRunning flag)?

Also, it seems like CellIter requires background finalization to have completed. It doesn't wait for it. But I don't see any reason why the callers (like updateForDebugMode) can guarantee that. Do you know what's going on here, Igor?
(In reply to Bill McCloskey (:billm) from comment #5)
> I was just looking at the CellIter/CellIterUnderGC code, and it seems pretty
> error-prone. Would it be possible to have a single class that works
> regardless of whether a GC is happening (by checking the gcRunning flag)?

Since incremental GC landed, it should be safe to use CellIter from a GC (due to some code simplifications that cause us to keep the free list synced during the GC).

> Also, it seems like CellIter requires background finalization to have
> completed. It doesn't wait for it. But I don't see any reason why the
> callers (like updateForDebugMode) can guarantee that. Do you know what's
> going on here, Igor?

Igor explained to me a while back that this isn't a problem because we only use CellIter for AllocKinds that can't be finalized in the background (and we assert this).

It sounds like Jim's question is comment 4 is still a possible problem, though.
OS: Linux → Mac OS X
Target Milestone: --- → mozilla13
Version: Trunk → 14 Branch
Assignee: general → jimb
The restrictions on js::gc::CellIter's use have relaxed since this bug was filed. In particular, it's okay to use during GC, and scripts are never finalized in the background. (And CellIter asserts that you only iterate over things that won't be finalized in the background.)
Status: NEW → RESOLVED
Closed: 12 years ago
Component: JavaScript Engine → Java to XPCOM Bridge
OS: Mac OS X → Linux
Resolution: --- → WORKSFORME
Target Milestone: mozilla13 → mozilla15
Version: 14 Branch → 17 Branch
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.