8065579: WB method to start G1 concurrent mark cycle should be introduced

Wed, 02 Dec 2015 13:58:34 +0530

author
kevinw
date
Wed, 02 Dec 2015 13:58:34 +0530
changeset 8194
047a642c9729
parent 8193
70649f10b88c
child 8195
cf93dd06db0f

8065579: WB method to start G1 concurrent mark cycle should be introduced
Summary: Add a WhiteBox callback to the VM to start a concurrent mark cycle in G1.
Reviewed-by: tschatzl, sjohanss
Contributed-by: Leonid Mesnik <leonid.mesnik@oracle.com>

src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp file | annotate | diff | comparison | revisions
src/share/vm/gc_implementation/g1/vm_operations_g1.cpp file | annotate | diff | comparison | revisions
src/share/vm/gc_interface/gcCause.cpp file | annotate | diff | comparison | revisions
src/share/vm/gc_interface/gcCause.hpp file | annotate | diff | comparison | revisions
src/share/vm/prims/whitebox.cpp file | annotate | diff | comparison | revisions
test/gc/whitebox/TestConcMarkCycleWB.java file | annotate | diff | comparison | revisions
test/testlibrary/whitebox/sun/hotspot/WhiteBox.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Tue Dec 15 09:46:51 2015 +0100
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Wed Dec 02 13:58:34 2015 +0530
     1.3 @@ -2331,6 +2331,7 @@
     1.4      case GCCause::_java_lang_system_gc:     return ExplicitGCInvokesConcurrent;
     1.5      case GCCause::_g1_humongous_allocation: return true;
     1.6      case GCCause::_update_allocation_context_stats_inc: return true;
     1.7 +    case GCCause::_wb_conc_mark:            return true;
     1.8      default:                                return false;
     1.9    }
    1.10  }
     2.1 --- a/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp	Tue Dec 15 09:46:51 2015 +0100
     2.2 +++ b/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp	Wed Dec 02 13:58:34 2015 +0530
     2.3 @@ -90,12 +90,8 @@
     2.4  
     2.5  void VM_G1IncCollectionPause::doit() {
     2.6    G1CollectedHeap* g1h = G1CollectedHeap::heap();
     2.7 -  assert(!_should_initiate_conc_mark ||
     2.8 -  ((_gc_cause == GCCause::_gc_locker && GCLockerInvokesConcurrent) ||
     2.9 -   (_gc_cause == GCCause::_java_lang_system_gc && ExplicitGCInvokesConcurrent) ||
    2.10 -    _gc_cause == GCCause::_g1_humongous_allocation ||
    2.11 -    _gc_cause == GCCause::_update_allocation_context_stats_inc),
    2.12 -      "only a GC locker, a System.gc(), stats update or a hum allocation induced GC should start a cycle");
    2.13 +  assert(!_should_initiate_conc_mark || g1h->should_do_concurrent_full_gc(_gc_cause),
    2.14 +      "only a GC locker, a System.gc(), stats update, whitebox, or a hum allocation induced GC should start a cycle");
    2.15  
    2.16    if (_word_size > 0) {
    2.17      // An allocation has been requested. So, try to do that first.
     3.1 --- a/src/share/vm/gc_interface/gcCause.cpp	Tue Dec 15 09:46:51 2015 +0100
     3.2 +++ b/src/share/vm/gc_interface/gcCause.cpp	Wed Dec 02 13:58:34 2015 +0530
     3.3 @@ -54,6 +54,9 @@
     3.4      case _wb_young_gc:
     3.5        return "WhiteBox Initiated Young GC";
     3.6  
     3.7 +    case _wb_conc_mark:
     3.8 +      return "WhiteBox Initiated Concurrent Mark";
     3.9 +
    3.10      case _update_allocation_context_stats_inc:
    3.11      case _update_allocation_context_stats_full:
    3.12        return "Update Allocation Context Stats";
     4.1 --- a/src/share/vm/gc_interface/gcCause.hpp	Tue Dec 15 09:46:51 2015 +0100
     4.2 +++ b/src/share/vm/gc_interface/gcCause.hpp	Wed Dec 02 13:58:34 2015 +0530
     4.3 @@ -47,6 +47,7 @@
     4.4      _heap_inspection,
     4.5      _heap_dump,
     4.6      _wb_young_gc,
     4.7 +    _wb_conc_mark,
     4.8      _update_allocation_context_stats_inc,
     4.9      _update_allocation_context_stats_full,
    4.10  
     5.1 --- a/src/share/vm/prims/whitebox.cpp	Tue Dec 15 09:46:51 2015 +0100
     5.2 +++ b/src/share/vm/prims/whitebox.cpp	Wed Dec 02 13:58:34 2015 +0530
     5.3 @@ -45,6 +45,7 @@
     5.4  #if INCLUDE_ALL_GCS
     5.5  #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp"
     5.6  #include "gc_implementation/g1/concurrentMark.hpp"
     5.7 +#include "gc_implementation/g1/concurrentMarkThread.hpp"
     5.8  #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
     5.9  #include "gc_implementation/g1/heapRegionRemSet.hpp"
    5.10  #endif // INCLUDE_ALL_GCS
    5.11 @@ -323,8 +324,16 @@
    5.12  
    5.13  WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
    5.14    G1CollectedHeap* g1 = G1CollectedHeap::heap();
    5.15 -  ConcurrentMark* cm = g1->concurrent_mark();
    5.16 -  return cm->concurrent_marking_in_progress();
    5.17 +  return g1->concurrent_mark()->cmThread()->during_cycle();
    5.18 +WB_END
    5.19 +
    5.20 +WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
    5.21 +  G1CollectedHeap* g1h = G1CollectedHeap::heap();
    5.22 +  if (!g1h->concurrent_mark()->cmThread()->during_cycle()) {
    5.23 +    g1h->collect(GCCause::_wb_conc_mark);
    5.24 +    return true;
    5.25 +  }
    5.26 +  return false;
    5.27  WB_END
    5.28  
    5.29  WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
    5.30 @@ -1031,6 +1040,7 @@
    5.31    {CC"g1NumMaxRegions",    CC"()J",                   (void*)&WB_G1NumMaxRegions  },
    5.32    {CC"g1NumFreeRegions",   CC"()J",                   (void*)&WB_G1NumFreeRegions  },
    5.33    {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
    5.34 +  {CC"g1StartConcMarkCycle",       CC"()Z",           (void*)&WB_G1StartMarkCycle  },
    5.35    {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;",
    5.36                                                        (void*)&WB_G1AuxiliaryMemoryUsage  },
    5.37  #endif // INCLUDE_ALL_GCS
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/gc/whitebox/TestConcMarkCycleWB.java	Wed Dec 02 13:58:34 2015 +0530
     6.3 @@ -0,0 +1,57 @@
     6.4 +/*
     6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test TestConMarkCycleWB
    6.29 + * @bug 8065579
    6.30 + * @requires vm.gc=="null" | vm.gc=="G1"
    6.31 + * @library /testlibrary /testlibrary/whitebox
    6.32 + * @build ClassFileInstaller com.oracle.java.testlibrary.* sun.hotspot.WhiteBox TestConcMarkCycleWB
    6.33 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    6.34 + *                              sun.hotspot.WhiteBox$WhiteBoxPermission
    6.35 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseG1GC TestConcMarkCycleWB
    6.36 + * @summary Verifies that ConcurrentMarking-related WB works properly
    6.37 + */
    6.38 +import static com.oracle.java.testlibrary.Asserts.assertFalse;
    6.39 +import static com.oracle.java.testlibrary.Asserts.assertTrue;
    6.40 +import sun.hotspot.WhiteBox;
    6.41 +
    6.42 +public class TestConcMarkCycleWB {
    6.43 +
    6.44 +    public static void main(String[] args) throws Exception {
    6.45 +        WhiteBox wb = WhiteBox.getWhiteBox();
    6.46 +
    6.47 +        wb.youngGC();
    6.48 +        assertTrue(wb.g1StartConcMarkCycle());
    6.49 +        while (wb.g1InConcurrentMark()) {
    6.50 +            Thread.sleep(5);
    6.51 +        }
    6.52 +
    6.53 +        wb.fullGC();
    6.54 +        assertTrue(wb.g1StartConcMarkCycle());
    6.55 +        while (wb.g1InConcurrentMark()) {
    6.56 +            Thread.sleep(5);
    6.57 +        }
    6.58 +        assertTrue(wb.g1StartConcMarkCycle());
    6.59 +    }
    6.60 +}
     7.1 --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Tue Dec 15 09:46:51 2015 +0100
     7.2 +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Wed Dec 02 13:58:34 2015 +0530
     7.3 @@ -174,12 +174,16 @@
     7.4    public native long incMetaspaceCapacityUntilGC(long increment);
     7.5    public native long metaspaceCapacityUntilGC();
     7.6  
     7.7 -  // force Young GC
     7.8 +  // Force Young GC
     7.9    public native void youngGC();
    7.10  
    7.11 -  // force Full GC
    7.12 +  // Force Full GC
    7.13    public native void fullGC();
    7.14  
    7.15 +  // Method tries to start concurrent mark cycle.
    7.16 +  // It returns false if CM Thread is always in concurrent cycle.
    7.17 +  public native boolean g1StartConcMarkCycle();
    7.18 +
    7.19    // Tests on ReservedSpace/VirtualSpace classes
    7.20    public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
    7.21    public native void runMemoryUnitTests();

mercurial