< prev index next >

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Print this page
rev 60637 : 8252141: Rename G1YoungRemSetSamplingThread to better reflect its purpose
Reviewed-by:


  46 #include "gc/g1/g1HeapSizingPolicy.hpp"
  47 #include "gc/g1/g1HeapTransition.hpp"
  48 #include "gc/g1/g1HeapVerifier.hpp"
  49 #include "gc/g1/g1HotCardCache.hpp"
  50 #include "gc/g1/g1InitLogger.hpp"
  51 #include "gc/g1/g1MemoryPool.hpp"
  52 #include "gc/g1/g1OopClosures.inline.hpp"
  53 #include "gc/g1/g1ParallelCleaning.hpp"
  54 #include "gc/g1/g1ParScanThreadState.inline.hpp"
  55 #include "gc/g1/g1Policy.hpp"
  56 #include "gc/g1/g1RedirtyCardsQueue.hpp"
  57 #include "gc/g1/g1RegionToSpaceMapper.hpp"
  58 #include "gc/g1/g1RemSet.hpp"
  59 #include "gc/g1/g1RootClosures.hpp"
  60 #include "gc/g1/g1RootProcessor.hpp"
  61 #include "gc/g1/g1SATBMarkQueueSet.hpp"
  62 #include "gc/g1/g1StringDedup.hpp"
  63 #include "gc/g1/g1ThreadLocalData.hpp"
  64 #include "gc/g1/g1Trace.hpp"
  65 #include "gc/g1/g1YCTypes.hpp"
  66 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
  67 #include "gc/g1/g1VMOperations.hpp"
  68 #include "gc/g1/heapRegion.inline.hpp"
  69 #include "gc/g1/heapRegionRemSet.hpp"
  70 #include "gc/g1/heapRegionSet.inline.hpp"
  71 #include "gc/shared/concurrentGCBreakpoints.hpp"
  72 #include "gc/shared/gcBehaviours.hpp"
  73 #include "gc/shared/gcHeapSummary.hpp"
  74 #include "gc/shared/gcId.hpp"
  75 #include "gc/shared/gcLocker.hpp"
  76 #include "gc/shared/gcTimer.hpp"
  77 #include "gc/shared/gcTraceTime.inline.hpp"
  78 #include "gc/shared/generationSpec.hpp"
  79 #include "gc/shared/isGCActiveMark.hpp"
  80 #include "gc/shared/locationPrinter.inline.hpp"
  81 #include "gc/shared/oopStorageParState.hpp"
  82 #include "gc/shared/preservedMarks.inline.hpp"
  83 #include "gc/shared/suspendibleThreadSet.hpp"
  84 #include "gc/shared/referenceProcessor.inline.hpp"
  85 #include "gc/shared/taskTerminator.hpp"
  86 #include "gc/shared/taskqueue.inline.hpp"


1401     // serialize them) or by the GC workers while holding the
1402     // OldSets_lock.
1403     // (b) If we're not at a safepoint, operations on the master
1404     // humongous set should be invoked while holding the Heap_lock.
1405 
1406     if (SafepointSynchronize::is_at_safepoint()) {
1407       guarantee(Thread::current()->is_VM_thread() ||
1408                 OldSets_lock->owned_by_self(),
1409                 "master humongous set MT safety protocol at a safepoint");
1410     } else {
1411       guarantee(Heap_lock->owned_by_self(),
1412                 "master humongous set MT safety protocol outside a safepoint");
1413     }
1414   }
1415   bool is_correct_type(HeapRegion* hr) { return hr->is_humongous(); }
1416   const char* get_description() { return "Humongous Regions"; }
1417 };
1418 
1419 G1CollectedHeap::G1CollectedHeap() :
1420   CollectedHeap(),
1421   _young_gen_sampling_thread(NULL),
1422   _workers(NULL),
1423   _card_table(NULL),
1424   _collection_pause_end(Ticks::now()),
1425   _soft_ref_policy(),
1426   _old_set("Old Region Set", new OldRegionSetChecker()),
1427   _archive_set("Archive Region Set", new ArchiveRegionSetChecker()),
1428   _humongous_set("Humongous Region Set", new HumongousRegionSetChecker()),
1429   _bot(NULL),
1430   _listener(),
1431   _numa(G1NUMA::create()),
1432   _hrm(NULL),
1433   _allocator(NULL),
1434   _verifier(NULL),
1435   _summary_bytes_used(0),
1436   _bytes_used_during_gc(0),
1437   _archive_allocator(NULL),
1438   _survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
1439   _old_evac_stats("Old", OldPLABSize, PLABWeight),
1440   _expand_heap_after_alloc_failure(true),
1441   _g1mm(NULL),


