src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
changeset 49751 c3a10df652c0
parent 49727 2bbd5117d91a
child 49752 93d84f667d12
equal deleted inserted replaced
49750:bdcfe8154201 49751:c3a10df652c0
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "classfile/metadataOnStackMark.hpp"
    26 #include "classfile/metadataOnStackMark.hpp"
    27 #include "classfile/symbolTable.hpp"
    27 #include "classfile/symbolTable.hpp"
    28 #include "code/codeCache.hpp"
    28 #include "code/codeCache.hpp"
       
    29 #include "gc/g1/g1BarrierSet.hpp"
    29 #include "gc/g1/g1CollectedHeap.inline.hpp"
    30 #include "gc/g1/g1CollectedHeap.inline.hpp"
    30 #include "gc/g1/g1CollectorState.hpp"
    31 #include "gc/g1/g1CollectorState.hpp"
    31 #include "gc/g1/g1ConcurrentMark.inline.hpp"
    32 #include "gc/g1/g1ConcurrentMark.inline.hpp"
    32 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
    33 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
    33 #include "gc/g1/g1HeapVerifier.hpp"
    34 #include "gc/g1/g1HeapVerifier.hpp"
   403     vm_shutdown_during_initialization("Could not create ConcurrentMarkThread");
   404     vm_shutdown_during_initialization("Could not create ConcurrentMarkThread");
   404   }
   405   }
   405 
   406 
   406   assert(CGC_lock != NULL, "CGC_lock must be initialized");
   407   assert(CGC_lock != NULL, "CGC_lock must be initialized");
   407 
   408 
   408   SATBMarkQueueSet& satb_qs = JavaThread::satb_mark_queue_set();
   409   SATBMarkQueueSet& satb_qs = G1BarrierSet::satb_mark_queue_set();
   409   satb_qs.set_buffer_size(G1SATBBufferSize);
   410   satb_qs.set_buffer_size(G1SATBBufferSize);
   410 
   411 
   411   _root_regions.init(_g1h->survivor(), this);
   412   _root_regions.init(_g1h->survivor(), this);
   412 
   413 
   413   if (FLAG_IS_DEFAULT(ConcGCThreads) || ConcGCThreads == 0) {
   414   if (FLAG_IS_DEFAULT(ConcGCThreads) || ConcGCThreads == 0) {
   760   ReferenceProcessor* rp = _g1h->ref_processor_cm();
   761   ReferenceProcessor* rp = _g1h->ref_processor_cm();
   761   // enable ("weak") refs discovery
   762   // enable ("weak") refs discovery
   762   rp->enable_discovery();
   763   rp->enable_discovery();
   763   rp->setup_policy(false); // snapshot the soft ref policy to be used in this cycle
   764   rp->setup_policy(false); // snapshot the soft ref policy to be used in this cycle
   764 
   765 
   765   SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
   766   SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
   766   // This is the start of  the marking cycle, we're expected all
   767   // This is the start of  the marking cycle, we're expected all
   767   // threads to have SATB queues with active set to false.
   768   // threads to have SATB queues with active set to false.
   768   satb_mq_set.set_active_all_threads(true, /* new active value */
   769   satb_mq_set.set_active_all_threads(true, /* new active value */
   769                                      false /* expected_active */);
   770                                      false /* expected_active */);
   770 
   771 
  1071 
  1072 
  1072   bool const mark_finished = !has_overflown();
  1073   bool const mark_finished = !has_overflown();
  1073   if (mark_finished) {
  1074   if (mark_finished) {
  1074     weak_refs_work(false /* clear_all_soft_refs */);
  1075     weak_refs_work(false /* clear_all_soft_refs */);
  1075 
  1076 
  1076     SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
  1077     SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
  1077     // We're done with marking.
  1078     // We're done with marking.
  1078     // This is the end of the marking cycle, we're expected all
  1079     // This is the end of the marking cycle, we're expected all
  1079     // threads to have SATB queues with active set to true.
  1080     // threads to have SATB queues with active set to true.
  1080     satb_mq_set.set_active_all_threads(false, /* new active value */
  1081     satb_mq_set.set_active_all_threads(false, /* new active value */
  1081                                        true /* expected_active */);
  1082                                        true /* expected_active */);
  1693 
  1694 
  1694         jt->satb_mark_queue().apply_closure_and_empty(&_cm_satb_cl);
  1695         jt->satb_mark_queue().apply_closure_and_empty(&_cm_satb_cl);
  1695       }
  1696       }
  1696     } else if (thread->is_VM_thread()) {
  1697     } else if (thread->is_VM_thread()) {
  1697       if (thread->claim_oops_do(true, _thread_parity)) {
  1698       if (thread->claim_oops_do(true, _thread_parity)) {
  1698         JavaThread::satb_mark_queue_set().shared_satb_queue()->apply_closure_and_empty(&_cm_satb_cl);
  1699         G1BarrierSet::satb_mark_queue_set().shared_satb_queue()->apply_closure_and_empty(&_cm_satb_cl);
  1699       }
  1700       }
  1700     }
  1701     }
  1701   }
  1702   }
  1702 };
  1703 };
  1703 
  1704 
  1753     // active_workers will be fewer. The extra ones will just bail out
  1754     // active_workers will be fewer. The extra ones will just bail out
  1754     // immediately.
  1755     // immediately.
  1755     _g1h->workers()->run_task(&remarkTask);
  1756     _g1h->workers()->run_task(&remarkTask);
  1756   }
  1757   }
  1757 
  1758 
  1758   SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
  1759   SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
  1759   guarantee(has_overflown() ||
  1760   guarantee(has_overflown() ||
  1760             satb_mq_set.completed_buffers_num() == 0,
  1761             satb_mq_set.completed_buffers_num() == 0,
  1761             "Invariant: has_overflown = %s, num buffers = " SIZE_FORMAT,
  1762             "Invariant: has_overflown = %s, num buffers = " SIZE_FORMAT,
  1762             BOOL_TO_STR(has_overflown()),
  1763             BOOL_TO_STR(has_overflown()),
  1763             satb_mq_set.completed_buffers_num());
  1764             satb_mq_set.completed_buffers_num());
  1935   }
  1936   }
  1936   _first_overflow_barrier_sync.abort();
  1937   _first_overflow_barrier_sync.abort();
  1937   _second_overflow_barrier_sync.abort();
  1938   _second_overflow_barrier_sync.abort();
  1938   _has_aborted = true;
  1939   _has_aborted = true;
  1939 
  1940 
  1940   SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
  1941   SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
  1941   satb_mq_set.abandon_partial_marking();
  1942   satb_mq_set.abandon_partial_marking();
  1942   // This can be called either during or outside marking, we'll read
  1943   // This can be called either during or outside marking, we'll read
  1943   // the expected_active value from the SATB queue set.
  1944   // the expected_active value from the SATB queue set.
  1944   satb_mq_set.set_active_all_threads(
  1945   satb_mq_set.set_active_all_threads(
  1945                                  false, /* new active value */
  1946                                  false, /* new active value */
  2145     return;
  2146     return;
  2146   }
  2147   }
  2147 
  2148 
  2148   // (6) Finally, we check whether there are enough completed STAB
  2149   // (6) Finally, we check whether there are enough completed STAB
  2149   // buffers available for processing. If there are, we abort.
  2150   // buffers available for processing. If there are, we abort.
  2150   SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
  2151   SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
  2151   if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) {
  2152   if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) {
  2152     // we do need to process SATB buffers, we'll abort and restart
  2153     // we do need to process SATB buffers, we'll abort and restart
  2153     // the marking task to do so
  2154     // the marking task to do so
  2154     set_has_aborted();
  2155     set_has_aborted();
  2155     return;
  2156     return;
  2300   // notices that SATB buffers are available for draining. It'd be
  2301   // notices that SATB buffers are available for draining. It'd be
  2301   // very counter productive if it did that. :-)
  2302   // very counter productive if it did that. :-)
  2302   _draining_satb_buffers = true;
  2303   _draining_satb_buffers = true;
  2303 
  2304 
  2304   G1CMSATBBufferClosure satb_cl(this, _g1h);
  2305   G1CMSATBBufferClosure satb_cl(this, _g1h);
  2305   SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
  2306   SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
  2306 
  2307 
  2307   // This keeps claiming and applying the closure to completed buffers
  2308   // This keeps claiming and applying the closure to completed buffers
  2308   // until we run out of buffers or we need to abort.
  2309   // until we run out of buffers or we need to abort.
  2309   while (!has_aborted() &&
  2310   while (!has_aborted() &&
  2310          satb_mq_set.apply_closure_to_completed_buffer(&satb_cl)) {
  2311          satb_mq_set.apply_closure_to_completed_buffer(&satb_cl)) {