* src/threads/posix/lock.c: Likewise.
* src/threads/posix/thread-posix.c: Likewise.
* src/vm/jit/x86_64/Makefile.am (noinst_HEADERS): Removed
machine-instr.h, added atomic.hpp.
* src/vm/jit/x86_64/asmpart.S (asm_compare_and_swap): Removed.
(asm_memory_barrier): Likewise.
* src/vm/jit/x86_64/atomic.hpp: New file.
* src/vm/jit/x86_64/machine-instr.h: Removed.
--HG--
branch : twisti
#include <stdint.h>
#include <unistd.h>
+#if 0
#include "machine-instr.h"
+#else
+#include "atomic.hpp"
+#endif
#include "mm/memory.h"
*/
JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, java_lang_Object *expected, java_lang_Object *x)
{
-#if 1
+#if 0
void **p;
void *value;
p = (volatile void **) (((uint8_t *) o) + offset);
- result = atomic_compare_and_swap_address(p, expected, x);
+ result = Atomic_cas_ptr(p, expected, x);
if (result == expected)
return true;
*/
JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, sun_misc_Unsafe* this, java_lang_Object* o, int64_t offset, int32_t expected, int32_t x)
{
-#if 1
+#if 0
int32_t *p;
int32_t value;
return false;
#else
- int32_t *p;
- int32_t result;
+ uint32_t *p;
+ uint32_t result;
/* XXX Use LLNI */
- p = (int32_t *) (((uint8_t *) o) + offset);
+ p = (uint32_t *) (((uint8_t *) o) + offset);
- result = atomic_compare_and_swap_int(p, expected, x);
+ result = Atomic_cas_32(p, expected, x);
if (result == expected)
return true;
*/
JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int64_t expected, int64_t x)
{
+#if 0
int64_t *p;
int64_t value;
}
return false;
+#else
+ uint64_t *p;
+ uint64_t result;
+
+ /* XXX Use LLNI */
+
+ p = (uint64_t *) (((uint8_t *) o) + offset);
+
+ result = Atomic_cas_64(p, expected, x);
+
+ if (result == expected)
+ return true;
+
+ return false;
+#endif
}
\
*_p = x; \
\
- MEMORY_BARRIER(); \
+ Atomic_mb(); \
\
LLNI_CRITICAL_END;
*_p = _x;
- MEMORY_BARRIER();
+ Atomic_mb();
LLNI_CRITICAL_END;
}
#if defined(USE_FAKE_ATOMIC_INSTRUCTIONS)
#include "threads/posix/generic-primitives.h"
#else
-#include "machine-instr.h"
+#include "atomic.hpp"
#endif
#if defined(ENABLE_JVMTI)
t->index, t_other->index));
/* Set FLC bit first, then read the lockword again */
- MEMORY_BARRIER();
+ Atomic_mb();
lockword = lock_lockword_get(t, o);
/* most common case: try to thin-lock an unlocked object */
LLNI_CRITICAL_START_THREAD(t);
- lockword = COMPARE_AND_SWAP_OLD_VALUE(&(LLNI_DIRECT(o)->lockword), THIN_UNLOCKED, thinlock);
+ lockword = Atomic_cas_ptr(&(LLNI_DIRECT(o)->lockword), THIN_UNLOCKED, thinlock);
LLNI_CRITICAL_END_THREAD(t);
if (lockword == THIN_UNLOCKED) {
/* memory barrier for Java Memory Model */
STORE_ORDER_BARRIER();
lock_lockword_set(t, o, THIN_UNLOCKED);
- /* memory barrier for thin locking */
- MEMORY_BARRIER();
+ /* Memory barrier for thin locking. */
+ Atomic_mb();
/* check if there has been a flat lock contention on this object */
#include "arch.h"
-#if !defined(USE_FAKE_ATOMIC_INSTRUCTIONS)
-# include "machine-instr.h"
-#else
+#if defined(USE_FAKE_ATOMIC_INSTRUCTIONS)
# include "threads/posix/generic-primitives.h"
#endif
noinst_HEADERS = \
arch.h \
- machine-instr.h \
+ atomic.hpp \
\
md-asm.h
/* src/vm/jit/x86_64/asmpart.S - Java-C interface functions for x86_64
- Copyright (C) 1996-2005, 2006, 2007, 2008 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
.globl asm_builtin_d2i
.globl asm_builtin_d2l
- .globl asm_compare_and_swap
- .globl asm_memory_barrier
-
.globl asm_get_cycle_count
ret
-/* asm_compare_and_swap ********************************************************
-
- Does an atomic compare and swap. Required for the lock
- implementation.
-
-*******************************************************************************/
-
-asm_compare_and_swap:
- mov a1,v0 /* v0 is %rax */
- lock cmpxchg a2,(a0)
- ret
-
-
-/* asm_memory_barrier **********************************************************
-
- A memory barrier for the Java Memory Model.
-
-*******************************************************************************/
-
-asm_memory_barrier:
- mfence
- ret
-
-
/* asm_get_cycle_count *********************************************************
Get the current time-stamp counter from the CPU.
--- /dev/null
+/* src/vm/jit/i386/atomic.hpp - i386 atomic instructions
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _ATOMIC_HPP
+#define _ATOMIC_HPP
+
+#include "config.h"
+
+#include <stdint.h>
+
+
+/**
+ * An atomic compare and swap for 32-bit integer values.
+ *
+ * @param p Pointer to memory address.
+ * @param oldval Old value to be expected.
+ * @param newval New value to be stored.
+ *
+ * @return value of the memory location before the store
+ */
+inline static uint32_t Atomic_cas_32(volatile uint32_t *p, uint32_t oldval, uint32_t newval)
+{
+ int32_t result;
+
+ __asm__ __volatile__ ("lock; cmpxchgl %2, %1"
+ : "=a" (result), "=m" (*p)
+ : "r" (newval), "m" (*p), "0" (oldval));
+
+ return result;
+}
+
+
+/**
+ * An atomic compare and swap for 64-bit integer values.
+ *
+ * @param p Pointer to memory address.
+ * @param oldval Old value to be expected.
+ * @param newval New value to be stored.
+ *
+ * @return value of the memory location before the store
+ */
+inline static uint64_t Atomic_cas_64(volatile uint64_t *p, uint64_t oldval, uint64_t newval)
+{
+ int64_t result;
+
+ __asm__ __volatile__ ("lock; cmpxchgq %2, %1"
+ : "=a" (result), "=m" (*p)
+ : "r" (newval), "m" (*p), "0" (oldval));
+
+ return result;
+}
+
+
+/**
+ * An atomic compare and swap for pointer values.
+ *
+ * @param p Pointer to memory address.
+ * @param oldval Old value to be expected.
+ * @param newval New value to be stored.
+ *
+ * @return value of the memory location before the store
+ */
+inline static void* Atomic_cas_ptr(volatile void** p, void* oldval, void* newval)
+{
+ return (void*) Atomic_cas_64((volatile uint64_t*) p, (uint64_t) oldval, (uint64_t) newval);
+}
+
+
+/**
+ * A memory barrier.
+ */
+inline static void Atomic_mb(void)
+{
+ __asm__ __volatile__ ("mfence" : : : "memory");
+}
+
+
+#define STORE_ORDER_BARRIER() __asm__ __volatile__ ("" : : : "memory");
+#define MEMORY_BARRIER_AFTER_ATOMIC() /* nothing */
+
+#endif /* _ATOMIC_HPP */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
+++ /dev/null
-#ifndef _MACHINE_INSTR_H
-#define _MACHINE_INSTR_H
-
-static inline long
-__attribute__ ((unused))
-compare_and_swap (volatile long *p, long oldval, long newval)
-{
- long ret;
-
- __asm__ __volatile__ ("lock; cmpxchgq %2, %1"
- : "=a" (ret), "=m" (*p)
- : "r" (newval), "m" (*p), "0" (oldval));
- return ret;
-}
-
-#define STORE_ORDER_BARRIER() __asm__ __volatile__ ("" : : : "memory");
-#define MEMORY_BARRIER_AFTER_ATOMIC() /* nothing */
-#define MEMORY_BARRIER() __asm__ __volatile__ ( \
- "mfence" : : : "memory" );
-
-#endif