Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/annparser.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 1998, 2018 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 "jcl_internal.h"
27
28
#include "vmaccess.h"
29
30
typedef enum METHOD_OBJECT_TYPE {
31
OBJECT_TYPE_METHOD,
32
OBJECT_TYPE_CONSTRUCTOR,
33
OBJECT_TYPE_UNKNOWN
34
} METHOD_OBJECT_TYPE;
35
36
jobject JNICALL
37
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Field_2(JNIEnv *env, jclass unusedClass, jobject jlrField)
38
{
39
jobject result = NULL;
40
j9object_t fieldObject = NULL;
41
J9VMThread *vmThread = (J9VMThread *) env;
42
43
enterVMFromJNI(vmThread);
44
fieldObject = J9_JNI_UNWRAP_REFERENCE(jlrField);
45
if (NULL != fieldObject) {
46
J9JNIFieldID *fieldID = vmThread->javaVM->reflectFunctions.idFromFieldObject(vmThread, NULL, fieldObject);
47
48
j9object_t annotationsData = getFieldAnnotationData(vmThread, fieldID->declaringClass, fieldID);
49
if (NULL != annotationsData) {
50
result = vmThread->javaVM->internalVMFunctions->j9jni_createLocalRef(env, annotationsData);
51
}
52
}
53
exitVMToJNI(vmThread);
54
return result;
55
}
56
57
jobject JNICALL
58
Java_com_ibm_oti_reflect_TypeAnnotationParser_getTypeAnnotationsDataImpl__Ljava_lang_reflect_Field_2(JNIEnv *env, jclass unusedClass, jobject jlrField)
59
{
60
return getFieldTypeAnnotationsAsByteArray(env, jlrField);
61
}
62
63
static jobject
64
getExecutableAnnotationDataHelper(JNIEnv *env, jobject jlrMethod, METHOD_OBJECT_TYPE objType,
65
j9object_t (*getAnnotationData)(struct J9VMThread *vmThread, struct J9Class *declaringClass, J9Method *ramMethod))
66
{
67
jobject result = NULL;
68
j9object_t methodObject = NULL;
69
J9VMThread *vmThread = (J9VMThread *) env;
70
71
enterVMFromJNI(vmThread);
72
methodObject = J9_JNI_UNWRAP_REFERENCE(jlrMethod);
73
if (NULL != methodObject) {
74
J9JNIMethodID *methodID = NULL;
75
J9Method *ramMethod = NULL;
76
J9Class *declaringClass = NULL;
77
j9object_t annotationsData = NULL;
78
79
if ((OBJECT_TYPE_UNKNOWN == objType)) {
80
objType = (J9OBJECT_CLAZZ(vmThread, methodObject) == J9VMJAVALANGREFLECTCONSTRUCTOR_OR_NULL(vmThread->javaVM)) ? OBJECT_TYPE_CONSTRUCTOR: OBJECT_TYPE_METHOD;
81
}
82
if (OBJECT_TYPE_CONSTRUCTOR == objType) {
83
methodID = vmThread->javaVM->reflectFunctions.idFromConstructorObject(vmThread, methodObject);
84
} else {
85
methodID = vmThread->javaVM->reflectFunctions.idFromMethodObject(vmThread, methodObject);
86
}
87
88
ramMethod = methodID->method;
89
declaringClass = J9_CURRENT_CLASS(J9_CLASS_FROM_METHOD(ramMethod));
90
91
annotationsData = getAnnotationData(vmThread, declaringClass, ramMethod);
92
if (NULL != annotationsData) {
93
result = vmThread->javaVM->internalVMFunctions->j9jni_createLocalRef(env, annotationsData);
94
}
95
}
96
exitVMToJNI(vmThread);
97
return result;
98
}
99
100
jbyteArray getMethodTypeAnnotationsAsByteArray(JNIEnv *env, jobject jlrMethod) {
101
return getExecutableAnnotationDataHelper(env, jlrMethod, OBJECT_TYPE_UNKNOWN, getMethodTypeAnnotationData);
102
}
103
104
jobject JNICALL
105
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Constructor_2(JNIEnv *env, jclass unusedClass, jobject jlrConstructor)
106
{
107
return getExecutableAnnotationDataHelper(env, jlrConstructor, OBJECT_TYPE_CONSTRUCTOR, getMethodAnnotationData);
108
}
109
110
jobject JNICALL
111
Java_com_ibm_oti_reflect_TypeAnnotationParser_getTypeAnnotationsDataImpl__Ljava_lang_reflect_Constructor_2(JNIEnv *env, jclass unusedClass, jobject jlrConstructor)
112
{
113
return getExecutableAnnotationDataHelper(env, jlrConstructor, OBJECT_TYPE_CONSTRUCTOR, getMethodTypeAnnotationData);
114
}
115
116
jobject JNICALL
117
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Method_2(JNIEnv *env, jclass unusedClass, jobject jlrMethod)
118
{
119
return getExecutableAnnotationDataHelper(env, jlrMethod, OBJECT_TYPE_METHOD, getMethodAnnotationData);
120
}
121
122
jobject JNICALL
123
Java_com_ibm_oti_reflect_TypeAnnotationParser_getTypeAnnotationsDataImpl__Ljava_lang_reflect_Method_2(JNIEnv *env, jclass unusedClass, jobject jlrMethod)
124
{
125
return getExecutableAnnotationDataHelper(env, jlrMethod, OBJECT_TYPE_UNKNOWN, getMethodTypeAnnotationData);
126
}
127
128
jobject JNICALL
129
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsDataImpl__Ljava_lang_Class_2(JNIEnv *env, jclass unusedClass, jclass jlClass)
130
{
131
return Java_java_lang_Class_getDeclaredAnnotationsData(env, jlClass);
132
}
133
134
jobject JNICALL
135
Java_com_ibm_oti_reflect_TypeAnnotationParser_getTypeAnnotationsDataImpl__Ljava_lang_Class_2(JNIEnv *env, jclass unusedClass, jclass jlClass)
136
{
137
return getClassTypeAnnotationsAsByteArray(env, jlClass);
138
}
139
140
jobject JNICALL
141
Java_com_ibm_oti_reflect_AnnotationParser_getParameterAnnotationsData__Ljava_lang_reflect_Constructor_2(JNIEnv *env, jclass unusedClass, jobject jlrConstructor)
142
{
143
return getExecutableAnnotationDataHelper(env, jlrConstructor, OBJECT_TYPE_CONSTRUCTOR, getMethodParametersAnnotationData);
144
}
145
146
jobject JNICALL
147
Java_com_ibm_oti_reflect_AnnotationParser_getParameterAnnotationsData__Ljava_lang_reflect_Method_2(JNIEnv *env, jclass unusedClass, jobject jlrMethod)
148
{
149
return getExecutableAnnotationDataHelper(env, jlrMethod, OBJECT_TYPE_METHOD, getMethodParametersAnnotationData);
150
}
151
152
jobject JNICALL
153
Java_com_ibm_oti_reflect_AnnotationParser_getDefaultValueData(JNIEnv *env, jclass unusedClass, jobject jlrMethod)
154
{
155
return getExecutableAnnotationDataHelper(env, jlrMethod, OBJECT_TYPE_METHOD, getMethodDefaultAnnotationData);
156
}
157
158
jobject JNICALL
159
Java_com_ibm_oti_reflect_AnnotationParser_getConstantPool(JNIEnv *env, jclass unusedClass, jobject classToIntrospect)
160
{
161
return Java_java_lang_Access_getConstantPool(env, unusedClass, classToIntrospect);
162
}
163
164