diff src/share/vm/runtime/atomic.hpp @ 11033:d9eed26d638a

8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes Summary: Added Atomic::inc(short*) to support this change. Reviewed-by: coleenp, dcubed, dholmes, minqi
author iklam
date Sun, 23 Jun 2013 22:08:28 -0700
parents 0598674c0056
children de6a9e811145
line wrap: on
line diff
--- a/src/share/vm/runtime/atomic.hpp	Fri Jun 21 10:55:26 2013 -0700
+++ b/src/share/vm/runtime/atomic.hpp	Sun Jun 23 22:08:28 2013 -0700
@@ -64,11 +64,13 @@
 
   // Atomically increment location
   inline static void inc    (volatile jint*     dest);
+         static void inc    (volatile jshort*   dest);
   inline static void inc_ptr(volatile intptr_t* dest);
   inline static void inc_ptr(volatile void*     dest);
 
   // Atomically decrement a location
   inline static void dec    (volatile jint*     dest);
+         static void dec    (volatile jshort*    dest);
   inline static void dec_ptr(volatile intptr_t* dest);
   inline static void dec_ptr(volatile void*     dest);
 
@@ -95,4 +97,24 @@
   inline static void*    cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value);
 };
 
+// To use Atomic::inc(jshort* dest) and Atomic::dec(jshort* dest), the address must be specially
+// aligned, such that (*dest) occupies the upper 16 bits of an aligned 32-bit word. The best way to
+// achieve is to place your short value next to another short value, which doesn't need atomic ops.
+//
+// Example
+//  ATOMIC_SHORT_PAIR(
+//    volatile short _refcount,  // needs atomic operation
+//    unsigned short _length     // number of UTF8 characters in the symbol (does not need atomic op)
+//  );
+
+#ifdef VM_LITTLE_ENDIAN
+#define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \
+    non_atomic_decl; \
+    atomic_decl
+#else
+#define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \
+    atomic_decl ; \
+    non_atomic_decl
+#endif
+
 #endif // SHARE_VM_RUNTIME_ATOMIC_HPP