Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/BreakpointTest.java
38855 views
1
/*
2
* Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 6496524
27
* @summary Setting breakpoint in jdb crashes Hotspot JVM
28
*
29
* @author jjh
30
*
31
* @run build TestScaffold VMConnection TargetListener TargetAdapter
32
* @run compile -g BreakpointTest.java
33
* @run main BreakpointTest
34
*/
35
import com.sun.jdi.*;
36
import com.sun.jdi.event.*;
37
import com.sun.jdi.request.*;
38
39
import java.util.*;
40
41
// The debuggee just runs in a loop. The debugger
42
// sets a bkpt on the Math.random call. When the
43
// bkpt is hit, the debugger disables it, resumes
44
// the debuggee, waits a bit, and enables the bkpt again.
45
46
class BreakpointTarg {
47
public final static int BKPT_LINE = 54;
48
// LINE NUMBER SENSITIVE
49
50
public static long count;
51
static void doit() {
52
Object[] roots = new Object[200000];
53
while (true) {
54
int index = (int) (Math.random() * roots.length); // BKPT_LINE
55
// This println makes the test pass
56
//System.out.println("Debuggee: index = " + index);
57
roots[index] = new Object(); // bkpt here passes
58
// and null instead of new Object()
59
// passes
60
count++;
61
}
62
}
63
64
public static void main(String[] args) {
65
doit();
66
}
67
}
68
69
/********** test program **********/
70
71
public class BreakpointTest extends TestScaffold {
72
ClassType targetClass;
73
ThreadReference mainThread;
74
75
BreakpointTest (String args[]) {
76
super(args);
77
}
78
79
public static void main(String[] args) throws Exception {
80
new BreakpointTest(args).startTests();
81
}
82
83
/********** event handlers **********/
84
85
static int maxBkpts = 50;
86
int bkptCount;
87
BreakpointRequest bkptRequest;
88
Field debuggeeCountField;
89
90
// When we get a bkpt we want to disable the request,
91
// resume the debuggee, and then re-enable the request
92
public void breakpointReached(BreakpointEvent event) {
93
System.out.println("Got BreakpointEvent: " + bkptCount +
94
", debuggeeCount = " +
95
((LongValue)targetClass.
96
getValue(debuggeeCountField)).value()
97
);
98
bkptRequest.disable();
99
}
100
101
public void eventSetComplete(EventSet set) {
102
set.resume();
103
104
// The main thread watchs the bkptCount to
105
// see if bkpts stop coming in. The
106
// test _should_ fail well before maxBkpts bkpts.
107
if (bkptCount++ < maxBkpts) {
108
try {
109
Thread.sleep(100);
110
} catch (InterruptedException ee) {
111
}
112
bkptRequest.enable();
113
}
114
}
115
116
public void vmDisconnected(VMDisconnectEvent event) {
117
println("Got VMDisconnectEvent");
118
}
119
120
/********** test core **********/
121
122
protected void runTests() throws Exception {
123
/*
124
* Get to the top of main()
125
* to determine targetClass and mainThread
126
*/
127
BreakpointEvent bpe = startToMain("BreakpointTarg");
128
targetClass = (ClassType)bpe.location().declaringType();
129
mainThread = bpe.thread();
130
EventRequestManager erm = vm().eventRequestManager();
131
132
Location loc1 = findLocation(
133
targetClass,
134
BreakpointTarg.BKPT_LINE);
135
136
bkptRequest = erm.createBreakpointRequest(loc1);
137
bkptRequest.enable();
138
debuggeeCountField = targetClass.fieldByName("count");
139
try {
140
141
addListener (this);
142
} catch (Exception ex){
143
ex.printStackTrace();
144
failure("failure: Could not add listener");
145
throw new Exception("BreakpointTest: failed");
146
}
147
148
int prevBkptCount;
149
vm().resume();
150
while (!vmDisconnected && bkptCount < maxBkpts) {
151
try {
152
Thread.sleep(5000);
153
} catch (InterruptedException ee) {
154
}
155
}
156
157
println("done with loop, final count = " +
158
((LongValue)targetClass.
159
getValue(debuggeeCountField)).value());
160
bkptRequest.disable();
161
removeListener(this);
162
163
164
/*
165
* deal with results of test
166
* if anything has called failure("foo") testFailed will be true
167
*/
168
if (!testFailed) {
169
println("BreakpointTest: passed");
170
} else {
171
throw new Exception("BreakpointTest: failed");
172
}
173
}
174
}
175
176