Changeset 51624 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Dec 2, 2009, 10:25:58 PM (15 years ago)
Author:
[email protected]
Message:

Add zombies to JSC
https://bugs.webkit.org/show_bug.cgi?id=32103

Reviewed by Gavin Barraclough.

Add a compile time flag to make the JSC collector replace "unreachable"
objects with zombie objects. The zombie object is a JSCell subclass that
ASSERTs on any attempt to use the JSCell methods. In addition there are
a number of additional assertions in bottleneck code to catch zombie usage
as quickly as possible.

Grrr. Argh. Brains.

Location:
trunk/JavaScriptCore/runtime
Files:
5 edited

Legend:

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

    r48067 r51624  
    105105        {
    106106            ASSERT(!m_isReadOnly);
    107            
     107
     108#if ENABLE(JSC_ZOMBIES)
     109            ASSERT(!v.isZombie());
     110#endif
     111
    108112            if (m_isUsingInlineBuffer && m_size < inlineCapacity) {
    109113                m_vector.uncheckedAppend(v);
     
    188192            , m_argCount(argCount)
    189193        {
     194#if ENABLE(JSC_ZOMBIES)
     195            for (size_t i = 0; i < argCount; i++)
     196                ASSERT(!m_args[i].isZombie());
     197#endif
    190198        }
    191199       
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r50833 r51624  
    3333#include "JSString.h"
    3434#include "JSValue.h"
     35#include "JSZombie.h"
    3536#include "MarkStack.h"
    3637#include "Nodes.h"
     
    195196    sweep<PrimaryHeap>();
    196197    // No need to sweep number heap, because the JSNumber destructor doesn't do anything.
    197 
     198#if ENABLE(JSC_ZOMBIES)
     199    ASSERT(primaryHeap.numLiveObjects == primaryHeap.numZombies);
     200#else
    198201    ASSERT(!primaryHeap.numLiveObjects);
    199 
     202#endif
    200203    freeBlocks(&primaryHeap);
    201204    freeBlocks(&numberHeap);
     
    10371040                        if (cell->u.freeCell.zeroIfFree == 0)
    10381041                            continue;
    1039                        
     1042#if ENABLE(JSC_ZOMBIES)
     1043                        if (!imp->isZombie()) {
     1044                            const ClassInfo* info = imp->classInfo();
     1045                            imp->~JSCell();
     1046                            new (imp) JSZombie(info, JSZombie::leakedZombieStructure());
     1047                            heap.numZombies++;
     1048                        }
     1049#else
    10401050                        imp->~JSCell();
     1051#endif
    10411052                    }
    1042                    
     1053                    --numLiveObjects;
     1054#if !ENABLE(JSC_ZOMBIES)
    10431055                    --usedCells;
    1044                     --numLiveObjects;
    10451056                   
    10461057                    // put cell on the free list
     
    10481059                    cell->u.freeCell.next = freeList - (cell + 1);
    10491060                    freeList = cell;
     1061#endif
    10501062                }
    10511063            }
     
    10601072                        if (heapType != NumberHeap) {
    10611073                            JSCell* imp = reinterpret_cast<JSCell*>(cell);
     1074#if ENABLE(JSC_ZOMBIES)
     1075                            if (!imp->isZombie()) {
     1076                                const ClassInfo* info = imp->classInfo();
     1077                                imp->~JSCell();
     1078                                new (imp) JSZombie(info, JSZombie::leakedZombieStructure());
     1079                                heap.numZombies++;
     1080                            }
     1081#else
    10621082                            imp->~JSCell();
     1083#endif
    10631084                        }
     1085#if !ENABLE(JSC_ZOMBIES)
    10641086                        --usedCells;
    10651087                        --numLiveObjects;
     
    10691091                        cell->u.freeCell.next = freeList - (cell + 1);
    10701092                        freeList = cell;
     1093#endif
    10711094                    }
    10721095                }
  • trunk/JavaScriptCore/runtime/Collector.h

    r49365 r51624  
    6161        size_t numLiveObjectsAtLastCollect;
    6262        size_t extraCost;
     63#if ENABLE(JSC_ZOMBIES)
     64        size_t numZombies;
     65#endif
    6366
    6467        OperationInProgress operationInProgress;
  • trunk/JavaScriptCore/runtime/JSCell.h

    r49955 r51624  
    4343        friend class JSValue;
    4444        friend class JSAPIValueWrapper;
     45        friend class JSZombie;
    4546        friend struct VPtrSet;
    4647
     
    9192
    9293        virtual void markChildren(MarkStack&);
     94#if ENABLE(JSC_ZOMBIES)
     95        virtual bool isZombie() const { return false; }
     96#endif
    9397
    9498        // Object operations, with the toObject operation included.
     
    343347        return cellBlock(c)->heap;
    344348    }
    345 
     349   
     350#if ENABLE(JSC_ZOMBIES)
     351    inline bool JSValue::isZombie() const
     352    {
     353        return isCell() && asCell() && asCell()->isZombie();
     354    }
     355#endif
    346356} // namespace JSC
    347357
  • trunk/JavaScriptCore/runtime/JSValue.h

    r51334 r51624  
    169169        uint32_t toUInt32(ExecState*, bool& ok) const;
    170170
     171#if ENABLE(JSC_ZOMBIES)
     172        bool isZombie() const;
     173#endif
     174
    171175        // Floating point conversions (this is a convenience method for webcore;
    172176        // signle precision float is not a representation used in JS or JSC).
     
    439443        JSValue v;
    440444        v.u.asEncodedJSValue = encodedJSValue;
     445#if ENABLE(JSC_ZOMBIES)
     446        ASSERT(!v.isZombie());
     447#endif
    441448        return v;
    442449    }
     
    485492            u.asBits.tag = EmptyValueTag;
    486493        u.asBits.payload = reinterpret_cast<int32_t>(ptr);
     494#if ENABLE(JSC_ZOMBIES)
     495        ASSERT(!isZombie());
     496#endif
    487497    }
    488498
     
    494504            u.asBits.tag = EmptyValueTag;
    495505        u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
     506#if ENABLE(JSC_ZOMBIES)
     507        ASSERT(!isZombie());
     508#endif
    496509    }
    497510
     
    794807        : m_ptr(ptr)
    795808    {
     809#if ENABLE(JSC_ZOMBIES)
     810        ASSERT(!isZombie());
     811#endif
    796812    }
    797813
     
    799815        : m_ptr(const_cast<JSCell*>(ptr))
    800816    {
     817#if ENABLE(JSC_ZOMBIES)
     818        ASSERT(!isZombie());
     819#endif
    801820    }
    802821
Note: See TracChangeset for help on using the changeset viewer.