< prev index next >

src/share/vm/prims/jni.cpp

Print this page




2613   JNIWrapper("GetObjectField");
2614 #ifndef USDT2
2615   DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID);
2616 #else /* USDT2 */
2617   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(
2618                                    env, obj, (uintptr_t) fieldID);
2619 #endif /* USDT2 */
2620   oop o = JNIHandles::resolve_non_null(obj);
2621   Klass* k = o->klass();
2622   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2623   // Keep JVMTI addition small and only check enabled flag here.
2624   // jni_GetField_probe() assumes that is okay to create handles.
2625   if (JvmtiExport::should_post_field_access()) {
2626     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2627   }
2628   jobject ret = JNIHandles::make_local(env, o->obj_field(offset));
2629 #if INCLUDE_ALL_GCS
2630   // If G1 is enabled and we are accessing the value of the referent
2631   // field in a reference object then we need to register a non-null
2632   // referent with the SATB barrier.
2633   if (UseG1GC) {
2634     bool needs_barrier = false;
2635 
2636     if (ret != NULL &&
2637         offset == java_lang_ref_Reference::referent_offset &&
2638         InstanceKlass::cast(k)->reference_type() != REF_NONE) {
2639       assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
2640       needs_barrier = true;
2641     }
2642 
2643     if (needs_barrier) {
2644       oop referent = JNIHandles::resolve(ret);
2645       G1SATBCardTableModRefBS::enqueue(referent);
2646     }
2647   }
2648 #endif // INCLUDE_ALL_GCS
2649 #ifndef USDT2
2650   DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret);
2651 #else /* USDT2 */
2652 HOTSPOT_JNI_GETOBJECTFIELD_RETURN(
2653                                   ret);


4234   int s_len = java_lang_String::length(s);
4235   if (start < 0 || len < 0 || start > s_len - len) {
4236     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
4237   } else {
4238     //%note jni_7
4239     if (len > 0) {
4240       ResourceMark rm(THREAD);
4241       char *utf_region = java_lang_String::as_utf8_string(s, start, len);
4242       int utf_len = (int)strlen(utf_region);
4243       memcpy(buf, utf_region, utf_len);
4244       buf[utf_len] = 0;
4245     } else {
4246       // JDK null-terminates the buffer even in len is zero
4247       if (buf != NULL) {
4248         buf[0] = 0;
4249       }
4250     }
4251   }
4252 JNI_END
4253 


















4254 
4255 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
4256   JNIWrapper("GetPrimitiveArrayCritical");
4257 #ifndef USDT2
4258   DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy);
4259 #else /* USDT2 */
4260  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(
4261                                              env, array, (uintptr_t *) isCopy);
4262 #endif /* USDT2 */
4263   GC_locker::lock_critical(thread);
4264   if (isCopy != NULL) {
4265     *isCopy = JNI_FALSE;
4266   }
4267   oop a = JNIHandles::resolve_non_null(array);
4268   assert(a->is_array(), "just checking");
4269   BasicType type;
4270   if (a->is_objArray()) {
4271     type = T_OBJECT;
4272   } else {
4273     type = TypeArrayKlass::cast(a->klass())->element_type();
4274   }
4275   void* ret = arrayOop(a)->base(type);
4276 #ifndef USDT2
4277   DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret);
4278 #else /* USDT2 */
4279  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(
4280                                               ret);
4281 #endif /* USDT2 */
4282   return ret;
4283 JNI_END
4284 
4285 
4286 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
4287   JNIWrapper("ReleasePrimitiveArrayCritical");
4288 #ifndef USDT2
4289   DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode);
4290 #else /* USDT2 */
4291   HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(
4292                                                   env, array, carray, mode);
4293 #endif /* USDT2 */
4294   // The array, carray and mode arguments are ignored
4295   GC_locker::unlock_critical(thread);
4296 #ifndef USDT2
4297   DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return);
4298 #else /* USDT2 */
4299 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN(
4300 );
4301 #endif /* USDT2 */
4302 JNI_END
4303 
4304 
4305 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
4306   JNIWrapper("GetStringCritical");
4307 #ifndef USDT2
4308   DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy);
4309 #else /* USDT2 */
4310   HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(
4311                                       env, string, (uintptr_t *) isCopy);
4312 #endif /* USDT2 */
4313   GC_locker::lock_critical(thread);
4314   if (isCopy != NULL) {
4315     *isCopy = JNI_FALSE;
4316   }
4317   oop s = JNIHandles::resolve_non_null(string);
4318   int s_len = java_lang_String::length(s);
4319   typeArrayOop s_value = java_lang_String::value(s);
4320   int s_offset = java_lang_String::offset(s);
4321   const jchar* ret;
4322   if (s_len > 0) {
4323     ret = s_value->char_at_addr(s_offset);
4324   } else {
4325     ret = (jchar*) s_value->base(T_CHAR);
4326   }
4327 #ifndef USDT2
4328   DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret);
4329 #else /* USDT2 */
4330  HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN(
4331                                       (uint16_t *) ret);
4332 #endif /* USDT2 */
4333   return ret;
4334 JNI_END
4335 
4336 
4337 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
4338   JNIWrapper("ReleaseStringCritical");
4339 #ifndef USDT2
4340   DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars);
4341 #else /* USDT2 */
4342   HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(
4343                                           env, str, (uint16_t *) chars);
4344 #endif /* USDT2 */
4345   // The str and chars arguments are ignored
4346   GC_locker::unlock_critical(thread);
4347 #ifndef USDT2
4348   DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return);
4349 #else /* USDT2 */
4350 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN(
4351 );
4352 #endif /* USDT2 */
4353 JNI_END
4354 
4355 
4356 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
4357   JNIWrapper("jni_NewWeakGlobalRef");
4358 #ifndef USDT2
4359   DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref);
4360 #else /* USDT2 */
4361  HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(
4362                                     env, ref);
4363 #endif /* USDT2 */
4364   Handle ref_handle(thread, JNIHandles::resolve(ref));
4365   jweak ret = JNIHandles::make_weak_global(ref_handle);
4366 #ifndef USDT2




