63 assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); 64 return (unsigned int)Atomic::xchg((jint)exchange_value, (volatile jint*)dest); 65 } 66 67 unsigned Atomic::cmpxchg(unsigned int exchange_value, 68 volatile unsigned int* dest, unsigned int compare_value) { 69 assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); 70 return (unsigned int)Atomic::cmpxchg((jint)exchange_value, (volatile jint*)dest, 71 (jint)compare_value); 72 } 73 74 jlong Atomic::add(jlong add_value, volatile jlong* dest) { 75 jlong old = load(dest); 76 jlong new_value = old + add_value; 77 while (old != cmpxchg(new_value, dest, old)) { 78 old = load(dest); 79 new_value = old + add_value; 80 } 81 return old; 82 } | 63 assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); 64 return (unsigned int)Atomic::xchg((jint)exchange_value, (volatile jint*)dest); 65 } 66 67 unsigned Atomic::cmpxchg(unsigned int exchange_value, 68 volatile unsigned int* dest, unsigned int compare_value) { 69 assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); 70 return (unsigned int)Atomic::cmpxchg((jint)exchange_value, (volatile jint*)dest, 71 (jint)compare_value); 72 } 73 74 jlong Atomic::add(jlong add_value, volatile jlong* dest) { 75 jlong old = load(dest); 76 jlong new_value = old + add_value; 77 while (old != cmpxchg(new_value, dest, old)) { 78 old = load(dest); 79 new_value = old + add_value; 80 } 81 return old; 82 } 83 84 void Atomic::inc(volatile short* dest) { 85 // Most platforms do not support atomic increment on a 2-byte value. However, 86 // if the value occupies the most significant 16 bits of an aligned 32-bit 87 // word, then we can do this with an atomic add of 0x10000 to the 32-bit word. 88 // 89 // The least significant parts of this 32-bit word will never be affected, even 90 // in case of overflow/underflow. 91 // 92 // Use the ATOMIC_SHORT_PAIR macro to get the desired alignment. 93 #ifdef VM_LITTLE_ENDIAN 94 assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); 95 (void)Atomic::add(0x10000, (volatile int*)(dest-1)); 96 #else 97 assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); 98 (void)Atomic::add(0x10000, (volatile int*)(dest)); 99 #endif 100 } 101 102 void Atomic::dec(volatile short* dest) { 103 #ifdef VM_LITTLE_ENDIAN 104 assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); 105 (void)Atomic::add(-0x10000, (volatile int*)(dest-1)); 106 #else 107 assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); 108 (void)Atomic::add(-0x10000, (volatile int*)(dest)); 109 #endif 110 } 111 |