Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassLoaderReference/visibleClasses/visibleclasses001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2020, 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.ClassLoaderReference.visibleClasses;
25
26
import nsk.share.*;
27
import nsk.share.jdi.*;
28
29
import com.sun.jdi.*;
30
import com.sun.jdi.event.*;
31
import com.sun.jdi.request.*;
32
33
import java.util.*;
34
import java.io.*;
35
36
/**
37
* The test for the implementation of an object of the type <BR>
38
* ClassLoader. <BR>
39
* <BR>
40
* The test checks up that results of the method <BR>
41
* <code>com.sun.jdi.ClassLoader.visibleClasses()</code> <BR>
42
* complies with its spec. <BR>
43
* <BR>
44
* The test checks up on the following assertion: <BR>
45
* Returns a list of all classes for which this class loader <BR>
46
* has been recorded as the initiating loader in the target VM.<BR>
47
* The list contains ReferenceTypes defined directly by <BR>
48
* this loader (as returned by definedClasses()) and <BR>
49
* any types for which loading was delegated by <BR>
50
* this class loader to another class loader. <BR>
51
* <BR>
52
* The case to check includes a class loader with no <BR>
53
* delegated types, that is, the expected returned value should <BR>
54
* be equal to one returned by ClassLoader.definedClasses(), <BR>
55
* except primitive arrays defined by bootstrap class loader <BR>
56
* and visible. <BR>
57
* <BR>
58
* The test has three phases and works as follows. <BR>
59
* <BR>
60
* In first phase, <BR>
61
* upon launching debuggee's VM which will be suspended, <BR>
62
* a debugger waits for the VMStartEvent within a predefined <BR>
63
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
64
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
65
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
66
* and waits for the event within the predefined time interval. <BR>
67
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
68
* Upon getting the ClassPrepareEvent, <BR>
69
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
70
* within debuggee's special methodForCommunication(). <BR>
71
* <BR>
72
* In second phase to check the assetion, <BR>
73
* the debugger and the debuggee perform the following. <BR>
74
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
75
* - The debuggee prepares a ClassLoader object and invokes <BR>
76
* the methodForCommunication to be suspended and <BR>
77
* to inform the debugger with the event. <BR>
78
* - Upon getting the BreakpointEvent, <BR>
79
* the debugger performs the check. <BR>
80
* Note. To inform each other of needed actions, the debugger and <BR>
81
* and the debuggee use debuggeee's variable "instruction". <BR>
82
* <BR>
83
* In third phase when at the end, <BR>
84
* the debuggee changes the value of the "instruction" <BR>
85
* to inform the debugger of checks finished, and both end. <BR>
86
* <BR>
87
*/
88
89
public class visibleclasses001 extends JDIBase {
90
91
public static void main (String argv[]) {
92
93
int result = run(argv, System.out);
94
95
System.exit(result + PASS_BASE);
96
}
97
98
public static int run (String argv[], PrintStream out) {
99
100
int exitCode = new visibleclasses001().runThis(argv, out);
101
102
if (exitCode != PASSED) {
103
System.out.println("TEST FAILED");
104
}
105
return testExitCode;
106
}
107
108
// ************************************************ test parameters
109
110
private String debuggeeName =
111
"nsk.jdi.ClassLoaderReference.visibleClasses.visibleclasses001a";
112
113
//====================================================== test program
114
115
static List<String> primitiveArraysNamesPatterns = Arrays.asList(new String[] {
116
"^boolean(\\[\\])+", "^byte(\\[\\])+", "^char(\\[\\])+", "^int(\\[\\])+",
117
"^short(\\[\\])+", "^long(\\[\\])+", "^float(\\[\\])+", "^double(\\[\\])+"});
118
119
private int runThis (String argv[], PrintStream out) {
120
121
argsHandler = new ArgumentHandler(argv);
122
logHandler = new Log(out, argsHandler);
123
Binder binder = new Binder(argsHandler, logHandler);
124
125
waitTime = argsHandler.getWaitTime() * 60000;
126
127
try {
128
log2("launching a debuggee :");
129
log2(" " + debuggeeName);
130
if (argsHandler.verbose()) {
131
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
132
} else {
133
debuggee = binder.bindToDebugee(debuggeeName);
134
}
135
if (debuggee == null) {
136
log3("ERROR: no debuggee launched");
137
return FAILED;
138
}
139
log2("debuggee launched");
140
} catch ( Exception e ) {
141
log3("ERROR: Exception : " + e);
142
log2(" test cancelled");
143
return FAILED;
144
}
145
146
debuggee.redirectOutput(logHandler);
147
148
vm = debuggee.VM();
149
150
eventQueue = vm.eventQueue();
151
if (eventQueue == null) {
152
log3("ERROR: eventQueue == null : TEST ABORTED");
153
vm.exit(PASS_BASE);
154
return FAILED;
155
}
156
157
log2("invocation of the method runTest()");
158
switch (runTest()) {
159
160
case 0 : log2("test phase has finished normally");
161
log2(" waiting for the debuggee to finish ...");
162
debuggee.waitFor();
163
164
log2("......getting the debuggee's exit status");
165
int status = debuggee.getStatus();
166
if (status != PASS_BASE) {
167
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
168
status + " != PASS_BASE");
169
testExitCode = FAILED;
170
} else {
171
log2("......debuggee returned expected exit status: " +
172
status + " == PASS_BASE");
173
}
174
break;
175
176
default : log3("ERROR: runTest() returned unexpected value");
177
178
case 1 : log3("test phase has not finished normally: debuggee is still alive");
179
log2("......forcing: vm.exit();");
180
testExitCode = FAILED;
181
try {
182
vm.exit(PASS_BASE);
183
} catch ( Exception e ) {
184
log3("ERROR: Exception : e");
185
}
186
break;
187
188
case 2 : log3("test cancelled due to VMDisconnectedException");
189
log2("......trying: vm.process().destroy();");
190
testExitCode = FAILED;
191
try {
192
Process vmProcess = vm.process();
193
if (vmProcess != null) {
194
vmProcess.destroy();
195
}
196
} catch ( Exception e ) {
197
log3("ERROR: Exception : e");
198
}
199
break;
200
}
201
202
return testExitCode;
203
}
204
205
206
/*
207
* Return value: 0 - normal end of the test
208
* 1 - ubnormal end of the test
209
* 2 - VMDisconnectedException while test phase
210
*/
211
212
private int runTest() {
213
214
try {
215
testRun();
216
217
log2("waiting for VMDeathEvent");
218
getEventSet();
219
if (eventIterator.nextEvent() instanceof VMDeathEvent)
220
return 0;
221
222
log3("ERROR: last event is not the VMDeathEvent");
223
return 1;
224
} catch ( VMDisconnectedException e ) {
225
log3("ERROR: VMDisconnectedException : " + e);
226
return 2;
227
} catch ( Exception e ) {
228
log3("ERROR: Exception : " + e);
229
return 1;
230
}
231
232
}
233
234
private void testRun()
235
throws JDITestRuntimeException, Exception {
236
237
eventRManager = vm.eventRequestManager();
238
239
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
240
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
241
cpRequest.addClassFilter(debuggeeName);
242
243
cpRequest.enable();
244
vm.resume();
245
getEventSet();
246
cpRequest.disable();
247
248
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
249
debuggeeClass = event.referenceType();
250
251
if (!debuggeeClass.name().equals(debuggeeName))
252
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
253
254
log2(" received: ClassPrepareEvent for debuggeeClass");
255
256
String bPointMethod = "methodForCommunication";
257
String lineForComm = "lineForComm";
258
BreakpointRequest bpRequest;
259
260
bpRequest = settingBreakpoint(debuggee.threadByNameOrThrow("main"),
261
debuggeeClass,
262
bPointMethod, lineForComm, "zero");
263
bpRequest.enable();
264
265
//------------------------------------------------------ testing section
266
267
log1(" TESTING BEGINS");
268
269
for (int i = 0; ; i++) {
270
271
vm.resume();
272
breakpointForCommunication();
273
274
int instruction = ((IntegerValue)
275
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
276
277
if (instruction == 0) {
278
vm.resume();
279
break;
280
}
281
282
log1(":::::: case: # 0");
283
284
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
285
286
log2("......getting: List classes = vm.allClasses();");
287
List<ReferenceType> classes = vm.allClasses();
288
log2(" classes.size() == " + classes.size());
289
290
vm.resume();
291
breakpointForCommunication();
292
293
log1(":::::: case: # 1");
294
295
String ClassLoaderObjName = "classLoader";
296
297
log2("......getting: Value val = debuggeeClass.getValue(debuggeeClass.fieldByName(ClassLoaderObjName));");
298
Value val = debuggeeClass.getValue(debuggeeClass.fieldByName(ClassLoaderObjName));
299
300
log2("......getting: ClassLoaderReference clRef = (ClassLoaderReference) val;");
301
ClassLoaderReference clRef = (ClassLoaderReference) val;
302
303
log2("......getting: List definedClasses = clRef.definedClasses();");
304
List<ReferenceType> definedClasses = clRef.definedClasses();
305
306
log2("......getting: List visibleClasses = clRef.visibleClasses();");
307
List<ReferenceType> visibleClasses = clRef.visibleClasses();
308
309
log2("......checking up on: visibleClasses.size() == definedClasses.size()");
310
311
if (visibleClasses.size() != definedClasses.size()) {
312
log2(" : visibleClasses.size() != definedClasses.size()");
313
log2(" : definedClasses.size() == " + definedClasses.size());
314
log2(" : visibleClasses.size() == " + visibleClasses.size());
315
316
for (ReferenceType vcl : visibleClasses) {
317
318
int vclIndex = visibleClasses.indexOf(vcl);
319
String vclName = vcl.name();
320
321
if (primitiveArraysNamesPatterns.stream().anyMatch(vcl.name()::matches)) {
322
log2(" : visibleClasses[" + vclIndex + "].name() == " + vclName +
323
" Correct - primitive arrays are visible for class loader");
324
} else {
325
log3(" : visibleClasses[" + vclIndex + "].name() == " + vclName);
326
327
classes.stream().filter(cl -> cl.name().equals(vclName))
328
.forEach(cl -> log3(" : List classes contains an object with the name: " + cl.name()));
329
330
testExitCode = FAILED;
331
}
332
}
333
}
334
335
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336
}
337
log1(" TESTING ENDS");
338
return;
339
}
340
341
}
342
343