Mercurial > hg > graal-compiler
annotate src/share/vm/prims/jni.cpp @ 878:abe076e3636f
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
Summary: JVM_FindClassFromBootLoader returns null if class not found
Reviewed-by: acorn, alanb, dholmes
author | mchung |
---|---|
date | Mon, 27 Jul 2009 09:06:22 -0700 |
parents | 715dceaa89b7 |
children | ad6585fd4087 |
rev | line source |
---|---|
0 | 1 /* |
579 | 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_jni.cpp.incl" | |
27 | |
28 static jint CurrentVersion = JNI_VERSION_1_6; | |
29 | |
30 | |
31 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace | |
32 // '-return' probe regardless of the return path is taken out of the function. | |
33 // Methods that have multiple return paths use this to avoid having to | |
34 // instrument each return path. Methods that use CHECK or THROW must use this | |
35 // since those macros can cause an immedate uninstrumented return. | |
36 // | |
37 // In order to get the return value, a reference to the variable containing | |
38 // the return value must be passed to the contructor of the object, and | |
39 // the return value must be set before return (since the mark object has | |
40 // a reference to it). | |
41 // | |
42 // Example: | |
43 // DT_RETURN_MARK_DECL(SomeFunc, int); | |
44 // JNI_ENTRY(int, SomeFunc, ...) | |
45 // int return_value = 0; | |
46 // DT_RETURN_MARK(SomeFunc, int, (const int&)return_value); | |
47 // foo(CHECK_0) | |
48 // return_value = 5; | |
49 // return return_value; | |
50 // JNI_END | |
51 #define DT_RETURN_MARK_DECL(name, type) \ | |
52 HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type); \ | |
53 DTRACE_ONLY( \ | |
54 class DTraceReturnProbeMark_##name { \ | |
55 public: \ | |
56 const type& _ret_ref; \ | |
57 DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ | |
58 ~DTraceReturnProbeMark_##name() { \ | |
59 HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref); \ | |
60 } \ | |
61 } \ | |
62 ) | |
63 // Void functions are simpler since there's no return value | |
64 #define DT_VOID_RETURN_MARK_DECL(name) \ | |
65 HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return); \ | |
66 DTRACE_ONLY( \ | |
67 class DTraceReturnProbeMark_##name { \ | |
68 public: \ | |
69 ~DTraceReturnProbeMark_##name() { \ | |
70 HS_DTRACE_PROBE0(hotspot_jni, name##__return); \ | |
71 } \ | |
72 } \ | |
73 ) | |
74 | |
75 | |
76 // Place these macros in the function to mark the return. Non-void | |
77 // functions need the type and address of the return value. | |
78 #define DT_RETURN_MARK(name, type, ref) \ | |
79 DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) ) | |
80 #define DT_VOID_RETURN_MARK(name) \ | |
81 DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark ) | |
82 | |
83 | |
84 // Use these to select distinct code for floating-point vs. non-floating point | |
85 // situations. Used from within common macros where we need slightly | |
86 // different behavior for Float/Double | |
87 #define FP_SELECT_Boolean(intcode, fpcode) intcode | |
88 #define FP_SELECT_Byte(intcode, fpcode) intcode | |
89 #define FP_SELECT_Char(intcode, fpcode) intcode | |
90 #define FP_SELECT_Short(intcode, fpcode) intcode | |
91 #define FP_SELECT_Object(intcode, fpcode) intcode | |
92 #define FP_SELECT_Int(intcode, fpcode) intcode | |
93 #define FP_SELECT_Long(intcode, fpcode) intcode | |
94 #define FP_SELECT_Float(intcode, fpcode) fpcode | |
95 #define FP_SELECT_Double(intcode, fpcode) fpcode | |
96 #define FP_SELECT(TypeName, intcode, fpcode) \ | |
97 FP_SELECT_##TypeName(intcode, fpcode) | |
98 | |
99 #define COMMA , | |
100 | |
101 // Choose DT_RETURN_MARK macros based on the type: float/double -> void | |
102 // (dtrace doesn't do FP yet) | |
103 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \ | |
104 FP_SELECT(TypeName, \ | |
105 DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) ) | |
106 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \ | |
107 FP_SELECT(TypeName, \ | |
108 DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) ) | |
109 | |
110 | |
111 // out-of-line helpers for class jfieldIDWorkaround: | |
112 | |
113 bool jfieldIDWorkaround::is_valid_jfieldID(klassOop k, jfieldID id) { | |
114 if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) { | |
115 uintptr_t as_uint = (uintptr_t) id; | |
116 intptr_t offset = raw_instance_offset(id); | |
117 if (is_checked_jfieldID(id)) { | |
118 if (!klass_hash_ok(k, id)) { | |
119 return false; | |
120 } | |
121 } | |
122 return instanceKlass::cast(k)->contains_field_offset(offset); | |
123 } else { | |
124 JNIid* result = (JNIid*) id; | |
125 #ifdef ASSERT | |
126 return result != NULL && result->is_static_field_id(); | |
127 #else | |
128 return result != NULL; | |
129 #endif | |
130 } | |
131 } | |
132 | |
133 | |
134 intptr_t jfieldIDWorkaround::encode_klass_hash(klassOop k, intptr_t offset) { | |
135 if (offset <= small_offset_mask) { | |
136 klassOop field_klass = k; | |
137 klassOop super_klass = Klass::cast(field_klass)->super(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
138 // With compressed oops the most super class with nonstatic fields would |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
139 // be the owner of fields embedded in the header. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
140 while (instanceKlass::cast(super_klass)->has_nonstatic_fields() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
141 instanceKlass::cast(super_klass)->contains_field_offset(offset)) { |
0 | 142 field_klass = super_klass; // super contains the field also |
143 super_klass = Klass::cast(field_klass)->super(); | |
144 } | |
145 debug_only(No_Safepoint_Verifier nosafepoint;) | |
146 uintptr_t klass_hash = field_klass->identity_hash(); | |
147 return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place; | |
148 } else { | |
149 #if 0 | |
150 #ifndef PRODUCT | |
151 { | |
152 ResourceMark rm; | |
153 warning("VerifyJNIFields: long offset %d in %s", offset, Klass::cast(k)->external_name()); | |
154 } | |
155 #endif | |
156 #endif | |
157 return 0; | |
158 } | |
159 } | |
160 | |
161 bool jfieldIDWorkaround::klass_hash_ok(klassOop k, jfieldID id) { | |
162 uintptr_t as_uint = (uintptr_t) id; | |
163 intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask; | |
164 do { | |
165 debug_only(No_Safepoint_Verifier nosafepoint;) | |
166 // Could use a non-blocking query for identity_hash here... | |
167 if ((k->identity_hash() & klass_mask) == klass_hash) | |
168 return true; | |
169 k = Klass::cast(k)->super(); | |
170 } while (k != NULL); | |
171 return false; | |
172 } | |
173 | |
174 void jfieldIDWorkaround::verify_instance_jfieldID(klassOop k, jfieldID id) { | |
175 guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" ); | |
176 uintptr_t as_uint = (uintptr_t) id; | |
177 intptr_t offset = raw_instance_offset(id); | |
178 if (VerifyJNIFields) { | |
179 if (is_checked_jfieldID(id)) { | |
180 guarantee(klass_hash_ok(k, id), | |
181 "Bug in native code: jfieldID class must match object"); | |
182 } else { | |
183 #if 0 | |
184 #ifndef PRODUCT | |
185 if (Verbose) { | |
186 ResourceMark rm; | |
187 warning("VerifyJNIFields: unverified offset %d for %s", offset, Klass::cast(k)->external_name()); | |
188 } | |
189 #endif | |
190 #endif | |
191 } | |
192 } | |
193 guarantee(instanceKlass::cast(k)->contains_field_offset(offset), | |
194 "Bug in native code: jfieldID offset must address interior of object"); | |
195 } | |
196 | |
197 // Pick a reasonable higher bound for local capacity requested | |
198 // for EnsureLocalCapacity and PushLocalFrame. We don't want it too | |
199 // high because a test (or very unusual application) may try to allocate | |
200 // that many handles and run out of swap space. An implementation is | |
201 // permitted to allocate more handles than the ensured capacity, so this | |
202 // value is set high enough to prevent compatibility problems. | |
203 const int MAX_REASONABLE_LOCAL_CAPACITY = 4*K; | |
204 | |
205 | |
206 // Wrapper to trace JNI functions | |
207 | |
208 #ifdef ASSERT | |
209 Histogram* JNIHistogram; | |
210 static volatile jint JNIHistogram_lock = 0; | |
211 | |
212 class JNITraceWrapper : public StackObj { | |
213 public: | |
214 JNITraceWrapper(const char* format, ...) { | |
215 if (TraceJNICalls) { | |
216 va_list ap; | |
217 va_start(ap, format); | |
218 tty->print("JNI "); | |
219 tty->vprint_cr(format, ap); | |
220 va_end(ap); | |
221 } | |
222 } | |
223 }; | |
224 | |
225 class JNIHistogramElement : public HistogramElement { | |
226 public: | |
227 JNIHistogramElement(const char* name); | |
228 }; | |
229 | |
230 JNIHistogramElement::JNIHistogramElement(const char* elementName) { | |
231 _name = elementName; | |
232 uintx count = 0; | |
233 | |
234 while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) { | |
235 while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) { | |
236 count +=1; | |
237 if ( (WarnOnStalledSpinLock > 0) | |
238 && (count % WarnOnStalledSpinLock == 0)) { | |
239 warning("JNIHistogram_lock seems to be stalled"); | |
240 } | |
241 } | |
242 } | |
243 | |
244 | |
245 if(JNIHistogram == NULL) | |
246 JNIHistogram = new Histogram("JNI Call Counts",100); | |
247 | |
248 JNIHistogram->add_element(this); | |
249 Atomic::dec(&JNIHistogram_lock); | |
250 } | |
251 | |
252 #define JNICountWrapper(arg) \ | |
253 static JNIHistogramElement* e = new JNIHistogramElement(arg); \ | |
254 /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \ | |
255 if (e != NULL) e->increment_count() | |
256 #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg) | |
257 #else | |
258 #define JNIWrapper(arg) | |
259 #endif | |
260 | |
261 | |
262 // Implementation of JNI entries | |
263 | |
264 DT_RETURN_MARK_DECL(DefineClass, jclass); | |
265 | |
266 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef, | |
267 const jbyte *buf, jsize bufLen)) | |
268 JNIWrapper("DefineClass"); | |
269 | |
270 DTRACE_PROBE5(hotspot_jni, DefineClass__entry, | |
271 env, name, loaderRef, buf, bufLen); | |
272 jclass cls = NULL; | |
273 DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); | |
274 | |
275 // Since exceptions can be thrown, class initialization can take place | |
276 // if name is NULL no check for class name in .class stream has to be made. | |
277 symbolHandle class_name; | |
278 if (name != NULL) { | |
279 const int str_len = (int)strlen(name); | |
280 if (str_len > symbolOopDesc::max_length()) { | |
281 // It's impossible to create this class; the name cannot fit | |
282 // into the constant pool. | |
283 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); | |
284 } | |
285 class_name = oopFactory::new_symbol_handle(name, str_len, CHECK_NULL); | |
286 } | |
287 | |
288 ResourceMark rm(THREAD); | |
289 ClassFileStream st((u1*) buf, bufLen, NULL); | |
290 Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); | |
291 | |
292 if (UsePerfData && !class_loader.is_null()) { | |
293 // check whether the current caller thread holds the lock or not. | |
294 // If not, increment the corresponding counter | |
295 if (ObjectSynchronizer:: | |
296 query_lock_ownership((JavaThread*)THREAD, class_loader) != | |
297 ObjectSynchronizer::owner_self) { | |
298 ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc(); | |
299 } | |
300 } | |
301 klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader, | |
302 Handle(), &st, CHECK_NULL); | |
303 | |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
304 if (TraceClassResolution && k != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
305 trace_class_resolution(k); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
306 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
307 |
0 | 308 cls = (jclass)JNIHandles::make_local( |
309 env, Klass::cast(k)->java_mirror()); | |
310 return cls; | |
311 JNI_END | |
312 | |
313 | |
314 | |
315 static bool first_time_FindClass = true; | |
316 | |
317 DT_RETURN_MARK_DECL(FindClass, jclass); | |
318 | |
319 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name)) | |
320 JNIWrapper("FindClass"); | |
321 DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name); | |
322 | |
323 jclass result = NULL; | |
324 DT_RETURN_MARK(FindClass, jclass, (const jclass&)result); | |
325 | |
326 // Remember if we are the first invocation of jni_FindClass | |
327 bool first_time = first_time_FindClass; | |
328 first_time_FindClass = false; | |
329 | |
330 // Sanity check the name: it cannot be null or larger than the maximum size | |
331 // name we can fit in the constant pool. | |
332 if (name == NULL || (int)strlen(name) > symbolOopDesc::max_length()) { | |
333 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); | |
334 } | |
335 | |
336 //%note jni_3 | |
337 Handle loader; | |
338 Handle protection_domain; | |
339 // Find calling class | |
340 instanceKlassHandle k (THREAD, thread->security_get_caller_class(0)); | |
341 if (k.not_null()) { | |
342 loader = Handle(THREAD, k->class_loader()); | |
343 // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed | |
344 // in the correct class context. | |
345 if (loader.is_null() && | |
346 k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) { | |
347 JavaValue result(T_OBJECT); | |
348 JavaCalls::call_static(&result, k, | |
349 vmSymbolHandles::getFromClass_name(), | |
350 vmSymbolHandles::void_class_signature(), | |
351 thread); | |
352 if (HAS_PENDING_EXCEPTION) { | |
353 Handle ex(thread, thread->pending_exception()); | |
354 CLEAR_PENDING_EXCEPTION; | |
355 THROW_HANDLE_0(ex); | |
356 } | |
357 oop mirror = (oop) result.get_jobject(); | |
358 loader = Handle(THREAD, | |
359 instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->class_loader()); | |
360 protection_domain = Handle(THREAD, | |
361 instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->protection_domain()); | |
362 } | |
363 } else { | |
364 // We call ClassLoader.getSystemClassLoader to obtain the system class loader. | |
365 loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
366 } | |
367 | |
368 symbolHandle sym = oopFactory::new_symbol_handle(name, CHECK_NULL); | |
369 result = find_class_from_class_loader(env, sym, true, loader, | |
370 protection_domain, true, thread); | |
371 | |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
372 if (TraceClassResolution && result != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
373 trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result))); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
374 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
375 |
0 | 376 // If we were the first invocation of jni_FindClass, we enable compilation again |
377 // rather than just allowing invocation counter to overflow and decay. | |
378 // Controlled by flag DelayCompilationDuringStartup. | |
379 if (first_time && !CompileTheWorld) | |
380 CompilationPolicy::completed_vm_startup(); | |
381 | |
382 return result; | |
383 JNI_END | |
384 | |
385 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID); | |
386 | |
387 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method)) | |
388 JNIWrapper("FromReflectedMethod"); | |
389 DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method); | |
390 jmethodID ret = NULL; | |
391 DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret); | |
392 | |
393 // method is a handle to a java.lang.reflect.Method object | |
394 oop reflected = JNIHandles::resolve_non_null(method); | |
395 oop mirror = NULL; | |
396 int slot = 0; | |
397 | |
398 if (reflected->klass() == SystemDictionary::reflect_constructor_klass()) { | |
399 mirror = java_lang_reflect_Constructor::clazz(reflected); | |
400 slot = java_lang_reflect_Constructor::slot(reflected); | |
401 } else { | |
402 assert(reflected->klass() == SystemDictionary::reflect_method_klass(), "wrong type"); | |
403 mirror = java_lang_reflect_Method::clazz(reflected); | |
404 slot = java_lang_reflect_Method::slot(reflected); | |
405 } | |
406 klassOop k = java_lang_Class::as_klassOop(mirror); | |
407 | |
408 KlassHandle k1(THREAD, k); | |
409 // Make sure class is initialized before handing id's out to methods | |
410 Klass::cast(k1())->initialize(CHECK_NULL); | |
411 methodOop m = instanceKlass::cast(k1())->method_with_idnum(slot); | |
412 ret = m==NULL? NULL : m->jmethod_id(); // return NULL if reflected method deleted | |
413 return ret; | |
414 JNI_END | |
415 | |
416 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID); | |
417 | |
418 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field)) | |
419 JNIWrapper("FromReflectedField"); | |
420 DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field); | |
421 jfieldID ret = NULL; | |
422 DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret); | |
423 | |
424 // field is a handle to a java.lang.reflect.Field object | |
425 oop reflected = JNIHandles::resolve_non_null(field); | |
426 oop mirror = java_lang_reflect_Field::clazz(reflected); | |
427 klassOop k = java_lang_Class::as_klassOop(mirror); | |
428 int slot = java_lang_reflect_Field::slot(reflected); | |
429 int modifiers = java_lang_reflect_Field::modifiers(reflected); | |
430 | |
431 KlassHandle k1(THREAD, k); | |
432 // Make sure class is initialized before handing id's out to fields | |
433 Klass::cast(k1())->initialize(CHECK_NULL); | |
434 | |
435 // First check if this is a static field | |
436 if (modifiers & JVM_ACC_STATIC) { | |
437 intptr_t offset = instanceKlass::cast(k1())->offset_from_fields( slot ); | |
438 JNIid* id = instanceKlass::cast(k1())->jni_id_for(offset); | |
439 assert(id != NULL, "corrupt Field object"); | |
440 debug_only(id->set_is_static_field_id();) | |
441 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop | |
442 ret = jfieldIDWorkaround::to_static_jfieldID(id); | |
443 return ret; | |
444 } | |
445 | |
446 // The slot is the index of the field description in the field-array | |
447 // The jfieldID is the offset of the field within the object | |
448 // It may also have hash bits for k, if VerifyJNIFields is turned on. | |
449 intptr_t offset = instanceKlass::cast(k1())->offset_from_fields( slot ); | |
450 assert(instanceKlass::cast(k1())->contains_field_offset(offset), "stay within object"); | |
451 ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset); | |
452 return ret; | |
453 JNI_END | |
454 | |
455 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject); | |
456 | |
457 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic)) | |
458 JNIWrapper("ToReflectedMethod"); | |
459 DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic); | |
460 jobject ret = NULL; | |
461 DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret); | |
462 | |
463 methodHandle m (THREAD, JNIHandles::resolve_jmethod_id(method_id)); | |
464 assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match"); | |
465 oop reflection_method; | |
466 if (m->is_initializer()) { | |
467 reflection_method = Reflection::new_constructor(m, CHECK_NULL); | |
468 } else { | |
469 reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL); | |
470 } | |
471 ret = JNIHandles::make_local(env, reflection_method); | |
472 return ret; | |
473 JNI_END | |
474 | |
475 DT_RETURN_MARK_DECL(GetSuperclass, jclass); | |
476 | |
477 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub)) | |
478 JNIWrapper("GetSuperclass"); | |
479 DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub); | |
480 jclass obj = NULL; | |
481 DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj); | |
482 | |
483 oop mirror = JNIHandles::resolve_non_null(sub); | |
484 // primitive classes return NULL | |
485 if (java_lang_Class::is_primitive(mirror)) return NULL; | |
486 | |
487 // Rules of Class.getSuperClass as implemented by KLass::java_super: | |
488 // arrays return Object | |
489 // interfaces return NULL | |
490 // proper classes return Klass::super() | |
491 klassOop k = java_lang_Class::as_klassOop(mirror); | |
492 if (Klass::cast(k)->is_interface()) return NULL; | |
493 | |
494 // return mirror for superclass | |
495 klassOop super = Klass::cast(k)->java_super(); | |
496 // super2 is the value computed by the compiler's getSuperClass intrinsic: | |
497 debug_only(klassOop super2 = ( Klass::cast(k)->oop_is_javaArray() | |
498 ? SystemDictionary::object_klass() | |
499 : Klass::cast(k)->super() ) ); | |
500 assert(super == super2, | |
501 "java_super computation depends on interface, array, other super"); | |
502 obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(Klass::cast(super)->java_mirror()); | |
503 return obj; | |
504 JNI_END | |
505 | |
506 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super)) | |
507 JNIWrapper("IsSubclassOf"); | |
508 DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super); | |
509 oop sub_mirror = JNIHandles::resolve_non_null(sub); | |
510 oop super_mirror = JNIHandles::resolve_non_null(super); | |
511 if (java_lang_Class::is_primitive(sub_mirror) || | |
512 java_lang_Class::is_primitive(super_mirror)) { | |
513 jboolean ret = (sub_mirror == super_mirror); | |
514 DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); | |
515 return ret; | |
516 } | |
517 klassOop sub_klass = java_lang_Class::as_klassOop(sub_mirror); | |
518 klassOop super_klass = java_lang_Class::as_klassOop(super_mirror); | |
519 assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom"); | |
520 jboolean ret = Klass::cast(sub_klass)->is_subtype_of(super_klass) ? | |
521 JNI_TRUE : JNI_FALSE; | |
522 DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); | |
523 return ret; | |
524 JNI_END | |
525 | |
526 DT_RETURN_MARK_DECL(Throw, jint); | |
527 | |
528 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj)) | |
529 JNIWrapper("Throw"); | |
530 DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj); | |
531 jint ret = JNI_OK; | |
532 DT_RETURN_MARK(Throw, jint, (const jint&)ret); | |
533 | |
534 THROW_OOP_(JNIHandles::resolve(obj), JNI_OK); | |
535 ShouldNotReachHere(); | |
536 JNI_END | |
537 | |
538 DT_RETURN_MARK_DECL(ThrowNew, jint); | |
539 | |
540 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message)) | |
541 JNIWrapper("ThrowNew"); | |
542 DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message); | |
543 jint ret = JNI_OK; | |
544 DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret); | |
545 | |
546 instanceKlass* k = instanceKlass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
547 symbolHandle name = symbolHandle(THREAD, k->name()); | |
548 Handle class_loader (THREAD, k->class_loader()); | |
549 Handle protection_domain (THREAD, k->protection_domain()); | |
550 THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK); | |
551 ShouldNotReachHere(); | |
552 JNI_END | |
553 | |
554 | |
555 // JNI functions only transform a pending async exception to a synchronous | |
556 // exception in ExceptionOccurred and ExceptionCheck calls, since | |
557 // delivering an async exception in other places won't change the native | |
558 // code's control flow and would be harmful when native code further calls | |
559 // JNI functions with a pending exception. Async exception is also checked | |
560 // during the call, so ExceptionOccurred/ExceptionCheck won't return | |
561 // false but deliver the async exception at the very end during | |
562 // state transition. | |
563 | |
564 static void jni_check_async_exceptions(JavaThread *thread) { | |
565 assert(thread == Thread::current(), "must be itself"); | |
566 thread->check_and_handle_async_exceptions(); | |
567 } | |
568 | |
569 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env)) | |
570 JNIWrapper("ExceptionOccurred"); | |
571 DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env); | |
572 jni_check_async_exceptions(thread); | |
573 oop exception = thread->pending_exception(); | |
574 jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception); | |
575 DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret); | |
576 return ret; | |
577 JNI_END | |
578 | |
579 | |
580 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env)) | |
581 JNIWrapper("ExceptionDescribe"); | |
582 DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env); | |
583 if (thread->has_pending_exception()) { | |
584 Handle ex(thread, thread->pending_exception()); | |
585 thread->clear_pending_exception(); | |
586 if (ex->is_a(SystemDictionary::threaddeath_klass())) { | |
587 // Don't print anything if we are being killed. | |
588 } else { | |
589 jio_fprintf(defaultStream::error_stream(), "Exception "); | |
590 if (thread != NULL && thread->threadObj() != NULL) { | |
591 ResourceMark rm(THREAD); | |
592 jio_fprintf(defaultStream::error_stream(), | |
593 "in thread \"%s\" ", thread->get_thread_name()); | |
594 } | |
595 if (ex->is_a(SystemDictionary::throwable_klass())) { | |
596 JavaValue result(T_VOID); | |
597 JavaCalls::call_virtual(&result, | |
598 ex, | |
599 KlassHandle(THREAD, | |
600 SystemDictionary::throwable_klass()), | |
601 vmSymbolHandles::printStackTrace_name(), | |
602 vmSymbolHandles::void_method_signature(), | |
603 THREAD); | |
604 // If an exception is thrown in the call it gets thrown away. Not much | |
605 // we can do with it. The native code that calls this, does not check | |
606 // for the exception - hence, it might still be in the thread when DestroyVM gets | |
607 // called, potentially causing a few asserts to trigger - since no pending exception | |
608 // is expected. | |
609 CLEAR_PENDING_EXCEPTION; | |
610 } else { | |
611 ResourceMark rm(THREAD); | |
612 jio_fprintf(defaultStream::error_stream(), | |
613 ". Uncaught exception of type %s.", | |
614 Klass::cast(ex->klass())->external_name()); | |
615 } | |
616 } | |
617 } | |
618 DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return); | |
619 JNI_END | |
620 | |
621 | |
622 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env)) | |
623 JNIWrapper("ExceptionClear"); | |
624 DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env); | |
625 | |
626 // The jni code might be using this API to clear java thrown exception. | |
627 // So just mark jvmti thread exception state as exception caught. | |
628 JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state(); | |
629 if (state != NULL && state->is_exception_detected()) { | |
630 state->set_exception_caught(); | |
631 } | |
632 thread->clear_pending_exception(); | |
633 DTRACE_PROBE(hotspot_jni, ExceptionClear__return); | |
634 JNI_END | |
635 | |
636 | |
637 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg)) | |
638 JNIWrapper("FatalError"); | |
639 DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg); | |
640 tty->print_cr("FATAL ERROR in native method: %s", msg); | |
641 thread->print_stack(); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
113
diff
changeset
|
642 os::abort(); // Dump core and abort |
0 | 643 JNI_END |
644 | |
645 | |
646 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity)) | |
647 JNIWrapper("PushLocalFrame"); | |
648 DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity); | |
649 //%note jni_11 | |
650 if (capacity < 0 && capacity > MAX_REASONABLE_LOCAL_CAPACITY) { | |
651 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR); | |
652 return JNI_ERR; | |
653 } | |
654 JNIHandleBlock* old_handles = thread->active_handles(); | |
655 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread); | |
656 assert(new_handles != NULL, "should not be NULL"); | |
657 new_handles->set_pop_frame_link(old_handles); | |
658 thread->set_active_handles(new_handles); | |
659 jint ret = JNI_OK; | |
660 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret); | |
661 return ret; | |
662 JNI_END | |
663 | |
664 | |
665 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result)) | |
666 JNIWrapper("PopLocalFrame"); | |
667 DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result); | |
668 //%note jni_11 | |
669 Handle result_handle(thread, JNIHandles::resolve(result)); | |
670 JNIHandleBlock* old_handles = thread->active_handles(); | |
671 JNIHandleBlock* new_handles = old_handles->pop_frame_link(); | |
672 if (new_handles != NULL) { | |
673 // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL. | |
674 // This way code will still work if PopLocalFrame is called without a corresponding | |
675 // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise | |
676 // the release_block call will release the blocks. | |
677 thread->set_active_handles(new_handles); | |
678 old_handles->set_pop_frame_link(NULL); // clear link we won't release new_handles below | |
679 JNIHandleBlock::release_block(old_handles, thread); // may block | |
680 result = JNIHandles::make_local(thread, result_handle()); | |
681 } | |
682 DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result); | |
683 return result; | |
684 JNI_END | |
685 | |
686 | |
687 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref)) | |
688 JNIWrapper("NewGlobalRef"); | |
689 DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref); | |
690 Handle ref_handle(thread, JNIHandles::resolve(ref)); | |
691 jobject ret = JNIHandles::make_global(ref_handle); | |
692 DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret); | |
693 return ret; | |
694 JNI_END | |
695 | |
696 // Must be JNI_ENTRY (with HandleMark) | |
697 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref)) | |
698 JNIWrapper("DeleteGlobalRef"); | |
699 DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref); | |
700 JNIHandles::destroy_global(ref); | |
701 DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return); | |
702 JNI_END | |
703 | |
704 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj)) | |
705 JNIWrapper("DeleteLocalRef"); | |
706 DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj); | |
707 JNIHandles::destroy_local(obj); | |
708 DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return); | |
709 JNI_END | |
710 | |
711 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2)) | |
712 JNIWrapper("IsSameObject"); | |
713 DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2); | |
714 oop a = JNIHandles::resolve(r1); | |
715 oop b = JNIHandles::resolve(r2); | |
716 jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE; | |
717 DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret); | |
718 return ret; | |
719 JNI_END | |
720 | |
721 | |
722 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref)) | |
723 JNIWrapper("NewLocalRef"); | |
724 DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref); | |
725 jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref)); | |
726 DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret); | |
727 return ret; | |
728 JNI_END | |
729 | |
730 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity)) | |
731 JNIWrapper("EnsureLocalCapacity"); | |
732 DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity); | |
733 jint ret; | |
734 if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) { | |
735 ret = JNI_OK; | |
736 } else { | |
737 ret = JNI_ERR; | |
738 } | |
739 DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret); | |
740 return ret; | |
741 JNI_END | |
742 | |
743 // Return the Handle Type | |
744 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj)) | |
745 JNIWrapper("GetObjectRefType"); | |
746 DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj); | |
747 jobjectRefType ret; | |
748 if (JNIHandles::is_local_handle(thread, obj) || | |
749 JNIHandles::is_frame_handle(thread, obj)) | |
750 ret = JNILocalRefType; | |
751 else if (JNIHandles::is_global_handle(obj)) | |
752 ret = JNIGlobalRefType; | |
753 else if (JNIHandles::is_weak_global_handle(obj)) | |
754 ret = JNIWeakGlobalRefType; | |
755 else | |
756 ret = JNIInvalidRefType; | |
757 DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret); | |
758 return ret; | |
759 JNI_END | |
760 | |
761 | |
762 class JNI_ArgumentPusher : public SignatureIterator { | |
763 protected: | |
764 JavaCallArguments* _arguments; | |
765 | |
766 virtual void get_bool () = 0; | |
767 virtual void get_char () = 0; | |
768 virtual void get_short () = 0; | |
769 virtual void get_byte () = 0; | |
770 virtual void get_int () = 0; | |
771 virtual void get_long () = 0; | |
772 virtual void get_float () = 0; | |
773 virtual void get_double () = 0; | |
774 virtual void get_object () = 0; | |
775 | |
776 JNI_ArgumentPusher(Thread *thread, symbolOop signature) | |
777 : SignatureIterator(thread, signature) { | |
778 this->_return_type = T_ILLEGAL; | |
779 _arguments = NULL; | |
780 } | |
781 | |
782 public: | |
783 virtual void iterate( uint64_t fingerprint ) = 0; | |
784 | |
785 void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; } | |
786 | |
787 inline void do_bool() { if (!is_return_type()) get_bool(); } | |
788 inline void do_char() { if (!is_return_type()) get_char(); } | |
789 inline void do_short() { if (!is_return_type()) get_short(); } | |
790 inline void do_byte() { if (!is_return_type()) get_byte(); } | |
791 inline void do_int() { if (!is_return_type()) get_int(); } | |
792 inline void do_long() { if (!is_return_type()) get_long(); } | |
793 inline void do_float() { if (!is_return_type()) get_float(); } | |
794 inline void do_double() { if (!is_return_type()) get_double(); } | |
795 inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); } | |
796 inline void do_array(int begin, int end) { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array | |
797 inline void do_void() { } | |
798 | |
799 JavaCallArguments* arguments() { return _arguments; } | |
800 void push_receiver(Handle h) { _arguments->push_oop(h); } | |
801 }; | |
802 | |
803 | |
804 class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher { | |
805 protected: | |
806 va_list _ap; | |
807 | |
808 inline void get_bool() { _arguments->push_int(va_arg(_ap, jint)); } // bool is coerced to int when using va_arg | |
809 inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg | |
810 inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg | |
811 inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg | |
812 inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); } | |
813 | |
814 // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests | |
815 | |
816 inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); } | |
817 inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg | |
818 inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); } | |
819 inline void get_object() { jobject l = va_arg(_ap, jobject); | |
820 _arguments->push_oop(Handle((oop *)l, false)); } | |
821 | |
822 inline void set_ap(va_list rap) { | |
823 #ifdef va_copy | |
824 va_copy(_ap, rap); | |
825 #elif defined (__va_copy) | |
826 __va_copy(_ap, rap); | |
827 #else | |
828 _ap = rap; | |
829 #endif | |
830 } | |
831 | |
832 public: | |
833 JNI_ArgumentPusherVaArg(Thread *thread, symbolOop signature, va_list rap) | |
834 : JNI_ArgumentPusher(thread, signature) { | |
835 set_ap(rap); | |
836 } | |
837 JNI_ArgumentPusherVaArg(Thread *thread, jmethodID method_id, va_list rap) | |
838 : JNI_ArgumentPusher(thread, JNIHandles::resolve_jmethod_id(method_id)->signature()) { | |
839 set_ap(rap); | |
840 } | |
841 | |
842 // Optimized path if we have the bitvector form of signature | |
843 void iterate( uint64_t fingerprint ) { | |
844 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments | |
845 else { | |
846 _return_type = (BasicType)((fingerprint >> static_feature_size) & | |
847 result_feature_mask); | |
848 | |
849 assert(fingerprint, "Fingerprint should not be 0"); | |
850 fingerprint = fingerprint >> (static_feature_size + result_feature_size); | |
851 while ( 1 ) { | |
852 switch ( fingerprint & parameter_feature_mask ) { | |
853 case bool_parm: | |
854 case char_parm: | |
855 case short_parm: | |
856 case byte_parm: | |
857 case int_parm: | |
858 get_int(); | |
859 break; | |
860 case obj_parm: | |
861 get_object(); | |
862 break; | |
863 case long_parm: | |
864 get_long(); | |
865 break; | |
866 case float_parm: | |
867 get_float(); | |
868 break; | |
869 case double_parm: | |
870 get_double(); | |
871 break; | |
872 case done_parm: | |
873 return; | |
874 break; | |
875 default: | |
876 ShouldNotReachHere(); | |
877 break; | |
878 } | |
879 fingerprint >>= parameter_feature_size; | |
880 } | |
881 } | |
882 } | |
883 }; | |
884 | |
885 | |
886 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher { | |
887 protected: | |
888 const jvalue *_ap; | |
889 | |
890 inline void get_bool() { _arguments->push_int((jint)(_ap++)->z); } | |
891 inline void get_char() { _arguments->push_int((jint)(_ap++)->c); } | |
892 inline void get_short() { _arguments->push_int((jint)(_ap++)->s); } | |
893 inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); } | |
894 inline void get_int() { _arguments->push_int((jint)(_ap++)->i); } | |
895 | |
896 inline void get_long() { _arguments->push_long((_ap++)->j); } | |
897 inline void get_float() { _arguments->push_float((_ap++)->f); } | |
898 inline void get_double() { _arguments->push_double((_ap++)->d);} | |
899 inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); } | |
900 | |
901 inline void set_ap(const jvalue *rap) { _ap = rap; } | |
902 | |
903 public: | |
904 JNI_ArgumentPusherArray(Thread *thread, symbolOop signature, const jvalue *rap) | |
905 : JNI_ArgumentPusher(thread, signature) { | |
906 set_ap(rap); | |
907 } | |
908 JNI_ArgumentPusherArray(Thread *thread, jmethodID method_id, const jvalue *rap) | |
909 : JNI_ArgumentPusher(thread, JNIHandles::resolve_jmethod_id(method_id)->signature()) { | |
910 set_ap(rap); | |
911 } | |
912 | |
913 // Optimized path if we have the bitvector form of signature | |
914 void iterate( uint64_t fingerprint ) { | |
915 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments | |
916 else { | |
917 _return_type = (BasicType)((fingerprint >> static_feature_size) & | |
918 result_feature_mask); | |
919 assert(fingerprint, "Fingerprint should not be 0"); | |
920 fingerprint = fingerprint >> (static_feature_size + result_feature_size); | |
921 while ( 1 ) { | |
922 switch ( fingerprint & parameter_feature_mask ) { | |
923 case bool_parm: | |
924 get_bool(); | |
925 break; | |
926 case char_parm: | |
927 get_char(); | |
928 break; | |
929 case short_parm: | |
930 get_short(); | |
931 break; | |
932 case byte_parm: | |
933 get_byte(); | |
934 break; | |
935 case int_parm: | |
936 get_int(); | |
937 break; | |
938 case obj_parm: | |
939 get_object(); | |
940 break; | |
941 case long_parm: | |
942 get_long(); | |
943 break; | |
944 case float_parm: | |
945 get_float(); | |
946 break; | |
947 case double_parm: | |
948 get_double(); | |
949 break; | |
950 case done_parm: | |
951 return; | |
952 break; | |
953 default: | |
954 ShouldNotReachHere(); | |
955 break; | |
956 } | |
957 fingerprint >>= parameter_feature_size; | |
958 } | |
959 } | |
960 } | |
961 }; | |
962 | |
963 | |
964 enum JNICallType { | |
965 JNI_STATIC, | |
966 JNI_VIRTUAL, | |
967 JNI_NONVIRTUAL | |
968 }; | |
969 | |
970 static methodHandle jni_resolve_interface_call(Handle recv, methodHandle method, TRAPS) { | |
971 assert(!method.is_null() , "method should not be null"); | |
972 | |
973 KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) | |
974 if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); | |
975 KlassHandle spec_klass (THREAD, method->method_holder()); | |
976 symbolHandle name (THREAD, method->name()); | |
977 symbolHandle signature (THREAD, method->signature()); | |
978 CallInfo info; | |
979 LinkResolver::resolve_interface_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); | |
980 return info.selected_method(); | |
981 } | |
982 | |
983 static methodHandle jni_resolve_virtual_call(Handle recv, methodHandle method, TRAPS) { | |
984 assert(!method.is_null() , "method should not be null"); | |
985 | |
986 KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) | |
987 if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); | |
988 KlassHandle spec_klass (THREAD, method->method_holder()); | |
989 symbolHandle name (THREAD, method->name()); | |
990 symbolHandle signature (THREAD, method->signature()); | |
991 CallInfo info; | |
992 LinkResolver::resolve_virtual_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); | |
993 return info.selected_method(); | |
994 } | |
995 | |
996 | |
997 | |
998 static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { | |
999 methodHandle method(THREAD, JNIHandles::resolve_jmethod_id(method_id)); | |
1000 | |
1001 // Create object to hold arguments for the JavaCall, and associate it with | |
1002 // the jni parser | |
1003 ResourceMark rm(THREAD); | |
1004 int number_of_parameters = method->size_of_parameters(); | |
1005 JavaCallArguments java_args(number_of_parameters); | |
1006 args->set_java_argument_object(&java_args); | |
1007 | |
1008 assert(method->is_static(), "method should be static"); | |
1009 | |
1010 // Fill out JavaCallArguments object | |
1011 args->iterate( Fingerprinter(THREAD, method).fingerprint() ); | |
1012 // Initialize result type | |
1013 result->set_type(args->get_ret_type()); | |
1014 | |
1015 // Invoke the method. Result is returned as oop. | |
1016 JavaCalls::call(result, method, &java_args, CHECK); | |
1017 | |
1018 // Convert result | |
1019 if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { | |
1020 result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); | |
1021 } | |
1022 } | |
1023 | |
1024 | |
1025 static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { | |
1026 oop recv = JNIHandles::resolve(receiver); | |
1027 if (recv == NULL) { | |
1028 THROW(vmSymbols::java_lang_NullPointerException()); | |
1029 } | |
1030 Handle h_recv(THREAD, recv); | |
1031 | |
1032 int number_of_parameters; | |
1033 methodOop selected_method; | |
1034 { | |
1035 methodOop m = JNIHandles::resolve_jmethod_id(method_id); | |
1036 number_of_parameters = m->size_of_parameters(); | |
1037 klassOop holder = m->method_holder(); | |
1038 if (!(Klass::cast(holder))->is_interface()) { | |
1039 // non-interface call -- for that little speed boost, don't handlize | |
1040 debug_only(No_Safepoint_Verifier nosafepoint;) | |
1041 if (call_type == JNI_VIRTUAL) { | |
1042 // jni_GetMethodID makes sure class is linked and initialized | |
1043 // so m should have a valid vtable index. | |
1044 int vtbl_index = m->vtable_index(); | |
1045 if (vtbl_index != methodOopDesc::nonvirtual_vtable_index) { | |
1046 klassOop k = h_recv->klass(); | |
1047 // k might be an arrayKlassOop but all vtables start at | |
1048 // the same place. The cast is to avoid virtual call and assertion. | |
1049 instanceKlass *ik = (instanceKlass*)k->klass_part(); | |
1050 selected_method = ik->method_at_vtable(vtbl_index); | |
1051 } else { | |
1052 // final method | |
1053 selected_method = m; | |
1054 } | |
1055 } else { | |
1056 // JNI_NONVIRTUAL call | |
1057 selected_method = m; | |
1058 } | |
1059 } else { | |
1060 // interface call | |
1061 KlassHandle h_holder(THREAD, holder); | |
1062 | |
1063 int itbl_index = m->cached_itable_index(); | |
1064 if (itbl_index == -1) { | |
1065 itbl_index = klassItable::compute_itable_index(m); | |
1066 m->set_cached_itable_index(itbl_index); | |
1067 // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again | |
1068 } | |
1069 klassOop k = h_recv->klass(); | |
1070 selected_method = instanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); | |
1071 } | |
1072 } | |
1073 | |
1074 methodHandle method(THREAD, selected_method); | |
1075 | |
1076 // Create object to hold arguments for the JavaCall, and associate it with | |
1077 // the jni parser | |
1078 ResourceMark rm(THREAD); | |
1079 JavaCallArguments java_args(number_of_parameters); | |
1080 args->set_java_argument_object(&java_args); | |
1081 | |
1082 // handle arguments | |
1083 assert(!method->is_static(), "method should not be static"); | |
1084 args->push_receiver(h_recv); // Push jobject handle | |
1085 | |
1086 // Fill out JavaCallArguments object | |
1087 args->iterate( Fingerprinter(THREAD, method).fingerprint() ); | |
1088 // Initialize result type | |
1089 result->set_type(args->get_ret_type()); | |
1090 | |
1091 // Invoke the method. Result is returned as oop. | |
1092 JavaCalls::call(result, method, &java_args, CHECK); | |
1093 | |
1094 // Convert result | |
1095 if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { | |
1096 result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); | |
1097 } | |
1098 } | |
1099 | |
1100 | |
1101 static instanceOop alloc_object(jclass clazz, TRAPS) { | |
1102 KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1103 Klass::cast(k())->check_valid_for_instantiation(false, CHECK_NULL); | |
1104 instanceKlass::cast(k())->initialize(CHECK_NULL); | |
1105 instanceOop ih = instanceKlass::cast(k())->allocate_instance(THREAD); | |
1106 return ih; | |
1107 } | |
1108 | |
1109 DT_RETURN_MARK_DECL(AllocObject, jobject); | |
1110 | |
1111 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz)) | |
1112 JNIWrapper("AllocObject"); | |
1113 | |
1114 DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz); | |
1115 jobject ret = NULL; | |
1116 DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret); | |
1117 | |
1118 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1119 ret = JNIHandles::make_local(env, i); | |
1120 return ret; | |
1121 JNI_END | |
1122 | |
1123 DT_RETURN_MARK_DECL(NewObjectA, jobject); | |
1124 | |
1125 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args)) | |
1126 JNIWrapper("NewObjectA"); | |
1127 DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID); | |
1128 jobject obj = NULL; | |
1129 DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj); | |
1130 | |
1131 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1132 obj = JNIHandles::make_local(env, i); | |
1133 JavaValue jvalue(T_VOID); | |
1134 JNI_ArgumentPusherArray ap(THREAD, methodID, args); | |
1135 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); | |
1136 return obj; | |
1137 JNI_END | |
1138 | |
1139 DT_RETURN_MARK_DECL(NewObjectV, jobject); | |
1140 | |
1141 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)) | |
1142 JNIWrapper("NewObjectV"); | |
1143 DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID); | |
1144 jobject obj = NULL; | |
1145 DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj); | |
1146 | |
1147 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1148 obj = JNIHandles::make_local(env, i); | |
1149 JavaValue jvalue(T_VOID); | |
1150 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1151 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); | |
1152 return obj; | |
1153 JNI_END | |
1154 | |
1155 DT_RETURN_MARK_DECL(NewObject, jobject); | |
1156 | |
1157 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)) | |
1158 JNIWrapper("NewObject"); | |
1159 DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID); | |
1160 jobject obj = NULL; | |
1161 DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj); | |
1162 | |
1163 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1164 obj = JNIHandles::make_local(env, i); | |
1165 va_list args; | |
1166 va_start(args, methodID); | |
1167 JavaValue jvalue(T_VOID); | |
1168 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1169 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); | |
1170 va_end(args); | |
1171 return obj; | |
1172 JNI_END | |
1173 | |
1174 | |
1175 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj)) | |
1176 JNIWrapper("GetObjectClass"); | |
1177 DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj); | |
1178 klassOop k = JNIHandles::resolve_non_null(obj)->klass(); | |
1179 jclass ret = | |
1180 (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror()); | |
1181 DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret); | |
1182 return ret; | |
1183 JNI_END | |
1184 | |
1185 JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)) | |
1186 JNIWrapper("IsInstanceOf"); | |
1187 DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz); | |
1188 jboolean ret = JNI_TRUE; | |
1189 if (obj != NULL) { | |
1190 ret = JNI_FALSE; | |
1191 klassOop k = java_lang_Class::as_klassOop( | |
1192 JNIHandles::resolve_non_null(clazz)); | |
1193 if (k != NULL) { | |
1194 ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE; | |
1195 } | |
1196 } | |
1197 DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret); | |
1198 return ret; | |
1199 JNI_END | |
1200 | |
1201 | |
1202 static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str, | |
1203 const char *sig, bool is_static, TRAPS) { | |
1204 // %%%% This code should probably just call into a method in the LinkResolver | |
1205 // | |
1206 // The class should have been loaded (we have an instance of the class | |
1207 // passed in) so the method and signature should already be in the symbol | |
1208 // table. If they're not there, the method doesn't exist. | |
1209 symbolHandle signature = | |
1210 symbolHandle(THREAD, SymbolTable::probe(sig, (int)strlen(sig))); | |
1211 symbolHandle name; | |
1212 if (name_str == NULL) { | |
1213 name = vmSymbolHandles::object_initializer_name(); | |
1214 } else { | |
1215 name = symbolHandle(THREAD, | |
1216 SymbolTable::probe(name_str, (int)strlen(name_str))); | |
1217 } | |
1218 if (name.is_null() || signature.is_null()) { | |
1219 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1220 } | |
1221 | |
1222 // Throw a NoSuchMethodError exception if we have an instance of a | |
1223 // primitive java.lang.Class | |
1224 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) { | |
1225 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1226 } | |
1227 | |
1228 KlassHandle klass(THREAD, | |
1229 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1230 | |
1231 // Make sure class is linked and initialized before handing id's out to | |
1232 // methodOops. | |
1233 Klass::cast(klass())->initialize(CHECK_NULL); | |
1234 | |
1235 methodOop m; | |
1236 if (name() == vmSymbols::object_initializer_name() || | |
1237 name() == vmSymbols::class_initializer_name()) { | |
1238 // Never search superclasses for constructors | |
1239 if (klass->oop_is_instance()) { | |
1240 m = instanceKlass::cast(klass())->find_method(name(), signature()); | |
1241 } else { | |
1242 m = NULL; | |
1243 } | |
1244 } else { | |
1245 m = klass->lookup_method(name(), signature()); | |
1246 // Look up interfaces | |
1247 if (m == NULL && klass->oop_is_instance()) { | |
1248 m = instanceKlass::cast(klass())->lookup_method_in_all_interfaces(name(), | |
1249 signature()); | |
1250 } | |
1251 } | |
1252 if (m == NULL || (m->is_static() != is_static)) { | |
1253 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1254 } | |
1255 return m->jmethod_id(); | |
1256 } | |
1257 | |
1258 | |
1259 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz, | |
1260 const char *name, const char *sig)) | |
1261 JNIWrapper("GetMethodID"); | |
1262 DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig); | |
1263 jmethodID ret = get_method_id(env, clazz, name, sig, false, thread); | |
1264 DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret); | |
1265 return ret; | |
1266 JNI_END | |
1267 | |
1268 | |
1269 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz, | |
1270 const char *name, const char *sig)) | |
1271 JNIWrapper("GetStaticMethodID"); | |
1272 DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig); | |
1273 jmethodID ret = get_method_id(env, clazz, name, sig, true, thread); | |
1274 DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret); | |
1275 return ret; | |
1276 JNI_END | |
1277 | |
1278 | |
1279 | |
1280 // | |
1281 // Calling Methods | |
1282 // | |
1283 | |
1284 | |
1285 #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \ | |
1286 \ | |
1287 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\ | |
1288 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType);\ | |
1289 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType);\ | |
1290 \ | |
1291 JNI_ENTRY(ResultType, \ | |
1292 jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ | |
1293 JNIWrapper("Call" XSTR(Result) "Method"); \ | |
1294 \ | |
1295 DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID);\ | |
1296 ResultType ret = 0;\ | |
1297 DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ | |
1298 (const ResultType&)ret);\ | |
1299 \ | |
1300 va_list args; \ | |
1301 va_start(args, methodID); \ | |
1302 JavaValue jvalue(Tag); \ | |
1303 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); \ | |
1304 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ | |
1305 va_end(args); \ | |
1306 ret = jvalue.get_##ResultType(); \ | |
1307 return ret;\ | |
1308 JNI_END \ | |
1309 \ | |
1310 \ | |
1311 JNI_ENTRY(ResultType, \ | |
1312 jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ | |
1313 JNIWrapper("Call" XSTR(Result) "MethodV"); \ | |
1314 \ | |
1315 DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID);\ | |
1316 ResultType ret = 0;\ | |
1317 DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ | |
1318 (const ResultType&)ret);\ | |
1319 \ | |
1320 JavaValue jvalue(Tag); \ | |
1321 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); \ | |
1322 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ | |
1323 ret = jvalue.get_##ResultType(); \ | |
1324 return ret;\ | |
1325 JNI_END \ | |
1326 \ | |
1327 \ | |
1328 JNI_ENTRY(ResultType, \ | |
1329 jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ | |
1330 JNIWrapper("Call" XSTR(Result) "MethodA"); \ | |
1331 DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID);\ | |
1332 ResultType ret = 0;\ | |
1333 DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ | |
1334 (const ResultType&)ret);\ | |
1335 \ | |
1336 JavaValue jvalue(Tag); \ | |
1337 JNI_ArgumentPusherArray ap(THREAD, methodID, args); \ | |
1338 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ | |
1339 ret = jvalue.get_##ResultType(); \ | |
1340 return ret;\ | |
1341 JNI_END | |
1342 | |
1343 // the runtime type of subword integral basic types is integer | |
1344 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1345 DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE) | |
1346 DEFINE_CALLMETHOD(jchar, Char, T_CHAR) | |
1347 DEFINE_CALLMETHOD(jshort, Short, T_SHORT) | |
1348 | |
1349 DEFINE_CALLMETHOD(jobject, Object, T_OBJECT) | |
1350 DEFINE_CALLMETHOD(jint, Int, T_INT) | |
1351 DEFINE_CALLMETHOD(jlong, Long, T_LONG) | |
1352 DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT) | |
1353 DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE) | |
1354 | |
1355 DT_VOID_RETURN_MARK_DECL(CallVoidMethod); | |
1356 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV); | |
1357 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA); | |
1358 | |
1359 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)) | |
1360 JNIWrapper("CallVoidMethod"); | |
1361 DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID); | |
1362 DT_VOID_RETURN_MARK(CallVoidMethod); | |
1363 | |
1364 va_list args; | |
1365 va_start(args, methodID); | |
1366 JavaValue jvalue(T_VOID); | |
1367 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1368 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); | |
1369 va_end(args); | |
1370 JNI_END | |
1371 | |
1372 | |
1373 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) | |
1374 JNIWrapper("CallVoidMethodV"); | |
1375 DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID); | |
1376 DT_VOID_RETURN_MARK(CallVoidMethodV); | |
1377 | |
1378 JavaValue jvalue(T_VOID); | |
1379 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1380 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); | |
1381 JNI_END | |
1382 | |
1383 | |
1384 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) | |
1385 JNIWrapper("CallVoidMethodA"); | |
1386 DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID); | |
1387 DT_VOID_RETURN_MARK(CallVoidMethodA); | |
1388 | |
1389 JavaValue jvalue(T_VOID); | |
1390 JNI_ArgumentPusherArray ap(THREAD, methodID, args); | |
1391 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); | |
1392 JNI_END | |
1393 | |
1394 | |
1395 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \ | |
1396 \ | |
1397 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\ | |
1398 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType);\ | |
1399 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType);\ | |
1400 \ | |
1401 JNI_ENTRY(ResultType, \ | |
1402 jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ | |
1403 JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ | |
1404 \ | |
1405 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##Method__entry, env, obj, cls, methodID);\ | |
1406 ResultType ret;\ | |
1407 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ | |
1408 (const ResultType&)ret);\ | |
1409 \ | |
1410 va_list args; \ | |
1411 va_start(args, methodID); \ | |
1412 JavaValue jvalue(Tag); \ | |
1413 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); \ | |
1414 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ | |
1415 va_end(args); \ | |
1416 ret = jvalue.get_##ResultType(); \ | |
1417 return ret;\ | |
1418 JNI_END \ | |
1419 \ | |
1420 JNI_ENTRY(ResultType, \ | |
1421 jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ | |
1422 JNIWrapper("CallNonvitual" XSTR(Result) "#MethodV"); \ | |
1423 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodV__entry, env, obj, cls, methodID);\ | |
1424 ResultType ret;\ | |
1425 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ | |
1426 (const ResultType&)ret);\ | |
1427 \ | |
1428 JavaValue jvalue(Tag); \ | |
1429 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); \ | |
1430 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ | |
1431 ret = jvalue.get_##ResultType(); \ | |
1432 return ret;\ | |
1433 JNI_END \ | |
1434 \ | |
1435 JNI_ENTRY(ResultType, \ | |
1436 jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
1437 JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ | |
1438 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodA__entry, env, obj, cls, methodID);\ | |
1439 ResultType ret;\ | |
1440 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ | |
1441 (const ResultType&)ret);\ | |
1442 \ | |
1443 JavaValue jvalue(Tag); \ | |
1444 JNI_ArgumentPusherArray ap(THREAD, methodID, args); \ | |
1445 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ | |
1446 ret = jvalue.get_##ResultType(); \ | |
1447 return ret;\ | |
1448 JNI_END | |
1449 | |
1450 // the runtime type of subword integral basic types is integer | |
1451 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1452 DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE) | |
1453 DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR) | |
1454 DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT) | |
1455 | |
1456 DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT) | |
1457 DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT) | |
1458 DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG) | |
1459 DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT) | |
1460 DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE) | |
1461 | |
1462 | |
1463 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod); | |
1464 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV); | |
1465 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA); | |
1466 | |
1467 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) | |
1468 JNIWrapper("CallNonvirtualVoidMethod"); | |
1469 | |
1470 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry, | |
1471 env, obj, cls, methodID); | |
1472 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod); | |
1473 | |
1474 va_list args; | |
1475 va_start(args, methodID); | |
1476 JavaValue jvalue(T_VOID); | |
1477 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1478 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); | |
1479 va_end(args); | |
1480 JNI_END | |
1481 | |
1482 | |
1483 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) | |
1484 JNIWrapper("CallNonvirtualVoidMethodV"); | |
1485 | |
1486 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry, | |
1487 env, obj, cls, methodID); | |
1488 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV); | |
1489 | |
1490 JavaValue jvalue(T_VOID); | |
1491 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1492 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); | |
1493 JNI_END | |
1494 | |
1495 | |
1496 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) | |
1497 JNIWrapper("CallNonvirtualVoidMethodA"); | |
1498 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry, | |
1499 env, obj, cls, methodID); | |
1500 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA); | |
1501 JavaValue jvalue(T_VOID); | |
1502 JNI_ArgumentPusherArray ap(THREAD, methodID, args); | |
1503 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); | |
1504 JNI_END | |
1505 | |
1506 | |
1507 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \ | |
1508 \ | |
1509 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\ | |
1510 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType);\ | |
1511 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType);\ | |
1512 \ | |
1513 JNI_ENTRY(ResultType, \ | |
1514 jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ | |
1515 JNIWrapper("CallStatic" XSTR(Result) "Method"); \ | |
1516 \ | |
1517 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##Method__entry, env, cls, methodID);\ | |
1518 ResultType ret = 0;\ | |
1519 DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ | |
1520 (const ResultType&)ret);\ | |
1521 \ | |
1522 va_list args; \ | |
1523 va_start(args, methodID); \ | |
1524 JavaValue jvalue(Tag); \ | |
1525 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); \ | |
1526 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ | |
1527 va_end(args); \ | |
1528 ret = jvalue.get_##ResultType(); \ | |
1529 return ret;\ | |
1530 JNI_END \ | |
1531 \ | |
1532 JNI_ENTRY(ResultType, \ | |
1533 jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ | |
1534 JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ | |
1535 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodV__entry, env, cls, methodID);\ | |
1536 ResultType ret = 0;\ | |
1537 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ | |
1538 (const ResultType&)ret);\ | |
1539 \ | |
1540 JavaValue jvalue(Tag); \ | |
1541 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); \ | |
1542 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ | |
1543 ret = jvalue.get_##ResultType(); \ | |
1544 return ret;\ | |
1545 JNI_END \ | |
1546 \ | |
1547 JNI_ENTRY(ResultType, \ | |
1548 jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
1549 JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ | |
1550 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodA__entry, env, cls, methodID);\ | |
1551 ResultType ret = 0;\ | |
1552 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ | |
1553 (const ResultType&)ret);\ | |
1554 \ | |
1555 JavaValue jvalue(Tag); \ | |
1556 JNI_ArgumentPusherArray ap(THREAD, methodID, args); \ | |
1557 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ | |
1558 ret = jvalue.get_##ResultType(); \ | |
1559 return ret;\ | |
1560 JNI_END | |
1561 | |
1562 // the runtime type of subword integral basic types is integer | |
1563 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1564 DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE) | |
1565 DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR) | |
1566 DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT) | |
1567 | |
1568 DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT) | |
1569 DEFINE_CALLSTATICMETHOD(jint, Int, T_INT) | |
1570 DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG) | |
1571 DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT) | |
1572 DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE) | |
1573 | |
1574 | |
1575 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod); | |
1576 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV); | |
1577 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA); | |
1578 | |
1579 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)) | |
1580 JNIWrapper("CallStaticVoidMethod"); | |
1581 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID); | |
1582 DT_VOID_RETURN_MARK(CallStaticVoidMethod); | |
1583 | |
1584 va_list args; | |
1585 va_start(args, methodID); | |
1586 JavaValue jvalue(T_VOID); | |
1587 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1588 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); | |
1589 va_end(args); | |
1590 JNI_END | |
1591 | |
1592 | |
1593 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) | |
1594 JNIWrapper("CallStaticVoidMethodV"); | |
1595 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID); | |
1596 DT_VOID_RETURN_MARK(CallStaticVoidMethodV); | |
1597 | |
1598 JavaValue jvalue(T_VOID); | |
1599 JNI_ArgumentPusherVaArg ap(THREAD, methodID, args); | |
1600 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); | |
1601 JNI_END | |
1602 | |
1603 | |
1604 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) | |
1605 JNIWrapper("CallStaticVoidMethodA"); | |
1606 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID); | |
1607 DT_VOID_RETURN_MARK(CallStaticVoidMethodA); | |
1608 | |
1609 JavaValue jvalue(T_VOID); | |
1610 JNI_ArgumentPusherArray ap(THREAD, methodID, args); | |
1611 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); | |
1612 JNI_END | |
1613 | |
1614 | |
1615 // | |
1616 // Accessing Fields | |
1617 // | |
1618 | |
1619 | |
1620 DT_RETURN_MARK_DECL(GetFieldID, jfieldID); | |
1621 | |
1622 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz, | |
1623 const char *name, const char *sig)) | |
1624 JNIWrapper("GetFieldID"); | |
1625 DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig); | |
1626 jfieldID ret = 0; | |
1627 DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret); | |
1628 | |
1629 // The class should have been loaded (we have an instance of the class | |
1630 // passed in) so the field and signature should already be in the symbol | |
1631 // table. If they're not there, the field doesn't exist. | |
1632 symbolHandle fieldname = | |
1633 symbolHandle(THREAD, SymbolTable::probe(name, (int)strlen(name))); | |
1634 symbolHandle signame = | |
1635 symbolHandle(THREAD, SymbolTable::probe(sig, (int)strlen(sig))); | |
1636 if (fieldname.is_null() || signame.is_null()) { | |
1637 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); | |
1638 } | |
1639 KlassHandle k(THREAD, | |
1640 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1641 // Make sure class is initialized before handing id's out to fields | |
1642 Klass::cast(k())->initialize(CHECK_NULL); | |
1643 | |
1644 fieldDescriptor fd; | |
1645 if (!Klass::cast(k())->oop_is_instance() || | |
1646 !instanceKlass::cast(k())->find_field(fieldname(), signame(), false, &fd)) { | |
1647 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); | |
1648 } | |
1649 | |
1650 // A jfieldID for a non-static field is simply the offset of the field within the instanceOop | |
1651 // It may also have hash bits for k, if VerifyJNIFields is turned on. | |
1652 ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset()); | |
1653 return ret; | |
1654 JNI_END | |
1655 | |
1656 | |
1657 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)) | |
1658 JNIWrapper("GetObjectField"); | |
1659 DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID); | |
1660 oop o = JNIHandles::resolve_non_null(obj); | |
1661 klassOop k = o->klass(); | |
1662 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
1663 // Keep JVMTI addition small and only check enabled flag here. | |
1664 // jni_GetField_probe() assumes that is okay to create handles. | |
1665 if (JvmtiExport::should_post_field_access()) { | |
1666 o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); | |
1667 } | |
1668 jobject ret = JNIHandles::make_local(env, o->obj_field(offset)); | |
1669 DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret); | |
1670 return ret; | |
1671 JNI_END | |
1672 | |
1673 | |
1674 #define DEFINE_GETFIELD(Return,Fieldname,Result) \ | |
1675 \ | |
1676 DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\ | |
1677 \ | |
1678 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ | |
1679 JNIWrapper("Get" XSTR(Result) "Field"); \ | |
1680 \ | |
1681 DTRACE_PROBE3(hotspot_jni, Get##Result##Field__entry, env, obj, fieldID);\ | |
1682 Return ret = 0;\ | |
1683 DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ | |
1684 \ | |
1685 oop o = JNIHandles::resolve_non_null(obj); \ | |
1686 klassOop k = o->klass(); \ | |
1687 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
1688 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1689 /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ | |
1690 /* and creates a ResetNoHandleMark. */ \ | |
1691 if (JvmtiExport::should_post_field_access()) { \ | |
1692 o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ | |
1693 } \ | |
1694 ret = o->Fieldname##_field(offset); \ | |
1695 return ret; \ | |
1696 JNI_END | |
1697 | |
1698 DEFINE_GETFIELD(jboolean, bool, Boolean) | |
1699 DEFINE_GETFIELD(jbyte, byte, Byte) | |
1700 DEFINE_GETFIELD(jchar, char, Char) | |
1701 DEFINE_GETFIELD(jshort, short, Short) | |
1702 DEFINE_GETFIELD(jint, int, Int) | |
1703 DEFINE_GETFIELD(jlong, long, Long) | |
1704 DEFINE_GETFIELD(jfloat, float, Float) | |
1705 DEFINE_GETFIELD(jdouble, double, Double) | |
1706 | |
1707 address jni_GetBooleanField_addr() { | |
1708 return (address)jni_GetBooleanField; | |
1709 } | |
1710 address jni_GetByteField_addr() { | |
1711 return (address)jni_GetByteField; | |
1712 } | |
1713 address jni_GetCharField_addr() { | |
1714 return (address)jni_GetCharField; | |
1715 } | |
1716 address jni_GetShortField_addr() { | |
1717 return (address)jni_GetShortField; | |
1718 } | |
1719 address jni_GetIntField_addr() { | |
1720 return (address)jni_GetIntField; | |
1721 } | |
1722 address jni_GetLongField_addr() { | |
1723 return (address)jni_GetLongField; | |
1724 } | |
1725 address jni_GetFloatField_addr() { | |
1726 return (address)jni_GetFloatField; | |
1727 } | |
1728 address jni_GetDoubleField_addr() { | |
1729 return (address)jni_GetDoubleField; | |
1730 } | |
1731 | |
1732 JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)) | |
1733 JNIWrapper("SetObjectField"); | |
1734 DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value); | |
1735 oop o = JNIHandles::resolve_non_null(obj); | |
1736 klassOop k = o->klass(); | |
1737 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
1738 // Keep JVMTI addition small and only check enabled flag here. | |
1739 // jni_SetField_probe_nh() assumes that is not okay to create handles | |
1740 // and creates a ResetNoHandleMark. | |
1741 if (JvmtiExport::should_post_field_modification()) { | |
1742 jvalue field_value; | |
1743 field_value.l = value; | |
1744 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value); | |
1745 } | |
1746 o->obj_field_put(offset, JNIHandles::resolve(value)); | |
1747 DTRACE_PROBE(hotspot_jni, SetObjectField__return); | |
1748 JNI_END | |
1749 | |
1750 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \ | |
1751 \ | |
1752 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ | |
1753 JNIWrapper("Set" XSTR(Result) "Field"); \ | |
1754 \ | |
1755 HS_DTRACE_PROBE_CDECL_N(hotspot_jni, Set##Result##Field__entry, \ | |
1756 ( JNIEnv*, jobject, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ | |
1757 HS_DTRACE_PROBE_N(hotspot_jni, Set##Result##Field__entry, \ | |
1758 ( env, obj, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ | |
1759 \ | |
1760 oop o = JNIHandles::resolve_non_null(obj); \ | |
1761 klassOop k = o->klass(); \ | |
1762 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
1763 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1764 /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ | |
1765 /* and creates a ResetNoHandleMark. */ \ | |
1766 if (JvmtiExport::should_post_field_modification()) { \ | |
1767 jvalue field_value; \ | |
1768 field_value.unionType = value; \ | |
1769 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ | |
1770 } \ | |
1771 o->Fieldname##_field_put(offset, value); \ | |
1772 DTRACE_PROBE(hotspot_jni, Set##Result##Field__return);\ | |
1773 JNI_END | |
1774 | |
1775 DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z) | |
1776 DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b) | |
1777 DEFINE_SETFIELD(jchar, char, Char, 'C', c) | |
1778 DEFINE_SETFIELD(jshort, short, Short, 'S', s) | |
1779 DEFINE_SETFIELD(jint, int, Int, 'I', i) | |
1780 DEFINE_SETFIELD(jlong, long, Long, 'J', j) | |
1781 DEFINE_SETFIELD(jfloat, float, Float, 'F', f) | |
1782 DEFINE_SETFIELD(jdouble, double, Double, 'D', d) | |
1783 | |
1784 DT_RETURN_MARK_DECL(ToReflectedField, jobject); | |
1785 | |
1786 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic)) | |
1787 JNIWrapper("ToReflectedField"); | |
1788 DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry, | |
1789 env, cls, fieldID, isStatic); | |
1790 jobject ret = NULL; | |
1791 DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret); | |
1792 | |
1793 fieldDescriptor fd; | |
1794 bool found = false; | |
1795 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)); | |
1796 | |
1797 assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID"); | |
1798 | |
1799 if (isStatic) { | |
1800 // Static field. The fieldID a JNIid specifying the field holder and the offset within the klassOop. | |
1801 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
1802 assert(id->is_static_field_id(), "invalid static field id"); | |
1803 found = instanceKlass::cast(id->holder())->find_local_field_from_offset(id->offset(), true, &fd); | |
1804 } else { | |
1805 // Non-static field. The fieldID is really the offset of the field within the instanceOop. | |
1806 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
1807 found = instanceKlass::cast(k)->find_field_from_offset(offset, false, &fd); | |
1808 } | |
1809 assert(found, "bad fieldID passed into jni_ToReflectedField"); | |
1810 oop reflected = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); | |
1811 ret = JNIHandles::make_local(env, reflected); | |
1812 return ret; | |
1813 JNI_END | |
1814 | |
1815 | |
1816 // | |
1817 // Accessing Static Fields | |
1818 // | |
1819 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID); | |
1820 | |
1821 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz, | |
1822 const char *name, const char *sig)) | |
1823 JNIWrapper("GetStaticFieldID"); | |
1824 DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig); | |
1825 jfieldID ret = NULL; | |
1826 DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret); | |
1827 | |
1828 // The class should have been loaded (we have an instance of the class | |
1829 // passed in) so the field and signature should already be in the symbol | |
1830 // table. If they're not there, the field doesn't exist. | |
1831 symbolHandle fieldname = | |
1832 symbolHandle(THREAD, SymbolTable::probe(name, (int)strlen(name))); | |
1833 symbolHandle signame = | |
1834 symbolHandle(THREAD, SymbolTable::probe(sig, (int)strlen(sig))); | |
1835 if (fieldname.is_null() || signame.is_null()) { | |
1836 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); | |
1837 } | |
1838 KlassHandle k(THREAD, | |
1839 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1840 // Make sure class is initialized before handing id's out to static fields | |
1841 Klass::cast(k())->initialize(CHECK_NULL); | |
1842 | |
1843 fieldDescriptor fd; | |
1844 if (!Klass::cast(k())->oop_is_instance() || | |
1845 !instanceKlass::cast(k())->find_field(fieldname(), signame(), true, &fd)) { | |
1846 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); | |
1847 } | |
1848 | |
1849 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop | |
1850 JNIid* id = instanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset()); | |
1851 debug_only(id->set_is_static_field_id();) | |
1852 | |
1853 debug_only(int first_offset = instanceKlass::cast(fd.field_holder())->offset_of_static_fields();) | |
1854 debug_only(int end_offset = first_offset + (instanceKlass::cast(fd.field_holder())->static_field_size() * wordSize);) | |
1855 assert(id->offset() >= first_offset && id->offset() < end_offset, "invalid static field offset"); | |
1856 | |
1857 ret = jfieldIDWorkaround::to_static_jfieldID(id); | |
1858 return ret; | |
1859 JNI_END | |
1860 | |
1861 | |
1862 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)) | |
1863 JNIWrapper("GetStaticObjectField"); | |
1864 DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID); | |
1865 #ifndef JNICHECK_KERNEL | |
1866 DEBUG_ONLY(klassOop param_k = jniCheck::validate_class(thread, clazz);) | |
1867 #endif // JNICHECK_KERNEL | |
1868 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
1869 assert(id->is_static_field_id(), "invalid static field id"); | |
1870 // Keep JVMTI addition small and only check enabled flag here. | |
1871 // jni_GetField_probe() assumes that is okay to create handles. | |
1872 if (JvmtiExport::should_post_field_access()) { | |
1873 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); | |
1874 } | |
1875 jobject ret = JNIHandles::make_local(id->holder()->obj_field(id->offset())); | |
1876 DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret); | |
1877 return ret; | |
1878 JNI_END | |
1879 | |
1880 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \ | |
1881 \ | |
1882 DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\ | |
1883 \ | |
1884 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ | |
1885 JNIWrapper("GetStatic" XSTR(Result) "Field"); \ | |
1886 DTRACE_PROBE3(hotspot_jni, GetStatic##Result##Field__entry, env, clazz, fieldID);\ | |
1887 Return ret = 0;\ | |
1888 DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ | |
1889 (const Return&)ret);\ | |
1890 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
1891 assert(id->is_static_field_id(), "invalid static field id"); \ | |
1892 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1893 /* jni_GetField_probe() assumes that is okay to create handles. */ \ | |
1894 if (JvmtiExport::should_post_field_access()) { \ | |
1895 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ | |
1896 } \ | |
1897 ret = id->holder()-> Fieldname##_field (id->offset()); \ | |
1898 return ret;\ | |
1899 JNI_END | |
1900 | |
1901 DEFINE_GETSTATICFIELD(jboolean, bool, Boolean) | |
1902 DEFINE_GETSTATICFIELD(jbyte, byte, Byte) | |
1903 DEFINE_GETSTATICFIELD(jchar, char, Char) | |
1904 DEFINE_GETSTATICFIELD(jshort, short, Short) | |
1905 DEFINE_GETSTATICFIELD(jint, int, Int) | |
1906 DEFINE_GETSTATICFIELD(jlong, long, Long) | |
1907 DEFINE_GETSTATICFIELD(jfloat, float, Float) | |
1908 DEFINE_GETSTATICFIELD(jdouble, double, Double) | |
1909 | |
1910 | |
1911 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)) | |
1912 JNIWrapper("SetStaticObjectField"); | |
1913 DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value); | |
1914 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
1915 assert(id->is_static_field_id(), "invalid static field id"); | |
1916 // Keep JVMTI addition small and only check enabled flag here. | |
1917 // jni_SetField_probe() assumes that is okay to create handles. | |
1918 if (JvmtiExport::should_post_field_modification()) { | |
1919 jvalue field_value; | |
1920 field_value.l = value; | |
1921 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value); | |
1922 } | |
1923 id->holder()->obj_field_put(id->offset(), JNIHandles::resolve(value)); | |
1924 DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return); | |
1925 JNI_END | |
1926 | |
1927 | |
1928 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \ | |
1929 \ | |
1930 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ | |
1931 JNIWrapper("SetStatic" XSTR(Result) "Field"); \ | |
1932 HS_DTRACE_PROBE_CDECL_N(hotspot_jni, SetStatic##Result##Field__entry,\ | |
1933 ( JNIEnv*, jclass, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ | |
1934 HS_DTRACE_PROBE_N(hotspot_jni, SetStatic##Result##Field__entry, \ | |
1935 ( env, clazz, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ | |
1936 \ | |
1937 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
1938 assert(id->is_static_field_id(), "invalid static field id"); \ | |
1939 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1940 /* jni_SetField_probe() assumes that is okay to create handles. */ \ | |
1941 if (JvmtiExport::should_post_field_modification()) { \ | |
1942 jvalue field_value; \ | |
1943 field_value.unionType = value; \ | |
1944 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ | |
1945 } \ | |
1946 id->holder()-> Fieldname##_field_put (id->offset(), value); \ | |
1947 DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\ | |
1948 JNI_END | |
1949 | |
1950 DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z) | |
1951 DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b) | |
1952 DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c) | |
1953 DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s) | |
1954 DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i) | |
1955 DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j) | |
1956 DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f) | |
1957 DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d) | |
1958 | |
1959 | |
1960 // | |
1961 // String Operations | |
1962 // | |
1963 | |
1964 // Unicode Interface | |
1965 | |
1966 DT_RETURN_MARK_DECL(NewString, jstring); | |
1967 | |
1968 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len)) | |
1969 JNIWrapper("NewString"); | |
1970 DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len); | |
1971 jstring ret = NULL; | |
1972 DT_RETURN_MARK(NewString, jstring, (const jstring&)ret); | |
1973 oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL); | |
1974 ret = (jstring) JNIHandles::make_local(env, string); | |
1975 return ret; | |
1976 JNI_END | |
1977 | |
1978 | |
1979 JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string)) | |
1980 JNIWrapper("GetStringLength"); | |
1981 DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string); | |
1982 jsize ret = java_lang_String::length(JNIHandles::resolve_non_null(string)); | |
1983 DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret); | |
1984 return ret; | |
1985 JNI_END | |
1986 | |
1987 | |
1988 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars( | |
1989 JNIEnv *env, jstring string, jboolean *isCopy)) | |
1990 JNIWrapper("GetStringChars"); | |
1991 DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy); | |
1992 //%note jni_5 | |
1993 if (isCopy != NULL) { | |
1994 *isCopy = JNI_TRUE; | |
1995 } | |
1996 oop s = JNIHandles::resolve_non_null(string); | |
1997 int s_len = java_lang_String::length(s); | |
1998 typeArrayOop s_value = java_lang_String::value(s); | |
1999 int s_offset = java_lang_String::offset(s); | |
2000 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1); // add one for zero termination | |
2001 if (s_len > 0) { | |
2002 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); | |
2003 } | |
2004 buf[s_len] = 0; | |
2005 DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf); | |
2006 return buf; | |
2007 JNI_END | |
2008 | |
2009 | |
2010 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)) | |
2011 JNIWrapper("ReleaseStringChars"); | |
2012 DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars); | |
2013 //%note jni_6 | |
2014 if (chars != NULL) { | |
2015 // Since String objects are supposed to be immutable, don't copy any | |
2016 // new data back. A bad user will have to go after the char array. | |
2017 FreeHeap((void*) chars); | |
2018 } | |
2019 DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return); | |
2020 JNI_END | |
2021 | |
2022 | |
2023 // UTF Interface | |
2024 | |
2025 DT_RETURN_MARK_DECL(NewStringUTF, jstring); | |
2026 | |
2027 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes)) | |
2028 JNIWrapper("NewStringUTF"); | |
2029 DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes); | |
2030 jstring ret; | |
2031 DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret); | |
2032 | |
2033 oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL); | |
2034 ret = (jstring) JNIHandles::make_local(env, result); | |
2035 return ret; | |
2036 JNI_END | |
2037 | |
2038 | |
2039 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string)) | |
2040 JNIWrapper("GetStringUTFLength"); | |
2041 DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string); | |
2042 jsize ret = java_lang_String::utf8_length(JNIHandles::resolve_non_null(string)); | |
2043 DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret); | |
2044 return ret; | |
2045 JNI_END | |
2046 | |
2047 | |
2048 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)) | |
2049 JNIWrapper("GetStringUTFChars"); | |
2050 DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy); | |
2051 ResourceMark rm; | |
2052 char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(string)); | |
2053 int length = (int)strlen(str); | |
2054 char* result = AllocateHeap(length+1, "GetStringUTFChars"); | |
2055 strcpy(result, str); | |
2056 if (isCopy != NULL) *isCopy = JNI_TRUE; | |
2057 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); | |
2058 return result; | |
2059 JNI_END | |
2060 | |
2061 | |
2062 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars)) | |
2063 JNIWrapper("ReleaseStringUTFChars"); | |
2064 DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars); | |
2065 if (chars != NULL) { | |
2066 FreeHeap((char*) chars); | |
2067 } | |
2068 DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return); | |
2069 JNI_END | |
2070 | |
2071 | |
2072 JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array)) | |
2073 JNIWrapper("GetArrayLength"); | |
2074 DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array); | |
2075 arrayOop a = arrayOop(JNIHandles::resolve_non_null(array)); | |
2076 assert(a->is_array(), "must be array"); | |
2077 jsize ret = a->length(); | |
2078 DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret); | |
2079 return ret; | |
2080 JNI_END | |
2081 | |
2082 | |
2083 // | |
2084 // Object Array Operations | |
2085 // | |
2086 | |
2087 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray); | |
2088 | |
2089 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)) | |
2090 JNIWrapper("NewObjectArray"); | |
2091 DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement); | |
2092 jobjectArray ret = NULL; | |
2093 DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret); | |
2094 KlassHandle ek(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(elementClass))); | |
2095 klassOop ako = Klass::cast(ek())->array_klass(CHECK_NULL); | |
2096 KlassHandle ak = KlassHandle(THREAD, ako); | |
2097 objArrayKlass::cast(ak())->initialize(CHECK_NULL); | |
2098 objArrayOop result = objArrayKlass::cast(ak())->allocate(length, CHECK_NULL); | |
2099 oop initial_value = JNIHandles::resolve(initialElement); | |
2100 if (initial_value != NULL) { // array already initialized with NULL | |
2101 for (int index = 0; index < length; index++) { | |
2102 result->obj_at_put(index, initial_value); | |
2103 } | |
2104 } | |
2105 ret = (jobjectArray) JNIHandles::make_local(env, result); | |
2106 return ret; | |
2107 JNI_END | |
2108 | |
2109 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject); | |
2110 | |
2111 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)) | |
2112 JNIWrapper("GetObjectArrayElement"); | |
2113 DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index); | |
2114 jobject ret = NULL; | |
2115 DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret); | |
2116 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); | |
2117 if (a->is_within_bounds(index)) { | |
2118 jobject ret = JNIHandles::make_local(env, a->obj_at(index)); | |
2119 return ret; | |
2120 } else { | |
2121 char buf[jintAsStringSize]; | |
2122 sprintf(buf, "%d", index); | |
2123 THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); | |
2124 } | |
2125 JNI_END | |
2126 | |
2127 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement); | |
2128 | |
2129 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value)) | |
2130 JNIWrapper("SetObjectArrayElement"); | |
2131 DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value); | |
2132 DT_VOID_RETURN_MARK(SetObjectArrayElement); | |
2133 | |
2134 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); | |
2135 oop v = JNIHandles::resolve(value); | |
2136 if (a->is_within_bounds(index)) { | |
2137 if (v == NULL || v->is_a(objArrayKlass::cast(a->klass())->element_klass())) { | |
2138 a->obj_at_put(index, v); | |
2139 } else { | |
2140 THROW(vmSymbols::java_lang_ArrayStoreException()); | |
2141 } | |
2142 } else { | |
2143 char buf[jintAsStringSize]; | |
2144 sprintf(buf, "%d", index); | |
2145 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); | |
2146 } | |
2147 JNI_END | |
2148 | |
2149 | |
2150 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \ | |
2151 \ | |
2152 DT_RETURN_MARK_DECL_FOR(Result, New##Result##Array, Return);\ | |
2153 \ | |
2154 JNI_ENTRY(Return, \ | |
2155 jni_New##Result##Array(JNIEnv *env, jsize len)) \ | |
2156 JNIWrapper("New" XSTR(Result) "Array"); \ | |
2157 DTRACE_PROBE2(hotspot_jni, New##Result##Array__entry, env, len);\ | |
2158 Return ret = NULL;\ | |
2159 DT_RETURN_MARK_FOR(Result, New##Result##Array, Return, (const Return&)ret);\ | |
2160 \ | |
2161 oop obj= oopFactory::Allocator(len, CHECK_0); \ | |
2162 ret = (Return) JNIHandles::make_local(env, obj); \ | |
2163 return ret;\ | |
2164 JNI_END | |
2165 | |
2166 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean) | |
2167 DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte) | |
2168 DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short) | |
2169 DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char) | |
2170 DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int) | |
2171 DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) | |
2172 DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) | |
2173 DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) | |
2174 | |
2175 | |
2176 // Return an address which will fault if the caller writes to it. | |
2177 | |
2178 static char* get_bad_address() { | |
2179 static char* bad_address = NULL; | |
2180 if (bad_address == NULL) { | |
2181 size_t size = os::vm_allocation_granularity(); | |
2182 bad_address = os::reserve_memory(size); | |
2183 if (bad_address != NULL) { | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
237
diff
changeset
|
2184 os::protect_memory(bad_address, size, os::MEM_PROT_READ, |
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
237
diff
changeset
|
2185 /*is_committed*/false); |
0 | 2186 } |
2187 } | |
2188 return bad_address; | |
2189 } | |
2190 | |
2191 | |
2192 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \ | |
2193 \ | |
2194 JNI_QUICK_ENTRY(ElementType*, \ | |
2195 jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ | |
2196 JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ | |
2197 DTRACE_PROBE3(hotspot_jni, Get##Result##ArrayElements__entry, env, array, isCopy);\ | |
2198 /* allocate an chunk of memory in c land */ \ | |
2199 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2200 ElementType* result; \ | |
2201 int len = a->length(); \ | |
2202 if (len == 0) { \ | |
2203 /* Empty array: legal but useless, can't return NULL. \ | |
2204 * Return a pointer to something useless. \ | |
2205 * Avoid asserts in typeArrayOop. */ \ | |
2206 result = (ElementType*)get_bad_address(); \ | |
2207 } else { \ | |
2208 result = NEW_C_HEAP_ARRAY(ElementType, len); \ | |
2209 /* copy the array to the c chunk */ \ | |
2210 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ | |
2211 } \ | |
2212 if (isCopy) *isCopy = JNI_TRUE; \ | |
2213 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ | |
2214 return result; \ | |
2215 JNI_END | |
2216 | |
2217 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) | |
2218 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) | |
2219 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) | |
2220 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) | |
2221 DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int) | |
2222 DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long) | |
2223 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) | |
2224 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) | |
2225 | |
2226 | |
2227 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \ | |
2228 \ | |
2229 JNI_QUICK_ENTRY(void, \ | |
2230 jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ | |
2231 ElementType *buf, jint mode)) \ | |
2232 JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ | |
2233 DTRACE_PROBE4(hotspot_jni, Release##Result##ArrayElements__entry, env, array, buf, mode);\ | |
2234 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2235 int len = a->length(); \ | |
2236 if (len != 0) { /* Empty array: nothing to free or copy. */ \ | |
2237 if ((mode == 0) || (mode == JNI_COMMIT)) { \ | |
2238 memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ | |
2239 } \ | |
2240 if ((mode == 0) || (mode == JNI_ABORT)) { \ | |
2241 FreeHeap(buf); \ | |
2242 } \ | |
2243 } \ | |
2244 DTRACE_PROBE(hotspot_jni, Release##Result##ArrayElements__return);\ | |
2245 JNI_END | |
2246 | |
2247 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) | |
2248 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) | |
2249 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) | |
2250 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) | |
2251 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int) | |
2252 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long) | |
2253 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) | |
2254 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) | |
2255 | |
2256 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ | |
2257 DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\ | |
2258 \ | |
2259 JNI_ENTRY(void, \ | |
2260 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
2261 jsize len, ElementType *buf)) \ | |
2262 JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ | |
2263 DTRACE_PROBE5(hotspot_jni, Get##Result##ArrayRegion__entry, env, array, start, len, buf);\ | |
2264 DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ | |
2265 typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2266 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ | |
2267 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
2268 } else { \ | |
2269 if (len > 0) { \ | |
2270 int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \ | |
2271 memcpy((u_char*) buf, \ | |
2272 (u_char*) src->Tag##_at_addr(start), \ | |
2273 len << sc); \ | |
2274 } \ | |
2275 } \ | |
2276 JNI_END | |
2277 | |
2278 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool) | |
2279 DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) | |
2280 DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short) | |
2281 DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char) | |
2282 DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int) | |
2283 DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long) | |
2284 DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) | |
2285 DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) | |
2286 | |
2287 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ | |
2288 DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\ | |
2289 \ | |
2290 JNI_ENTRY(void, \ | |
2291 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
2292 jsize len, const ElementType *buf)) \ | |
2293 JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ | |
2294 DTRACE_PROBE5(hotspot_jni, Set##Result##ArrayRegion__entry, env, array, start, len, buf);\ | |
2295 DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ | |
2296 typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2297 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ | |
2298 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
2299 } else { \ | |
2300 if (len > 0) { \ | |
2301 int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \ | |
2302 memcpy((u_char*) dst->Tag##_at_addr(start), \ | |
2303 (u_char*) buf, \ | |
2304 len << sc); \ | |
2305 } \ | |
2306 } \ | |
2307 JNI_END | |
2308 | |
2309 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool) | |
2310 DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) | |
2311 DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short) | |
2312 DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char) | |
2313 DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int) | |
2314 DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long) | |
2315 DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) | |
2316 DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) | |
2317 | |
2318 | |
2319 // | |
2320 // Interception of natives | |
2321 // | |
2322 | |
2323 // The RegisterNatives call being attempted tried to register with a method that | |
2324 // is not native. Ask JVM TI what prefixes have been specified. Then check | |
2325 // to see if the native method is now wrapped with the prefixes. See the | |
2326 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details. | |
2327 static methodOop find_prefixed_native(KlassHandle k, | |
2328 symbolHandle name, symbolHandle signature, TRAPS) { | |
2329 ResourceMark rm(THREAD); | |
2330 methodOop method; | |
2331 int name_len = name->utf8_length(); | |
2332 char* name_str = name->as_utf8(); | |
2333 int prefix_count; | |
2334 char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); | |
2335 for (int i = 0; i < prefix_count; i++) { | |
2336 char* prefix = prefixes[i]; | |
2337 int prefix_len = (int)strlen(prefix); | |
2338 | |
2339 // try adding this prefix to the method name and see if it matches another method name | |
2340 int trial_len = name_len + prefix_len; | |
2341 char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1); | |
2342 strcpy(trial_name_str, prefix); | |
2343 strcat(trial_name_str, name_str); | |
2344 symbolHandle trial_name(THREAD, SymbolTable::probe(trial_name_str, trial_len)); | |
2345 if (trial_name.is_null()) { | |
2346 continue; // no such symbol, so this prefix wasn't used, try the next prefix | |
2347 } | |
2348 method = Klass::cast(k())->lookup_method(trial_name(), signature()); | |
2349 if (method == NULL) { | |
2350 continue; // signature doesn't match, try the next prefix | |
2351 } | |
2352 if (method->is_native()) { | |
2353 method->set_is_prefixed_native(); | |
2354 return method; // wahoo, we found a prefixed version of the method, return it | |
2355 } | |
2356 // found as non-native, so prefix is good, add it, probably just need more prefixes | |
2357 name_len = trial_len; | |
2358 name_str = trial_name_str; | |
2359 } | |
2360 return NULL; // not found | |
2361 } | |
2362 | |
2363 static bool register_native(KlassHandle k, symbolHandle name, symbolHandle signature, address entry, TRAPS) { | |
2364 methodOop method = Klass::cast(k())->lookup_method(name(), signature()); | |
2365 if (method == NULL) { | |
2366 ResourceMark rm; | |
2367 stringStream st; | |
2368 st.print("Method %s name or signature does not match", | |
2369 methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name(), signature())); | |
2370 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); | |
2371 } | |
2372 if (!method->is_native()) { | |
2373 // trying to register to a non-native method, see if a JVM TI agent has added prefix(es) | |
2374 method = find_prefixed_native(k, name, signature, THREAD); | |
2375 if (method == NULL) { | |
2376 ResourceMark rm; | |
2377 stringStream st; | |
2378 st.print("Method %s is not declared as native", | |
2379 methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name(), signature())); | |
2380 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); | |
2381 } | |
2382 } | |
2383 | |
2384 if (entry != NULL) { | |
2385 method->set_native_function(entry, | |
2386 methodOopDesc::native_bind_event_is_interesting); | |
2387 } else { | |
2388 method->clear_native_function(); | |
2389 } | |
2390 if (PrintJNIResolving) { | |
2391 ResourceMark rm(THREAD); | |
2392 tty->print_cr("[Registering JNI native method %s.%s]", | |
2393 Klass::cast(method->method_holder())->external_name(), | |
2394 method->name()->as_C_string()); | |
2395 } | |
2396 return true; | |
2397 } | |
2398 | |
2399 DT_RETURN_MARK_DECL(RegisterNatives, jint); | |
2400 | |
2401 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz, | |
2402 const JNINativeMethod *methods, | |
2403 jint nMethods)) | |
2404 JNIWrapper("RegisterNatives"); | |
2405 DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods); | |
2406 jint ret = 0; | |
2407 DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret); | |
2408 | |
2409 KlassHandle h_k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
2410 | |
2411 for (int index = 0; index < nMethods; index++) { | |
2412 const char* meth_name = methods[index].name; | |
2413 const char* meth_sig = methods[index].signature; | |
2414 int meth_name_len = (int)strlen(meth_name); | |
2415 | |
2416 // The class should have been loaded (we have an instance of the class | |
2417 // passed in) so the method and signature should already be in the symbol | |
2418 // table. If they're not there, the method doesn't exist. | |
2419 symbolHandle name(THREAD, SymbolTable::probe(meth_name, meth_name_len)); | |
2420 symbolHandle signature(THREAD, SymbolTable::probe(meth_sig, (int)strlen(meth_sig))); | |
2421 | |
2422 if (name.is_null() || signature.is_null()) { | |
2423 ResourceMark rm; | |
2424 stringStream st; | |
2425 st.print("Method %s.%s%s not found", Klass::cast(h_k())->external_name(), meth_name, meth_sig); | |
2426 // Must return negative value on failure | |
2427 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1); | |
2428 } | |
2429 | |
2430 bool res = register_native(h_k, name, signature, | |
2431 (address) methods[index].fnPtr, THREAD); | |
2432 if (!res) { | |
2433 ret = -1; | |
2434 break; | |
2435 } | |
2436 } | |
2437 return ret; | |
2438 JNI_END | |
2439 | |
2440 | |
2441 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz)) | |
2442 JNIWrapper("UnregisterNatives"); | |
2443 DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz); | |
2444 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz)); | |
2445 //%note jni_2 | |
2446 if (Klass::cast(k)->oop_is_instance()) { | |
2447 for (int index = 0; index < instanceKlass::cast(k)->methods()->length(); index++) { | |
2448 methodOop m = methodOop(instanceKlass::cast(k)->methods()->obj_at(index)); | |
2449 if (m->is_native()) { | |
2450 m->clear_native_function(); | |
2451 m->set_signature_handler(NULL); | |
2452 } | |
2453 } | |
2454 } | |
2455 DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0); | |
2456 return 0; | |
2457 JNI_END | |
2458 | |
2459 // | |
2460 // Monitor functions | |
2461 // | |
2462 | |
2463 DT_RETURN_MARK_DECL(MonitorEnter, jint); | |
2464 | |
2465 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj)) | |
2466 DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj); | |
2467 jint ret = JNI_ERR; | |
2468 DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret); | |
2469 | |
2470 // If the object is null, we can't do anything with it | |
2471 if (jobj == NULL) { | |
2472 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); | |
2473 } | |
2474 | |
2475 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
2476 ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR)); | |
2477 ret = JNI_OK; | |
2478 return ret; | |
2479 JNI_END | |
2480 | |
2481 DT_RETURN_MARK_DECL(MonitorExit, jint); | |
2482 | |
2483 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj)) | |
2484 DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj); | |
2485 jint ret = JNI_ERR; | |
2486 DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret); | |
2487 | |
2488 // Don't do anything with a null object | |
2489 if (jobj == NULL) { | |
2490 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); | |
2491 } | |
2492 | |
2493 Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); | |
2494 ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR)); | |
2495 | |
2496 ret = JNI_OK; | |
2497 return ret; | |
2498 JNI_END | |
2499 | |
2500 // | |
2501 // Extensions | |
2502 // | |
2503 | |
2504 DT_VOID_RETURN_MARK_DECL(GetStringRegion); | |
2505 | |
2506 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf)) | |
2507 JNIWrapper("GetStringRegion"); | |
2508 DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf); | |
2509 DT_VOID_RETURN_MARK(GetStringRegion); | |
2510 oop s = JNIHandles::resolve_non_null(string); | |
2511 int s_len = java_lang_String::length(s); | |
2512 if (start < 0 || len < 0 || start + len > s_len) { | |
2513 THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); | |
2514 } else { | |
2515 if (len > 0) { | |
2516 int s_offset = java_lang_String::offset(s); | |
2517 typeArrayOop s_value = java_lang_String::value(s); | |
2518 memcpy(buf, s_value->char_at_addr(s_offset+start), sizeof(jchar)*len); | |
2519 } | |
2520 } | |
2521 JNI_END | |
2522 | |
2523 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion); | |
2524 | |
2525 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf)) | |
2526 JNIWrapper("GetStringUTFRegion"); | |
2527 DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf); | |
2528 DT_VOID_RETURN_MARK(GetStringUTFRegion); | |
2529 oop s = JNIHandles::resolve_non_null(string); | |
2530 int s_len = java_lang_String::length(s); | |
2531 if (start < 0 || len < 0 || start + len > s_len) { | |
2532 THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); | |
2533 } else { | |
2534 //%note jni_7 | |
2535 if (len > 0) { | |
2536 ResourceMark rm(THREAD); | |
2537 char *utf_region = java_lang_String::as_utf8_string(s, start, len); | |
2538 int utf_len = (int)strlen(utf_region); | |
2539 memcpy(buf, utf_region, utf_len); | |
2540 buf[utf_len] = 0; | |
2541 } else { | |
2542 // JDK null-terminates the buffer even in len is zero | |
2543 if (buf != NULL) { | |
2544 buf[0] = 0; | |
2545 } | |
2546 } | |
2547 } | |
2548 JNI_END | |
2549 | |
2550 | |
2551 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)) | |
2552 JNIWrapper("GetPrimitiveArrayCritical"); | |
2553 DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy); | |
2554 GC_locker::lock_critical(thread); | |
2555 if (isCopy != NULL) { | |
2556 *isCopy = JNI_FALSE; | |
2557 } | |
2558 oop a = JNIHandles::resolve_non_null(array); | |
2559 assert(a->is_array(), "just checking"); | |
2560 BasicType type; | |
2561 if (a->is_objArray()) { | |
2562 type = T_OBJECT; | |
2563 } else { | |
2564 type = typeArrayKlass::cast(a->klass())->element_type(); | |
2565 } | |
2566 void* ret = arrayOop(a)->base(type); | |
2567 DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret); | |
2568 return ret; | |
2569 JNI_END | |
2570 | |
2571 | |
2572 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode)) | |
2573 JNIWrapper("ReleasePrimitiveArrayCritical"); | |
2574 DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode); | |
2575 // The array, carray and mode arguments are ignored | |
2576 GC_locker::unlock_critical(thread); | |
2577 DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return); | |
2578 JNI_END | |
2579 | |
2580 | |
2581 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)) | |
2582 JNIWrapper("GetStringCritical"); | |
2583 DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy); | |
2584 GC_locker::lock_critical(thread); | |
2585 if (isCopy != NULL) { | |
2586 *isCopy = JNI_FALSE; | |
2587 } | |
2588 oop s = JNIHandles::resolve_non_null(string); | |
2589 int s_len = java_lang_String::length(s); | |
2590 typeArrayOop s_value = java_lang_String::value(s); | |
2591 int s_offset = java_lang_String::offset(s); | |
2592 const jchar* ret; | |
2593 if (s_len > 0) { | |
2594 ret = s_value->char_at_addr(s_offset); | |
2595 } else { | |
2596 ret = (jchar*) s_value->base(T_CHAR); | |
2597 } | |
2598 DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret); | |
2599 return ret; | |
2600 JNI_END | |
2601 | |
2602 | |
2603 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars)) | |
2604 JNIWrapper("ReleaseStringCritical"); | |
2605 DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars); | |
2606 // The str and chars arguments are ignored | |
2607 GC_locker::unlock_critical(thread); | |
2608 DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return); | |
2609 JNI_END | |
2610 | |
2611 | |
2612 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref)) | |
2613 JNIWrapper("jni_NewWeakGlobalRef"); | |
2614 DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref); | |
2615 Handle ref_handle(thread, JNIHandles::resolve(ref)); | |
2616 jweak ret = JNIHandles::make_weak_global(ref_handle); | |
2617 DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret); | |
2618 return ret; | |
2619 JNI_END | |
2620 | |
2621 // Must be JNI_ENTRY (with HandleMark) | |
2622 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref)) | |
2623 JNIWrapper("jni_DeleteWeakGlobalRef"); | |
2624 DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref); | |
2625 JNIHandles::destroy_weak_global(ref); | |
2626 DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return); | |
2627 JNI_END | |
2628 | |
2629 | |
2630 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env)) | |
2631 JNIWrapper("jni_ExceptionCheck"); | |
2632 DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env); | |
2633 jni_check_async_exceptions(thread); | |
2634 jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE; | |
2635 DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret); | |
2636 return ret; | |
2637 JNI_END | |
2638 | |
2639 | |
2640 // Initialization state for three routines below relating to | |
2641 // java.nio.DirectBuffers | |
2642 static jint directBufferSupportInitializeStarted = 0; | |
2643 static volatile jint directBufferSupportInitializeEnded = 0; | |
2644 static volatile jint directBufferSupportInitializeFailed = 0; | |
2645 static jclass bufferClass = NULL; | |
2646 static jclass directBufferClass = NULL; | |
2647 static jclass directByteBufferClass = NULL; | |
2648 static jmethodID directByteBufferConstructor = NULL; | |
2649 static jfieldID directBufferAddressField = NULL; | |
2650 static jfieldID bufferCapacityField = NULL; | |
2651 | |
2652 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) { | |
2653 Handle loader; // null (bootstrap) loader | |
2654 Handle protection_domain; // null protection domain | |
2655 | |
2656 symbolHandle sym = oopFactory::new_symbol_handle(name, CHECK_NULL); | |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2657 jclass result = find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2658 |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2659 if (TraceClassResolution && result != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2660 trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result))); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2661 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2662 return result; |
0 | 2663 } |
2664 | |
2665 // These lookups are done with the NULL (bootstrap) ClassLoader to | |
2666 // circumvent any security checks that would be done by jni_FindClass. | |
2667 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env)) | |
2668 { | |
2669 if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; } | |
2670 if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; } | |
2671 if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; } | |
2672 return true; | |
2673 } | |
2674 JNI_END | |
2675 | |
2676 | |
2677 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) { | |
2678 if (directBufferSupportInitializeFailed) { | |
2679 return false; | |
2680 } | |
2681 | |
2682 if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) { | |
2683 if (!lookupDirectBufferClasses(env)) { | |
2684 directBufferSupportInitializeFailed = 1; | |
2685 return false; | |
2686 } | |
2687 | |
2688 // Make global references for these | |
2689 bufferClass = (jclass) env->NewGlobalRef(bufferClass); | |
2690 directBufferClass = (jclass) env->NewGlobalRef(directBufferClass); | |
2691 directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass); | |
2692 | |
2693 // Get needed field and method IDs | |
2694 directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V"); | |
2695 directBufferAddressField = env->GetFieldID(bufferClass, "address", "J"); | |
2696 bufferCapacityField = env->GetFieldID(bufferClass, "capacity", "I"); | |
2697 | |
2698 if ((directByteBufferConstructor == NULL) || | |
2699 (directBufferAddressField == NULL) || | |
2700 (bufferCapacityField == NULL)) { | |
2701 directBufferSupportInitializeFailed = 1; | |
2702 return false; | |
2703 } | |
2704 | |
2705 directBufferSupportInitializeEnded = 1; | |
2706 } else { | |
2707 while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) { | |
521
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2708 // Set state as yield_all can call os:sleep. On Solaris, yield_all calls |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2709 // os::sleep which requires the VM state transition. On other platforms, it |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2710 // is not necessary. The following call to change the VM state is purposely |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2711 // put inside the loop to avoid potential deadlock when multiple threads |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2712 // try to call this method. See 6791815 for more details. |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2713 ThreadInVMfromNative tivn(thread); |
0 | 2714 os::yield_all(); |
2715 } | |
2716 } | |
2717 | |
2718 return !directBufferSupportInitializeFailed; | |
2719 } | |
2720 | |
2721 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity) | |
2722 { | |
2723 // thread_from_jni_environment() will block if VM is gone. | |
2724 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
2725 | |
2726 JNIWrapper("jni_NewDirectByteBuffer"); | |
2727 DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity); | |
2728 | |
2729 if (!directBufferSupportInitializeEnded) { | |
2730 if (!initializeDirectBufferSupport(env, thread)) { | |
2731 DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL); | |
2732 return NULL; | |
2733 } | |
2734 } | |
2735 | |
2736 // Being paranoid about accidental sign extension on address | |
2737 jlong addr = (jlong) ((uintptr_t) address); | |
2738 // NOTE that package-private DirectByteBuffer constructor currently | |
2739 // takes int capacity | |
2740 jint cap = (jint) capacity; | |
2741 jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap); | |
2742 DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret); | |
2743 return ret; | |
2744 } | |
2745 | |
2746 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*); | |
2747 | |
2748 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf) | |
2749 { | |
2750 // thread_from_jni_environment() will block if VM is gone. | |
2751 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
2752 | |
2753 JNIWrapper("jni_GetDirectBufferAddress"); | |
2754 DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf); | |
2755 void* ret = NULL; | |
2756 DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret); | |
2757 | |
2758 if (!directBufferSupportInitializeEnded) { | |
2759 if (!initializeDirectBufferSupport(env, thread)) { | |
2760 return 0; | |
2761 } | |
2762 } | |
2763 | |
2764 if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) { | |
2765 return 0; | |
2766 } | |
2767 | |
2768 ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField); | |
2769 return ret; | |
2770 } | |
2771 | |
2772 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong); | |
2773 | |
2774 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf) | |
2775 { | |
2776 // thread_from_jni_environment() will block if VM is gone. | |
2777 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
2778 | |
2779 JNIWrapper("jni_GetDirectBufferCapacity"); | |
2780 DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf); | |
2781 jlong ret = -1; | |
2782 DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret); | |
2783 | |
2784 if (!directBufferSupportInitializeEnded) { | |
2785 if (!initializeDirectBufferSupport(env, thread)) { | |
2786 ret = 0; | |
2787 return ret; | |
2788 } | |
2789 } | |
2790 | |
2791 if (buf == NULL) { | |
2792 return -1; | |
2793 } | |
2794 | |
2795 if (!env->IsInstanceOf(buf, directBufferClass)) { | |
2796 return -1; | |
2797 } | |
2798 | |
2799 // NOTE that capacity is currently an int in the implementation | |
2800 ret = env->GetIntField(buf, bufferCapacityField); | |
2801 return ret; | |
2802 } | |
2803 | |
2804 | |
2805 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env)) | |
2806 JNIWrapper("GetVersion"); | |
2807 DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env); | |
2808 DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion); | |
2809 return CurrentVersion; | |
2810 JNI_END | |
2811 | |
2812 extern struct JavaVM_ main_vm; | |
2813 | |
2814 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm)) | |
2815 JNIWrapper("jni_GetJavaVM"); | |
2816 DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm); | |
2817 *vm = (JavaVM *)(&main_vm); | |
2818 DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK); | |
2819 return JNI_OK; | |
2820 JNI_END | |
2821 | |
2822 // Structure containing all jni functions | |
2823 struct JNINativeInterface_ jni_NativeInterface = { | |
2824 NULL, | |
2825 NULL, | |
2826 NULL, | |
2827 | |
2828 NULL, | |
2829 | |
2830 jni_GetVersion, | |
2831 | |
2832 jni_DefineClass, | |
2833 jni_FindClass, | |
2834 | |
2835 jni_FromReflectedMethod, | |
2836 jni_FromReflectedField, | |
2837 | |
2838 jni_ToReflectedMethod, | |
2839 | |
2840 jni_GetSuperclass, | |
2841 jni_IsAssignableFrom, | |
2842 | |
2843 jni_ToReflectedField, | |
2844 | |
2845 jni_Throw, | |
2846 jni_ThrowNew, | |
2847 jni_ExceptionOccurred, | |
2848 jni_ExceptionDescribe, | |
2849 jni_ExceptionClear, | |
2850 jni_FatalError, | |
2851 | |
2852 jni_PushLocalFrame, | |
2853 jni_PopLocalFrame, | |
2854 | |
2855 jni_NewGlobalRef, | |
2856 jni_DeleteGlobalRef, | |
2857 jni_DeleteLocalRef, | |
2858 jni_IsSameObject, | |
2859 | |
2860 jni_NewLocalRef, | |
2861 jni_EnsureLocalCapacity, | |
2862 | |
2863 jni_AllocObject, | |
2864 jni_NewObject, | |
2865 jni_NewObjectV, | |
2866 jni_NewObjectA, | |
2867 | |
2868 jni_GetObjectClass, | |
2869 jni_IsInstanceOf, | |
2870 | |
2871 jni_GetMethodID, | |
2872 | |
2873 jni_CallObjectMethod, | |
2874 jni_CallObjectMethodV, | |
2875 jni_CallObjectMethodA, | |
2876 jni_CallBooleanMethod, | |
2877 jni_CallBooleanMethodV, | |
2878 jni_CallBooleanMethodA, | |
2879 jni_CallByteMethod, | |
2880 jni_CallByteMethodV, | |
2881 jni_CallByteMethodA, | |
2882 jni_CallCharMethod, | |
2883 jni_CallCharMethodV, | |
2884 jni_CallCharMethodA, | |
2885 jni_CallShortMethod, | |
2886 jni_CallShortMethodV, | |
2887 jni_CallShortMethodA, | |
2888 jni_CallIntMethod, | |
2889 jni_CallIntMethodV, | |
2890 jni_CallIntMethodA, | |
2891 jni_CallLongMethod, | |
2892 jni_CallLongMethodV, | |
2893 jni_CallLongMethodA, | |
2894 jni_CallFloatMethod, | |
2895 jni_CallFloatMethodV, | |
2896 jni_CallFloatMethodA, | |
2897 jni_CallDoubleMethod, | |
2898 jni_CallDoubleMethodV, | |
2899 jni_CallDoubleMethodA, | |
2900 jni_CallVoidMethod, | |
2901 jni_CallVoidMethodV, | |
2902 jni_CallVoidMethodA, | |
2903 | |
2904 jni_CallNonvirtualObjectMethod, | |
2905 jni_CallNonvirtualObjectMethodV, | |
2906 jni_CallNonvirtualObjectMethodA, | |
2907 jni_CallNonvirtualBooleanMethod, | |
2908 jni_CallNonvirtualBooleanMethodV, | |
2909 jni_CallNonvirtualBooleanMethodA, | |
2910 jni_CallNonvirtualByteMethod, | |
2911 jni_CallNonvirtualByteMethodV, | |
2912 jni_CallNonvirtualByteMethodA, | |
2913 jni_CallNonvirtualCharMethod, | |
2914 jni_CallNonvirtualCharMethodV, | |
2915 jni_CallNonvirtualCharMethodA, | |
2916 jni_CallNonvirtualShortMethod, | |
2917 jni_CallNonvirtualShortMethodV, | |
2918 jni_CallNonvirtualShortMethodA, | |
2919 jni_CallNonvirtualIntMethod, | |
2920 jni_CallNonvirtualIntMethodV, | |
2921 jni_CallNonvirtualIntMethodA, | |
2922 jni_CallNonvirtualLongMethod, | |
2923 jni_CallNonvirtualLongMethodV, | |
2924 jni_CallNonvirtualLongMethodA, | |
2925 jni_CallNonvirtualFloatMethod, | |
2926 jni_CallNonvirtualFloatMethodV, | |
2927 jni_CallNonvirtualFloatMethodA, | |
2928 jni_CallNonvirtualDoubleMethod, | |
2929 jni_CallNonvirtualDoubleMethodV, | |
2930 jni_CallNonvirtualDoubleMethodA, | |
2931 jni_CallNonvirtualVoidMethod, | |
2932 jni_CallNonvirtualVoidMethodV, | |
2933 jni_CallNonvirtualVoidMethodA, | |
2934 | |
2935 jni_GetFieldID, | |
2936 | |
2937 jni_GetObjectField, | |
2938 jni_GetBooleanField, | |
2939 jni_GetByteField, | |
2940 jni_GetCharField, | |
2941 jni_GetShortField, | |
2942 jni_GetIntField, | |
2943 jni_GetLongField, | |
2944 jni_GetFloatField, | |
2945 jni_GetDoubleField, | |
2946 | |
2947 jni_SetObjectField, | |
2948 jni_SetBooleanField, | |
2949 jni_SetByteField, | |
2950 jni_SetCharField, | |
2951 jni_SetShortField, | |
2952 jni_SetIntField, | |
2953 jni_SetLongField, | |
2954 jni_SetFloatField, | |
2955 jni_SetDoubleField, | |
2956 | |
2957 jni_GetStaticMethodID, | |
2958 | |
2959 jni_CallStaticObjectMethod, | |
2960 jni_CallStaticObjectMethodV, | |
2961 jni_CallStaticObjectMethodA, | |
2962 jni_CallStaticBooleanMethod, | |
2963 jni_CallStaticBooleanMethodV, | |
2964 jni_CallStaticBooleanMethodA, | |
2965 jni_CallStaticByteMethod, | |
2966 jni_CallStaticByteMethodV, | |
2967 jni_CallStaticByteMethodA, | |
2968 jni_CallStaticCharMethod, | |
2969 jni_CallStaticCharMethodV, | |
2970 jni_CallStaticCharMethodA, | |
2971 jni_CallStaticShortMethod, | |
2972 jni_CallStaticShortMethodV, | |
2973 jni_CallStaticShortMethodA, | |
2974 jni_CallStaticIntMethod, | |
2975 jni_CallStaticIntMethodV, | |
2976 jni_CallStaticIntMethodA, | |
2977 jni_CallStaticLongMethod, | |
2978 jni_CallStaticLongMethodV, | |
2979 jni_CallStaticLongMethodA, | |
2980 jni_CallStaticFloatMethod, | |
2981 jni_CallStaticFloatMethodV, | |
2982 jni_CallStaticFloatMethodA, | |
2983 jni_CallStaticDoubleMethod, | |
2984 jni_CallStaticDoubleMethodV, | |
2985 jni_CallStaticDoubleMethodA, | |
2986 jni_CallStaticVoidMethod, | |
2987 jni_CallStaticVoidMethodV, | |
2988 jni_CallStaticVoidMethodA, | |
2989 | |
2990 jni_GetStaticFieldID, | |
2991 | |
2992 jni_GetStaticObjectField, | |
2993 jni_GetStaticBooleanField, | |
2994 jni_GetStaticByteField, | |
2995 jni_GetStaticCharField, | |
2996 jni_GetStaticShortField, | |
2997 jni_GetStaticIntField, | |
2998 jni_GetStaticLongField, | |
2999 jni_GetStaticFloatField, | |
3000 jni_GetStaticDoubleField, | |
3001 | |
3002 jni_SetStaticObjectField, | |
3003 jni_SetStaticBooleanField, | |
3004 jni_SetStaticByteField, | |
3005 jni_SetStaticCharField, | |
3006 jni_SetStaticShortField, | |
3007 jni_SetStaticIntField, | |
3008 jni_SetStaticLongField, | |
3009 jni_SetStaticFloatField, | |
3010 jni_SetStaticDoubleField, | |
3011 | |
3012 jni_NewString, | |
3013 jni_GetStringLength, | |
3014 jni_GetStringChars, | |
3015 jni_ReleaseStringChars, | |
3016 | |
3017 jni_NewStringUTF, | |
3018 jni_GetStringUTFLength, | |
3019 jni_GetStringUTFChars, | |
3020 jni_ReleaseStringUTFChars, | |
3021 | |
3022 jni_GetArrayLength, | |
3023 | |
3024 jni_NewObjectArray, | |
3025 jni_GetObjectArrayElement, | |
3026 jni_SetObjectArrayElement, | |
3027 | |
3028 jni_NewBooleanArray, | |
3029 jni_NewByteArray, | |
3030 jni_NewCharArray, | |
3031 jni_NewShortArray, | |
3032 jni_NewIntArray, | |
3033 jni_NewLongArray, | |
3034 jni_NewFloatArray, | |
3035 jni_NewDoubleArray, | |
3036 | |
3037 jni_GetBooleanArrayElements, | |
3038 jni_GetByteArrayElements, | |
3039 jni_GetCharArrayElements, | |
3040 jni_GetShortArrayElements, | |
3041 jni_GetIntArrayElements, | |
3042 jni_GetLongArrayElements, | |
3043 jni_GetFloatArrayElements, | |
3044 jni_GetDoubleArrayElements, | |
3045 | |
3046 jni_ReleaseBooleanArrayElements, | |
3047 jni_ReleaseByteArrayElements, | |
3048 jni_ReleaseCharArrayElements, | |
3049 jni_ReleaseShortArrayElements, | |
3050 jni_ReleaseIntArrayElements, | |
3051 jni_ReleaseLongArrayElements, | |
3052 jni_ReleaseFloatArrayElements, | |
3053 jni_ReleaseDoubleArrayElements, | |
3054 | |
3055 jni_GetBooleanArrayRegion, | |
3056 jni_GetByteArrayRegion, | |
3057 jni_GetCharArrayRegion, | |
3058 jni_GetShortArrayRegion, | |
3059 jni_GetIntArrayRegion, | |
3060 jni_GetLongArrayRegion, | |
3061 jni_GetFloatArrayRegion, | |
3062 jni_GetDoubleArrayRegion, | |
3063 | |
3064 jni_SetBooleanArrayRegion, | |
3065 jni_SetByteArrayRegion, | |
3066 jni_SetCharArrayRegion, | |
3067 jni_SetShortArrayRegion, | |
3068 jni_SetIntArrayRegion, | |
3069 jni_SetLongArrayRegion, | |
3070 jni_SetFloatArrayRegion, | |
3071 jni_SetDoubleArrayRegion, | |
3072 | |
3073 jni_RegisterNatives, | |
3074 jni_UnregisterNatives, | |
3075 | |
3076 jni_MonitorEnter, | |
3077 jni_MonitorExit, | |
3078 | |
3079 jni_GetJavaVM, | |
3080 | |
3081 jni_GetStringRegion, | |
3082 jni_GetStringUTFRegion, | |
3083 | |
3084 jni_GetPrimitiveArrayCritical, | |
3085 jni_ReleasePrimitiveArrayCritical, | |
3086 | |
3087 jni_GetStringCritical, | |
3088 jni_ReleaseStringCritical, | |
3089 | |
3090 jni_NewWeakGlobalRef, | |
3091 jni_DeleteWeakGlobalRef, | |
3092 | |
3093 jni_ExceptionCheck, | |
3094 | |
3095 jni_NewDirectByteBuffer, | |
3096 jni_GetDirectBufferAddress, | |
3097 jni_GetDirectBufferCapacity, | |
3098 | |
3099 // New 1_6 features | |
3100 | |
3101 jni_GetObjectRefType | |
3102 }; | |
3103 | |
3104 | |
3105 // For jvmti use to modify jni function table. | |
3106 // Java threads in native contiues to run until it is transitioned | |
3107 // to VM at safepoint. Before the transition or before it is blocked | |
3108 // for safepoint it may access jni function table. VM could crash if | |
3109 // any java thread access the jni function table in the middle of memcpy. | |
3110 // To avoid this each function pointers are copied automically. | |
3111 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) { | |
3112 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
3113 intptr_t *a = (intptr_t *) jni_functions(); | |
3114 intptr_t *b = (intptr_t *) new_jni_NativeInterface; | |
3115 for (uint i=0; i < sizeof(struct JNINativeInterface_)/sizeof(void *); i++) { | |
3116 Atomic::store_ptr(*b++, a++); | |
3117 } | |
3118 } | |
3119 | |
3120 void quicken_jni_functions() { | |
3121 // Replace Get<Primitive>Field with fast versions | |
3122 if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access() | |
3123 && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls | |
3124 #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2) | |
3125 // windows x86 currently needs SEH wrapper and the gain of the fast | |
3126 // versions currently isn't certain for server vm on uniprocessor. | |
3127 && os::is_MP() | |
3128 #endif | |
3129 ) { | |
3130 address func; | |
3131 func = JNI_FastGetField::generate_fast_get_boolean_field(); | |
3132 if (func != (address)-1) { | |
3133 jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func; | |
3134 } | |
3135 func = JNI_FastGetField::generate_fast_get_byte_field(); | |
3136 if (func != (address)-1) { | |
3137 jni_NativeInterface.GetByteField = (GetByteField_t)func; | |
3138 } | |
3139 func = JNI_FastGetField::generate_fast_get_char_field(); | |
3140 if (func != (address)-1) { | |
3141 jni_NativeInterface.GetCharField = (GetCharField_t)func; | |
3142 } | |
3143 func = JNI_FastGetField::generate_fast_get_short_field(); | |
3144 if (func != (address)-1) { | |
3145 jni_NativeInterface.GetShortField = (GetShortField_t)func; | |
3146 } | |
3147 func = JNI_FastGetField::generate_fast_get_int_field(); | |
3148 if (func != (address)-1) { | |
3149 jni_NativeInterface.GetIntField = (GetIntField_t)func; | |
3150 } | |
3151 func = JNI_FastGetField::generate_fast_get_long_field(); | |
3152 if (func != (address)-1) { | |
3153 jni_NativeInterface.GetLongField = (GetLongField_t)func; | |
3154 } | |
3155 func = JNI_FastGetField::generate_fast_get_float_field(); | |
3156 if (func != (address)-1) { | |
3157 jni_NativeInterface.GetFloatField = (GetFloatField_t)func; | |
3158 } | |
3159 func = JNI_FastGetField::generate_fast_get_double_field(); | |
3160 if (func != (address)-1) { | |
3161 jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func; | |
3162 } | |
3163 } | |
3164 } | |
3165 | |
3166 // Returns the function structure | |
3167 struct JNINativeInterface_* jni_functions() { | |
3168 #ifndef JNICHECK_KERNEL | |
3169 if (CheckJNICalls) return jni_functions_check(); | |
3170 #else // JNICHECK_KERNEL | |
3171 if (CheckJNICalls) warning("-Xcheck:jni is not supported in kernel vm."); | |
3172 #endif // JNICHECK_KERNEL | |
3173 return &jni_NativeInterface; | |
3174 } | |
3175 | |
3176 // Returns the function structure | |
3177 struct JNINativeInterface_* jni_functions_nocheck() { | |
3178 return &jni_NativeInterface; | |
3179 } | |
3180 | |
3181 | |
3182 // Invocation API | |
3183 | |
3184 | |
3185 // Forward declaration | |
3186 extern const struct JNIInvokeInterface_ jni_InvokeInterface; | |
3187 | |
3188 // Global invocation API vars | |
3189 volatile jint vm_created = 0; | |
3190 // Indicate whether it is safe to recreate VM | |
3191 volatile jint safe_to_recreate_vm = 1; | |
3192 struct JavaVM_ main_vm = {&jni_InvokeInterface}; | |
3193 | |
3194 | |
3195 #define JAVASTACKSIZE (400 * 1024) /* Default size of a thread java stack */ | |
3196 #define PROCSTACKSIZE 0 /* 0 means default size in HPI */ | |
3197 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL }; | |
3198 | |
3199 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*); | |
3200 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint); | |
3201 | |
3202 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { | |
3203 HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_); | |
3204 JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_; | |
3205 jint ret = JNI_ERR; | |
3206 DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret); | |
3207 | |
3208 if (Threads::is_supported_jni_version(args->version)) { | |
3209 ret = JNI_OK; | |
3210 } | |
3211 // 1.1 style no longer supported in hotspot. | |
3212 // According the JNI spec, we should update args->version on return. | |
3213 // We also use the structure to communicate with launcher about default | |
3214 // stack size. | |
3215 if (args->version == JNI_VERSION_1_1) { | |
3216 args->version = JNI_VERSION_1_2; | |
3217 // javaStackSize is int in arguments structure | |
3218 assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow"); | |
3219 args->javaStackSize = (jint)(ThreadStackSize * K); | |
3220 } | |
3221 return ret; | |
3222 } | |
3223 | |
3224 HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); | |
3225 DT_RETURN_MARK_DECL(CreateJavaVM, jint); | |
3226 | |
3227 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) { | |
3228 HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); | |
3229 | |
3230 jint result = JNI_ERR; | |
3231 DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result); | |
3232 | |
3233 // At the moment it's only possible to have one Java VM, | |
3234 // since some of the runtime state is in global variables. | |
3235 | |
3236 // We cannot use our mutex locks here, since they only work on | |
3237 // Threads. We do an atomic compare and exchange to ensure only | |
3238 // one thread can call this method at a time | |
3239 | |
3240 // We use Atomic::xchg rather than Atomic::add/dec since on some platforms | |
3241 // the add/dec implementations are dependent on whether we are running | |
3242 // on a multiprocessor, and at this stage of initialization the os::is_MP | |
3243 // function used to determine this will always return false. Atomic::xchg | |
3244 // does not have this problem. | |
3245 if (Atomic::xchg(1, &vm_created) == 1) { | |
3246 return JNI_ERR; // already created, or create attempt in progress | |
3247 } | |
3248 if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) { | |
3249 return JNI_ERR; // someone tried and failed and retry not allowed. | |
3250 } | |
3251 | |
3252 assert(vm_created == 1, "vm_created is true during the creation"); | |
3253 | |
3254 /** | |
3255 * Certain errors during initialization are recoverable and do not | |
3256 * prevent this method from being called again at a later time | |
3257 * (perhaps with different arguments). However, at a certain | |
3258 * point during initialization if an error occurs we cannot allow | |
3259 * this function to be called again (or it will crash). In those | |
3260 * situations, the 'canTryAgain' flag is set to false, which atomically | |
3261 * sets safe_to_recreate_vm to 1, such that any new call to | |
3262 * JNI_CreateJavaVM will immediately fail using the above logic. | |
3263 */ | |
3264 bool can_try_again = true; | |
3265 | |
3266 result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again); | |
3267 if (result == JNI_OK) { | |
3268 JavaThread *thread = JavaThread::current(); | |
3269 /* thread is thread_in_vm here */ | |
3270 *vm = (JavaVM *)(&main_vm); | |
3271 *(JNIEnv**)penv = thread->jni_environment(); | |
3272 | |
3273 // Tracks the time application was running before GC | |
3274 RuntimeService::record_application_start(); | |
3275 | |
3276 // Notify JVMTI | |
3277 if (JvmtiExport::should_post_thread_life()) { | |
3278 JvmtiExport::post_thread_start(thread); | |
3279 } | |
3280 // Check if we should compile all classes on bootclasspath | |
3281 NOT_PRODUCT(if (CompileTheWorld) ClassLoader::compile_the_world();) | |
3282 // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. | |
3283 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
3284 } else { | |
3285 if (can_try_again) { | |
3286 // reset safe_to_recreate_vm to 1 so that retrial would be possible | |
3287 safe_to_recreate_vm = 1; | |
3288 } | |
3289 | |
3290 // Creation failed. We must reset vm_created | |
3291 *vm = 0; | |
3292 *(JNIEnv**)penv = 0; | |
3293 // reset vm_created last to avoid race condition. Use OrderAccess to | |
3294 // control both compiler and architectural-based reordering. | |
3295 OrderAccess::release_store(&vm_created, 0); | |
3296 } | |
3297 | |
3298 return result; | |
3299 } | |
3300 | |
3301 HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \ | |
3302 JavaVM**, jsize, jsize*); | |
3303 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint); | |
3304 | |
3305 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) { | |
3306 // See bug 4367188, the wrapper can sometimes cause VM crashes | |
3307 // JNIWrapper("GetCreatedJavaVMs"); | |
3308 HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \ | |
3309 vm_buf, bufLen, numVMs); | |
3310 if (vm_created) { | |
3311 if (numVMs != NULL) *numVMs = 1; | |
3312 if (bufLen > 0) *vm_buf = (JavaVM *)(&main_vm); | |
3313 } else { | |
3314 if (numVMs != NULL) *numVMs = 0; | |
3315 } | |
3316 HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK); | |
3317 return JNI_OK; | |
3318 } | |
3319 | |
3320 extern "C" { | |
3321 | |
3322 DT_RETURN_MARK_DECL(DestroyJavaVM, jint); | |
3323 | |
3324 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) { | |
3325 DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm); | |
3326 jint res = JNI_ERR; | |
3327 DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res); | |
3328 | |
3329 if (!vm_created) { | |
3330 res = JNI_ERR; | |
3331 return res; | |
3332 } | |
3333 | |
3334 JNIWrapper("DestroyJavaVM"); | |
3335 JNIEnv *env; | |
3336 JavaVMAttachArgs destroyargs; | |
3337 destroyargs.version = CurrentVersion; | |
3338 destroyargs.name = (char *)"DestroyJavaVM"; | |
3339 destroyargs.group = NULL; | |
3340 res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs); | |
3341 if (res != JNI_OK) { | |
3342 return res; | |
3343 } | |
3344 | |
3345 // Since this is not a JVM_ENTRY we have to set the thread state manually before entering. | |
3346 JavaThread* thread = JavaThread::current(); | |
3347 ThreadStateTransition::transition_from_native(thread, _thread_in_vm); | |
3348 if (Threads::destroy_vm()) { | |
3349 // Should not change thread state, VM is gone | |
3350 vm_created = false; | |
3351 res = JNI_OK; | |
3352 return res; | |
3353 } else { | |
3354 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
3355 res = JNI_ERR; | |
3356 return res; | |
3357 } | |
3358 } | |
3359 | |
3360 | |
3361 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) { | |
3362 JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args; | |
3363 | |
3364 // Check below commented out from JDK1.2fcs as well | |
3365 /* | |
3366 if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) { | |
3367 return JNI_EVERSION; | |
3368 } | |
3369 */ | |
3370 | |
3371 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
3372 if (t != NULL) { | |
3373 // If the thread has been attached this operation is a no-op | |
3374 *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment(); | |
3375 return JNI_OK; | |
3376 } | |
3377 | |
3378 // Create a thread and mark it as attaching so it will be skipped by the | |
3379 // ThreadsListEnumerator - see CR 6404306 | |
3380 JavaThread* thread = new JavaThread(true); | |
3381 | |
3382 // Set correct safepoint info. The thread is going to call into Java when | |
3383 // initializing the Java level thread object. Hence, the correct state must | |
3384 // be set in order for the Safepoint code to deal with it correctly. | |
3385 thread->set_thread_state(_thread_in_vm); | |
3386 // Must do this before initialize_thread_local_storage | |
3387 thread->record_stack_base_and_size(); | |
3388 thread->initialize_thread_local_storage(); | |
3389 | |
3390 if (!os::create_attached_thread(thread)) { | |
3391 delete thread; | |
3392 return JNI_ERR; | |
3393 } | |
3394 thread->initialize_tlab(); | |
3395 | |
3396 // Crucial that we do not have a safepoint check for this thread, since it has | |
3397 // not been added to the Thread list yet. | |
3398 { Threads_lock->lock_without_safepoint_check(); | |
3399 // This must be inside this lock in order to get FullGCALot to work properly, i.e., to | |
3400 // avoid this thread trying to do a GC before it is added to the thread-list | |
3401 thread->set_active_handles(JNIHandleBlock::allocate_block()); | |
3402 Threads::add(thread, daemon); | |
3403 Threads_lock->unlock(); | |
3404 } | |
3405 // Create thread group and name info from attach arguments | |
3406 oop group = NULL; | |
3407 char* thread_name = NULL; | |
3408 if (args != NULL && Threads::is_supported_jni_version(args->version)) { | |
3409 group = JNIHandles::resolve(args->group); | |
3410 thread_name = args->name; // may be NULL | |
3411 } | |
3412 if (group == NULL) group = Universe::main_thread_group(); | |
3413 | |
3414 // Create Java level thread object and attach it to this thread | |
3415 bool attach_failed = false; | |
3416 { | |
3417 EXCEPTION_MARK; | |
3418 HandleMark hm(THREAD); | |
3419 Handle thread_group(THREAD, group); | |
3420 thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD); | |
3421 if (HAS_PENDING_EXCEPTION) { | |
3422 CLEAR_PENDING_EXCEPTION; | |
3423 // cleanup outside the handle mark. | |
3424 attach_failed = true; | |
3425 } | |
3426 } | |
3427 | |
3428 if (attach_failed) { | |
3429 // Added missing cleanup | |
3430 thread->cleanup_failed_attach_current_thread(); | |
3431 return JNI_ERR; | |
3432 } | |
3433 | |
3434 // mark the thread as no longer attaching | |
3435 // this uses a fence to push the change through so we don't have | |
3436 // to regrab the threads_lock | |
3437 thread->set_attached(); | |
3438 | |
3439 // Enable stack overflow checks | |
3440 thread->create_stack_guard_pages(); | |
3441 | |
3442 // Set java thread status. | |
3443 java_lang_Thread::set_thread_status(thread->threadObj(), | |
3444 java_lang_Thread::RUNNABLE); | |
3445 | |
3446 // Notify the debugger | |
3447 if (JvmtiExport::should_post_thread_life()) { | |
3448 JvmtiExport::post_thread_start(thread); | |
3449 } | |
3450 | |
3451 *(JNIEnv**)penv = thread->jni_environment(); | |
3452 | |
3453 // Now leaving the VM, so change thread_state. This is normally automatically taken care | |
3454 // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by | |
3455 // using ThreadStateTransition::transition, we do a callback to the safepoint code if | |
3456 // needed. | |
3457 | |
3458 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
3459 | |
3460 // Perform any platform dependent FPU setup | |
3461 os::setup_fpu(); | |
3462 | |
3463 return JNI_OK; | |
3464 } | |
3465 | |
3466 | |
3467 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) { | |
3468 DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args); | |
3469 if (!vm_created) { | |
3470 DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR); | |
3471 return JNI_ERR; | |
3472 } | |
3473 | |
3474 JNIWrapper("AttachCurrentThread"); | |
3475 jint ret = attach_current_thread(vm, penv, _args, false); | |
3476 DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret); | |
3477 return ret; | |
3478 } | |
3479 | |
3480 | |
3481 jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { | |
3482 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm); | |
3483 VM_Exit::block_if_vm_exited(); | |
3484 | |
3485 JNIWrapper("DetachCurrentThread"); | |
3486 | |
3487 // If the thread has been deattacted the operations is a no-op | |
3488 if (ThreadLocalStorage::thread() == NULL) { | |
3489 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); | |
3490 return JNI_OK; | |
3491 } | |
3492 | |
3493 JavaThread* thread = JavaThread::current(); | |
3494 if (thread->has_last_Java_frame()) { | |
3495 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR); | |
3496 // Can't detach a thread that's running java, that can't work. | |
3497 return JNI_ERR; | |
3498 } | |
3499 | |
3500 // Safepoint support. Have to do call-back to safepoint code, if in the | |
3501 // middel of a safepoint operation | |
3502 ThreadStateTransition::transition_from_native(thread, _thread_in_vm); | |
3503 | |
3504 // XXX: Note that JavaThread::exit() call below removes the guards on the | |
3505 // stack pages set up via enable_stack_{red,yellow}_zone() calls | |
3506 // above in jni_AttachCurrentThread. Unfortunately, while the setting | |
3507 // of the guards is visible in jni_AttachCurrentThread above, | |
3508 // the removal of the guards is buried below in JavaThread::exit() | |
3509 // here. The abstraction should be more symmetrically either exposed | |
3510 // or hidden (e.g. it could probably be hidden in the same | |
3511 // (platform-dependent) methods where we do alternate stack | |
3512 // maintenance work?) | |
3513 thread->exit(false, JavaThread::jni_detach); | |
3514 delete thread; | |
3515 | |
3516 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); | |
3517 return JNI_OK; | |
3518 } | |
3519 | |
3520 DT_RETURN_MARK_DECL(GetEnv, jint); | |
3521 | |
3522 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) { | |
3523 DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version); | |
3524 jint ret = JNI_ERR; | |
3525 DT_RETURN_MARK(GetEnv, jint, (const jint&)ret); | |
3526 | |
3527 if (!vm_created) { | |
3528 *penv = NULL; | |
3529 ret = JNI_EDETACHED; | |
3530 return ret; | |
3531 } | |
3532 | |
3533 if (JvmtiExport::is_jvmti_version(version)) { | |
3534 ret = JvmtiExport::get_jvmti_interface(vm, penv, version); | |
3535 return ret; | |
3536 } | |
3537 | |
3538 #ifndef JVMPI_VERSION_1 | |
3539 // need these in order to be polite about older agents | |
3540 #define JVMPI_VERSION_1 ((jint)0x10000001) | |
3541 #define JVMPI_VERSION_1_1 ((jint)0x10000002) | |
3542 #define JVMPI_VERSION_1_2 ((jint)0x10000003) | |
3543 #endif // !JVMPI_VERSION_1 | |
3544 | |
3545 Thread* thread = ThreadLocalStorage::thread(); | |
3546 if (thread != NULL && thread->is_Java_thread()) { | |
3547 if (Threads::is_supported_jni_version_including_1_1(version)) { | |
3548 *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment(); | |
3549 ret = JNI_OK; | |
3550 return ret; | |
3551 | |
3552 } else if (version == JVMPI_VERSION_1 || | |
3553 version == JVMPI_VERSION_1_1 || | |
3554 version == JVMPI_VERSION_1_2) { | |
3555 tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported."); | |
3556 tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); | |
3557 ret = JNI_EVERSION; | |
3558 return ret; | |
3559 } else if (JvmtiExport::is_jvmdi_version(version)) { | |
3560 tty->print_cr("FATAL ERROR: JVMDI is no longer supported."); | |
3561 tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); | |
3562 ret = JNI_EVERSION; | |
3563 return ret; | |
3564 } else { | |
3565 *penv = NULL; | |
3566 ret = JNI_EVERSION; | |
3567 return ret; | |
3568 } | |
3569 } else { | |
3570 *penv = NULL; | |
3571 ret = JNI_EDETACHED; | |
3572 return ret; | |
3573 } | |
3574 } | |
3575 | |
3576 | |
3577 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) { | |
3578 DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args); | |
3579 if (!vm_created) { | |
3580 DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR); | |
3581 return JNI_ERR; | |
3582 } | |
3583 | |
3584 JNIWrapper("AttachCurrentThreadAsDaemon"); | |
3585 jint ret = attach_current_thread(vm, penv, _args, true); | |
3586 DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret); | |
3587 return ret; | |
3588 } | |
3589 | |
3590 | |
3591 } // End extern "C" | |
3592 | |
3593 const struct JNIInvokeInterface_ jni_InvokeInterface = { | |
3594 NULL, | |
3595 NULL, | |
3596 NULL, | |
3597 | |
3598 jni_DestroyJavaVM, | |
3599 jni_AttachCurrentThread, | |
3600 jni_DetachCurrentThread, | |
3601 jni_GetEnv, | |
3602 jni_AttachCurrentThreadAsDaemon | |
3603 }; |