0N/A/*
1879N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "runtime/atomic.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "os_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "os_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "os_windows.inline.hpp"
1879N/A#endif
2796N/A#ifdef TARGET_OS_FAMILY_bsd
2796N/A# include "os_bsd.inline.hpp"
2796N/A#endif
1879N/A#ifdef TARGET_OS_ARCH_linux_x86
1879N/A# include "atomic_linux_x86.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_ARCH_linux_sparc
1879N/A# include "atomic_linux_sparc.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_ARCH_linux_zero
1879N/A# include "atomic_linux_zero.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_ARCH_solaris_x86
1879N/A# include "atomic_solaris_x86.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_ARCH_solaris_sparc
1879N/A# include "atomic_solaris_sparc.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_ARCH_windows_x86
1879N/A# include "atomic_windows_x86.inline.hpp"
1879N/A#endif
2621N/A#ifdef TARGET_OS_ARCH_linux_arm
2621N/A# include "atomic_linux_arm.inline.hpp"
2621N/A#endif
2621N/A#ifdef TARGET_OS_ARCH_linux_ppc
2621N/A# include "atomic_linux_ppc.inline.hpp"
2621N/A#endif
2796N/A#ifdef TARGET_OS_ARCH_bsd_x86
2796N/A# include "atomic_bsd_x86.inline.hpp"
2796N/A#endif
2796N/A#ifdef TARGET_OS_ARCH_bsd_zero
2796N/A# include "atomic_bsd_zero.inline.hpp"
2796N/A#endif
0N/A
0N/Ajbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) {
0N/A assert(sizeof(jbyte) == 1, "assumption.");
0N/A uintptr_t dest_addr = (uintptr_t)dest;
0N/A uintptr_t offset = dest_addr % sizeof(jint);
0N/A volatile jint* dest_int = (volatile jint*)(dest_addr - offset);
0N/A jint cur = *dest_int;
0N/A jbyte* cur_as_bytes = (jbyte*)(&cur);
0N/A jint new_val = cur;
0N/A jbyte* new_val_as_bytes = (jbyte*)(&new_val);
0N/A new_val_as_bytes[offset] = exchange_value;
0N/A while (cur_as_bytes[offset] == compare_value) {
0N/A jint res = cmpxchg(new_val, dest_int, cur);
0N/A if (res == cur) break;
0N/A cur = res;
0N/A new_val = cur;
0N/A new_val_as_bytes[offset] = exchange_value;
0N/A }
0N/A return cur_as_bytes[offset];
0N/A}
113N/A
113N/Aunsigned Atomic::xchg(unsigned int exchange_value, volatile unsigned int* dest) {
113N/A assert(sizeof(unsigned int) == sizeof(jint), "more work to do");
113N/A return (unsigned int)Atomic::xchg((jint)exchange_value, (volatile jint*)dest);
113N/A}
113N/A
113N/Aunsigned Atomic::cmpxchg(unsigned int exchange_value,
113N/A volatile unsigned int* dest, unsigned int compare_value) {
113N/A assert(sizeof(unsigned int) == sizeof(jint), "more work to do");
113N/A return (unsigned int)Atomic::cmpxchg((jint)exchange_value, (volatile jint*)dest,
113N/A (jint)compare_value);
113N/A}
2592N/A
2592N/Ajlong Atomic::add(jlong add_value, volatile jlong* dest) {
2592N/A jlong old = load(dest);
2592N/A jlong new_value = old + add_value;
2592N/A while (old != cmpxchg(new_value, dest, old)) {
2592N/A old = load(dest);
2592N/A new_value = old + add_value;
2592N/A }
2592N/A return old;
2592N/A}