hotspot/src/share/vm/gc/g1/concurrentMark.cpp
changeset 35061 be6025ebffea
parent 34282 92f8f8941296
child 35065 b4ff0249c092
equal deleted inserted replaced
35060:382d0689141c 35061:be6025ebffea
    29 #include "gc/g1/concurrentMark.inline.hpp"
    29 #include "gc/g1/concurrentMark.inline.hpp"
    30 #include "gc/g1/concurrentMarkThread.inline.hpp"
    30 #include "gc/g1/concurrentMarkThread.inline.hpp"
    31 #include "gc/g1/g1CollectedHeap.inline.hpp"
    31 #include "gc/g1/g1CollectedHeap.inline.hpp"
    32 #include "gc/g1/g1CollectorPolicy.hpp"
    32 #include "gc/g1/g1CollectorPolicy.hpp"
    33 #include "gc/g1/g1CollectorState.hpp"
    33 #include "gc/g1/g1CollectorState.hpp"
    34 #include "gc/g1/g1ErgoVerbose.hpp"
       
    35 #include "gc/g1/g1Log.hpp"
       
    36 #include "gc/g1/g1OopClosures.inline.hpp"
    34 #include "gc/g1/g1OopClosures.inline.hpp"
    37 #include "gc/g1/g1RemSet.hpp"
    35 #include "gc/g1/g1RemSet.hpp"
    38 #include "gc/g1/g1StringDedup.hpp"
    36 #include "gc/g1/g1StringDedup.hpp"
    39 #include "gc/g1/heapRegion.inline.hpp"
    37 #include "gc/g1/heapRegion.inline.hpp"
    40 #include "gc/g1/heapRegionManager.inline.hpp"
    38 #include "gc/g1/heapRegionManager.inline.hpp"
    42 #include "gc/g1/heapRegionSet.inline.hpp"
    40 #include "gc/g1/heapRegionSet.inline.hpp"
    43 #include "gc/g1/suspendibleThreadSet.hpp"
    41 #include "gc/g1/suspendibleThreadSet.hpp"
    44 #include "gc/shared/gcId.hpp"
    42 #include "gc/shared/gcId.hpp"
    45 #include "gc/shared/gcTimer.hpp"
    43 #include "gc/shared/gcTimer.hpp"
    46 #include "gc/shared/gcTrace.hpp"
    44 #include "gc/shared/gcTrace.hpp"
    47 #include "gc/shared/gcTraceTime.hpp"
    45 #include "gc/shared/gcTraceTime.inline.hpp"
    48 #include "gc/shared/genOopClosures.inline.hpp"
    46 #include "gc/shared/genOopClosures.inline.hpp"
    49 #include "gc/shared/referencePolicy.hpp"
    47 #include "gc/shared/referencePolicy.hpp"
    50 #include "gc/shared/strongRootsScope.hpp"
    48 #include "gc/shared/strongRootsScope.hpp"
    51 #include "gc/shared/taskqueue.inline.hpp"
    49 #include "gc/shared/taskqueue.inline.hpp"
    52 #include "gc/shared/vmGCOperations.hpp"
    50 #include "gc/shared/vmGCOperations.hpp"
       
    51 #include "logging/log.hpp"
    53 #include "memory/allocation.hpp"
    52 #include "memory/allocation.hpp"
    54 #include "memory/resourceArea.hpp"
    53 #include "memory/resourceArea.hpp"
    55 #include "oops/oop.inline.hpp"
    54 #include "oops/oop.inline.hpp"
    56 #include "runtime/atomic.inline.hpp"
    55 #include "runtime/atomic.inline.hpp"
    57 #include "runtime/handles.inline.hpp"
    56 #include "runtime/handles.inline.hpp"
   230   assert(isEmpty(), "stack should been emptied while handling overflow");
   229   assert(isEmpty(), "stack should been emptied while handling overflow");
   231   assert(_capacity <= (jint) MarkStackSizeMax, "stack bigger than permitted");
   230   assert(_capacity <= (jint) MarkStackSizeMax, "stack bigger than permitted");
   232   // Clear expansion flag
   231   // Clear expansion flag
   233   _should_expand = false;
   232   _should_expand = false;
   234   if (_capacity == (jint) MarkStackSizeMax) {
   233   if (_capacity == (jint) MarkStackSizeMax) {
   235     if (PrintGCDetails && Verbose) {
   234     log_trace(gc)("(benign) Can't expand marking stack capacity, at max size limit");
   236       gclog_or_tty->print_cr(" (benign) Can't expand marking stack capacity, at max size limit");
       
   237     }
       
   238     return;
   235     return;
   239   }
   236   }
   240   // Double capacity if possible
   237   // Double capacity if possible
   241   jint new_capacity = MIN2(_capacity*2, (jint) MarkStackSizeMax);
   238   jint new_capacity = MIN2(_capacity*2, (jint) MarkStackSizeMax);
   242   // Do not give up existing stack until we have managed to
   239   // Do not give up existing stack until we have managed to
   252     }
   249     }
   253     _base = (oop*)(_virtual_space.low());
   250     _base = (oop*)(_virtual_space.low());
   254     _index = 0;
   251     _index = 0;
   255     _capacity = new_capacity;
   252     _capacity = new_capacity;
   256   } else {
   253   } else {
   257     if (PrintGCDetails && Verbose) {
   254     // Failed to double capacity, continue;
   258       // Failed to double capacity, continue;
   255     log_trace(gc)("(benign) Failed to expand marking stack capacity from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
   259       gclog_or_tty->print(" (benign) Failed to expand marking stack capacity from "
   256                   _capacity / K, new_capacity / K);
   260                           SIZE_FORMAT "K to " SIZE_FORMAT "K",
       
   261                           _capacity / K, new_capacity / K);
       
   262     }
       
   263   }
   257   }
   264 }
   258 }
   265 
   259 
   266 void CMMarkStack::set_should_expand() {
   260 void CMMarkStack::set_should_expand() {
   267   // If we're resetting the marking state because of an
   261   // If we're resetting the marking state because of an
   846       // not clear the overflow flag since we rely on it being true when
   840       // not clear the overflow flag since we rely on it being true when
   847       // we exit this method to abort the pause and restart concurrent
   841       // we exit this method to abort the pause and restart concurrent
   848       // marking.
   842       // marking.
   849       reset_marking_state(true /* clear_overflow */);
   843       reset_marking_state(true /* clear_overflow */);
   850 
   844 
   851       if (G1Log::fine()) {
   845       log_info(gc)("Concurrent Mark reset for overflow");
   852         gclog_or_tty->gclog_stamp();
       
   853         gclog_or_tty->print_cr("[GC concurrent-mark-reset-for-overflow]");
       
   854       }
       
   855     }
   846     }
   856   }
   847   }
   857 
   848 
   858   // after this, each task should reset its own data structures then
   849   // after this, each task should reset its own data structures then
   859   // then go into the second barrier
   850   // then go into the second barrier
   985     }
   976     }
   986   }
   977   }
   987 };
   978 };
   988 
   979 
   989 void ConcurrentMark::scanRootRegions() {
   980 void ConcurrentMark::scanRootRegions() {
   990   double scan_start = os::elapsedTime();
       
   991 
       
   992   // Start of concurrent marking.
   981   // Start of concurrent marking.
   993   ClassLoaderDataGraph::clear_claimed_marks();
   982   ClassLoaderDataGraph::clear_claimed_marks();
   994 
   983 
   995   // scan_in_progress() will have been set to true only if there was
   984   // scan_in_progress() will have been set to true only if there was
   996   // at least one root region to scan. So, if it's false, we
   985   // at least one root region to scan. So, if it's false, we
   997   // should not attempt to do any further work.
   986   // should not attempt to do any further work.
   998   if (root_regions()->scan_in_progress()) {
   987   if (root_regions()->scan_in_progress()) {
   999     if (G1Log::fine()) {
   988     GCTraceConcTime(Info, gc) tt("Concurrent Root Region Scan");
  1000       gclog_or_tty->gclog_stamp();
       
  1001       gclog_or_tty->print_cr("[GC concurrent-root-region-scan-start]");
       
  1002     }
       
  1003 
   989 
  1004     _parallel_marking_threads = calc_parallel_marking_threads();
   990     _parallel_marking_threads = calc_parallel_marking_threads();
  1005     assert(parallel_marking_threads() <= max_parallel_marking_threads(),
   991     assert(parallel_marking_threads() <= max_parallel_marking_threads(),
  1006            "Maximum number of marking threads exceeded");
   992            "Maximum number of marking threads exceeded");
  1007     uint active_workers = MAX2(1U, parallel_marking_threads());
   993     uint active_workers = MAX2(1U, parallel_marking_threads());
  1008 
   994 
  1009     CMRootRegionScanTask task(this);
   995     CMRootRegionScanTask task(this);
  1010     _parallel_workers->set_active_workers(active_workers);
   996     _parallel_workers->set_active_workers(active_workers);
  1011     _parallel_workers->run_task(&task);
   997     _parallel_workers->run_task(&task);
  1012 
       
  1013     if (G1Log::fine()) {
       
  1014       gclog_or_tty->gclog_stamp();
       
  1015       gclog_or_tty->print_cr("[GC concurrent-root-region-scan-end, %1.7lf secs]", os::elapsedTime() - scan_start);
       
  1016     }
       
  1017 
   998 
  1018     // It's possible that has_aborted() is true here without actually
   999     // It's possible that has_aborted() is true here without actually
  1019     // aborting the survivor scan earlier. This is OK as it's
  1000     // aborting the survivor scan earlier. This is OK as it's
  1020     // mainly used for sanity checking.
  1001     // mainly used for sanity checking.
  1021     root_regions()->scan_finished();
  1002     root_regions()->scan_finished();
  1047   _parallel_workers->set_active_workers(active_workers);
  1028   _parallel_workers->set_active_workers(active_workers);
  1048   _parallel_workers->run_task(&markingTask);
  1029   _parallel_workers->run_task(&markingTask);
  1049   print_stats();
  1030   print_stats();
  1050 }
  1031 }
  1051 
  1032 
  1052 // Helper class to get rid of some boilerplate code.
       
  1053 class G1CMTraceTime : public StackObj {
       
  1054   GCTraceTimeImpl _gc_trace_time;
       
  1055   static bool doit_and_prepend(bool doit) {
       
  1056     if (doit) {
       
  1057       gclog_or_tty->put(' ');
       
  1058     }
       
  1059     return doit;
       
  1060   }
       
  1061 
       
  1062  public:
       
  1063   G1CMTraceTime(const char* title, bool doit)
       
  1064     : _gc_trace_time(title, doit_and_prepend(doit), false, G1CollectedHeap::heap()->gc_timer_cm()) {
       
  1065   }
       
  1066 };
       
  1067 
       
  1068 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) {
  1033 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) {
  1069   // world is stopped at this checkpoint
  1034   // world is stopped at this checkpoint
  1070   assert(SafepointSynchronize::is_at_safepoint(),
  1035   assert(SafepointSynchronize::is_at_safepoint(),
  1071          "world should be stopped");
  1036          "world should be stopped");
  1072 
  1037 
  1081   SvcGCMarker sgcm(SvcGCMarker::OTHER);
  1046   SvcGCMarker sgcm(SvcGCMarker::OTHER);
  1082 
  1047 
  1083   if (VerifyDuringGC) {
  1048   if (VerifyDuringGC) {
  1084     HandleMark hm;  // handle scope
  1049     HandleMark hm;  // handle scope
  1085     g1h->prepare_for_verify();
  1050     g1h->prepare_for_verify();
  1086     Universe::verify(VerifyOption_G1UsePrevMarking,
  1051     Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (before)");
  1087                      " VerifyDuringGC:(before)");
       
  1088   }
  1052   }
  1089   g1h->check_bitmaps("Remark Start");
  1053   g1h->check_bitmaps("Remark Start");
  1090 
  1054 
  1091   G1CollectorPolicy* g1p = g1h->g1_policy();
  1055   G1CollectorPolicy* g1p = g1h->g1_policy();
  1092   g1p->record_concurrent_mark_remark_start();
  1056   g1p->record_concurrent_mark_remark_start();
  1100   weakRefsWork(clear_all_soft_refs);
  1064   weakRefsWork(clear_all_soft_refs);
  1101 
  1065 
  1102   if (has_overflown()) {
  1066   if (has_overflown()) {
  1103     // Oops.  We overflowed.  Restart concurrent marking.
  1067     // Oops.  We overflowed.  Restart concurrent marking.
  1104     _restart_for_overflow = true;
  1068     _restart_for_overflow = true;
  1105     if (G1TraceMarkStackOverflow) {
  1069     log_develop_trace(gc)("Remark led to restart for overflow.");
  1106       gclog_or_tty->print_cr("\nRemark led to restart for overflow.");
       
  1107     }
       
  1108 
  1070 
  1109     // Verify the heap w.r.t. the previous marking bitmap.
  1071     // Verify the heap w.r.t. the previous marking bitmap.
  1110     if (VerifyDuringGC) {
  1072     if (VerifyDuringGC) {
  1111       HandleMark hm;  // handle scope
  1073       HandleMark hm;  // handle scope
  1112       g1h->prepare_for_verify();
  1074       g1h->prepare_for_verify();
  1113       Universe::verify(VerifyOption_G1UsePrevMarking,
  1075       Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (overflow)");
  1114                        " VerifyDuringGC:(overflow)");
       
  1115     }
  1076     }
  1116 
  1077 
  1117     // Clear the marking state because we will be restarting
  1078     // Clear the marking state because we will be restarting
  1118     // marking due to overflowing the global mark stack.
  1079     // marking due to overflowing the global mark stack.
  1119     reset_marking_state();
  1080     reset_marking_state();
  1120   } else {
  1081   } else {
  1121     {
  1082     {
  1122       G1CMTraceTime trace("GC aggregate-data", G1Log::finer());
  1083       GCTraceTime(Debug, gc) trace("GC Aggregate Data", g1h->gc_timer_cm());
  1123 
  1084 
  1124       // Aggregate the per-task counting data that we have accumulated
  1085       // Aggregate the per-task counting data that we have accumulated
  1125       // while marking.
  1086       // while marking.
  1126       aggregate_count_data();
  1087       aggregate_count_data();
  1127     }
  1088     }
  1134                                        true /* expected_active */);
  1095                                        true /* expected_active */);
  1135 
  1096 
  1136     if (VerifyDuringGC) {
  1097     if (VerifyDuringGC) {
  1137       HandleMark hm;  // handle scope
  1098       HandleMark hm;  // handle scope
  1138       g1h->prepare_for_verify();
  1099       g1h->prepare_for_verify();
  1139       Universe::verify(VerifyOption_G1UseNextMarking,
  1100       Universe::verify(VerifyOption_G1UseNextMarking, "During GC (after)");
  1140                        " VerifyDuringGC:(after)");
       
  1141     }
  1101     }
  1142     g1h->check_bitmaps("Remark End");
  1102     g1h->check_bitmaps("Remark End");
  1143     assert(!restart_for_overflow(), "sanity");
  1103     assert(!restart_for_overflow(), "sanity");
  1144     // Completely reset the marking state since marking completed
  1104     // Completely reset the marking state since marking completed
  1145     set_non_marking_state();
  1105     set_non_marking_state();
  1654   g1h->verify_region_sets_optional();
  1614   g1h->verify_region_sets_optional();
  1655 
  1615 
  1656   if (VerifyDuringGC) {
  1616   if (VerifyDuringGC) {
  1657     HandleMark hm;  // handle scope
  1617     HandleMark hm;  // handle scope
  1658     g1h->prepare_for_verify();
  1618     g1h->prepare_for_verify();
  1659     Universe::verify(VerifyOption_G1UsePrevMarking,
  1619     Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (before)");
  1660                      " VerifyDuringGC:(before)");
       
  1661   }
  1620   }
  1662   g1h->check_bitmaps("Cleanup Start");
  1621   g1h->check_bitmaps("Cleanup Start");
  1663 
  1622 
  1664   G1CollectorPolicy* g1p = g1h->g1_policy();
  1623   G1CollectorPolicy* g1p = g1h->g1_policy();
  1665   g1p->record_concurrent_mark_cleanup_start();
  1624   g1p->record_concurrent_mark_cleanup_start();
  1697 
  1656 
  1698   double count_end = os::elapsedTime();
  1657   double count_end = os::elapsedTime();
  1699   double this_final_counting_time = (count_end - start);
  1658   double this_final_counting_time = (count_end - start);
  1700   _total_counting_time += this_final_counting_time;
  1659   _total_counting_time += this_final_counting_time;
  1701 
  1660 
  1702   if (G1PrintRegionLivenessInfo) {
  1661   if (log_is_enabled(Trace, gc, liveness)) {
  1703     G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Marking");
  1662     G1PrintRegionLivenessInfoClosure cl("Post-Marking");
  1704     _g1h->heap_region_iterate(&cl);
  1663     _g1h->heap_region_iterate(&cl);
  1705   }
  1664   }
  1706 
  1665 
  1707   // Install newly created mark bitMap as "prev".
  1666   // Install newly created mark bitMap as "prev".
  1708   swapMarkBitMaps();
  1667   swapMarkBitMaps();
  1741 
  1700 
  1742   // Statistics.
  1701   // Statistics.
  1743   double end = os::elapsedTime();
  1702   double end = os::elapsedTime();
  1744   _cleanup_times.add((end - start) * 1000.0);
  1703   _cleanup_times.add((end - start) * 1000.0);
  1745 
  1704 
  1746   if (G1Log::fine()) {
       
  1747     g1h->g1_policy()->print_heap_transition(start_used_bytes);
       
  1748   }
       
  1749 
       
  1750   // Clean up will have freed any regions completely full of garbage.
  1705   // Clean up will have freed any regions completely full of garbage.
  1751   // Update the soft reference policy with the new heap occupancy.
  1706   // Update the soft reference policy with the new heap occupancy.
  1752   Universe::update_heap_info_at_gc();
  1707   Universe::update_heap_info_at_gc();
  1753 
  1708 
  1754   if (VerifyDuringGC) {
  1709   if (VerifyDuringGC) {
  1755     HandleMark hm;  // handle scope
  1710     HandleMark hm;  // handle scope
  1756     g1h->prepare_for_verify();
  1711     g1h->prepare_for_verify();
  1757     Universe::verify(VerifyOption_G1UsePrevMarking,
  1712     Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (after)");
  1758                      " VerifyDuringGC:(after)");
       
  1759   }
  1713   }
  1760 
  1714 
  1761   g1h->check_bitmaps("Cleanup End");
  1715   g1h->check_bitmaps("Cleanup End");
  1762 
  1716 
  1763   g1h->verify_region_sets_optional();
  1717   g1h->verify_region_sets_optional();
  1786   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  1740   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  1787 
  1741 
  1788   _cleanup_list.verify_optional();
  1742   _cleanup_list.verify_optional();
  1789   FreeRegionList tmp_free_list("Tmp Free List");
  1743   FreeRegionList tmp_free_list("Tmp Free List");
  1790 
  1744 
  1791   if (G1ConcRegionFreeingVerbose) {
  1745   log_develop_trace(gc, freelist)("G1ConcRegionFreeing [complete cleanup] : "
  1792     gclog_or_tty->print_cr("G1ConcRegionFreeing [complete cleanup] : "
  1746                                   "cleanup list has %u entries",
  1793                            "cleanup list has %u entries",
  1747                                   _cleanup_list.length());
  1794                            _cleanup_list.length());
       
  1795   }
       
  1796 
  1748 
  1797   // No one else should be accessing the _cleanup_list at this point,
  1749   // No one else should be accessing the _cleanup_list at this point,
  1798   // so it is not necessary to take any locks
  1750   // so it is not necessary to take any locks
  1799   while (!_cleanup_list.is_empty()) {
  1751   while (!_cleanup_list.is_empty()) {
  1800     HeapRegion* hr = _cleanup_list.remove_region(true /* from_head */);
  1752     HeapRegion* hr = _cleanup_list.remove_region(true /* from_head */);
  1808     // we do during this process. We'll also append the local list when
  1760     // we do during this process. We'll also append the local list when
  1809     // _cleanup_list is empty (which means we just removed the last
  1761     // _cleanup_list is empty (which means we just removed the last
  1810     // region from the _cleanup_list).
  1762     // region from the _cleanup_list).
  1811     if ((tmp_free_list.length() % G1SecondaryFreeListAppendLength == 0) ||
  1763     if ((tmp_free_list.length() % G1SecondaryFreeListAppendLength == 0) ||
  1812         _cleanup_list.is_empty()) {
  1764         _cleanup_list.is_empty()) {
  1813       if (G1ConcRegionFreeingVerbose) {
  1765       log_develop_trace(gc, freelist)("G1ConcRegionFreeing [complete cleanup] : "
  1814         gclog_or_tty->print_cr("G1ConcRegionFreeing [complete cleanup] : "
  1766                                       "appending %u entries to the secondary_free_list, "
  1815                                "appending %u entries to the secondary_free_list, "
  1767                                       "cleanup list still has %u entries",
  1816                                "cleanup list still has %u entries",
  1768                                       tmp_free_list.length(),
  1817                                tmp_free_list.length(),
  1769                                       _cleanup_list.length());
  1818                                _cleanup_list.length());
       
  1819       }
       
  1820 
  1770 
  1821       {
  1771       {
  1822         MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
  1772         MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
  1823         g1h->secondary_free_list_add(&tmp_free_list);
  1773         g1h->secondary_free_list_add(&tmp_free_list);
  1824         SecondaryFreeList_lock->notify_all();
  1774         SecondaryFreeList_lock->notify_all();
  2071   G1CMIsAliveClosure g1_is_alive(g1h);
  2021   G1CMIsAliveClosure g1_is_alive(g1h);
  2072 
  2022 
  2073   // Inner scope to exclude the cleaning of the string and symbol
  2023   // Inner scope to exclude the cleaning of the string and symbol
  2074   // tables from the displayed time.
  2024   // tables from the displayed time.
  2075   {
  2025   {
  2076     G1CMTraceTime t("GC ref-proc", G1Log::finer());
  2026     GCTraceTime(Debug, gc) trace("GC Ref Proc", g1h->gc_timer_cm());
  2077 
  2027 
  2078     ReferenceProcessor* rp = g1h->ref_processor_cm();
  2028     ReferenceProcessor* rp = g1h->ref_processor_cm();
  2079 
  2029 
  2080     // See the comment in G1CollectedHeap::ref_processing_init()
  2030     // See the comment in G1CollectedHeap::ref_processing_init()
  2081     // about how reference processing currently works in G1.
  2031     // about how reference processing currently works in G1.
  2161 
  2111 
  2162   assert(_markStack.isEmpty(), "Marking should have completed");
  2112   assert(_markStack.isEmpty(), "Marking should have completed");
  2163 
  2113 
  2164   // Unload Klasses, String, Symbols, Code Cache, etc.
  2114   // Unload Klasses, String, Symbols, Code Cache, etc.
  2165   {
  2115   {
  2166     G1CMTraceTime trace("Unloading", G1Log::finer());
  2116     GCTraceTime(Debug, gc) trace("Unloading", g1h->gc_timer_cm());
  2167 
  2117 
  2168     if (ClassUnloadingWithConcurrentMark) {
  2118     if (ClassUnloadingWithConcurrentMark) {
  2169       bool purged_classes;
  2119       bool purged_classes;
  2170 
  2120 
  2171       {
  2121       {
  2172         G1CMTraceTime trace("System Dictionary Unloading", G1Log::finest());
  2122         GCTraceTime(Trace, gc) trace("System Dictionary Unloading", g1h->gc_timer_cm());
  2173         purged_classes = SystemDictionary::do_unloading(&g1_is_alive, false /* Defer klass cleaning */);
  2123         purged_classes = SystemDictionary::do_unloading(&g1_is_alive, false /* Defer klass cleaning */);
  2174       }
  2124       }
  2175 
  2125 
  2176       {
  2126       {
  2177         G1CMTraceTime trace("Parallel Unloading", G1Log::finest());
  2127         GCTraceTime(Trace, gc) trace("Parallel Unloading", g1h->gc_timer_cm());
  2178         weakRefsWorkParallelPart(&g1_is_alive, purged_classes);
  2128         weakRefsWorkParallelPart(&g1_is_alive, purged_classes);
  2179       }
  2129       }
  2180     }
  2130     }
  2181 
  2131 
  2182     if (G1StringDedup::is_enabled()) {
  2132     if (G1StringDedup::is_enabled()) {
  2183       G1CMTraceTime trace("String Deduplication Unlink", G1Log::finest());
  2133       GCTraceTime(Trace, gc) trace("String Deduplication Unlink", g1h->gc_timer_cm());
  2184       G1StringDedup::unlink(&g1_is_alive);
  2134       G1StringDedup::unlink(&g1_is_alive);
  2185     }
  2135     }
  2186   }
  2136   }
  2187 }
  2137 }
  2188 
  2138 
  2299 void ConcurrentMark::checkpointRootsFinalWork() {
  2249 void ConcurrentMark::checkpointRootsFinalWork() {
  2300   ResourceMark rm;
  2250   ResourceMark rm;
  2301   HandleMark   hm;
  2251   HandleMark   hm;
  2302   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  2252   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  2303 
  2253 
  2304   G1CMTraceTime trace("Finalize Marking", G1Log::finer());
  2254   GCTraceTime(Debug, gc) trace("Finalize Marking", g1h->gc_timer_cm());
  2305 
  2255 
  2306   g1h->ensure_parsability(false);
  2256   g1h->ensure_parsability(false);
  2307 
  2257 
  2308   // this is remark, so we'll use up all active threads
  2258   // this is remark, so we'll use up all active threads
  2309   uint active_workers = g1h->workers()->active_workers();
  2259   uint active_workers = g1h->workers()->active_workers();
  2612     task_card_bm->clear();
  2562     task_card_bm->clear();
  2613   }
  2563   }
  2614 }
  2564 }
  2615 
  2565 
  2616 void ConcurrentMark::print_stats() {
  2566 void ConcurrentMark::print_stats() {
  2617   if (G1MarkingVerboseLevel > 0) {
  2567   if (!log_is_enabled(Debug, gc, stats)) {
  2618     gclog_or_tty->print_cr("---------------------------------------------------------------------");
  2568     return;
  2619     for (size_t i = 0; i < _active_tasks; ++i) {
  2569   }
  2620       _tasks[i]->print_stats();
  2570   log_debug(gc, stats)("---------------------------------------------------------------------");
  2621       gclog_or_tty->print_cr("---------------------------------------------------------------------");
  2571   for (size_t i = 0; i < _active_tasks; ++i) {
  2622     }
  2572     _tasks[i]->print_stats();
       
  2573     log_debug(gc, stats)("---------------------------------------------------------------------");
  2623   }
  2574   }
  2624 }
  2575 }
  2625 
  2576 
  2626 // abandon current marking iteration due to a Full GC
  2577 // abandon current marking iteration due to a Full GC
  2627 void ConcurrentMark::abort() {
  2578 void ConcurrentMark::abort() {
  2661   _g1h->register_concurrent_cycle_end();
  2612   _g1h->register_concurrent_cycle_end();
  2662 }
  2613 }
  2663 
  2614 
  2664 static void print_ms_time_info(const char* prefix, const char* name,
  2615 static void print_ms_time_info(const char* prefix, const char* name,
  2665                                NumberSeq& ns) {
  2616                                NumberSeq& ns) {
  2666   gclog_or_tty->print_cr("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).",
  2617   log_trace(gc, marking)("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).",
  2667                          prefix, ns.num(), name, ns.sum()/1000.0, ns.avg());
  2618                          prefix, ns.num(), name, ns.sum()/1000.0, ns.avg());
  2668   if (ns.num() > 0) {
  2619   if (ns.num() > 0) {
  2669     gclog_or_tty->print_cr("%s         [std. dev = %8.2f ms, max = %8.2f ms]",
  2620     log_trace(gc, marking)("%s         [std. dev = %8.2f ms, max = %8.2f ms]",
  2670                            prefix, ns.sd(), ns.maximum());
  2621                            prefix, ns.sd(), ns.maximum());
  2671   }
  2622   }
  2672 }
  2623 }
  2673 
  2624 
  2674 void ConcurrentMark::print_summary_info() {
  2625 void ConcurrentMark::print_summary_info() {
  2675   gclog_or_tty->print_cr(" Concurrent marking:");
  2626   LogHandle(gc, marking) log;
       
  2627   if (!log.is_trace()) {
       
  2628     return;
       
  2629   }
       
  2630 
       
  2631   log.trace(" Concurrent marking:");
  2676   print_ms_time_info("  ", "init marks", _init_times);
  2632   print_ms_time_info("  ", "init marks", _init_times);
  2677   print_ms_time_info("  ", "remarks", _remark_times);
  2633   print_ms_time_info("  ", "remarks", _remark_times);
  2678   {
  2634   {
  2679     print_ms_time_info("     ", "final marks", _remark_mark_times);
  2635     print_ms_time_info("     ", "final marks", _remark_mark_times);
  2680     print_ms_time_info("     ", "weak refs", _remark_weak_ref_times);
  2636     print_ms_time_info("     ", "weak refs", _remark_weak_ref_times);
  2681 
  2637 
  2682   }
  2638   }
  2683   print_ms_time_info("  ", "cleanups", _cleanup_times);
  2639   print_ms_time_info("  ", "cleanups", _cleanup_times);
  2684   gclog_or_tty->print_cr("    Final counting total time = %8.2f s (avg = %8.2f ms).",
  2640   log.trace("    Final counting total time = %8.2f s (avg = %8.2f ms).",
  2685                          _total_counting_time,
  2641             _total_counting_time, (_cleanup_times.num() > 0 ? _total_counting_time * 1000.0 / (double)_cleanup_times.num() : 0.0));
  2686                          (_cleanup_times.num() > 0 ? _total_counting_time * 1000.0 /
       
  2687                           (double)_cleanup_times.num()
       
  2688                          : 0.0));
       
  2689   if (G1ScrubRemSets) {
  2642   if (G1ScrubRemSets) {
  2690     gclog_or_tty->print_cr("    RS scrub total time = %8.2f s (avg = %8.2f ms).",
  2643     log.trace("    RS scrub total time = %8.2f s (avg = %8.2f ms).",
  2691                            _total_rs_scrub_time,
  2644               _total_rs_scrub_time, (_cleanup_times.num() > 0 ? _total_rs_scrub_time * 1000.0 / (double)_cleanup_times.num() : 0.0));
  2692                            (_cleanup_times.num() > 0 ? _total_rs_scrub_time * 1000.0 /
  2645   }
  2693                             (double)_cleanup_times.num()
  2646   log.trace("  Total stop_world time = %8.2f s.",
  2694                            : 0.0));
  2647             (_init_times.sum() + _remark_times.sum() + _cleanup_times.sum())/1000.0);
  2695   }
  2648   log.trace("  Total concurrent time = %8.2f s (%8.2f s marking).",
  2696   gclog_or_tty->print_cr("  Total stop_world time = %8.2f s.",
  2649             cmThread()->vtime_accum(), cmThread()->vtime_mark_accum());
  2697                          (_init_times.sum() + _remark_times.sum() +
       
  2698                           _cleanup_times.sum())/1000.0);
       
  2699   gclog_or_tty->print_cr("  Total concurrent time = %8.2f s "
       
  2700                 "(%8.2f s marking).",
       
  2701                 cmThread()->vtime_accum(),
       
  2702                 cmThread()->vtime_mark_accum());
       
  2703 }
  2650 }
  2704 
  2651 
  2705 void ConcurrentMark::print_worker_threads_on(outputStream* st) const {
  2652 void ConcurrentMark::print_worker_threads_on(outputStream* st) const {
  2706   _parallel_workers->print_worker_threads_on(st);
  2653   _parallel_workers->print_worker_threads_on(st);
  2707 }
  2654 }
  3077   // limits to get the regular clock call early
  3024   // limits to get the regular clock call early
  3078   decrease_limits();
  3025   decrease_limits();
  3079 }
  3026 }
  3080 
  3027 
  3081 void CMTask::print_stats() {
  3028 void CMTask::print_stats() {
  3082   gclog_or_tty->print_cr("Marking Stats, task = %u, calls = %d",
  3029   log_debug(gc, stats)("Marking Stats, task = %u, calls = %d",
  3083                          _worker_id, _calls);
  3030                        _worker_id, _calls);
  3084   gclog_or_tty->print_cr("  Elapsed time = %1.2lfms, Termination time = %1.2lfms",
  3031   log_debug(gc, stats)("  Elapsed time = %1.2lfms, Termination time = %1.2lfms",
  3085                          _elapsed_time_ms, _termination_time_ms);
  3032                        _elapsed_time_ms, _termination_time_ms);
  3086   gclog_or_tty->print_cr("  Step Times (cum): num = %d, avg = %1.2lfms, sd = %1.2lfms",
  3033   log_debug(gc, stats)("  Step Times (cum): num = %d, avg = %1.2lfms, sd = %1.2lfms",
  3087                          _step_times_ms.num(), _step_times_ms.avg(),
  3034                        _step_times_ms.num(), _step_times_ms.avg(),
  3088                          _step_times_ms.sd());
  3035                        _step_times_ms.sd());
  3089   gclog_or_tty->print_cr("                    max = %1.2lfms, total = %1.2lfms",
  3036   log_debug(gc, stats)("                    max = %1.2lfms, total = %1.2lfms",
  3090                          _step_times_ms.maximum(), _step_times_ms.sum());
  3037                        _step_times_ms.maximum(), _step_times_ms.sum());
  3091 }
  3038 }
  3092 
  3039 
  3093 bool ConcurrentMark::try_stealing(uint worker_id, int* hash_seed, oop& obj) {
  3040 bool ConcurrentMark::try_stealing(uint worker_id, int* hash_seed, oop& obj) {
  3094   return _task_queues->steal(worker_id, hash_seed, obj);
  3041   return _task_queues->steal(worker_id, hash_seed, obj);
  3095 }
  3042 }
  3585 #define G1PPRL_SUM_BYTE_FORMAT(tag)    "  " tag ": " SIZE_FORMAT
  3532 #define G1PPRL_SUM_BYTE_FORMAT(tag)    "  " tag ": " SIZE_FORMAT
  3586 #define G1PPRL_SUM_MB_FORMAT(tag)      "  " tag ": %1.2f MB"
  3533 #define G1PPRL_SUM_MB_FORMAT(tag)      "  " tag ": %1.2f MB"
  3587 #define G1PPRL_SUM_MB_PERC_FORMAT(tag) G1PPRL_SUM_MB_FORMAT(tag) " / %1.2f %%"
  3534 #define G1PPRL_SUM_MB_PERC_FORMAT(tag) G1PPRL_SUM_MB_FORMAT(tag) " / %1.2f %%"
  3588 
  3535 
  3589 G1PrintRegionLivenessInfoClosure::
  3536 G1PrintRegionLivenessInfoClosure::
  3590 G1PrintRegionLivenessInfoClosure(outputStream* out, const char* phase_name)
  3537 G1PrintRegionLivenessInfoClosure(const char* phase_name)
  3591   : _out(out),
  3538   : _total_used_bytes(0), _total_capacity_bytes(0),
  3592     _total_used_bytes(0), _total_capacity_bytes(0),
       
  3593     _total_prev_live_bytes(0), _total_next_live_bytes(0),
  3539     _total_prev_live_bytes(0), _total_next_live_bytes(0),
  3594     _hum_used_bytes(0), _hum_capacity_bytes(0),
  3540     _hum_used_bytes(0), _hum_capacity_bytes(0),
  3595     _hum_prev_live_bytes(0), _hum_next_live_bytes(0),
  3541     _hum_prev_live_bytes(0), _hum_next_live_bytes(0),
  3596     _total_remset_bytes(0), _total_strong_code_roots_bytes(0) {
  3542     _total_remset_bytes(0), _total_strong_code_roots_bytes(0) {
  3597   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  3543   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  3598   MemRegion g1_reserved = g1h->g1_reserved();
  3544   MemRegion g1_reserved = g1h->g1_reserved();
  3599   double now = os::elapsedTime();
  3545   double now = os::elapsedTime();
  3600 
  3546 
  3601   // Print the header of the output.
  3547   // Print the header of the output.
  3602   _out->cr();
  3548   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX" PHASE %s @ %1.3f", phase_name, now);
  3603   _out->print_cr(G1PPRL_LINE_PREFIX" PHASE %s @ %1.3f", phase_name, now);
  3549   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX" HEAP"
  3604   _out->print_cr(G1PPRL_LINE_PREFIX" HEAP"
  3550                           G1PPRL_SUM_ADDR_FORMAT("reserved")
  3605                  G1PPRL_SUM_ADDR_FORMAT("reserved")
  3551                           G1PPRL_SUM_BYTE_FORMAT("region-size"),
  3606                  G1PPRL_SUM_BYTE_FORMAT("region-size"),
  3552                           p2i(g1_reserved.start()), p2i(g1_reserved.end()),
  3607                  p2i(g1_reserved.start()), p2i(g1_reserved.end()),
  3553                           HeapRegion::GrainBytes);
  3608                  HeapRegion::GrainBytes);
  3554   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX);
  3609   _out->print_cr(G1PPRL_LINE_PREFIX);
  3555   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX
  3610   _out->print_cr(G1PPRL_LINE_PREFIX
  3556                           G1PPRL_TYPE_H_FORMAT
  3611                 G1PPRL_TYPE_H_FORMAT
  3557                           G1PPRL_ADDR_BASE_H_FORMAT
  3612                 G1PPRL_ADDR_BASE_H_FORMAT
  3558                           G1PPRL_BYTE_H_FORMAT
  3613                 G1PPRL_BYTE_H_FORMAT
  3559                           G1PPRL_BYTE_H_FORMAT
  3614                 G1PPRL_BYTE_H_FORMAT
  3560                           G1PPRL_BYTE_H_FORMAT
  3615                 G1PPRL_BYTE_H_FORMAT
  3561                           G1PPRL_DOUBLE_H_FORMAT
  3616                 G1PPRL_DOUBLE_H_FORMAT
  3562                           G1PPRL_BYTE_H_FORMAT
  3617                 G1PPRL_BYTE_H_FORMAT
  3563                           G1PPRL_BYTE_H_FORMAT,
  3618                 G1PPRL_BYTE_H_FORMAT,
  3564                           "type", "address-range",
  3619                 "type", "address-range",
  3565                           "used", "prev-live", "next-live", "gc-eff",
  3620                 "used", "prev-live", "next-live", "gc-eff",
  3566                           "remset", "code-roots");
  3621                 "remset", "code-roots");
  3567   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX
  3622   _out->print_cr(G1PPRL_LINE_PREFIX
  3568                           G1PPRL_TYPE_H_FORMAT
  3623                 G1PPRL_TYPE_H_FORMAT
  3569                           G1PPRL_ADDR_BASE_H_FORMAT
  3624                 G1PPRL_ADDR_BASE_H_FORMAT
  3570                           G1PPRL_BYTE_H_FORMAT
  3625                 G1PPRL_BYTE_H_FORMAT
  3571                           G1PPRL_BYTE_H_FORMAT
  3626                 G1PPRL_BYTE_H_FORMAT
  3572                           G1PPRL_BYTE_H_FORMAT
  3627                 G1PPRL_BYTE_H_FORMAT
  3573                           G1PPRL_DOUBLE_H_FORMAT
  3628                 G1PPRL_DOUBLE_H_FORMAT
  3574                           G1PPRL_BYTE_H_FORMAT
  3629                 G1PPRL_BYTE_H_FORMAT
  3575                           G1PPRL_BYTE_H_FORMAT,
  3630                 G1PPRL_BYTE_H_FORMAT,
  3576                           "", "",
  3631                 "", "",
  3577                           "(bytes)", "(bytes)", "(bytes)", "(bytes/ms)",
  3632                 "(bytes)", "(bytes)", "(bytes)", "(bytes/ms)",
  3578                           "(bytes)", "(bytes)");
  3633                 "(bytes)", "(bytes)");
       
  3634 }
  3579 }
  3635 
  3580 
  3636 // It takes as a parameter a reference to one of the _hum_* fields, it
  3581 // It takes as a parameter a reference to one of the _hum_* fields, it
  3637 // deduces the corresponding value for a region in a humongous region
  3582 // deduces the corresponding value for a region in a humongous region
  3638 // series (either the region size, or what's left if the _hum_* field
  3583 // series (either the region size, or what's left if the _hum_* field
  3699   _total_next_live_bytes += next_live_bytes;
  3644   _total_next_live_bytes += next_live_bytes;
  3700   _total_remset_bytes    += remset_bytes;
  3645   _total_remset_bytes    += remset_bytes;
  3701   _total_strong_code_roots_bytes += strong_code_roots_bytes;
  3646   _total_strong_code_roots_bytes += strong_code_roots_bytes;
  3702 
  3647 
  3703   // Print a line for this particular region.
  3648   // Print a line for this particular region.
  3704   _out->print_cr(G1PPRL_LINE_PREFIX
  3649   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX
  3705                  G1PPRL_TYPE_FORMAT
  3650                           G1PPRL_TYPE_FORMAT
  3706                  G1PPRL_ADDR_BASE_FORMAT
  3651                           G1PPRL_ADDR_BASE_FORMAT
  3707                  G1PPRL_BYTE_FORMAT
  3652                           G1PPRL_BYTE_FORMAT
  3708                  G1PPRL_BYTE_FORMAT
  3653                           G1PPRL_BYTE_FORMAT
  3709                  G1PPRL_BYTE_FORMAT
  3654                           G1PPRL_BYTE_FORMAT
  3710                  G1PPRL_DOUBLE_FORMAT
  3655                           G1PPRL_DOUBLE_FORMAT
  3711                  G1PPRL_BYTE_FORMAT
  3656                           G1PPRL_BYTE_FORMAT
  3712                  G1PPRL_BYTE_FORMAT,
  3657                           G1PPRL_BYTE_FORMAT,
  3713                  type, p2i(bottom), p2i(end),
  3658                           type, p2i(bottom), p2i(end),
  3714                  used_bytes, prev_live_bytes, next_live_bytes, gc_eff,
  3659                           used_bytes, prev_live_bytes, next_live_bytes, gc_eff,
  3715                  remset_bytes, strong_code_roots_bytes);
  3660                           remset_bytes, strong_code_roots_bytes);
  3716 
  3661 
  3717   return false;
  3662   return false;
  3718 }
  3663 }
  3719 
  3664 
  3720 G1PrintRegionLivenessInfoClosure::~G1PrintRegionLivenessInfoClosure() {
  3665 G1PrintRegionLivenessInfoClosure::~G1PrintRegionLivenessInfoClosure() {
  3721   // add static memory usages to remembered set sizes
  3666   // add static memory usages to remembered set sizes
  3722   _total_remset_bytes += HeapRegionRemSet::fl_mem_size() + HeapRegionRemSet::static_mem_size();
  3667   _total_remset_bytes += HeapRegionRemSet::fl_mem_size() + HeapRegionRemSet::static_mem_size();
  3723   // Print the footer of the output.
  3668   // Print the footer of the output.
  3724   _out->print_cr(G1PPRL_LINE_PREFIX);
  3669   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX);
  3725   _out->print_cr(G1PPRL_LINE_PREFIX
  3670   log_trace(gc, liveness)(G1PPRL_LINE_PREFIX
  3726                  " SUMMARY"
  3671                          " SUMMARY"
  3727                  G1PPRL_SUM_MB_FORMAT("capacity")
  3672                          G1PPRL_SUM_MB_FORMAT("capacity")
  3728                  G1PPRL_SUM_MB_PERC_FORMAT("used")
  3673                          G1PPRL_SUM_MB_PERC_FORMAT("used")
  3729                  G1PPRL_SUM_MB_PERC_FORMAT("prev-live")
  3674                          G1PPRL_SUM_MB_PERC_FORMAT("prev-live")
  3730                  G1PPRL_SUM_MB_PERC_FORMAT("next-live")
  3675                          G1PPRL_SUM_MB_PERC_FORMAT("next-live")
  3731                  G1PPRL_SUM_MB_FORMAT("remset")
  3676                          G1PPRL_SUM_MB_FORMAT("remset")
  3732                  G1PPRL_SUM_MB_FORMAT("code-roots"),
  3677                          G1PPRL_SUM_MB_FORMAT("code-roots"),
  3733                  bytes_to_mb(_total_capacity_bytes),
  3678                          bytes_to_mb(_total_capacity_bytes),
  3734                  bytes_to_mb(_total_used_bytes),
  3679                          bytes_to_mb(_total_used_bytes),
  3735                  perc(_total_used_bytes, _total_capacity_bytes),
  3680                          perc(_total_used_bytes, _total_capacity_bytes),
  3736                  bytes_to_mb(_total_prev_live_bytes),
  3681                          bytes_to_mb(_total_prev_live_bytes),
  3737                  perc(_total_prev_live_bytes, _total_capacity_bytes),
  3682                          perc(_total_prev_live_bytes, _total_capacity_bytes),
  3738                  bytes_to_mb(_total_next_live_bytes),
  3683                          bytes_to_mb(_total_next_live_bytes),
  3739                  perc(_total_next_live_bytes, _total_capacity_bytes),
  3684                          perc(_total_next_live_bytes, _total_capacity_bytes),
  3740                  bytes_to_mb(_total_remset_bytes),
  3685                          bytes_to_mb(_total_remset_bytes),
  3741                  bytes_to_mb(_total_strong_code_roots_bytes));
  3686                          bytes_to_mb(_total_strong_code_roots_bytes));
  3742   _out->cr();
  3687 }
  3743 }