--- old/src/share/vm/oops/symbol.hpp 2013-06-20 11:09:46.060663587 -0700 +++ new/src/share/vm/oops/symbol.hpp 2013-06-20 11:09:45.927657017 -0700 @@ -27,6 +27,7 @@ #include "utilities/utf8.hpp" #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" // A Symbol is a canonicalized string. // All Symbols reside in global SymbolTable and are reference counted. @@ -101,14 +102,25 @@ // type without virtual functions. class ClassLoaderData; -class Symbol : public MetaspaceObj { +// We separate the fields in SymbolBase from Symbol::_body so that +// Symbol::size(int) can correctly calculate the space needed. +class SymbolBase : public MetaspaceObj { friend class VMStructs; friend class SymbolTable; friend class MoveSymbols; - private: - volatile int _refcount; + public: + ATOMIC_SHORT_PAIR( + volatile short _refcount, // needs atomic operation + unsigned short _length // number of UTF8 characters in the symbol (does not need atomic op) + ); int _identity_hash; - unsigned short _length; // number of UTF8 characters in the symbol +}; + +class Symbol : private SymbolBase { + friend class VMStructs; + friend class SymbolTable; + friend class MoveSymbols; + private: jbyte _body[1]; enum { @@ -117,7 +129,7 @@ }; static int size(int length) { - size_t sz = heap_word_size(sizeof(Symbol) + (length > 0 ? length - 1 : 0)); + size_t sz = heap_word_size(sizeof(SymbolBase) + (length > 0 ? length : 0)); return align_object_size(sz); }