diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index da53a7532e..6350ef5938 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -2729,11 +2729,15 @@ Avian_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J extern "C" JNIEXPORT int64_t JNICALL Avian_sun_misc_Unsafe_getIntVolatile -(Thread*, object, uintptr_t* arguments) +(Thread* t, object, uintptr_t* arguments) { object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); + // avoid blocking the VM if this is being called in a busy loop + PROTECT(t, o); + { ENTER(t, Thread::IdleState); } + int32_t result = fieldAtOffset(o, offset); loadMemoryBarrier(); return result; @@ -2764,6 +2768,10 @@ Avian_sun_misc_Unsafe_getLongVolatile object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); + // avoid blocking the VM if this is being called in a busy loop + PROTECT(t, o); + { ENTER(t, Thread::IdleState); } + object field; if (BytesPerWord < 8) { field = local::fieldForOffset(t, o, offset); @@ -2869,10 +2877,14 @@ Avian_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ extern "C" JNIEXPORT int64_t JNICALL Avian_sun_misc_Unsafe_getObjectVolatile -(Thread*, object, uintptr_t* arguments) +(Thread* t, object, uintptr_t* arguments) { object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); + + // avoid blocking the VM if this is being called in a busy loop + PROTECT(t, o); + { ENTER(t, Thread::IdleState); } uintptr_t value = fieldAtOffset(o, offset); loadMemoryBarrier();