Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassLoaderReference/definedClasses/definedclasses005a.java
41161 views
1
/*
2
* Copyright (c) 2002, 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.ClassLoaderReference.definedClasses;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import java.io.*;
31
32
/**
33
* The debugged applcation of the test.
34
*/
35
public class definedclasses005a {
36
37
//------------------------------------------------------- immutable common fields
38
39
private static int exitStatus;
40
private static ArgumentHandler argHandler;
41
private static Log log;
42
private static IOPipe pipe;
43
44
//------------------------------------------------------- immutable common methods
45
46
static void display(String msg) {
47
log.display("debuggee > " + msg);
48
}
49
50
static void complain(String msg) {
51
log.complain("debuggee FAILURE > " + msg);
52
}
53
54
public static void receiveSignal(String signal) {
55
String line = pipe.readln();
56
57
if ( !line.equals(signal) )
58
throw new Failure("UNEXPECTED debugger's signal " + line);
59
60
display("debuger's <" + signal + "> signal received.");
61
}
62
63
//------------------------------------------------------ mutable common fields
64
65
//------------------------------------------------------ test specific fields
66
67
private final static String prefix = "nsk.jdi.ClassLoaderReference.definedClasses.";
68
private final static String checkedClassName = prefix + "definedclasses005b";
69
static definedclasses005aClassLoader customClassLoader;
70
static Class loadedClass;
71
72
//------------------------------------------------------ mutable common method
73
74
public static void main (String argv[]) throws ClassNotFoundException {
75
76
exitStatus = Consts.TEST_PASSED;
77
argHandler = new ArgumentHandler(argv);
78
log = new Log(System.err, argHandler);
79
pipe = argHandler.createDebugeeIOPipe(log);
80
81
try {
82
String checkedClassDir = (argHandler.getArguments())[0] + File.separator + "loadclass";
83
customClassLoader = new definedclasses005aClassLoader(checkedClassDir);
84
85
loadedClass = customClassLoader.preloadClass(checkedClassName);
86
87
// ensure that class was loaded by custom class loader
88
if (!(loadedClass.getClassLoader() instanceof definedclasses005aClassLoader)) {
89
throw new Failure("Default system loader was used to load class " + checkedClassName);
90
}
91
92
display ("Checked class loaded but not prepared: " + checkedClassName);
93
94
pipe.println(definedclasses005.SIGNAL_READY);
95
96
receiveSignal(definedclasses005.SIGNAL_QUIT);
97
display("completed succesfully.");
98
System.exit(Consts.TEST_PASSED + Consts.JCK_STATUS_BASE);
99
} catch (Failure e) {
100
log.complain(e.getMessage());
101
System.exit(Consts.TEST_FAILED + Consts.JCK_STATUS_BASE);
102
}
103
}
104
105
//--------------------------------------------------------- test specific methods
106
107
}
108
109
//--------------------------------------------------------- test specific classes
110
111
/**
112
* Custom class loader.
113
*/
114
class definedclasses005aClassLoader extends ClassLoader {
115
116
private String classPath;
117
118
public definedclasses005aClassLoader(String classPath) {
119
super(definedclasses005aClassLoader.class.getClassLoader());
120
this.classPath = classPath;
121
}
122
123
public Class preloadClass (String className) throws ClassNotFoundException {
124
return findClass(className);
125
}
126
127
protected synchronized Class findClass(String name) throws ClassNotFoundException {
128
String classFileName = classPath + "/" + name.replace('.', '/') + ".class";
129
130
FileInputStream in;
131
try {
132
in = new FileInputStream(classFileName);
133
if (in == null) {
134
throw new ClassNotFoundException(classFileName);
135
}
136
} catch (FileNotFoundException e) {
137
throw new ClassNotFoundException(classFileName, e);
138
}
139
140
int len;
141
byte data[];
142
try {
143
len = in.available();
144
data = new byte[len];
145
for (int total = 0; total < data.length; ) {
146
total += in.read(data, total, data.length - total);
147
}
148
} catch (IOException e) {
149
throw new ClassNotFoundException(classFileName, e);
150
} finally {
151
try {
152
in.close();
153
} catch (IOException e) {
154
throw new ClassNotFoundException(classFileName, e);
155
}
156
}
157
158
return defineClass(name, data, 0, data.length);
159
}
160
}
161
162