Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/classUnloadRequests/clsunlreq001.java
41161 views
1
/*
2
* Copyright (c) 2001, 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.EventRequestManager.classUnloadRequests;
25
26
import com.sun.jdi.VMDisconnectedException;
27
import com.sun.jdi.VirtualMachine;
28
import com.sun.jdi.request.ClassUnloadRequest;
29
import com.sun.jdi.request.EventRequestManager;
30
import com.sun.jdi.event.*;
31
32
import java.util.List;
33
import java.io.*;
34
35
import nsk.share.*;
36
import nsk.share.jpda.*;
37
import nsk.share.jdi.*;
38
39
/**
40
* The test checks that the JDI method
41
* <code>com.sun.jdi.request.EventRequestManager.classUnloadRequests()</code>
42
* properly returns all previously created ClassUnloadRequest objects when:
43
* <li>event requests are disabled
44
* <li>event requests are enabled.<br>
45
* ClassUnloadRequest objects are distinguished by the different
46
* <code>EventRequest</code>'s properties.<br>
47
* EventHandler was added as workaround for the bug 4430096.
48
* This prevents the target VM from potential hangup.
49
*/
50
public class clsunlreq001 {
51
public static final int PASSED = 0;
52
public static final int FAILED = 2;
53
public static final int JCK_STATUS_BASE = 95;
54
static final String DEBUGGEE_CLASS =
55
"nsk.jdi.EventRequestManager.classUnloadRequests.clsunlreq001t";
56
static final String COMMAND_READY = "ready";
57
static final String COMMAND_QUIT = "quit";
58
59
static final int CLSUNL_NUM = 7;
60
static final String PROPS[][] = {
61
{"first", "a quick"},
62
{"second", "brown"},
63
{"third", "fox"},
64
{"fourth", "jumps"},
65
{"fifth", "over"},
66
{"sixth", "the lazy"},
67
{"seventh", "dog"}
68
};
69
70
private ArgumentHandler argHandler;
71
private Log log;
72
private IOPipe pipe;
73
private Debugee debuggee;
74
private VirtualMachine vm;
75
private EventListener elThread;
76
private volatile int tot_res = PASSED;
77
78
public static void main (String argv[]) {
79
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
80
}
81
82
public static int run(String argv[], PrintStream out) {
83
return new clsunlreq001().runIt(argv, out);
84
}
85
86
private int runIt(String args[], PrintStream out) {
87
argHandler = new ArgumentHandler(args);
88
log = new Log(out, argHandler);
89
Binder binder = new Binder(argHandler, log);
90
ClassUnloadRequest clunlRequest[] = new ClassUnloadRequest[CLSUNL_NUM];
91
String cmd;
92
93
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
94
pipe = debuggee.createIOPipe();
95
debuggee.redirectStderr(log, "clsunlreq001t.err> ");
96
vm = debuggee.VM();
97
EventRequestManager erManager = vm.eventRequestManager();
98
debuggee.resume();
99
cmd = pipe.readln();
100
if (!cmd.equals(COMMAND_READY)) {
101
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
102
tot_res = FAILED;
103
return quitDebuggee();
104
}
105
106
for (int i=0; i<CLSUNL_NUM; i++) {
107
log.display("Creating ClassUnloadRequest #" + i
108
+ " with the property ("
109
+ PROPS[i][0] + "," + PROPS[i][1] + ")...");
110
clunlRequest[i] = erManager.createClassUnloadRequest();
111
clunlRequest[i].putProperty(PROPS[i][0], PROPS[i][1]);
112
}
113
elThread = new EventListener();
114
elThread.start();
115
116
// Check ClassUnloadRequest requests when event requests are disabled
117
log.display("\n1) Getting ClassUnloadRequest objects with disabled event requests...");
118
checkRequests(erManager, 1);
119
120
// Check ClassUnloadRequest requests when event requests are enabled
121
for (int i=0; i<CLSUNL_NUM; i++) {
122
clunlRequest[i].enable();
123
}
124
log.display("\n2) Getting ClassUnloadRequest objects with enabled event requests...");
125
checkRequests(erManager, 2);
126
127
// Finish the test
128
for (int i=0; i<CLSUNL_NUM; i++) {
129
clunlRequest[i].disable();
130
}
131
return quitDebuggee();
132
}
133
134
private void checkRequests(EventRequestManager erManager, int t_case) {
135
List reqL = erManager.classUnloadRequests();
136
if (reqL.size() != CLSUNL_NUM) {
137
log.complain("TEST CASE #" + t_case + " FAILED: found " + reqL.size()
138
+ " ClassUnload requests\n\texpected: " + CLSUNL_NUM);
139
tot_res = FAILED;
140
return;
141
}
142
for (int i=0; i<CLSUNL_NUM; i++) {
143
ClassUnloadRequest clunlReq =
144
(ClassUnloadRequest) reqL.get(i);
145
boolean notFound = true;
146
for (int j=0; j<CLSUNL_NUM; j++) {
147
String propKey = (String) clunlReq.getProperty(PROPS[j][0]);
148
if (propKey != null) {
149
if (propKey.equals(PROPS[j][1])) {
150
log.display("Found expected ClassUnload request with the property: ("
151
+ PROPS[j][0] + "," + propKey + ")");
152
} else {
153
log.complain("TEST CASE #" + t_case
154
+ " FAILED: found ClassUnload request with unexpected property: ("
155
+ PROPS[j][0] + "," + propKey + ")");
156
tot_res = FAILED;
157
}
158
notFound = false;
159
break;
160
}
161
}
162
if (notFound) {
163
log.complain("\nTEST CASE #" + t_case
164
+ " FAILED: found unexpected ClassUnload request");
165
tot_res = FAILED;
166
}
167
}
168
}
169
170
private int quitDebuggee() {
171
if (elThread != null) {
172
elThread.isConnected = false;
173
try {
174
if (elThread.isAlive())
175
elThread.join();
176
} catch (InterruptedException e) {
177
log.complain("TEST INCOMPLETE: caught InterruptedException "
178
+ e);
179
tot_res = FAILED;
180
}
181
}
182
183
pipe.println(COMMAND_QUIT);
184
185
// Class containing a critical section which may lead to time out of the test
186
class criticalSection extends Thread {
187
public void run() {
188
debuggee.waitFor();
189
}
190
}
191
192
criticalSection critSect = new criticalSection();
193
log.display("\nStarting potential timed out section: waiting "
194
+ argHandler.getWaitTime() + " minute(s) for debuggee's exit...");
195
critSect.start();
196
try {
197
critSect.join(argHandler.getWaitTime()*60000);
198
if (critSect.isAlive()) {
199
log.complain("TEST FAILED: Timeout occured while waiting for debuggee's exit");
200
return FAILED;
201
}
202
} catch (InterruptedException e) {
203
log.complain("TEST INCOMPLETE: InterruptedException caught while waiting for debuggee's exit");
204
return FAILED;
205
}
206
log.display("Potential timed out section passed\n");
207
208
int debStat = debuggee.getStatus();
209
if (debStat != (JCK_STATUS_BASE + PASSED)) {
210
log.complain("TEST FAILED: debuggee's process finished with status: "
211
+ debStat);
212
tot_res = FAILED;
213
} else
214
log.display("Debuggee's process finished with status: "
215
+ debStat);
216
217
return tot_res;
218
}
219
220
class EventListener extends Thread {
221
public volatile boolean isConnected = true;
222
223
public void run() {
224
try {
225
do {
226
EventSet eventSet = vm.eventQueue().remove(1000);
227
if (eventSet != null) { // there is not a timeout
228
EventIterator it = eventSet.eventIterator();
229
while (it.hasNext()) {
230
Event event = it.nextEvent();
231
if (event instanceof VMDeathEvent) {
232
tot_res = FAILED;
233
isConnected = false;
234
log.complain("TEST FAILED: unexpected VMDeathEvent");
235
} else if (event instanceof VMDisconnectEvent) {
236
tot_res = FAILED;
237
isConnected = false;
238
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
239
} else
240
log.display("EventListener: following JDI event occured: "
241
+ event.toString());
242
}
243
if (isConnected) {
244
eventSet.resume();
245
}
246
}
247
} while (isConnected);
248
} catch (InterruptedException e) {
249
tot_res = FAILED;
250
log.complain("FAILURE in EventListener: caught unexpected "
251
+ e);
252
} catch (VMDisconnectedException e) {
253
tot_res = FAILED;
254
log.complain("FAILURE in EventListener: caught unexpected "
255
+ e);
256
e.printStackTrace();
257
}
258
log.display("EventListener: exiting");
259
}
260
}
261
}
262
263