2613   JNIWrapper("GetObjectField");
2614 #ifndef USDT2
2615   DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID);
2616 #else /* USDT2 */
2617   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(
2618                                    env, obj, (uintptr_t) fieldID);
2619 #endif /* USDT2 */
2620   oop o = JNIHandles::resolve_non_null(obj);
2621   Klass* k = o->klass();
2622   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2623   // Keep JVMTI addition small and only check enabled flag here.
2624   // jni_GetField_probe() assumes that is okay to create handles.
2625   if (JvmtiExport::should_post_field_access()) {
2626     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2627   }
2628   jobject ret = JNIHandles::make_local(env, o->obj_field(offset));
2629 #if INCLUDE_ALL_GCS
2630   // If G1 is enabled and we are accessing the value of the referent
2631   // field in a reference object then we need to register a non-null
2632   // referent with the SATB barrier.
2633   if (UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier)) {
2634     bool needs_barrier = false;
2635 
2636     if (ret != NULL &&
2637         offset == java_lang_ref_Reference::referent_offset &&
2638         InstanceKlass::cast(k)->reference_type() != REF_NONE) {
2639       assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
2640       needs_barrier = true;
2641     }
2642 
2643     if (needs_barrier) {
2644       oop referent = JNIHandles::resolve(ret);
2645       G1SATBCardTableModRefBS::enqueue(referent);
2646     }
2647   }
2648 #endif // INCLUDE_ALL_GCS
2649 #ifndef USDT2
2650   DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret);
2651 #else /* USDT2 */
2652 HOTSPOT_JNI_GETOBJECTFIELD_RETURN(
2653                                   ret);


