Changeset 48068 in webkit for trunk/JavaScriptCore/runtime


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.

Location:
trunk/JavaScriptCore/runtime
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r47842 r48068  
    748748            for (size_t block = 0; block < usedPrimaryBlocks; block++) {
    749749                if ((primaryBlocks[block] == blockAddr) & (offset <= lastCellOffset)) {
    750                     if (reinterpret_cast<CollectorCell*>(xAsBits)->u.freeCell.zeroIfFree != 0) {
     750                    if (reinterpret_cast<CollectorCell*>(xAsBits)->u.freeCell.zeroIfFree) {
    751751                        markStack.append(reinterpret_cast<JSCell*>(xAsBits));
    752752                        markStack.drain();
     
    10121012    ProtectCountSet::iterator end = m_protectedValues.end();
    10131013    for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it) {
    1014         JSCell* val = it->first;
    1015         if (!val->marked()) {
    1016             markStack.append(val);
    1017             markStack.drain();
    1018         }
     1014        markStack.append(it->first);
     1015        markStack.drain();
    10191016    }
    10201017
     
    11481145    if (m_markListSet && m_markListSet->size())
    11491146        MarkedArgumentBuffer::markLists(markStack, *m_markListSet);
    1150     if (m_globalData->exception && !m_globalData->exception.marked())
     1147    if (m_globalData->exception)
    11511148        markStack.append(m_globalData->exception);
    11521149    m_globalData->interpreter->registerFile().markCallFrames(markStack, this);
    1153     m_globalData->smallStrings.mark();
     1150    m_globalData->smallStrings.markChildren(markStack);
    11541151    if (m_globalData->functionCodeBlockBeingReparsed)
    11551152        m_globalData->functionCodeBlockBeingReparsed->markAggregate(markStack);
     
    12551252        return "gettersetter";
    12561253    ASSERT(cell->isObject());
    1257     const ClassInfo* info = static_cast<JSObject*>(cell)->classInfo();
     1254    const ClassInfo* info = cell->classInfo();
    12581255    return info ? info->className : "Object";
    12591256}
  • 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    }
  • trunk/JavaScriptCore/runtime/JSCell.h

    r47799 r48068  
    2424#define JSCell_h
    2525
     26#include "Collector.h"
     27#include "JSImmediate.h"
     28#include "JSValue.h"
     29#include "MarkStack.h"
     30#include "Structure.h"
    2631#include <wtf/Noncopyable.h>
    27 #include "Structure.h"
    28 #include "JSValue.h"
    29 #include "JSImmediate.h"
    30 #include "Collector.h"
    3132
    3233namespace JSC {
     
    8889        void* operator new(size_t, void* placementNewDestination) { return placementNewDestination; }
    8990
    90         void markCellDirect();
    9191        virtual void markChildren(MarkStack&);
    92         bool marked() const;
    9392
    9493        // Object operations, with the toObject operation included.
     
    114113    };
    115114
     115    // FIXME: We should deprecate this and just use JSValue::asCell() instead.
    116116    JSCell* asCell(JSValue);
    117117
     
    157157    }
    158158
    159     inline bool JSCell::marked() const
    160     {
    161         return Heap::isCellMarked(this);
    162     }
    163 
    164     inline void JSCell::markCellDirect()
    165     {
    166         Heap::markCell(this);
    167     }
    168 
    169159    inline void JSCell::markChildren(MarkStack&)
    170160    {
    171         ASSERT(marked());
    172161    }
    173162
     
    236225        }
    237226        return false;
    238     }
    239 
    240     inline void JSValue::markDirect()
    241     {
    242         ASSERT(!marked());
    243         asCell()->markCellDirect();
    244     }
    245 
    246     inline void JSValue::markChildren(MarkStack& markStack)
    247     {
    248         ASSERT(marked());
    249         asCell()->markChildren(markStack);
    250     }
    251 
    252     inline bool JSValue::marked() const
    253     {
    254         return !isCell() || asCell()->marked();
    255227    }
    256228
     
    342314        return JSValue();
    343315    }
    344    
    345     inline bool JSValue::hasChildren() const
    346     {
    347         return asCell()->structure()->typeInfo().type() >= CompoundType;
    348     }
    349    
    350316
    351317    inline JSObject* JSValue::toObject(ExecState* exec) const
     
    361327    ALWAYS_INLINE void MarkStack::append(JSCell* cell)
    362328    {
     329        ASSERT(!m_isCheckingForDefaultMarkViolation);
    363330        ASSERT(cell);
    364         if (cell->marked())
     331        if (Heap::isCellMarked(cell))
    365332            return;
    366         cell->markCellDirect();
     333        Heap::markCell(cell);
    367334        if (cell->structure()->typeInfo().type() >= CompoundType)
    368335            m_values.append(cell);
     336    }
     337
     338    ALWAYS_INLINE void MarkStack::append(JSValue value)
     339    {
     340        ASSERT(value);
     341        if (value.isCell())
     342            append(value.asCell());
     343    }
     344
     345    inline void Structure::markAggregate(MarkStack& markStack)
     346    {
     347        markStack.append(m_prototype);
    369348    }
    370349
  • trunk/JavaScriptCore/runtime/JSObject.cpp

    r47780 r48068  
    3939#include <wtf/Assertions.h>
    4040
    41 
    4241namespace JSC {
    4342
     
    4645void JSObject::markChildren(MarkStack& markStack)
    4746{
     47#ifndef NDEBUG
     48    bool wasCheckingForDefaultMarkViolation = markStack.m_isCheckingForDefaultMarkViolation;
     49    markStack.m_isCheckingForDefaultMarkViolation = false;
     50#endif
     51
    4852    markChildrenDirect(markStack);
     53
     54#ifndef NDEBUG
     55    markStack.m_isCheckingForDefaultMarkViolation = wasCheckingForDefaultMarkViolation;
     56#endif
    4957}
    5058
  • trunk/JavaScriptCore/runtime/JSValue.h

    r47288 r48068  
    2121 */
    2222
    23 #include <stddef.h> // for size_t
    24 #include <stdint.h>
    25 
    2623#ifndef JSValue_h
    2724#define JSValue_h
     
    3027#include "ConstructData.h"
    3128#include <math.h>
     29#include <stddef.h> // for size_t
     30#include <stdint.h>
    3231#include <wtf/AlwaysInline.h>
    3332#include <wtf/Assertions.h>
     
    4342    class JSObject;
    4443    class JSString;
    45     class MarkStack;
    4644    class PropertySlot;
    4745    class PutPropertySlot;
     
    172170        // signle precision float is not a representation used in JS or JSC).
    173171        float toFloat(ExecState* exec) const { return static_cast<float>(toNumber(exec)); }
    174 
    175         // Garbage collection.
    176         void markChildren(MarkStack&);
    177         bool hasChildren() const;
    178         bool marked() const;
    179         void markDirect();
    180172
    181173        // Object operations, with the toObject operation included.
  • trunk/JavaScriptCore/runtime/MarkStack.h

    r47267 r48068  
    2828
    2929#include "JSValue.h"
    30 
    3130#include <wtf/Noncopyable.h>
    3231
    3332namespace JSC {
     33
    3434    class JSGlobalData;
    3535    class Register;
     
    4141        MarkStack(void* jsArrayVPtr)
    4242            : m_jsArrayVPtr(jsArrayVPtr)
     43#ifndef NDEBUG
     44            , m_isCheckingForDefaultMarkViolation(false)
     45#endif
    4346        {
    4447        }
    4548
    46         ALWAYS_INLINE void append(JSValue value)
    47         {
    48             ASSERT(value);
    49             if (value.marked())
    50                 return;
    51             value.markDirect();
    52             if (value.hasChildren())
    53                 m_values.append(value.asCell());
    54         }
    55 
    56         ALWAYS_INLINE void append(JSCell* cell);
     49        ALWAYS_INLINE void append(JSValue);
     50        ALWAYS_INLINE void append(JSCell*);
    5751       
    5852        ALWAYS_INLINE void appendValues(Register* values, size_t count, MarkSetProperties properties = NoNullValues)
     
    7771
    7872    private:
     73        void markChildren(JSCell*);
     74
    7975        struct MarkSet {
    8076            MarkSet(JSValue* values, JSValue* end, MarkSetProperties properties)
     
    181177        MarkStackArray<JSCell*> m_values;
    182178        static size_t s_pageSize;
     179
     180#ifndef NDEBUG
     181    public:
     182        bool m_isCheckingForDefaultMarkViolation;
     183#endif
    183184    };
    184185}
  • trunk/JavaScriptCore/runtime/SmallStrings.cpp

    r47022 r48068  
    8383}
    8484
    85 void SmallStrings::mark()
     85void SmallStrings::markChildren(MarkStack& markStack)
    8686{
    87     if (m_emptyString && !m_emptyString->marked())
    88         m_emptyString->markCellDirect();
     87    if (m_emptyString)
     88        markStack.append(m_emptyString);
    8989    for (unsigned i = 0; i < numCharactersToStore; ++i) {
    90         if (m_singleCharacterStrings[i] && !m_singleCharacterStrings[i]->marked())
    91             m_singleCharacterStrings[i]->markCellDirect();
     90        if (m_singleCharacterStrings[i])
     91            markStack.append(m_singleCharacterStrings[i]);
    9292    }
    9393}
  • trunk/JavaScriptCore/runtime/SmallStrings.h

    r45891 r48068  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434    class JSGlobalData;
    3535    class JSString;
    36 
     36    class MarkStack;
    3737    class SmallStringsStorage;
    3838
     
    5757        UString::Rep* singleCharacterStringRep(unsigned char character);
    5858
    59         void mark();
     59        void markChildren(MarkStack&);
    6060
    6161        unsigned count() const;
  • trunk/JavaScriptCore/runtime/Structure.h

    r47605 r48068  
    3030#include "JSType.h"
    3131#include "JSValue.h"
    32 #include "MarkStack.h"
    3332#include "PropertyMapHashTable.h"
    3433#include "StructureChain.h"
     
    4746namespace JSC {
    4847
     48    class MarkStack;
    4949    class PropertyNameArray;
    5050    class PropertyNameArrayData;
     
    7474        ~Structure();
    7575
    76         void markAggregate(MarkStack& markStack)
    77         {
    78             markStack.append(m_prototype);
    79         }
     76        void markAggregate(MarkStack&);
    8077
    8178        // These should be used with caution. 
Note: See TracChangeset for help on using the changeset viewer.