src/share/vm/runtime/atomic.hpp

changeset 5306
d9eed26d638a
parent 4647
0598674c0056
child 6198
55fb97c4c58d
     1.1 --- a/src/share/vm/runtime/atomic.hpp	Fri Jun 21 10:55:26 2013 -0700
     1.2 +++ b/src/share/vm/runtime/atomic.hpp	Sun Jun 23 22:08:28 2013 -0700
     1.3 @@ -64,11 +64,13 @@
     1.4  
     1.5    // Atomically increment location
     1.6    inline static void inc    (volatile jint*     dest);
     1.7 +         static void inc    (volatile jshort*   dest);
     1.8    inline static void inc_ptr(volatile intptr_t* dest);
     1.9    inline static void inc_ptr(volatile void*     dest);
    1.10  
    1.11    // Atomically decrement a location
    1.12    inline static void dec    (volatile jint*     dest);
    1.13 +         static void dec    (volatile jshort*    dest);
    1.14    inline static void dec_ptr(volatile intptr_t* dest);
    1.15    inline static void dec_ptr(volatile void*     dest);
    1.16  
    1.17 @@ -95,4 +97,24 @@
    1.18    inline static void*    cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value);
    1.19  };
    1.20  
    1.21 +// To use Atomic::inc(jshort* dest) and Atomic::dec(jshort* dest), the address must be specially
    1.22 +// aligned, such that (*dest) occupies the upper 16 bits of an aligned 32-bit word. The best way to
    1.23 +// achieve is to place your short value next to another short value, which doesn't need atomic ops.
    1.24 +//
    1.25 +// Example
    1.26 +//  ATOMIC_SHORT_PAIR(
    1.27 +//    volatile short _refcount,  // needs atomic operation
    1.28 +//    unsigned short _length     // number of UTF8 characters in the symbol (does not need atomic op)
    1.29 +//  );
    1.30 +
    1.31 +#ifdef VM_LITTLE_ENDIAN
    1.32 +#define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \
    1.33 +    non_atomic_decl; \
    1.34 +    atomic_decl
    1.35 +#else
    1.36 +#define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \
    1.37 +    atomic_decl ; \
    1.38 +    non_atomic_decl
    1.39 +#endif
    1.40 +
    1.41  #endif // SHARE_VM_RUNTIME_ATOMIC_HPP

mercurial