Ignore:
Timestamp:
Nov 29, 2007, 7:02:08 PM (18 years ago)
Author:
[email protected]
Message:

Make the JS collector work with multiple threads

Reviewed by Maciej and Darin.

Under heavy contention it was possible the GC to suspend other
threads inside the pthread spinlock, which could lead to the GC
thread blocking on the pthread spinlock itself.

We now determine and store each thread's stack base when it is
registered, thus removing the need for any calls to pthread_get_stackaddr_np
that needed the pthread spinlock.

File:
1 edited

Legend:

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

    r28110 r28223  
    409409class Collector::Thread {
    410410public:
    411   Thread(pthread_t pthread, const PlatformThread& platThread) : posixThread(pthread), platformThread(platThread) {}
     411  Thread(pthread_t pthread, const PlatformThread& platThread, void* base)
     412  : posixThread(pthread), platformThread(platThread), stackBase(base) {}
    412413  Thread* next;
    413414  pthread_t posixThread;
    414415  PlatformThread platformThread;
     416  void* stackBase;
    415417};
    416418
     
    465467#endif
    466468
    467     Collector::Thread *thread = new Collector::Thread(pthread_self(), getCurrentPlatformThread());
     469    Collector::Thread *thread = new Collector::Thread(pthread_self(), getCurrentPlatformThread(), currentThreadStackBase());
    468470
    469471    thread->next = registeredThreads;
     
    676678}
    677679
    678 static inline void* otherThreadStackBase(const PlatformThreadRegisters& regs, Collector::Thread* thread)
    679 {
    680 #if PLATFORM(DARWIN)
    681   (void)regs;
    682   return pthread_get_stackaddr_np(thread->posixThread);
    683 // end PLATFORM(DARWIN);
    684 #elif PLATFORM(X86) && PLATFORM(WIN_OS)
    685   LDT_ENTRY desc;
    686   NT_TIB* tib;
    687   GetThreadSelectorEntry(thread->platformThread.handle, regs.SegFs, &desc);
    688   tib = (NT_TIB*)(uintptr_t)(desc.BaseLow | desc.HighWord.Bytes.BaseMid << 16 | desc.HighWord.Bytes.BaseHi << 24);
    689   ASSERT(tib == tib->Self);
    690   return tib->StackBase;
    691 #else
    692 #error Need a way to get the stack pointer for another thread on this platform
    693 #endif
    694 }
    695 
    696680void Collector::markOtherThreadConservatively(Thread* thread)
    697681{
     
    705689 
    706690  void* stackPointer = otherThreadStackPointer(regs);
    707   void* stackBase = otherThreadStackBase(regs, thread);
    708   markStackObjectsConservatively(stackPointer, stackBase);
     691  markStackObjectsConservatively(stackPointer, thread->stackBase);
    709692
    710693  resumeThread(thread->platformThread);
Note: See TracChangeset for help on using the changeset viewer.