Path: blob/master/test/jdk/com/sun/jdi/BreakpointWithFullGC.java
41152 views
/*1* Copyright (c) 2009, 2018, 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*/2223/*24* @test25* @bug 686229526* @summary Verify breakpoints still work after a full GC.27* @comment converted from test/jdk/com/sun/jdi/BreakpointWithFullGC.sh28*29* @library /test/lib30* @compile -g BreakpointWithFullGC.java31* @run main/othervm BreakpointWithFullGC32*/3334import jdk.test.lib.process.OutputAnalyzer;35import lib.jdb.Jdb;36import lib.jdb.JdbCommand;37import lib.jdb.JdbTest;3839import java.util.ArrayList;40import java.util.List;4142class BreakpointWithFullGCTarg {43public static List<Object> objList = new ArrayList<>();4445private static void init(int numObjs) {46for (int i = 0; i < numObjs; i++) {47objList.add(new Object());48}49}5051public static void main(String[] args) {52for (int i = 0; i < 10; i++) {53System.out.println("top of loop"); // @1 breakpoint54init(500000);55objList.clear();56System.gc();57System.out.println("bottom of loop"); // @1 breakpoint58}59System.out.println("end of test"); // @1 breakpoint60}61}6263public class BreakpointWithFullGC extends JdbTest {64public static void main(String argv[]) {65new BreakpointWithFullGC().run();66}6768private BreakpointWithFullGC() {69super(new LaunchOptions(DEBUGGEE_CLASS)70.addDebuggeeOptions(DEBUGGEE_OPTIONS));71}7273private static final String DEBUGGEE_CLASS = BreakpointWithFullGCTarg.class.getName();74// We don't specify "-Xmx" for debuggee as we have full GCs with any value.75private static final String[] DEBUGGEE_OPTIONS = {"-verbose:gc"};7677@Override78protected void runCases() {79setBreakpointsFromTestSource("BreakpointWithFullGC.java", 1);8081// get to the first loop breakpoint82jdb.command(JdbCommand.run());83// 19 "cont" commands gets us through all the loop breakpoints.84for (int i = 1; i <= 19; i++) {85jdb.command(JdbCommand.cont());86}87// get to the last breakpoint88jdb.command(JdbCommand.cont());8990jdb.contToExit(1);9192new OutputAnalyzer(getJdbOutput())93// make sure we hit the first breakpoint at least once94.stdoutShouldMatch("System\\..*top of loop")95// make sure we hit the second breakpoint at least once96.stdoutShouldMatch("System\\..*bottom of loop")97// make sure we hit the last breakpoint98.stdoutShouldMatch("System\\..*end of test");99new OutputAnalyzer(getDebuggeeOutput())100// check for error message due to thread ID change101.stderrShouldNotContain("Exception in thread \"event-handler\" java.lang.NullPointerException");102}103}104105106