1538                                          HeapRegion::GrainBytes,
1539                                          translation_factor,
1540                                          mtGC);
1541 
1542   os::trace_page_sizes_for_requested_size(description,
1543                                           size,
1544                                           preferred_page_size,
1545                                           page_size,
1546                                           rs.base(),
1547                                           rs.size());
1548 
1549   return result;
1550 }
1551 
1552 jint G1CollectedHeap::initialize_concurrent_refinement() {
1553   jint ecode = JNI_OK;
1554   _cr = G1ConcurrentRefine::create(&ecode);
1555   return ecode;
1556 }
1557 
1558 jint G1CollectedHeap::initialize_young_gen_sampling_thread() {
1559   _young_gen_sampling_thread = new G1YoungRemSetSamplingThread();
1560   if (_young_gen_sampling_thread->osthread() == NULL) {
1561     vm_shutdown_during_initialization("Could not create G1YoungRemSetSamplingThread");
1562     return JNI_ENOMEM;
1563   }
1564   return JNI_OK;
1565 }
1566 
1567 jint G1CollectedHeap::initialize() {
1568 
1569   // Necessary to satisfy locking discipline assertions.
1570 
1571   MutexLocker x(Heap_lock);
1572 
1573   // While there are no constraints in the GC code that HeapWordSize
1574   // be any particular value, there are multiple other areas in the
1575   // system which believe this to be true (e.g. oop->object_size in some
1576   // cases incorrectly returns the size in wordSize units rather than
1577   // HeapWordSize).
1578   guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
1579 
1580   size_t init_byte_size = InitialHeapSize;
1581   size_t reserved_byte_size = G1Arguments::heap_reserved_size_bytes();


1715 
1716   // Create the G1ConcurrentMark data structure and thread.
1717   // (Must do this late, so that "max_regions" is defined.)
1718   _cm = new G1ConcurrentMark(this, prev_bitmap_storage, next_bitmap_storage);
1719   _cm_thread = _cm->cm_thread();
1720 
1721   // Now expand into the initial heap size.
1722   if (!expand(init_byte_size, _workers)) {
1723     vm_shutdown_during_initialization("Failed to allocate initial heap.");
1724     return JNI_ENOMEM;
1725   }
1726 
1727   // Perform any initialization actions delegated to the policy.
1728   policy()->init(this, &_collection_set);
1729 
1730   jint ecode = initialize_concurrent_refinement();
1731   if (ecode != JNI_OK) {
1732     return ecode;
1733   }
1734 
1735   ecode = initialize_young_gen_sampling_thread();
1736   if (ecode != JNI_OK) {
1737     return ecode;
1738   }
1739 
1740   {
1741     G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
1742     dcqs.set_process_cards_threshold(concurrent_refine()->yellow_zone());
1743     dcqs.set_max_cards(concurrent_refine()->red_zone());
1744   }
1745 
1746   // Here we allocate the dummy HeapRegion that is required by the
1747   // G1AllocRegion class.
1748   HeapRegion* dummy_region = _hrm->get_dummy_region();
1749 
1750   // We'll re-use the same region whether the alloc region will
1751   // require BOT updates or not and, if it doesn't, then a non-young
1752   // region will complain that it cannot support allocations without
1753   // BOT updates. So we'll tag the dummy region as eden to avoid that.
1754   dummy_region->set_eden();
1755   // Make sure it's full.


1761   // Do create of the monitoring and management support so that
1762   // values in the heap have been properly initialized.
1763   _g1mm = new G1MonitoringSupport(this);
1764 
1765   G1StringDedup::initialize();
1766 
1767   _preserved_marks_set.init(ParallelGCThreads);
1768 
1769   _collection_set.initialize(max_regions());
1770 
1771   G1InitLogger::print();
1772 
1773   return JNI_OK;
1774 }
1775 
1776 void G1CollectedHeap::stop() {
1777   // Stop all concurrent threads. We do this to make sure these threads
1778   // do not continue to execute and access resources (e.g. logging)
1779   // that are destroyed during shutdown.
1780   _cr->stop();
1781   _young_gen_sampling_thread->stop();
1782   _cm_thread->stop();
1783   if (G1StringDedup::is_enabled()) {
1784     G1StringDedup::stop();
1785   }
1786 }
1787 
1788 void G1CollectedHeap::safepoint_synchronize_begin() {
1789   SuspendibleThreadSet::synchronize();
1790 }
1791 
1792 void G1CollectedHeap::safepoint_synchronize_end() {
1793   SuspendibleThreadSet::desynchronize();
1794 }
1795 
1796 void G1CollectedHeap::post_initialize() {
1797   CollectedHeap::post_initialize();
1798   ref_processing_init();
1799 }
1800 
1801 void G1CollectedHeap::ref_processing_init() {


2516   if (_hrm != NULL) {
2517     st->cr();
2518     print_regions_on(st);
2519   }
2520 }
2521 
2522 void G1CollectedHeap::print_on_error(outputStream* st) const {
2523   this->CollectedHeap::print_on_error(st);
2524 
2525   if (_cm != NULL) {
2526     st->cr();
2527     _cm->print_on_error(st);
2528   }
2529 }
2530 
2531 void G1CollectedHeap::gc_threads_do(ThreadClosure* tc) const {
2532   workers()->threads_do(tc);
2533   tc->do_thread(_cm_thread);
2534   _cm->threads_do(tc);
2535   _cr->threads_do(tc);
2536   tc->do_thread(_young_gen_sampling_thread);
2537   if (G1StringDedup::is_enabled()) {
2538     G1StringDedup::threads_do(tc);
2539   }
2540 }
2541 
2542 void G1CollectedHeap::print_tracing_info() const {
2543   rem_set()->print_summary_info();
2544   concurrent_mark()->print_summary_info();
2545 }
2546 
2547 #ifndef PRODUCT
2548 // Helpful for debugging RSet issues.
2549 
2550 class PrintRSetsClosure : public HeapRegionClosure {
2551 private:
2552   const char* _msg;
2553   size_t _occupied_sum;
2554 
2555 public:
2556   bool do_heap_region(HeapRegion* r) {




  46 #include "gc/g1/g1HeapSizingPolicy.hpp"
  47 #include "gc/g1/g1HeapTransition.hpp"
  48 #include "gc/g1/g1HeapVerifier.hpp"
  49 #include "gc/g1/g1HotCardCache.hpp"
  50 #include "gc/g1/g1InitLogger.hpp"
  51 #include "gc/g1/g1MemoryPool.hpp"
  52 #include "gc/g1/g1OopClosures.inline.hpp"
  53 #include "gc/g1/g1ParallelCleaning.hpp"
  54 #include "gc/g1/g1ParScanThreadState.inline.hpp"
  55 #include "gc/g1/g1Policy.hpp"
  56 #include "gc/g1/g1RedirtyCardsQueue.hpp"
  57 #include "gc/g1/g1RegionToSpaceMapper.hpp"
  58 #include "gc/g1/g1RemSet.hpp"
  59 #include "gc/g1/g1RootClosures.hpp"
  60 #include "gc/g1/g1RootProcessor.hpp"
  61 #include "gc/g1/g1SATBMarkQueueSet.hpp"
  62 #include "gc/g1/g1StringDedup.hpp"
  63 #include "gc/g1/g1ThreadLocalData.hpp"
  64 #include "gc/g1/g1Trace.hpp"
  65 #include "gc/g1/g1YCTypes.hpp"
  66 #include "gc/g1/g1ServiceThread.hpp"
  67 #include "gc/g1/g1VMOperations.hpp"
  68 #include "gc/g1/heapRegion.inline.hpp"
  69 #include "gc/g1/heapRegionRemSet.hpp"
  70 #include "gc/g1/heapRegionSet.inline.hpp"
  71 #include "gc/shared/concurrentGCBreakpoints.hpp"
  72 #include "gc/shared/gcBehaviours.hpp"
  73 #include "gc/shared/gcHeapSummary.hpp"
  74 #include "gc/shared/gcId.hpp"
  75 #include "gc/shared/gcLocker.hpp"
  76 #include "gc/shared/gcTimer.hpp"
  77 #include "gc/shared/gcTraceTime.inline.hpp"
  78 #include "gc/shared/generationSpec.hpp"
  79 #include "gc/shared/isGCActiveMark.hpp"
  80 #include "gc/shared/locationPrinter.inline.hpp"
  81 #include "gc/shared/oopStorageParState.hpp"
  82 #include "gc/shared/preservedMarks.inline.hpp"
  83 #include "gc/shared/suspendibleThreadSet.hpp"
  84 #include "gc/shared/referenceProcessor.inline.hpp"
  85 #include "gc/shared/taskTerminator.hpp"
  86 #include "gc/shared/taskqueue.inline.hpp"


1401     // serialize them) or by the GC workers while holding the
1402     // OldSets_lock.
1403     // (b) If we're not at a safepoint, operations on the master
1404     // humongous set should be invoked while holding the Heap_lock.
1405 
1406     if (SafepointSynchronize::is_at_safepoint()) {
1407       guarantee(Thread::current()->is_VM_thread() ||
1408                 OldSets_lock->owned_by_self(),
1409                 "master humongous set MT safety protocol at a safepoint");
1410     } else {
1411       guarantee(Heap_lock->owned_by_self(),
1412                 "master humongous set MT safety protocol outside a safepoint");
1413     }
1414   }
1415   bool is_correct_type(HeapRegion* hr) { return hr->is_humongous(); }
1416   const char* get_description() { return "Humongous Regions"; }
1417 };
1418 
1419 G1CollectedHeap::G1CollectedHeap() :
1420   CollectedHeap(),
1421   _service_thread(NULL),
1422   _workers(NULL),
1423   _card_table(NULL),
1424   _collection_pause_end(Ticks::now()),
1425   _soft_ref_policy(),
1426   _old_set("Old Region Set", new OldRegionSetChecker()),
1427   _archive_set("Archive Region Set", new ArchiveRegionSetChecker()),
1428   _humongous_set("Humongous Region Set", new HumongousRegionSetChecker()),
1429   _bot(NULL),
1430   _listener(),
1431   _numa(G1NUMA::create()),
1432   _hrm(NULL),
1433   _allocator(NULL),
1434   _verifier(NULL),
1435   _summary_bytes_used(0),
1436   _bytes_used_during_gc(0),
1437   _archive_allocator(NULL),
1438   _survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
1439   _old_evac_stats("Old", OldPLABSize, PLABWeight),
1440   _expand_heap_after_alloc_failure(true),
1441   _g1mm(NULL),


