Changeset 18888 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Jan 16, 2007, 1:07:54 PM (18 years ago)
Author:
ggaren
Message:

Reviewed by Darin Adler.


Added re-entrency checking to GC allocation and collection. It is an error
to allocate or collect from within a collection. We've had at least one
case of each bug in the past.


Added a comment to the API header, explaining that API clients must not
make this mistake, either.


Layout tests and JS tests pass.

  • API/JSObjectRef.h:
  • kjs/collector.cpp: (KJS::GCLock::GCLock): (KJS::GCLock::~GCLock): (KJS::Collector::allocate): (KJS::Collector::collect):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/collector.cpp

    r18811 r18888  
    111111bool Collector::memoryFull = false;
    112112
     113#ifndef NDEBUG
     114class GCLock {
     115    static bool isLocked;
     116
     117public:
     118    GCLock()
     119    {
     120        ASSERT(!isLocked);
     121        isLocked = true;
     122    }
     123   
     124    ~GCLock()
     125    {
     126        ASSERT(isLocked);
     127        isLocked = false;
     128    }
     129};
     130
     131bool GCLock::isLocked = false;
     132#endif
     133
    113134void* Collector::allocate(size_t s)
    114135{
     
    124145    numLiveObjects = heap.numLiveObjects;
    125146  }
     147 
     148#ifndef NDEBUG
     149  GCLock lock;
     150#endif
    126151 
    127152  if (s > CELL_SIZE) {
     
    463488  assert(JSLock::lockCount() > 0);
    464489
     490#ifndef NDEBUG
     491  GCLock lock;
     492#endif
     493 
    465494#if USE(MULTIPLE_THREADS)
    466495    bool currentThreadIsMainThread = !pthread_is_threaded_np() || pthread_main_np();
Note: See TracChangeset for help on using the changeset viewer.