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/signature001a.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 java.io.*;
27
import nsk.share.*;
28
import nsk.share.jpda.*;
29
import nsk.share.jdi.*;
30
31
import java.lang.reflect.Method;
32
33
// This class is the debugged application in the test
34
35
// NOTE: Test does not check array class because of difficulty of
36
// providing reliable technique for unloading such class.
37
// So all these testcases are commented in the test.
38
39
class signature001a {
40
static final int PASSED = 0;
41
static final int FAILED = 2;
42
static final int JCK_STATUS_BASE = 95;
43
44
static final String PREFIX = "nsk.jdi.ClassUnloadEvent.classSignature";
45
static final String CHECKED_CLASS = PREFIX + ".signature001c";
46
static final String CHECKED_INTFACE = PREFIX + ".signature001b";
47
static final String CHECKED_ARRAY = PREFIX + ".signature001c[]";
48
49
public static void main(String args[]) {
50
signature001a _signature001a = new signature001a();
51
System.exit(JCK_STATUS_BASE + _signature001a.run(args));
52
}
53
54
int run (String args[]) {
55
ArgumentHandler argHandler = new ArgumentHandler(args);
56
IOPipe pipe = argHandler.createDebugeeIOPipe();
57
58
// define directory to load class files
59
String loadClassDir = (argHandler.getArguments())[0] + File.separator + "loadclass";
60
61
// notify debugger that debugee is ready
62
pipe.println(signature001.COMMAND_READY);
63
64
// wait for a command to load checked class
65
String command = pipe.readln();
66
if (!command.equals(signature001.COMMAND_LOAD)) {
67
System.err.println("TEST BUG: unexpected command: " + command);
68
return FAILED;
69
}
70
71
// load checked class for further unloading
72
ClassUnloader checkedClassUnloader = new ClassUnloader();
73
try {
74
checkedClassUnloader.loadClass(CHECKED_CLASS, loadClassDir);
75
} catch (Exception ex) {
76
System.err.println("Unexpected exception while loading " + CHECKED_CLASS + ":");
77
System.err.println(ex);
78
return FAILED;
79
}
80
81
// load checked interface for further unloading
82
ClassUnloader checkedInterfaceUnloader = new ClassUnloader();
83
try {
84
checkedInterfaceUnloader.loadClass(CHECKED_INTFACE, loadClassDir);
85
} catch (Exception ex) {
86
System.err.println("Unexpected exception while loading " + CHECKED_INTFACE + ":");
87
System.err.println(ex);
88
return FAILED;
89
}
90
91
/*
92
// to load array type
93
Object object1;
94
try {
95
object1 = class1.newInstance();
96
} catch (Throwable e) {
97
System.err.println("Cannot create instance of " + CHECKED_CLASS);
98
System.err.println("Exception/error: " + e.getMessage());
99
return FAILED;
100
}
101
Method method1;
102
try {
103
method1 = class1.getMethod("initArray", null);
104
method1.invoke(object1, null);
105
System.out.println("method initArray is invoked");
106
} catch (Exception e) {
107
System.out.println(e.getMessage());
108
}
109
try {
110
if (!(Class.forName(CHECKED_ARRAY).getClassLoader() instanceof KlassLoader)) {
111
System.err.println("TEST BUG: Incorrect loader of type" + CHECKED_ARRAY);
112
return FAILED;
113
}
114
} catch (Exception e) {
115
System.out.println(e.getMessage());
116
}
117
*/
118
119
// notify debugger that checked class is loaded
120
pipe.println(signature001.COMMAND_LOADED);
121
122
// turn off pipe pinging
123
pipe.setPingTimeout(0);
124
125
// wait for a command to unload checked class
126
command = pipe.readln();
127
if (!command.equals(signature001.COMMAND_UNLOAD)) {
128
System.err.println("TEST BUG: unexpected command: " + command);
129
return FAILED;
130
}
131
132
// try to unload checked class
133
boolean classes_unloaded = checkedClassUnloader.unloadClass()
134
&& checkedInterfaceUnloader.unloadClass();
135
136
if (!classes_unloaded) {
137
pipe.println(signature001.COMMAND_LOADED);
138
} else {
139
pipe.println(signature001.COMMAND_UNLOADED);
140
}
141
142
// wait for a command to exit
143
pipe.println(signature001.COMMAND_UNLOAD);
144
145
command = pipe.readln();
146
if (!command.equals(signature001.COMMAND_QUIT)) {
147
System.err.println("TEST BUG: unknown command: " + command);
148
return FAILED;
149
}
150
return PASSED;
151
}
152
}
153
154