Extra Zero/Shark patches for review
Christos Zoulas
christos at zoulas.com
Sat Nov 21 14:03:49 PST 2009
On Nov 20, 8:27am, glewis at eyesbeyond.com (Greg Lewis) wrote:
-- Subject: Re: Extra Zero/Shark patches for review
Here's the complete set of changes to build zero on NetBSD/amd64. I would
commit them myself, but you know what will happen if I do.. :-(
1. Don't use OS_NAME is not defined yet.
2. Set the run path for NetBSD
3. atomic fixes for NetBSD
4. rest of changes greg posted for zero build
5,6. Fix the build for ia64. Is this hack needed?
Best,
christos
diff -r d6e9dd8952b4 make/bsd/makefiles/zeroshark.make
--- a/make/bsd/makefiles/zeroshark.make Tue Nov 17 08:32:33 2009 -0500
+++ b/make/bsd/makefiles/zeroshark.make Sat Nov 21 16:58:11 2009 -0500
@@ -44,16 +44,18 @@
ifdef ALT_PACKAGE_PATH
PACKAGE_PATH = $(ALT_PACKAGE_PATH)
else
- ifeq ($(OS_VENDOR), Apple)
+ ifeq ($(OS_VENDOR),Apple)
PACKAGE_PATH = /opt/local
else
- ifeq ($(OS_NAME), netbsd)
+ ifeq ($(OS_VENDOR),NetBSD)
PACKAGE_PATH = /usr/pkg
+ LIBS += -Wl,-R${PACKAGE_PATH}/lib
else
PACKAGE_PATH = /usr/local
endif
endif
endif
+
CFLAGS += -I$(PACKAGE_PATH)/include
LIBS += -L$(PACKAGE_PATH)/lib -lffi
diff -r d6e9dd8952b4 src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp
--- a/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp Tue Nov 17 08:32:33 2009 -0500
+++ b/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp Sat Nov 21 16:58:11 2009 -0500
@@ -23,136 +23,63 @@
*
*/
-// Implementation of class atomic
+#include <sys/types.h>
+#ifdef __NetBSD__
+#include <sys/atomic.h>
+#else
-#ifdef M68K
+#include <machine/atomic.h>
-/*
- * __m68k_cmpxchg
- *
- * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
- * Returns newval on success and oldval if no exchange happened.
- * This implementation is processor specific and works on
- * 68020 68030 68040 and 68060.
- *
- * It will not work on ColdFire, 68000 and 68010 since they lack the CAS
- * instruction.
- * Using a kernelhelper would be better for arch complete implementation.
- *
- */
+#define atomic_add_int_nv(av, d) atomic_add_int(av, d), *d
+#define atomic_add_ptr_nv(av, d) atomic_add_ptr(av, d), *d
-static inline int __m68k_cmpxchg(int oldval, int newval, volatile int *ptr) {
- int ret;
- __asm __volatile ("cas%.l %0,%2,%1"
- : "=d" (ret), "+m" (*(ptr))
- : "d" (newval), "0" (oldval));
- return ret;
+static __inline __attribute__((__always_inline__))
+unsigned int
+atomic_swap_uint(volatile unsigned int *dest, unsigned int exchange_value)
+{
+ jint prev = *dest;
+ atomic_store_rel_int(dest, exchange_value);
+ return prev;
}
-/* Perform an atomic compare and swap: if the current value of `*PTR'
- is OLDVAL, then write NEWVAL into `*PTR'. Return the contents of
- `*PTR' before the operation.*/
-static inline int m68k_compare_and_swap(volatile int *ptr,
- int oldval,
- int newval) {
- for (;;) {
- int prev = *ptr;
- if (prev != oldval)
- return prev;
-
- if (__m68k_cmpxchg (prev, newval, ptr) == newval)
- // Success.
- return prev;
-
- // We failed even though prev == oldval. Try again.
- }
+static __inline __attribute__((__always_inline__))
+void *
+atomic_swap_ptr(volatile void *dest, void *exchange_value)
+{
+ void *prev = *(void **)dest;
+ atomic_store_rel_int(dest, exchange_value);
+ return prev;
}
-/* Atomically add an int to memory. */
-static inline int m68k_add_and_fetch(volatile int *ptr, int add_value) {
- for (;;) {
- // Loop until success.
-
- int prev = *ptr;
-
- if (__m68k_cmpxchg (prev, prev + add_value, ptr) == prev + add_value)
- return prev + add_value;
- }
+static __inline __attribute__((__always_inline__))
+unsigned int
+atomic_cas_uint(volatile unsigned int *dest, unsigned int compare_value,
+ unsigned int exchange_value)
+{
+ unsigned int prev = *dest;
+ atomic_cmpset_int(dest, compare_value, exchange_value);
+ return prev;
}
-/* Atomically write VALUE into `*PTR' and returns the previous
- contents of `*PTR'. */
-static inline int m68k_lock_test_and_set(volatile int *ptr, int newval) {
- for (;;) {
- // Loop until success.
- int prev = *ptr;
-
- if (__m68k_cmpxchg (prev, newval, ptr) == prev)
- return prev;
- }
-}
-#endif // M68K
-
-#ifdef ARM
-
-/*
- * __kernel_cmpxchg
- *
- * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
- * Return zero if *ptr was changed or non-zero if no exchange happened.
- * The C flag is also set if *ptr was changed to allow for assembly
- * optimization in the calling code.
- *
- */
-
-typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
-#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
-
-
-
-/* Perform an atomic compare and swap: if the current value of `*PTR'
- is OLDVAL, then write NEWVAL into `*PTR'. Return the contents of
- `*PTR' before the operation.*/
-static inline int arm_compare_and_swap(volatile int *ptr,
- int oldval,
- int newval) {
- for (;;) {
- int prev = *ptr;
- if (prev != oldval)
- return prev;
-
- if (__kernel_cmpxchg (prev, newval, ptr) == 0)
- // Success.
- return prev;
-
- // We failed even though prev == oldval. Try again.
- }
+static __inline __attribute__((__always_inline__))
+unsigned long
+atomic_cas_ulong(volatile unsigned long *dest, unsigned long compare_value,
+ unsigned long exchange_value)
+{
+ unsigned long prev = *dest;
+ atomic_cmpset_long(dest, compare_value, exchange_value);
+ return prev;
}
-/* Atomically add an int to memory. */
-static inline int arm_add_and_fetch(volatile int *ptr, int add_value) {
- for (;;) {
- // Loop until a __kernel_cmpxchg succeeds.
-
- int prev = *ptr;
-
- if (__kernel_cmpxchg (prev, prev + add_value, ptr) == 0)
- return prev + add_value;
- }
+static __inline __attribute__((__always_inline__))
+unsigned void *
+atomic_cas_ptr(volatile void *dest, void *compare_value, void *exchange_value)
+{
+ void *prev = *(void **)dest;
+ atomic_cmpset_ptr(dest, compare_value, exchange_value);
+ return prev;
}
-
-/* Atomically write VALUE into `*PTR' and returns the previous
- contents of `*PTR'. */
-static inline int arm_lock_test_and_set(volatile int *ptr, int newval) {
- for (;;) {
- // Loop until a __kernel_cmpxchg succeeds.
- int prev = *ptr;
-
- if (__kernel_cmpxchg (prev, newval, ptr) == 0)
- return prev;
- }
-}
-#endif // ARM
+#endif
inline void Atomic::store(jint store_value, volatile jint* dest) {
*dest = store_value;
@@ -163,31 +90,15 @@
}
inline jint Atomic::add(jint add_value, volatile jint* dest) {
-#ifdef ARM
- return arm_add_and_fetch(dest, add_value);
-#else
-#ifdef M68K
- return m68k_add_and_fetch(dest, add_value);
-#else
- return __sync_add_and_fetch(dest, add_value);
-#endif // M68K
-#endif // ARM
+ return atomic_add_int_nv((volatile u_int*) dest, add_value);
}
inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
-#ifdef ARM
- return arm_add_and_fetch(dest, add_value);
-#else
-#ifdef M68K
- return m68k_add_and_fetch(dest, add_value);
-#else
- return __sync_add_and_fetch(dest, add_value);
-#endif // M68K
-#endif // ARM
+ return (intptr_t)atomic_add_ptr_nv((volatile void *)dest, add_value);
}
inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
- return (void *) add_ptr(add_value, (volatile intptr_t *) dest);
+ return atomic_add_ptr_nv(dest, add_value);
}
inline void Atomic::inc(volatile jint* dest) {
@@ -215,79 +126,41 @@
}
inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
-#ifdef ARM
- return arm_lock_test_and_set(dest, exchange_value);
-#else
-#ifdef M68K
- return m68k_lock_test_and_set(dest, exchange_value);
-#else
- // __sync_lock_test_and_set is a bizarrely named atomic exchange
- // operation. Note that some platforms only support this with the
- // limitation that the only valid value to store is the immediate
- // constant 1. There is a test for this in JNI_CreateJavaVM().
- return __sync_lock_test_and_set (dest, exchange_value);
-#endif // M68K
-#endif // ARM
+ return (jint)atomic_swap_uint((volatile u_int *)dest, (u_int)exchange_value);
}
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value,
volatile intptr_t* dest) {
-#ifdef ARM
- return arm_lock_test_and_set(dest, exchange_value);
-#else
-#ifdef M68K
- return m68k_lock_test_and_set(dest, exchange_value);
-#else
- return __sync_lock_test_and_set (dest, exchange_value);
-#endif // M68K
-#endif // ARM
+ return (intptr_t)atomic_swap_ptr((volatile void *)dest,
+ (void *)exchange_value);
}
inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
- return (void *) xchg_ptr((intptr_t) exchange_value,
- (volatile intptr_t*) dest);
+ return atomic_swap_ptr(dest, exchange_value);
}
inline jint Atomic::cmpxchg(jint exchange_value,
volatile jint* dest,
jint compare_value) {
-#ifdef ARM
- return arm_compare_and_swap(dest, compare_value, exchange_value);
-#else
-#ifdef M68K
- return m68k_compare_and_swap(dest, compare_value, exchange_value);
-#else
- return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
-#endif // M68K
-#endif // ARM
+ return atomic_cas_uint((volatile u_int *)dest, compare_value, exchange_value);
}
inline jlong Atomic::cmpxchg(jlong exchange_value,
volatile jlong* dest,
jlong compare_value) {
-
- return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
+ return atomic_cas_ulong((volatile u_long *)dest, compare_value,
+ exchange_value);
}
inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value,
volatile intptr_t* dest,
intptr_t compare_value) {
-#ifdef ARM
- return arm_compare_and_swap(dest, compare_value, exchange_value);
-#else
-#ifdef M68K
- return m68k_compare_and_swap(dest, compare_value, exchange_value);
-#else
- return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
-#endif // M68K
-#endif // ARM
+ return (intptr_t)atomic_cas_ptr((volatile void *)dest, (void *)compare_value,
+ (void *)exchange_value);
}
inline void* Atomic::cmpxchg_ptr(void* exchange_value,
volatile void* dest,
void* compare_value) {
-
- return (void *) cmpxchg_ptr((intptr_t) exchange_value,
- (volatile intptr_t*) dest,
- (intptr_t) compare_value);
+ return atomic_cas_ptr((volatile void *)dest, compare_value, exchange_value);
}
diff -r d6e9dd8952b4 src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp
--- a/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp Tue Nov 17 08:32:33 2009 -0500
+++ b/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp Sat Nov 21 16:58:11 2009 -0500
@@ -23,6 +23,10 @@
*
*/
+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__)
+# include <pthread_np.h> /* For pthread_attr_get_np */
+#endif
+
// do not include precompiled header file
#include "incls/_os_bsd_zero.cpp.incl"
@@ -145,6 +149,7 @@
thread->disable_stack_red_zone();
ShouldNotCallThis();
}
+#ifndef _ALLBSD_SOURCE
else {
// Accessing stack address below sp may cause SEGV if
// current thread has MAP_GROWSDOWN stack. This should
@@ -163,6 +168,7 @@
fatal("recursive segv. expanding stack.");
}
}
+#endif
}
}
@@ -230,6 +236,7 @@
// Nothing to do
}
+#ifndef _ALLBSD_SOURCE
int os::Bsd::get_fpu_control_word() {
ShouldNotCallThis();
}
@@ -237,6 +244,7 @@
void os::Bsd::set_fpu_control_word(int fpu) {
ShouldNotCallThis();
}
+#endif
bool os::is_allocatable(size_t bytes) {
ShouldNotCallThis();
@@ -267,6 +275,48 @@
}
static void current_stack_region(address *bottom, size_t *size) {
+ address stack_bottom;
+ address stack_top;
+ size_t stack_bytes;
+
+#ifdef __APPLE__
+ pthread_t self = pthread_self();
+ stack_top = (address) pthread_get_stackaddr_np(self);
+ stack_bytes = pthread_get_stacksize_np(self);
+ stack_bottom = stacktop - stack_bytes;
+#elif defined(__OpenBSD__)
+ stack_t ss;
+ int rslt = pthread_stackseg_np(pthread_self(), &ss);
+
+ if (rslt != 0)
+ fatal1("pthread_stackseg_np failed with err = %d", rslt);
+
+ stack_top = (address) ss.ss_sp;
+ stack_bytes = ss.ss_size;
+ stack_bottom = stacktop - stack_bytes;
+#elif defined(_ALLBSD_SOURCE)
+ pthread_attr_t attr;
+
+ int rslt = pthread_attr_init(&attr);
+
+ // JVM needs to know exact stack location, abort if it fails
+ if (rslt != 0)
+ fatal1("pthread_attr_init failed with err = %d", rslt);
+
+ rslt = pthread_attr_get_np(pthread_self(), &attr);
+
+ if (rslt != 0)
+ fatal1("pthread_attr_get_np failed with err = %d", rslt);
+
+ if (pthread_attr_getstackaddr(&attr, (void **) &stack_bottom) != 0 ||
+ pthread_attr_getstacksize(&attr, &stack_bytes) != 0) {
+ fatal("Can not locate current stack attributes!");
+ }
+
+ pthread_attr_destroy(&attr);
+
+ stack_top = stack_bottom + stack_bytes;
+#else /* Linux */
pthread_attr_t attr;
int res = pthread_getattr_np(pthread_self(), &attr);
if (res != 0) {
@@ -278,13 +328,11 @@
}
}
- address stack_bottom;
- size_t stack_bytes;
res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes);
if (res != 0) {
fatal1("pthread_attr_getstack failed with errno = %d", res);
}
- address stack_top = stack_bottom + stack_bytes;
+ stack_top = stack_bottom + stack_bytes;
// The block of memory returned by pthread_attr_getstack() includes
// guard pages where present. We need to trim these off.
@@ -326,6 +374,7 @@
stack_bottom = stack_top - stack_bytes;
}
+#endif
assert(os::current_stack_pointer() >= stack_bottom, "should do");
assert(os::current_stack_pointer() < stack_top, "should do");
diff -r d6e9dd8952b4 src/share/vm/interpreter/bytecodeInterpreter.cpp
--- a/src/share/vm/interpreter/bytecodeInterpreter.cpp Tue Nov 17 08:32:33 2009 -0500
+++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp Sat Nov 21 16:58:11 2009 -0500
@@ -383,6 +383,9 @@
if (THREAD->has_pending_exception()) goto label; \
}
+#ifdef IA64
+static double ia64_double_zero = 0.0;
+#endif
/*
* BytecodeInterpreter::run(interpreterState istate)
* BytecodeInterpreter::runWithChecks(interpreterState istate)
diff -r d6e9dd8952b4 src/share/vm/opto/connode.cpp
--- a/src/share/vm/opto/connode.cpp Tue Nov 17 08:32:33 2009 -0500
+++ b/src/share/vm/opto/connode.cpp Sat Nov 21 16:58:11 2009 -0500
@@ -707,6 +707,9 @@
//=============================================================================
//------------------------------Value------------------------------------------
+#ifdef IA64
+static double ia64_double_zero = 0.0;
+#endif
const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
const Type *t = phase->type( in(1) );
if( t == Type::TOP ) return Type::TOP;
More information about the bsd-port-dev
mailing list