Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.base/share/classes/java/lang/VMAccess.java
12513 views
1
/*[INCLUDE-IF Sidecar16]*/
2
/*******************************************************************************
3
* Copyright (c) 2012, 2021 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
22
*******************************************************************************/
23
24
package java.lang;
25
26
import java.util.Objects;
27
import java.util.Properties;
28
29
/*[IF Sidecar19-SE]*/
30
import jdk.internal.reflect.ConstantPool;
31
/*[ELSE]*/
32
import sun.reflect.ConstantPool;
33
/*[ENDIF]*/
34
35
36
import com.ibm.oti.vm.*;
37
import com.ibm.jit.JITHelpers;
38
39
/**
40
* Helper class to allow privileged access to classes
41
* from outside the java.lang package. Based on sun.misc.SharedSecrets
42
* implementation.
43
*/
44
final class VMAccess implements VMLangAccess {
45
46
private static ClassLoader extClassLoader;
47
48
/**
49
* Native used to find and load a class using the VM
50
*
51
* @return java.lang.Class
52
* the class or null.
53
* @param className String
54
* the name of the class to search for.
55
* @param classLoader
56
* the classloader to do the work
57
*/
58
static native Class<?> findClassOrNull(String className, ClassLoader classLoader);
59
60
@Override
61
public Class<?> findClassOrNullHelper(String className, ClassLoader classLoader) {
62
return VMAccess.findClassOrNull(className, classLoader);
63
}
64
65
66
/*[IF Sidecar19-SE]*/
67
/**
68
* Answer the platform class loader.
69
*/
70
@Override
71
public ClassLoader getPlatformClassLoader() {
72
return jdk.internal.loader.ClassLoaders.platformClassLoader();
73
}
74
/*[ENDIF] Sidecar19-SE*/
75
76
/**
77
* Set the extension class loader. It can only be set once.
78
*
79
* @param loader the extension class loader
80
*/
81
static void setExtClassLoader(ClassLoader loader) {
82
extClassLoader = loader;
83
}
84
85
/**
86
* Answer the extension class loader.
87
*/
88
@Override
89
public ClassLoader getExtClassLoader() {
90
return extClassLoader;
91
}
92
93
/**
94
* Returns true if parent is the ancestor of child.
95
* Parent and child must not be null.
96
*/
97
/*[PR CMVC 191554] Provide access to ClassLoader methods to improve performance */
98
@Override
99
public boolean isAncestor(java.lang.ClassLoader parent, java.lang.ClassLoader child) {
100
return parent.isAncestorOf(child);
101
}
102
103
/**
104
* Returns the ClassLoader off clazz.
105
*/
106
/*[PR CMVC 191554] Provide access to ClassLoader methods to improve performance */
107
@Override
108
public java.lang.ClassLoader getClassloader(java.lang.Class clazz) {
109
return clazz.getClassLoaderImpl();
110
}
111
112
/**
113
* Returns the package name for a given class.
114
* clazz must not be null.
115
*/
116
/*[PR CMVC 191554] Provide access to ClassLoader methods to improve performance */
117
@Override
118
public java.lang.String getPackageName(java.lang.Class clazz) {
119
return clazz.getPackageName();
120
}
121
122
/**
123
* Returns a MethodHandle cache for a given class.
124
*/
125
@Override
126
public java.lang.Object getMethodHandleCache(java.lang.Class<?> clazz) {
127
return clazz.getMethodHandleCache();
128
}
129
130
/**
131
* Set a MethodHandle cache to a given class.
132
*/
133
@Override
134
public java.lang.Object setMethodHandleCache(java.lang.Class<?> clazz, java.lang.Object object) {
135
return clazz.setMethodHandleCache(object);
136
}
137
138
/**
139
* Returns a {@code java.util.Map} from method descriptor string to the equivalent {@code MethodType} as generated by {@code MethodType.fromMethodDescriptorString}.
140
* @param loader The {@code ClassLoader} used to get the MethodType.
141
* @return A {@code java.util.Map} from method descriptor string to the equivalent {@code MethodType}.
142
*/
143
@Override
144
public java.util.Map<String, java.lang.invoke.MethodType> getMethodTypeCache(ClassLoader loader) {
145
return loader != null ? loader.getMethodTypeCache() : null;
146
}
147
148
/**
149
* Provide internal access to the system properties without going through SecurityManager
150
*
151
* Important notes:
152
* 1. This API must NOT be exposed to application code directly or indirectly;
153
* 2. This method can only be used to retrieve system properties for internal usage,
154
* i.e., there is no security exception expected;
155
* 3. If there is an application caller in the call stack, AND the application caller(s)
156
* have to be check for permission to retrieve the system properties specified,
157
* then this API should NOT be used even though the immediate caller is in boot strap path.
158
*
159
* @return the system properties
160
*/
161
@Override
162
public Properties internalGetProperties() {
163
return System.internalGetProperties();
164
}
165
166
167
/*[IF !Sidecar19-SE]*/
168
/**
169
* Returns the system packages for the bootloader
170
* @return An array of packages defined by the bootloader
171
*/
172
@Override
173
public Package[] getSystemPackages() {
174
return Package.getSystemPackages();
175
}
176
177
/**
178
* Returns the system package for the 'name'
179
* @param name must not be null
180
* @return The package
181
*/
182
@Override
183
public Package getSystemPackage(String name) {
184
return Package.getSystemPackage(name);
185
}
186
/*[ENDIF]*/
187
188
/**
189
* Returns an InternalConstantPool object.
190
*
191
* @param addr - the native addr of the J9ConstantPool
192
* @return An InternalConstantPool reference object
193
*/
194
@Override
195
public Object createInternalConstantPool(long addr) {
196
return new InternalConstantPool(addr);
197
}
198
199
/**
200
* Returns a ConstantPool object
201
* @param internalConstantPool An object ref to a j9constantpool
202
* @return ConstantPool instance
203
*/
204
@Override
205
public ConstantPool getConstantPool(Object internalConstantPool) {
206
return Access.getConstantPool(internalConstantPool);
207
}
208
209
/**
210
* Returns an InternalConstantPool object from a J9Class address. The ConstantPool
211
* natives expect an InternalConstantPool as the constantPoolOop parameter.
212
*
213
* @param j9class the native address of the J9Class
214
* @return InternalConstantPool a wrapper for a j9constantpool
215
*/
216
public Object getInternalConstantPoolFromJ9Class(long j9class) {
217
long j9constantpool = VM.getJ9ConstantPoolFromJ9Class(j9class);
218
return createInternalConstantPool(j9constantpool);
219
}
220
221
/**
222
* Returns an InternalConstantPool object from a Class. The ConstantPool
223
* natives expect an InternalConstantPool as the constantPoolOop parameter.
224
*
225
* @param clazz the Class to fetch the constant pool from
226
* @return an InternalConstantPool wrapper for a j9constantpool
227
*/
228
public Object getInternalConstantPoolFromClass(Class clazz) {
229
JITHelpers helpers = JITHelpers.getHelpers();
230
long j9class;
231
if (helpers.is32Bit()) {
232
j9class = helpers.getJ9ClassFromClass32(clazz);
233
} else {
234
j9class = helpers.getJ9ClassFromClass64(clazz);
235
}
236
return getInternalConstantPoolFromJ9Class(j9class);
237
}
238
239
/*[IF Sidecar19-SE]*/
240
@Override
241
public void addPackageToList(java.lang.Class<?> newClass, ClassLoader loader) {
242
java.lang.ClassLoader packageLoader = loader;
243
if (Objects.isNull(packageLoader)) {
244
packageLoader = ClassLoader.getSystemClassLoader();
245
}
246
packageLoader.addPackageToList(newClass);
247
}
248
/*[ENDIF] Sidecar19-SE */
249
250
@Override
251
public Thread createThread(Runnable runnable, String threadName, boolean isSystemThreadGroup, boolean inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader) {
252
return new Thread(runnable, threadName, isSystemThreadGroup, inheritThreadLocals, isDaemon, contextClassLoader);
253
}
254
255
@Override
256
public void prepare(Class<?> theClass) {
257
J9VMInternals.prepare(theClass);
258
}
259
260
/*[IF JAVA_SPEC_VERSION >= 11]*/
261
/**
262
* Returns whether the classloader name should be included in the stack trace for the provided StackTraceElement.
263
*
264
* @param element The StackTraceElement to check
265
* @return true if the classloader name should be included, false otherwise
266
*/
267
@Override
268
public boolean getIncludeClassLoaderName(StackTraceElement element) {
269
return element.getIncludeClassLoaderName();
270
}
271
272
/**
273
* Returns whether the module version should be included in the stack trace for the provided StackTraceElement.
274
*
275
* @param element The StackTraceElement to check
276
* @return true if the module version should be included, false otherwise
277
*/
278
@Override
279
public boolean getIncludeModuleVersion(StackTraceElement element) {
280
return element.getIncludeModuleVersion();
281
}
282
/*[ENDIF] JAVA_SPEC_VERSION >= 11*/
283
}
284
285