1538                                          HeapRegion::GrainBytes,
1539                                          translation_factor,
1540                                          mtGC);
1541 
1542   os::trace_page_sizes_for_requested_size(description,
1543                                           size,
1544                                           preferred_page_size,
1545                                           page_size,
1546                                           rs.base(),
1547                                           rs.size());
1548 
1549   return result;
1550 }
1551 
1552 jint G1CollectedHeap::initialize_concurrent_refinement() {
1553   jint ecode = JNI_OK;
1554   _cr = G1ConcurrentRefine::create(&ecode);
1555   return ecode;
1556 }
1557 
1558 jint G1CollectedHeap::initialize_service_thread() {
1559   _service_thread = new G1ServiceThread();
1560   if (_service_thread->osthread() == NULL) {
1561     vm_shutdown_during_initialization("Could not create G1ServiceThread");
1562     return JNI_ENOMEM;
1563   }
1564   return JNI_OK;
1565 }
1566 
1567 jint G1CollectedHeap::initialize() {
1568 
1569   // Necessary to satisfy locking discipline assertions.
1570 
1571   MutexLocker x(Heap_lock);
1572 
1573   // While there are no constraints in the GC code that HeapWordSize
1574   // be any particular value, there are multiple other areas in the
1575   // system which believe this to be true (e.g. oop->object_size in some
1576   // cases incorrectly returns the size in wordSize units rather than
1577   // HeapWordSize).
1578   guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
1579 
1580   size_t init_byte_size = InitialHeapSize;
1581   size_t reserved_byte_size = G1Arguments::heap_reserved_size_bytes();


1715 
1716   // Create the G1ConcurrentMark data structure and thread.
1717   // (Must do this late, so that "max_regions" is defined.)
1718   _cm = new G1ConcurrentMark(this, prev_bitmap_storage, next_bitmap_storage);
1719   _cm_thread = _cm->cm_thread();
1720 
1721   // Now expand into the initial heap size.
1722   if (!expand(init_byte_size, _workers)) {
1723     vm_shutdown_during_initialization("Failed to allocate initial heap.");
1724     return JNI_ENOMEM;
1725   }
1726 
1727   // Perform any initialization actions delegated to the policy.
1728   policy()->init(this, &_collection_set);
1729 
1730   jint ecode = initialize_concurrent_refinement();
1731   if (ecode != JNI_OK) {
1732     return ecode;
1733   }
1734 
1735   ecode = initialize_service_thread();
1736   if (ecode != JNI_OK) {
1737     return ecode;
1738   }
1739 
1740   {
1741     G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
1742     dcqs.set_process_cards_threshold(concurrent_refine()->yellow_zone());
1743     dcqs.set_max_cards(concurrent_refine()->red_zone());
1744   }
1745 
1746   // Here we allocate the dummy HeapRegion that is required by the
1747   // G1AllocRegion class.
1748   HeapRegion* dummy_region = _hrm->get_dummy_region();
1749 
1750   // We'll re-use the same region whether the alloc region will
1751   // require BOT updates or not and, if it doesn't, then a non-young
1752   // region will complain that it cannot support allocations without
1753   // BOT updates. So we'll tag the dummy region as eden to avoid that.
1754   dummy_region->set_eden();
1755   // Make sure it's full.


1761   // Do create of the monitoring and management support so that
1762   // values in the heap have been properly initialized.
1763   _g1mm = new G1MonitoringSupport(this);
1764 
1765   G1StringDedup::initialize();
1766 
1767   _preserved_marks_set.init(ParallelGCThreads);
1768 
1769   _collection_set.initialize(max_regions());
1770 
1771   G1InitLogger::print();
1772 
1773   return JNI_OK;
1774 }
1775 
1776 void G1CollectedHeap::stop() {
1777   // Stop all concurrent threads. We do this to make sure these threads
1778   // do not continue to execute and access resources (e.g. logging)
1779   // that are destroyed during shutdown.
1780   _cr->stop();
1781   _service_thread->stop();
1782   _cm_thread->stop();
1783   if (G1StringDedup::is_enabled()) {
1784     G1StringDedup::stop();
1785   }
1786 }
1787 
1788 void G1CollectedHeap::safepoint_synchronize_begin() {
1789   SuspendibleThreadSet::synchronize();
1790 }
1791 
1792 void G1CollectedHeap::safepoint_synchronize_end() {
1793   SuspendibleThreadSet::desynchronize();
1794 }
1795 
1796 void G1CollectedHeap::post_initialize() {
1797   CollectedHeap::post_initialize();
1798   ref_processing_init();
1799 }
1800 
1801 void G1CollectedHeap::ref_processing_init() {


2516   if (_hrm != NULL) {
2517     st->cr();
2518     print_regions_on(st);
2519   }
2520 }
2521 
2522 void G1CollectedHeap::print_on_error(outputStream* st) const {
2523   this->CollectedHeap::print_on_error(st);
2524 
2525   if (_cm != NULL) {
2526     st->cr();
2527     _cm->print_on_error(st);
2528   }
2529 }
2530 
2531 void G1CollectedHeap::gc_threads_do(ThreadClosure* tc) const {
2532   workers()->threads_do(tc);
2533   tc->do_thread(_cm_thread);
2534   _cm->threads_do(tc);
2535   _cr->threads_do(tc);
2536   tc->do_thread(_service_thread);
2537   if (G1StringDedup::is_enabled()) {
2538     G1StringDedup::threads_do(tc);
2539   }
2540 }
2541 
2542 void G1CollectedHeap::print_tracing_info() const {
2543   rem_set()->print_summary_info();
2544   concurrent_mark()->print_summary_info();
2545 }
2546 
2547 #ifndef PRODUCT
2548 // Helpful for debugging RSet issues.
2549 
2550 class PrintRSetsClosure : public HeapRegionClosure {
2551 private:
2552   const char* _msg;
2553   size_t _occupied_sum;
2554 
2555 public:
2556   bool do_heap_region(HeapRegion* r) {


< prev index next >