Changeset 1789 in webkit for trunk/JavaScriptCore/kjs


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):
Location:
trunk/JavaScriptCore/kjs
Files:
4 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
  • trunk/JavaScriptCore/kjs/collector.h

    r1126 r1789  
    9393    static int numGCNotAllowedObjects();
    9494    static int numReferencedObjects();
    95     static void lock();
    96     static void unlock();
    9795#endif
    9896  private:
  • trunk/JavaScriptCore/kjs/internal.cpp

    r1623 r1789  
    6868  const double Inf = *(const double*) Inf_Bytes;
    6969};
     70
     71#ifdef APPLE_CHANGES
     72static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT;
     73static pthread_mutex_t interpreterLock;
     74
     75static void initializeInterpreterLock()
     76{
     77  pthread_mutexattr_t attr;
     78
     79  pthread_mutexattr_init(&attr);
     80  pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
     81
     82  pthread_mutex_init(&interpreterLock, &attr);
     83}
     84
     85static inline void lockInterpreter()
     86{
     87  pthread_once(&interpreterLockOnce, initializeInterpreterLock);
     88  pthread_mutex_lock(&interpreterLock);
     89}
     90
     91static inline void unlockInterpreter()
     92{
     93  pthread_mutex_unlock(&interpreterLock);
     94}
     95
     96#endif
     97
    7098
    7199// ------------------------------ UndefinedImp ---------------------------------
     
    689717ProgramNode *Parser::progNode = 0;
    690718int Parser::sid = 0;
    691 #ifdef APPLE_CHANGES
    692 static pthread_mutex_t parserLock = PTHREAD_MUTEX_INITIALIZER;
    693 #endif
    694719
    695720ProgramNode *Parser::parse(const UChar *code, unsigned int length, int *sourceId,
    696721                           int *errLine, UString *errMsg)
    697722{
    698 #ifdef APPLE_CHANGES
    699   pthread_mutex_lock(&parserLock);
    700 #endif
    701723  if (errLine)
    702724    *errLine = -1;
     
    727749#endif
    728750    delete prog;
    729 #ifdef APPLE_CHANGES
    730     pthread_mutex_unlock(&parserLock);
    731 #endif
    732751    return 0;
    733752  }
    734753
    735 #ifdef APPLE_CHANGES
    736   pthread_mutex_unlock(&parserLock);
    737 #endif
    738754  return prog;
    739755}
     
    778794  // as a root set for garbage collection
    779795#ifdef APPLE_CHANGES
    780   Collector::lock();
     796  pthread_mutex_lock(&interpreterLock);
    781797  m_interpreter = interp;
    782798#endif
     
    792808  }
    793809#ifdef APPLE_CHANGES
    794   Collector::unlock();
     810  pthread_mutex_unlock(&interpreterLock);
    795811#endif
    796812
     
    939955  // remove from global chain (see init())
    940956#ifdef APPLE_CHANGES
    941   Collector::lock();
     957  pthread_mutex_lock(&interpreterLock);
    942958#endif
    943959  next->prev = prev;
     
    951967  }
    952968#ifdef APPLE_CHANGES
    953   Collector::unlock();
     969  pthread_mutex_unlock(&interpreterLock);
    954970#endif
    955971}
     
    9891005Completion InterpreterImp::evaluate(const UString &code, const Value &thisV)
    9901006{
     1007#ifdef APPLE_CHANGES
     1008  pthread_mutex_lock(&interpreterLock);
     1009#endif
    9911010  // prevent against infinite recursion
    9921011  if (recursion >= 20) {
     1012#ifdef APPLE_CHANGES
     1013    Completion result = Completion(Throw,Error::create(globExec,GeneralError,"Recursion too deep"));
     1014    pthread_mutex_unlock(&interpreterLock);
     1015    return result;
     1016#else
    9931017    return Completion(Throw,Error::create(globExec,GeneralError,"Recursion too deep"));
     1018#endif
    9941019  }
    9951020
     
    10041029    bool cont = dbg->sourceParsed(globExec,sid,code,errLine);
    10051030    if (!cont)
     1031#ifdef APPLE_CHANGES
     1032      {
     1033        pthread_mutex_unlock(&interpreterLock);
     1034        return Completion(Break);
     1035      }
     1036#else
    10061037      return Completion(Break);
     1038#endif
    10071039  }
    10081040
     
    10111043    Object err = Error::create(globExec,SyntaxError,errMsg.ascii(),errLine);
    10121044    err.put(globExec,"sid",Number(sid));
     1045#ifdef APPLE_CHANGES
     1046    pthread_mutex_unlock(&interpreterLock);
     1047#endif
    10131048    return Completion(Throw,err);
    10141049  }
     
    10531088  recursion--;
    10541089
     1090#ifdef APPLE_CHANGES
     1091    pthread_mutex_unlock(&interpreterLock);
     1092#endif
    10551093  return res;
    10561094}
  • trunk/JavaScriptCore/kjs/value.cpp

    r1623 r1789  
    4242// ----------------------------- ValueImp -------------------------------------
    4343
    44 #if APPLE_CHANGES
    45 ValueImp::ValueImp() :
    46   refcount(0)
    47 {
    48   // Tell the garbage collector that this memory block corresponds to a real object now
    49   Collector::lock();
    50   _flags = VI_CREATED;
    51   //fprintf(stderr,"ValueImp::ValueImp %p\n",(void*)this);
    52   Collector::unlock();
    53 }
    54 #else
    5544ValueImp::ValueImp() :
    5645  refcount(0),
     
    6049  //fprintf(stderr,"ValueImp::ValueImp %p\n",(void*)this);
    6150}
    62 #endif
    6351
    6452ValueImp::~ValueImp()
     
    8169void ValueImp::setGcAllowed()
    8270{
    83 #ifdef APPLE_CHANGES
    84   Collector::lock();
    85 #endif
    8671  //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this);
    8772  _flags |= VI_GCALLOWED;
    88 #ifdef APPLE_CHANGES
    89   Collector::unlock();
    90 #endif
    9173}
    9274
Note: See TracChangeset for help on using the changeset viewer.