153
154 // Symbols should be stored in the read-only region of CDS archive.
155 static bool is_read_only_by_default() { return true; }
156
157 // Returns the largest size symbol we can safely hold.
158 static int max_length() { return max_symbol_length; }
159 unsigned identity_hash() const {
160 unsigned addr_bits = (unsigned)((uintptr_t)this >> (LogMinObjAlignmentInBytes + 3));
161 return ((unsigned)_identity_hash & 0xffff) |
162 ((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
163 }
164
165 // Reference counting. See comments above this class for when to use.
166 int refcount() const { return extract_refcount(_length_and_refcount); }
167 bool try_increment_refcount();
168 void increment_refcount();
169 void decrement_refcount();
170 bool is_permanent() {
171 return (refcount() == PERM_REFCOUNT);
172 }
173
174 // Function char_at() returns the Symbol's selected u1 byte as a char type.
175 //
176 // Note that all multi-byte chars have the sign bit set on all their bytes.
177 // No single byte chars have their sign bit set.
178 char char_at(int index) const {
179 assert(index >=0 && index < length(), "symbol index overflow");
180 return (char)base()[index];
181 }
182
183 const u1* bytes() const { return base(); }
184
185 int utf8_length() const { return length(); }
186
187 // Compares the symbol with a string.
188 bool equals(const char* str, int len) const {
189 int l = utf8_length();
190 if (l != len) return false;
191 while (l-- > 0) {
192 if (str[l] != char_at(l))
|
153
154 // Symbols should be stored in the read-only region of CDS archive.
155 static bool is_read_only_by_default() { return true; }
156
157 // Returns the largest size symbol we can safely hold.
158 static int max_length() { return max_symbol_length; }
159 unsigned identity_hash() const {
160 unsigned addr_bits = (unsigned)((uintptr_t)this >> (LogMinObjAlignmentInBytes + 3));
161 return ((unsigned)_identity_hash & 0xffff) |
162 ((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
163 }
164
165 // Reference counting. See comments above this class for when to use.
166 int refcount() const { return extract_refcount(_length_and_refcount); }
167 bool try_increment_refcount();
168 void increment_refcount();
169 void decrement_refcount();
170 bool is_permanent() {
171 return (refcount() == PERM_REFCOUNT);
172 }
173 void make_permanent();
174
175 // Function char_at() returns the Symbol's selected u1 byte as a char type.
176 //
177 // Note that all multi-byte chars have the sign bit set on all their bytes.
178 // No single byte chars have their sign bit set.
179 char char_at(int index) const {
180 assert(index >=0 && index < length(), "symbol index overflow");
181 return (char)base()[index];
182 }
183
184 const u1* bytes() const { return base(); }
185
186 int utf8_length() const { return length(); }
187
188 // Compares the symbol with a string.
189 bool equals(const char* str, int len) const {
190 int l = utf8_length();
191 if (l != len) return false;
192 while (l-- > 0) {
193 if (str[l] != char_at(l))
|