Ignore:
Timestamp:
Aug 9, 2002, 4:24:41 PM (23 years ago)
Author:
mjs
Message:
  • fixed 2948835 - JavaScriptCore locking is too fine grained, makes it too slow
  • kjs/collector.cpp: (Collector::allocate): (Collector::collect): (Collector::finalCheck): (Collector::numInterpreters): (Collector::numGCNotAllowedObjects): (Collector::numReferencedObjects):
  • kjs/collector.h:
  • kjs/internal.cpp: (initializeInterpreterLock): (lockInterpreter): (unlockInterpreter): (Parser::parse): (InterpreterImp::InterpreterImp): (InterpreterImp::clear): (InterpreterImp::evaluate):
  • kjs/value.cpp: (ValueImp::ValueImp): (ValueImp::setGcAllowed):
File:
1 edited

Legend:

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

    r1371 r1789  
    6767}
    6868
    69 #ifdef APPLE_CHANGES
    70 static pthread_mutex_t collectorLock = PTHREAD_MUTEX_INITIALIZER;
    71 static pthread_cond_t collectorCondition = PTHREAD_COND_INITIALIZER;
    72 static unsigned collectorLockCount = 0;
    73 static pthread_t collectorLockThread;
    74 #endif
    7569CollectorBlock* Collector::root = 0L;
    7670CollectorBlock* Collector::currentBlock = 0L;
     
    9185  if (s == 0)
    9286    return 0L;
    93 
    94 #ifdef APPLE_CHANGES
    95   lock();
    96 #endif
    9787
    9888  // Try and deal with memory requirements in a scalable way. Simple scripts
     
    162152  }
    163153
    164 #ifdef APPLE_CHANGES
    165   unlock();
    166 #endif
    167 
    168154  return m;
    169155}
     
    174160bool Collector::collect()
    175161{
    176 #ifdef APPLE_CHANGES
    177   lock();
    178 #endif
    179162#ifdef KJS_DEBUG_MEM
    180163  fprintf(stderr,"Collector::collect()\n");
     
    287270    finalCheck();
    288271#endif
    289 #ifdef APPLE_CHANGES
    290   unlock();
    291 #endif
    292272  return deleted;
    293273}
     
    296276void Collector::finalCheck()
    297277{
    298 #ifdef APPLE_CHANGES
    299   lock();
    300 #endif
    301278  CollectorBlock *block = root;
    302279  while (block) {
     
    314291    block = block->next;
    315292  }
    316 #ifdef APPLE_CHANGES
    317   unlock();
    318 #endif
    319293}
    320294#endif
     
    323297int Collector::numInterpreters()
    324298{
    325   lock();
    326299  int count = 0;
    327300  if (InterpreterImp::s_hook) {
     
    332305    } while (scr != InterpreterImp::s_hook);
    333306  }
    334   unlock();
    335307  return count;
    336308}
     
    338310int Collector::numGCNotAllowedObjects()
    339311{
    340   lock();
    341312  int count = 0;
    342313  CollectorBlock *block = root;
     
    353324    block = block->next;
    354325  }
    355   unlock();
    356326  return count;
    357327}
     
    359329int Collector::numReferencedObjects()
    360330{
    361   lock();
    362331  int count = 0;
    363332  CollectorBlock *block = root;
     
    374343    block = block->next;
    375344  }
    376   unlock();
    377345  return count;
    378346}
    379347
    380 void Collector::lock()
    381 {
    382   pthread_mutex_lock(&collectorLock);
    383   while (collectorLockCount > 0 &&
    384          !pthread_equal(pthread_self(), collectorLockThread)) {
    385     pthread_cond_wait(&collectorCondition, &collectorLock);
    386   }
    387   collectorLockThread = pthread_self();
    388   collectorLockCount++;
    389   pthread_mutex_unlock(&collectorLock);
    390 }
    391 
    392 void Collector::unlock()
    393 {
    394   pthread_mutex_lock(&collectorLock);
    395   collectorLockCount--;
    396   if (collectorLockCount == 0) {
    397     pthread_cond_signal(&collectorCondition);
    398   }
    399   pthread_mutex_unlock(&collectorLock);
    400 }
    401 
    402 #endif
     348#endif
Note: See TracChangeset for help on using the changeset viewer.