Changeset 64655 in webkit


Ignore:
Timestamp:
Aug 4, 2010 10:18:07 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-08-04 Nathan Lawrence <nlawrence@apple.com>

Reviewed by Darin Adler.

Refactoring MarkStack::append to take a reference. This is in
preparation for movable objects when we will need to update pointers.
http://bugs.webkit.org/show_bug.cgi?id=41177

Unless otherwise noted, all changes are to either return by reference
or pass a reference to MarkStack::append.

  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::markAggregate):
  • runtime/Collector.cpp: (JSC::Heap::markConservatively):

Added a temporary variable to prevent marking from changing an
unknown value on the stack

  • runtime/JSCell.h: (JSC::JSValue::asCell): (JSC::MarkStack::append): (JSC::MarkStack::appendInternal):
  • runtime/JSGlobalObject.cpp: (JSC::markIfNeeded):
  • runtime/JSONObject.cpp: (JSC::Stringifier::Holder::object):
  • runtime/JSObject.h: (JSC::JSObject::prototype):
  • runtime/JSStaticScopeObject.cpp: (JSC::JSStaticScopeObject::markChildren):
  • runtime/JSValue.h: (JSC::JSValue::JSValue): (JSC::JSValue::asCell):
  • runtime/MarkStack.h:
  • runtime/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::createStructure):

Changed the structure flags to include a custom markChildren.

(JSC::NativeErrorConstructor::markChildren):

Update the prototype of the stored structure.

  • runtime/NativeErrorConstructor.h:

Added structure flags.

  • runtime/Structure.h: (JSC::Structure::storedPrototype):

2010-08-04 Nathan Lawrence <nlawrence@apple.com>

Reviewed by Darin Adler.

Removed unneeded marking. We need to remove this marking in order to have
MarkStack::append take references for updating movable objects.

