< prev index next >

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

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/metadataOnStackMark.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "gc/g1/g1BarrierSet.hpp"
  30 #include "gc/g1/g1CollectedHeap.inline.hpp"
  31 #include "gc/g1/g1CollectorState.hpp"
  32 #include "gc/g1/g1ConcurrentMark.inline.hpp"
  33 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
  34 #include "gc/g1/g1HeapVerifier.hpp"
  35 #include "gc/g1/g1OopClosures.inline.hpp"
  36 #include "gc/g1/g1Policy.hpp"
  37 #include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
  38 #include "gc/g1/g1StringDedup.hpp"
  39 #include "gc/g1/g1ThreadLocalData.hpp"
  40 #include "gc/g1/heapRegion.inline.hpp"
  41 #include "gc/g1/heapRegionRemSet.hpp"
  42 #include "gc/g1/heapRegionSet.inline.hpp"
  43 #include "gc/shared/adaptiveSizePolicy.hpp"
  44 #include "gc/shared/gcId.hpp"
  45 #include "gc/shared/gcTimer.hpp"
  46 #include "gc/shared/gcTrace.hpp"
  47 #include "gc/shared/gcTraceTime.inline.hpp"


1561          "Ergonomically chosen workers(%u) should be less than or equal to active workers(%u)",
1562          ergo_workers, _workers->active_workers());
1563 
1564   G1CMRefProcTaskProxy proc_task_proxy(proc_task, _g1h, _cm);
1565 
1566   // We need to reset the concurrency level before each
1567   // proxy task execution, so that the termination protocol
1568   // and overflow handling in G1CMTask::do_marking_step() knows
1569   // how many workers to wait for.
1570   _cm->set_concurrency(ergo_workers);
1571   _workers->run_task(&proc_task_proxy, ergo_workers);
1572 }
1573 
1574 void G1ConcurrentMark::weak_refs_work(bool clear_all_soft_refs) {
1575   ResourceMark rm;
1576   HandleMark   hm;
1577 
1578   // Is alive closure.
1579   G1CMIsAliveClosure g1_is_alive(_g1h);
1580 
1581   // Inner scope to exclude the cleaning of the string and symbol
1582   // tables from the displayed time.
1583   {
1584     GCTraceTime(Debug, gc, phases) debug("Reference Processing", _gc_timer_cm);
1585 
1586     ReferenceProcessor* rp = _g1h->ref_processor_cm();
1587 
1588     // See the comment in G1CollectedHeap::ref_processing_init()
1589     // about how reference processing currently works in G1.
1590 
1591     // Set the soft reference policy
1592     rp->setup_policy(clear_all_soft_refs);
1593     assert(_global_mark_stack.is_empty(), "mark stack should be empty");
1594 
1595     // Instances of the 'Keep Alive' and 'Complete GC' closures used
1596     // in serial reference processing. Note these closures are also
1597     // used for serially processing (by the the current thread) the
1598     // JNI references during parallel reference processing.
1599     //
1600     // These closures do not need to synchronize with the worker
1601     // threads involved in parallel reference processing as these
1602     // instances are executed serially by the current thread (e.g.


1656     rp->verify_no_references_recorded();
1657     assert(!rp->discovery_enabled(), "Post condition");
1658   }
1659 
1660   if (has_overflown()) {
1661     // We can not trust g1_is_alive and the contents of the heap if the marking stack
1662     // overflowed while processing references. Exit the VM.
1663     fatal("Overflow during reference processing, can not continue. Please "
1664           "increase MarkStackSizeMax (current value: " SIZE_FORMAT ") and "
1665           "restart.", MarkStackSizeMax);
1666     return;
1667   }
1668 
1669   assert(_global_mark_stack.is_empty(), "Marking should have completed");
1670 
1671   {
1672     GCTraceTime(Debug, gc, phases) debug("Weak Processing", _gc_timer_cm);
1673     WeakProcessor::weak_oops_do(&g1_is_alive, &do_nothing_cl);
1674   }
1675 
1676   // Unload Klasses, String, Symbols, Code Cache, etc.
1677   if (ClassUnloadingWithConcurrentMark) {
1678     GCTraceTime(Debug, gc, phases) debug("Class Unloading", _gc_timer_cm);
1679     bool purged_classes = SystemDictionary::do_unloading(_gc_timer_cm, false /* Defer cleaning */);
1680     _g1h->complete_cleaning(&g1_is_alive, purged_classes);
1681   } else {
1682     GCTraceTime(Debug, gc, phases) debug("Cleanup", _gc_timer_cm);
1683     // No need to clean string table and symbol table as they are treated as strong roots when
1684     // class unloading is disabled.
1685     _g1h->partial_cleaning(&g1_is_alive, false, false, G1StringDedup::is_enabled());
1686   }
1687 }
1688 
1689 class G1PrecleanYieldClosure : public YieldClosure {
1690   G1ConcurrentMark* _cm;
1691 
1692 public:
1693   G1PrecleanYieldClosure(G1ConcurrentMark* cm) : _cm(cm) { }
1694 
1695   virtual bool should_return() {
1696     return _cm->has_aborted();
1697   }
1698 
1699   virtual bool should_return_fine_grain() {
1700     _cm->do_yield_check();
1701     return _cm->has_aborted();
1702   }
1703 };
1704 
1705 void G1ConcurrentMark::preclean() {




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/metadataOnStackMark.hpp"

  27 #include "code/codeCache.hpp"
  28 #include "gc/g1/g1BarrierSet.hpp"
  29 #include "gc/g1/g1CollectedHeap.inline.hpp"
  30 #include "gc/g1/g1CollectorState.hpp"
  31 #include "gc/g1/g1ConcurrentMark.inline.hpp"
  32 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
  33 #include "gc/g1/g1HeapVerifier.hpp"
  34 #include "gc/g1/g1OopClosures.inline.hpp"
  35 #include "gc/g1/g1Policy.hpp"
  36 #include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
  37 #include "gc/g1/g1StringDedup.hpp"
  38 #include "gc/g1/g1ThreadLocalData.hpp"
  39 #include "gc/g1/heapRegion.inline.hpp"
  40 #include "gc/g1/heapRegionRemSet.hpp"
  41 #include "gc/g1/heapRegionSet.inline.hpp"
  42 #include "gc/shared/adaptiveSizePolicy.hpp"
  43 #include "gc/shared/gcId.hpp"
  44 #include "gc/shared/gcTimer.hpp"
  45 #include "gc/shared/gcTrace.hpp"
  46 #include "gc/shared/gcTraceTime.inline.hpp"


1560          "Ergonomically chosen workers(%u) should be less than or equal to active workers(%u)",
1561          ergo_workers, _workers->active_workers());
1562 
1563   G1CMRefProcTaskProxy proc_task_proxy(proc_task, _g1h, _cm);
1564 
1565   // We need to reset the concurrency level before each
1566   // proxy task execution, so that the termination protocol
1567   // and overflow handling in G1CMTask::do_marking_step() knows
1568   // how many workers to wait for.
1569   _cm->set_concurrency(ergo_workers);
1570   _workers->run_task(&proc_task_proxy, ergo_workers);
1571 }
1572 
1573 void G1ConcurrentMark::weak_refs_work(bool clear_all_soft_refs) {
1574   ResourceMark rm;
1575   HandleMark   hm;
1576 
1577   // Is alive closure.
1578   G1CMIsAliveClosure g1_is_alive(_g1h);
1579 
1580   // Inner scope to exclude the cleaning of the string table
1581   // from the displayed time.
1582   {
1583     GCTraceTime(Debug, gc, phases) debug("Reference Processing", _gc_timer_cm);
1584 
1585     ReferenceProcessor* rp = _g1h->ref_processor_cm();
1586 
1587     // See the comment in G1CollectedHeap::ref_processing_init()
1588     // about how reference processing currently works in G1.
1589 
1590     // Set the soft reference policy
1591     rp->setup_policy(clear_all_soft_refs);
1592     assert(_global_mark_stack.is_empty(), "mark stack should be empty");
1593 
1594     // Instances of the 'Keep Alive' and 'Complete GC' closures used
1595     // in serial reference processing. Note these closures are also
1596     // used for serially processing (by the the current thread) the
1597     // JNI references during parallel reference processing.
1598     //
1599     // These closures do not need to synchronize with the worker
1600     // threads involved in parallel reference processing as these
1601     // instances are executed serially by the current thread (e.g.


1655     rp->verify_no_references_recorded();
1656     assert(!rp->discovery_enabled(), "Post condition");
1657   }
1658 
1659   if (has_overflown()) {
1660     // We can not trust g1_is_alive and the contents of the heap if the marking stack
1661     // overflowed while processing references. Exit the VM.
1662     fatal("Overflow during reference processing, can not continue. Please "
1663           "increase MarkStackSizeMax (current value: " SIZE_FORMAT ") and "
1664           "restart.", MarkStackSizeMax);
1665     return;
1666   }
1667 
1668   assert(_global_mark_stack.is_empty(), "Marking should have completed");
1669 
1670   {
1671     GCTraceTime(Debug, gc, phases) debug("Weak Processing", _gc_timer_cm);
1672     WeakProcessor::weak_oops_do(&g1_is_alive, &do_nothing_cl);
1673   }
1674 
1675   // Unload Klasses, String, Code Cache, etc.
1676   if (ClassUnloadingWithConcurrentMark) {
1677     GCTraceTime(Debug, gc, phases) debug("Class Unloading", _gc_timer_cm);
1678     bool purged_classes = SystemDictionary::do_unloading(_gc_timer_cm, false /* Defer cleaning */);
1679     _g1h->complete_cleaning(&g1_is_alive, purged_classes);
1680   } else {
1681     GCTraceTime(Debug, gc, phases) debug("Cleanup", _gc_timer_cm);
1682     // No need to clean string table as it is treated as strong roots when
1683     // class unloading is disabled.
1684     _g1h->partial_cleaning(&g1_is_alive, false, G1StringDedup::is_enabled());
1685   }
1686 }
1687 
1688 class G1PrecleanYieldClosure : public YieldClosure {
1689   G1ConcurrentMark* _cm;
1690 
1691 public:
1692   G1PrecleanYieldClosure(G1ConcurrentMark* cm) : _cm(cm) { }
1693 
1694   virtual bool should_return() {
1695     return _cm->has_aborted();
1696   }
1697 
1698   virtual bool should_return_fine_grain() {
1699     _cm->do_yield_check();
1700     return _cm->has_aborted();
1701   }
1702 };
1703 
1704 void G1ConcurrentMark::preclean() {


< prev index next >