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/tc02x001.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: <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>tc02x001aClass1</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 tc02x001 {
57
58
public final static String SGL_READY = "ready";
59
public final static String SGL_PERFORM = "perform";
60
public final static String SGL_QUIT = "quit";
61
62
private final static String prefix = "nsk.jdi.BScenarios.multithrd.";
63
private final static String debuggerName = prefix + "tc02x001";
64
private final static String debugeeName = debuggerName + "a";
65
private final static String testedClassName = debugeeName + "Class1";
66
67
private static int exitStatus;
68
private static Log log;
69
private static Debugee debugee;
70
private static long waitTime;
71
private static int brkpEventCount = 0;
72
73
private ClassType debugeeClass;
74
75
private static void display(String msg) {
76
log.display(msg);
77
}
78
79
private static void complain(String msg) {
80
log.complain("debugger FAILURE> " + msg + "\n");
81
}
82
83
public static void main(String argv[]) {
84
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
85
}
86
87
public static int run(String argv[], PrintStream out) {
88
89
exitStatus = Consts.TEST_PASSED;
90
91
tc02x001 thisTest = new tc02x001();
92
93
ArgumentHandler argHandler = new ArgumentHandler(argv);
94
log = new Log(out, argHandler);
95
96
waitTime = argHandler.getWaitTime() * 60000;
97
98
debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);
99
100
try {
101
thisTest.execTest();
102
} catch (Throwable e) {
103
complain("Unexpected " + e);
104
exitStatus = Consts.TEST_FAILED;
105
e.printStackTrace();
106
} finally {
107
debugee.resume();
108
debugee.quit();
109
}
110
display("Test finished. exitStatus = " + exitStatus);
111
112
return exitStatus;
113
}
114
115
private void execTest() throws Failure {
116
117
debugeeClass = (ClassType)debugee.classByName(debugeeName);
118
display("Tested class\t:" + debugeeClass.name());
119
120
display("\nTEST BEGINS");
121
display("===========");
122
123
EventSet eventSet = null;
124
EventIterator eventIterator = null;
125
Event event;
126
long totalTime = waitTime;
127
long tmp, begin = System.currentTimeMillis(),
128
delta = 0;
129
boolean exit = false;
130
131
EventRequestManager evm = debugee.getEventRequestManager();
132
MethodEntryRequest mthdReq = evm.createMethodEntryRequest();
133
mthdReq.addClassFilter(testedClassName);
134
mthdReq.enable();
135
136
debugee.resume();
137
debugee.sendSignal(SGL_PERFORM);
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
hitClassBreakpoint((MethodEntryEvent )event);
158
display(" event ===>>> " + (brkpEventCount+1) + " MethodEntryEvent arrived");
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
exit = exit || (brkpEventCount == tc02x001a.threadCount);
171
tmp = System.currentTimeMillis();
172
delta = tmp - begin;
173
totalTime -= delta;
174
begin = tmp;
175
}
176
177
if (brkpEventCount < tc02x001a.threadCount) {
178
if (totalTime <= 0) {
179
complain("out of wait time...");
180
}
181
complain("expecting " + tc02x001a.threadCount
182
+ " MethodBreakpoint events, but "
183
+ brkpEventCount + " events arrived.");
184
exitStatus = Consts.TEST_FAILED;
185
}
186
187
display("=============");
188
display("TEST FINISHES\n");
189
}
190
191
private void hitClassBreakpoint(MethodEntryEvent event) {
192
ThreadReference thrd = event.thread();
193
194
display("event info:");
195
display("\tthread\t- " + event.thread().name());
196
try {
197
display("\tsource\t- " + event.location().sourceName());
198
} catch (AbsentInformationException e) {
199
}
200
display("\tmethod\t- " + event.location().method().name());
201
display("\tline\t- " + event.location().lineNumber());
202
203
if (event.location().lineNumber() == tc02x001a.checkClassBrkpLine) {
204
display("ClassBreakpoint stops on the expected line "
205
+ event.location().lineNumber() + " in method "
206
+ event.method().name());
207
} else {
208
complain("ClassBreakpoint stops on line " + event.location().lineNumber()
209
+ " in method " + event.method().name()
210
+ ", expected line number is "
211
+ tc02x001a.checkClassBrkpLine);
212
exitStatus = Consts.TEST_FAILED;
213
}
214
215
display("");
216
217
brkpEventCount++;
218
}
219
}
220
221