Ignore:
Timestamp:
Sep 4, 2009, 12:03:33 PM (16 years ago)
Author:
Darin Adler
Message:

DateInstance object collected on ARM JIT (JSValue: WTF_USE_JSVALUE32)
https://bugs.webkit.org/show_bug.cgi?id=28909

Patch by Darin Adler <Darin Adler> on 2009-09-04
Reviewed by Geoff Garen.

Part two.

Make some improvements to garbage collection code:

1) Create a runtime assertion that catches any classes that

override markChildren but have the HasDefaultMark bit set.

2) Remove checks of the mark bit outside the MarkStack::append

function; they are redundant.

3) Improve the efficiency of the asObject and asArray functions

when called on JSCell* to avoid a round trip to JSValue.

4) Make more callers use the checked asCell and asObject

casting functions rather than unchecked casts.

5) Removed the JSCell::marked function and other GC-related

functions because these operations are no longer things that
code other than the core GC code needs to do directly. Fixed
callers that were calling them.

  • runtime/Collector.cpp:

(JSC::Heap::markConservatively): Removed unneeded call to MarkStack::drain.
(JSC::Heap::markProtectedObjects): Removed unneeded check of the mark
bit and call to MarkStack::drain.
(JSC::Heap::collect): Removed unneeded checks of the mark bit and also
changed call to SmallStrings::mark to call markChildren instead to match
the rest of the objects.
(JSC::typeName): Removed unneeded cast to JSObject*.

  • runtime/JSArray.h:

(JSC::asArray): Added an overload for JSCell* and changed the JSValue
version to call it. Removed some unneeded casts.
(JSC::JSArray::markChildrenDirect): Marked this function inline. It's in
a header, and if not marked inline this could lead to linking problems.
(JSC::MarkStack::markChildren): Added. This helper function is used by
the drain function to avoid repating code. Also added the code here to
check fro default mark violations in debug code. If a markChildren
function adds something to the mark stack, but the type info claimed
hasDefaultMark was true, then we will get an assertion now. Also fixed
the assertion about the mark bit to use the Heap function directly
because we don't have a JSCell::marked function any more.
(JSC::MarkStack::drain): Changed a local variable from "v" to "value",
and from "currentCell" to "cell". Changed to call markChildren in two
places instead of repeating a chain of if statements twice. Changed
code that reads and writes the mark bit to use Heap::isCellMarked and
Heap::markCell so we can eliminate the JSCell::marked and
JSCell::markCellDirect functions.

  • runtime/JSCell.h: Removed JSCell's markCellDirect and marked member

functions. Added a comment explaining that asCell should be deprecated
in favor of the JSValue asCell member function.
(JSC::MarkStack::append): Added the assertion that catches callers
that have set the HasDefaultMark bit incorrectly. Changed
code that reads and writes the mark bit to use Heap::isCellMarked and
Heap::markCell so we can eliminate the JSCell::marked and
JSCell::markCellDirect functions. Moved the overload of
MarkStack::append for JSValue here so it can call through to the cell
version. The old version had a copy of all the code instead, but that
repeated the conversion from JSValue to JSCell* and the check for
whether a value is a cell multiple times.
(JSC::Structure::markAggregate): Moved this function here to avoid
dependencies for Structure.h, since this calls MarkStack::append.

  • runtime/JSObject.cpp:

(JSC::JSObject::markChildren): Added code to clear
m_isCheckingForDefaultMarkViolation so the marking done by JSObject
doesn't trigger the assertion.

  • runtime/JSValue.h: Moved some stray includes that were outside the

header guard inside it. Not sure how that happened! Removed the
GC-related member functions markChildren, hasChildren, marked, and
markDirect.

  • runtime/JSWrapperObject.h: Made markChildren private.

(JSC::JSWrapperObject::createStructure): Added. Fixes a bug where the
HasDefaultMark bit was set.

  • runtime/MarkStack.h: Added m_isCheckingForDefaultMarkViolation and

initialized it to false. Moved the append function body from here to
JSCell.h. Added a declaration of a private markChildren function used
inside the drain function.

  • runtime/SmallStrings.cpp:

(JSC::SmallStrings::markChildren): Changed the name and style of this
function to match other functions. This allows us to share the normal
mark stack code path.

  • runtime/SmallStrings.h: Changed the name and interface of mark to

the more-normal markChildren style.

  • runtime/Structure.h: Moved the body of markAggregate into the

