diff src/share/vm/oops/symbol.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 63e54c37ac64
children 9758d9f36299
line wrap: on
line diff
--- a/src/share/vm/oops/symbol.hpp	Fri Jun 21 10:55:26 2013 -0700
+++ b/src/share/vm/oops/symbol.hpp	Sun Jun 23 22:08:28 2013 -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,22 @@
 // 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 {
+ 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;
+};
+
+class Symbol : private SymbolBase {
   friend class VMStructs;
   friend class SymbolTable;
   friend class MoveSymbols;
  private:
-  volatile int   _refcount;
-  int            _identity_hash;
-  unsigned short _length; // number of UTF8 characters in the symbol
   jbyte _body[1];
 
   enum {
@@ -117,7 +126,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);
   }