Tue, 11 Nov 2014 11:05:41 +0100
8056071: compiler/whitebox/IsMethodCompilableTest.java fails with 'method() is not compilable after 3 iterations'
Summary: Always use MDO if valid and always compile trivial methods with C1 if available.
Reviewed-by: kvn, iveresov
duke@435 | 1 | /* |
mikael@6198 | 2 | * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "runtime/atomic.hpp" |
stefank@2314 | 27 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 28 | # include "os_linux.inline.hpp" |
stefank@2314 | 29 | #endif |
stefank@2314 | 30 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 31 | # include "os_solaris.inline.hpp" |
stefank@2314 | 32 | #endif |
stefank@2314 | 33 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 34 | # include "os_windows.inline.hpp" |
stefank@2314 | 35 | #endif |
goetz@6461 | 36 | #ifdef TARGET_OS_FAMILY_aix |
goetz@6461 | 37 | # include "os_aix.inline.hpp" |
goetz@6461 | 38 | #endif |
never@3156 | 39 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 40 | # include "os_bsd.inline.hpp" |
never@3156 | 41 | #endif |
twisti@4318 | 42 | |
twisti@4318 | 43 | #include "runtime/atomic.inline.hpp" |
duke@435 | 44 | |
duke@435 | 45 | jbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { |
duke@435 | 46 | assert(sizeof(jbyte) == 1, "assumption."); |
duke@435 | 47 | uintptr_t dest_addr = (uintptr_t)dest; |
duke@435 | 48 | uintptr_t offset = dest_addr % sizeof(jint); |
duke@435 | 49 | volatile jint* dest_int = (volatile jint*)(dest_addr - offset); |
duke@435 | 50 | jint cur = *dest_int; |
duke@435 | 51 | jbyte* cur_as_bytes = (jbyte*)(&cur); |
duke@435 | 52 | jint new_val = cur; |
duke@435 | 53 | jbyte* new_val_as_bytes = (jbyte*)(&new_val); |
duke@435 | 54 | new_val_as_bytes[offset] = exchange_value; |
duke@435 | 55 | while (cur_as_bytes[offset] == compare_value) { |
duke@435 | 56 | jint res = cmpxchg(new_val, dest_int, cur); |
duke@435 | 57 | if (res == cur) break; |
duke@435 | 58 | cur = res; |
duke@435 | 59 | new_val = cur; |
duke@435 | 60 | new_val_as_bytes[offset] = exchange_value; |
duke@435 | 61 | } |
duke@435 | 62 | return cur_as_bytes[offset]; |
duke@435 | 63 | } |
coleenp@548 | 64 | |
coleenp@548 | 65 | unsigned Atomic::xchg(unsigned int exchange_value, volatile unsigned int* dest) { |
coleenp@548 | 66 | assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); |
coleenp@548 | 67 | return (unsigned int)Atomic::xchg((jint)exchange_value, (volatile jint*)dest); |
coleenp@548 | 68 | } |
coleenp@548 | 69 | |
coleenp@548 | 70 | unsigned Atomic::cmpxchg(unsigned int exchange_value, |
coleenp@548 | 71 | volatile unsigned int* dest, unsigned int compare_value) { |
coleenp@548 | 72 | assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); |
coleenp@548 | 73 | return (unsigned int)Atomic::cmpxchg((jint)exchange_value, (volatile jint*)dest, |
coleenp@548 | 74 | (jint)compare_value); |
coleenp@548 | 75 | } |
minqi@2964 | 76 | |
minqi@2964 | 77 | jlong Atomic::add(jlong add_value, volatile jlong* dest) { |
minqi@2964 | 78 | jlong old = load(dest); |
minqi@2964 | 79 | jlong new_value = old + add_value; |
minqi@2964 | 80 | while (old != cmpxchg(new_value, dest, old)) { |
minqi@2964 | 81 | old = load(dest); |
minqi@2964 | 82 | new_value = old + add_value; |
minqi@2964 | 83 | } |
minqi@2964 | 84 | return old; |
minqi@2964 | 85 | } |
iklam@5306 | 86 | |
iklam@5306 | 87 | void Atomic::inc(volatile short* dest) { |
iklam@5306 | 88 | // Most platforms do not support atomic increment on a 2-byte value. However, |
iklam@5306 | 89 | // if the value occupies the most significant 16 bits of an aligned 32-bit |
iklam@5306 | 90 | // word, then we can do this with an atomic add of 0x10000 to the 32-bit word. |
iklam@5306 | 91 | // |
iklam@5306 | 92 | // The least significant parts of this 32-bit word will never be affected, even |
iklam@5306 | 93 | // in case of overflow/underflow. |
iklam@5306 | 94 | // |
iklam@5306 | 95 | // Use the ATOMIC_SHORT_PAIR macro to get the desired alignment. |
iklam@5306 | 96 | #ifdef VM_LITTLE_ENDIAN |
iklam@5306 | 97 | assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); |
iklam@5306 | 98 | (void)Atomic::add(0x10000, (volatile int*)(dest-1)); |
iklam@5306 | 99 | #else |
iklam@5306 | 100 | assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); |
iklam@5306 | 101 | (void)Atomic::add(0x10000, (volatile int*)(dest)); |
iklam@5306 | 102 | #endif |
iklam@5306 | 103 | } |
iklam@5306 | 104 | |
iklam@5306 | 105 | void Atomic::dec(volatile short* dest) { |
iklam@5306 | 106 | #ifdef VM_LITTLE_ENDIAN |
iklam@5306 | 107 | assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); |
iklam@5306 | 108 | (void)Atomic::add(-0x10000, (volatile int*)(dest-1)); |
iklam@5306 | 109 | #else |
iklam@5306 | 110 | assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); |
iklam@5306 | 111 | (void)Atomic::add(-0x10000, (volatile int*)(dest)); |
iklam@5306 | 112 | #endif |
iklam@5306 | 113 | } |
iklam@5306 | 114 |