4234   int s_len = java_lang_String::length(s);
4235   if (start < 0 || len < 0 || start > s_len - len) {
4236     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
4237   } else {
4238     //%note jni_7
4239     if (len > 0) {
4240       ResourceMark rm(THREAD);
4241       char *utf_region = java_lang_String::as_utf8_string(s, start, len);
4242       int utf_len = (int)strlen(utf_region);
4243       memcpy(buf, utf_region, utf_len);
4244       buf[utf_len] = 0;
4245     } else {
4246       // JDK null-terminates the buffer even in len is zero
4247       if (buf != NULL) {
4248         buf[0] = 0;
4249       }
4250     }
4251   }
4252 JNI_END
4253 
4254 static oop lock_gc_or_pin_object(JavaThread* thread, jobject obj) {
4255   if (Universe::heap()->supports_object_pinning()) {
4256     const oop o = JNIHandles::resolve_non_null(obj);
4257     return Universe::heap()->pin_object(thread, o);
4258   } else {
4259     GC_locker::lock_critical(thread);
4260     return JNIHandles::resolve_non_null(obj);
4261   }
4262 }
4263 
4264 static void unlock_gc_or_unpin_object(JavaThread* thread, jobject obj) {
4265   if (Universe::heap()->supports_object_pinning()) {
4266     const oop o = JNIHandles::resolve_non_null(obj);
4267     return Universe::heap()->unpin_object(thread, o);
4268   } else {
4269     GC_locker::unlock_critical(thread);
4270   }
4271 }
4272 
4273 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
4274   JNIWrapper("GetPrimitiveArrayCritical");
4275 #ifndef USDT2
4276   DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy);
4277 #else /* USDT2 */
4278  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(
4279                                              env, array, (uintptr_t *) isCopy);
4280 #endif /* USDT2 */

4281   if (isCopy != NULL) {
4282     *isCopy = JNI_FALSE;
4283   }
4284   oop a = lock_gc_or_pin_object(thread, array);
4285   assert(a->is_array(), "just checking");
4286   BasicType type;
4287   if (a->is_objArray()) {
4288     type = T_OBJECT;
4289   } else {
4290     type = TypeArrayKlass::cast(a->klass())->element_type();
4291   }
4292   void* ret = arrayOop(a)->base(type);
4293 #ifndef USDT2
4294   DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret);
4295 #else /* USDT2 */
4296  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(
4297                                               ret);
4298 #endif /* USDT2 */
4299   return ret;
4300 JNI_END
4301 
4302 
4303 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
4304   JNIWrapper("ReleasePrimitiveArrayCritical");
4305 #ifndef USDT2
4306   DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode);
4307 #else /* USDT2 */
4308   HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(
4309                                                   env, array, carray, mode);
4310 #endif /* USDT2 */
4311   // The array, carray and mode arguments are ignored
4312   unlock_gc_or_unpin_object(thread, array);
4313 #ifndef USDT2
4314   DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return);
4315 #else /* USDT2 */
4316 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN(
4317 );
4318 #endif /* USDT2 */
4319 JNI_END
4320 
4321 
4322 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
4323   JNIWrapper("GetStringCritical");
4324 #ifndef USDT2
4325   DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy);
4326 #else /* USDT2 */
4327   HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(
4328                                       env, string, (uintptr_t *) isCopy);
4329 #endif /* USDT2 */

4330   if (isCopy != NULL) {
4331     *isCopy = JNI_FALSE;
4332   }
4333   oop s = lock_gc_or_pin_object(thread, string);
4334   int s_len = java_lang_String::length(s);
4335   typeArrayOop s_value = java_lang_String::value(s);
4336   int s_offset = java_lang_String::offset(s);
4337   const jchar* ret;
4338   if (s_len > 0) {
4339     ret = s_value->char_at_addr(s_offset);
4340   } else {
4341     ret = (jchar*) s_value->base(T_CHAR);
4342   }
4343 #ifndef USDT2
4344   DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret);
4345 #else /* USDT2 */
4346  HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN(
4347                                       (uint16_t *) ret);
4348 #endif /* USDT2 */
4349   return ret;
4350 JNI_END
4351 
4352 
4353 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
4354   JNIWrapper("ReleaseStringCritical");
4355 #ifndef USDT2
4356   DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars);
4357 #else /* USDT2 */
4358   HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(
4359                                           env, str, (uint16_t *) chars);
4360 #endif /* USDT2 */
4361   // The str and chars arguments are ignored
4362   unlock_gc_or_unpin_object(thread, str);
4363 #ifndef USDT2
4364   DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return);
4365 #else /* USDT2 */
4366 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN(
4367 );
4368 #endif /* USDT2 */
4369 JNI_END
4370 
4371 
4372 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
4373   JNIWrapper("jni_NewWeakGlobalRef");
4374 #ifndef USDT2
4375   DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref);
4376 #else /* USDT2 */
4377  HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(
4378                                     env, ref);
4379 #endif /* USDT2 */
4380   Handle ref_handle(thread, JNIHandles::resolve(ref));
4381   jweak ret = JNIHandles::make_weak_global(ref_handle);
4382 #ifndef USDT2


< prev index next >