142 Symbol(const Symbol& s1);
143
144 // Low-level access (used with care, since not GC-safe)
145 const u1* base() const { return &_body[0]; }
146
147 int size() const { return size(utf8_length()); }
148 int byte_size() const { return byte_size(utf8_length()); };
149 // length without the _body
150 size_t effective_length() const { return (size_t)byte_size() - sizeof(Symbol); }
151
152 // Symbols should be stored in the read-only region of CDS archive.
153 static bool is_read_only_by_default() { return true; }
154
155 // Returns the largest size symbol we can safely hold.
156 static int max_length() { return max_symbol_length; }
157 unsigned identity_hash() const {
158 unsigned addr_bits = (unsigned)((uintptr_t)this >> LogBytesPerWord);
159 return ((unsigned)extract_hash(_hash_and_refcount) & 0xffff) |
160 ((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
161 }
162
163 // Reference counting. See comments above this class for when to use.
164 int refcount() const { return extract_refcount(_hash_and_refcount); }
165 bool try_increment_refcount();
166 void increment_refcount();
167 void decrement_refcount();
168 bool is_permanent() const {
169 return (refcount() == PERM_REFCOUNT);
170 }
171 void update_identity_hash() NOT_CDS_RETURN;
172 void set_permanent() NOT_CDS_RETURN;
173 void make_permanent();
174
175 static void maybe_increment_refcount(Symbol* s) {
176 if (s != nullptr) {
177 s->increment_refcount();
178 }
179 }
180 static void maybe_decrement_refcount(Symbol* s) {
181 if (s != nullptr) {
231 assert(len >= 0 && substring != nullptr, "substring must be valid");
232 if (position < 0) return false; // can happen with ends_with
233 if (position + len > utf8_length()) return false;
234 return (memcmp((char*)base() + position, substring, len) == 0);
235 }
236
237 // Tests if the symbol contains the given byte at the given position.
238 bool contains_byte_at(int position, char code_byte) const {
239 if (position < 0) return false; // can happen with ends_with
240 if (position >= utf8_length()) return false;
241 return code_byte == char_at(position);
242 }
243
244 // Test if the symbol has the give substring at or after the i-th char.
245 int index_of_at(int i, const char* substr, int substr_len) const;
246
247 // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
248 // note that the ordering is not alfabetical
249 inline int fast_compare(const Symbol* other) const;
250
251 // Returns receiver converted to null-terminated UTF-8 string; string is
252 // allocated in resource area, or in the char buffer provided by caller.
253 char* as_C_string() const;
254 char* as_C_string(char* buf, int size) const;
255
256 // Returns an escaped form of a Java string.
257 char* as_quoted_ascii() const;
258
259 // Returns a null terminated utf8 string in a resource array
260 char* as_utf8() const { return as_C_string(); }
261
262 jchar* as_unicode(int& length) const;
263
264 // Treating this symbol as a class name, returns the Java name for the class.
265 // String is allocated in resource area if buffer is not provided.
266 // See Klass::external_name()
267 const char* as_klass_external_name() const;
268 const char* as_klass_external_name(char* buf, int size) const;
269
270 // Treating the symbol as a signature, print the return
|
142 Symbol(const Symbol& s1);
143
144 // Low-level access (used with care, since not GC-safe)
145 const u1* base() const { return &_body[0]; }
146
147 int size() const { return size(utf8_length()); }
148 int byte_size() const { return byte_size(utf8_length()); };
149 // length without the _body
150 size_t effective_length() const { return (size_t)byte_size() - sizeof(Symbol); }
151
152 // Symbols should be stored in the read-only region of CDS archive.
153 static bool is_read_only_by_default() { return true; }
154
155 // Returns the largest size symbol we can safely hold.
156 static int max_length() { return max_symbol_length; }
157 unsigned identity_hash() const {
158 unsigned addr_bits = (unsigned)((uintptr_t)this >> LogBytesPerWord);
159 return ((unsigned)extract_hash(_hash_and_refcount) & 0xffff) |
160 ((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
161 }
162 static unsigned identity_hash(const Symbol* symbol_or_null) {
163 return symbol_or_null == nullptr ? 0 : symbol_or_null->identity_hash();
164 }
165
166 // Reference counting. See comments above this class for when to use.
167 int refcount() const { return extract_refcount(_hash_and_refcount); }
168 bool try_increment_refcount();
169 void increment_refcount();
170 void decrement_refcount();
171 bool is_permanent() const {
172 return (refcount() == PERM_REFCOUNT);
173 }
174 void update_identity_hash() NOT_CDS_RETURN;
175 void set_permanent() NOT_CDS_RETURN;
176 void make_permanent();
177
178 static void maybe_increment_refcount(Symbol* s) {
179 if (s != nullptr) {
180 s->increment_refcount();
181 }
182 }
183 static void maybe_decrement_refcount(Symbol* s) {
184 if (s != nullptr) {
234 assert(len >= 0 && substring != nullptr, "substring must be valid");
235 if (position < 0) return false; // can happen with ends_with
236 if (position + len > utf8_length()) return false;
237 return (memcmp((char*)base() + position, substring, len) == 0);
238 }
239
240 // Tests if the symbol contains the given byte at the given position.
241 bool contains_byte_at(int position, char code_byte) const {
242 if (position < 0) return false; // can happen with ends_with
243 if (position >= utf8_length()) return false;
244 return code_byte == char_at(position);
245 }
246
247 // Test if the symbol has the give substring at or after the i-th char.
248 int index_of_at(int i, const char* substr, int substr_len) const;
249
250 // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
251 // note that the ordering is not alfabetical
252 inline int fast_compare(const Symbol* other) const;
253
254 // Perform a memcmp against the other block of bytes, up to the end
255 // of the shorter of the two. If lengths differ but the bytes are
256 // the same, the shorter one compares lower.
257 int cmp(const Symbol* other) const {
258 return cmp((char*)other->base(), other->utf8_length());
259 }
260 int cmp(const char* str, int len) const {
261 int mylen = utf8_length();
262 int cmp = memcmp((char*)base(), str, mylen < len ? mylen : len);
263 // mylen - len cannot overflow because symbol length >= 0
264 return cmp != 0 ? cmp : mylen - len;
265 }
266
267 // Returns receiver converted to null-terminated UTF-8 string; string is
268 // allocated in resource area, or in the char buffer provided by caller.
269 char* as_C_string() const;
270 char* as_C_string(char* buf, int size) const;
271
272 // Returns an escaped form of a Java string.
273 char* as_quoted_ascii() const;
274
275 // Returns a null terminated utf8 string in a resource array
276 char* as_utf8() const { return as_C_string(); }
277
278 jchar* as_unicode(int& length) const;
279
280 // Treating this symbol as a class name, returns the Java name for the class.
281 // String is allocated in resource area if buffer is not provided.
282 // See Klass::external_name()
283 const char* as_klass_external_name() const;
284 const char* as_klass_external_name(char* buf, int size) const;
285
286 // Treating the symbol as a signature, print the return
|