src/hotspot/share/gc/shared/barrierSet.cpp
changeset 52955 f0f3dc30e3bb
parent 51600 56309b1b9d9b
equal deleted inserted replaced
52954:799e964e32b6 52955:f0f3dc30e3bb
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "gc/shared/barrierSet.hpp"
    26 #include "gc/shared/barrierSet.hpp"
    27 #include "gc/shared/barrierSetAssembler.hpp"
    27 #include "gc/shared/barrierSetAssembler.hpp"
    28 #include "runtime/thread.hpp"
    28 #include "runtime/thread.hpp"
       
    29 #include "utilities/debug.hpp"
    29 #include "utilities/macros.hpp"
    30 #include "utilities/macros.hpp"
    30 
    31 
    31 BarrierSet* BarrierSet::_barrier_set = NULL;
    32 BarrierSet* BarrierSet::_barrier_set = NULL;
    32 
       
    33 class SetBarrierSetNonJavaThread : public ThreadClosure {
       
    34   BarrierSet* _barrier_set;
       
    35   size_t _count;
       
    36 
       
    37 public:
       
    38   SetBarrierSetNonJavaThread(BarrierSet* barrier_set) :
       
    39     _barrier_set(barrier_set), _count(0) {}
       
    40 
       
    41   virtual void do_thread(Thread* thread) {
       
    42     _barrier_set->on_thread_create(thread);
       
    43     ++_count;
       
    44   }
       
    45 
       
    46   size_t count() const { return _count; }
       
    47 };
       
    48 
    33 
    49 void BarrierSet::set_barrier_set(BarrierSet* barrier_set) {
    34 void BarrierSet::set_barrier_set(BarrierSet* barrier_set) {
    50   assert(_barrier_set == NULL, "Already initialized");
    35   assert(_barrier_set == NULL, "Already initialized");
    51   _barrier_set = barrier_set;
    36   _barrier_set = barrier_set;
    52 
    37 
    53   // Some threads are created before the barrier set, so the call to
    38   // Notify barrier set of the current (main) thread.  Normally the
    54   // BarrierSet::on_thread_create had to be deferred for them.  Now that
    39   // Thread constructor deals with this, but the main thread is
    55   // we have the barrier set, do those deferred calls.
    40   // created before we get here.  Verify it isn't yet on the thread
    56 
       
    57   // First do any non-JavaThreads.
       
    58   SetBarrierSetNonJavaThread njt_closure(_barrier_set);
       
    59   Threads::non_java_threads_do(&njt_closure);
       
    60 
       
    61   // Do the current (main) thread.  Ensure it's the one and only
       
    62   // JavaThread so far.  Also verify that it isn't yet on the thread
       
    63   // list, else we'd also need to call BarrierSet::on_thread_attach.
    41   // list, else we'd also need to call BarrierSet::on_thread_attach.
       
    42   // This is the only thread that can exist at this point; the Thread
       
    43   // constructor objects to other threads being created before the
       
    44   // barrier set is available.
    64   assert(Thread::current()->is_Java_thread(),
    45   assert(Thread::current()->is_Java_thread(),
    65          "Expected main thread to be a JavaThread");
    46          "Expected main thread to be a JavaThread");
    66   assert((njt_closure.count() + 1) == Threads::threads_before_barrier_set(),
       
    67          "Unexpected JavaThreads before barrier set initialization: "
       
    68          "Non-JavaThreads: " SIZE_FORMAT ", all: " SIZE_FORMAT,
       
    69          njt_closure.count(), Threads::threads_before_barrier_set());
       
    70   assert(!JavaThread::current()->on_thread_list(),
    47   assert(!JavaThread::current()->on_thread_list(),
    71          "Main thread already on thread list.");
    48          "Main thread already on thread list.");
    72   _barrier_set->on_thread_create(Thread::current());
    49   _barrier_set->on_thread_create(Thread::current());
    73 }
    50 }
    74 
    51