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