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/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.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: TC4
42
* Description: Exception breakpoint
43
* Steps: 1.Set method breakpoint on Main.foo()
44
* 2.Debug Main
45
* 3.Stops on line 27 in Main.java
46
*
47
* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.
48
* After <code>MethodEntryEvent</code> arrived, debugger checks method name and if
49
* the one corresponds to specified name, it checks line number of the
50
* event location. It should be 64th line, that is method <code>tc04x001a.foo</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.multithrd.";
64
private final static String debuggerName = prefix + "tc04x001";
65
private final static String debugeeName = debuggerName + "a";
66
private final static String methodName = "foo";
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
74
private ClassType debugeeClass;
75
76
private static void display(String msg) {
77
log.display(msg);
78
}
79
80
private static void complain(String msg) {
81
log.complain("debugger FAILURE> " + msg + "\n");
82
}
83
84
public static void main(String argv[]) {
85
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
86
}
87
88
public static int run(String argv[], PrintStream out) {
89
90
exitStatus = Consts.TEST_PASSED;
91
92
tc04x001 thisTest = new tc04x001();
93
94
ArgumentHandler argHandler = new ArgumentHandler(argv);
95
log = new Log(out, argHandler);
96
97
waitTime = argHandler.getWaitTime() * 60000;
98
99
Binder binder = new Binder(argHandler, log);
100
debugee = binder.bindToDebugee(debugeeName);
101
102
try {
103
thisTest.execTest();
104
} catch (Throwable e) {
105
complain("Unexpected " + e);
106
exitStatus = Consts.TEST_FAILED;
107
e.printStackTrace();
108
} finally {
109
debugee.resume();
110
}
111
display("Test finished. exitStatus = " + exitStatus);
112
113
return exitStatus;
114
}
115
116
private void execTest() throws Failure {
117
118
display("\nTEST BEGINS");
119
display("===========");
120
121
EventSet eventSet = null;
122
EventIterator eventIterator = null;
123
Event event;
124
long totalTime = waitTime;
125
long tmp, begin = System.currentTimeMillis(),
126
delta = 0;
127
boolean exit = false;
128
EventRequestManager evm = debugee.getEventRequestManager();
129
MethodEntryRequest mthdReq = evm.createMethodEntryRequest();
130
display("MethodEntryRequest created, expecting events "
131
+ "from method \"" + methodName + "\"");
132
display("---------------------------------------------"
133
+ "-----------");
134
mthdReq.addClassFilter(debugeeName);
135
mthdReq.enable();
136
137
debugee.resume();
138
139
while (totalTime > 0 && !exit) {
140
if (eventIterator == null || !eventIterator.hasNext()) {
141
try {
142
eventSet = debugee.VM().eventQueue().remove(totalTime);
143
} catch (InterruptedException e) {
144
new Failure(e);
145
}
146
if (eventSet != null) {
147
eventIterator = eventSet.eventIterator();
148
} else {
149
eventIterator = null;
150
}
151
}
152
if (eventIterator != null) {
153
while (eventIterator.hasNext()) {
154
event = eventIterator.nextEvent();
155
156
if (event instanceof MethodEntryEvent) {
157
display(" event ===>>> " + " MethodEntryEvent arrived");
158
hitMethodBreakpoint((MethodEntryEvent )event);
159
debugee.resume();
160
161
} else if (event instanceof VMDeathEvent) {
162
exit = true;
163
break;
164
} else if (event instanceof VMDisconnectEvent) {
165
exit = true;
166
break;
167
} // if
168
} // while
169
} // if
170
171
tmp = System.currentTimeMillis();
172
delta = tmp - begin;
173
totalTime -= delta;
174
begin = tmp;
175
}
176
177
if (totalTime <= 0) {
178
complain("out of wait time...");
179
exitStatus = Consts.TEST_FAILED;
180
}
181
if (brkpEventCount < tc04x001a.threadCount) {
182
complain("expecting " + tc04x001a.threadCount
183
+ " MethodBreakpoint events, but "
184
+ brkpEventCount + " events arrived.");
185
exitStatus = Consts.TEST_FAILED;
186
}
187
188
display("=============");
189
display("TEST FINISHES\n");
190
}
191
192
private void hitMethodBreakpoint(MethodEntryEvent event) {
193
ThreadReference thrd = event.thread();
194
195
display("event info:");
196
display("\tthread\t- " + event.thread().name());
197
try {
198
display("\tsource\t- " + event.location().sourceName());
199
} catch (AbsentInformationException e) {
200
}
201
display("\tmethod\t- " + event.location().method().name());
202
display("\tline\t- " + event.location().lineNumber());
203
204
if (!event.method().name().equals(methodName)) {
205
display("the event skipped, method - " + event.method().name() + "\n");
206
return;
207
}
208
209
if (event.location().lineNumber() == tc04x001a.checkMethodBrkpLine) {
210
display("!!!MethodBreakpoint stops on the expected line "
211
+ event.location().lineNumber() + " in method "
212
+ "\"" + event.method().name() + "\"!!!");
213
} else {
214
complain("MethodBreakpoint stops on line " + event.location().lineNumber()
215
+ " in method " + event.method().name()
216
+ ", expected line number is "
217
+ tc04x001a.checkMethodBrkpLine);
218
exitStatus = Consts.TEST_FAILED;
219
}
220
221
display("");
222
223
brkpEventCount++;
224
}
225
}
226
227