< prev index next >

src/share/vm/prims/unsafe.cpp

Print this page

        

*** 165,195 **** --- 165,200 ---- #define truncate_jfloat(x) (x) #define truncate_jdouble(x) (x) #define GET_FIELD(obj, offset, type_name, v) \ oop p = JNIHandles::resolve(obj); \ + p = oopDesc::bs()->read_barrier(p); \ type_name v = *(type_name*)index_oop_from_field_offset_long(p, offset) #define SET_FIELD(obj, offset, type_name, x) \ oop p = JNIHandles::resolve(obj); \ + p = oopDesc::bs()->write_barrier(p); \ *(type_name*)index_oop_from_field_offset_long(p, offset) = truncate_##type_name(x) #define GET_FIELD_VOLATILE(obj, offset, type_name, v) \ oop p = JNIHandles::resolve(obj); \ + p = oopDesc::bs()->read_barrier(p); \ if (support_IRIW_for_not_multiple_copy_atomic_cpu) { \ OrderAccess::fence(); \ } \ volatile type_name v = OrderAccess::load_acquire((volatile type_name*)index_oop_from_field_offset_long(p, offset)); #define SET_FIELD_VOLATILE(obj, offset, type_name, x) \ oop p = JNIHandles::resolve(obj); \ + p = oopDesc::bs()->write_barrier(p); \ OrderAccess::release_store_fence((volatile type_name*)index_oop_from_field_offset_long(p, offset), truncate_##type_name(x)); // Macros for oops that check UseCompressedOops #define GET_OOP_FIELD(obj, offset, v) \ oop p = JNIHandles::resolve(obj); \ + p = oopDesc::bs()->read_barrier(p); \ oop v; \ if (UseCompressedOops) { \ narrowOop n = *(narrowOop*)index_oop_from_field_offset_long(p, offset); \ v = oopDesc::decode_heap_oop(n); \ } else { \
*** 216,226 **** } #endif static void ensure_satb_referent_alive(oop o, jlong offset, oop v) { #if INCLUDE_ALL_GCS ! if (UseG1GC && v != NULL && is_java_lang_ref_Reference_access(o, offset)) { G1SATBCardTableModRefBS::enqueue(v); } #endif } --- 221,231 ---- } #endif static void ensure_satb_referent_alive(oop o, jlong offset, oop v) { #if INCLUDE_ALL_GCS ! if ((UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier)) && v != NULL && is_java_lang_ref_Reference_access(o, offset)) { G1SATBCardTableModRefBS::enqueue(v); } #endif }
*** 236,248 **** UNSAFE_END UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h)) UnsafeWrapper("Unsafe_SetObject"); if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); ! oop x = JNIHandles::resolve(x_h); //SET_FIELD(obj, offset, oop, x); ! oop p = JNIHandles::resolve(obj); if (UseCompressedOops) { if (x != NULL) { // If there is a heap base pointer, we are obliged to emit a store barrier. oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); } else { --- 241,253 ---- UNSAFE_END UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h)) UnsafeWrapper("Unsafe_SetObject"); if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); ! oop x = oopDesc::bs()->read_barrier(JNIHandles::resolve(x_h)); //SET_FIELD(obj, offset, oop, x); ! oop p = oopDesc::bs()->write_barrier(JNIHandles::resolve(obj)); if (UseCompressedOops) { if (x != NULL) { // If there is a heap base pointer, we are obliged to emit a store barrier. oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); } else {
*** 271,292 **** return JNIHandles::make_local(env, v); UNSAFE_END UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) UnsafeWrapper("Unsafe_SetObject"); ! oop x = JNIHandles::resolve(x_h); ! oop p = JNIHandles::resolve(obj); if (UseCompressedOops) { oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); } else { oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); } UNSAFE_END UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) UnsafeWrapper("Unsafe_GetObjectVolatile"); oop p = JNIHandles::resolve(obj); void* addr = index_oop_from_field_offset_long(p, offset); volatile oop v; if (UseCompressedOops) { volatile narrowOop n = *(volatile narrowOop*) addr; (void)const_cast<oop&>(v = oopDesc::decode_heap_oop(n)); --- 276,298 ---- return JNIHandles::make_local(env, v); UNSAFE_END UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) UnsafeWrapper("Unsafe_SetObject"); ! oop x = oopDesc::bs()->read_barrier(JNIHandles::resolve(x_h)); ! oop p = oopDesc::bs()->write_barrier(JNIHandles::resolve(obj)); if (UseCompressedOops) { oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); } else { oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); } UNSAFE_END UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) UnsafeWrapper("Unsafe_GetObjectVolatile"); oop p = JNIHandles::resolve(obj); + p = oopDesc::bs()->read_barrier(p); void* addr = index_oop_from_field_offset_long(p, offset); volatile oop v; if (UseCompressedOops) { volatile narrowOop n = *(volatile narrowOop*) addr; (void)const_cast<oop&>(v = oopDesc::decode_heap_oop(n));
*** 302,311 **** --- 308,319 ---- UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) UnsafeWrapper("Unsafe_SetObjectVolatile"); oop x = JNIHandles::resolve(x_h); oop p = JNIHandles::resolve(obj); + x = oopDesc::bs()->read_barrier(x); + p = oopDesc::bs()->write_barrier(p); void* addr = index_oop_from_field_offset_long(p, offset); OrderAccess::release(); if (UseCompressedOops) { oop_store((narrowOop*)addr, x); } else {
*** 350,360 **** GET_FIELD_VOLATILE(obj, offset, jlong, v); return v; } else { Handle p (THREAD, JNIHandles::resolve(obj)); ! jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); jlong value = Atomic::load(addr); return value; } } --- 358,368 ---- GET_FIELD_VOLATILE(obj, offset, jlong, v); return v; } else { Handle p (THREAD, JNIHandles::resolve(obj)); ! jlong* addr = (jlong*)(index_oop_from_field_offset_long(oopDesc::bs()->read_barrier(p()), offset)); MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); jlong value = Atomic::load(addr); return value; } }
*** 366,376 **** if (VM_Version::supports_cx8()) { SET_FIELD_VOLATILE(obj, offset, jlong, x); } else { Handle p (THREAD, JNIHandles::resolve(obj)); ! jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); Atomic::store(x, addr); } } UNSAFE_END --- 374,384 ---- if (VM_Version::supports_cx8()) { SET_FIELD_VOLATILE(obj, offset, jlong, x); } else { Handle p (THREAD, JNIHandles::resolve(obj)); ! jlong* addr = (jlong*)(index_oop_from_field_offset_long(oopDesc::bs()->write_barrier(p()), offset)); MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); Atomic::store(x, addr); } } UNSAFE_END
*** 454,463 **** --- 462,473 ---- UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) UnsafeWrapper("Unsafe_SetOrderedObject"); oop x = JNIHandles::resolve(x_h); oop p = JNIHandles::resolve(obj); + x = oopDesc::bs()->read_barrier(x); + p = oopDesc::bs()->write_barrier(p); void* addr = index_oop_from_field_offset_long(p, offset); OrderAccess::release(); if (UseCompressedOops) { oop_store((narrowOop*)addr, x); } else {
*** 476,486 **** if (VM_Version::supports_cx8()) { SET_FIELD_VOLATILE(obj, offset, jlong, x); } else { Handle p (THREAD, JNIHandles::resolve(obj)); ! jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); Atomic::store(x, addr); } } #endif --- 486,496 ---- if (VM_Version::supports_cx8()) { SET_FIELD_VOLATILE(obj, offset, jlong, x); } else { Handle p (THREAD, JNIHandles::resolve(obj)); ! jlong* addr = (jlong*)(index_oop_from_field_offset_long(oopDesc::bs()->write_barrier(p()), offset)); MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); Atomic::store(x, addr); } } #endif
*** 664,673 **** --- 674,684 ---- size_t sz = (size_t)size; if (sz != (julong)size || size < 0) { THROW(vmSymbols::java_lang_IllegalArgumentException()); } oop base = JNIHandles::resolve(obj); + base = oopDesc::bs()->write_barrier(base); void* p = index_oop_from_field_offset_long(base, offset); Copy::fill_to_memory_atomic(p, sz, value); UNSAFE_END UNSAFE_ENTRY(void, Unsafe_CopyMemory(JNIEnv *env, jobject unsafe, jlong srcAddr, jlong dstAddr, jlong size))
*** 693,702 **** --- 704,715 ---- if (sz != (julong)size || size < 0) { THROW(vmSymbols::java_lang_IllegalArgumentException()); } oop srcp = JNIHandles::resolve(srcObj); oop dstp = JNIHandles::resolve(dstObj); + srcp = oopDesc::bs()->read_barrier(srcp); + dstp = oopDesc::bs()->write_barrier(dstp); if (dstp != NULL && !dstp->is_typeArray()) { // NYI: This works only for non-oop arrays at present. // Generalizing it would be reasonable, but requires card marking. // Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad. THROW(vmSymbols::java_lang_IllegalArgumentException());
*** 1200,1227 **** UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) UnsafeWrapper("Unsafe_CompareAndSwapObject"); oop x = JNIHandles::resolve(x_h); oop e = JNIHandles::resolve(e_h); oop p = JNIHandles::resolve(obj); HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset); ! oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e, true); ! jboolean success = (res == e); ! if (success) ! update_barrier_set((void*)addr, x); ! return success; UNSAFE_END UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) UnsafeWrapper("Unsafe_CompareAndSwapInt"); ! oop p = JNIHandles::resolve(obj); jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); return (jint)(Atomic::cmpxchg(x, addr, e)) == e; UNSAFE_END UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) UnsafeWrapper("Unsafe_CompareAndSwapLong"); ! Handle p (THREAD, JNIHandles::resolve(obj)); jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); #ifdef SUPPORTS_NATIVE_CX8 return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; #else if (VM_Version::supports_cx8()) --- 1213,1261 ---- UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) UnsafeWrapper("Unsafe_CompareAndSwapObject"); oop x = JNIHandles::resolve(x_h); oop e = JNIHandles::resolve(e_h); oop p = JNIHandles::resolve(obj); + + p = oopDesc::bs()->write_barrier(p); + x = oopDesc::bs()->read_barrier(x); + HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset); ! jboolean success; ! #if INCLUDE_ALL_GCS ! if (UseShenandoahGC && ShenandoahCASBarrier) { ! oop expected; ! do { ! expected = e; ! e = oopDesc::atomic_compare_exchange_oop(x, addr, expected, true); ! success = oopDesc::unsafe_equals(e, expected); ! } while ((! success) && oopDesc::unsafe_equals(oopDesc::bs()->read_barrier(e), oopDesc::bs()->read_barrier(expected))); ! } else ! #endif ! { ! success = oopDesc::unsafe_equals(e, oopDesc::atomic_compare_exchange_oop(x, addr, e, true)); ! } ! if (! success) { ! return false; ! } ! ! update_barrier_set((void*)addr, x); ! ! return true; UNSAFE_END UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) UnsafeWrapper("Unsafe_CompareAndSwapInt"); ! // We are about to write to this entry so check to see if we need to copy it. ! oop p = oopDesc::bs()->write_barrier(JNIHandles::resolve(obj)); jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); return (jint)(Atomic::cmpxchg(x, addr, e)) == e; UNSAFE_END UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) UnsafeWrapper("Unsafe_CompareAndSwapLong"); ! Handle p (THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve(obj))); jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); #ifdef SUPPORTS_NATIVE_CX8 return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; #else if (VM_Version::supports_cx8())
< prev index next >