Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/BreakpointTest.java
38855 views
/*1* Copyright (c) 2001, 2007, 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 649652426* @summary Setting breakpoint in jdb crashes Hotspot JVM27*28* @author jjh29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g BreakpointTest.java32* @run main BreakpointTest33*/34import com.sun.jdi.*;35import com.sun.jdi.event.*;36import com.sun.jdi.request.*;3738import java.util.*;3940// The debuggee just runs in a loop. The debugger41// sets a bkpt on the Math.random call. When the42// bkpt is hit, the debugger disables it, resumes43// the debuggee, waits a bit, and enables the bkpt again.4445class BreakpointTarg {46public final static int BKPT_LINE = 54;47// LINE NUMBER SENSITIVE4849public static long count;50static void doit() {51Object[] roots = new Object[200000];52while (true) {53int index = (int) (Math.random() * roots.length); // BKPT_LINE54// This println makes the test pass55//System.out.println("Debuggee: index = " + index);56roots[index] = new Object(); // bkpt here passes57// and null instead of new Object()58// passes59count++;60}61}6263public static void main(String[] args) {64doit();65}66}6768/********** test program **********/6970public class BreakpointTest extends TestScaffold {71ClassType targetClass;72ThreadReference mainThread;7374BreakpointTest (String args[]) {75super(args);76}7778public static void main(String[] args) throws Exception {79new BreakpointTest(args).startTests();80}8182/********** event handlers **********/8384static int maxBkpts = 50;85int bkptCount;86BreakpointRequest bkptRequest;87Field debuggeeCountField;8889// When we get a bkpt we want to disable the request,90// resume the debuggee, and then re-enable the request91public void breakpointReached(BreakpointEvent event) {92System.out.println("Got BreakpointEvent: " + bkptCount +93", debuggeeCount = " +94((LongValue)targetClass.95getValue(debuggeeCountField)).value()96);97bkptRequest.disable();98}99100public void eventSetComplete(EventSet set) {101set.resume();102103// The main thread watchs the bkptCount to104// see if bkpts stop coming in. The105// test _should_ fail well before maxBkpts bkpts.106if (bkptCount++ < maxBkpts) {107try {108Thread.sleep(100);109} catch (InterruptedException ee) {110}111bkptRequest.enable();112}113}114115public void vmDisconnected(VMDisconnectEvent event) {116println("Got VMDisconnectEvent");117}118119/********** test core **********/120121protected void runTests() throws Exception {122/*123* Get to the top of main()124* to determine targetClass and mainThread125*/126BreakpointEvent bpe = startToMain("BreakpointTarg");127targetClass = (ClassType)bpe.location().declaringType();128mainThread = bpe.thread();129EventRequestManager erm = vm().eventRequestManager();130131Location loc1 = findLocation(132targetClass,133BreakpointTarg.BKPT_LINE);134135bkptRequest = erm.createBreakpointRequest(loc1);136bkptRequest.enable();137debuggeeCountField = targetClass.fieldByName("count");138try {139140addListener (this);141} catch (Exception ex){142ex.printStackTrace();143failure("failure: Could not add listener");144throw new Exception("BreakpointTest: failed");145}146147int prevBkptCount;148vm().resume();149while (!vmDisconnected && bkptCount < maxBkpts) {150try {151Thread.sleep(5000);152} catch (InterruptedException ee) {153}154}155156println("done with loop, final count = " +157((LongValue)targetClass.158getValue(debuggeeCountField)).value());159bkptRequest.disable();160removeListener(this);161162163/*164* deal with results of test165* if anything has called failure("foo") testFailed will be true166*/167if (!testFailed) {168println("BreakpointTest: passed");169} else {170throw new Exception("BreakpointTest: failed");171}172}173}174175176