author | rriggs |
Fri, 02 Mar 2018 14:17:04 -0500 | |
changeset 49121 | 10f447530d32 |
parent 47216 | 71c04702a3d5 |
child 49123 | d8057fc6fffc |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, 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 |
#include <stdlib.h> |
|
27 |
#include <string.h> |
|
28 |
||
29 |
#include "jvm.h" |
|
30 |
#include "jni.h" |
|
31 |
#include "jni_util.h" |
|
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
32 |
#include "java_lang_String.h" |
2 | 33 |
|
34 |
/* Due to a bug in the win32 C runtime library strings |
|
35 |
* such as "z:" need to be appended with a "." so we |
|
36 |
* must allocate at least 4 bytes to allow room for |
|
37 |
* this expansion. See 4235353 for details. |
|
38 |
*/ |
|
39 |
#define MALLOC_MIN4(len) ((char *)malloc((len) + 1 < 4 ? 4 : (len) + 1)) |
|
40 |
||
41 |
/** |
|
42 |
* Throw a Java exception by name. Similar to SignalError. |
|
43 |
*/ |
|
44 |
JNIEXPORT void JNICALL |
|
45 |
JNU_ThrowByName(JNIEnv *env, const char *name, const char *msg) |
|
46 |
{ |
|
47 |
jclass cls = (*env)->FindClass(env, name); |
|
48 |
||
49 |
if (cls != 0) /* Otherwise an exception has already been thrown */ |
|
50 |
(*env)->ThrowNew(env, cls, msg); |
|
51 |
} |
|
52 |
||
53 |
/* JNU_Throw common exceptions */ |
|
54 |
||
55 |
JNIEXPORT void JNICALL |
|
56 |
JNU_ThrowNullPointerException(JNIEnv *env, const char *msg) |
|
57 |
{ |
|
58 |
JNU_ThrowByName(env, "java/lang/NullPointerException", msg); |
|
59 |
} |
|
60 |
||
61 |
JNIEXPORT void JNICALL |
|
62 |
JNU_ThrowArrayIndexOutOfBoundsException(JNIEnv *env, const char *msg) |
|
63 |
{ |
|
64 |
JNU_ThrowByName(env, "java/lang/ArrayIndexOutOfBoundsException", msg); |
|
65 |
} |
|
66 |
||
67 |
JNIEXPORT void JNICALL |
|
68 |
JNU_ThrowOutOfMemoryError(JNIEnv *env, const char *msg) |
|
69 |
{ |
|
70 |
JNU_ThrowByName(env, "java/lang/OutOfMemoryError", msg); |
|
71 |
} |
|
72 |
||
73 |
JNIEXPORT void JNICALL |
|
74 |
JNU_ThrowIllegalArgumentException(JNIEnv *env, const char *msg) |
|
75 |
{ |
|
76 |
JNU_ThrowByName(env, "java/lang/IllegalArgumentException", msg); |
|
77 |
} |
|
78 |
||
79 |
JNIEXPORT void JNICALL |
|
80 |
JNU_ThrowIllegalAccessError(JNIEnv *env, const char *msg) |
|
81 |
{ |
|
82 |
JNU_ThrowByName(env, "java/lang/IllegalAccessError", msg); |
|
83 |
} |
|
84 |
||
85 |
JNIEXPORT void JNICALL |
|
86 |
JNU_ThrowIllegalAccessException(JNIEnv *env, const char *msg) |
|
87 |
{ |
|
88 |
JNU_ThrowByName(env, "java/lang/IllegalAccessException", msg); |
|
89 |
} |
|
90 |
||
91 |
JNIEXPORT void JNICALL |
|
92 |
JNU_ThrowInternalError(JNIEnv *env, const char *msg) |
|
93 |
{ |
|
94 |
JNU_ThrowByName(env, "java/lang/InternalError", msg); |
|
95 |
} |
|
96 |
||
97 |
JNIEXPORT void JNICALL |
|
98 |
JNU_ThrowNoSuchFieldException(JNIEnv *env, const char *msg) |
|
99 |
{ |
|
100 |
JNU_ThrowByName(env, "java/lang/NoSuchFieldException", msg); |
|
101 |
} |
|
102 |
||
103 |
JNIEXPORT void JNICALL |
|
104 |
JNU_ThrowNoSuchMethodException(JNIEnv *env, const char *msg) |
|
105 |
{ |
|
106 |
JNU_ThrowByName(env, "java/lang/NoSuchMethodException", msg); |
|
107 |
} |
|
108 |
||
109 |
JNIEXPORT void JNICALL |
|
110 |
JNU_ThrowClassNotFoundException(JNIEnv *env, const char *msg) |
|
111 |
{ |
|
112 |
JNU_ThrowByName(env, "java/lang/ClassNotFoundException", msg); |
|
113 |
} |
|
114 |
||
115 |
JNIEXPORT void JNICALL |
|
116 |
JNU_ThrowNumberFormatException(JNIEnv *env, const char *msg) |
|
117 |
{ |
|
118 |
JNU_ThrowByName(env, "java/lang/NumberFormatException", msg); |
|
119 |
} |
|
120 |
||
121 |
JNIEXPORT void JNICALL |
|
122 |
JNU_ThrowIOException(JNIEnv *env, const char *msg) |
|
123 |
{ |
|
124 |
JNU_ThrowByName(env, "java/io/IOException", msg); |
|
125 |
} |
|
126 |
||
127 |
JNIEXPORT void JNICALL |
|
128 |
JNU_ThrowNoSuchFieldError(JNIEnv *env, const char *msg) |
|
129 |
{ |
|
130 |
JNU_ThrowByName(env, "java/lang/NoSuchFieldError", msg); |
|
131 |
} |
|
132 |
||
133 |
JNIEXPORT void JNICALL |
|
134 |
JNU_ThrowNoSuchMethodError(JNIEnv *env, const char *msg) |
|
135 |
{ |
|
136 |
JNU_ThrowByName(env, "java/lang/NoSuchMethodError", msg); |
|
137 |
} |
|
138 |
||
139 |
JNIEXPORT void JNICALL |
|
140 |
JNU_ThrowStringIndexOutOfBoundsException(JNIEnv *env, const char *msg) |
|
141 |
{ |
|
142 |
JNU_ThrowByName(env, "java/lang/StringIndexOutOfBoundsException", msg); |
|
143 |
} |
|
144 |
||
145 |
JNIEXPORT void JNICALL |
|
146 |
JNU_ThrowInstantiationException(JNIEnv *env, const char *msg) |
|
147 |
{ |
|
148 |
JNU_ThrowByName(env, "java/lang/InstantiationException", msg); |
|
149 |
} |
|
150 |
||
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
151 |
/* |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
152 |
* Throw an exception by name, using the string returned by |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
153 |
* getLastErrorString for the detail string. If the last-error |
2 | 154 |
* string is NULL, use the given default detail string. |
155 |
*/ |
|
156 |
JNIEXPORT void JNICALL |
|
157 |
JNU_ThrowByNameWithLastError(JNIEnv *env, const char *name, |
|
158 |
const char *defaultDetail) |
|
159 |
{ |
|
160 |
char buf[256]; |
|
30784 | 161 |
size_t n = getLastErrorString(buf, sizeof(buf)); |
2 | 162 |
|
163 |
if (n > 0) { |
|
164 |
jstring s = JNU_NewStringPlatform(env, buf); |
|
165 |
if (s != NULL) { |
|
166 |
jobject x = JNU_NewObjectByName(env, name, |
|
167 |
"(Ljava/lang/String;)V", s); |
|
168 |
if (x != NULL) { |
|
169 |
(*env)->Throw(env, x); |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
if (!(*env)->ExceptionOccurred(env)) { |
|
174 |
JNU_ThrowByName(env, name, defaultDetail); |
|
175 |
} |
|
176 |
} |
|
177 |
||
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
178 |
/* |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
179 |
* Throw an exception by name, using a given message and the string |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
180 |
* returned by getLastErrorString to construct the detail string. |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
181 |
*/ |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
182 |
JNIEXPORT void JNICALL |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
183 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
184 |
(JNIEnv *env, const char *name, const char *message) |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
185 |
{ |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
186 |
char buf[256]; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
187 |
size_t n = getLastErrorString(buf, sizeof(buf)); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
188 |
size_t messagelen = message == NULL ? 0 : strlen(message); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
189 |
|
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
190 |
if (n > 0) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
191 |
jstring s = JNU_NewStringPlatform(env, buf); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
192 |
if (s != NULL) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
193 |
jobject x = NULL; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
194 |
if (messagelen) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
195 |
jstring s2 = NULL; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
196 |
size_t messageextlen = messagelen + 4; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
197 |
char *str1 = (char *)malloc((messageextlen) * sizeof(char)); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
198 |
if (str1 == 0) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
199 |
JNU_ThrowOutOfMemoryError(env, 0); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
200 |
return; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
201 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
202 |
jio_snprintf(str1, messageextlen, " (%s)", message); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
203 |
s2 = (*env)->NewStringUTF(env, str1); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
204 |
free(str1); |
42442 | 205 |
JNU_CHECK_EXCEPTION(env); |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
206 |
if (s2 != NULL) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
207 |
jstring s3 = JNU_CallMethodByName( |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
208 |
env, NULL, s, "concat", |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
209 |
"(Ljava/lang/String;)Ljava/lang/String;", |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
210 |
s2).l; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
211 |
(*env)->DeleteLocalRef(env, s2); |
42442 | 212 |
JNU_CHECK_EXCEPTION(env); |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
213 |
if (s3 != NULL) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
214 |
(*env)->DeleteLocalRef(env, s); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
215 |
s = s3; |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
216 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
217 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
218 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
219 |
x = JNU_NewObjectByName(env, name, "(Ljava/lang/String;)V", s); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
220 |
if (x != NULL) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
221 |
(*env)->Throw(env, x); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
222 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
223 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
224 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
225 |
|
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
226 |
if (!(*env)->ExceptionOccurred(env)) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
227 |
if (messagelen) { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
228 |
JNU_ThrowByName(env, name, message); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
229 |
} else { |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
230 |
JNU_ThrowByName(env, name, "no further information"); |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
231 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
232 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
233 |
} |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
234 |
|
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
235 |
/* |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
236 |
* Convenience method. |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
35260
diff
changeset
|
237 |
* Call JNU_ThrowByNameWithLastError for java.io.IOException. |
2 | 238 |
*/ |
239 |
JNIEXPORT void JNICALL |
|
240 |
JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail) |
|
241 |
{ |
|
242 |
JNU_ThrowByNameWithLastError(env, "java/io/IOException", defaultDetail); |
|
243 |
} |
|
244 |
||
245 |
||
246 |
JNIEXPORT jvalue JNICALL |
|
247 |
JNU_CallStaticMethodByName(JNIEnv *env, |
|
248 |
jboolean *hasException, |
|
249 |
const char *class_name, |
|
250 |
const char *name, |
|
251 |
const char *signature, |
|
252 |
...) |
|
253 |
{ |
|
254 |
jclass clazz; |
|
255 |
jmethodID mid; |
|
256 |
va_list args; |
|
257 |
jvalue result; |
|
258 |
const char *p = signature; |
|
259 |
||
260 |
/* find out the return type */ |
|
261 |
while (*p && *p != ')') |
|
262 |
p++; |
|
263 |
p++; |
|
264 |
||
265 |
result.i = 0; |
|
266 |
||
267 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
268 |
goto done2; |
|
269 |
||
270 |
clazz = (*env)->FindClass(env, class_name); |
|
271 |
if (clazz == 0) |
|
272 |
goto done2; |
|
273 |
mid = (*env)->GetStaticMethodID(env, clazz, name, signature); |
|
274 |
if (mid == 0) |
|
275 |
goto done1; |
|
276 |
va_start(args, signature); |
|
277 |
switch (*p) { |
|
278 |
case 'V': |
|
279 |
(*env)->CallStaticVoidMethodV(env, clazz, mid, args); |
|
280 |
break; |
|
281 |
case '[': |
|
282 |
case 'L': |
|
283 |
result.l = (*env)->CallStaticObjectMethodV(env, clazz, mid, args); |
|
284 |
break; |
|
285 |
case 'Z': |
|
286 |
result.z = (*env)->CallStaticBooleanMethodV(env, clazz, mid, args); |
|
287 |
break; |
|
288 |
case 'B': |
|
289 |
result.b = (*env)->CallStaticByteMethodV(env, clazz, mid, args); |
|
290 |
break; |
|
291 |
case 'C': |
|
292 |
result.c = (*env)->CallStaticCharMethodV(env, clazz, mid, args); |
|
293 |
break; |
|
294 |
case 'S': |
|
295 |
result.s = (*env)->CallStaticShortMethodV(env, clazz, mid, args); |
|
296 |
break; |
|
297 |
case 'I': |
|
298 |
result.i = (*env)->CallStaticIntMethodV(env, clazz, mid, args); |
|
299 |
break; |
|
300 |
case 'J': |
|
301 |
result.j = (*env)->CallStaticLongMethodV(env, clazz, mid, args); |
|
302 |
break; |
|
303 |
case 'F': |
|
304 |
result.f = (*env)->CallStaticFloatMethodV(env, clazz, mid, args); |
|
305 |
break; |
|
306 |
case 'D': |
|
307 |
result.d = (*env)->CallStaticDoubleMethodV(env, clazz, mid, args); |
|
308 |
break; |
|
309 |
default: |
|
310 |
(*env)->FatalError(env, "JNU_CallStaticMethodByName: illegal signature"); |
|
311 |
} |
|
312 |
va_end(args); |
|
313 |
||
314 |
done1: |
|
315 |
(*env)->DeleteLocalRef(env, clazz); |
|
316 |
done2: |
|
317 |
if (hasException) { |
|
318 |
*hasException = (*env)->ExceptionCheck(env); |
|
319 |
} |
|
320 |
return result; |
|
321 |
} |
|
322 |
||
323 |
JNIEXPORT jvalue JNICALL |
|
324 |
JNU_CallMethodByName(JNIEnv *env, |
|
325 |
jboolean *hasException, |
|
326 |
jobject obj, |
|
327 |
const char *name, |
|
328 |
const char *signature, |
|
329 |
...) |
|
330 |
{ |
|
331 |
jvalue result; |
|
332 |
va_list args; |
|
333 |
||
334 |
va_start(args, signature); |
|
335 |
result = JNU_CallMethodByNameV(env, hasException, obj, name, signature, |
|
336 |
args); |
|
337 |
va_end(args); |
|
338 |
||
339 |
return result; |
|
340 |
} |
|
341 |
||
342 |
||
343 |
JNIEXPORT jvalue JNICALL |
|
344 |
JNU_CallMethodByNameV(JNIEnv *env, |
|
345 |
jboolean *hasException, |
|
346 |
jobject obj, |
|
347 |
const char *name, |
|
348 |
const char *signature, |
|
349 |
va_list args) |
|
350 |
{ |
|
351 |
jclass clazz; |
|
352 |
jmethodID mid; |
|
353 |
jvalue result; |
|
354 |
const char *p = signature; |
|
355 |
||
356 |
/* find out the return type */ |
|
357 |
while (*p && *p != ')') |
|
358 |
p++; |
|
359 |
p++; |
|
360 |
||
361 |
result.i = 0; |
|
362 |
||
363 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
364 |
goto done2; |
|
365 |
||
366 |
clazz = (*env)->GetObjectClass(env, obj); |
|
367 |
mid = (*env)->GetMethodID(env, clazz, name, signature); |
|
368 |
if (mid == 0) |
|
369 |
goto done1; |
|
370 |
||
371 |
switch (*p) { |
|
372 |
case 'V': |
|
373 |
(*env)->CallVoidMethodV(env, obj, mid, args); |
|
374 |
break; |
|
375 |
case '[': |
|
376 |
case 'L': |
|
377 |
result.l = (*env)->CallObjectMethodV(env, obj, mid, args); |
|
378 |
break; |
|
379 |
case 'Z': |
|
380 |
result.z = (*env)->CallBooleanMethodV(env, obj, mid, args); |
|
381 |
break; |
|
382 |
case 'B': |
|
383 |
result.b = (*env)->CallByteMethodV(env, obj, mid, args); |
|
384 |
break; |
|
385 |
case 'C': |
|
386 |
result.c = (*env)->CallCharMethodV(env, obj, mid, args); |
|
387 |
break; |
|
388 |
case 'S': |
|
389 |
result.s = (*env)->CallShortMethodV(env, obj, mid, args); |
|
390 |
break; |
|
391 |
case 'I': |
|
392 |
result.i = (*env)->CallIntMethodV(env, obj, mid, args); |
|
393 |
break; |
|
394 |
case 'J': |
|
395 |
result.j = (*env)->CallLongMethodV(env, obj, mid, args); |
|
396 |
break; |
|
397 |
case 'F': |
|
398 |
result.f = (*env)->CallFloatMethodV(env, obj, mid, args); |
|
399 |
break; |
|
400 |
case 'D': |
|
401 |
result.d = (*env)->CallDoubleMethodV(env, obj, mid, args); |
|
402 |
break; |
|
403 |
default: |
|
404 |
(*env)->FatalError(env, "JNU_CallMethodByNameV: illegal signature"); |
|
405 |
} |
|
406 |
done1: |
|
407 |
(*env)->DeleteLocalRef(env, clazz); |
|
408 |
done2: |
|
409 |
if (hasException) { |
|
410 |
*hasException = (*env)->ExceptionCheck(env); |
|
411 |
} |
|
412 |
return result; |
|
413 |
} |
|
414 |
||
415 |
JNIEXPORT jobject JNICALL |
|
416 |
JNU_NewObjectByName(JNIEnv *env, const char *class_name, |
|
417 |
const char *constructor_sig, ...) |
|
418 |
{ |
|
419 |
jobject obj = NULL; |
|
420 |
||
421 |
jclass cls = 0; |
|
422 |
jmethodID cls_initMID; |
|
423 |
va_list args; |
|
424 |
||
425 |
if ((*env)->EnsureLocalCapacity(env, 2) < 0) |
|
426 |
goto done; |
|
427 |
||
428 |
cls = (*env)->FindClass(env, class_name); |
|
429 |
if (cls == 0) { |
|
430 |
goto done; |
|
431 |
} |
|
432 |
cls_initMID = (*env)->GetMethodID(env, cls, |
|
433 |
"<init>", constructor_sig); |
|
434 |
if (cls_initMID == NULL) { |
|
435 |
goto done; |
|
436 |
} |
|
437 |
va_start(args, constructor_sig); |
|
438 |
obj = (*env)->NewObjectV(env, cls, cls_initMID, args); |
|
439 |
va_end(args); |
|
440 |
||
441 |
done: |
|
442 |
(*env)->DeleteLocalRef(env, cls); |
|
443 |
return obj; |
|
444 |
} |
|
445 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
446 |
/* Optimized for charset ISO_8559_1 */ |
2 | 447 |
static jstring |
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
448 |
newSizedString8859_1(JNIEnv *env, const char *str, const int len) |
2 | 449 |
{ |
450 |
jchar buf[512]; |
|
451 |
jchar *str1; |
|
452 |
jstring result; |
|
453 |
int i; |
|
454 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
455 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
456 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
457 |
|
2 | 458 |
if (len > 512) { |
459 |
str1 = (jchar *)malloc(len * sizeof(jchar)); |
|
460 |
if (str1 == 0) { |
|
461 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
462 |
return 0; |
|
463 |
} |
|
464 |
} else |
|
465 |
str1 = buf; |
|
466 |
||
467 |
for (i=0;i<len;i++) |
|
468 |
str1[i] = (unsigned char)str[i]; |
|
469 |
result = (*env)->NewString(env, str1, len); |
|
470 |
if (str1 != buf) |
|
471 |
free(str1); |
|
472 |
return result; |
|
473 |
} |
|
474 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
475 |
static jstring |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
476 |
newString8859_1(JNIEnv *env, const char *str) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
477 |
{ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
478 |
int len = (int)strlen(str); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
479 |
return newSizedString8859_1(env, str, len); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
480 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
481 |
|
2 | 482 |
static const char* |
483 |
getString8859_1Chars(JNIEnv *env, jstring jstr) |
|
484 |
{ |
|
485 |
int i; |
|
486 |
char *result; |
|
487 |
jint len = (*env)->GetStringLength(env, jstr); |
|
488 |
const jchar *str = (*env)->GetStringCritical(env, jstr, 0); |
|
489 |
if (str == 0) { |
|
490 |
return 0; |
|
491 |
} |
|
492 |
||
493 |
result = MALLOC_MIN4(len); |
|
494 |
if (result == 0) { |
|
495 |
(*env)->ReleaseStringCritical(env, jstr, str); |
|
496 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
497 |
return 0; |
|
498 |
} |
|
499 |
||
500 |
for (i=0; i<len; i++) { |
|
501 |
jchar unicode = str[i]; |
|
502 |
if (unicode <= 0x00ff) |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
503 |
result[i] = (char)unicode; |
2 | 504 |
else |
505 |
result[i] = '?'; |
|
506 |
} |
|
507 |
||
508 |
result[len] = 0; |
|
509 |
(*env)->ReleaseStringCritical(env, jstr, str); |
|
510 |
return result; |
|
511 |
} |
|
512 |
||
513 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
514 |
/* Optimized for charset ISO646-US (us-ascii) */ |
2 | 515 |
static jstring |
516 |
newString646_US(JNIEnv *env, const char *str) |
|
517 |
{ |
|
30784 | 518 |
int len = (int)strlen(str); |
2 | 519 |
jchar buf[512]; |
520 |
jchar *str1; |
|
521 |
jstring result; |
|
522 |
int i; |
|
523 |
||
524 |
if (len > 512) { |
|
525 |
str1 = (jchar *)malloc(len * sizeof(jchar)); |
|
526 |
if (str1 == 0) { |
|
527 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
528 |
return 0; |
|
529 |
} |
|
530 |
} else |
|
531 |
str1 = buf; |
|
532 |
||
533 |
for (i=0; i<len; i++) { |
|
534 |
unsigned char c = (unsigned char)str[i]; |
|
535 |
if (c <= 0x7f) |
|
536 |
str1[i] = c; |
|
537 |
else |
|
538 |
str1[i] = '?'; |
|
539 |
} |
|
540 |
||
541 |
result = (*env)->NewString(env, str1, len); |
|
542 |
if (str1 != buf) |
|
543 |
free(str1); |
|
544 |
return result; |
|
545 |
} |
|
546 |
||
547 |
static const char* |
|
548 |
getString646_USChars(JNIEnv *env, jstring jstr) |
|
549 |
{ |
|
550 |
int i; |
|
551 |
char *result; |
|
552 |
jint len = (*env)->GetStringLength(env, jstr); |
|
553 |
const jchar *str = (*env)->GetStringCritical(env, jstr, 0); |
|
554 |
if (str == 0) { |
|
555 |
return 0; |
|
556 |
} |
|
557 |
||
558 |
result = MALLOC_MIN4(len); |
|
559 |
if (result == 0) { |
|
560 |
(*env)->ReleaseStringCritical(env, jstr, str); |
|
561 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
562 |
return 0; |
|
563 |
} |
|
564 |
||
565 |
for (i=0; i<len; i++) { |
|
566 |
jchar unicode = str[i]; |
|
567 |
if (unicode <= 0x007f ) |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
568 |
result[i] = (char)unicode; |
2 | 569 |
else |
570 |
result[i] = '?'; |
|
571 |
} |
|
572 |
||
573 |
result[len] = 0; |
|
574 |
(*env)->ReleaseStringCritical(env, jstr, str); |
|
575 |
return result; |
|
576 |
} |
|
577 |
||
578 |
/* enumeration of c1 row from Cp1252 */ |
|
579 |
static int cp1252c1chars[32] = { |
|
580 |
0x20AC,0xFFFD,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, |
|
581 |
0x02C6,0x2030,0x0160,0x2039,0x0152,0xFFFD,0x017D,0xFFFD, |
|
582 |
0xFFFD,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, |
|
583 |
0x02Dc,0x2122,0x0161,0x203A,0x0153,0xFFFD,0x017E,0x0178 |
|
584 |
}; |
|
585 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
586 |
/* Optimized for charset Cp1252 */ |
2 | 587 |
static jstring |
588 |
newStringCp1252(JNIEnv *env, const char *str) |
|
589 |
{ |
|
590 |
int len = (int) strlen(str); |
|
591 |
jchar buf[512]; |
|
592 |
jchar *str1; |
|
593 |
jstring result; |
|
594 |
int i; |
|
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
595 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
596 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
597 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
598 |
|
2 | 599 |
if (len > 512) { |
600 |
str1 = (jchar *)malloc(len * sizeof(jchar)); |
|
601 |
if (str1 == 0) { |
|
602 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
603 |
return 0; |
|
604 |
} |
|
605 |
} else |
|
606 |
str1 = buf; |
|
607 |
||
608 |
for (i=0; i<len; i++) { |
|
609 |
unsigned char c = (unsigned char)str[i]; |
|
610 |
if ((c >= 0x80) && (c <= 0x9f)) |
|
611 |
str1[i] = cp1252c1chars[c-128]; |
|
612 |
else |
|
613 |
str1[i] = c; |
|
614 |
} |
|
615 |
||
616 |
result = (*env)->NewString(env, str1, len); |
|
617 |
if (str1 != buf) |
|
618 |
free(str1); |
|
619 |
return result; |
|
620 |
} |
|
621 |
||
622 |
static const char* |
|
623 |
getStringCp1252Chars(JNIEnv *env, jstring jstr) |
|
624 |
{ |
|
625 |
int i; |
|
626 |
char *result; |
|
627 |
jint len = (*env)->GetStringLength(env, jstr); |
|
628 |
const jchar *str = (*env)->GetStringCritical(env, jstr, 0); |
|
629 |
if (str == 0) { |
|
630 |
return 0; |
|
631 |
} |
|
632 |
||
633 |
result = MALLOC_MIN4(len); |
|
634 |
if (result == 0) { |
|
635 |
(*env)->ReleaseStringCritical(env, jstr, str); |
|
636 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
637 |
return 0; |
|
638 |
} |
|
639 |
||
640 |
for (i=0; i<len; i++) { |
|
641 |
jchar c = str[i]; |
|
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
642 |
if (c < 256) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
643 |
if ((c >= 0x80) && (c <= 0x9f)) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
644 |
result[i] = '?'; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
645 |
} else { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
646 |
result[i] = (char)c; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
647 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
648 |
} else switch(c) { |
2 | 649 |
case 0x20AC: result[i] = (char)0x80; break; |
650 |
case 0x201A: result[i] = (char)0x82; break; |
|
651 |
case 0x0192: result[i] = (char)0x83; break; |
|
652 |
case 0x201E: result[i] = (char)0x84; break; |
|
653 |
case 0x2026: result[i] = (char)0x85; break; |
|
654 |
case 0x2020: result[i] = (char)0x86; break; |
|
655 |
case 0x2021: result[i] = (char)0x87; break; |
|
656 |
case 0x02C6: result[i] = (char)0x88; break; |
|
657 |
case 0x2030: result[i] = (char)0x89; break; |
|
658 |
case 0x0160: result[i] = (char)0x8A; break; |
|
659 |
case 0x2039: result[i] = (char)0x8B; break; |
|
660 |
case 0x0152: result[i] = (char)0x8C; break; |
|
661 |
case 0x017D: result[i] = (char)0x8E; break; |
|
662 |
case 0x2018: result[i] = (char)0x91; break; |
|
663 |
case 0x2019: result[i] = (char)0x92; break; |
|
664 |
case 0x201C: result[i] = (char)0x93; break; |
|
665 |
case 0x201D: result[i] = (char)0x94; break; |
|
666 |
case 0x2022: result[i] = (char)0x95; break; |
|
667 |
case 0x2013: result[i] = (char)0x96; break; |
|
668 |
case 0x2014: result[i] = (char)0x97; break; |
|
669 |
case 0x02DC: result[i] = (char)0x98; break; |
|
670 |
case 0x2122: result[i] = (char)0x99; break; |
|
671 |
case 0x0161: result[i] = (char)0x9A; break; |
|
672 |
case 0x203A: result[i] = (char)0x9B; break; |
|
673 |
case 0x0153: result[i] = (char)0x9C; break; |
|
674 |
case 0x017E: result[i] = (char)0x9E; break; |
|
675 |
case 0x0178: result[i] = (char)0x9F; break; |
|
676 |
default: result[i] = '?'; break; |
|
677 |
} |
|
678 |
} |
|
679 |
||
680 |
result[len] = 0; |
|
681 |
(*env)->ReleaseStringCritical(env, jstr, str); |
|
682 |
return result; |
|
683 |
} |
|
684 |
||
685 |
static int fastEncoding = NO_ENCODING_YET; |
|
686 |
static jstring jnuEncoding = NULL; |
|
687 |
||
688 |
/* Cached method IDs */ |
|
689 |
static jmethodID String_init_ID; /* String(byte[], enc) */ |
|
690 |
static jmethodID String_getBytes_ID; /* String.getBytes(enc) */ |
|
691 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
692 |
/* Cached field IDs */ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
693 |
static jfieldID String_coder_ID; /* String.coder */ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
694 |
static jfieldID String_value_ID; /* String.value */ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
695 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
696 |
static jboolean isJNUEncodingSupported = JNI_FALSE; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
697 |
static jboolean jnuEncodingSupported(JNIEnv *env) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
698 |
jboolean exe; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
699 |
if (isJNUEncodingSupported == JNI_TRUE) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
700 |
return JNI_TRUE; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
701 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
702 |
isJNUEncodingSupported = (jboolean) JNU_CallStaticMethodByName ( |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
703 |
env, &exe, |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
704 |
"java/nio/charset/Charset", |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
705 |
"isSupported", |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
706 |
"(Ljava/lang/String;)Z", |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
707 |
jnuEncoding).z; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
708 |
return isJNUEncodingSupported; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
709 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
710 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
711 |
/* Create a new string by converting str to a heap-allocated byte array and |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
712 |
* calling the appropriate String constructor. |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
713 |
*/ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
714 |
static jstring |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
715 |
newSizedStringJava(JNIEnv *env, const char *str, const int len) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
716 |
{ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
717 |
jstring result = NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
718 |
jbyteArray bytes = 0; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
719 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
720 |
if ((*env)->EnsureLocalCapacity(env, 2) < 0) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
721 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
722 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
723 |
bytes = (*env)->NewByteArray(env, len); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
724 |
if (bytes != NULL) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
725 |
jclass strClazz = JNU_ClassString(env); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
726 |
CHECK_NULL_RETURN(strClazz, 0); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
727 |
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte *)str); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
728 |
if (jnuEncodingSupported(env)) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
729 |
result = (*env)->NewObject(env, strClazz, |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
730 |
String_init_ID, bytes, jnuEncoding); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
731 |
} else { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
732 |
/*If the encoding specified in sun.jnu.encoding is not endorsed |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
733 |
by "Charset.isSupported" we have to fall back to use String(byte[]) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
734 |
explicitly here without specifying the encoding name, in which the |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
735 |
StringCoding class will pickup the iso-8859-1 as the fallback |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
736 |
converter for us. |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
737 |
*/ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
738 |
jmethodID mid = (*env)->GetMethodID(env, strClazz, |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
739 |
"<init>", "([B)V"); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
740 |
if (mid != NULL) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
741 |
result = (*env)->NewObject(env, strClazz, mid, bytes); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
742 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
743 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
744 |
(*env)->DeleteLocalRef(env, bytes); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
745 |
return result; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
746 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
747 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
748 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
749 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
750 |
static jstring |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
751 |
newStringJava(JNIEnv *env, const char *str) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
752 |
{ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
753 |
int len = (int)strlen(str); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
754 |
return newSizedStringJava(env, str, len); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
755 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
756 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
757 |
/* Optimized for charset UTF-8 */ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
758 |
static jstring |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
759 |
newStringUTF8(JNIEnv *env, const char *str) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
760 |
{ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
761 |
int len; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
762 |
const unsigned char *p; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
763 |
unsigned char asciiCheck; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
764 |
for (asciiCheck = 0, p = (const unsigned char*)str; *p != '\0'; p++) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
765 |
asciiCheck |= *p; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
766 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
767 |
len = (int)((const char*)p - str); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
768 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
769 |
if (asciiCheck < 0x80) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
770 |
// ascii fast-path |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
771 |
return newSizedString8859_1(env, str, len); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
772 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
773 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
774 |
return newSizedStringJava(env, str, len); |
3111
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2
diff
changeset
|
775 |
} |
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2
diff
changeset
|
776 |
|
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
777 |
/* Initialize the fast encoding from the encoding name. */ |
3111
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2
diff
changeset
|
778 |
void |
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
779 |
InitializeEncoding(JNIEnv *env, const char *encname) |
2 | 780 |
{ |
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
781 |
jclass strClazz = NULL; |
2 | 782 |
|
783 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
784 |
return; |
|
785 |
||
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
786 |
strClazz = JNU_ClassString(env); |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
787 |
CHECK_NULL(strClazz); |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
788 |
|
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
789 |
if (encname) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
790 |
/* |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
791 |
* On Solaris with nl_langinfo() called in GetJavaProperties(): |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
792 |
* |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
793 |
* locale undefined -> NULL -> hardcoded default |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
794 |
* "C" locale -> "" -> hardcoded default (on 2.6) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
795 |
* "C" locale -> "ISO646-US" (on Sol 7/8) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
796 |
* "en_US" locale -> "ISO8859-1" |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
797 |
* "en_GB" locale -> "ISO8859-1" (on Sol 7/8) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
798 |
* "en_UK" locale -> "ISO8859-1" (on 2.6) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
799 |
*/ |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
800 |
if ((strcmp(encname, "8859_1") == 0) || |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
801 |
(strcmp(encname, "ISO8859-1") == 0) || |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
802 |
(strcmp(encname, "ISO8859_1") == 0) || |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
803 |
(strcmp(encname, "ISO-8859-1") == 0)) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
804 |
fastEncoding = FAST_8859_1; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
805 |
} else if (strcmp(encname, "UTF-8") == 0) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
806 |
fastEncoding = FAST_UTF_8; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
807 |
jstring enc = (*env)->NewStringUTF(env, encname); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
808 |
if (enc == NULL) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
809 |
return; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
810 |
jnuEncoding = (jstring)(*env)->NewGlobalRef(env, enc); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
811 |
(*env)->DeleteLocalRef(env, enc); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
812 |
} else if (strcmp(encname, "ISO646-US") == 0) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
813 |
fastEncoding = FAST_646_US; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
814 |
} else if (strcmp(encname, "Cp1252") == 0 || |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
815 |
/* This is a temporary fix until we move */ |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
816 |
/* to wide character versions of all Windows */ |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
817 |
/* calls. */ |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
818 |
strcmp(encname, "utf-16le") == 0) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
819 |
fastEncoding = FAST_CP1252; |
2 | 820 |
} else { |
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
821 |
fastEncoding = NO_FAST_ENCODING; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
822 |
jstring enc = (*env)->NewStringUTF(env, encname); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
823 |
if (enc == NULL) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
824 |
return; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
825 |
jnuEncoding = (jstring)(*env)->NewGlobalRef(env, enc); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
826 |
(*env)->DeleteLocalRef(env, enc); |
2 | 827 |
} |
828 |
} else { |
|
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
829 |
JNU_ThrowInternalError(env, "platform encoding undefined"); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
830 |
return; |
2 | 831 |
} |
832 |
||
833 |
/* Initialize method-id cache */ |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
834 |
String_getBytes_ID = (*env)->GetMethodID(env, strClazz, |
2 | 835 |
"getBytes", "(Ljava/lang/String;)[B"); |
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
836 |
CHECK_NULL(String_getBytes_ID); |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
837 |
String_init_ID = (*env)->GetMethodID(env, strClazz, |
2 | 838 |
"<init>", "([BLjava/lang/String;)V"); |
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
839 |
String_coder_ID = (*env)->GetFieldID(env, strClazz, "coder", "B"); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
840 |
String_value_ID = (*env)->GetFieldID(env, strClazz, "value", "[B"); |
2 | 841 |
} |
842 |
||
843 |
JNIEXPORT jstring |
|
844 |
NewStringPlatform(JNIEnv *env, const char *str) |
|
845 |
{ |
|
846 |
return JNU_NewStringPlatform(env, str); |
|
847 |
} |
|
848 |
||
849 |
JNIEXPORT jstring JNICALL |
|
850 |
JNU_NewStringPlatform(JNIEnv *env, const char *str) |
|
851 |
{ |
|
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
852 |
if (fastEncoding == FAST_UTF_8) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
853 |
return newStringUTF8(env, str); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
854 |
if (fastEncoding == FAST_8859_1) |
22938 | 855 |
return newString8859_1(env, str); |
856 |
if (fastEncoding == FAST_646_US) |
|
857 |
return newString646_US(env, str); |
|
858 |
if (fastEncoding == FAST_CP1252) |
|
859 |
return newStringCp1252(env, str); |
|
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
860 |
if (fastEncoding == NO_ENCODING_YET) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
861 |
JNU_ThrowInternalError(env, "platform encoding not initialized"); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
862 |
return NULL; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
863 |
} |
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
864 |
return newStringJava(env, str); |
2 | 865 |
} |
866 |
||
867 |
JNIEXPORT const char * |
|
868 |
GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) |
|
869 |
{ |
|
870 |
return JNU_GetStringPlatformChars(env, jstr, isCopy); |
|
871 |
} |
|
872 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
873 |
static const char* getStringBytes(JNIEnv *env, jstring jstr) { |
22938 | 874 |
char *result = NULL; |
875 |
jbyteArray hab = 0; |
|
2 | 876 |
|
22938 | 877 |
if ((*env)->EnsureLocalCapacity(env, 2) < 0) |
878 |
return 0; |
|
2 | 879 |
|
22938 | 880 |
if (jnuEncodingSupported(env)) { |
881 |
hab = (*env)->CallObjectMethod(env, jstr, String_getBytes_ID, jnuEncoding); |
|
882 |
} else { |
|
883 |
jmethodID mid; |
|
884 |
jclass strClazz = JNU_ClassString(env); |
|
885 |
CHECK_NULL_RETURN(strClazz, 0); |
|
886 |
mid = (*env)->GetMethodID(env, strClazz, |
|
887 |
"getBytes", "()[B"); |
|
888 |
if (mid != NULL) { |
|
889 |
hab = (*env)->CallObjectMethod(env, jstr, mid); |
|
3111
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2
diff
changeset
|
890 |
} |
22938 | 891 |
} |
2 | 892 |
|
22938 | 893 |
if (!(*env)->ExceptionCheck(env)) { |
894 |
jint len = (*env)->GetArrayLength(env, hab); |
|
895 |
result = MALLOC_MIN4(len); |
|
896 |
if (result == 0) { |
|
897 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
898 |
(*env)->DeleteLocalRef(env, hab); |
|
899 |
return 0; |
|
2 | 900 |
} |
22938 | 901 |
(*env)->GetByteArrayRegion(env, hab, 0, len, (jbyte *)result); |
902 |
result[len] = 0; /* NULL-terminate */ |
|
903 |
} |
|
3111
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2
diff
changeset
|
904 |
|
22938 | 905 |
(*env)->DeleteLocalRef(env, hab); |
2 | 906 |
return result; |
907 |
} |
|
908 |
||
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
909 |
static const char* |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
910 |
getStringUTF8(JNIEnv *env, jstring jstr) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
911 |
{ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
912 |
int i; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
913 |
char *result; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
914 |
jbyteArray value; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
915 |
jint len; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
916 |
jbyte *str; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
917 |
jint rlen; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
918 |
int ri; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
919 |
jbyte coder = (*env)->GetByteField(env, jstr, String_coder_ID); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
920 |
if (coder != java_lang_String_LATIN1) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
921 |
return getStringBytes(env, jstr); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
922 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
923 |
if ((*env)->EnsureLocalCapacity(env, 2) < 0) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
924 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
925 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
926 |
value = (*env)->GetObjectField(env, jstr, String_value_ID); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
927 |
if (value == NULL) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
928 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
929 |
len = (*env)->GetArrayLength(env, value); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
930 |
str = (*env)->GetPrimitiveArrayCritical(env, value, NULL); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
931 |
if (str == NULL) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
932 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
933 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
934 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
935 |
rlen = len; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
936 |
// we need two bytes for each latin-1 char above 127 (negative jbytes) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
937 |
for (i = 0; i < len; i++) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
938 |
if (str[i] < 0) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
939 |
rlen++; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
940 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
941 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
942 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
943 |
result = MALLOC_MIN4(rlen); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
944 |
if (result == NULL) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
945 |
(*env)->ReleasePrimitiveArrayCritical(env, value, str, 0); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
946 |
JNU_ThrowOutOfMemoryError(env, 0); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
947 |
return NULL; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
948 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
949 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
950 |
for (ri = 0, i = 0; i < len; i++) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
951 |
jbyte c = str[i]; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
952 |
if (c < 0) { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
953 |
result[ri++] = (char)(0xc0 | ((c & 0xff) >> 6)); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
954 |
result[ri++] = (char)(0x80 | (c & 0x3f)); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
955 |
} else { |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
956 |
result[ri++] = c; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
957 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
958 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
959 |
(*env)->ReleasePrimitiveArrayCritical(env, value, str, 0); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
960 |
result[rlen] = '\0'; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
961 |
return result; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
962 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
963 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
964 |
JNIEXPORT const char * JNICALL |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
965 |
JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
966 |
{ |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
967 |
|
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
968 |
if (isCopy) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
969 |
*isCopy = JNI_TRUE; |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
970 |
|
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
971 |
if (fastEncoding == FAST_UTF_8) |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
972 |
return getStringUTF8(env, jstr); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
973 |
if (fastEncoding == FAST_8859_1) |
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
974 |
return getString8859_1Chars(env, jstr); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
975 |
if (fastEncoding == FAST_646_US) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
976 |
return getString646_USChars(env, jstr); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
977 |
if (fastEncoding == FAST_CP1252) |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
978 |
return getStringCp1252Chars(env, jstr); |
49121
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
979 |
if (fastEncoding == NO_ENCODING_YET) { |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
980 |
JNU_ThrowInternalError(env, "platform encoding not initialized"); |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
981 |
return 0; |
10f447530d32
8198697: Simplify initialization of platform encoding
rriggs
parents:
47216
diff
changeset
|
982 |
} else |
45572
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
983 |
return getStringBytes(env, jstr); |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
984 |
} |
07f412070bd9
8181147: JNI_GetStringPlatformChars should have a fast path for UTF-8
redestad
parents:
42442
diff
changeset
|
985 |
|
2 | 986 |
JNIEXPORT void JNICALL |
987 |
JNU_ReleaseStringPlatformChars(JNIEnv *env, jstring jstr, const char *str) |
|
988 |
{ |
|
989 |
free((void *)str); |
|
990 |
} |
|
991 |
||
992 |
/* |
|
993 |
* Export the platform dependent path canonicalization so that |
|
994 |
* VM can find it when loading system classes. |
|
23235
d1b1878b2eaa
8034025: Remove JPLIS agent dependency on canonicalize_md.c
sla
parents:
22938
diff
changeset
|
995 |
* This function is also used by the instrumentation agent. |
2 | 996 |
*/ |
997 |
extern int canonicalize(char *path, const char *out, int len); |
|
998 |
||
999 |
JNIEXPORT int |
|
23235
d1b1878b2eaa
8034025: Remove JPLIS agent dependency on canonicalize_md.c
sla
parents:
22938
diff
changeset
|
1000 |
Canonicalize(JNIEnv *unused, char *orig, char *out, int len) |
2 | 1001 |
{ |
1002 |
/* canonicalize an already natived path */ |
|
1003 |
return canonicalize(orig, out, len); |
|
1004 |
} |
|
1005 |
||
1006 |
JNIEXPORT jclass JNICALL |
|
1007 |
JNU_ClassString(JNIEnv *env) |
|
1008 |
{ |
|
1009 |
static jclass cls = 0; |
|
1010 |
if (cls == 0) { |
|
1011 |
jclass c; |
|
1012 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
|
1013 |
return 0; |
|
1014 |
c = (*env)->FindClass(env, "java/lang/String"); |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1015 |
CHECK_NULL_RETURN(c, NULL); |
2 | 1016 |
cls = (*env)->NewGlobalRef(env, c); |
1017 |
(*env)->DeleteLocalRef(env, c); |
|
1018 |
} |
|
1019 |
return cls; |
|
1020 |
} |
|
1021 |
||
1022 |
JNIEXPORT jclass JNICALL |
|
1023 |
JNU_ClassClass(JNIEnv *env) |
|
1024 |
{ |
|
1025 |
static jclass cls = 0; |
|
1026 |
if (cls == 0) { |
|
1027 |
jclass c; |
|
1028 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
|
1029 |
return 0; |
|
1030 |
c = (*env)->FindClass(env, "java/lang/Class"); |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1031 |
CHECK_NULL_RETURN(c, NULL); |
2 | 1032 |
cls = (*env)->NewGlobalRef(env, c); |
1033 |
(*env)->DeleteLocalRef(env, c); |
|
1034 |
} |
|
1035 |
return cls; |
|
1036 |
} |
|
1037 |
||
1038 |
JNIEXPORT jclass JNICALL |
|
1039 |
JNU_ClassObject(JNIEnv *env) |
|
1040 |
{ |
|
1041 |
static jclass cls = 0; |
|
1042 |
if (cls == 0) { |
|
1043 |
jclass c; |
|
1044 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
|
1045 |
return 0; |
|
1046 |
c = (*env)->FindClass(env, "java/lang/Object"); |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1047 |
CHECK_NULL_RETURN(c, NULL); |
2 | 1048 |
cls = (*env)->NewGlobalRef(env, c); |
1049 |
(*env)->DeleteLocalRef(env, c); |
|
1050 |
} |
|
1051 |
return cls; |
|
1052 |
} |
|
1053 |
||
1054 |
JNIEXPORT jclass JNICALL |
|
1055 |
JNU_ClassThrowable(JNIEnv *env) |
|
1056 |
{ |
|
1057 |
static jclass cls = 0; |
|
1058 |
if (cls == 0) { |
|
1059 |
jclass c; |
|
1060 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
|
1061 |
return 0; |
|
1062 |
c = (*env)->FindClass(env, "java/lang/Throwable"); |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1063 |
CHECK_NULL_RETURN(c, NULL); |
2 | 1064 |
cls = (*env)->NewGlobalRef(env, c); |
1065 |
(*env)->DeleteLocalRef(env, c); |
|
1066 |
} |
|
1067 |
return cls; |
|
1068 |
} |
|
1069 |
||
1070 |
JNIEXPORT jint JNICALL |
|
1071 |
JNU_CopyObjectArray(JNIEnv *env, jobjectArray dst, jobjectArray src, |
|
1072 |
jint count) |
|
1073 |
{ |
|
1074 |
int i; |
|
1075 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
|
1076 |
return -1; |
|
1077 |
for (i=0; i<count; i++) { |
|
1078 |
jstring p = (*env)->GetObjectArrayElement(env, src, i); |
|
1079 |
(*env)->SetObjectArrayElement(env, dst, i, p); |
|
1080 |
(*env)->DeleteLocalRef(env, p); |
|
1081 |
} |
|
1082 |
return 0; |
|
1083 |
} |
|
1084 |
||
1085 |
JNIEXPORT void * JNICALL |
|
1086 |
JNU_GetEnv(JavaVM *vm, jint version) |
|
1087 |
{ |
|
1088 |
void *env; |
|
1089 |
(*vm)->GetEnv(vm, &env, version); |
|
1090 |
return env; |
|
1091 |
} |
|
1092 |
||
1093 |
JNIEXPORT jint JNICALL |
|
1094 |
JNU_IsInstanceOfByName(JNIEnv *env, jobject object, char* classname) |
|
1095 |
{ |
|
1096 |
jclass cls; |
|
1097 |
if ((*env)->EnsureLocalCapacity(env, 1) < 0) |
|
1098 |
return JNI_ERR; |
|
1099 |
cls = (*env)->FindClass(env, classname); |
|
1100 |
if (cls != NULL) { |
|
1101 |
jint result = (*env)->IsInstanceOf(env, object, cls); |
|
1102 |
(*env)->DeleteLocalRef(env, cls); |
|
1103 |
return result; |
|
1104 |
} |
|
1105 |
return JNI_ERR; |
|
1106 |
} |
|
1107 |
||
1108 |
JNIEXPORT jboolean JNICALL |
|
1109 |
JNU_Equals(JNIEnv *env, jobject object1, jobject object2) |
|
1110 |
{ |
|
1111 |
static jmethodID mid = NULL; |
|
1112 |
if (mid == NULL) { |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1113 |
jclass objClazz = JNU_ClassObject(env); |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1114 |
CHECK_NULL_RETURN(objClazz, JNI_FALSE); |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1115 |
mid = (*env)->GetMethodID(env, objClazz, "equals", |
2 | 1116 |
"(Ljava/lang/Object;)Z"); |
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1117 |
CHECK_NULL_RETURN(mid, JNI_FALSE); |
2 | 1118 |
} |
1119 |
return (*env)->CallBooleanMethod(env, object1, mid, object2); |
|
1120 |
} |
|
1121 |
||
1122 |
||
1123 |
/************************************************************************ |
|
1124 |
* Thread calls |
|
1125 |
*/ |
|
1126 |
||
1127 |
static jmethodID Object_waitMID; |
|
1128 |
static jmethodID Object_notifyMID; |
|
1129 |
static jmethodID Object_notifyAllMID; |
|
1130 |
||
1131 |
JNIEXPORT void JNICALL |
|
1132 |
JNU_MonitorWait(JNIEnv *env, jobject object, jlong timeout) |
|
1133 |
{ |
|
1134 |
if (object == NULL) { |
|
1135 |
JNU_ThrowNullPointerException(env, "JNU_MonitorWait argument"); |
|
1136 |
return; |
|
1137 |
} |
|
1138 |
if (Object_waitMID == NULL) { |
|
1139 |
jclass cls = JNU_ClassObject(env); |
|
1140 |
if (cls == NULL) { |
|
1141 |
return; |
|
1142 |
} |
|
1143 |
Object_waitMID = (*env)->GetMethodID(env, cls, "wait", "(J)V"); |
|
1144 |
if (Object_waitMID == NULL) { |
|
1145 |
return; |
|
1146 |
} |
|
1147 |
} |
|
1148 |
(*env)->CallVoidMethod(env, object, Object_waitMID, timeout); |
|
1149 |
} |
|
1150 |
||
1151 |
JNIEXPORT void JNICALL |
|
1152 |
JNU_Notify(JNIEnv *env, jobject object) |
|
1153 |
{ |
|
1154 |
if (object == NULL) { |
|
1155 |
JNU_ThrowNullPointerException(env, "JNU_Notify argument"); |
|
1156 |
return; |
|
1157 |
} |
|
1158 |
if (Object_notifyMID == NULL) { |
|
1159 |
jclass cls = JNU_ClassObject(env); |
|
1160 |
if (cls == NULL) { |
|
1161 |
return; |
|
1162 |
} |
|
1163 |
Object_notifyMID = (*env)->GetMethodID(env, cls, "notify", "()V"); |
|
1164 |
if (Object_notifyMID == NULL) { |
|
1165 |
return; |
|
1166 |
} |
|
1167 |
} |
|
1168 |
(*env)->CallVoidMethod(env, object, Object_notifyMID); |
|
1169 |
} |
|
1170 |
||
1171 |
JNIEXPORT void JNICALL |
|
1172 |
JNU_NotifyAll(JNIEnv *env, jobject object) |
|
1173 |
{ |
|
1174 |
if (object == NULL) { |
|
1175 |
JNU_ThrowNullPointerException(env, "JNU_NotifyAll argument"); |
|
1176 |
return; |
|
1177 |
} |
|
1178 |
if (Object_notifyAllMID == NULL) { |
|
1179 |
jclass cls = JNU_ClassObject(env); |
|
1180 |
if (cls == NULL) { |
|
1181 |
return; |
|
1182 |
} |
|
1183 |
Object_notifyAllMID = (*env)->GetMethodID(env, cls,"notifyAll", "()V"); |
|
1184 |
if (Object_notifyAllMID == NULL) { |
|
1185 |
return; |
|
1186 |
} |
|
1187 |
} |
|
1188 |
(*env)->CallVoidMethod(env, object, Object_notifyAllMID); |
|
1189 |
} |
|
1190 |
||
1191 |
||
1192 |
/************************************************************************ |
|
1193 |
* Debugging utilities |
|
1194 |
*/ |
|
1195 |
||
1196 |
JNIEXPORT void JNICALL |
|
1197 |
JNU_PrintString(JNIEnv *env, char *hdr, jstring string) |
|
1198 |
{ |
|
1199 |
if (string == NULL) { |
|
1200 |
fprintf(stderr, "%s: is NULL\n", hdr); |
|
1201 |
} else { |
|
1202 |
const char *stringPtr = JNU_GetStringPlatformChars(env, string, 0); |
|
1203 |
if (stringPtr == 0) |
|
1204 |
return; |
|
1205 |
fprintf(stderr, "%s: %s\n", hdr, stringPtr); |
|
1206 |
JNU_ReleaseStringPlatformChars(env, string, stringPtr); |
|
1207 |
} |
|
1208 |
} |
|
1209 |
||
1210 |
JNIEXPORT void JNICALL |
|
1211 |
JNU_PrintClass(JNIEnv *env, char* hdr, jobject object) |
|
1212 |
{ |
|
1213 |
if (object == NULL) { |
|
1214 |
fprintf(stderr, "%s: object is NULL\n", hdr); |
|
1215 |
return; |
|
1216 |
} else { |
|
1217 |
jclass cls = (*env)->GetObjectClass(env, object); |
|
1218 |
jstring clsName = JNU_ToString(env, cls); |
|
22653
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1219 |
if (clsName == NULL) { |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1220 |
JNU_PrintString(env, hdr, clsName); |
7a464b795af5
8030993: Check jdk/src/share/native/common/jni_util.c for JNI pending exceptions
rriggs
parents:
7668
diff
changeset
|
1221 |
} |
2 | 1222 |
(*env)->DeleteLocalRef(env, cls); |
1223 |
(*env)->DeleteLocalRef(env, clsName); |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
JNIEXPORT jstring JNICALL |
|
1228 |
JNU_ToString(JNIEnv *env, jobject object) |
|
1229 |
{ |
|
1230 |
if (object == NULL) { |
|
1231 |
return (*env)->NewStringUTF(env, "NULL"); |
|
1232 |
} else { |
|
1233 |
return (jstring)JNU_CallMethodByName(env, |
|
1234 |
NULL, |
|
1235 |
object, |
|
1236 |
"toString", |
|
1237 |
"()Ljava/lang/String;").l; |
|
1238 |
} |
|
1239 |
} |
|
1240 |
||
1241 |
JNIEXPORT jvalue JNICALL |
|
1242 |
JNU_GetFieldByName(JNIEnv *env, |
|
1243 |
jboolean *hasException, |
|
1244 |
jobject obj, |
|
1245 |
const char *name, |
|
1246 |
const char *signature) |
|
1247 |
{ |
|
1248 |
jclass cls; |
|
1249 |
jfieldID fid; |
|
1250 |
jvalue result; |
|
1251 |
||
1252 |
result.i = 0; |
|
1253 |
||
1254 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
1255 |
goto done2; |
|
1256 |
||
1257 |
cls = (*env)->GetObjectClass(env, obj); |
|
1258 |
fid = (*env)->GetFieldID(env, cls, name, signature); |
|
1259 |
if (fid == 0) |
|
1260 |
goto done1; |
|
1261 |
||
1262 |
switch (*signature) { |
|
1263 |
case '[': |
|
1264 |
case 'L': |
|
1265 |
result.l = (*env)->GetObjectField(env, obj, fid); |
|
1266 |
break; |
|
1267 |
case 'Z': |
|
1268 |
result.z = (*env)->GetBooleanField(env, obj, fid); |
|
1269 |
break; |
|
1270 |
case 'B': |
|
1271 |
result.b = (*env)->GetByteField(env, obj, fid); |
|
1272 |
break; |
|
1273 |
case 'C': |
|
1274 |
result.c = (*env)->GetCharField(env, obj, fid); |
|
1275 |
break; |
|
1276 |
case 'S': |
|
1277 |
result.s = (*env)->GetShortField(env, obj, fid); |
|
1278 |
break; |
|
1279 |
case 'I': |
|
1280 |
result.i = (*env)->GetIntField(env, obj, fid); |
|
1281 |
break; |
|
1282 |
case 'J': |
|
1283 |
result.j = (*env)->GetLongField(env, obj, fid); |
|
1284 |
break; |
|
1285 |
case 'F': |
|
1286 |
result.f = (*env)->GetFloatField(env, obj, fid); |
|
1287 |
break; |
|
1288 |
case 'D': |
|
1289 |
result.d = (*env)->GetDoubleField(env, obj, fid); |
|
1290 |
break; |
|
1291 |
||
1292 |
default: |
|
1293 |
(*env)->FatalError(env, "JNU_GetFieldByName: illegal signature"); |
|
1294 |
} |
|
1295 |
||
1296 |
done1: |
|
1297 |
(*env)->DeleteLocalRef(env, cls); |
|
1298 |
done2: |
|
1299 |
if (hasException) { |
|
1300 |
*hasException = (*env)->ExceptionCheck(env); |
|
1301 |
} |
|
1302 |
return result; |
|
1303 |
} |
|
1304 |
||
1305 |
JNIEXPORT void JNICALL |
|
1306 |
JNU_SetFieldByName(JNIEnv *env, |
|
1307 |
jboolean *hasException, |
|
1308 |
jobject obj, |
|
1309 |
const char *name, |
|
1310 |
const char *signature, |
|
1311 |
...) |
|
1312 |
{ |
|
1313 |
jclass cls; |
|
1314 |
jfieldID fid; |
|
1315 |
va_list args; |
|
1316 |
||
1317 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
1318 |
goto done2; |
|
1319 |
||
1320 |
cls = (*env)->GetObjectClass(env, obj); |
|
1321 |
fid = (*env)->GetFieldID(env, cls, name, signature); |
|
1322 |
if (fid == 0) |
|
1323 |
goto done1; |
|
1324 |
||
1325 |
va_start(args, signature); |
|
1326 |
switch (*signature) { |
|
1327 |
case '[': |
|
1328 |
case 'L': |
|
1329 |
(*env)->SetObjectField(env, obj, fid, va_arg(args, jobject)); |
|
1330 |
break; |
|
1331 |
case 'Z': |
|
1332 |
(*env)->SetBooleanField(env, obj, fid, (jboolean)va_arg(args, int)); |
|
1333 |
break; |
|
1334 |
case 'B': |
|
1335 |
(*env)->SetByteField(env, obj, fid, (jbyte)va_arg(args, int)); |
|
1336 |
break; |
|
1337 |
case 'C': |
|
1338 |
(*env)->SetCharField(env, obj, fid, (jchar)va_arg(args, int)); |
|
1339 |
break; |
|
1340 |
case 'S': |
|
1341 |
(*env)->SetShortField(env, obj, fid, (jshort)va_arg(args, int)); |
|
1342 |
break; |
|
1343 |
case 'I': |
|
1344 |
(*env)->SetIntField(env, obj, fid, va_arg(args, jint)); |
|
1345 |
break; |
|
1346 |
case 'J': |
|
1347 |
(*env)->SetLongField(env, obj, fid, va_arg(args, jlong)); |
|
1348 |
break; |
|
1349 |
case 'F': |
|
1350 |
(*env)->SetFloatField(env, obj, fid, (jfloat)va_arg(args, jdouble)); |
|
1351 |
break; |
|
1352 |
case 'D': |
|
1353 |
(*env)->SetDoubleField(env, obj, fid, va_arg(args, jdouble)); |
|
1354 |
break; |
|
1355 |
||
1356 |
default: |
|
1357 |
(*env)->FatalError(env, "JNU_SetFieldByName: illegal signature"); |
|
1358 |
} |
|
1359 |
va_end(args); |
|
1360 |
||
1361 |
done1: |
|
1362 |
(*env)->DeleteLocalRef(env, cls); |
|
1363 |
done2: |
|
1364 |
if (hasException) { |
|
1365 |
*hasException = (*env)->ExceptionCheck(env); |
|
1366 |
} |
|
1367 |
} |
|
1368 |
||
1369 |
JNIEXPORT jvalue JNICALL |
|
1370 |
JNU_GetStaticFieldByName(JNIEnv *env, |
|
1371 |
jboolean *hasException, |
|
1372 |
const char *classname, |
|
1373 |
const char *name, |
|
1374 |
const char *signature) |
|
1375 |
{ |
|
1376 |
jclass cls; |
|
1377 |
jfieldID fid; |
|
1378 |
jvalue result; |
|
1379 |
||
1380 |
result.i = 0; |
|
1381 |
||
1382 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
1383 |
goto done2; |
|
1384 |
||
1385 |
cls = (*env)->FindClass(env, classname); |
|
1386 |
if (cls == 0) |
|
1387 |
goto done2; |
|
1388 |
||
1389 |
fid = (*env)->GetStaticFieldID(env, cls, name, signature); |
|
1390 |
if (fid == 0) |
|
1391 |
goto done1; |
|
1392 |
||
1393 |
switch (*signature) { |
|
1394 |
case '[': |
|
1395 |
case 'L': |
|
1396 |
result.l = (*env)->GetStaticObjectField(env, cls, fid); |
|
1397 |
break; |
|
1398 |
case 'Z': |
|
1399 |
result.z = (*env)->GetStaticBooleanField(env, cls, fid); |
|
1400 |
break; |
|
1401 |
case 'B': |
|
1402 |
result.b = (*env)->GetStaticByteField(env, cls, fid); |
|
1403 |
break; |
|
1404 |
case 'C': |
|
1405 |
result.c = (*env)->GetStaticCharField(env, cls, fid); |
|
1406 |
break; |
|
1407 |
case 'S': |
|
1408 |
result.s = (*env)->GetStaticShortField(env, cls, fid); |
|
1409 |
break; |
|
1410 |
case 'I': |
|
1411 |
result.i = (*env)->GetStaticIntField(env, cls, fid); |
|
1412 |
break; |
|
1413 |
case 'J': |
|
1414 |
result.j = (*env)->GetStaticLongField(env, cls, fid); |
|
1415 |
break; |
|
1416 |
case 'F': |
|
1417 |
result.f = (*env)->GetStaticFloatField(env, cls, fid); |
|
1418 |
break; |
|
1419 |
case 'D': |
|
1420 |
result.d = (*env)->GetStaticDoubleField(env, cls, fid); |
|
1421 |
break; |
|
1422 |
||
1423 |
default: |
|
1424 |
(*env)->FatalError(env, "JNU_GetStaticFieldByName: illegal signature"); |
|
1425 |
} |
|
1426 |
||
1427 |
done1: |
|
1428 |
(*env)->DeleteLocalRef(env, cls); |
|
1429 |
done2: |
|
1430 |
if (hasException) { |
|
1431 |
*hasException = (*env)->ExceptionCheck(env); |
|
1432 |
} |
|
1433 |
return result; |
|
1434 |
} |
|
1435 |
||
1436 |
JNIEXPORT void JNICALL |
|
1437 |
JNU_SetStaticFieldByName(JNIEnv *env, |
|
1438 |
jboolean *hasException, |
|
1439 |
const char *classname, |
|
1440 |
const char *name, |
|
1441 |
const char *signature, |
|
1442 |
...) |
|
1443 |
{ |
|
1444 |
jclass cls; |
|
1445 |
jfieldID fid; |
|
1446 |
va_list args; |
|
1447 |
||
1448 |
if ((*env)->EnsureLocalCapacity(env, 3) < 0) |
|
1449 |
goto done2; |
|
1450 |
||
1451 |
cls = (*env)->FindClass(env, classname); |
|
1452 |
if (cls == 0) |
|
1453 |
goto done2; |
|
1454 |
||
1455 |
fid = (*env)->GetStaticFieldID(env, cls, name, signature); |
|
1456 |
if (fid == 0) |
|
1457 |
goto done1; |
|
1458 |
||
1459 |
va_start(args, signature); |
|
1460 |
switch (*signature) { |
|
1461 |
case '[': |
|
1462 |
case 'L': |
|
1463 |
(*env)->SetStaticObjectField(env, cls, fid, va_arg(args, jobject)); |
|
1464 |
break; |
|
1465 |
case 'Z': |
|
1466 |
(*env)->SetStaticBooleanField(env, cls, fid, (jboolean)va_arg(args, int)); |
|
1467 |
break; |
|
1468 |
case 'B': |
|
1469 |
(*env)->SetStaticByteField(env, cls, fid, (jbyte)va_arg(args, int)); |
|
1470 |
break; |
|
1471 |
case 'C': |
|
1472 |
(*env)->SetStaticCharField(env, cls, fid, (jchar)va_arg(args, int)); |
|
1473 |
break; |
|
1474 |
case 'S': |
|
1475 |
(*env)->SetStaticShortField(env, cls, fid, (jshort)va_arg(args, int)); |
|
1476 |
break; |
|
1477 |
case 'I': |
|
1478 |
(*env)->SetStaticIntField(env, cls, fid, va_arg(args, jint)); |
|
1479 |
break; |
|
1480 |
case 'J': |
|
1481 |
(*env)->SetStaticLongField(env, cls, fid, va_arg(args, jlong)); |
|
1482 |
break; |
|
1483 |
case 'F': |
|
1484 |
(*env)->SetStaticFloatField(env, cls, fid, (jfloat)va_arg(args, jdouble)); |
|
1485 |
break; |
|
1486 |
case 'D': |
|
1487 |
(*env)->SetStaticDoubleField(env, cls, fid, va_arg(args, jdouble)); |
|
1488 |
break; |
|
1489 |
||
1490 |
default: |
|
1491 |
(*env)->FatalError(env, "JNU_SetStaticFieldByName: illegal signature"); |
|
1492 |
} |
|
1493 |
va_end(args); |
|
1494 |
||
1495 |
done1: |
|
1496 |
(*env)->DeleteLocalRef(env, cls); |
|
1497 |
done2: |
|
1498 |
if (hasException) { |
|
1499 |
*hasException = (*env)->ExceptionCheck(env); |
|
1500 |
} |
|
1501 |
} |