12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/metadataOnStackMark.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "gc/g1/bufferingOopClosure.hpp"
32 #include "gc/g1/concurrentG1Refine.hpp"
33 #include "gc/g1/concurrentG1RefineThread.hpp"
34 #include "gc/g1/concurrentMarkThread.inline.hpp"
35 #include "gc/g1/g1Allocator.inline.hpp"
36 #include "gc/g1/g1CollectedHeap.inline.hpp"
37 #include "gc/g1/g1CollectionSet.hpp"
38 #include "gc/g1/g1CollectorPolicy.hpp"
39 #include "gc/g1/g1CollectorState.hpp"
40 #include "gc/g1/g1EvacStats.inline.hpp"
41 #include "gc/g1/g1FullGCScope.hpp"
42 #include "gc/g1/g1GCPhaseTimes.hpp"
43 #include "gc/g1/g1HeapSizingPolicy.hpp"
44 #include "gc/g1/g1HeapTransition.hpp"
45 #include "gc/g1/g1HeapVerifier.hpp"
46 #include "gc/g1/g1HotCardCache.hpp"
47 #include "gc/g1/g1OopClosures.inline.hpp"
48 #include "gc/g1/g1ParScanThreadState.inline.hpp"
49 #include "gc/g1/g1Policy.hpp"
50 #include "gc/g1/g1RegionToSpaceMapper.hpp"
51 #include "gc/g1/g1RemSet.inline.hpp"
52 #include "gc/g1/g1RootClosures.hpp"
53 #include "gc/g1/g1RootProcessor.hpp"
54 #include "gc/g1/g1SerialFullCollector.hpp"
55 #include "gc/g1/g1StringDedup.hpp"
56 #include "gc/g1/g1YCTypes.hpp"
57 #include "gc/g1/heapRegion.inline.hpp"
58 #include "gc/g1/heapRegionRemSet.hpp"
59 #include "gc/g1/heapRegionSet.inline.hpp"
1537 _verifier->verify_region_sets_optional();
1538 }
1539
1540 // Public methods.
1541
1542 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* collector_policy) :
1543 CollectedHeap(),
1544 _collector_policy(collector_policy),
1545 _gc_timer_stw(new (ResourceObj::C_HEAP, mtGC) STWGCTimer()),
1546 _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()),
1547 _g1_policy(create_g1_policy(_gc_timer_stw)),
1548 _collection_set(this, _g1_policy),
1549 _dirty_card_queue_set(false),
1550 _is_alive_closure_cm(this),
1551 _is_alive_closure_stw(this),
1552 _ref_processor_cm(NULL),
1553 _ref_processor_stw(NULL),
1554 _bot(NULL),
1555 _hot_card_cache(NULL),
1556 _g1_rem_set(NULL),
1557 _cg1r(NULL),
1558 _g1mm(NULL),
1559 _preserved_marks_set(true /* in_c_heap */),
1560 _secondary_free_list("Secondary Free List", new SecondaryFreeRegionListMtSafeChecker()),
1561 _old_set("Old Set", false /* humongous */, new OldRegionSetMtSafeChecker()),
1562 _humongous_set("Master Humongous Set", true /* humongous */, new HumongousRegionSetMtSafeChecker()),
1563 _humongous_reclaim_candidates(),
1564 _has_humongous_reclaim_candidates(false),
1565 _archive_allocator(NULL),
1566 _free_regions_coming(false),
1567 _gc_time_stamp(0),
1568 _summary_bytes_used(0),
1569 _survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
1570 _old_evac_stats("Old", OldPLABSize, PLABWeight),
1571 _expand_heap_after_alloc_failure(true),
1572 _old_marking_cycles_started(0),
1573 _old_marking_cycles_completed(0),
1574 _in_cset_fast_test() {
1575
1576 _workers = new WorkGang("GC Thread", ParallelGCThreads,
1577 /* are_GC_task_threads */true,
1616 G1RegionToSpaceMapper* result =
1617 G1RegionToSpaceMapper::create_mapper(rs,
1618 size,
1619 rs.alignment(),
1620 HeapRegion::GrainBytes,
1621 translation_factor,
1622 mtGC);
1623
1624 os::trace_page_sizes_for_requested_size(description,
1625 size,
1626 preferred_page_size,
1627 rs.alignment(),
1628 rs.base(),
1629 rs.size());
1630
1631 return result;
1632 }
1633
1634 jint G1CollectedHeap::initialize_concurrent_refinement() {
1635 jint ecode = JNI_OK;
1636 _cg1r = ConcurrentG1Refine::create(&ecode);
1637 return ecode;
1638 }
1639
1640 jint G1CollectedHeap::initialize() {
1641 CollectedHeap::pre_initialize();
1642 os::enable_vtime();
1643
1644 // Necessary to satisfy locking discipline assertions.
1645
1646 MutexLocker x(Heap_lock);
1647
1648 // While there are no constraints in the GC code that HeapWordSize
1649 // be any particular value, there are multiple other areas in the
1650 // system which believe this to be true (e.g. oop->object_size in some
1651 // cases incorrectly returns the size in wordSize units rather than
1652 // HeapWordSize).
1653 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
1654
1655 size_t init_byte_size = collector_policy()->initial_heap_byte_size();
1656 size_t max_byte_size = collector_policy()->max_heap_byte_size();
1774 if (!expand(init_byte_size, _workers)) {
1775 vm_shutdown_during_initialization("Failed to allocate initial heap.");
1776 return JNI_ENOMEM;
1777 }
1778
1779 // Perform any initialization actions delegated to the policy.
1780 g1_policy()->init(this, &_collection_set);
1781
1782 JavaThread::satb_mark_queue_set().initialize(SATB_Q_CBL_mon,
1783 SATB_Q_FL_lock,
1784 G1SATBProcessCompletedThreshold,
1785 Shared_SATB_Q_lock);
1786
1787 jint ecode = initialize_concurrent_refinement();
1788 if (ecode != JNI_OK) {
1789 return ecode;
1790 }
1791
1792 JavaThread::dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon,
1793 DirtyCardQ_FL_lock,
1794 (int)concurrent_g1_refine()->yellow_zone(),
1795 (int)concurrent_g1_refine()->red_zone(),
1796 Shared_DirtyCardQ_lock,
1797 NULL, // fl_owner
1798 true); // init_free_ids
1799
1800 dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon,
1801 DirtyCardQ_FL_lock,
1802 -1, // never trigger processing
1803 -1, // no limit on length
1804 Shared_DirtyCardQ_lock,
1805 &JavaThread::dirty_card_queue_set());
1806
1807 // Here we allocate the dummy HeapRegion that is required by the
1808 // G1AllocRegion class.
1809 HeapRegion* dummy_region = _hrm.get_dummy_region();
1810
1811 // We'll re-use the same region whether the alloc region will
1812 // require BOT updates or not and, if it doesn't, then a non-young
1813 // region will complain that it cannot support allocations without
1814 // BOT updates. So we'll tag the dummy region as eden to avoid that.
1815 dummy_region->set_eden();
1819
1820 _allocator->init_mutator_alloc_region();
1821
1822 // Do create of the monitoring and management support so that
1823 // values in the heap have been properly initialized.
1824 _g1mm = new G1MonitoringSupport(this);
1825
1826 G1StringDedup::initialize();
1827
1828 _preserved_marks_set.init(ParallelGCThreads);
1829
1830 _collection_set.initialize(max_regions());
1831
1832 return JNI_OK;
1833 }
1834
1835 void G1CollectedHeap::stop() {
1836 // Stop all concurrent threads. We do this to make sure these threads
1837 // do not continue to execute and access resources (e.g. logging)
1838 // that are destroyed during shutdown.
1839 _cg1r->stop();
1840 _cmThread->stop();
1841 if (G1StringDedup::is_enabled()) {
1842 G1StringDedup::stop();
1843 }
1844 }
1845
1846 void G1CollectedHeap::safepoint_synchronize_begin() {
1847 SuspendibleThreadSet::synchronize();
1848 }
1849
1850 void G1CollectedHeap::safepoint_synchronize_end() {
1851 SuspendibleThreadSet::desynchronize();
1852 }
1853
1854 size_t G1CollectedHeap::conservative_max_heap_alignment() {
1855 return HeapRegion::max_region_size();
1856 }
1857
1858 void G1CollectedHeap::post_initialize() {
1859 ref_processing_init();
2419 print_on(st);
2420
2421 // Print the per-region information.
2422 print_regions_on(st);
2423 }
2424
2425 void G1CollectedHeap::print_on_error(outputStream* st) const {
2426 this->CollectedHeap::print_on_error(st);
2427
2428 if (_cm != NULL) {
2429 st->cr();
2430 _cm->print_on_error(st);
2431 }
2432 }
2433
2434 void G1CollectedHeap::print_gc_threads_on(outputStream* st) const {
2435 workers()->print_worker_threads_on(st);
2436 _cmThread->print_on(st);
2437 st->cr();
2438 _cm->print_worker_threads_on(st);
2439 _cg1r->print_worker_threads_on(st); // also prints the sample thread
2440 if (G1StringDedup::is_enabled()) {
2441 G1StringDedup::print_worker_threads_on(st);
2442 }
2443 }
2444
2445 void G1CollectedHeap::gc_threads_do(ThreadClosure* tc) const {
2446 workers()->threads_do(tc);
2447 tc->do_thread(_cmThread);
2448 _cm->threads_do(tc);
2449 _cg1r->threads_do(tc); // also iterates over the sample thread
2450 if (G1StringDedup::is_enabled()) {
2451 G1StringDedup::threads_do(tc);
2452 }
2453 }
2454
2455 void G1CollectedHeap::print_tracing_info() const {
2456 g1_rem_set()->print_summary_info();
2457 concurrent_mark()->print_summary_info();
2458 }
2459
2460 #ifndef PRODUCT
2461 // Helpful for debugging RSet issues.
2462
2463 class PrintRSetsClosure : public HeapRegionClosure {
2464 private:
2465 const char* _msg;
2466 size_t _occupied_sum;
2467
2468 public:
2469 bool doHeapRegion(HeapRegion* r) {
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/metadataOnStackMark.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "gc/g1/bufferingOopClosure.hpp"
32 #include "gc/g1/concurrentMarkThread.inline.hpp"
33 #include "gc/g1/g1Allocator.inline.hpp"
34 #include "gc/g1/g1CollectedHeap.inline.hpp"
35 #include "gc/g1/g1CollectionSet.hpp"
36 #include "gc/g1/g1CollectorPolicy.hpp"
37 #include "gc/g1/g1CollectorState.hpp"
38 #include "gc/g1/g1ConcurrentRefine.hpp"
39 #include "gc/g1/g1ConcurrentRefineThread.hpp"
40 #include "gc/g1/g1EvacStats.inline.hpp"
41 #include "gc/g1/g1FullGCScope.hpp"
42 #include "gc/g1/g1GCPhaseTimes.hpp"
43 #include "gc/g1/g1HeapSizingPolicy.hpp"
44 #include "gc/g1/g1HeapTransition.hpp"
45 #include "gc/g1/g1HeapVerifier.hpp"
46 #include "gc/g1/g1HotCardCache.hpp"
47 #include "gc/g1/g1OopClosures.inline.hpp"
48 #include "gc/g1/g1ParScanThreadState.inline.hpp"
49 #include "gc/g1/g1Policy.hpp"
50 #include "gc/g1/g1RegionToSpaceMapper.hpp"
51 #include "gc/g1/g1RemSet.inline.hpp"
52 #include "gc/g1/g1RootClosures.hpp"
53 #include "gc/g1/g1RootProcessor.hpp"
54 #include "gc/g1/g1SerialFullCollector.hpp"
55 #include "gc/g1/g1StringDedup.hpp"
56 #include "gc/g1/g1YCTypes.hpp"
57 #include "gc/g1/heapRegion.inline.hpp"
58 #include "gc/g1/heapRegionRemSet.hpp"
59 #include "gc/g1/heapRegionSet.inline.hpp"
1537 _verifier->verify_region_sets_optional();
1538 }
1539
1540 // Public methods.
1541
1542 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* collector_policy) :
1543 CollectedHeap(),
1544 _collector_policy(collector_policy),
1545 _gc_timer_stw(new (ResourceObj::C_HEAP, mtGC) STWGCTimer()),
1546 _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()),
1547 _g1_policy(create_g1_policy(_gc_timer_stw)),
1548 _collection_set(this, _g1_policy),
1549 _dirty_card_queue_set(false),
1550 _is_alive_closure_cm(this),
1551 _is_alive_closure_stw(this),
1552 _ref_processor_cm(NULL),
1553 _ref_processor_stw(NULL),
1554 _bot(NULL),
1555 _hot_card_cache(NULL),
1556 _g1_rem_set(NULL),
1557 _cr(NULL),
1558 _g1mm(NULL),
1559 _preserved_marks_set(true /* in_c_heap */),
1560 _secondary_free_list("Secondary Free List", new SecondaryFreeRegionListMtSafeChecker()),
1561 _old_set("Old Set", false /* humongous */, new OldRegionSetMtSafeChecker()),
1562 _humongous_set("Master Humongous Set", true /* humongous */, new HumongousRegionSetMtSafeChecker()),
1563 _humongous_reclaim_candidates(),
1564 _has_humongous_reclaim_candidates(false),
1565 _archive_allocator(NULL),
1566 _free_regions_coming(false),
1567 _gc_time_stamp(0),
1568 _summary_bytes_used(0),
1569 _survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
1570 _old_evac_stats("Old", OldPLABSize, PLABWeight),
1571 _expand_heap_after_alloc_failure(true),
1572 _old_marking_cycles_started(0),
1573 _old_marking_cycles_completed(0),
1574 _in_cset_fast_test() {
1575
1576 _workers = new WorkGang("GC Thread", ParallelGCThreads,
1577 /* are_GC_task_threads */true,
1616 G1RegionToSpaceMapper* result =
1617 G1RegionToSpaceMapper::create_mapper(rs,
1618 size,
1619 rs.alignment(),
1620 HeapRegion::GrainBytes,
1621 translation_factor,
1622 mtGC);
1623
1624 os::trace_page_sizes_for_requested_size(description,
1625 size,
1626 preferred_page_size,
1627 rs.alignment(),
1628 rs.base(),
1629 rs.size());
1630
1631 return result;
1632 }
1633
1634 jint G1CollectedHeap::initialize_concurrent_refinement() {
1635 jint ecode = JNI_OK;
1636 _cr = G1ConcurrentRefine::create(&ecode);
1637 return ecode;
1638 }
1639
1640 jint G1CollectedHeap::initialize() {
1641 CollectedHeap::pre_initialize();
1642 os::enable_vtime();
1643
1644 // Necessary to satisfy locking discipline assertions.
1645
1646 MutexLocker x(Heap_lock);
1647
1648 // While there are no constraints in the GC code that HeapWordSize
1649 // be any particular value, there are multiple other areas in the
1650 // system which believe this to be true (e.g. oop->object_size in some
1651 // cases incorrectly returns the size in wordSize units rather than
1652 // HeapWordSize).
1653 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
1654
1655 size_t init_byte_size = collector_policy()->initial_heap_byte_size();
1656 size_t max_byte_size = collector_policy()->max_heap_byte_size();
1774 if (!expand(init_byte_size, _workers)) {
1775 vm_shutdown_during_initialization("Failed to allocate initial heap.");
1776 return JNI_ENOMEM;
1777 }
1778
1779 // Perform any initialization actions delegated to the policy.
1780 g1_policy()->init(this, &_collection_set);
1781
1782 JavaThread::satb_mark_queue_set().initialize(SATB_Q_CBL_mon,
1783 SATB_Q_FL_lock,
1784 G1SATBProcessCompletedThreshold,
1785 Shared_SATB_Q_lock);
1786
1787 jint ecode = initialize_concurrent_refinement();
1788 if (ecode != JNI_OK) {
1789 return ecode;
1790 }
1791
1792 JavaThread::dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon,
1793 DirtyCardQ_FL_lock,
1794 (int)concurrent_refine()->yellow_zone(),
1795 (int)concurrent_refine()->red_zone(),
1796 Shared_DirtyCardQ_lock,
1797 NULL, // fl_owner
1798 true); // init_free_ids
1799
1800 dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon,
1801 DirtyCardQ_FL_lock,
1802 -1, // never trigger processing
1803 -1, // no limit on length
1804 Shared_DirtyCardQ_lock,
1805 &JavaThread::dirty_card_queue_set());
1806
1807 // Here we allocate the dummy HeapRegion that is required by the
1808 // G1AllocRegion class.
1809 HeapRegion* dummy_region = _hrm.get_dummy_region();
1810
1811 // We'll re-use the same region whether the alloc region will
1812 // require BOT updates or not and, if it doesn't, then a non-young
1813 // region will complain that it cannot support allocations without
1814 // BOT updates. So we'll tag the dummy region as eden to avoid that.
1815 dummy_region->set_eden();
1819
1820 _allocator->init_mutator_alloc_region();
1821
1822 // Do create of the monitoring and management support so that
1823 // values in the heap have been properly initialized.
1824 _g1mm = new G1MonitoringSupport(this);
1825
1826 G1StringDedup::initialize();
1827
1828 _preserved_marks_set.init(ParallelGCThreads);
1829
1830 _collection_set.initialize(max_regions());
1831
1832 return JNI_OK;
1833 }
1834
1835 void G1CollectedHeap::stop() {
1836 // Stop all concurrent threads. We do this to make sure these threads
1837 // do not continue to execute and access resources (e.g. logging)
1838 // that are destroyed during shutdown.
1839 _cr->stop();
1840 _cmThread->stop();
1841 if (G1StringDedup::is_enabled()) {
1842 G1StringDedup::stop();
1843 }
1844 }
1845
1846 void G1CollectedHeap::safepoint_synchronize_begin() {
1847 SuspendibleThreadSet::synchronize();
1848 }
1849
1850 void G1CollectedHeap::safepoint_synchronize_end() {
1851 SuspendibleThreadSet::desynchronize();
1852 }
1853
1854 size_t G1CollectedHeap::conservative_max_heap_alignment() {
1855 return HeapRegion::max_region_size();
1856 }
1857
1858 void G1CollectedHeap::post_initialize() {
1859 ref_processing_init();
2419 print_on(st);
2420
2421 // Print the per-region information.
2422 print_regions_on(st);
2423 }
2424
2425 void G1CollectedHeap::print_on_error(outputStream* st) const {
2426 this->CollectedHeap::print_on_error(st);
2427
2428 if (_cm != NULL) {
2429 st->cr();
2430 _cm->print_on_error(st);
2431 }
2432 }
2433
2434 void G1CollectedHeap::print_gc_threads_on(outputStream* st) const {
2435 workers()->print_worker_threads_on(st);
2436 _cmThread->print_on(st);
2437 st->cr();
2438 _cm->print_worker_threads_on(st);
2439 _cr->print_worker_threads_on(st); // also prints the sample thread
2440 if (G1StringDedup::is_enabled()) {
2441 G1StringDedup::print_worker_threads_on(st);
2442 }
2443 }
2444
2445 void G1CollectedHeap::gc_threads_do(ThreadClosure* tc) const {
2446 workers()->threads_do(tc);
2447 tc->do_thread(_cmThread);
2448 _cm->threads_do(tc);
2449 _cr->threads_do(tc); // also iterates over the sample thread
2450 if (G1StringDedup::is_enabled()) {
2451 G1StringDedup::threads_do(tc);
2452 }
2453 }
2454
2455 void G1CollectedHeap::print_tracing_info() const {
2456 g1_rem_set()->print_summary_info();
2457 concurrent_mark()->print_summary_info();
2458 }
2459
2460 #ifndef PRODUCT
2461 // Helpful for debugging RSet issues.
2462
2463 class PrintRSetsClosure : public HeapRegionClosure {
2464 private:
2465 const char* _msg;
2466 size_t _occupied_sum;
2467
2468 public:
2469 bool doHeapRegion(HeapRegion* r) {
|