https://bugs.webkit.org/show_bug.cgi?id=41177

  • JSValueWrapper.cpp: (JSValueWrapper::JSObjectMark):
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r64649 r64655  
     12010-08-04  Nathan Lawrence  <nlawrence@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Refactoring MarkStack::append to take a reference.  This is in
     6        preparation for movable objects when we will need to update pointers.
     7        http://bugs.webkit.org/show_bug.cgi?id=41177
     8
     9        Unless otherwise noted, all changes are to either return by reference
     10        or pass a reference to MarkStack::append.
     11
     12        * bytecode/CodeBlock.cpp:
     13        (JSC::CodeBlock::markAggregate):
     14        * runtime/Collector.cpp:
     15        (JSC::Heap::markConservatively):
     16            Added a temporary variable to prevent marking from changing an
     17            unknown value on the stack
     18        * runtime/JSCell.h:
     19        (JSC::JSValue::asCell):
     20        (JSC::MarkStack::append):
     21        (JSC::MarkStack::appendInternal):
     22        * runtime/JSGlobalObject.cpp:
     23        (JSC::markIfNeeded):
     24        * runtime/JSONObject.cpp:
     25        (JSC::Stringifier::Holder::object):
     26        * runtime/JSObject.h:
     27        (JSC::JSObject::prototype):
     28        * runtime/JSStaticScopeObject.cpp:
     29        (JSC::JSStaticScopeObject::markChildren):
     30        * runtime/JSValue.h:
     31        (JSC::JSValue::JSValue):
     32        (JSC::JSValue::asCell):
     33        * runtime/MarkStack.h:
     34        * runtime/NativeErrorConstructor.cpp:
     35        (JSC::NativeErrorConstructor::createStructure):
     36            Changed the structure flags to include a custom markChildren.
     37        (JSC::NativeErrorConstructor::markChildren):
     38            Update the prototype of the stored structure.
     39        * runtime/NativeErrorConstructor.h:
     40            Added structure flags.
     41        * runtime/Structure.h:
     42        (JSC::Structure::storedPrototype):
     43
    1442010-08-03  Nathan Lawrence  <nlawrence@apple.com>
    245
  • trunk/JavaScriptCore/bytecode/CodeBlock.cpp

    r63449 r64655  
    15141514{
    15151515    for (size_t i = 0; i < m_constantRegisters.size(); ++i)
    1516         markStack.append(m_constantRegisters[i].jsValue());
     1516        markStack.append(m_constantRegisters[i]);
    15171517    for (size_t i = 0; i < m_functionExprs.size(); ++i)
    15181518        m_functionExprs[i]->markAggregate(markStack);
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r64624 r64655  
    692692                if (m_heap.collectorBlock(block) != blockAddr)
    693693                    continue;
    694                 markStack.append(reinterpret_cast<JSCell*>(xAsBits));
     694                // While markStack.append normally takes a reference to update,
     695                // we don't actually want the heap to be updated since we don't
     696                // know for sure that it's actually a pointer. In the future
     697                // this will be replaced by some appendRoot function for this
     698                // specific case.
     699                JSCell* cell = reinterpret_cast<JSCell*>(xAsBits);
     700                markStack.append(cell);
    695701                markStack.drain();
    696702            }
  • trunk/JavaScriptCore/runtime/JSCell.h

    r60631 r64655  
    3636
    3737    class JSCell : public NoncopyableCustomAllocated {
     38        friend class CollectorHeap;
    3839        friend class GetterSetter;
    3940        friend class Heap;
     
    238239
    239240#if !USE(JSVALUE32_64)
    240     ALWAYS_INLINE JSCell* JSValue::asCell() const
     241    ALWAYS_INLINE JSCell*& JSValue::asCell()
     242    {
     243        ASSERT(isCell());
     244        return m_ptr;
     245    }
     246
     247    ALWAYS_INLINE JSCell* const& JSValue::asCell() const
    241248    {
    242249        ASSERT(isCell());
     
    330337    }
    331338
    332     ALWAYS_INLINE void MarkStack::append(JSCell* cell)
     339    template<typename T>
     340    ALWAYS_INLINE void MarkStack::append(T*& cell)
     341    {
     342        // References in C++ are not covariant.  JSObject* being a subtype of JSCell*
     343        // does not mean that JSObject*& can be used as a subtype of JSCell*& because
     344        // treating a JSObject*& as a JSCell*& would allow us to change the pointer to
     345        // point to something that is a JSCell but not a JSObject.
     346        //
     347        // In this case, we need to be able to change the pointer, and although we know
     348        // it to be safe, C++ doesn't, requiring us to use templated functions that
     349        // pass a casted version to an internal function.
     350        //
     351        // Currently we're not doing anything with the value of the pointer, so nothing
     352        // unsafe will happen.  In the future, when we have movable objects, we will be
     353        // changing the value of the pointer to be the new location, in which case the
     354        // type will be preserved.
     355        JSCell*& ptr = *reinterpret_cast<JSCell**>(&cell);
     356        appendInternal(ptr);
     357    }
     358
     359    ALWAYS_INLINE void MarkStack::append(JSValue& value)
     360    {
     361        ASSERT(value);
     362        if (value.isCell())
     363            appendInternal(value.asCell());
     364    }
     365
     366    ALWAYS_INLINE void MarkStack::append(Register& reg)
     367    {
     368        JSValue value = reg.jsValue();
     369        append(value);
     370        reg = value;
     371    }
     372
     373    inline void MarkStack::appendInternal(JSCell*& cell)
    333374    {
    334375        ASSERT(!m_isCheckingForDefaultMarkViolation);
     
    341382    }
    342383
    343     ALWAYS_INLINE void MarkStack::append(JSValue value)
    344     {
    345         ASSERT(value);
    346         if (value.isCell())
    347             append(value.asCell());
    348     }
    349 
    350384    inline Heap* Heap::heap(JSValue v)
    351385    {
  • trunk/JavaScriptCore/runtime/JSGlobalObject.cpp

    r63882 r64655  
    8181static const int preferredScriptCheckTimeInterval = 1000;
    8282
    83 static inline void markIfNeeded(MarkStack& markStack, JSValue v)
     83template<typename T> static inline void markIfNeeded(MarkStack& markStack, T*& v)
    8484{
    8585    if (v)
     
    8787}
    8888
    89 static inline void markIfNeeded(MarkStack& markStack, const RefPtr<Structure>& s)
     89static inline void markIfNeeded(MarkStack& markStack, RefPtr<Structure>& s)
    9090{
    9191    if (s)
    92         markIfNeeded(markStack, s->storedPrototype());
     92        markStack.append(s->storedPrototype());
    9393}
    9494
  • trunk/JavaScriptCore/runtime/JSONObject.cpp

    r60762 r64655  
    8383        Holder(JSObject*);
    8484
    85         JSObject* object() const { return m_object; }
     85        JSObject*& object() { return m_object; }
     86        JSObject* const& object() const { return m_object; }
    8687
    8788        bool appendNextProperty(Stringifier&, StringBuilder&);
    8889
    8990    private:
    90         JSObject* const m_object;
     91        JSObject* m_object;
    9192        const bool m_isArray;
    9293        bool m_isJSArray;
  • trunk/JavaScriptCore/runtime/JSObject.h

    r62896 r64655  
    8787        virtual ~JSObject();
    8888
    89         JSValue prototype() const;
     89        JSValue& prototype();
     90        const JSValue& prototype() const;
    9091        void setPrototype(JSValue prototype);
    9192        bool setPrototypeWithCycleCheck(JSValue prototype);
     
    313314}
    314315
    315 inline JSValue JSObject::prototype() const
     316inline JSValue& JSObject::prototype()
     317{
     318    return m_structure->storedPrototype();
     319}
     320
     321inline const JSValue& JSObject::prototype() const
    316322{
    317323    return m_structure->storedPrototype();
  • trunk/JavaScriptCore/runtime/JSStaticScopeObject.cpp

    r58986 r64655  
    3535{
    3636    JSVariableObject::markChildren(markStack);
    37     markStack.append(d()->registerStore.jsValue());
     37    markStack.append(d()->registerStore);
    3838}
    3939
  • trunk/JavaScriptCore/runtime/JSValue.h

    r62896 r64655  
    200200
    201201        bool isCell() const;
    202         JSCell* asCell() const;
     202        JSCell*& asCell();
     203        JSCell* const& asCell() const;
    203204        bool isValidCallee();
    204205
     
    241242                int32_t payload;
    242243            } asBits;
     244            struct {
     245                int32_t tag;
     246                JSCell* ptr;
     247            } asPtr;
    243248#else
    244249            struct {
     
    246251                int32_t tag;
    247252            } asBits;
     253            struct {
     254                JSCell* ptr;
     255                int32_t tag;
     256            } asPtr;
    248257#endif
    249258        } u;
     
    492501        else
    493502            u.asBits.tag = EmptyValueTag;
    494         u.asBits.payload = reinterpret_cast<int32_t>(ptr);
     503        u.asPtr.ptr = ptr;
    495504#if ENABLE(JSC_ZOMBIES)
    496505        ASSERT(!isZombie());
     
    504513        else
    505514            u.asBits.tag = EmptyValueTag;
    506         u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
     515        u.asPtr.ptr = const_cast<JSCell*>(ptr);
    507516#if ENABLE(JSC_ZOMBIES)
    508517        ASSERT(!isZombie());
     
    599608    }
    600609   
    601     ALWAYS_INLINE JSCell* JSValue::asCell() const
     610    ALWAYS_INLINE JSCell* const& JSValue::asCell() const
    602611    {
    603612        ASSERT(isCell());
    604         return reinterpret_cast<JSCell*>(u.asBits.payload);
     613        return u.asPtr.ptr;
     614    }
     615
     616    ALWAYS_INLINE JSCell*& JSValue::asCell()
     617    {
     618        ASSERT(isCell());
     619        return u.asPtr.ptr;
    605620    }
    606621
  • trunk/JavaScriptCore/runtime/MarkStack.h

    r53922 r64655  
    4747        }
    4848
    49         ALWAYS_INLINE void append(JSValue);
    50         void append(JSCell*);
     49        template<typename T> ALWAYS_INLINE void append(T*& cell);
     50        ALWAYS_INLINE void append(JSValue&);
     51        ALWAYS_INLINE void append(Register&);
    5152       
    5253        ALWAYS_INLINE void appendValues(Register* values, size_t count, MarkSetProperties properties = NoNullValues)
     
    7172
    7273    private:
     74        void appendInternal(JSCell*&);
     75
    7376        void markChildren(JSCell*);
    7477
  • trunk/JavaScriptCore/runtime/NativeErrorConstructor.cpp

    r60762 r64655  
    6969}
    7070
     71PassRefPtr<Structure> NativeErrorConstructor::createStructure(JSObject* prototype)
     72{
     73    return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
     74}
     75
     76void NativeErrorConstructor::markChildren(MarkStack& markStack)
     77{
     78    InternalFunction::markChildren(markStack);
     79
     80    markStack.append(m_errorStructure->storedPrototype());
     81}
     82
    7183} // namespace JSC
  • trunk/JavaScriptCore/runtime/NativeErrorConstructor.h

    r60762 r64655  
    3737
    3838        Structure* errorStructure() { return m_errorStructure.get(); }
     39        static PassRefPtr<Structure> createStructure(JSObject* prototype);
     40
     41    protected:
     42        static const unsigned StructureFlags = InternalFunction::StructureFlags | OverridesMarkChildren;
    3943
    4044    private:
    4145        virtual ConstructType getConstructData(ConstructData&);
    4246        virtual CallType getCallData(CallData&);
     47
     48        virtual void markChildren(MarkStack&);
    4349
    4450        virtual const ClassInfo* classInfo() const { return &info; }
  • trunk/JavaScriptCore/runtime/Structure.h

    r54798 r64655  
    9595        const TypeInfo& typeInfo() const { return m_typeInfo; }
    9696
    97         JSValue storedPrototype() const { return m_prototype; }
     97        const JSValue& storedPrototype() const { return m_prototype; }
     98        JSValue& storedPrototype() { return m_prototype; }
    9899        JSValue prototypeForLookup(ExecState*) const;
    99100        StructureChain* prototypeChain(ExecState*) const;
  • trunk/JavaScriptGlue/ChangeLog

    r64626 r64655  
     12010-08-04  Nathan Lawrence  <nlawrence@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Removed unneeded marking.  We need to remove this marking in order to have
     6        MarkStack::append take references for updating movable objects.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=41177
     9
     10        * JSValueWrapper.cpp:
     11        (JSValueWrapper::JSObjectMark):
     12
    1132010-08-03  Gavin Barraclough  <barraclough@apple.com>
    214
  • trunk/JavaScriptGlue/JSValueWrapper.cpp

    r52856 r64655  
    193193}
    194194
    195 void JSValueWrapper::JSObjectMark(void *data)
    196 {
    197     JSValueWrapper* ptr = (JSValueWrapper*)data;
    198     if (ptr)
    199     {
    200         // This results in recursive marking but will be otherwise safe and correct.
    201         // We claim the array vptr is 0 because we don't have access to it here, and
    202         // claiming 0 is functionally harmless -- it merely means that we can't
    203         // devirtualise marking of arrays when recursing from this point.
    204         MarkStack markStack(0);
    205         markStack.append(ptr->fValue.get());
    206         markStack.drain();
    207     }
    208 }
     195void JSValueWrapper::JSObjectMark(void*)
     196{
     197    // The object doesn't need to be marked here because it is a protected
     198    // object and should therefore be marked by
     199    // JSC::Heap::markProtectedObjects.
     200
     201    // We are keeping the function around because the function is passed as a
     202    // callback.
     203}
Note: See TracChangeset for help on using the changeset viewer.