Changeset 1126 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- May 10, 2002, 9:41:01 AM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r1112 r1126 30 30 #include <typeinfo> 31 31 #endif 32 #ifdef APPLE_CHANGES 33 #include <pthread.h> 34 #endif 32 35 33 36 namespace KJS { … … 47 50 using namespace KJS; 48 51 52 49 53 CollectorBlock::CollectorBlock(int s) 50 54 : size(s), … … 63 67 } 64 68 69 #ifdef APPLE_CHANGES 70 // FIXME: fix these once static initializers for pthread_cond_t and 71 // pthread_mutex_t are fixed not to warn. 72 static pthread_mutex_t collectorLock = {_PTHREAD_MUTEX_SIG_init, {}}; 73 static pthread_cond_t collectorCondition = {_PTHREAD_COND_SIG_init, {}}; 74 static unsigned collectorLockCount = 0; 75 static pthread_t collectorLockThread; 76 #endif 65 77 CollectorBlock* Collector::root = 0L; 66 78 CollectorBlock* Collector::currentBlock = 0L; … … 81 93 if (s == 0) 82 94 return 0L; 95 96 #ifdef APPLE_CHANGES 97 lock(); 98 #endif 83 99 84 100 // Try and deal with memory requirements in a scalable way. Simple scripts … … 148 164 } 149 165 166 #ifdef APPLE_CHANGES 167 unlock(); 168 #endif 169 150 170 return m; 151 171 } … … 156 176 bool Collector::collect() 157 177 { 178 #ifdef APPLE_CHANGES 179 lock(); 180 #endif 158 181 #ifdef KJS_DEBUG_MEM 159 182 fprintf(stderr,"Collector::collect()\n"); … … 253 276 finalCheck(); 254 277 #endif 278 #ifdef APPLE_CHANGES 279 unlock(); 280 #endif 255 281 return deleted; 256 282 } … … 259 285 void Collector::finalCheck() 260 286 { 287 #ifdef APPLE_CHANGES 288 lock(); 289 #endif 261 290 CollectorBlock *block = root; 262 291 while (block) { … … 274 303 block = block->next; 275 304 } 305 #ifdef APPLE_CHANGES 306 unlock(); 307 #endif 276 308 } 277 309 #endif … … 280 312 int Collector::numInterpreters() 281 313 { 314 lock(); 282 315 int count = 0; 283 316 if (InterpreterImp::s_hook) { … … 288 321 } while (scr != InterpreterImp::s_hook); 289 322 } 323 unlock(); 290 324 return count; 291 325 } … … 293 327 int Collector::numGCNotAllowedObjects() 294 328 { 329 lock(); 295 330 int count = 0; 296 331 CollectorBlock *block = root; … … 307 342 block = block->next; 308 343 } 344 unlock(); 309 345 return count; 310 346 } … … 312 348 int Collector::numReferencedObjects() 313 349 { 350 lock(); 314 351 int count = 0; 315 352 CollectorBlock *block = root; … … 326 363 block = block->next; 327 364 } 365 unlock(); 328 366 return count; 329 367 } 330 #endif 368 369 void Collector::lock() 370 { 371 pthread_mutex_lock(&collectorLock); 372 while (collectorLockCount > 0 && 373 !pthread_equal(pthread_self(), collectorLockThread)) { 374 pthread_cond_wait(&collectorCondition, &collectorLock); 375 } 376 collectorLockThread = pthread_self(); 377 collectorLockCount++; 378 pthread_mutex_unlock(&collectorLock); 379 } 380 381 void Collector::unlock() 382 { 383 pthread_mutex_lock(&collectorLock); 384 collectorLockCount--; 385 if (collectorLockCount == 0) { 386 pthread_cond_signal(&collectorCondition); 387 } 388 pthread_mutex_unlock(&collectorLock); 389 } 390 391 #endif -
trunk/JavaScriptCore/kjs/collector.h
r1112 r1126 93 93 static int numGCNotAllowedObjects(); 94 94 static int numReferencedObjects(); 95 static void lock(); 96 static void unlock(); 95 97 #endif 96 98 private: -
trunk/JavaScriptCore/kjs/internal.cpp
r1024 r1126 689 689 ProgramNode *Parser::progNode = 0; 690 690 int Parser::sid = 0; 691 #ifdef APPLE_CHANGES 692 static pthread_mutex_t parserLock = {_PTHREAD_MUTEX_SIG_init, {}}; 693 #endif 691 694 692 695 ProgramNode *Parser::parse(const UChar *code, unsigned int length, int *sourceId, 693 696 int *errLine, UString *errMsg) 694 697 { 698 #ifdef APPLE_CHANGES 699 pthread_mutex_lock(&parserLock); 700 #endif 695 701 if (errLine) 696 702 *errLine = -1; … … 721 727 #endif 722 728 delete prog; 729 #ifdef APPLE_CHANGES 730 pthread_mutex_unlock(&parserLock); 731 #endif 723 732 return 0; 724 733 } 725 734 735 #ifdef APPLE_CHANGES 736 pthread_mutex_unlock(&parserLock); 737 #endif 726 738 return prog; 727 739 } … … 765 777 // add this interpreter to the global chain 766 778 // as a root set for garbage collection 779 #ifdef APPLE_CHANGES 780 Collector::lock(); 781 #endif 767 782 if (s_hook) { 768 783 prev = s_hook; … … 775 790 globalInit(); 776 791 } 792 #ifdef APPLE_CHANGES 793 Collector::unlock(); 794 #endif 777 795 778 796 m_interpreter = interp; … … 927 945 //fprintf(stderr,"InterpreterImp::clear\n"); 928 946 // remove from global chain (see init()) 947 #ifdef APPLE_CHANGES 948 Collector::lock(); 949 #endif 929 950 next->prev = prev; 930 951 prev->next = next; … … 936 957 globalClear(); 937 958 } 959 #ifdef APPLE_CHANGES 960 Collector::unlock(); 961 #endif 938 962 } 939 963 -
trunk/JavaScriptCore/kjs/ustring.cpp
r1024 r1126 122 122 UString::Rep UString::Rep::null = { 0, 0, 1 }; 123 123 UString UString::null; 124 #ifdef APPLE_CHANGES 125 // FIXME: fix this once static initializers for pthread_once_t 126 pthread_once_t statBufferKeyOnce = {_PTHREAD_ONCE_SIG_init, {}}; 127 pthread_key_t statBufferKey; 128 #else 124 129 static char *statBuffer = 0L; 130 #endif 125 131 126 132 UChar::UChar(const UCharReference &c) … … 278 284 } 279 285 286 #ifdef APPLE_CHANGES 287 static void statBufferKeyCleanup(void *statBuffer) 288 { 289 if (statBuffer != NULL) 290 delete [] (char *)statBuffer; 291 } 292 293 static void statBufferKeyInit(void) 294 { 295 pthread_key_create(&statBufferKey, statBufferKeyCleanup); 296 } 297 #endif 298 280 299 char *UString::ascii() const 281 300 { 301 #ifdef APPLE_CHANGES 302 pthread_once(&statBufferKeyOnce, statBufferKeyInit); 303 char *statBuffer = (char *)pthread_getspecific(statBufferKey); 304 #endif 282 305 if (statBuffer) 283 306 delete [] statBuffer; … … 288 311 statBuffer[size()] = '\0'; 289 312 313 #ifdef APPLE_CHANGES 314 pthread_setspecific(statBufferKey, statBuffer); 315 #endif 290 316 return statBuffer; 291 317 } -
trunk/JavaScriptCore/kjs/value.cpp
r1024 r1126 42 42 // ------------------------------ ValueImp ------------------------------------- 43 43 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 44 55 ValueImp::ValueImp() : 45 56 refcount(0), … … 49 60 //fprintf(stderr,"ValueImp::ValueImp %p\n",(void*)this); 50 61 } 62 #endif 51 63 52 64 ValueImp::~ValueImp() … … 68 80 void ValueImp::setGcAllowed() 69 81 { 82 #ifdef APPLE_CHANGES 83 Collector::lock(); 84 #endif 70 85 //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this); 71 86 _flags |= VI_GCALLOWED; 87 #ifdef APPLE_CHANGES 88 Collector::unlock(); 89 #endif 72 90 } 73 91 -
trunk/JavaScriptCore/kjs/value.h
r1024 r1126 95 95 virtual ~ValueImp(); 96 96 97 #ifdef APPLE_CHANGES 98 // The collecter lock is not locked around the ref() and unref() 99 // methods for the following reasons: 100 // 101 // - The only cases where chaging the refcount could possibly 102 // affect the collector's behavior is incrementing from 0 to 1, 103 // and decrementing from 1 to 0. 104 // 105 // - In the 0 to 1 case, the GC allowed flag will always be off 106 // beforehand, and set right afterwards. And setting it grabs the 107 // collector lock. So if this happens in the middle of GC, the 108 // collector will see either a refcount 0 GC not allowed object, 109 // or a refcount 1 GC not allowed object, and these cases are 110 // treated exactly the same. 111 // 112 // - In the 1 to 0 case, the only possible bad effect is that the 113 // object will live for one GC cycle longer than it should have 114 // to, which is really not so bad. 115 // 116 // - In theory on some platforms increment or decrement could make 117 // other threads see intermediate values that are different from 118 // both the start and end value. If that turns out to really be 119 // the case we will have to reconsider this scheme. 120 #endif 97 121 inline ValueImp* ref() { refcount++; return this; } 98 122 inline bool deref() { return (!--refcount); }
Note:
See TracChangeset
for help on using the changeset viewer.