Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/java_lang_Access.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 1998, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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
21
*******************************************************************************/
22
23
#include "jni.h"
24
#include "jcl.h"
25
#include "jclprots.h"
26
#include "jclglob.h"
27
#include "jniidcacheinit.h"
28
29
/**
30
* Return the constant pool for a class.
31
* Note: This method is also called from annparser.c:Java_com_ibm_oti_reflect_AnnotationParser_getConstantPool.
32
*
33
* @param env The current thread.
34
* @param unusedClass See note above - this parameter should not be used.
35
* @param classToIntrospect The Class or InternalConstantPool instance the ConstantPool should represent.
36
*
37
* @return a ConstantPool object reference or NULL on error.
38
*/
39
jobject JNICALL
40
Java_java_lang_Access_getConstantPool(JNIEnv *env, jclass unusedClass, jobject classToIntrospect)
41
{
42
jclass sun_reflect_ConstantPool = JCL_CACHE_GET(env,CLS_sun_reflect_ConstantPool);
43
jfieldID constantPoolOop;
44
jobject constantPool;
45
J9VMThread *vmThread = (J9VMThread *)env;
46
J9InternalVMFunctions *vmFunctions = vmThread->javaVM->internalVMFunctions;
47
J9MemoryManagerFunctions *gcFunctions = vmThread->javaVM->memoryManagerFunctions;
48
j9object_t classObject = NULL;
49
50
/* lazy-initialize the cached field IDs */
51
if (NULL == sun_reflect_ConstantPool) {
52
if (!initializeSunReflectConstantPoolIDCache(env)) {
53
return NULL;
54
}
55
sun_reflect_ConstantPool = JCL_CACHE_GET(env, CLS_sun_reflect_ConstantPool);
56
}
57
58
/* allocate the new ConstantPool object */
59
constantPool = (*env)->AllocObject(env, sun_reflect_ConstantPool);
60
if (NULL == constantPool) {
61
return NULL;
62
}
63
64
/* if this method is called with java/lang/Class, allocate an InternalConstantPool and store the J9ConstantPool */
65
vmFunctions->internalEnterVMFromJNI(vmThread);
66
classObject = J9_JNI_UNWRAP_REFERENCE(classToIntrospect);
67
if (J9VMJAVALANGCLASS_OR_NULL(vmThread->javaVM) == J9OBJECT_CLAZZ(vmThread, classObject)) {
68
J9Class *clazz = J9VM_J9CLASS_FROM_HEAPCLASS(vmThread, classObject);
69
J9ConstantPool *constantPool = (J9ConstantPool *)clazz->ramConstantPool;
70
J9Class *internalConstantPool = J9VMJAVALANGINTERNALCONSTANTPOOL_OR_NULL(vmThread->javaVM);
71
Assert_JCL_notNull(internalConstantPool);
72
j9object_t internalConstantPoolObject = gcFunctions->J9AllocateObject(vmThread, internalConstantPool, J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
73
if (NULL == internalConstantPoolObject) {
74
vmFunctions->setHeapOutOfMemoryError(vmThread);
75
vmFunctions->internalExitVMToJNI(vmThread);
76
return NULL;
77
}
78
J9VMJAVALANGINTERNALCONSTANTPOOL_SET_VMREF(vmThread, internalConstantPoolObject, constantPool);
79
classToIntrospect = vmFunctions->j9jni_createLocalRef(env, internalConstantPoolObject);
80
}
81
vmFunctions->internalExitVMToJNI(vmThread);
82
83
/* and set the private constantPoolOop member */
84
constantPoolOop = JCL_CACHE_GET(env, FID_sun_reflect_ConstantPool_constantPoolOop);
85
(*env)->SetObjectField(env, constantPool, constantPoolOop, classToIntrospect);
86
87
return constantPool;
88
}
89
90