Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/tc02x004.java
41160 views
1
/*
2
* Copyright (c) 2002, 2019, 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
package nsk.jdi.BScenarios.multithrd;
25
26
import jdk.test.lib.Utils;
27
import nsk.share.*;
28
import nsk.share.jpda.*;
29
import nsk.share.jdi.*;
30
31
import com.sun.jdi.*;
32
import com.sun.jdi.request.*;
33
import com.sun.jdi.event.*;
34
35
import java.util.*;
36
import java.io.*;
37
38
/**
39
* This test is from the group of so-called Borland's scenarios and
40
* implements the following test case: <br>
41
* Suite 2 - Breakpoints (multiple threads) <br>
42
* Test case: TC2 <br>
43
* Description: Class breakpoint <br>
44
* Steps: 1.Add class breakpoint: singlethread.Class1 <br>
45
* 2.Debug Main <br>
46
* X. Stops on line 13 in Class1.java <br>
47
*
48
* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.
49
* After <code>MethodEntryEvent</code> arrived, debugger checks line number of one's
50
* location. It should be 73th line, that is constructor of <code>tc02x004aClass1</code>
51
* class. Every thread must generate <code>MethodEntryEvent</code>.
52
*
53
* In case, when at least one event doesn't arrive during waittime
54
* interval or line number of event is wrong, test fails.
55
*/
56
57
public class tc02x004 {
58
59
public final static String SGL_READY = "ready";
60
public final static String SGL_PERFORM = "perform";
61
public final static String SGL_QUIT = "quit";
62
63
private final static String prefix = "nsk.jdi.BScenarios.multithrd.";
64
private final static String debuggerName = prefix + "tc02x004";
65
private final static String debugeeName = debuggerName + "a";
66
private final static String testedClassName = debugeeName + "Class1";
67
68
private static int exitStatus;
69
private static Log log;
70
private static Debugee debugee;
71
private static long waitTime;
72
private static int brkpEventCount = 0;
73
MethodEntryRequest mthdReq;
74
EventRequestManager evm;
75
76
private ClassType debugeeClass;
77
78
private static void display(String msg) {
79
log.display(msg);
80
}
81
82
private static void complain(String msg) {
83
log.complain("debugger FAILURE> " + msg + "\n");
84
}
85
86
public static void main(String argv[]) {
87
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
88
}
89
90
public static int run(String argv[], PrintStream out) {
91
92
exitStatus = Consts.TEST_PASSED;
93
94
tc02x004 thisTest = new tc02x004();
95
96
ArgumentHandler argHandler = new ArgumentHandler(argv);
97
log = new Log(out, argHandler);
98
99
waitTime = Utils.adjustTimeout(argHandler.getWaitTime() * 60000);
100
101
Binder binder = new Binder(argHandler, log);
102
debugee = binder.bindToDebugee(debugeeName);
103
debugee.redirectStderr(log.getOutStream());
104
thisTest.evm = debugee.getEventRequestManager();
105
106
try {
107
thisTest.execTest();
108
} catch (Throwable e) {
109
complain("Unexpected " + e);
110
exitStatus = Consts.TEST_FAILED;
111
e.printStackTrace();
112
thisTest.evm.deleteEventRequest(thisTest.mthdReq);
113
} finally {
114
debugee.resume();
115
}
116
display("Test finished. exitStatus = " + exitStatus);
117
118
debugee.endDebugee();
119
return exitStatus;
120
}
121
122
private void execTest() throws Failure {
123
124
display("\nTEST BEGINS");
125
display("===========");
126
debugee.resume();
127
128
EventSet eventSet = null;
129
EventIterator eventIterator = null;
130
Event event;
131
long totalTime = waitTime;
132
long tmp, begin = System.currentTimeMillis(),
133
delta = 0;
134
boolean exit = false;
135
136
mthdReq = evm.createMethodEntryRequest();
137
mthdReq.addClassFilter(testedClassName);
138
mthdReq.enable();
139
debugee.resume();
140
141
while (totalTime > 0 && !exit) {
142
if (eventIterator == null || !eventIterator.hasNext()) {
143
try {
144
eventSet = debugee.VM().eventQueue().remove(totalTime);
145
} catch (InterruptedException e) {
146
new Failure(e);
147
}
148
if (eventSet != null) {
149
eventIterator = eventSet.eventIterator();
150
} else {
151
eventIterator = null;
152
}
153
}
154
if (eventIterator != null) {
155
while (eventIterator.hasNext()) {
156
event = eventIterator.nextEvent();
157
158
if (event instanceof MethodEntryEvent) {
159
display(" event ===>>> " + (brkpEventCount+1) + " MethodEntryEvent arrived");
160
hitClassBreakpoint((MethodEntryEvent )event);
161
debugee.resume();
162
163
} else if (event instanceof VMDeathEvent) {
164
exit = true;
165
break;
166
} else if (event instanceof VMDisconnectEvent) {
167
exit = true;
168
break;
169
} // if
170
} // while
171
} // if
172
exit = exit || (brkpEventCount == tc02x004a.threadCount);
173
tmp = System.currentTimeMillis();
174
delta = tmp - begin;
175
totalTime -= delta;
176
begin = tmp;
177
}
178
179
if (totalTime <= 0) {
180
complain("out of wait time...");
181
exitStatus = Consts.TEST_FAILED;
182
}
183
if (brkpEventCount < tc02x004a.threadCount) {
184
complain("expecting " + tc02x004a.threadCount
185
+ " breakpoint events, but "
186
+ brkpEventCount + " events arrived.");
187
exitStatus = Consts.TEST_FAILED;
188
}
189
190
display("=============");
191
display("TEST FINISHES\n");
192
}
193
194
private void hitClassBreakpoint(MethodEntryEvent event) {
195
ThreadReference thrd = event.thread();
196
197
display("event info:");
198
display("\tthread\t- " + event.thread().name());
199
try {
200
display("\tsource\t- " + event.location().sourceName());
201
} catch (AbsentInformationException e) {
202
}
203
display("\tmethod\t- " + event.location().method().name());
204
display("\tline\t- " + event.location().lineNumber());
205
206
display("thread:\t" + event.thread().name());
207
try {
208
display("source:\t" + event.location().sourceName());
209
} catch (AbsentInformationException e) {
210
}
211
display("method:\t" + event.location().method().name());
212
display("line:\t" + event.location().lineNumber());
213
if (event.location().lineNumber() == tc02x004a.checkClassBrkpLine) {
214
display("ClassBreakpoint stops on the expected line "
215
+ event.location().lineNumber() + " in method "
216
+ event.method().name());
217
} else {
218
complain("ClassBreakpoint stops on line " + event.location().lineNumber()
219
+ " in method " + event.method().name()
220
+ ", expected line number is "
221
+ tc02x004a.checkClassBrkpLine);
222
exitStatus = Consts.TEST_FAILED;
223
}
224
225
display("");
226
227
brkpEventCount++;
228
}
229
}
230
231