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/tc03x001.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.multithrd;
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:
40
* Suite 2 - Breakpoints (multiple threads)
41
* Test case: TC3
42
* Description: Exception breakpoint
43
* Steps: 1.Set caught exception breakpoint on class
44
* javax.sound.midi.MidiUnavailableException
45
* 2.Debug Main
46
* X. Stops on line 42 in Main.java
47
*
48
* When the test is starting debugee, debugger creates <code>ExceptionRequest</code>.
49
* After <code>ExceptionEvent</code> arrived, debugger checks line number of one's
50
* location. It should be 74th line, that is throwing <code>tc03x001aException</code>.
51
* Every thread must generate <code>ExceptionEvent</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 tc03x001 {
58
59
public final static String SGL_READY = "ready";
60
public final static String SGL_LOAD = "load";
61
public final static String SGL_PERFORM = "perform";
62
public final static String SGL_QUIT = "quit";
63
64
private final static String prefix = "nsk.jdi.BScenarios.multithrd.";
65
private final static String debuggerName = prefix + "tc03x001";
66
private final static String debugeeName = debuggerName + "a";
67
private final static String exceptionName = debugeeName + "Exception";
68
69
private static int exitStatus;
70
private static Log log;
71
private static Debugee debugee;
72
private static long waitTime;
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
private static void display(String msg) {
80
log.display(msg);
81
}
82
83
private static void complain(String msg) {
84
log.complain("debugger FAILURE> " + msg + "\n");
85
}
86
87
public static void main(String argv[]) {
88
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
89
}
90
91
public static int run(String argv[], PrintStream out) {
92
93
exitStatus = Consts.TEST_PASSED;
94
tc03x001 thisTest = new tc03x001();
95
96
ArgumentHandler argHandler = new ArgumentHandler(argv);
97
log = new Log(out, argHandler);
98
waitTime = argHandler.getWaitTime() * 60000;
99
100
Binder binder = new Binder(argHandler, log);
101
debugee = binder.bindToDebugee(debugeeName);
102
IOPipe pipe = debugee.createIOPipe();
103
104
try {
105
thisTest.execTest();
106
} catch (Throwable e) {
107
complain("Unexpected " + e);
108
exitStatus = Consts.TEST_FAILED;
109
e.printStackTrace();
110
} finally {
111
debugee.endDebugee();
112
}
113
display("Test finished. exitStatus = " + exitStatus);
114
115
return exitStatus;
116
}
117
118
private void execTest() throws Failure {
119
evm = debugee.getEventRequestManager();
120
121
ClassPrepareRequest crq = evm.createClassPrepareRequest();
122
crq.addClassFilter(exceptionName);
123
crq.enable();
124
125
// event handling thread
126
Thread eventHandler = new Thread() {
127
public void run() {
128
EventQueue eventQueue = debugee.VM().eventQueue();
129
EventSet eventSet = null;
130
while (!exit) {
131
try {
132
eventSet = eventQueue.remove(1000);
133
} catch (InterruptedException e) {
134
new Failure("Event handling thread interrupted:\n\t" + e);
135
}
136
if (eventSet == null) {
137
continue;
138
}
139
EventIterator eventIterator = eventSet.eventIterator();
140
while (eventIterator.hasNext()) {
141
Event event = eventIterator.nextEvent();
142
143
if (event instanceof ClassPrepareEvent) {
144
exReq = evm.createExceptionRequest(
145
((ClassPrepareEvent )event).referenceType(),
146
true, false);
147
exReq.enable();
148
debugee.resume();
149
150
} else if (event instanceof ExceptionEvent) {
151
hitEvent((ExceptionEvent )event);
152
debugee.resume();
153
154
} else if (event instanceof VMDeathEvent) {
155
exit = true;
156
} else if (event instanceof VMDisconnectEvent) {
157
exit = true;
158
break;
159
} else {
160
throw new Failure("Unexpected event:\n\t" + event);
161
} // if
162
exit = exit || (eventCount >= tc03x001a.threadCount);
163
} // while
164
} // while
165
} // run()
166
}; // eventHadler
167
168
display("Starting handling event");
169
eventHandler.start();
170
171
debugee.resume();
172
debugee.receiveExpectedSignal(SGL_READY);
173
174
display("\nTEST BEGINS");
175
display("===========");
176
debugee.sendSignal(SGL_LOAD);
177
178
display("Waiting for all events received");
179
try {
180
eventHandler.join(waitTime);
181
} catch (InterruptedException e) {
182
throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"
183
+ e);
184
} finally {
185
crq.disable();
186
exReq.disable();
187
exit = true;
188
if (eventHandler.isAlive()) {
189
display("Interrupting event handling thread");
190
eventHandler.interrupt();
191
}
192
}
193
194
if (eventCount < tc03x001a.threadCount) {
195
complain("expecting " + tc03x001a.threadCount
196
+ " ExceptionEvents, but "
197
+ eventCount + " events arrived.");
198
exitStatus = Consts.TEST_FAILED;
199
}
200
display("=============");
201
display("TEST FINISHES\n");
202
debugee.sendSignal(SGL_QUIT);
203
}
204
205
private void hitEvent(ExceptionEvent event) {
206
ThreadReference thrd = event.thread();
207
208
display("event info:");
209
display("\tthread\t- " + event.thread().name());
210
try {
211
display("\tsource\t- " + event.location().sourceName());
212
} catch (AbsentInformationException e) {
213
}
214
display("\tmethod\t- " + event.location().method().name());
215
display("\tline\t- " + event.location().lineNumber());
216
217
if (event.location().lineNumber() == tc03x001a.checkExBrkpLine) {
218
display("ExceptionEvent occurs on the expected line "
219
+ event.location().lineNumber() + " in method "
220
+ event.location().method().name());
221
} else {
222
complain("ExceptionEvent occurs stops on line " + event.location().lineNumber()
223
+ " in method " + event.location().method().name()
224
+ ", expected line number is "
225
+ tc03x001a.checkExBrkpLine);
226
exitStatus = Consts.TEST_FAILED;
227
}
228
229
display("");
230
231
eventCount++;
232
}
233
}
234
235