Mercurial > hg > truffle
comparison 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 |
comparison
equal
deleted
inserted
replaced
11032:b7bc7c94b4b5 | 11033:d9eed26d638a |
---|---|
25 #ifndef SHARE_VM_OOPS_SYMBOL_HPP | 25 #ifndef SHARE_VM_OOPS_SYMBOL_HPP |
26 #define SHARE_VM_OOPS_SYMBOL_HPP | 26 #define SHARE_VM_OOPS_SYMBOL_HPP |
27 | 27 |
28 #include "utilities/utf8.hpp" | 28 #include "utilities/utf8.hpp" |
29 #include "memory/allocation.hpp" | 29 #include "memory/allocation.hpp" |
30 #include "runtime/atomic.hpp" | |
30 | 31 |
31 // A Symbol is a canonicalized string. | 32 // A Symbol is a canonicalized string. |
32 // All Symbols reside in global SymbolTable and are reference counted. | 33 // All Symbols reside in global SymbolTable and are reference counted. |
33 | 34 |
34 // Reference counting | 35 // Reference counting |
99 // This cannot be inherited from ResourceObj because it cannot have a vtable. | 100 // This cannot be inherited from ResourceObj because it cannot have a vtable. |
100 // Since sometimes this is allocated from Metadata, pick a base allocation | 101 // Since sometimes this is allocated from Metadata, pick a base allocation |
101 // type without virtual functions. | 102 // type without virtual functions. |
102 class ClassLoaderData; | 103 class ClassLoaderData; |
103 | 104 |
104 class Symbol : public MetaspaceObj { | 105 // We separate the fields in SymbolBase from Symbol::_body so that |
106 // Symbol::size(int) can correctly calculate the space needed. | |
107 class SymbolBase : public MetaspaceObj { | |
108 public: | |
109 ATOMIC_SHORT_PAIR( | |
110 volatile short _refcount, // needs atomic operation | |
111 unsigned short _length // number of UTF8 characters in the symbol (does not need atomic op) | |
112 ); | |
113 int _identity_hash; | |
114 }; | |
115 | |
116 class Symbol : private SymbolBase { | |
105 friend class VMStructs; | 117 friend class VMStructs; |
106 friend class SymbolTable; | 118 friend class SymbolTable; |
107 friend class MoveSymbols; | 119 friend class MoveSymbols; |
108 private: | 120 private: |
109 volatile int _refcount; | |
110 int _identity_hash; | |
111 unsigned short _length; // number of UTF8 characters in the symbol | |
112 jbyte _body[1]; | 121 jbyte _body[1]; |
113 | 122 |
114 enum { | 123 enum { |
115 // max_symbol_length is constrained by type of _length | 124 // max_symbol_length is constrained by type of _length |
116 max_symbol_length = (1 << 16) -1 | 125 max_symbol_length = (1 << 16) -1 |
117 }; | 126 }; |
118 | 127 |
119 static int size(int length) { | 128 static int size(int length) { |
120 size_t sz = heap_word_size(sizeof(Symbol) + (length > 0 ? length - 1 : 0)); | 129 size_t sz = heap_word_size(sizeof(SymbolBase) + (length > 0 ? length : 0)); |
121 return align_object_size(sz); | 130 return align_object_size(sz); |
122 } | 131 } |
123 | 132 |
124 void byte_at_put(int index, int value) { | 133 void byte_at_put(int index, int value) { |
125 assert(index >=0 && index < _length, "symbol index overflow"); | 134 assert(index >=0 && index < _length, "symbol index overflow"); |