JSCell.h to avoid a circular dependency with JSCell.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSArray.h

    r47812 r48068  
    122122    JSArray* constructArray(ExecState*, const ArgList& values);
    123123
     124    inline JSArray* asArray(JSCell* cell)
     125    {
     126        ASSERT(cell->inherits(&JSArray::info));
     127        return static_cast<JSArray*>(cell);
     128    }
     129
    124130    inline JSArray* asArray(JSValue value)
    125131    {
    126         ASSERT(asObject(value)->inherits(&JSArray::info));
    127         return static_cast<JSArray*>(asObject(value));
    128     }
    129 
    130     inline bool isJSArray(JSGlobalData* globalData, JSValue v) { return v.isCell() && v.asCell()->vptr() == globalData->jsArrayVPtr; }
     132        return asArray(value.asCell());
     133    }
     134
     135    inline bool isJSArray(JSGlobalData* globalData, JSValue v)
     136    {
     137        return v.isCell() && v.asCell()->vptr() == globalData->jsArrayVPtr;
     138    }
    131139    inline bool isJSArray(JSGlobalData* globalData, JSCell* cell) { return cell->vptr() == globalData->jsArrayVPtr; }
    132140
    133     void JSArray::markChildrenDirect(MarkStack& markStack) {
     141    inline void JSArray::markChildrenDirect(MarkStack& markStack)
     142    {
    134143        JSObject::markChildrenDirect(markStack);
    135144       
    136145        ArrayStorage* storage = m_storage;
    137        
     146
    138147        unsigned usedVectorLength = std::min(storage->m_length, storage->m_vectorLength);
    139148        markStack.appendValues(storage->m_vector, usedVectorLength, MayContainNullValues);
    140        
     149
    141150        if (SparseArrayValueMap* map = storage->m_sparseValueMap) {
    142151            SparseArrayValueMap::iterator end = map->end();
     
    144153                markStack.append(it->second);
    145154        }
     155    }
     156
     157    inline void MarkStack::markChildren(JSCell* cell)
     158    {
     159        ASSERT(Heap::isCellMarked(cell));
     160        if (cell->structure()->typeInfo().hasDefaultMark()) {
     161#ifdef NDEBUG
     162            asObject(cell)->markChildrenDirect(*this);
     163#else
     164            ASSERT(!m_isCheckingForDefaultMarkViolation);
     165            m_isCheckingForDefaultMarkViolation = true;
     166            cell->markChildren(*this);
     167            ASSERT(m_isCheckingForDefaultMarkViolation);
     168            m_isCheckingForDefaultMarkViolation = false;
     169#endif
     170            return;
     171        }
     172        if (cell->vptr() == m_jsArrayVPtr) {
     173            asArray(cell)->markChildrenDirect(*this);
     174            return;
     175        }
     176        cell->markChildren(*this);
    146177    }
    147178
     
    158189            findNextUnmarkedNullValue:
    159190                ASSERT(current.m_values != end);
    160                 JSValue v = *current.m_values;
     191                JSValue value = *current.m_values;
    161192                current.m_values++;
    162                
    163                 if (!v || v.marked()) {
     193
     194                JSCell* cell;
     195                if (!value || !value.isCell() || Heap::isCellMarked(cell = value.asCell())) {
    164196                    if (current.m_values == end) {
    165197                        m_markSets.removeLast();
     
    168200                    goto findNextUnmarkedNullValue;
    169201                }
    170                
    171                 JSCell* currentCell = v.asCell();
    172                 currentCell->markCellDirect();
    173                 if (currentCell->structure()->typeInfo().type() < CompoundType) {
     202
     203                Heap::markCell(cell);
     204                if (cell->structure()->typeInfo().type() < CompoundType) {
    174205                    if (current.m_values == end) {
    175206                        m_markSets.removeLast();
     
    178209                    goto findNextUnmarkedNullValue;
    179210                }
    180                
     211
    181212                if (current.m_values == end)
    182213                    m_markSets.removeLast();
    183214
    184                 if (currentCell->structure()->typeInfo().hasDefaultMark())
    185                     static_cast<JSObject*>(currentCell)->markChildrenDirect(*this);
    186                 else if (currentCell->vptr() == m_jsArrayVPtr)
    187                     static_cast<JSArray*>(currentCell)->markChildrenDirect(*this);
    188                 else
    189                     currentCell->markChildren(*this);
     215                markChildren(cell);
    190216            }
    191             while (!m_values.isEmpty()) {
    192                 JSCell* current = m_values.removeLast();
    193                 ASSERT(current->marked());
    194                 if (current->structure()->typeInfo().hasDefaultMark())
    195                     static_cast<JSObject*>(current)->markChildrenDirect(*this);
    196                 else if (current->vptr() == m_jsArrayVPtr)
    197                     static_cast<JSArray*>(current)->markChildrenDirect(*this);
    198                 else
    199                     current->markChildren(*this);
    200             }
     217            while (!m_values.isEmpty())
     218                markChildren(m_values.removeLast());
    201219        }
    202220    }
Note: See TracChangeset for help on using the changeset viewer.