Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @ 14392:b5c8a61d7fa0
Merge
author | kvn |
---|---|
date | Fri, 21 Jun 2013 15:56:24 -0700 |
parents | f2110083203d |
children | c49c7f835e8d |
comparison
equal
deleted
inserted
replaced
14391:d2907f74462e | 14392:b5c8a61d7fa0 |
---|---|
37 #include "gc_implementation/parallelScavenge/psOldGen.hpp" | 37 #include "gc_implementation/parallelScavenge/psOldGen.hpp" |
38 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" | 38 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" |
39 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" | 39 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" |
40 #include "gc_implementation/parallelScavenge/psScavenge.hpp" | 40 #include "gc_implementation/parallelScavenge/psScavenge.hpp" |
41 #include "gc_implementation/parallelScavenge/psYoungGen.hpp" | 41 #include "gc_implementation/parallelScavenge/psYoungGen.hpp" |
42 #include "gc_implementation/shared/gcHeapSummary.hpp" | |
43 #include "gc_implementation/shared/gcTimer.hpp" | |
44 #include "gc_implementation/shared/gcTrace.hpp" | |
45 #include "gc_implementation/shared/gcTraceTime.hpp" | |
42 #include "gc_implementation/shared/isGCActiveMark.hpp" | 46 #include "gc_implementation/shared/isGCActiveMark.hpp" |
43 #include "gc_interface/gcCause.hpp" | 47 #include "gc_interface/gcCause.hpp" |
44 #include "memory/gcLocker.inline.hpp" | 48 #include "memory/gcLocker.inline.hpp" |
45 #include "memory/referencePolicy.hpp" | 49 #include "memory/referencePolicy.hpp" |
46 #include "memory/referenceProcessor.hpp" | 50 #include "memory/referenceProcessor.hpp" |
57 #include "utilities/stack.inline.hpp" | 61 #include "utilities/stack.inline.hpp" |
58 | 62 |
59 #include <math.h> | 63 #include <math.h> |
60 | 64 |
61 // All sizes are in HeapWords. | 65 // All sizes are in HeapWords. |
62 const size_t ParallelCompactData::Log2RegionSize = 9; // 512 words | 66 const size_t ParallelCompactData::Log2RegionSize = 16; // 64K words |
63 const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize; | 67 const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize; |
64 const size_t ParallelCompactData::RegionSizeBytes = | 68 const size_t ParallelCompactData::RegionSizeBytes = |
65 RegionSize << LogHeapWordSize; | 69 RegionSize << LogHeapWordSize; |
66 const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1; | 70 const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1; |
67 const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1; | 71 const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1; |
68 const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask; | 72 const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask; |
73 | |
74 const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words | |
75 const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize; | |
76 const size_t ParallelCompactData::BlockSizeBytes = | |
77 BlockSize << LogHeapWordSize; | |
78 const size_t ParallelCompactData::BlockSizeOffsetMask = BlockSize - 1; | |
79 const size_t ParallelCompactData::BlockAddrOffsetMask = BlockSizeBytes - 1; | |
80 const size_t ParallelCompactData::BlockAddrMask = ~BlockAddrOffsetMask; | |
81 | |
82 const size_t ParallelCompactData::BlocksPerRegion = RegionSize / BlockSize; | |
83 const size_t ParallelCompactData::Log2BlocksPerRegion = | |
84 Log2RegionSize - Log2BlockSize; | |
69 | 85 |
70 const ParallelCompactData::RegionData::region_sz_t | 86 const ParallelCompactData::RegionData::region_sz_t |
71 ParallelCompactData::RegionData::dc_shift = 27; | 87 ParallelCompactData::RegionData::dc_shift = 27; |
72 | 88 |
73 const ParallelCompactData::RegionData::region_sz_t | 89 const ParallelCompactData::RegionData::region_sz_t |
357 | 373 |
358 _region_vspace = 0; | 374 _region_vspace = 0; |
359 _reserved_byte_size = 0; | 375 _reserved_byte_size = 0; |
360 _region_data = 0; | 376 _region_data = 0; |
361 _region_count = 0; | 377 _region_count = 0; |
378 | |
379 _block_vspace = 0; | |
380 _block_data = 0; | |
381 _block_count = 0; | |
362 } | 382 } |
363 | 383 |
364 bool ParallelCompactData::initialize(MemRegion covered_region) | 384 bool ParallelCompactData::initialize(MemRegion covered_region) |
365 { | 385 { |
366 _region_start = covered_region.start(); | 386 _region_start = covered_region.start(); |
370 assert(region_align_down(_region_start) == _region_start, | 390 assert(region_align_down(_region_start) == _region_start, |
371 "region start not aligned"); | 391 "region start not aligned"); |
372 assert((region_size & RegionSizeOffsetMask) == 0, | 392 assert((region_size & RegionSizeOffsetMask) == 0, |
373 "region size not a multiple of RegionSize"); | 393 "region size not a multiple of RegionSize"); |
374 | 394 |
375 bool result = initialize_region_data(region_size); | 395 bool result = initialize_region_data(region_size) && initialize_block_data(); |
376 | |
377 return result; | 396 return result; |
378 } | 397 } |
379 | 398 |
380 PSVirtualSpace* | 399 PSVirtualSpace* |
381 ParallelCompactData::create_vspace(size_t count, size_t element_size) | 400 ParallelCompactData::create_vspace(size_t count, size_t element_size) |
416 return true; | 435 return true; |
417 } | 436 } |
418 return false; | 437 return false; |
419 } | 438 } |
420 | 439 |
440 bool ParallelCompactData::initialize_block_data() | |
441 { | |
442 assert(_region_count != 0, "region data must be initialized first"); | |
443 const size_t count = _region_count << Log2BlocksPerRegion; | |
444 _block_vspace = create_vspace(count, sizeof(BlockData)); | |
445 if (_block_vspace != 0) { | |
446 _block_data = (BlockData*)_block_vspace->reserved_low_addr(); | |
447 _block_count = count; | |
448 return true; | |
449 } | |
450 return false; | |
451 } | |
452 | |
421 void ParallelCompactData::clear() | 453 void ParallelCompactData::clear() |
422 { | 454 { |
423 memset(_region_data, 0, _region_vspace->committed_size()); | 455 memset(_region_data, 0, _region_vspace->committed_size()); |
456 memset(_block_data, 0, _block_vspace->committed_size()); | |
424 } | 457 } |
425 | 458 |
426 void ParallelCompactData::clear_range(size_t beg_region, size_t end_region) { | 459 void ParallelCompactData::clear_range(size_t beg_region, size_t end_region) { |
427 assert(beg_region <= _region_count, "beg_region out of range"); | 460 assert(beg_region <= _region_count, "beg_region out of range"); |
428 assert(end_region <= _region_count, "end_region out of range"); | 461 assert(end_region <= _region_count, "end_region out of range"); |
462 assert(RegionSize % BlockSize == 0, "RegionSize not a multiple of BlockSize"); | |
429 | 463 |
430 const size_t region_cnt = end_region - beg_region; | 464 const size_t region_cnt = end_region - beg_region; |
431 memset(_region_data + beg_region, 0, region_cnt * sizeof(RegionData)); | 465 memset(_region_data + beg_region, 0, region_cnt * sizeof(RegionData)); |
466 | |
467 const size_t beg_block = beg_region * BlocksPerRegion; | |
468 const size_t block_cnt = region_cnt * BlocksPerRegion; | |
469 memset(_block_data + beg_block, 0, block_cnt * sizeof(BlockData)); | |
432 } | 470 } |
433 | 471 |
434 HeapWord* ParallelCompactData::partial_obj_end(size_t region_idx) const | 472 HeapWord* ParallelCompactData::partial_obj_end(size_t region_idx) const |
435 { | 473 { |
436 const RegionData* cur_cp = region(region_idx); | 474 const RegionData* cur_cp = region(region_idx); |
705 return true; | 743 return true; |
706 } | 744 } |
707 | 745 |
708 HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) { | 746 HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) { |
709 assert(addr != NULL, "Should detect NULL oop earlier"); | 747 assert(addr != NULL, "Should detect NULL oop earlier"); |
710 assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap"); | 748 assert(PSParallelCompact::gc_heap()->is_in(addr), "not in heap"); |
749 assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "not marked"); | |
750 | |
751 // Region covering the object. | |
752 RegionData* const region_ptr = addr_to_region_ptr(addr); | |
753 HeapWord* result = region_ptr->destination(); | |
754 | |
755 // If the entire Region is live, the new location is region->destination + the | |
756 // offset of the object within in the Region. | |
757 | |
758 // Run some performance tests to determine if this special case pays off. It | |
759 // is worth it for pointers into the dense prefix. If the optimization to | |
760 // avoid pointer updates in regions that only point to the dense prefix is | |
761 // ever implemented, this should be revisited. | |
762 if (region_ptr->data_size() == RegionSize) { | |
763 result += region_offset(addr); | |
764 return result; | |
765 } | |
766 | |
767 // Otherwise, the new location is region->destination + block offset + the | |
768 // number of live words in the Block that are (a) to the left of addr and (b) | |
769 // due to objects that start in the Block. | |
770 | |
771 // Fill in the block table if necessary. This is unsynchronized, so multiple | |
772 // threads may fill the block table for a region (harmless, since it is | |
773 // idempotent). | |
774 if (!region_ptr->blocks_filled()) { | |
775 PSParallelCompact::fill_blocks(addr_to_region_idx(addr)); | |
776 region_ptr->set_blocks_filled(); | |
777 } | |
778 | |
779 HeapWord* const search_start = block_align_down(addr); | |
780 const size_t block_offset = addr_to_block_ptr(addr)->offset(); | |
781 | |
782 const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); | |
783 const size_t live = bitmap->live_words_in_range(search_start, oop(addr)); | |
784 result += block_offset + live; | |
785 DEBUG_ONLY(PSParallelCompact::check_new_location(addr, result)); | |
786 return result; | |
787 } | |
788 | |
711 #ifdef ASSERT | 789 #ifdef ASSERT |
712 if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) { | |
713 gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr); | |
714 } | |
715 #endif | |
716 assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked"); | |
717 | |
718 // Region covering the object. | |
719 size_t region_index = addr_to_region_idx(addr); | |
720 const RegionData* const region_ptr = region(region_index); | |
721 HeapWord* const region_addr = region_align_down(addr); | |
722 | |
723 assert(addr < region_addr + RegionSize, "Region does not cover object"); | |
724 assert(addr_to_region_ptr(region_addr) == region_ptr, "sanity check"); | |
725 | |
726 HeapWord* result = region_ptr->destination(); | |
727 | |
728 // If all the data in the region is live, then the new location of the object | |
729 // can be calculated from the destination of the region plus the offset of the | |
730 // object in the region. | |
731 if (region_ptr->data_size() == RegionSize) { | |
732 result += pointer_delta(addr, region_addr); | |
733 DEBUG_ONLY(PSParallelCompact::check_new_location(addr, result);) | |
734 return result; | |
735 } | |
736 | |
737 // The new location of the object is | |
738 // region destination + | |
739 // size of the partial object extending onto the region + | |
740 // sizes of the live objects in the Region that are to the left of addr | |
741 const size_t partial_obj_size = region_ptr->partial_obj_size(); | |
742 HeapWord* const search_start = region_addr + partial_obj_size; | |
743 | |
744 const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); | |
745 size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr)); | |
746 | |
747 result += partial_obj_size + live_to_left; | |
748 DEBUG_ONLY(PSParallelCompact::check_new_location(addr, result);) | |
749 return result; | |
750 } | |
751 | |
752 #ifdef ASSERT | |
753 void ParallelCompactData::verify_clear(const PSVirtualSpace* vspace) | 790 void ParallelCompactData::verify_clear(const PSVirtualSpace* vspace) |
754 { | 791 { |
755 const size_t* const beg = (const size_t*)vspace->committed_low_addr(); | 792 const size_t* const beg = (const size_t*)vspace->committed_low_addr(); |
756 const size_t* const end = (const size_t*)vspace->committed_high_addr(); | 793 const size_t* const end = (const size_t*)vspace->committed_high_addr(); |
757 for (const size_t* p = beg; p < end; ++p) { | 794 for (const size_t* p = beg; p < end; ++p) { |
760 } | 797 } |
761 | 798 |
762 void ParallelCompactData::verify_clear() | 799 void ParallelCompactData::verify_clear() |
763 { | 800 { |
764 verify_clear(_region_vspace); | 801 verify_clear(_region_vspace); |
802 verify_clear(_block_vspace); | |
765 } | 803 } |
766 #endif // #ifdef ASSERT | 804 #endif // #ifdef ASSERT |
767 | 805 |
768 #ifdef NOT_PRODUCT | 806 STWGCTimer PSParallelCompact::_gc_timer; |
769 ParallelCompactData::RegionData* debug_region(size_t region_index) { | 807 ParallelOldTracer PSParallelCompact::_gc_tracer; |
770 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
771 return sd.region(region_index); | |
772 } | |
773 #endif | |
774 | |
775 elapsedTimer PSParallelCompact::_accumulated_time; | 808 elapsedTimer PSParallelCompact::_accumulated_time; |
776 unsigned int PSParallelCompact::_total_invocations = 0; | 809 unsigned int PSParallelCompact::_total_invocations = 0; |
777 unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0; | 810 unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0; |
778 jlong PSParallelCompact::_time_of_last_gc = 0; | 811 jlong PSParallelCompact::_time_of_last_gc = 0; |
779 CollectorCounters* PSParallelCompact::_counters = NULL; | 812 CollectorCounters* PSParallelCompact::_counters = NULL; |
943 { | 976 { |
944 // Update the from & to space pointers in space_info, since they are swapped | 977 // Update the from & to space pointers in space_info, since they are swapped |
945 // at each young gen gc. Do the update unconditionally (even though a | 978 // at each young gen gc. Do the update unconditionally (even though a |
946 // promotion failure does not swap spaces) because an unknown number of minor | 979 // promotion failure does not swap spaces) because an unknown number of minor |
947 // collections will have swapped the spaces an unknown number of times. | 980 // collections will have swapped the spaces an unknown number of times. |
948 TraceTime tm("pre compact", print_phases(), true, gclog_or_tty); | 981 GCTraceTime tm("pre compact", print_phases(), true, &_gc_timer); |
949 ParallelScavengeHeap* heap = gc_heap(); | 982 ParallelScavengeHeap* heap = gc_heap(); |
950 _space_info[from_space_id].set_space(heap->young_gen()->from_space()); | 983 _space_info[from_space_id].set_space(heap->young_gen()->from_space()); |
951 _space_info[to_space_id].set_space(heap->young_gen()->to_space()); | 984 _space_info[to_space_id].set_space(heap->young_gen()->to_space()); |
952 | 985 |
953 pre_gc_values->fill(heap); | 986 pre_gc_values->fill(heap); |
960 | 993 |
961 // We need to track unique mark sweep invocations as well. | 994 // We need to track unique mark sweep invocations as well. |
962 _total_invocations++; | 995 _total_invocations++; |
963 | 996 |
964 heap->print_heap_before_gc(); | 997 heap->print_heap_before_gc(); |
998 heap->trace_heap_before_gc(&_gc_tracer); | |
965 | 999 |
966 // Fill in TLABs | 1000 // Fill in TLABs |
967 heap->accumulate_statistics_all_tlabs(); | 1001 heap->accumulate_statistics_all_tlabs(); |
968 heap->ensure_parsability(true); // retire TLABs | 1002 heap->ensure_parsability(true); // retire TLABs |
969 | 1003 |
985 gc_task_manager()->release_all_resources(); | 1019 gc_task_manager()->release_all_resources(); |
986 } | 1020 } |
987 | 1021 |
988 void PSParallelCompact::post_compact() | 1022 void PSParallelCompact::post_compact() |
989 { | 1023 { |
990 TraceTime tm("post compact", print_phases(), true, gclog_or_tty); | 1024 GCTraceTime tm("post compact", print_phases(), true, &_gc_timer); |
991 | 1025 |
992 for (unsigned int id = old_space_id; id < last_space_id; ++id) { | 1026 for (unsigned int id = old_space_id; id < last_space_id; ++id) { |
993 // Clear the marking bitmap, summary data and split info. | 1027 // Clear the marking bitmap, summary data and split info. |
994 clear_data_covering_space(SpaceId(id)); | 1028 clear_data_covering_space(SpaceId(id)); |
995 // Update top(). Must be done after clearing the bitmap and summary data. | 1029 // Update top(). Must be done after clearing the bitmap and summary data. |
1811 #endif // #ifndef PRODUCT | 1845 #endif // #ifndef PRODUCT |
1812 | 1846 |
1813 void PSParallelCompact::summary_phase(ParCompactionManager* cm, | 1847 void PSParallelCompact::summary_phase(ParCompactionManager* cm, |
1814 bool maximum_compaction) | 1848 bool maximum_compaction) |
1815 { | 1849 { |
1816 TraceTime tm("summary phase", print_phases(), true, gclog_or_tty); | 1850 GCTraceTime tm("summary phase", print_phases(), true, &_gc_timer); |
1817 // trace("2"); | 1851 // trace("2"); |
1818 | 1852 |
1819 #ifdef ASSERT | 1853 #ifdef ASSERT |
1820 if (TraceParallelOldGCMarkingPhase) { | 1854 if (TraceParallelOldGCMarkingPhase) { |
1821 tty->print_cr("add_obj_count=" SIZE_FORMAT " " | 1855 tty->print_cr("add_obj_count=" SIZE_FORMAT " " |
1959 | 1993 |
1960 PSParallelCompact::invoke_no_policy(clear_all_soft_refs || | 1994 PSParallelCompact::invoke_no_policy(clear_all_soft_refs || |
1961 maximum_heap_compaction); | 1995 maximum_heap_compaction); |
1962 } | 1996 } |
1963 | 1997 |
1964 bool ParallelCompactData::region_contains(size_t region_index, HeapWord* addr) { | |
1965 size_t addr_region_index = addr_to_region_idx(addr); | |
1966 return region_index == addr_region_index; | |
1967 } | |
1968 | |
1969 // This method contains no policy. You should probably | 1998 // This method contains no policy. You should probably |
1970 // be calling invoke() instead. | 1999 // be calling invoke() instead. |
1971 bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { | 2000 bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { |
1972 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); | 2001 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
1973 assert(ref_processor() != NULL, "Sanity"); | 2002 assert(ref_processor() != NULL, "Sanity"); |
1974 | 2003 |
1975 if (GC_locker::check_active_before_gc()) { | 2004 if (GC_locker::check_active_before_gc()) { |
1976 return false; | 2005 return false; |
1977 } | 2006 } |
1978 | 2007 |
2008 ParallelScavengeHeap* heap = gc_heap(); | |
2009 | |
2010 _gc_timer.register_gc_start(os::elapsed_counter()); | |
2011 _gc_tracer.report_gc_start(heap->gc_cause(), _gc_timer.gc_start()); | |
2012 | |
1979 TimeStamp marking_start; | 2013 TimeStamp marking_start; |
1980 TimeStamp compaction_start; | 2014 TimeStamp compaction_start; |
1981 TimeStamp collection_exit; | 2015 TimeStamp collection_exit; |
1982 | 2016 |
1983 ParallelScavengeHeap* heap = gc_heap(); | |
1984 GCCause::Cause gc_cause = heap->gc_cause(); | 2017 GCCause::Cause gc_cause = heap->gc_cause(); |
1985 PSYoungGen* young_gen = heap->young_gen(); | 2018 PSYoungGen* young_gen = heap->young_gen(); |
1986 PSOldGen* old_gen = heap->old_gen(); | 2019 PSOldGen* old_gen = heap->old_gen(); |
1987 PSAdaptiveSizePolicy* size_policy = heap->size_policy(); | 2020 PSAdaptiveSizePolicy* size_policy = heap->size_policy(); |
1988 | 2021 |
1994 if (ZapUnusedHeapArea) { | 2027 if (ZapUnusedHeapArea) { |
1995 // Save information needed to minimize mangling | 2028 // Save information needed to minimize mangling |
1996 heap->record_gen_tops_before_GC(); | 2029 heap->record_gen_tops_before_GC(); |
1997 } | 2030 } |
1998 | 2031 |
1999 heap->pre_full_gc_dump(); | 2032 heap->pre_full_gc_dump(&_gc_timer); |
2000 | 2033 |
2001 _print_phases = PrintGCDetails && PrintParallelOldGCPhaseTimes; | 2034 _print_phases = PrintGCDetails && PrintParallelOldGCPhaseTimes; |
2002 | 2035 |
2003 // Make sure data structures are sane, make the heap parsable, and do other | 2036 // Make sure data structures are sane, make the heap parsable, and do other |
2004 // miscellaneous bookkeeping. | 2037 // miscellaneous bookkeeping. |
2021 gc_task_manager()->task_idle_workers(); | 2054 gc_task_manager()->task_idle_workers(); |
2022 heap->set_par_threads(gc_task_manager()->active_workers()); | 2055 heap->set_par_threads(gc_task_manager()->active_workers()); |
2023 | 2056 |
2024 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); | 2057 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
2025 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | 2058 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); |
2026 TraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, gclog_or_tty); | 2059 GCTraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, NULL); |
2027 TraceCollectorStats tcs(counters()); | 2060 TraceCollectorStats tcs(counters()); |
2028 TraceMemoryManagerStats tms(true /* Full GC */,gc_cause); | 2061 TraceMemoryManagerStats tms(true /* Full GC */,gc_cause); |
2029 | 2062 |
2030 if (TraceGen1Time) accumulated_time()->start(); | 2063 if (TraceGen1Time) accumulated_time()->start(); |
2031 | 2064 |
2041 ref_processor()->setup_policy(maximum_heap_compaction); | 2074 ref_processor()->setup_policy(maximum_heap_compaction); |
2042 | 2075 |
2043 bool marked_for_unloading = false; | 2076 bool marked_for_unloading = false; |
2044 | 2077 |
2045 marking_start.update(); | 2078 marking_start.update(); |
2046 marking_phase(vmthread_cm, maximum_heap_compaction); | 2079 marking_phase(vmthread_cm, maximum_heap_compaction, &_gc_tracer); |
2047 | 2080 |
2048 bool max_on_system_gc = UseMaximumCompactionOnSystemGC | 2081 bool max_on_system_gc = UseMaximumCompactionOnSystemGC |
2049 && gc_cause == GCCause::_java_lang_system_gc; | 2082 && gc_cause == GCCause::_java_lang_system_gc; |
2050 summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); | 2083 summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); |
2051 | 2084 |
2099 young_gen->to_space()->capacity_in_bytes(); | 2132 young_gen->to_space()->capacity_in_bytes(); |
2100 | 2133 |
2101 // Used for diagnostics | 2134 // Used for diagnostics |
2102 size_policy->clear_generation_free_space_flags(); | 2135 size_policy->clear_generation_free_space_flags(); |
2103 | 2136 |
2104 size_policy->compute_generation_free_space(young_live, | 2137 size_policy->compute_generations_free_space(young_live, |
2105 eden_live, | 2138 eden_live, |
2106 old_live, | 2139 old_live, |
2107 cur_eden, | 2140 cur_eden, |
2108 max_old_gen_size, | 2141 max_old_gen_size, |
2109 max_eden_size, | 2142 max_eden_size, |
2110 true /* full gc*/); | 2143 true /* full gc*/); |
2111 | 2144 |
2112 size_policy->check_gc_overhead_limit(young_live, | 2145 size_policy->check_gc_overhead_limit(young_live, |
2113 eden_live, | 2146 eden_live, |
2114 max_old_gen_size, | 2147 max_old_gen_size, |
2115 max_eden_size, | 2148 max_eden_size, |
2194 NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); | 2227 NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); |
2195 | 2228 |
2196 collection_exit.update(); | 2229 collection_exit.update(); |
2197 | 2230 |
2198 heap->print_heap_after_gc(); | 2231 heap->print_heap_after_gc(); |
2232 heap->trace_heap_after_gc(&_gc_tracer); | |
2233 | |
2199 if (PrintGCTaskTimeStamps) { | 2234 if (PrintGCTaskTimeStamps) { |
2200 gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " | 2235 gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " |
2201 INT64_FORMAT, | 2236 INT64_FORMAT, |
2202 marking_start.ticks(), compaction_start.ticks(), | 2237 marking_start.ticks(), compaction_start.ticks(), |
2203 collection_exit.ticks()); | 2238 collection_exit.ticks()); |
2204 gc_task_manager()->print_task_time_stamps(); | 2239 gc_task_manager()->print_task_time_stamps(); |
2205 } | 2240 } |
2206 | 2241 |
2207 heap->post_full_gc_dump(); | 2242 heap->post_full_gc_dump(&_gc_timer); |
2208 | 2243 |
2209 #ifdef TRACESPINNING | 2244 #ifdef TRACESPINNING |
2210 ParallelTaskTerminator::print_termination_counts(); | 2245 ParallelTaskTerminator::print_termination_counts(); |
2211 #endif | 2246 #endif |
2247 | |
2248 _gc_timer.register_gc_end(os::elapsed_counter()); | |
2249 | |
2250 _gc_tracer.report_dense_prefix(dense_prefix(old_space_id)); | |
2251 _gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions()); | |
2212 | 2252 |
2213 return true; | 2253 return true; |
2214 } | 2254 } |
2215 | 2255 |
2216 bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy, | 2256 bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy, |
2306 "shouldn't return NULL"); | 2346 "shouldn't return NULL"); |
2307 return ParallelScavengeHeap::gc_task_manager(); | 2347 return ParallelScavengeHeap::gc_task_manager(); |
2308 } | 2348 } |
2309 | 2349 |
2310 void PSParallelCompact::marking_phase(ParCompactionManager* cm, | 2350 void PSParallelCompact::marking_phase(ParCompactionManager* cm, |
2311 bool maximum_heap_compaction) { | 2351 bool maximum_heap_compaction, |
2352 ParallelOldTracer *gc_tracer) { | |
2312 // Recursively traverse all live objects and mark them | 2353 // Recursively traverse all live objects and mark them |
2313 TraceTime tm("marking phase", print_phases(), true, gclog_or_tty); | 2354 GCTraceTime tm("marking phase", print_phases(), true, &_gc_timer); |
2314 | 2355 |
2315 ParallelScavengeHeap* heap = gc_heap(); | 2356 ParallelScavengeHeap* heap = gc_heap(); |
2316 uint parallel_gc_threads = heap->gc_task_manager()->workers(); | 2357 uint parallel_gc_threads = heap->gc_task_manager()->workers(); |
2317 uint active_gc_threads = heap->gc_task_manager()->active_workers(); | 2358 uint active_gc_threads = heap->gc_task_manager()->active_workers(); |
2318 TaskQueueSetSuper* qset = ParCompactionManager::region_array(); | 2359 TaskQueueSetSuper* qset = ParCompactionManager::region_array(); |
2323 | 2364 |
2324 // Need new claim bits before marking starts. | 2365 // Need new claim bits before marking starts. |
2325 ClassLoaderDataGraph::clear_claimed_marks(); | 2366 ClassLoaderDataGraph::clear_claimed_marks(); |
2326 | 2367 |
2327 { | 2368 { |
2328 TraceTime tm_m("par mark", print_phases(), true, gclog_or_tty); | 2369 GCTraceTime tm_m("par mark", print_phases(), true, &_gc_timer); |
2370 | |
2329 ParallelScavengeHeap::ParStrongRootsScope psrs; | 2371 ParallelScavengeHeap::ParStrongRootsScope psrs; |
2330 | 2372 |
2331 GCTaskQueue* q = GCTaskQueue::create(); | 2373 GCTaskQueue* q = GCTaskQueue::create(); |
2332 | 2374 |
2333 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe)); | 2375 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe)); |
2336 Threads::create_thread_roots_marking_tasks(q); | 2378 Threads::create_thread_roots_marking_tasks(q); |
2337 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer)); | 2379 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer)); |
2338 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler)); | 2380 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler)); |
2339 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management)); | 2381 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management)); |
2340 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary)); | 2382 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary)); |
2383 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::class_loader_data)); | |
2341 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti)); | 2384 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti)); |
2342 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache)); | 2385 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache)); |
2343 | 2386 |
2344 if (active_gc_threads > 1) { | 2387 if (active_gc_threads > 1) { |
2345 for (uint j = 0; j < active_gc_threads; j++) { | 2388 for (uint j = 0; j < active_gc_threads; j++) { |
2350 gc_task_manager()->execute_and_wait(q); | 2393 gc_task_manager()->execute_and_wait(q); |
2351 } | 2394 } |
2352 | 2395 |
2353 // Process reference objects found during marking | 2396 // Process reference objects found during marking |
2354 { | 2397 { |
2355 TraceTime tm_r("reference processing", print_phases(), true, gclog_or_tty); | 2398 GCTraceTime tm_r("reference processing", print_phases(), true, &_gc_timer); |
2399 | |
2400 ReferenceProcessorStats stats; | |
2356 if (ref_processor()->processing_is_mt()) { | 2401 if (ref_processor()->processing_is_mt()) { |
2357 RefProcTaskExecutor task_executor; | 2402 RefProcTaskExecutor task_executor; |
2358 ref_processor()->process_discovered_references( | 2403 stats = ref_processor()->process_discovered_references( |
2359 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, | 2404 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, |
2360 &task_executor); | 2405 &task_executor, &_gc_timer); |
2361 } else { | 2406 } else { |
2362 ref_processor()->process_discovered_references( | 2407 stats = ref_processor()->process_discovered_references( |
2363 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL); | 2408 is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL, |
2364 } | 2409 &_gc_timer); |
2365 } | 2410 } |
2366 | 2411 |
2367 TraceTime tm_c("class unloading", print_phases(), true, gclog_or_tty); | 2412 gc_tracer->report_gc_reference_stats(stats); |
2413 } | |
2414 | |
2415 GCTraceTime tm_c("class unloading", print_phases(), true, &_gc_timer); | |
2368 | 2416 |
2369 // This is the point where the entire marking should have completed. | 2417 // This is the point where the entire marking should have completed. |
2370 assert(cm->marking_stacks_empty(), "Marking should have completed"); | 2418 assert(cm->marking_stacks_empty(), "Marking should have completed"); |
2371 | 2419 |
2372 // Follow system dictionary roots and unload classes. | 2420 // Follow system dictionary roots and unload classes. |
2381 // Delete entries for dead interned strings. | 2429 // Delete entries for dead interned strings. |
2382 StringTable::unlink(is_alive_closure()); | 2430 StringTable::unlink(is_alive_closure()); |
2383 | 2431 |
2384 // Clean up unreferenced symbols in symbol table. | 2432 // Clean up unreferenced symbols in symbol table. |
2385 SymbolTable::unlink(); | 2433 SymbolTable::unlink(); |
2434 _gc_tracer.report_object_count_after_gc(is_alive_closure()); | |
2386 } | 2435 } |
2387 | 2436 |
2388 void PSParallelCompact::follow_klass(ParCompactionManager* cm, Klass* klass) { | 2437 void PSParallelCompact::follow_klass(ParCompactionManager* cm, Klass* klass) { |
2389 ClassLoaderData* cld = klass->class_loader_data(); | 2438 ClassLoaderData* cld = klass->class_loader_data(); |
2390 // The actual processing of the klass is done when we | 2439 // The actual processing of the klass is done when we |
2421 }; | 2470 }; |
2422 static PSAlwaysTrueClosure always_true; | 2471 static PSAlwaysTrueClosure always_true; |
2423 | 2472 |
2424 void PSParallelCompact::adjust_roots() { | 2473 void PSParallelCompact::adjust_roots() { |
2425 // Adjust the pointers to reflect the new locations | 2474 // Adjust the pointers to reflect the new locations |
2426 TraceTime tm("adjust roots", print_phases(), true, gclog_or_tty); | 2475 GCTraceTime tm("adjust roots", print_phases(), true, &_gc_timer); |
2427 | 2476 |
2428 // Need new claim bits when tracing through and adjusting pointers. | 2477 // Need new claim bits when tracing through and adjusting pointers. |
2429 ClassLoaderDataGraph::clear_claimed_marks(); | 2478 ClassLoaderDataGraph::clear_claimed_marks(); |
2430 | 2479 |
2431 // General strong roots. | 2480 // General strong roots. |
2457 } | 2506 } |
2458 | 2507 |
2459 void PSParallelCompact::enqueue_region_draining_tasks(GCTaskQueue* q, | 2508 void PSParallelCompact::enqueue_region_draining_tasks(GCTaskQueue* q, |
2460 uint parallel_gc_threads) | 2509 uint parallel_gc_threads) |
2461 { | 2510 { |
2462 TraceTime tm("drain task setup", print_phases(), true, gclog_or_tty); | 2511 GCTraceTime tm("drain task setup", print_phases(), true, &_gc_timer); |
2463 | 2512 |
2464 // Find the threads that are active | 2513 // Find the threads that are active |
2465 unsigned int which = 0; | 2514 unsigned int which = 0; |
2466 | 2515 |
2467 const uint task_count = MAX2(parallel_gc_threads, 1U); | 2516 const uint task_count = MAX2(parallel_gc_threads, 1U); |
2531 | 2580 |
2532 #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4 | 2581 #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4 |
2533 | 2582 |
2534 void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q, | 2583 void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q, |
2535 uint parallel_gc_threads) { | 2584 uint parallel_gc_threads) { |
2536 TraceTime tm("dense prefix task setup", print_phases(), true, gclog_or_tty); | 2585 GCTraceTime tm("dense prefix task setup", print_phases(), true, &_gc_timer); |
2537 | 2586 |
2538 ParallelCompactData& sd = PSParallelCompact::summary_data(); | 2587 ParallelCompactData& sd = PSParallelCompact::summary_data(); |
2539 | 2588 |
2540 // Iterate over all the spaces adding tasks for updating | 2589 // Iterate over all the spaces adding tasks for updating |
2541 // regions in the dense prefix. Assume that 1 gc thread | 2590 // regions in the dense prefix. Assume that 1 gc thread |
2613 | 2662 |
2614 void PSParallelCompact::enqueue_region_stealing_tasks( | 2663 void PSParallelCompact::enqueue_region_stealing_tasks( |
2615 GCTaskQueue* q, | 2664 GCTaskQueue* q, |
2616 ParallelTaskTerminator* terminator_ptr, | 2665 ParallelTaskTerminator* terminator_ptr, |
2617 uint parallel_gc_threads) { | 2666 uint parallel_gc_threads) { |
2618 TraceTime tm("steal task setup", print_phases(), true, gclog_or_tty); | 2667 GCTraceTime tm("steal task setup", print_phases(), true, &_gc_timer); |
2619 | 2668 |
2620 // Once a thread has drained it's stack, it should try to steal regions from | 2669 // Once a thread has drained it's stack, it should try to steal regions from |
2621 // other threads. | 2670 // other threads. |
2622 if (parallel_gc_threads > 1) { | 2671 if (parallel_gc_threads > 1) { |
2623 for (uint j = 0; j < parallel_gc_threads; j++) { | 2672 for (uint j = 0; j < parallel_gc_threads; j++) { |
2624 q->enqueue(new StealRegionCompactionTask(terminator_ptr)); | 2673 q->enqueue(new StealRegionCompactionTask(terminator_ptr)); |
2625 } | 2674 } |
2626 } | 2675 } |
2627 } | 2676 } |
2628 | 2677 |
2678 #ifdef ASSERT | |
2679 // Write a histogram of the number of times the block table was filled for a | |
2680 // region. | |
2681 void PSParallelCompact::write_block_fill_histogram(outputStream* const out) | |
2682 { | |
2683 if (!TraceParallelOldGCCompactionPhase) return; | |
2684 | |
2685 typedef ParallelCompactData::RegionData rd_t; | |
2686 ParallelCompactData& sd = summary_data(); | |
2687 | |
2688 for (unsigned int id = old_space_id; id < last_space_id; ++id) { | |
2689 MutableSpace* const spc = _space_info[id].space(); | |
2690 if (spc->bottom() != spc->top()) { | |
2691 const rd_t* const beg = sd.addr_to_region_ptr(spc->bottom()); | |
2692 HeapWord* const top_aligned_up = sd.region_align_up(spc->top()); | |
2693 const rd_t* const end = sd.addr_to_region_ptr(top_aligned_up); | |
2694 | |
2695 size_t histo[5] = { 0, 0, 0, 0, 0 }; | |
2696 const size_t histo_len = sizeof(histo) / sizeof(size_t); | |
2697 const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t)); | |
2698 | |
2699 for (const rd_t* cur = beg; cur < end; ++cur) { | |
2700 ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)]; | |
2701 } | |
2702 out->print("%u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt); | |
2703 for (size_t i = 0; i < histo_len; ++i) { | |
2704 out->print(" " SIZE_FORMAT_W(5) " %5.1f%%", | |
2705 histo[i], 100.0 * histo[i] / region_cnt); | |
2706 } | |
2707 out->cr(); | |
2708 } | |
2709 } | |
2710 } | |
2711 #endif // #ifdef ASSERT | |
2712 | |
2629 void PSParallelCompact::compact() { | 2713 void PSParallelCompact::compact() { |
2630 // trace("5"); | 2714 // trace("5"); |
2631 TraceTime tm("compaction phase", print_phases(), true, gclog_or_tty); | 2715 GCTraceTime tm("compaction phase", print_phases(), true, &_gc_timer); |
2632 | 2716 |
2633 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | 2717 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
2634 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | 2718 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
2635 PSOldGen* old_gen = heap->old_gen(); | 2719 PSOldGen* old_gen = heap->old_gen(); |
2636 old_gen->start_array()->reset(); | 2720 old_gen->start_array()->reset(); |
2643 enqueue_region_draining_tasks(q, active_gc_threads); | 2727 enqueue_region_draining_tasks(q, active_gc_threads); |
2644 enqueue_dense_prefix_tasks(q, active_gc_threads); | 2728 enqueue_dense_prefix_tasks(q, active_gc_threads); |
2645 enqueue_region_stealing_tasks(q, &terminator, active_gc_threads); | 2729 enqueue_region_stealing_tasks(q, &terminator, active_gc_threads); |
2646 | 2730 |
2647 { | 2731 { |
2648 TraceTime tm_pc("par compact", print_phases(), true, gclog_or_tty); | 2732 GCTraceTime tm_pc("par compact", print_phases(), true, &_gc_timer); |
2649 | 2733 |
2650 gc_task_manager()->execute_and_wait(q); | 2734 gc_task_manager()->execute_and_wait(q); |
2651 | 2735 |
2652 #ifdef ASSERT | 2736 #ifdef ASSERT |
2653 // Verify that all regions have been processed before the deferred updates. | 2737 // Verify that all regions have been processed before the deferred updates. |
2657 #endif | 2741 #endif |
2658 } | 2742 } |
2659 | 2743 |
2660 { | 2744 { |
2661 // Update the deferred objects, if any. Any compaction manager can be used. | 2745 // Update the deferred objects, if any. Any compaction manager can be used. |
2662 TraceTime tm_du("deferred updates", print_phases(), true, gclog_or_tty); | 2746 GCTraceTime tm_du("deferred updates", print_phases(), true, &_gc_timer); |
2663 ParCompactionManager* cm = ParCompactionManager::manager_array(0); | 2747 ParCompactionManager* cm = ParCompactionManager::manager_array(0); |
2664 for (unsigned int id = old_space_id; id < last_space_id; ++id) { | 2748 for (unsigned int id = old_space_id; id < last_space_id; ++id) { |
2665 update_deferred_objects(cm, SpaceId(id)); | 2749 update_deferred_objects(cm, SpaceId(id)); |
2666 } | 2750 } |
2667 } | 2751 } |
2752 | |
2753 DEBUG_ONLY(write_block_fill_histogram(gclog_or_tty)); | |
2668 } | 2754 } |
2669 | 2755 |
2670 #ifdef ASSERT | 2756 #ifdef ASSERT |
2671 void PSParallelCompact::verify_complete(SpaceId space_id) { | 2757 void PSParallelCompact::verify_complete(SpaceId space_id) { |
2672 // All Regions between space bottom() to new_top() should be marked as filled | 2758 // All Regions between space bottom() to new_top() should be marked as filled |
3127 src_region_idx = next_src_region(closure, src_space_id, src_space_top, | 3213 src_region_idx = next_src_region(closure, src_space_id, src_space_top, |
3128 end_addr); | 3214 end_addr); |
3129 } while (true); | 3215 } while (true); |
3130 } | 3216 } |
3131 | 3217 |
3218 void PSParallelCompact::fill_blocks(size_t region_idx) | |
3219 { | |
3220 // Fill in the block table elements for the specified region. Each block | |
3221 // table element holds the number of live words in the region that are to the | |
3222 // left of the first object that starts in the block. Thus only blocks in | |
3223 // which an object starts need to be filled. | |
3224 // | |
3225 // The algorithm scans the section of the bitmap that corresponds to the | |
3226 // region, keeping a running total of the live words. When an object start is | |
3227 // found, if it's the first to start in the block that contains it, the | |
3228 // current total is written to the block table element. | |
3229 const size_t Log2BlockSize = ParallelCompactData::Log2BlockSize; | |
3230 const size_t Log2RegionSize = ParallelCompactData::Log2RegionSize; | |
3231 const size_t RegionSize = ParallelCompactData::RegionSize; | |
3232 | |
3233 ParallelCompactData& sd = summary_data(); | |
3234 const size_t partial_obj_size = sd.region(region_idx)->partial_obj_size(); | |
3235 if (partial_obj_size >= RegionSize) { | |
3236 return; // No objects start in this region. | |
3237 } | |
3238 | |
3239 // Ensure the first loop iteration decides that the block has changed. | |
3240 size_t cur_block = sd.block_count(); | |
3241 | |
3242 const ParMarkBitMap* const bitmap = mark_bitmap(); | |
3243 | |
3244 const size_t Log2BitsPerBlock = Log2BlockSize - LogMinObjAlignment; | |
3245 assert((size_t)1 << Log2BitsPerBlock == | |
3246 bitmap->words_to_bits(ParallelCompactData::BlockSize), "sanity"); | |
3247 | |
3248 size_t beg_bit = bitmap->words_to_bits(region_idx << Log2RegionSize); | |
3249 const size_t range_end = beg_bit + bitmap->words_to_bits(RegionSize); | |
3250 size_t live_bits = bitmap->words_to_bits(partial_obj_size); | |
3251 beg_bit = bitmap->find_obj_beg(beg_bit + live_bits, range_end); | |
3252 while (beg_bit < range_end) { | |
3253 const size_t new_block = beg_bit >> Log2BitsPerBlock; | |
3254 if (new_block != cur_block) { | |
3255 cur_block = new_block; | |
3256 sd.block(cur_block)->set_offset(bitmap->bits_to_words(live_bits)); | |
3257 } | |
3258 | |
3259 const size_t end_bit = bitmap->find_obj_end(beg_bit, range_end); | |
3260 if (end_bit < range_end - 1) { | |
3261 live_bits += end_bit - beg_bit + 1; | |
3262 beg_bit = bitmap->find_obj_beg(end_bit + 1, range_end); | |
3263 } else { | |
3264 return; | |
3265 } | |
3266 } | |
3267 } | |
3268 | |
3132 void | 3269 void |
3133 PSParallelCompact::move_and_update(ParCompactionManager* cm, SpaceId space_id) { | 3270 PSParallelCompact::move_and_update(ParCompactionManager* cm, SpaceId space_id) { |
3134 const MutableSpace* sp = space(space_id); | 3271 const MutableSpace* sp = space(space_id); |
3135 if (sp->is_empty()) { | 3272 if (sp->is_empty()) { |
3136 return; | 3273 return; |