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