atomic_linux_aarch64.hpp revision 11857:d0fbf661cc16
192108Sphk/* 292108Sphk * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 392108Sphk * Copyright (c) 2014, Red Hat Inc. All rights reserved. 492108Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 592108Sphk * 692108Sphk * This code is free software; you can redistribute it and/or modify it 792108Sphk * under the terms of the GNU General Public License version 2 only, as 892108Sphk * published by the Free Software Foundation. 992108Sphk * 1092108Sphk * This code is distributed in the hope that it will be useful, but WITHOUT 1192108Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1292108Sphk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1392108Sphk * version 2 for more details (a copy is included in the LICENSE file that 1492108Sphk * accompanied this code). 1592108Sphk * 1692108Sphk * You should have received a copy of the GNU General Public License version 1792108Sphk * 2 along with this work; if not, write to the Free Software Foundation, 1892108Sphk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1992108Sphk * 2092108Sphk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2192108Sphk * or visit www.oracle.com if you need additional information or have any 2292108Sphk * questions. 2392108Sphk * 2492108Sphk */ 2592108Sphk 2692108Sphk#ifndef OS_CPU_LINUX_AARCH64_VM_ATOMIC_LINUX_AARCH64_HPP 2792108Sphk#define OS_CPU_LINUX_AARCH64_VM_ATOMIC_LINUX_AARCH64_HPP 2892108Sphk 2992108Sphk#include "vm_version_aarch64.hpp" 3092108Sphk 3192108Sphk// Implementation of class atomic 3292108Sphk 3392108Sphk#define FULL_MEM_BARRIER __sync_synchronize() 3492108Sphk#define READ_MEM_BARRIER __atomic_thread_fence(__ATOMIC_ACQUIRE); 3592108Sphk#define WRITE_MEM_BARRIER __atomic_thread_fence(__ATOMIC_RELEASE); 3692108Sphk 3792108Sphkinline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } 3895276Sphkinline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } 3995276Sphkinline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } 4095276Sphkinline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } 4192108Sphkinline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } 4292108Sphk 4392108Sphkinline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } 4492108Sphkinline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } 4595323Sphkinline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } 4695323Sphkinline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } 4792108Sphkinline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } 4895362Sphk 4992108Sphk 5092108Sphkinline jint Atomic::add(jint add_value, volatile jint* dest) 5192108Sphk{ 5292108Sphk return __sync_add_and_fetch(dest, add_value); 5392514Sphk} 5492108Sphk 5592108Sphkinline void Atomic::inc(volatile jint* dest) 5693248Sphk{ 5792108Sphk add(1, dest); 5892108Sphk} 5992108Sphk 6092108Sphkinline void Atomic::inc_ptr(volatile void* dest) 61110541Sphk{ 6292108Sphk add_ptr(1, dest); 6392108Sphk} 6492108Sphk 65106518Sphkinline void Atomic::dec (volatile jint* dest) 6692108Sphk{ 67106518Sphk add(-1, dest); 6893248Sphk} 6993250Sphk 7092108Sphkinline void Atomic::dec_ptr(volatile void* dest) 7192108Sphk{ 7292108Sphk add_ptr(-1, dest); 7392108Sphk} 7492108Sphk 7593250Sphkinline jint Atomic::xchg (jint exchange_value, volatile jint* dest) 7692108Sphk{ 7792108Sphk jint res = __sync_lock_test_and_set (dest, exchange_value); 7892108Sphk FULL_MEM_BARRIER; 79107953Sphk return res; 8092108Sphk} 8192108Sphk 8292108Sphkinline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) 8393248Sphk{ 8493248Sphk return (void *) xchg_ptr((intptr_t) exchange_value, 8593248Sphk (volatile intptr_t*) dest); 8693248Sphk} 87106518Sphk 8892108Sphktemplate <typename T> T generic_cmpxchg(T exchange_value, volatile T* dest, 8993248Sphk T compare_value, cmpxchg_memory_order order) 90107953Sphk{ 9192108Sphk if (order == memory_order_relaxed) { 92106518Sphk T value = compare_value; 9393776Sphk __atomic_compare_exchange(dest, &value, &exchange_value, /*weak*/false, 9493776Sphk __ATOMIC_RELAXED, __ATOMIC_RELAXED); 9598066Sphk return value; 9693776Sphk } else { 9793248Sphk return __sync_val_compare_and_swap(dest, compare_value, exchange_value); 9892108Sphk } 9992108Sphk} 10095310Sphk 10192108Sphk#define VM_HAS_SPECIALIZED_CMPXCHG_BYTE 10292108Sphkinline jbyte Atomic::cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value, cmpxchg_memory_order order) 10398066Sphk{ 10493776Sphk return generic_cmpxchg(exchange_value, dest, compare_value, order); 10592108Sphk} 10693248Sphk 10792108Sphkinline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value, cmpxchg_memory_order order) 10892108Sphk{ 10995310Sphk return generic_cmpxchg(exchange_value, dest, compare_value, order); 11092108Sphk} 11193248Sphk 11292108Sphkinline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } 11392108Sphkinline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } 11492108Sphk 11592108Sphkinline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) 11692108Sphk{ 11792108Sphk return __sync_add_and_fetch(dest, add_value); 11892108Sphk} 11992108Sphk 12093776Sphkinline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) 12193776Sphk{ 12292108Sphk return (void *) add_ptr(add_value, (volatile intptr_t *) dest); 12392108Sphk} 12492108Sphk 12592108Sphkinline void Atomic::inc_ptr(volatile intptr_t* dest) 12692108Sphk{ 12792108Sphk add_ptr(1, dest); 12892108Sphk} 12992108Sphk 13092108Sphkinline void Atomic::dec_ptr(volatile intptr_t* dest) 13192108Sphk{ 13292108Sphk add_ptr(-1, dest); 13392108Sphk} 13492108Sphk 13592108Sphkinline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) 13692108Sphk{ 13792108Sphk intptr_t res = __sync_lock_test_and_set (dest, exchange_value); 13892108Sphk FULL_MEM_BARRIER; 13992108Sphk return res; 14092108Sphk} 14192108Sphk 14292108Sphkinline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value, cmpxchg_memory_order order) 14392108Sphk{ 14492108Sphk return generic_cmpxchg(exchange_value, dest, compare_value, order); 14592108Sphk} 14695310Sphk 14792108Sphkinline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value, cmpxchg_memory_order order) 14892108Sphk{ 14992108Sphk return generic_cmpxchg(exchange_value, dest, compare_value, order); 15092108Sphk} 15192108Sphk 15292108Sphkinline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value, cmpxchg_memory_order order) 15392108Sphk{ 154110541Sphk return (void *) cmpxchg_ptr((intptr_t) exchange_value, 155112026Sphk (volatile intptr_t*) dest, 15692108Sphk (intptr_t) compare_value, 15792108Sphk order); 15892108Sphk} 15992108Sphk 16092108Sphkinline jlong Atomic::load(volatile jlong* src) { return *src; } 16192108Sphk 16295310Sphk#endif // OS_CPU_LINUX_AARCH64_VM_ATOMIC_LINUX_AARCH64_HPP 16392108Sphk