8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes

Added Atomic::inc(short*) to support this change.

Reviewed-by: coleenp, dcubed, dholmes, minqi
This commit is contained in:
Ioi Lam 2013-06-23 22:08:28 -07:00
parent 1c281a9fb3
commit 196c8abc3d
5 changed files with 69 additions and 7 deletions

View file

@ -80,3 +80,32 @@ jlong Atomic::add(jlong add_value, volatile jlong* dest) {
}
return old;
}
void Atomic::inc(volatile short* dest) {
// Most platforms do not support atomic increment on a 2-byte value. However,
// if the value occupies the most significant 16 bits of an aligned 32-bit
// word, then we can do this with an atomic add of 0x10000 to the 32-bit word.
//
// The least significant parts of this 32-bit word will never be affected, even
// in case of overflow/underflow.
//
// Use the ATOMIC_SHORT_PAIR macro to get the desired alignment.
#ifdef VM_LITTLE_ENDIAN
assert((intx(dest) & 0x03) == 0x02, "wrong alignment");
(void)Atomic::add(0x10000, (volatile int*)(dest-1));
#else
assert((intx(dest) & 0x03) == 0x00, "wrong alignment");
(void)Atomic::add(0x10000, (volatile int*)(dest));
#endif
}
void Atomic::dec(volatile short* dest) {
#ifdef VM_LITTLE_ENDIAN
assert((intx(dest) & 0x03) == 0x02, "wrong alignment");
(void)Atomic::add(-0x10000, (volatile int*)(dest-1));
#else
assert((intx(dest) & 0x03) == 0x00, "wrong alignment");
(void)Atomic::add(-0x10000, (volatile int*)(dest));
#endif
}