12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #include "precompiled.hpp"
25 #include "aot/aotLoader.hpp"
26 #include "classfile/classLoaderDataGraph.hpp"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "classfile/stringTable.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "code/codeCache.hpp"
32 #include "gc/parallel/gcTaskManager.hpp"
33 #include "gc/parallel/parallelArguments.hpp"
34 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
35 #include "gc/parallel/parMarkBitMap.inline.hpp"
36 #include "gc/parallel/pcTasks.hpp"
37 #include "gc/parallel/psAdaptiveSizePolicy.hpp"
38 #include "gc/parallel/psCompactionManager.inline.hpp"
39 #include "gc/parallel/psOldGen.hpp"
40 #include "gc/parallel/psParallelCompact.inline.hpp"
41 #include "gc/parallel/psPromotionManager.inline.hpp"
42 #include "gc/parallel/psScavenge.hpp"
43 #include "gc/parallel/psYoungGen.hpp"
44 #include "gc/shared/gcCause.hpp"
45 #include "gc/shared/gcHeapSummary.hpp"
46 #include "gc/shared/gcId.hpp"
47 #include "gc/shared/gcLocker.hpp"
48 #include "gc/shared/gcTimer.hpp"
49 #include "gc/shared/gcTrace.hpp"
50 #include "gc/shared/gcTraceTime.inline.hpp"
51 #include "gc/shared/isGCActiveMark.hpp"
52 #include "gc/shared/referencePolicy.hpp"
53 #include "gc/shared/referenceProcessor.hpp"
54 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
55 #include "gc/shared/spaceDecorator.hpp"
56 #include "gc/shared/weakProcessor.hpp"
57 #include "logging/log.hpp"
58 #include "memory/iterator.inline.hpp"
59 #include "memory/resourceArea.hpp"
60 #include "memory/universe.hpp"
61 #include "oops/access.inline.hpp"
62 #include "oops/instanceClassLoaderKlass.inline.hpp"
63 #include "oops/instanceKlass.inline.hpp"
64 #include "oops/instanceMirrorKlass.inline.hpp"
65 #include "oops/methodData.hpp"
66 #include "oops/objArrayKlass.inline.hpp"
67 #include "oops/oop.inline.hpp"
68 #include "runtime/atomic.hpp"
69 #include "runtime/handles.inline.hpp"
70 #include "runtime/safepoint.hpp"
71 #include "runtime/vmThread.hpp"
72 #include "services/management.hpp"
73 #include "services/memTracker.hpp"
74 #include "services/memoryService.hpp"
75 #include "utilities/align.hpp"
76 #include "utilities/debug.hpp"
77 #include "utilities/events.hpp"
78 #include "utilities/formatBuffer.hpp"
79 #include "utilities/macros.hpp"
80 #include "utilities/stack.inline.hpp"
81 #if INCLUDE_JVMCI
82 #include "jvmci/jvmci.hpp"
83 #endif
84
85 #include <math.h>
86
87 // All sizes are in HeapWords.
88 const size_t ParallelCompactData::Log2RegionSize = 16; // 64K words
89 const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize;
90 const size_t ParallelCompactData::RegionSizeBytes =
91 RegionSize << LogHeapWordSize;
92 const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1;
93 const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1;
94 const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask;
95
96 const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words
97 const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize;
98 const size_t ParallelCompactData::BlockSizeBytes =
99 BlockSize << LogHeapWordSize;
100 const size_t ParallelCompactData::BlockSizeOffsetMask = BlockSize - 1;
101 const size_t ParallelCompactData::BlockAddrOffsetMask = BlockSizeBytes - 1;
102 const size_t ParallelCompactData::BlockAddrMask = ~BlockAddrOffsetMask;
|
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #include "precompiled.hpp"
25 #include "aot/aotLoader.hpp"
26 #include "classfile/classLoaderDataGraph.hpp"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "classfile/stringTable.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "code/codeCache.hpp"
32 #include "gc/parallel/parallelArguments.hpp"
33 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
34 #include "gc/parallel/parMarkBitMap.inline.hpp"
35 #include "gc/parallel/psAdaptiveSizePolicy.hpp"
36 #include "gc/parallel/psCompactionManager.inline.hpp"
37 #include "gc/parallel/psOldGen.hpp"
38 #include "gc/parallel/psParallelCompact.inline.hpp"
39 #include "gc/parallel/psPromotionManager.inline.hpp"
40 #include "gc/parallel/psRootType.inline.hpp"
41 #include "gc/parallel/psScavenge.hpp"
42 #include "gc/parallel/psYoungGen.hpp"
43 #include "gc/shared/gcCause.hpp"
44 #include "gc/shared/gcHeapSummary.hpp"
45 #include "gc/shared/gcId.hpp"
46 #include "gc/shared/gcLocker.hpp"
47 #include "gc/shared/gcTimer.hpp"
48 #include "gc/shared/gcTrace.hpp"
49 #include "gc/shared/gcTraceTime.inline.hpp"
50 #include "gc/shared/isGCActiveMark.hpp"
51 #include "gc/shared/referencePolicy.hpp"
52 #include "gc/shared/referenceProcessor.hpp"
53 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
54 #include "gc/shared/spaceDecorator.hpp"
55 #include "gc/shared/weakProcessor.hpp"
56 #include "gc/shared/workerPolicy.hpp"
57 #include "gc/shared/workgroup.hpp"
58 #if INCLUDE_JVMCI
59 #include "jvmci/jvmci.hpp"
60 #endif
61 #include "logging/log.hpp"
62 #include "memory/iterator.inline.hpp"
63 #include "memory/resourceArea.hpp"
64 #include "memory/universe.hpp"
65 #include "oops/access.inline.hpp"
66 #include "oops/instanceClassLoaderKlass.inline.hpp"
67 #include "oops/instanceKlass.inline.hpp"
68 #include "oops/instanceMirrorKlass.inline.hpp"
69 #include "oops/methodData.hpp"
70 #include "oops/objArrayKlass.inline.hpp"
71 #include "oops/oop.inline.hpp"
72 #include "runtime/atomic.hpp"
73 #include "runtime/handles.inline.hpp"
74 #include "runtime/safepoint.hpp"
75 #include "runtime/vmThread.hpp"
76 #include "services/management.hpp"
77 #include "services/memTracker.hpp"
78 #include "services/memoryService.hpp"
79 #include "utilities/align.hpp"
80 #include "utilities/debug.hpp"
81 #include "utilities/events.hpp"
82 #include "utilities/formatBuffer.hpp"
83 #include "utilities/macros.hpp"
84 #include "utilities/stack.inline.hpp"
85
86 #include <math.h>
87
88 // All sizes are in HeapWords.
89 const size_t ParallelCompactData::Log2RegionSize = 16; // 64K words
90 const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize;
91 const size_t ParallelCompactData::RegionSizeBytes =
92 RegionSize << LogHeapWordSize;
93 const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1;
94 const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1;
95 const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask;
96
97 const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words
98 const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize;
99 const size_t ParallelCompactData::BlockSizeBytes =
100 BlockSize << LogHeapWordSize;
101 const size_t ParallelCompactData::BlockSizeOffsetMask = BlockSize - 1;
102 const size_t ParallelCompactData::BlockAddrOffsetMask = BlockSizeBytes - 1;
103 const size_t ParallelCompactData::BlockAddrMask = ~BlockAddrOffsetMask;
|
998 heap->print_heap_before_gc();
999 heap->trace_heap_before_gc(&_gc_tracer);
1000
1001 // Fill in TLABs
1002 heap->ensure_parsability(true); // retire TLABs
1003
1004 if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {
1005 HandleMark hm; // Discard invalid handles created during verification
1006 Universe::verify("Before GC");
1007 }
1008
1009 // Verify object start arrays
1010 if (VerifyObjectStartArray &&
1011 VerifyBeforeGC) {
1012 heap->old_gen()->verify_object_start_array();
1013 }
1014
1015 DEBUG_ONLY(mark_bitmap()->verify_clear();)
1016 DEBUG_ONLY(summary_data().verify_clear();)
1017
1018 // Have worker threads release resources the next time they run a task.
1019 gc_task_manager()->release_all_resources();
1020
1021 ParCompactionManager::reset_all_bitmap_query_caches();
1022 }
1023
1024 void PSParallelCompact::post_compact()
1025 {
1026 GCTraceTime(Info, gc, phases) tm("Post Compact", &_gc_timer);
1027
1028 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
1029 // Clear the marking bitmap, summary data and split info.
1030 clear_data_covering_space(SpaceId(id));
1031 // Update top(). Must be done after clearing the bitmap and summary data.
1032 _space_info[id].publish_new_top();
1033 }
1034
1035 MutableSpace* const eden_space = _space_info[eden_space_id].space();
1036 MutableSpace* const from_space = _space_info[from_space_id].space();
1037 MutableSpace* const to_space = _space_info[to_space_id].space();
1038
1039 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
|
999 heap->print_heap_before_gc();
1000 heap->trace_heap_before_gc(&_gc_tracer);
1001
1002 // Fill in TLABs
1003 heap->ensure_parsability(true); // retire TLABs
1004
1005 if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {
1006 HandleMark hm; // Discard invalid handles created during verification
1007 Universe::verify("Before GC");
1008 }
1009
1010 // Verify object start arrays
1011 if (VerifyObjectStartArray &&
1012 VerifyBeforeGC) {
1013 heap->old_gen()->verify_object_start_array();
1014 }
1015
1016 DEBUG_ONLY(mark_bitmap()->verify_clear();)
1017 DEBUG_ONLY(summary_data().verify_clear();)
1018
1019 ParCompactionManager::reset_all_bitmap_query_caches();
1020 }
1021
1022 void PSParallelCompact::post_compact()
1023 {
1024 GCTraceTime(Info, gc, phases) tm("Post Compact", &_gc_timer);
1025
1026 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
1027 // Clear the marking bitmap, summary data and split info.
1028 clear_data_covering_space(SpaceId(id));
1029 // Update top(). Must be done after clearing the bitmap and summary data.
1030 _space_info[id].publish_new_top();
1031 }
1032
1033 MutableSpace* const eden_space = _space_info[eden_space_id].space();
1034 MutableSpace* const from_space = _space_info[from_space_id].space();
1035 MutableSpace* const to_space = _space_info[to_space_id].space();
1036
1037 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
|
1766 PSAdaptiveSizePolicy* size_policy = heap->size_policy();
1767
1768 // The scope of casr should end after code that can change
1769 // SoftRefPolicy::_should_clear_all_soft_refs.
1770 ClearedAllSoftRefs casr(maximum_heap_compaction,
1771 heap->soft_ref_policy());
1772
1773 if (ZapUnusedHeapArea) {
1774 // Save information needed to minimize mangling
1775 heap->record_gen_tops_before_GC();
1776 }
1777
1778 // Make sure data structures are sane, make the heap parsable, and do other
1779 // miscellaneous bookkeeping.
1780 pre_compact();
1781
1782 PreGCValues pre_gc_values(heap);
1783
1784 // Get the compaction manager reserved for the VM thread.
1785 ParCompactionManager* const vmthread_cm =
1786 ParCompactionManager::manager_array(gc_task_manager()->workers());
1787
1788 {
1789 ResourceMark rm;
1790 HandleMark hm;
1791
1792 // Set the number of GC threads to be used in this collection
1793 gc_task_manager()->set_active_gang();
1794 gc_task_manager()->task_idle_workers();
1795
1796 GCTraceCPUTime tcpu;
1797 GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause, true);
1798
1799 heap->pre_full_gc_dump(&_gc_timer);
1800
1801 TraceCollectorStats tcs(counters());
1802 TraceMemoryManagerStats tms(heap->old_gc_manager(), gc_cause);
1803
1804 if (log_is_enabled(Debug, gc, heap, exit)) {
1805 accumulated_time()->start();
1806 }
1807
1808 // Let the size policy know we're starting
1809 size_policy->major_collection_begin();
1810
1811 #if COMPILER2_OR_JVMCI
1812 DerivedPointerTable::clear();
1813 #endif
|
1764 PSAdaptiveSizePolicy* size_policy = heap->size_policy();
1765
1766 // The scope of casr should end after code that can change
1767 // SoftRefPolicy::_should_clear_all_soft_refs.
1768 ClearedAllSoftRefs casr(maximum_heap_compaction,
1769 heap->soft_ref_policy());
1770
1771 if (ZapUnusedHeapArea) {
1772 // Save information needed to minimize mangling
1773 heap->record_gen_tops_before_GC();
1774 }
1775
1776 // Make sure data structures are sane, make the heap parsable, and do other
1777 // miscellaneous bookkeeping.
1778 pre_compact();
1779
1780 PreGCValues pre_gc_values(heap);
1781
1782 // Get the compaction manager reserved for the VM thread.
1783 ParCompactionManager* const vmthread_cm =
1784 ParCompactionManager::manager_array(ParallelScavengeHeap::heap()->workers().total_workers());
1785
1786 {
1787 ResourceMark rm;
1788 HandleMark hm;
1789
1790 ParallelScavengeHeap::heap()->workers().update_active_workers(WorkerPolicy::calc_active_workers(
1791 ParallelScavengeHeap::heap()->workers().total_workers(),
1792 ParallelScavengeHeap::heap()->workers().active_workers(),
1793 Threads::number_of_non_daemon_threads()));
1794
1795 GCTraceCPUTime tcpu;
1796 GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause, true);
1797
1798 heap->pre_full_gc_dump(&_gc_timer);
1799
1800 TraceCollectorStats tcs(counters());
1801 TraceMemoryManagerStats tms(heap->old_gc_manager(), gc_cause);
1802
1803 if (log_is_enabled(Debug, gc, heap, exit)) {
1804 accumulated_time()->start();
1805 }
1806
1807 // Let the size policy know we're starting
1808 size_policy->major_collection_begin();
1809
1810 #if COMPILER2_OR_JVMCI
1811 DerivedPointerTable::clear();
1812 #endif
|
1913 counters->update_old_capacity(old_gen->capacity_in_bytes());
1914 counters->update_young_capacity(young_gen->capacity_in_bytes());
1915 }
1916
1917 heap->resize_all_tlabs();
1918
1919 // Resize the metaspace capacity after a collection
1920 MetaspaceGC::compute_new_size();
1921
1922 if (log_is_enabled(Debug, gc, heap, exit)) {
1923 accumulated_time()->stop();
1924 }
1925
1926 young_gen->print_used_change(pre_gc_values.young_gen_used());
1927 old_gen->print_used_change(pre_gc_values.old_gen_used());
1928 MetaspaceUtils::print_metaspace_change(pre_gc_values.metadata_used());
1929
1930 // Track memory usage and detect low memory
1931 MemoryService::track_memory_usage();
1932 heap->update_counters();
1933 gc_task_manager()->release_idle_workers();
1934
1935 heap->post_full_gc_dump(&_gc_timer);
1936 }
1937
1938 #ifdef ASSERT
1939 for (size_t i = 0; i < ParallelGCThreads + 1; ++i) {
1940 ParCompactionManager* const cm =
1941 ParCompactionManager::manager_array(int(i));
1942 assert(cm->marking_stack()->is_empty(), "should be empty");
1943 assert(cm->region_stack()->is_empty(), "Region stack " SIZE_FORMAT " is not empty", i);
1944 }
1945 #endif // ASSERT
1946
1947 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
1948 HandleMark hm; // Discard invalid handles created during verification
1949 Universe::verify("After GC");
1950 }
1951
1952 // Re-verify object start arrays
1953 if (VerifyObjectStartArray &&
1954 VerifyAfterGC) {
1955 old_gen->verify_object_start_array();
1956 }
1957
1958 if (ZapUnusedHeapArea) {
1959 old_gen->object_space()->check_mangled_unused_area_complete();
1960 }
1961
1962 NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
1963
1964 collection_exit.update();
1965
1966 heap->print_heap_after_gc();
1967 heap->trace_heap_after_gc(&_gc_tracer);
1968
1969 log_debug(gc, task, time)("VM-Thread " JLONG_FORMAT " " JLONG_FORMAT " " JLONG_FORMAT,
1970 marking_start.ticks(), compaction_start.ticks(),
1971 collection_exit.ticks());
1972 gc_task_manager()->print_task_time_stamps();
1973
1974 #ifdef TRACESPINNING
1975 ParallelTaskTerminator::print_termination_counts();
1976 #endif
1977
1978 AdaptiveSizePolicyOutput::print(size_policy, heap->total_collections());
1979
1980 _gc_timer.register_gc_end();
1981
1982 _gc_tracer.report_dense_prefix(dense_prefix(old_space_id));
1983 _gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions());
1984
1985 return true;
1986 }
1987
1988 bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
1989 PSYoungGen* young_gen,
1990 PSOldGen* old_gen) {
1991 MutableSpace* const eden_space = young_gen->eden_space();
1992 assert(!eden_space->is_empty(), "eden must be non-empty");
1993 assert(young_gen->virtual_space()->alignment() ==
1994 old_gen->virtual_space()->alignment(), "alignments do not match");
1995
1996 // We also return false when it's a heterogenous heap because old generation cannot absorb data from eden
1997 // when it is allocated on different memory (example, nv-dimm) than young.
1998 if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary) ||
1999 ParallelArguments::is_heterogeneous_heap()) {
2000 return false;
2001 }
2002
2003 // Both generations must be completely committed.
2004 if (young_gen->virtual_space()->uncommitted_size() != 0) {
2005 return false;
2006 }
2007 if (old_gen->virtual_space()->uncommitted_size() != 0) {
2008 return false;
2009 }
2010
2011 // Figure out how much to take from eden. Include the average amount promoted
2012 // in the total; otherwise the next young gen GC will simply bail out to a
2013 // full GC.
2014 const size_t alignment = old_gen->virtual_space()->alignment();
2015 const size_t eden_used = eden_space->used_in_bytes();
|
1912 counters->update_old_capacity(old_gen->capacity_in_bytes());
1913 counters->update_young_capacity(young_gen->capacity_in_bytes());
1914 }
1915
1916 heap->resize_all_tlabs();
1917
1918 // Resize the metaspace capacity after a collection
1919 MetaspaceGC::compute_new_size();
1920
1921 if (log_is_enabled(Debug, gc, heap, exit)) {
1922 accumulated_time()->stop();
1923 }
1924
1925 young_gen->print_used_change(pre_gc_values.young_gen_used());
1926 old_gen->print_used_change(pre_gc_values.old_gen_used());
1927 MetaspaceUtils::print_metaspace_change(pre_gc_values.metadata_used());
1928
1929 // Track memory usage and detect low memory
1930 MemoryService::track_memory_usage();
1931 heap->update_counters();
1932
1933 heap->post_full_gc_dump(&_gc_timer);
1934 }
1935
1936 #ifdef ASSERT
1937 for (size_t i = 0; i < ParallelGCThreads + 1; ++i) {
1938 ParCompactionManager* const cm =
1939 ParCompactionManager::manager_array(int(i));
1940 assert(cm->marking_stack()->is_empty(), "should be empty");
1941 assert(cm->region_stack()->is_empty(), "Region stack " SIZE_FORMAT " is not empty", i);
1942 }
1943 #endif // ASSERT
1944
1945 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
1946 HandleMark hm; // Discard invalid handles created during verification
1947 Universe::verify("After GC");
1948 }
1949
1950 // Re-verify object start arrays
1951 if (VerifyObjectStartArray &&
1952 VerifyAfterGC) {
1953 old_gen->verify_object_start_array();
1954 }
1955
1956 if (ZapUnusedHeapArea) {
1957 old_gen->object_space()->check_mangled_unused_area_complete();
1958 }
1959
1960 NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
1961
1962 collection_exit.update();
1963
1964 heap->print_heap_after_gc();
1965 heap->trace_heap_after_gc(&_gc_tracer);
1966
1967 log_debug(gc, task, time)("VM-Thread " JLONG_FORMAT " " JLONG_FORMAT " " JLONG_FORMAT,
1968 marking_start.ticks(), compaction_start.ticks(),
1969 collection_exit.ticks());
1970
1971 #ifdef TRACESPINNING
1972 ParallelTaskTerminator::print_termination_counts();
1973 #endif
1974
1975 AdaptiveSizePolicyOutput::print(size_policy, heap->total_collections());
1976
1977 _gc_timer.register_gc_end();
1978
1979 _gc_tracer.report_dense_prefix(dense_prefix(old_space_id));
1980 _gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions());
1981
1982 return true;
1983 }
1984
1985 bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
1986 PSYoungGen* young_gen,
1987 PSOldGen* old_gen) {
1988 MutableSpace* const eden_space = young_gen->eden_space();
1989 assert(!eden_space->is_empty(), "eden must be non-empty");
1990 assert(young_gen->virtual_space()->alignment() ==
1991 old_gen->virtual_space()->alignment(), "alignments do not match");
1992
1993 // We also return false when it's a heterogeneous heap because old generation cannot absorb data from eden
1994 // when it is allocated on different memory (example, nv-dimm) than young.
1995 if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary) ||
1996 ParallelArguments::is_heterogeneous_heap()) {
1997 return false;
1998 }
1999
2000 // Both generations must be completely committed.
2001 if (young_gen->virtual_space()->uncommitted_size() != 0) {
2002 return false;
2003 }
2004 if (old_gen->virtual_space()->uncommitted_size() != 0) {
2005 return false;
2006 }
2007
2008 // Figure out how much to take from eden. Include the average amount promoted
2009 // in the total; otherwise the next young gen GC will simply bail out to a
2010 // full GC.
2011 const size_t alignment = old_gen->virtual_space()->alignment();
2012 const size_t eden_used = eden_space->used_in_bytes();
|
2057 young_gen->reset_after_change();
2058 old_space->set_top(new_top);
2059 old_space->set_end(new_top);
2060 old_gen->reset_after_change();
2061
2062 // Update the object start array for the filler object and the data from eden.
2063 ObjectStartArray* const start_array = old_gen->start_array();
2064 for (HeapWord* p = unused_start; p < new_top; p += oop(p)->size()) {
2065 start_array->allocate_block(p);
2066 }
2067
2068 // Could update the promoted average here, but it is not typically updated at
2069 // full GCs and the value to use is unclear. Something like
2070 //
2071 // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
2072
2073 size_policy->set_bytes_absorbed_from_eden(absorb_size);
2074 return true;
2075 }
2076
2077 GCTaskManager* const PSParallelCompact::gc_task_manager() {
2078 assert(ParallelScavengeHeap::gc_task_manager() != NULL,
2079 "shouldn't return NULL");
2080 return ParallelScavengeHeap::gc_task_manager();
2081 }
2082
2083 class PCAddThreadRootsMarkingTaskClosure : public ThreadClosure {
2084 private:
2085 GCTaskQueue* _q;
2086
2087 public:
2088 PCAddThreadRootsMarkingTaskClosure(GCTaskQueue* q) : _q(q) { }
2089 void do_thread(Thread* t) {
2090 _q->enqueue(new ThreadRootsMarkingTask(t));
2091 }
2092 };
2093
2094 void PSParallelCompact::marking_phase(ParCompactionManager* cm,
2095 bool maximum_heap_compaction,
2096 ParallelOldTracer *gc_tracer) {
2097 // Recursively traverse all live objects and mark them
2098 GCTraceTime(Info, gc, phases) tm("Marking Phase", &_gc_timer);
2099
2100 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2101 uint parallel_gc_threads = heap->gc_task_manager()->workers();
2102 uint active_gc_threads = heap->gc_task_manager()->active_workers();
2103 TaskQueueSetSuper* qset = ParCompactionManager::stack_array();
2104 TaskTerminator terminator(active_gc_threads, qset);
2105
2106 PCMarkAndPushClosure mark_and_push_closure(cm);
2107 ParCompactionManager::FollowStackClosure follow_stack_closure(cm);
2108
2109 // Need new claim bits before marking starts.
2110 ClassLoaderDataGraph::clear_claimed_marks();
2111
2112 {
2113 GCTraceTime(Debug, gc, phases) tm("Par Mark", &_gc_timer);
2114
2115 ParallelScavengeHeap::ParStrongRootsScope psrs;
2116
2117 GCTaskQueue* q = GCTaskQueue::create();
2118
2119 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe));
2120 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles));
2121 // We scan the thread roots in parallel
2122 PCAddThreadRootsMarkingTaskClosure cl(q);
2123 Threads::java_threads_and_vm_thread_do(&cl);
2124 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer));
2125 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management));
2126 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));
2127 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::class_loader_data));
2128 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti));
2129 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache));
2130 JVMCI_ONLY(q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmci));)
2131
2132 if (active_gc_threads > 1) {
2133 for (uint j = 0; j < active_gc_threads; j++) {
2134 q->enqueue(new StealMarkingTask(terminator.terminator()));
2135 }
2136 }
2137
2138 gc_task_manager()->execute_and_wait(q);
2139 }
2140
2141 // Process reference objects found during marking
2142 {
2143 GCTraceTime(Debug, gc, phases) tm("Reference Processing", &_gc_timer);
2144
2145 ReferenceProcessorStats stats;
2146 ReferenceProcessorPhaseTimes pt(&_gc_timer, ref_processor()->max_num_queues());
2147
2148 if (ref_processor()->processing_is_mt()) {
2149 ref_processor()->set_active_mt_degree(active_gc_threads);
2150
2151 RefProcTaskExecutor task_executor;
2152 stats = ref_processor()->process_discovered_references(
2153 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure,
2154 &task_executor, &pt);
2155 } else {
2156 stats = ref_processor()->process_discovered_references(
2157 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL,
|
2054 young_gen->reset_after_change();
2055 old_space->set_top(new_top);
2056 old_space->set_end(new_top);
2057 old_gen->reset_after_change();
2058
2059 // Update the object start array for the filler object and the data from eden.
2060 ObjectStartArray* const start_array = old_gen->start_array();
2061 for (HeapWord* p = unused_start; p < new_top; p += oop(p)->size()) {
2062 start_array->allocate_block(p);
2063 }
2064
2065 // Could update the promoted average here, but it is not typically updated at
2066 // full GCs and the value to use is unclear. Something like
2067 //
2068 // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
2069
2070 size_policy->set_bytes_absorbed_from_eden(absorb_size);
2071 return true;
2072 }
2073
2074 class PCAddThreadRootsMarkingTaskClosure : public ThreadClosure {
2075 private:
2076 uint _worker_id;
2077
2078 public:
2079 PCAddThreadRootsMarkingTaskClosure(uint worker_id) : _worker_id(worker_id) { }
2080 void do_thread(Thread* thread) {
2081 assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
2082
2083 ResourceMark rm;
2084
2085 ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(_worker_id);
2086
2087 PCMarkAndPushClosure mark_and_push_closure(cm);
2088 MarkingCodeBlobClosure mark_and_push_in_blobs(&mark_and_push_closure, !CodeBlobToOopClosure::FixRelocations);
2089
2090 thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
2091
2092 // Do the real work
2093 cm->follow_marking_stacks();
2094 }
2095 };
2096
2097 void mark_from_roots_task(Parallel::RootType::Value root_type, uint which) {
2098 assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
2099
2100 ParCompactionManager* cm =
2101 ParCompactionManager::gc_thread_compaction_manager(which);
2102 PCMarkAndPushClosure mark_and_push_closure(cm);
2103
2104 switch (root_type) {
2105 case Parallel::RootType::universe:
2106 Universe::oops_do(&mark_and_push_closure);
2107 break;
2108
2109 case Parallel::RootType::jni_handles:
2110 JNIHandles::oops_do(&mark_and_push_closure);
2111 break;
2112
2113 case Parallel::RootType::object_synchronizer:
2114 ObjectSynchronizer::oops_do(&mark_and_push_closure);
2115 break;
2116
2117 case Parallel::RootType::management:
2118 Management::oops_do(&mark_and_push_closure);
2119 break;
2120
2121 case Parallel::RootType::jvmti:
2122 JvmtiExport::oops_do(&mark_and_push_closure);
2123 break;
2124
2125 case Parallel::RootType::system_dictionary:
2126 SystemDictionary::oops_do(&mark_and_push_closure);
2127 break;
2128
2129 case Parallel::RootType::class_loader_data:
2130 {
2131 CLDToOopClosure cld_closure(&mark_and_push_closure, ClassLoaderData::_claim_strong);
2132 ClassLoaderDataGraph::always_strong_cld_do(&cld_closure);
2133 }
2134 break;
2135
2136 case Parallel::RootType::code_cache:
2137 // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
2138 //ScavengableNMethods::scavengable_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
2139 AOTLoader::oops_do(&mark_and_push_closure);
2140 break;
2141
2142 #if INCLUDE_JVMCI
2143 case Parallel::RootType::jvmci:
2144 JVMCI::oops_do(&mark_and_push_closure);
2145 break;
2146 #endif
2147
2148 case Parallel::RootType::sentinel:
2149 DEBUG_ONLY(default:) // DEBUG_ONLY hack will create compile error on release builds (-Wswitch) and runtime check on deb
2150 fatal("Bad enumeration value: %u", root_type);
2151 break;
2152 }
2153
2154 // Do the real work
2155 cm->follow_marking_stacks();
2156 }
2157
2158 void steal_marking_task(ParallelTaskTerminator& terminator, uint worker_id) {
2159 assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
2160
2161 ParCompactionManager* cm =
2162 ParCompactionManager::gc_thread_compaction_manager(worker_id);
2163
2164 oop obj = NULL;
2165 ObjArrayTask task;
2166 do {
2167 while (ParCompactionManager::steal_objarray(worker_id, task)) {
2168 cm->follow_array((objArrayOop)task.obj(), task.index());
2169 cm->follow_marking_stacks();
2170 }
2171 while (ParCompactionManager::steal(worker_id, obj)) {
2172 cm->follow_contents(obj);
2173 cm->follow_marking_stacks();
2174 }
2175 } while (!terminator.offer_termination());
2176 }
2177
2178 class MarkFromRootsTask : public AbstractGangTask {
2179 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
2180 StrongRootsScope _strong_roots_scope; // needed for Threads::possibly_parallel_threads_do
2181 EnumClaimer<Parallel::RootType::Value> _enum_claimer;
2182 TaskTerminator _terminator;
2183 uint _active_workers;
2184
2185 public:
2186 MarkFromRootsTask(uint active_workers)
2187 : AbstractGangTask("MarkFromRootsTask"),
2188 _strong_roots_scope(active_workers),
2189 _enum_claimer(Parallel::RootType::sentinel),
2190 _terminator(active_workers, ParCompactionManager::stack_array()),
2191 _active_workers(active_workers) {}
2192
2193 virtual void work(uint worker_id) {
2194 for (Parallel::RootType::Value root_type; _enum_claimer.try_claim(root_type); /* empty */) {
2195 mark_from_roots_task(root_type, worker_id);
2196 }
2197
2198 PCAddThreadRootsMarkingTaskClosure closure(worker_id);
2199 Threads::possibly_parallel_threads_do(true /*parallel */, &closure);
2200
2201 if (_active_workers > 1) {
2202 steal_marking_task(*_terminator.terminator(), worker_id);
2203 }
2204 }
2205 };
2206
2207 class PCRefProcTask : public AbstractGangTask {
2208 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
2209 ProcessTask& _task;
2210 uint _ergo_workers;
2211 TaskTerminator _terminator;
2212
2213 public:
2214 PCRefProcTask(ProcessTask& task, uint ergo_workers)
2215 : AbstractGangTask("PCRefProcTask"),
2216 _task(task),
2217 _ergo_workers(ergo_workers),
2218 _terminator(_ergo_workers, ParCompactionManager::stack_array()) {
2219 }
2220
2221 virtual void work(uint worker_id) {
2222 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2223 assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
2224
2225 ParCompactionManager* cm =
2226 ParCompactionManager::gc_thread_compaction_manager(worker_id);
2227 PCMarkAndPushClosure mark_and_push_closure(cm);
2228 ParCompactionManager::FollowStackClosure follow_stack_closure(cm);
2229 _task.work(worker_id, *PSParallelCompact::is_alive_closure(),
2230 mark_and_push_closure, follow_stack_closure);
2231
2232 steal_marking_task(*_terminator.terminator(), worker_id);
2233 }
2234 };
2235
2236 class RefProcTaskExecutor: public AbstractRefProcTaskExecutor {
2237 void execute(ProcessTask& process_task, uint ergo_workers) {
2238 assert(ParallelScavengeHeap::heap()->workers().active_workers() == ergo_workers,
2239 "Ergonomically chosen workers (%u) must be equal to active workers (%u)",
2240 ergo_workers, ParallelScavengeHeap::heap()->workers().active_workers());
2241
2242 PCRefProcTask task(process_task, ergo_workers);
2243 ParallelScavengeHeap::heap()->workers().run_task(&task);
2244 }
2245 };
2246
2247 void PSParallelCompact::marking_phase(ParCompactionManager* cm,
2248 bool maximum_heap_compaction,
2249 ParallelOldTracer *gc_tracer) {
2250 // Recursively traverse all live objects and mark them
2251 GCTraceTime(Info, gc, phases) tm("Marking Phase", &_gc_timer);
2252
2253 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2254 uint active_gc_threads = ParallelScavengeHeap::heap()->workers().active_workers();
2255
2256 PCMarkAndPushClosure mark_and_push_closure(cm);
2257 ParCompactionManager::FollowStackClosure follow_stack_closure(cm);
2258
2259 // Need new claim bits before marking starts.
2260 ClassLoaderDataGraph::clear_claimed_marks();
2261
2262 {
2263 GCTraceTime(Debug, gc, phases) tm("Par Mark", &_gc_timer);
2264
2265 MarkFromRootsTask task(active_gc_threads);
2266 ParallelScavengeHeap::heap()->workers().run_task(&task);
2267 }
2268
2269 // Process reference objects found during marking
2270 {
2271 GCTraceTime(Debug, gc, phases) tm("Reference Processing", &_gc_timer);
2272
2273 ReferenceProcessorStats stats;
2274 ReferenceProcessorPhaseTimes pt(&_gc_timer, ref_processor()->max_num_queues());
2275
2276 if (ref_processor()->processing_is_mt()) {
2277 ref_processor()->set_active_mt_degree(active_gc_threads);
2278
2279 RefProcTaskExecutor task_executor;
2280 stats = ref_processor()->process_discovered_references(
2281 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure,
2282 &task_executor, &pt);
2283 } else {
2284 stats = ref_processor()->process_discovered_references(
2285 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL,
|
2249 FormatBuffer<> line("Fillable: ");
2250 for (int i = 0; i < _next_index; i++) {
2251 line.append(" " SIZE_FORMAT_W(7), _regions[i]);
2252 }
2253 log.trace("%s", line.buffer());
2254 _next_index = 0;
2255 }
2256
2257 void handle(size_t region) {
2258 if (!_enabled) {
2259 return;
2260 }
2261 _regions[_next_index++] = region;
2262 if (_next_index == LineLength) {
2263 print_line();
2264 }
2265 _total_regions++;
2266 }
2267 };
2268
2269 void PSParallelCompact::prepare_region_draining_tasks(GCTaskQueue* q,
2270 uint parallel_gc_threads)
2271 {
2272 GCTraceTime(Trace, gc, phases) tm("Drain Task Setup", &_gc_timer);
2273
2274 // Find the threads that are active
2275 unsigned int which = 0;
2276
2277 // Find all regions that are available (can be filled immediately) and
2278 // distribute them to the thread stacks. The iteration is done in reverse
2279 // order (high to low) so the regions will be removed in ascending order.
2280
2281 const ParallelCompactData& sd = PSParallelCompact::summary_data();
2282
2283 which = 0;
2284 // id + 1 is used to test termination so unsigned can
2285 // be used with an old_space_id == 0.
2286 FillableRegionLogger region_logger;
2287 for (unsigned int id = to_space_id; id + 1 > old_space_id; --id) {
2288 SpaceInfo* const space_info = _space_info + id;
2289 MutableSpace* const space = space_info->space();
2290 HeapWord* const new_top = space_info->new_top();
2291
2292 const size_t beg_region = sd.addr_to_region_idx(space_info->dense_prefix());
2293 const size_t end_region =
2294 sd.addr_to_region_idx(sd.region_align_up(new_top));
2295
2296 for (size_t cur = end_region - 1; cur + 1 > beg_region; --cur) {
2297 if (sd.region(cur)->claim_unsafe()) {
2298 ParCompactionManager* cm = ParCompactionManager::manager_array(which);
2299 cm->region_stack()->push(cur);
2300 region_logger.handle(cur);
2301 // Assign regions to tasks in round-robin fashion.
2302 if (++which == parallel_gc_threads) {
2303 which = 0;
2304 }
2305 }
2306 }
2307 region_logger.print_line();
2308 }
2309 }
2310
2311 #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4
2312
2313 void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q,
2314 uint parallel_gc_threads) {
2315 GCTraceTime(Trace, gc, phases) tm("Dense Prefix Task Setup", &_gc_timer);
2316
2317 ParallelCompactData& sd = PSParallelCompact::summary_data();
2318
2319 // Iterate over all the spaces adding tasks for updating
2320 // regions in the dense prefix. Assume that 1 gc thread
2321 // will work on opening the gaps and the remaining gc threads
2322 // will work on the dense prefix.
2323 unsigned int space_id;
2324 for (space_id = old_space_id; space_id < last_space_id; ++ space_id) {
2325 HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix();
2326 const MutableSpace* const space = _space_info[space_id].space();
2327
2328 if (dense_prefix_end == space->bottom()) {
2329 // There is no dense prefix for this space.
2330 continue;
2331 }
2332
2333 // The dense prefix is before this region.
|
2377 FormatBuffer<> line("Fillable: ");
2378 for (int i = 0; i < _next_index; i++) {
2379 line.append(" " SIZE_FORMAT_W(7), _regions[i]);
2380 }
2381 log.trace("%s", line.buffer());
2382 _next_index = 0;
2383 }
2384
2385 void handle(size_t region) {
2386 if (!_enabled) {
2387 return;
2388 }
2389 _regions[_next_index++] = region;
2390 if (_next_index == LineLength) {
2391 print_line();
2392 }
2393 _total_regions++;
2394 }
2395 };
2396
2397 void PSParallelCompact::prepare_region_draining_tasks(uint parallel_gc_threads)
2398 {
2399 GCTraceTime(Trace, gc, phases) tm("Drain Task Setup", &_gc_timer);
2400
2401 // Find the threads that are active
2402 unsigned int which = 0;
2403
2404 // Find all regions that are available (can be filled immediately) and
2405 // distribute them to the thread stacks. The iteration is done in reverse
2406 // order (high to low) so the regions will be removed in ascending order.
2407
2408 const ParallelCompactData& sd = PSParallelCompact::summary_data();
2409
2410 // id + 1 is used to test termination so unsigned can
2411 // be used with an old_space_id == 0.
2412 FillableRegionLogger region_logger;
2413 for (unsigned int id = to_space_id; id + 1 > old_space_id; --id) {
2414 SpaceInfo* const space_info = _space_info + id;
2415 MutableSpace* const space = space_info->space();
2416 HeapWord* const new_top = space_info->new_top();
2417
2418 const size_t beg_region = sd.addr_to_region_idx(space_info->dense_prefix());
2419 const size_t end_region =
2420 sd.addr_to_region_idx(sd.region_align_up(new_top));
2421
2422 for (size_t cur = end_region - 1; cur + 1 > beg_region; --cur) {
2423 if (sd.region(cur)->claim_unsafe()) {
2424 ParCompactionManager* cm = ParCompactionManager::manager_array(which);
2425 cm->region_stack()->push(cur);
2426 region_logger.handle(cur);
2427 // Assign regions to tasks in round-robin fashion.
2428 if (++which == parallel_gc_threads) {
2429 which = 0;
2430 }
2431 }
2432 }
2433 region_logger.print_line();
2434 }
2435 }
2436
2437 class TaskQueue : StackObj {
2438 volatile uint _counter;
2439 uint _size;
2440 uint _insert_index;
2441 PSParallelCompact::UpdateDensePrefixTask* _backing_array;
2442 public:
2443 TaskQueue(uint size) : _counter(0), _size(size), _insert_index(0), _backing_array(NULL) {
2444 _backing_array = NEW_C_HEAP_ARRAY(PSParallelCompact::UpdateDensePrefixTask, _size, mtGC);
2445 guarantee(_backing_array != NULL, "alloc failure");
2446 }
2447 ~TaskQueue() {
2448 assert(_counter >= _insert_index, "not all queue elements were claimed");
2449 FREE_C_HEAP_ARRAY(T, _backing_array);
2450 }
2451
2452 void push(const PSParallelCompact::UpdateDensePrefixTask& value) {
2453 assert(_insert_index < _size, "to small backing array");
2454 _backing_array[_insert_index++] = value;
2455 }
2456
2457 bool try_claim(PSParallelCompact::UpdateDensePrefixTask& reference) {
2458 uint claimed = Atomic::add(1u, &_counter) - 1; // -1 is so that we start with zero
2459 if (claimed < _insert_index) {
2460 reference = _backing_array[claimed];
2461 return true;
2462 } else {
2463 return false;
2464 }
2465 }
2466 };
2467
2468 #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4
2469
2470 void PSParallelCompact::enqueue_dense_prefix_tasks(TaskQueue& task_queue,
2471 uint parallel_gc_threads) {
2472 GCTraceTime(Trace, gc, phases) tm("Dense Prefix Task Setup", &_gc_timer);
2473
2474 ParallelCompactData& sd = PSParallelCompact::summary_data();
2475
2476 // Iterate over all the spaces adding tasks for updating
2477 // regions in the dense prefix. Assume that 1 gc thread
2478 // will work on opening the gaps and the remaining gc threads
2479 // will work on the dense prefix.
2480 unsigned int space_id;
2481 for (space_id = old_space_id; space_id < last_space_id; ++ space_id) {
2482 HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix();
2483 const MutableSpace* const space = _space_info[space_id].space();
2484
2485 if (dense_prefix_end == space->bottom()) {
2486 // There is no dense prefix for this space.
2487 continue;
2488 }
2489
2490 // The dense prefix is before this region.
|
2357 tasks_for_dense_prefix = parallel_gc_threads;
2358 } else {
2359 // Over partition
2360 tasks_for_dense_prefix = parallel_gc_threads *
2361 PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING;
2362 }
2363 size_t regions_per_thread = total_dense_prefix_regions /
2364 tasks_for_dense_prefix;
2365 // Give each thread at least 1 region.
2366 if (regions_per_thread == 0) {
2367 regions_per_thread = 1;
2368 }
2369
2370 for (uint k = 0; k < tasks_for_dense_prefix; k++) {
2371 if (region_index_start >= region_index_end_dense_prefix) {
2372 break;
2373 }
2374 // region_index_end is not processed
2375 size_t region_index_end = MIN2(region_index_start + regions_per_thread,
2376 region_index_end_dense_prefix);
2377 q->enqueue(new UpdateDensePrefixTask(SpaceId(space_id),
2378 region_index_start,
2379 region_index_end));
2380 region_index_start = region_index_end;
2381 }
2382 }
2383 // This gets any part of the dense prefix that did not
2384 // fit evenly.
2385 if (region_index_start < region_index_end_dense_prefix) {
2386 q->enqueue(new UpdateDensePrefixTask(SpaceId(space_id),
2387 region_index_start,
2388 region_index_end_dense_prefix));
2389 }
2390 }
2391 }
2392
2393 void PSParallelCompact::enqueue_region_stealing_tasks(
2394 GCTaskQueue* q,
2395 ParallelTaskTerminator* terminator_ptr,
2396 uint parallel_gc_threads) {
2397 GCTraceTime(Trace, gc, phases) tm("Steal Task Setup", &_gc_timer);
2398
2399 // Once a thread has drained it's stack, it should try to steal regions from
2400 // other threads.
2401 for (uint j = 0; j < parallel_gc_threads; j++) {
2402 q->enqueue(new CompactionWithStealingTask(terminator_ptr));
2403 }
2404 }
2405
2406 #ifdef ASSERT
2407 // Write a histogram of the number of times the block table was filled for a
2408 // region.
2409 void PSParallelCompact::write_block_fill_histogram()
2410 {
2411 if (!log_develop_is_enabled(Trace, gc, compaction)) {
2412 return;
2413 }
2414
2415 Log(gc, compaction) log;
2416 ResourceMark rm;
2417 LogStream ls(log.trace());
2418 outputStream* out = &ls;
2419
2420 typedef ParallelCompactData::RegionData rd_t;
2421 ParallelCompactData& sd = summary_data();
2422
2423 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
2424 MutableSpace* const spc = _space_info[id].space();
|
2514 tasks_for_dense_prefix = parallel_gc_threads;
2515 } else {
2516 // Over partition
2517 tasks_for_dense_prefix = parallel_gc_threads *
2518 PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING;
2519 }
2520 size_t regions_per_thread = total_dense_prefix_regions /
2521 tasks_for_dense_prefix;
2522 // Give each thread at least 1 region.
2523 if (regions_per_thread == 0) {
2524 regions_per_thread = 1;
2525 }
2526
2527 for (uint k = 0; k < tasks_for_dense_prefix; k++) {
2528 if (region_index_start >= region_index_end_dense_prefix) {
2529 break;
2530 }
2531 // region_index_end is not processed
2532 size_t region_index_end = MIN2(region_index_start + regions_per_thread,
2533 region_index_end_dense_prefix);
2534 task_queue.push(UpdateDensePrefixTask(SpaceId(space_id),
2535 region_index_start,
2536 region_index_end));
2537 region_index_start = region_index_end;
2538 }
2539 }
2540 // This gets any part of the dense prefix that did not
2541 // fit evenly.
2542 if (region_index_start < region_index_end_dense_prefix) {
2543 task_queue.push(UpdateDensePrefixTask(SpaceId(space_id),
2544 region_index_start,
2545 region_index_end_dense_prefix));
2546 }
2547 }
2548 }
2549
2550 #ifdef ASSERT
2551 // Write a histogram of the number of times the block table was filled for a
2552 // region.
2553 void PSParallelCompact::write_block_fill_histogram()
2554 {
2555 if (!log_develop_is_enabled(Trace, gc, compaction)) {
2556 return;
2557 }
2558
2559 Log(gc, compaction) log;
2560 ResourceMark rm;
2561 LogStream ls(log.trace());
2562 outputStream* out = &ls;
2563
2564 typedef ParallelCompactData::RegionData rd_t;
2565 ParallelCompactData& sd = summary_data();
2566
2567 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
2568 MutableSpace* const spc = _space_info[id].space();
|
2428 const rd_t* const end = sd.addr_to_region_ptr(top_aligned_up);
2429
2430 size_t histo[5] = { 0, 0, 0, 0, 0 };
2431 const size_t histo_len = sizeof(histo) / sizeof(size_t);
2432 const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t));
2433
2434 for (const rd_t* cur = beg; cur < end; ++cur) {
2435 ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)];
2436 }
2437 out->print("Block fill histogram: %u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt);
2438 for (size_t i = 0; i < histo_len; ++i) {
2439 out->print(" " SIZE_FORMAT_W(5) " %5.1f%%",
2440 histo[i], 100.0 * histo[i] / region_cnt);
2441 }
2442 out->cr();
2443 }
2444 }
2445 }
2446 #endif // #ifdef ASSERT
2447
2448 void PSParallelCompact::compact() {
2449 GCTraceTime(Info, gc, phases) tm("Compaction Phase", &_gc_timer);
2450
2451 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2452 PSOldGen* old_gen = heap->old_gen();
2453 old_gen->start_array()->reset();
2454 uint parallel_gc_threads = heap->gc_task_manager()->workers();
2455 uint active_gc_threads = heap->gc_task_manager()->active_workers();
2456 TaskQueueSetSuper* qset = ParCompactionManager::region_array();
2457 TaskTerminator terminator(active_gc_threads, qset);
2458
2459 GCTaskQueue* q = GCTaskQueue::create();
2460 prepare_region_draining_tasks(q, active_gc_threads);
2461 enqueue_dense_prefix_tasks(q, active_gc_threads);
2462 enqueue_region_stealing_tasks(q, terminator.terminator(), active_gc_threads);
2463
2464 {
2465 GCTraceTime(Trace, gc, phases) tm("Par Compact", &_gc_timer);
2466
2467 gc_task_manager()->execute_and_wait(q);
2468
2469 #ifdef ASSERT
2470 // Verify that all regions have been processed before the deferred updates.
2471 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
2472 verify_complete(SpaceId(id));
2473 }
2474 #endif
2475 }
2476
2477 {
2478 // Update the deferred objects, if any. Any compaction manager can be used.
2479 GCTraceTime(Trace, gc, phases) tm("Deferred Updates", &_gc_timer);
2480 ParCompactionManager* cm = ParCompactionManager::manager_array(0);
2481 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
2482 update_deferred_objects(cm, SpaceId(id));
2483 }
2484 }
2485
2486 DEBUG_ONLY(write_block_fill_histogram());
|
2572 const rd_t* const end = sd.addr_to_region_ptr(top_aligned_up);
2573
2574 size_t histo[5] = { 0, 0, 0, 0, 0 };
2575 const size_t histo_len = sizeof(histo) / sizeof(size_t);
2576 const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t));
2577
2578 for (const rd_t* cur = beg; cur < end; ++cur) {
2579 ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)];
2580 }
2581 out->print("Block fill histogram: %u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt);
2582 for (size_t i = 0; i < histo_len; ++i) {
2583 out->print(" " SIZE_FORMAT_W(5) " %5.1f%%",
2584 histo[i], 100.0 * histo[i] / region_cnt);
2585 }
2586 out->cr();
2587 }
2588 }
2589 }
2590 #endif // #ifdef ASSERT
2591
2592 //
2593 // CompactionWithStealingTask
2594 //
2595
2596 void compaction_with_stealing_task(ParallelTaskTerminator* terminator, uint which) {
2597 assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
2598
2599 ParCompactionManager* cm =
2600 ParCompactionManager::gc_thread_compaction_manager(which);
2601
2602 // Drain the stacks that have been preloaded with regions
2603 // that are ready to fill.
2604
2605 cm->drain_region_stacks();
2606
2607 guarantee(cm->region_stack()->is_empty(), "Not empty");
2608
2609 size_t region_index = 0;
2610
2611 while (true) {
2612 if (ParCompactionManager::steal(which, region_index)) {
2613 PSParallelCompact::fill_and_update_region(cm, region_index);
2614 cm->drain_region_stacks();
2615 } else {
2616 if (terminator->offer_termination()) {
2617 break;
2618 }
2619 // Go around again.
2620 }
2621 }
2622 return;
2623 }
2624
2625 class UpdateDensePrefixAndCompactionTask: public AbstractGangTask {
2626 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
2627 TaskQueue& _tq;
2628 TaskTerminator _terminator;
2629 uint _active_workers;
2630
2631 public:
2632 UpdateDensePrefixAndCompactionTask(TaskQueue& tq, uint active_workers) :
2633 AbstractGangTask("UpdateDensePrefixAndCompactionTask"),
2634 _tq(tq),
2635 _terminator(active_workers, ParCompactionManager::region_array()),
2636 _active_workers(active_workers) {
2637 }
2638 virtual void work(uint worker_id) {
2639 ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(worker_id);
2640
2641 for (PSParallelCompact::UpdateDensePrefixTask task; _tq.try_claim(task); /* empty */) {
2642 PSParallelCompact::update_and_deadwood_in_dense_prefix(cm,
2643 task._space_id,
2644 task._region_index_start,
2645 task._region_index_end);
2646 }
2647
2648 // Once a thread has drained it's stack, it should try to steal regions from
2649 // other threads.
2650 compaction_with_stealing_task(_terminator.terminator(), worker_id);
2651 }
2652 };
2653
2654 void PSParallelCompact::compact() {
2655 GCTraceTime(Info, gc, phases) tm("Compaction Phase", &_gc_timer);
2656
2657 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2658 PSOldGen* old_gen = heap->old_gen();
2659 old_gen->start_array()->reset();
2660 uint active_gc_threads = ParallelScavengeHeap::heap()->workers().active_workers();
2661
2662 TaskQueue task_queue(last_space_id*(active_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING + 1));
2663 prepare_region_draining_tasks(active_gc_threads);
2664 enqueue_dense_prefix_tasks(task_queue, active_gc_threads);
2665
2666 {
2667 GCTraceTime(Trace, gc, phases) tm("Par Compact", &_gc_timer);
2668
2669 UpdateDensePrefixAndCompactionTask task(task_queue, active_gc_threads);
2670 ParallelScavengeHeap::heap()->workers().run_task(&task);
2671
2672 #ifdef ASSERT
2673 // Verify that all regions have been processed before the deferred updates.
2674 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
2675 verify_complete(SpaceId(id));
2676 }
2677 #endif
2678 }
2679
2680 {
2681 // Update the deferred objects, if any. Any compaction manager can be used.
2682 GCTraceTime(Trace, gc, phases) tm("Deferred Updates", &_gc_timer);
2683 ParCompactionManager* cm = ParCompactionManager::manager_array(0);
2684 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
2685 update_deferred_objects(cm, SpaceId(id));
2686 }
2687 }
2688
2689 DEBUG_ONLY(write_block_fill_histogram());
|