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/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}
Note: See TracChangeset for help on using the changeset viewer.