diff --git a/makefile b/makefile index ff4de6b9ec..8a2ea85182 100644 --- a/makefile +++ b/makefile @@ -54,6 +54,18 @@ test-executable = $(executable) boot-classpath = $(classpath-build) embed-prefix = /avian-embedded +native-path = echo + +ifeq ($(build-platform),cygwin) + native-path = cygpath -m +endif + +path-separator = : + +ifneq (,$(filter mingw32 cygwin,$(build-platform))) + path-separator = ; +endif + ifdef openjdk ifdef openjdk-src include openjdk-src.mk @@ -72,11 +84,11 @@ ifdef openjdk options := $(options)-openjdk test-executable = $(executable-dynamic) library-path = LD_LIBRARY_PATH=$(build) - javahome = $(openjdk)/jre + javahome = "$$($(native-path) "$(openjdk)/jre")" endif classpath = openjdk - boot-classpath := $(boot-classpath):$(openjdk)/jre/lib/rt.jar + boot-classpath := "$(boot-classpath)$(path-separator)$$($(native-path) "$(openjdk)/jre/lib/rt.jar")" build-javahome = $(openjdk)/jre endif @@ -127,7 +139,7 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \ common-cflags = $(warnings) -fno-rtti -fno-exceptions -fno-omit-frame-pointer \ "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(build) $(classpath-cflags) \ -D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \ - -DUSE_ATOMIC_OPERATIONS "-DAVIAN_JAVA_HOME=\"$(javahome)\"" \ + -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ @@ -157,8 +169,6 @@ so-suffix = .so shared = -shared -native-path = echo - ifeq ($(arch),i386) pointer-size = 4 endif @@ -241,7 +251,6 @@ ifeq ($(platform),windows) build-cflags += -mno-cygwin lflags += -mno-cygwin cflags += -mno-cygwin - native-path = cygpath -m endif endif diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index a27c4ac9f4..13cab76928 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -1528,11 +1528,11 @@ Avian_sun_misc_Unsafe_compareAndSwapInt { object target = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); - int32_t expect = arguments[4]; - int32_t update = arguments[5]; + uint32_t expect = arguments[4]; + uint32_t update = arguments[5]; - return __sync_bool_compare_and_swap - (&cast(target, offset), expect, update); + return atomicCompareAndSwap32 + (&cast(target, offset), expect, update); } extern "C" JNIEXPORT int64_t JNICALL @@ -1541,11 +1541,11 @@ Avian_sun_misc_Unsafe_compareAndSwapObject { object target = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); - intptr_t expect = arguments[4]; - intptr_t update = arguments[5]; + uintptr_t expect = arguments[4]; + uintptr_t update = arguments[5]; - bool success = __sync_bool_compare_and_swap - (&cast(target, offset), expect, update); + bool success = atomicCompareAndSwap + (&cast(target, offset), expect, update); if (success) { mark(t, target, offset); @@ -1560,11 +1560,11 @@ Avian_sun_misc_Unsafe_compareAndSwapLong { object target = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); - int64_t expect; memcpy(&expect, arguments + 4, 8); - int64_t update; memcpy(&update, arguments + 6, 8); + uint64_t expect; memcpy(&expect, arguments + 4, 8); + uint64_t update; memcpy(&update, arguments + 6, 8); - return __sync_bool_compare_and_swap - (&cast(target, offset), expect, update); + return atomicCompareAndSwap64 + (&cast(target, offset), expect, update); } extern "C" JNIEXPORT int64_t JNICALL diff --git a/src/x86.h b/src/x86.h index 93278cdd7d..f5602b8015 100644 --- a/src/x86.h +++ b/src/x86.h @@ -223,6 +223,19 @@ atomicCompareAndSwap64(uint64_t* p, uint64_t old, uint64_t new_) (reinterpret_cast(p), new_, old); #elif (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 1) return __sync_bool_compare_and_swap(p, old, new_); +#elif defined ARCH_x86_32 + uint8_t result; + + __asm__ __volatile__("lock; cmpxchg8b %0; setz %1" + : "=m"(*p), "=q"(result) + : "a"(static_cast(old)), + "d"(static_cast(old >> 32)), + "b"(static_cast(new_)), + "c"(static_cast(new_ >> 32)), + "m"(*p) + : "memory"); + + return result != 0; #else uint8_t result;