Path: blob/master/test/jdk/com/sun/jdi/BreakpointTest.java
41152 views
/*1* Copyright (c) 2001, 2017, 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// THIS TEST IS LINE NUMBER SENSITIVE2425/**26* @test27* @bug 649652428* @key intermittent29* @summary Setting breakpoint in jdb crashes Hotspot JVM30* @author jjh31*32* @run build TestScaffold VMConnection TargetListener TargetAdapter33* @run compile -g BreakpointTest.java34* @run driver BreakpointTest35*/3637import com.sun.jdi.*;38import com.sun.jdi.event.*;39import com.sun.jdi.request.*;4041import java.util.*;4243// The debuggee just runs in a loop. The debugger44// sets a bkpt on the Math.random call. When the45// bkpt is hit, the debugger disables it, resumes46// the debuggee, waits a bit, and enables the bkpt again.4748class BreakpointTarg {49public final static int BKPT_LINE = 56;5051public static long count;52static void doit() {53Object[] roots = new Object[200000];54while (true) {55int index = (int) (Math.random() * roots.length); // BKPT_LINE56// This println makes the test pass57//System.out.println("Debuggee: index = " + index);58roots[index] = new Object(); // bkpt here passes59// and null instead of new Object()60// passes61count++;62}63}6465public static void main(String[] args) {66doit();67}68}6970/********** test program **********/7172public class BreakpointTest extends TestScaffold {73ClassType targetClass;74ThreadReference mainThread;7576BreakpointTest (String args[]) {77super(args);78}7980public static void main(String[] args) throws Exception {81new BreakpointTest(args).startTests();82}8384/********** event handlers **********/8586static int maxBkpts = 50;87int bkptCount;88BreakpointRequest bkptRequest;89Field debuggeeCountField;9091// When we get a bkpt we want to disable the request,92// resume the debuggee, and then re-enable the request93public void breakpointReached(BreakpointEvent event) {94System.out.println("Got BreakpointEvent: " + bkptCount +95", debuggeeCount = " +96((LongValue)targetClass.97getValue(debuggeeCountField)).value()98);99bkptRequest.disable();100}101102public void eventSetComplete(EventSet set) {103set.resume();104105// The main thread watchs the bkptCount to106// see if bkpts stop coming in. The107// test _should_ fail well before maxBkpts bkpts.108if (bkptCount++ < maxBkpts) {109try {110Thread.sleep(100);111} catch (InterruptedException ee) {112}113bkptRequest.enable();114}115}116117public void vmDisconnected(VMDisconnectEvent event) {118println("Got VMDisconnectEvent");119}120121/********** test core **********/122123protected void runTests() throws Exception {124/*125* Get to the top of main()126* to determine targetClass and mainThread127*/128BreakpointEvent bpe = startToMain("BreakpointTarg");129targetClass = (ClassType)bpe.location().declaringType();130mainThread = bpe.thread();131EventRequestManager erm = vm().eventRequestManager();132133Location loc1 = findLocation(134targetClass,135BreakpointTarg.BKPT_LINE);136137bkptRequest = erm.createBreakpointRequest(loc1);138bkptRequest.enable();139debuggeeCountField = targetClass.fieldByName("count");140try {141142addListener (this);143} catch (Exception ex){144ex.printStackTrace();145failure("failure: Could not add listener");146throw new Exception("BreakpointTest: failed");147}148149int prevBkptCount;150vm().resume();151while (!vmDisconnected && bkptCount < maxBkpts) {152try {153Thread.sleep(5000);154} catch (InterruptedException ee) {155}156}157158println("done with loop, final count = " +159((LongValue)targetClass.160getValue(debuggeeCountField)).value());161bkptRequest.disable();162removeListener(this);163164165/*166* deal with results of test167* if anything has called failure("foo") testFailed will be true168*/169if (!testFailed) {170println("BreakpointTest: passed");171} else {172throw new Exception("BreakpointTest: failed");173}174}175}176177178