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/tc03x003.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>tc03x003aClass1</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 tc03x003 {
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 + "tc03x003";
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 eventCount = 0;
73
private final static int expectedEventCount = 3;
74
75
private EventRequestManager evm = null;
76
private MethodEntryRequest mthdReq = 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
tc03x003 thisTest = new tc03x003();
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(testedClassName);
123
crq.enable();
124
125
// separate thread to handle event
126
Thread eventHandler = new Thread() {
127
public void run() {
128
EventQueue eventQueue = debugee.VM().eventQueue();
129
while (!exit) {
130
EventSet eventSet = null;
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
display(" event ===>>> " + event);
145
ClassPrepareEvent clsEvent = (ClassPrepareEvent)event;
146
hitEvent(clsEvent);
147
148
mthdReq = evm.createMethodEntryRequest();
149
ReferenceType testedClass = clsEvent.referenceType();
150
mthdReq.addClassFilter(testedClass);
151
mthdReq.enable();
152
153
debugee.resume();
154
155
} else if (event instanceof MethodEntryEvent) {
156
display(" event ===>>> " + event);
157
hitEvent((MethodEntryEvent )event);
158
debugee.resume();
159
160
} else if (event instanceof VMDeathEvent) {
161
exit = true;
162
break;
163
} else if (event instanceof VMDisconnectEvent) {
164
exit = true;
165
break;
166
} else {
167
throw new Failure("Unexpected event received:\n\t" + event);
168
} // if
169
exit = exit || (eventCount >= expectedEventCount);
170
} // while
171
} // while
172
} // run()
173
}; // eventHandler
174
175
display("Starting handling event");
176
eventHandler.start();
177
178
debugee.resume();
179
debugee.receiveExpectedSignal(SGL_READY);
180
181
display("\nTEST BEGINS");
182
display("===========");
183
debugee.sendSignal(SGL_LOAD);
184
185
display("Waiting for all events received");
186
try {
187
eventHandler.join(waitTime);
188
} catch (InterruptedException e) {
189
throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"
190
+ e);
191
} finally {
192
crq.disable();
193
mthdReq.disable();
194
exit = true;
195
if (eventHandler.isAlive()) {
196
display("Interrupting event handling thread");
197
eventHandler.interrupt();
198
}
199
}
200
201
if (eventCount < expectedEventCount) {
202
complain("Expecting " + expectedEventCount
203
+ " BreakpointEvents, but "
204
+ eventCount + " events arrived.");
205
exitStatus = Consts.TEST_FAILED;
206
}
207
208
display("=============");
209
display("TEST FINISHES\n");
210
debugee.sendSignal(SGL_QUIT);
211
}
212
213
private void hitEvent(MethodEntryEvent event) {
214
ThreadReference thrd = event.thread();
215
216
display("event info:");
217
display("\tthread\t- " + event.thread().name());
218
try {
219
display("\tsource\t- " + event.location().sourceName());
220
} catch (AbsentInformationException e) {
221
}
222
display("\tmethod\t- " + event.location().method().name());
223
display("\tline\t- " + event.location().lineNumber());
224
225
eventCount++;
226
if (event.location().lineNumber() == tc03x003a.checkLastLine1 ||
227
event.location().lineNumber() == tc03x003a.checkLastLine2) {
228
display("MethodEntryEvent occurs stops on the expected line "
229
+ event.location().lineNumber() + " in method "
230
+ event.method().name());
231
} else {
232
complain("MewthodEntryEvent occurs on line " + event.location().lineNumber()
233
+ " in method " + event.method().name()
234
+ ", expected line numbers are "
235
+ tc03x003a.checkLastLine1 + " or "
236
+ tc03x003a.checkLastLine2);
237
exitStatus = Consts.TEST_FAILED;
238
}
239
240
display("");
241
242
}
243
244
private void hitEvent(ClassPrepareEvent event) {
245
display("ClassPrepareEvent occurs\n");
246
eventCount++;
247
}
248
}
249
250