From 0a89683effbf41033ae88883c03df29b7ac5aa33 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 3 Mar 2014 14:51:43 -0700 Subject: [PATCH] move Unsafe.get{Object|Int}Volatile from classpath-openjdk.cpp to builtin.cpp This makes them available in all class libraries, not just the OpenJDK library. Note that I've also removed the unecessary idle statements, per ab4adef. --- classpath/sun/misc/Unsafe.java | 4 ++++ src/builtin.cpp | 24 ++++++++++++++++++++++++ src/classpath-openjdk.cpp | 32 -------------------------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/classpath/sun/misc/Unsafe.java b/classpath/sun/misc/Unsafe.java index 21c7c43d62..b581aea0ed 100644 --- a/classpath/sun/misc/Unsafe.java +++ b/classpath/sun/misc/Unsafe.java @@ -46,6 +46,8 @@ public final class Unsafe { public native void putDouble(long address, double x); + public native int getIntVolatile(Object o, long offset); + public native void putIntVolatile(Object o, long offset, int x); public native long getLongVolatile(Object o, long offset); @@ -64,6 +66,8 @@ public final class Unsafe { public native void putOrderedObject(Object o, long offset, Object x); + public native Object getObjectVolatile(Object o, long offset); + public native long getAddress(long address); public native void putAddress(long address, long x); diff --git a/src/builtin.cpp b/src/builtin.cpp index f5733f6ec3..4fe71630e9 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -723,6 +723,18 @@ Avian_sun_misc_Unsafe_putOrderedObject Avian_sun_misc_Unsafe_putObjectVolatile(t, method, arguments); } +extern "C" AVIAN_EXPORT int64_t JNICALL +Avian_sun_misc_Unsafe_getObjectVolatile +(Thread*, object, uintptr_t* arguments) +{ + object o = reinterpret_cast(arguments[1]); + int64_t offset; memcpy(&offset, arguments + 2, 8); + + uintptr_t value = fieldAtOffset(o, offset); + loadMemoryBarrier(); + return value; +} + extern "C" AVIAN_EXPORT int64_t JNICALL Avian_sun_misc_Unsafe_compareAndSwapObject (Thread* t, object, uintptr_t* arguments) @@ -916,6 +928,18 @@ Avian_sun_misc_Unsafe_putOrderedInt Avian_sun_misc_Unsafe_putIntVolatile(t, method, arguments); } +extern "C" AVIAN_EXPORT int64_t JNICALL +Avian_sun_misc_Unsafe_getIntVolatile +(Thread*, object, uintptr_t* arguments) +{ + object o = reinterpret_cast(arguments[1]); + int64_t offset; memcpy(&offset, arguments + 2, 8); + + int32_t result = fieldAtOffset(o, offset); + loadMemoryBarrier(); + return result; +} + extern "C" AVIAN_EXPORT void JNICALL Avian_sun_misc_Unsafe_throwException (Thread* t, object, uintptr_t* arguments) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index e0f1508d2f..91d61a2685 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -2640,22 +2640,6 @@ Avian_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J return fieldAtOffset(o, offset); } -extern "C" AVIAN_EXPORT int64_t JNICALL -Avian_sun_misc_Unsafe_getIntVolatile -(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; -} - extern "C" AVIAN_EXPORT int64_t JNICALL Avian_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J (Thread*, object, uintptr_t* arguments) @@ -2769,22 +2753,6 @@ Avian_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ fieldAtOffset(o, offset) = value; } -extern "C" AVIAN_EXPORT int64_t JNICALL -Avian_sun_misc_Unsafe_getObjectVolatile -(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(); - return value; -} - extern "C" AVIAN_EXPORT int64_t JNICALL Avian_sun_misc_Unsafe_pageSize (Thread*, object, uintptr_t*)