< prev index next >
src/share/vm/oops/symbol.hpp
Print this page
@@ -100,35 +100,30 @@
// This cannot be inherited from ResourceObj because it cannot have a vtable.
// Since sometimes this is allocated from Metadata, pick a base allocation
// type without virtual functions.
class ClassLoaderData;
-// 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 {
+class Symbol : public MetaspaceObj {
friend class VMStructs;
friend class SymbolTable;
friend class MoveSymbols;
+
private:
- jbyte _body[1];
+ ATOMIC_SHORT_PAIR(
+ volatile short _refcount, // needs atomic operation
+ unsigned short _length // number of UTF8 characters in the symbol (does not need atomic op)
+ );
+ short _identity_hash;
+ jbyte _body[2];
enum {
// max_symbol_length is constrained by type of _length
max_symbol_length = (1 << 16) -1
};
static int size(int length) {
- size_t sz = heap_word_size(sizeof(SymbolBase) + (length > 0 ? length : 0));
+ size_t sz = heap_word_size(sizeof(Symbol) + (length > 2 ? length - 2 : 0));
return align_object_size(sz);
}
void byte_at_put(int index, int value) {
assert(index >=0 && index < _length, "symbol index overflow");
@@ -148,12 +143,15 @@
int size() { return size(utf8_length()); }
// Returns the largest size symbol we can safely hold.
static int max_length() { return max_symbol_length; }
-
- int identity_hash() { return _identity_hash; }
+ unsigned identity_hash() {
+ unsigned addr_bits = (unsigned)((uintptr_t)this >> (LogMinObjAlignmentInBytes + 3));
+ return (unsigned)_identity_hash |
+ ((addr_bits ^ (_length << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
+ }
// For symbol table alternate hashing
unsigned int new_hash(juint seed);
// Reference counting. See comments above this class for when to use.
< prev index next >