Path: blob/master/test/hotspot/jtreg/gc/TestConcurrentGCBreakpoints.java
40930 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc;2425/*26* @test TestConcurrentGCBreakpoints27* @summary Test of WhiteBox concurrent GC control.28* @library /test/lib29* @build sun.hotspot.WhiteBox30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm32* -Xbootclasspath/a:.33* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI34* gc.TestConcurrentGCBreakpoints35*/3637import sun.hotspot.WhiteBox;38import sun.hotspot.gc.GC;3940public class TestConcurrentGCBreakpoints {4142private static final WhiteBox WB = WhiteBox.getWhiteBox();4344// All testN() assume initial state is idle, and restore that state.4546// Step through the common breakpoints.47private static void testSimpleCycle() throws Exception {48System.out.println("testSimpleCycle");49try {50// Run one cycle.51WB.concurrentGCRunTo(WB.AFTER_MARKING_STARTED);52WB.concurrentGCRunTo(WB.BEFORE_MARKING_COMPLETED);53WB.concurrentGCRunToIdle();54// Run a second cycle.55WB.concurrentGCRunTo(WB.AFTER_MARKING_STARTED);56WB.concurrentGCRunTo(WB.BEFORE_MARKING_COMPLETED);57WB.concurrentGCRunToIdle();58} finally {59WB.concurrentGCRunToIdle();60}61}6263// Verify attempted wraparound detected and reported.64private static void testEndBeforeBreakpointError() throws Exception {65System.out.println("testEndBeforeBreakpointError");66try {67WB.concurrentGCRunTo(WB.BEFORE_MARKING_COMPLETED);68try {69WB.concurrentGCRunTo(WB.AFTER_MARKING_STARTED);70} catch (IllegalStateException e) {71// Reached end of cycle before desired breakpoint.72}73} finally {74WB.concurrentGCRunToIdle();75}76}7778// Verify attempted wraparound detected and reported without throw.79private static void testEndBeforeBreakpoint() throws Exception {80System.out.println("testEndBeforeBreakpoint");81try {82WB.concurrentGCRunTo(WB.BEFORE_MARKING_COMPLETED);83if (WB.concurrentGCRunTo(WB.AFTER_MARKING_STARTED, false)) {84throw new RuntimeException("Unexpected wraparound");85}86} finally {87WB.concurrentGCRunToIdle();88}89}9091private static void testUnknownBreakpoint() throws Exception {92System.out.println("testUnknownBreakpoint");93try {94if (WB.concurrentGCRunTo("UNKNOWN BREAKPOINT", false)) {95throw new RuntimeException("RunTo UNKNOWN BREAKPOINT");96}97} finally {98WB.concurrentGCRunToIdle();99}100}101102private static void test() throws Exception {103try {104System.out.println("taking control");105WB.concurrentGCAcquireControl();106testSimpleCycle();107testEndBeforeBreakpointError();108testEndBeforeBreakpoint();109testUnknownBreakpoint();110} finally {111System.out.println("releasing control");112WB.concurrentGCReleaseControl();113}114}115116private static boolean expectSupported() {117return GC.G1.isSelected() ||118GC.Z.isSelected() ||119GC.Shenandoah.isSelected();120}121122private static boolean expectUnsupported() {123return GC.Serial.isSelected() ||124GC.Parallel.isSelected() ||125GC.Epsilon.isSelected();126}127128public static void main(String[] args) throws Exception {129boolean supported = WB.supportsConcurrentGCBreakpoints();130if (expectSupported()) {131if (supported) {132test();133} else {134throw new RuntimeException("Expected support");135}136} else if (expectUnsupported()) {137if (supported) {138throw new RuntimeException("Unexpected support");139}140} else {141throw new RuntimeException("Unknown GC");142}143}144}145146147