diff src/share/vm/runtime/atomic.hpp @ 11173:6b0fd0964b87

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 31 Jul 2013 11:00:54 +0200
parents d9eed26d638a
children de6a9e811145
line wrap: on
line diff
--- a/src/share/vm/runtime/atomic.hpp	Tue Jul 30 13:03:28 2013 -0700
+++ b/src/share/vm/runtime/atomic.hpp	Wed Jul 31 11:00:54 2013 +0200
@@ -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