108 109 // This is an int because it needs atomic operation on the refcount. Mask hash 110 // in high half word. length is the number of UTF8 characters in the symbol 111 volatile uint32_t _hash_and_refcount; 112 u2 _length; 113 u1 _body[2]; 114 115 enum { 116 max_symbol_length = 0xffff 117 }; 118 119 static int byte_size(int length) { 120 // minimum number of natural words needed to hold these bits (no non-heap version) 121 return (int)(sizeof(Symbol) + (length > 2 ? length - 2 : 0)); 122 } 123 static int size(int length) { 124 // minimum number of natural words needed to hold these bits (no non-heap version) 125 return (int)heap_word_size(byte_size(length)); 126 } 127 128 void byte_at_put(int index, u1 value) { 129 assert(index >=0 && index < length(), "symbol index overflow"); 130 _body[index] = value; 131 } 132 133 Symbol(const u1* name, int length, int refcount); 134 void* operator new(size_t size, int len) throw(); 135 void* operator new(size_t size, int len, Arena* arena) throw(); 136 137 void operator delete(void* p); 138 139 static short extract_hash(uint32_t value) { return (short)(value >> 16); } 140 static int extract_refcount(uint32_t value) { return value & 0xffff; } 141 static uint32_t pack_hash_and_refcount(short hash, int refcount); 142 143 int length() const { return _length; } 144 145 public: 146 // Low-level access (used with care, since not GC-safe) 147 const u1* base() const { return &_body[0]; } 148 149 int size() { return size(utf8_length()); } 150 int byte_size() { return byte_size(utf8_length()); } 151 152 // Symbols should be stored in the read-only region of CDS archive. | 108 109 // This is an int because it needs atomic operation on the refcount. Mask hash 110 // in high half word. length is the number of UTF8 characters in the symbol 111 volatile uint32_t _hash_and_refcount; 112 u2 _length; 113 u1 _body[2]; 114 115 enum { 116 max_symbol_length = 0xffff 117 }; 118 119 static int byte_size(int length) { 120 // minimum number of natural words needed to hold these bits (no non-heap version) 121 return (int)(sizeof(Symbol) + (length > 2 ? length - 2 : 0)); 122 } 123 static int size(int length) { 124 // minimum number of natural words needed to hold these bits (no non-heap version) 125 return (int)heap_word_size(byte_size(length)); 126 } 127 128 Symbol(const u1* name, int length, int refcount); 129 void* operator new(size_t size, int len) throw(); 130 void* operator new(size_t size, int len, Arena* arena) throw(); 131 132 void operator delete(void* p); 133 134 static short extract_hash(uint32_t value) { return (short)(value >> 16); } 135 static int extract_refcount(uint32_t value) { return value & 0xffff; } 136 static uint32_t pack_hash_and_refcount(short hash, int refcount); 137 138 int length() const { return _length; } 139 140 public: 141 // Low-level access (used with care, since not GC-safe) 142 const u1* base() const { return &_body[0]; } 143 144 int size() { return size(utf8_length()); } 145 int byte_size() { return byte_size(utf8_length()); } 146 147 // Symbols should be stored in the read-only region of CDS archive. |