< prev index next >

src/hotspot/share/oops/symbol.hpp

Print this page

141 
142  public:
143   Symbol(const Symbol& s1);
144 
145   // Low-level access (used with care, since not GC-safe)
146   const u1* base() const { return &_body[0]; }
147 
148   int size()      const     { return size(utf8_length()); }
149   int byte_size() const     { return byte_size(utf8_length()); };
150 
151   // Symbols should be stored in the read-only region of CDS archive.
152   static bool is_read_only_by_default() { return true; }
153 
154   // Returns the largest size symbol we can safely hold.
155   static int max_length() { return max_symbol_length; }
156   unsigned identity_hash() const {
157     unsigned addr_bits = (unsigned)((uintptr_t)this >> LogBytesPerWord);
158     return ((unsigned)extract_hash(_hash_and_refcount) & 0xffff) |
159            ((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
160   }



161 
162   // Reference counting.  See comments above this class for when to use.
163   int refcount() const { return extract_refcount(_hash_and_refcount); }
164   bool try_increment_refcount();
165   void increment_refcount();
166   void decrement_refcount();
167   bool is_permanent() const {
168     return (refcount() == PERM_REFCOUNT);
169   }
170   void update_identity_hash() NOT_CDS_RETURN;
171   void set_permanent() NOT_CDS_RETURN;
172   void make_permanent();
173 
174   static void maybe_increment_refcount(Symbol* s) {
175     if (s != nullptr) {
176       s->increment_refcount();
177     }
178   }
179   static void maybe_decrement_refcount(Symbol* s) {
180     if (s != nullptr) {

230     assert(len >= 0 && substring != nullptr, "substring must be valid");
231     if (position < 0)  return false;  // can happen with ends_with
232     if (position + len > utf8_length()) return false;
233     return (memcmp((char*)base() + position, substring, len) == 0);
234   }
235 
236   // Tests if the symbol contains the given byte at the given position.
237   bool contains_byte_at(int position, char code_byte) const {
238     if (position < 0)  return false;  // can happen with ends_with
239     if (position >= utf8_length()) return false;
240     return code_byte == char_at(position);
241   }
242 
243   // Test if the symbol has the give substring at or after the i-th char.
244   int index_of_at(int i, const char* substr, int substr_len) const;
245 
246   // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
247   // note that the ordering is not alfabetical
248   inline int fast_compare(const Symbol* other) const;
249 













250   // Returns receiver converted to null-terminated UTF-8 string; string is
251   // allocated in resource area, or in the char buffer provided by caller.
252   char* as_C_string() const;
253   char* as_C_string(char* buf, int size) const;
254 
255   // Returns an escaped form of a Java string.
256   char* as_quoted_ascii() const;
257 
258   // Returns a null terminated utf8 string in a resource array
259   char* as_utf8() const { return as_C_string(); }
260 
261   jchar* as_unicode(int& length) const;
262 
263   // Treating this symbol as a class name, returns the Java name for the class.
264   // String is allocated in resource area if buffer is not provided.
265   // See Klass::external_name()
266   const char* as_klass_external_name() const;
267   const char* as_klass_external_name(char* buf, int size) const;
268 
269   // Treating the symbol as a signature, print the return

141 
142  public:
143   Symbol(const Symbol& s1);
144 
145   // Low-level access (used with care, since not GC-safe)
146   const u1* base() const { return &_body[0]; }
147 
148   int size()      const     { return size(utf8_length()); }
149   int byte_size() const     { return byte_size(utf8_length()); };
150 
151   // Symbols should be stored in the read-only region of CDS archive.
152   static bool is_read_only_by_default() { return true; }
153 
154   // Returns the largest size symbol we can safely hold.
155   static int max_length() { return max_symbol_length; }
156   unsigned identity_hash() const {
157     unsigned addr_bits = (unsigned)((uintptr_t)this >> LogBytesPerWord);
158     return ((unsigned)extract_hash(_hash_and_refcount) & 0xffff) |
159            ((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
160   }
161   static unsigned identity_hash(const Symbol* symbol_or_null) {
162     return symbol_or_null == nullptr ? 0 : symbol_or_null->identity_hash();
163   }
164 
165   // Reference counting.  See comments above this class for when to use.
166   int refcount() const { return extract_refcount(_hash_and_refcount); }
167   bool try_increment_refcount();
168   void increment_refcount();
169   void decrement_refcount();
170   bool is_permanent() const {
171     return (refcount() == PERM_REFCOUNT);
172   }
173   void update_identity_hash() NOT_CDS_RETURN;
174   void set_permanent() NOT_CDS_RETURN;
175   void make_permanent();
176 
177   static void maybe_increment_refcount(Symbol* s) {
178     if (s != nullptr) {
179       s->increment_refcount();
180     }
181   }
182   static void maybe_decrement_refcount(Symbol* s) {
183     if (s != nullptr) {

233     assert(len >= 0 && substring != nullptr, "substring must be valid");
234     if (position < 0)  return false;  // can happen with ends_with
235     if (position + len > utf8_length()) return false;
236     return (memcmp((char*)base() + position, substring, len) == 0);
237   }
238 
239   // Tests if the symbol contains the given byte at the given position.
240   bool contains_byte_at(int position, char code_byte) const {
241     if (position < 0)  return false;  // can happen with ends_with
242     if (position >= utf8_length()) return false;
243     return code_byte == char_at(position);
244   }
245 
246   // Test if the symbol has the give substring at or after the i-th char.
247   int index_of_at(int i, const char* substr, int substr_len) const;
248 
249   // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
250   // note that the ordering is not alfabetical
251   inline int fast_compare(const Symbol* other) const;
252 
253   // Perform a memcmp against the other block of bytes, up to the end
254   // of the shorter of the two.  If lengths differ but the bytes are
255   // the same, the shorter one compares lower.
256   int cmp(const Symbol* other) const {
257     return cmp((char*)other->base(), other->utf8_length());
258   }
259   int cmp(const char* str, int len) const {
260     int mylen = utf8_length();
261     int cmp = memcmp((char*)base(), str, mylen < len ? mylen : len);
262     // mylen - len cannot overflow because symbol length >= 0
263     return cmp != 0 ? cmp : mylen - len;
264   }
265 
266   // Returns receiver converted to null-terminated UTF-8 string; string is
267   // allocated in resource area, or in the char buffer provided by caller.
268   char* as_C_string() const;
269   char* as_C_string(char* buf, int size) const;
270 
271   // Returns an escaped form of a Java string.
272   char* as_quoted_ascii() const;
273 
274   // Returns a null terminated utf8 string in a resource array
275   char* as_utf8() const { return as_C_string(); }
276 
277   jchar* as_unicode(int& length) const;
278 
279   // Treating this symbol as a class name, returns the Java name for the class.
280   // String is allocated in resource area if buffer is not provided.
281   // See Klass::external_name()
282   const char* as_klass_external_name() const;
283   const char* as_klass_external_name(char* buf, int size) const;
284 
285   // Treating the symbol as a signature, print the return
< prev index next >