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/tc03x002.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>tc03x002aClass1</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 tc03x002 {
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 + "tc03x002";
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 = 2;
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
tc03x002 thisTest = new tc03x002();
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 (Exception 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
// 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
display(" event ===>>> " + event);
145
mthdReq = evm.createMethodEntryRequest();
146
mthdReq.addClassFilter(testedClassName);
147
mthdReq.enable();
148
debugee.resume();
149
150
} else if (event instanceof MethodEntryEvent) {
151
display(" event ===>>> " + event);
152
hitEvent((MethodEntryEvent )event);
153
debugee.resume();
154
155
} else if (event instanceof VMDeathEvent) {
156
exit = true;
157
break;
158
} else if (event instanceof VMDisconnectEvent) {
159
exit = true;
160
break;
161
} else {
162
throw new Failure("Unexpected event:\n\t" + event);
163
} // if
164
exit = exit || (eventCount >= expectedEventCount);
165
} // while
166
} // while
167
} // run()
168
}; // eventHadler
169
170
display("Starting handling event");
171
eventHandler.start();
172
173
debugee.resume();
174
debugee.receiveExpectedSignal(SGL_READY);
175
176
display("\nTEST BEGINS");
177
display("===========");
178
debugee.sendSignal(SGL_LOAD);
179
180
display("Waiting for all events received");
181
try {
182
eventHandler.join(waitTime);
183
} catch (InterruptedException e) {
184
throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"
185
+ e);
186
} finally {
187
crq.disable();
188
mthdReq.disable();
189
exit = true;
190
if (eventHandler.isAlive()) {
191
display("Interrupting event handling thread");
192
eventHandler.interrupt();
193
}
194
}
195
196
if (eventCount < expectedEventCount) {
197
complain("Expecting " + expectedEventCount
198
+ " MethodEntryEvents, but "
199
+ eventCount + " events arrived.");
200
exitStatus = Consts.TEST_FAILED;
201
}
202
203
display("=============");
204
display("TEST FINISHES\n");
205
debugee.sendSignal(SGL_QUIT);
206
}
207
208
private void hitEvent(MethodEntryEvent event) {
209
ThreadReference thrd = event.thread();
210
211
display("event info:");
212
display("\tthread\t- " + event.thread().name());
213
try {
214
display("\tsource\t- " + event.location().sourceName());
215
} catch (AbsentInformationException e) {
216
}
217
display("\tmethod\t- " + event.location().method().name());
218
display("\tline\t- " + event.location().lineNumber());
219
220
eventCount++;
221
if (event.location().lineNumber() == tc03x002a.checkLastLine1 ||
222
event.location().lineNumber() == tc03x002a.checkLastLine2) {
223
display("MethodEntryEvent occurs on the expected line "
224
+ event.location().lineNumber() + " in method "
225
+ event.method().name());
226
} else {
227
complain("MethodEntryEvent occurs on line " + event.location().lineNumber()
228
+ " in method " + event.method().name()
229
+ ", expected line numbers are "
230
+ tc03x002a.checkLastLine1 + " or "
231
+ tc03x002a.checkLastLine2);
232
exitStatus = Consts.TEST_FAILED;
233
}
234
235
display("");
236
}
237
}
238
239