author | chegar |
Thu, 17 Oct 2019 20:53:35 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58678 | 9cf78a70fa4f |
parent 53212 | bccff579c2ff |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53212
bccff579c2ff
8216302: StackTraceElement::fill_in can use cached Class.name
shade
parents:
50735
diff
changeset
|
2 |
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/*- |
|
27 |
* Implementation of class Class |
|
28 |
* |
|
29 |
* former threadruntime.c, Sun Sep 22 12:09:39 1991 |
|
30 |
*/ |
|
31 |
||
32 |
#include <string.h> |
|
33 |
#include <stdlib.h> |
|
34 |
||
35 |
#include "jni.h" |
|
36 |
#include "jni_util.h" |
|
37 |
#include "jvm.h" |
|
58678 | 38 |
#include "check_classname.h" |
2 | 39 |
#include "java_lang_Class.h" |
40 |
||
41 |
#define OBJ "Ljava/lang/Object;" |
|
42 |
#define CLS "Ljava/lang/Class;" |
|
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
30341
diff
changeset
|
43 |
#define CPL "Ljdk/internal/reflect/ConstantPool;" |
2 | 44 |
#define STR "Ljava/lang/String;" |
45 |
#define FLD "Ljava/lang/reflect/Field;" |
|
46 |
#define MHD "Ljava/lang/reflect/Method;" |
|
47 |
#define CTR "Ljava/lang/reflect/Constructor;" |
|
48 |
#define PD "Ljava/security/ProtectionDomain;" |
|
49 |
#define BA "[B" |
|
50 |
||
51 |
static JNINativeMethod methods[] = { |
|
53212
bccff579c2ff
8216302: StackTraceElement::fill_in can use cached Class.name
shade
parents:
50735
diff
changeset
|
52 |
{"initClassName", "()" STR, (void *)&JVM_InitClassName}, |
2 | 53 |
{"getSuperclass", "()" CLS, NULL}, |
18179
9b6ad451b521
8016236: Class.getGenericInterfaces performance improvement
shade
parents:
18139
diff
changeset
|
54 |
{"getInterfaces0", "()[" CLS, (void *)&JVM_GetClassInterfaces}, |
2 | 55 |
{"isInterface", "()Z", (void *)&JVM_IsInterface}, |
56 |
{"getSigners", "()[" OBJ, (void *)&JVM_GetClassSigners}, |
|
57 |
{"setSigners", "([" OBJ ")V", (void *)&JVM_SetClassSigners}, |
|
58 |
{"isArray", "()Z", (void *)&JVM_IsArrayClass}, |
|
59 |
{"isPrimitive", "()Z", (void *)&JVM_IsPrimitiveClass}, |
|
60 |
{"getModifiers", "()I", (void *)&JVM_GetClassModifiers}, |
|
61 |
{"getDeclaredFields0","(Z)[" FLD, (void *)&JVM_GetClassDeclaredFields}, |
|
62 |
{"getDeclaredMethods0","(Z)[" MHD, (void *)&JVM_GetClassDeclaredMethods}, |
|
63 |
{"getDeclaredConstructors0","(Z)[" CTR, (void *)&JVM_GetClassDeclaredConstructors}, |
|
64 |
{"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain}, |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
65 |
{"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses}, |
20816
b44a353664b8
8014349: (cl) Class.getDeclaredClass problematic in some class loader configurations
jfranck
parents:
18179
diff
changeset
|
66 |
{"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass}, |
30341
a026e34714ed
8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
27072
diff
changeset
|
67 |
{"getSimpleBinaryName0", "()" STR, (void *)&JVM_GetSimpleBinaryName}, |
18179
9b6ad451b521
8016236: Class.getGenericInterfaces performance improvement
shade
parents:
18139
diff
changeset
|
68 |
{"getGenericSignature0", "()" STR, (void *)&JVM_GetClassSignature}, |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
69 |
{"getRawAnnotations", "()" BA, (void *)&JVM_GetClassAnnotations}, |
2 | 70 |
{"getConstantPool", "()" CPL, (void *)&JVM_GetClassConstantPool}, |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
71 |
{"desiredAssertionStatus0","("CLS")Z", (void *)&JVM_DesiredAssertionStatus}, |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
7668
diff
changeset
|
72 |
{"getEnclosingMethod0", "()[" OBJ, (void *)&JVM_GetEnclosingMethodInfo}, |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
7668
diff
changeset
|
73 |
{"getRawTypeAnnotations", "()" BA, (void *)&JVM_GetClassTypeAnnotations}, |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
74 |
{"getNestHost0", "()" CLS, (void *)&JVM_GetNestHost}, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
75 |
{"getNestMembers0", "()[" CLS, (void *)&JVM_GetNestMembers}, |
58678 | 76 |
{"linkClass", "(" CLS ")V", (void *)&JVM_LinkClass}, |
2 | 77 |
}; |
78 |
||
79 |
#undef OBJ |
|
80 |
#undef CLS |
|
81 |
#undef STR |
|
82 |
#undef FLD |
|
83 |
#undef MHD |
|
84 |
#undef CTR |
|
85 |
#undef PD |
|
86 |
||
87 |
JNIEXPORT void JNICALL |
|
88 |
Java_java_lang_Class_registerNatives(JNIEnv *env, jclass cls) |
|
89 |
{ |
|
90 |
methods[1].fnPtr = (void *)(*env)->GetSuperclass; |
|
91 |
(*env)->RegisterNatives(env, cls, methods, |
|
92 |
sizeof(methods)/sizeof(JNINativeMethod)); |
|
93 |
} |
|
94 |
||
95 |
JNIEXPORT jclass JNICALL |
|
96 |
Java_java_lang_Class_forName0(JNIEnv *env, jclass this, jstring classname, |
|
27072 | 97 |
jboolean initialize, jobject loader, jclass caller) |
2 | 98 |
{ |
99 |
char *clname; |
|
100 |
jclass cls = 0; |
|
101 |
char buf[128]; |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
102 |
jsize len; |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
103 |
jsize unicode_len; |
2 | 104 |
|
105 |
if (classname == NULL) { |
|
106 |
JNU_ThrowNullPointerException(env, 0); |
|
107 |
return 0; |
|
108 |
} |
|
109 |
||
110 |
len = (*env)->GetStringUTFLength(env, classname); |
|
111 |
unicode_len = (*env)->GetStringLength(env, classname); |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
112 |
if (len >= (jsize)sizeof(buf)) { |
2 | 113 |
clname = malloc(len + 1); |
114 |
if (clname == NULL) { |
|
115 |
JNU_ThrowOutOfMemoryError(env, NULL); |
|
116 |
return NULL; |
|
117 |
} |
|
118 |
} else { |
|
119 |
clname = buf; |
|
120 |
} |
|
121 |
(*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname); |
|
122 |
||
58678 | 123 |
if (verifyFixClassname(clname) == JNI_TRUE) { |
2 | 124 |
/* slashes present in clname, use name b4 translation for exception */ |
125 |
(*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname); |
|
126 |
JNU_ThrowClassNotFoundException(env, clname); |
|
127 |
goto done; |
|
128 |
} |
|
129 |
||
58678 | 130 |
if (!verifyClassname(clname, JNI_TRUE)) { /* expects slashed name */ |
2 | 131 |
JNU_ThrowClassNotFoundException(env, clname); |
132 |
goto done; |
|
133 |
} |
|
134 |
||
27072 | 135 |
cls = JVM_FindClassFromCaller(env, clname, initialize, loader, caller); |
2 | 136 |
|
137 |
done: |
|
138 |
if (clname != buf) { |
|
139 |
free(clname); |
|
140 |
} |
|
141 |
return cls; |
|
142 |
} |
|
143 |
||
144 |
JNIEXPORT jboolean JNICALL |
|
145 |
Java_java_lang_Class_isInstance(JNIEnv *env, jobject cls, jobject obj) |
|
146 |
{ |
|
147 |
if (obj == NULL) { |
|
148 |
return JNI_FALSE; |
|
149 |
} |
|
150 |
return (*env)->IsInstanceOf(env, obj, (jclass)cls); |
|
151 |
} |
|
152 |
||
153 |
JNIEXPORT jboolean JNICALL |
|
154 |
Java_java_lang_Class_isAssignableFrom(JNIEnv *env, jobject cls, jobject cls2) |
|
155 |
{ |
|
156 |
if (cls2 == NULL) { |
|
157 |
JNU_ThrowNullPointerException(env, 0); |
|
158 |
return JNI_FALSE; |
|
159 |
} |
|
160 |
return (*env)->IsAssignableFrom(env, cls2, cls); |
|
161 |
} |
|
162 |
||
163 |
JNIEXPORT jclass JNICALL |
|
164 |
Java_java_lang_Class_getPrimitiveClass(JNIEnv *env, |
|
165 |
jclass cls, |
|
166 |
jstring name) |
|
167 |
{ |
|
168 |
const char *utfName; |
|
169 |
jclass result; |
|
170 |
||
171 |
if (name == NULL) { |
|
172 |
JNU_ThrowNullPointerException(env, 0); |
|
173 |
return NULL; |
|
174 |
} |
|
175 |
||
176 |
utfName = (*env)->GetStringUTFChars(env, name, 0); |
|
177 |
if (utfName == 0) |
|
178 |
return NULL; |
|
179 |
||
180 |
result = JVM_FindPrimitiveClass(env, utfName); |
|
181 |
||
182 |
(*env)->ReleaseStringUTFChars(env, name, utfName); |
|
183 |
||
184 |
return result; |
|
185 |
} |