src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.cpp
changeset 49007 82d9d5744e5f
parent 48961 120b61d50f85
child 49164 7e958a8ebcd3
equal deleted inserted replaced
49006:c6d1c4ad90f4 49007:82d9d5744e5f
   218 bool G1SATBCardTableModRefBS::is_in_young(oop obj) const {
   218 bool G1SATBCardTableModRefBS::is_in_young(oop obj) const {
   219   volatile jbyte* p = byte_for((void*)obj);
   219   volatile jbyte* p = byte_for((void*)obj);
   220   return *p == g1_young_card_val();
   220   return *p == g1_young_card_val();
   221 }
   221 }
   222 
   222 
   223 void G1SATBCardTableLoggingModRefBS::flush_deferred_barriers(JavaThread* thread) {
   223 void G1SATBCardTableLoggingModRefBS::on_thread_attach(JavaThread* thread) {
   224   CardTableModRefBS::flush_deferred_barriers(thread);
   224   // This method initializes the SATB and dirty card queues before a
       
   225   // JavaThread is added to the Java thread list. Right now, we don't
       
   226   // have to do anything to the dirty card queue (it should have been
       
   227   // activated when the thread was created), but we have to activate
       
   228   // the SATB queue if the thread is created while a marking cycle is
       
   229   // in progress. The activation / de-activation of the SATB queues at
       
   230   // the beginning / end of a marking cycle is done during safepoints
       
   231   // so we have to make sure this method is called outside one to be
       
   232   // able to safely read the active field of the SATB queue set. Right
       
   233   // now, it is called just before the thread is added to the Java
       
   234   // thread list in the Threads::add() method. That method is holding
       
   235   // the Threads_lock which ensures we are outside a safepoint. We
       
   236   // cannot do the obvious and set the active field of the SATB queue
       
   237   // when the thread is created given that, in some cases, safepoints
       
   238   // might happen between the JavaThread constructor being called and the
       
   239   // thread being added to the Java thread list (an example of this is
       
   240   // when the structure for the DestroyJavaVM thread is created).
       
   241   assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");
       
   242   assert(!thread->satb_mark_queue().is_active(), "SATB queue should not be active");
       
   243   assert(thread->satb_mark_queue().is_empty(), "SATB queue should be empty");
       
   244   assert(thread->dirty_card_queue().is_active(), "Dirty card queue should be active");
       
   245 
       
   246   // If we are creating the thread during a marking cycle, we should
       
   247   // set the active field of the SATB queue to true.
       
   248   if (thread->satb_mark_queue_set().is_active()) {
       
   249     thread->satb_mark_queue().set_active(true);
       
   250   }
       
   251 }
       
   252 
       
   253 void G1SATBCardTableLoggingModRefBS::on_thread_detach(JavaThread* thread) {
       
   254   // Flush any deferred card marks, SATB buffers and dirty card queue buffers
       
   255   CardTableModRefBS::on_thread_detach(thread);
   225   thread->satb_mark_queue().flush();
   256   thread->satb_mark_queue().flush();
   226   thread->dirty_card_queue().flush();
   257   thread->dirty_card_queue().flush();
   227 }
   258 }