Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassUnloadEvent/className/classname001.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.ClassUnloadEvent.className;
25
26
import com.sun.jdi.*;
27
import com.sun.jdi.event.*;
28
import com.sun.jdi.request.*;
29
30
import java.io.*;
31
import java.util.List;
32
33
import nsk.share.*;
34
import nsk.share.jpda.*;
35
import nsk.share.jdi.*;
36
37
38
// This class is the debugger application in the test
39
40
public class classname001 {
41
static final int PASSED = 0;
42
static final int FAILED = 2;
43
static final int JCK_STATUS_BASE = 95;
44
45
static final int TIMEOUT_DELTA = 1000; // milliseconds
46
47
static final String COMMAND_READY = "ready";
48
static final String COMMAND_QUIT = "quit";
49
static final String COMMAND_LOAD = "load";
50
static final String COMMAND_LOADED = "loaded";
51
static final String COMMAND_UNLOAD = "unload";
52
static final String COMMAND_UNLOADED = "unloaded";
53
54
static final String PREFIX = "nsk.jdi.ClassUnloadEvent.className";
55
static final String DEBUGGEE_NAME = PREFIX + ".classname001a";
56
static final String CHECKED_CLASS = PREFIX + ".classname001b";
57
static final String KLASSLOADER = ClassUnloader.INTERNAL_CLASS_LOADER_NAME;
58
59
static private Debugee debuggee;
60
static private VirtualMachine vm;
61
static private IOPipe pipe;
62
static private Log log;
63
static private ArgumentHandler argHandler;
64
static private EventSet eventSet;
65
66
static private ClassUnloadRequest checkedRequest;
67
68
static private long eventTimeout;
69
static private boolean testFailed;
70
static private boolean eventReceived;
71
72
public static void main (String args[]) {
73
System.exit(run(args, System.out) + JCK_STATUS_BASE);
74
}
75
76
public static int run(final String args[], final PrintStream out) {
77
78
testFailed = false;
79
eventReceived = false;
80
81
argHandler = new ArgumentHandler(args);
82
log = new Log(out, argHandler);
83
eventTimeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
84
85
// launch debugee
86
87
Binder binder = new Binder(argHandler, log);
88
log.display("Connecting to debuggee");
89
debuggee = binder.bindToDebugee(DEBUGGEE_NAME);
90
debuggee.redirectStderr(log, "classname001a >");
91
92
pipe = debuggee.createIOPipe();
93
vm = debuggee.VM();
94
95
// create request and wait for ClassUnloadEvent
96
97
try {
98
99
// resume debugee and wait for it becomes ready
100
log.display("Resuming debuggee");
101
debuggee.resume();
102
103
log.display("Waiting for command: " + COMMAND_READY);
104
String command = pipe.readln();
105
if (command == null || !command.equals(COMMAND_READY)) {
106
throw new Failure("TEST BUG: unexpected debuggee's command: " + command);
107
}
108
109
// get mirror of debugee class
110
ReferenceType rType;
111
if ((rType = debuggee.classByName(DEBUGGEE_NAME)) == null) {
112
throw new Failure("TEST BUG: cannot find debuggee's class " + DEBUGGEE_NAME);
113
}
114
115
// send command to load checked class and waits for a confirmation
116
pipe.println(COMMAND_LOAD);
117
log.display("Waiting for checked class is loaded");
118
command = pipe.readln();
119
120
if (command == null || !command.equals(COMMAND_LOADED)) {
121
throw new Failure("TEST BUG: unexpected debuggee's command: " + command);
122
}
123
124
// checked class has been loaded!
125
log.display("Checked class has been loaded in debuggee!");
126
127
// check that checked class is loaded in debugee
128
log.display("Finding checked class in debuggee");
129
if ((rType = debuggee.classByName(CHECKED_CLASS)) == null) {
130
throw new Failure("TEST BUG: cannot find checked class loaded: " + CHECKED_CLASS);
131
}
132
rType = null;
133
134
// check that user-defined classloader is also loaded in debuggee
135
log.display("Finding user-defined class loader in debuggee");
136
if ((rType = debuggee.classByName(KLASSLOADER)) == null) {
137
throw new Failure("TEST BUG: cannot find user-defined classloader loaded: " + KLASSLOADER);
138
}
139
rType = null;
140
141
// create request for class unload event
142
log.display("Creating request for ClassUnloadEvent");
143
EventRequestManager erManager = vm.eventRequestManager();
144
if ((checkedRequest = erManager.createClassUnloadRequest()) == null) {
145
throw new Failure("TEST BUG: unable to create ClassUnloadRequest");
146
} else {
147
log.display("ClassUnloadRequest created");
148
}
149
// checkedRequest.addClassFilter("nsk.jdi.ClassUnloadEvent.className.*");
150
151
// enable event request
152
log.display("Enabling event request");
153
checkedRequest.enable();
154
155
// turn off pipe pinging
156
pipe.setPingTimeout(0);
157
158
// force checked class to be unloaded from debuggee
159
log.display("Waiting for checked class is unloaded");
160
pipe.println(COMMAND_UNLOAD);
161
command = pipe.readln();
162
163
// end the test if checked class has not been actually unloaded or error occurs
164
if (command != null && command.equals(COMMAND_LOADED)) {
165
throw new Warning("TEST INCOMPLETE: unable to unload class");
166
}
167
168
if (command == null || !command.equals(COMMAND_UNLOADED)) {
169
throw new Failure("TEST BUG: unexpected debuggee's command: " + command);
170
}
171
172
// checked class has been unloaded
173
log.display("Checked class forced to be unloaded from debuggee!");
174
175
// waiting for event until timeout exceeds
176
log.display("Waiting for ClassUnloadEvent for checked class");
177
long timeToFinish = System.currentTimeMillis() + eventTimeout;
178
while (!eventReceived && System.currentTimeMillis() < timeToFinish) {
179
180
// get next event set
181
eventSet = null;
182
try {
183
eventSet = vm.eventQueue().remove(TIMEOUT_DELTA);
184
} catch (Exception e) {
185
throw new Failure("TEST INCOMPLETE: Unexpected exception while getting event: " + e);
186
}
187
if (eventSet == null)
188
continue;
189
190
// handle each event from the event set
191
EventIterator eventIterator = eventSet.eventIterator();
192
while (eventIterator.hasNext()) {
193
194
Event event = eventIterator.nextEvent();
195
log.display("\nEvent received:\n " + event);
196
197
// handle ClassUnloadEvent
198
if (event instanceof ClassUnloadEvent) {
199
200
ClassUnloadEvent castedEvent = (ClassUnloadEvent)event;
201
log.display("Received event is ClassUnloadEvent:\n " + castedEvent);
202
203
// check that received event is for checked request
204
EventRequest eventRequest = castedEvent.request();
205
if (!(checkedRequest.equals(eventRequest))) {
206
log.complain("FAILURE 1: eventRequest is not equal to checked request");
207
testFailed = true;
208
}
209
210
// check that received event is for checked VM
211
VirtualMachine eventMachine = castedEvent.virtualMachine();
212
if (!(vm.equals(eventMachine))) {
213
log.complain("FAILURE 2: eventVirtualMachine is not equal to checked vm");
214
testFailed = true;
215
}
216
217
// test the method ClassUnloadEvent.className()
218
String refName = castedEvent.className();
219
220
// check that received event is for checked class
221
log.display("ClassUnloadEvent is received for " + refName);
222
if ((refName == null) || (refName.equals(""))) {
223
log.complain("FAILURE 3: ClassUnloadEvent.className() returns null or empty string");
224
testFailed = true;
225
} else if (refName.equals(CHECKED_CLASS)) {
226
227
// mark that ClassUnloadEvent for checked class received
228
eventReceived = true;
229
log.display("Expected ClassUnloadEvent for checked class received!");
230
231
/*
232
// check that checked class is not included in debuggee's list of loaded classes
233
List loadedClasses = vm.classesByName(CHECKED_CLASS);
234
if (loadedClasses != null) {
235
log.complain("FAILURE 4: ClassUnloadEvent is received for class to be unloaded\n"
236
+ " but class still presents in the list of all debuggee classes");
237
testFailed = true;
238
}
239
*/
240
241
} else {
242
243
// ClassUnloadEvent for another class received; just display it
244
List loadedClasses = vm.classesByName(refName);
245
if (loadedClasses != null) {
246
log.display("ClassUnloadEvent was received for loaded class " + refName);
247
}
248
}
249
}
250
251
// ignore all other events
252
}
253
254
log.display("Resuming event set");
255
eventSet.resume();
256
}
257
258
log.display("");
259
260
// check that expected event has been received
261
log.display("Searching checked class in debuggee");
262
rType = debuggee.classByName(CHECKED_CLASS);
263
if (rType != null) {
264
if (eventReceived) {
265
log.complain("FAILURE 4: ClassUnloadEvent is received for class to be unloaded\n"
266
+ " but class still presents in the list of all debuggee classes");
267
testFailed = true;
268
} else {
269
log.display("WARNING: Unable to test ClassUnloadEvent because checked class\n"
270
+ " was not actually unloaded");
271
}
272
} else {
273
if (!eventReceived) {
274
log.complain("FAILURE 6: ClassUnloadEvent was not received for class to be unloaded\n"
275
+ " but class no longe presents in the list of all debuggee classes ");
276
testFailed = true;
277
}
278
}
279
280
} catch (Warning e) {
281
log.display("WARNING: " + e.getMessage());
282
} catch (Failure e) {
283
log.complain("TEST FAILURE: " + e.getMessage());
284
testFailed = true;
285
} catch (Exception e) {
286
log.complain("Unexpected exception: " + e);
287
e.printStackTrace(out);
288
testFailed = true;
289
} finally {
290
291
// disable event request to prevent appearance of further events
292
if (checkedRequest != null) {
293
log.display("Disabling event request");
294
checkedRequest.disable();
295
}
296
297
// force debugee to exit
298
log.display("Sending command: " + COMMAND_QUIT);
299
pipe.println(COMMAND_QUIT);
300
301
log.display("Waiting for debuggee terminating");
302
int debuggeeStatus = debuggee.endDebugee();
303
if (debuggeeStatus == PASSED + JCK_STATUS_BASE) {
304
log.display("Debuggee PASSED with exit code: " + debuggeeStatus);
305
} else {
306
log.complain("Debuggee FAILED with exit code: " + debuggeeStatus);
307
testFailed = true;
308
}
309
}
310
311
// check test results
312
if (testFailed) {
313
log.complain("TEST FAILED");
314
return FAILED;
315
}
316
return PASSED;
317
}
318
319
static class Warning extends Failure {
320
Warning(String msg) {
321
super(msg);
322
}
323
}
324
325
}
326
327