< prev index next >

src/hotspot/share/oops/symbol.hpp

Print this page

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     return contains_utf8_at(0, str, len);
193   }
194   bool equals(const char* str) const { return equals(str, (int) strlen(str)); }
195 
196   // Tests if the symbol starts with the given prefix.
197   bool starts_with(const char* prefix, int len) const {
198     return contains_utf8_at(0, prefix, len);
199   }
200   bool starts_with(const char* prefix) const {
201     return starts_with(prefix, (int) strlen(prefix));
202   }
203   bool starts_with(int prefix_char) const {
204     return contains_byte_at(0, prefix_char);
205   }
206   // Tests if the symbol ends with the given suffix.
207   bool ends_with(const char* suffix, int len) const {
208     return contains_utf8_at(utf8_length() - len, suffix, len);
209   }
210   bool ends_with(const char* suffix) const {
211     return ends_with(suffix, (int) strlen(suffix));
212   }
213   bool ends_with(int suffix_char) const {
214     return contains_byte_at(utf8_length() - 1, suffix_char);
215   }
216 
217   // Tests if the symbol contains the given utf8 substring
218   // at the given byte position.
219   bool contains_utf8_at(int position, const char* substring, int len) const {
220     assert(len >= 0 && substring != NULL, "substring must be valid");
221     if (position < 0)  return false;  // can happen with ends_with
222     if (position + len > utf8_length()) return false;
223     return (memcmp((char*)base() + position, substring, len) == 0);
224   }
225 
226   // Tests if the symbol contains the given byte at the given position.
227   bool contains_byte_at(int position, char code_byte) const {
228     if (position < 0)  return false;  // can happen with ends_with
229     if (position >= utf8_length()) return false;
230     return code_byte == char_at(position);
231   }
232 












233   // Tests if the symbol starts with the given prefix.
234   int index_of_at(int i, const char* str, int len) const;
235 
236   // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
237   // note that the ordering is not alfabetical
238   inline int fast_compare(const Symbol* other) const;
239 
240   // Returns receiver converted to null-terminated UTF-8 string; string is
241   // allocated in resource area, or in the char buffer provided by caller.
242   char* as_C_string() const;
243   char* as_C_string(char* buf, int size) const;
244 
245   // Returns an escaped form of a Java string.
246   char* as_quoted_ascii() const;
247 
248   // Returns a null terminated utf8 string in a resource array
249   char* as_utf8() const { return as_C_string(); }
250 
251   jchar* as_unicode(int& length) const;
252 

256   const char* as_klass_external_name() const;
257   const char* as_klass_external_name(char* buf, int size) const;
258 
259   // Treating the symbol as a signature, print the return
260   // type to the outputStream. Prints external names as 'double' or
261   // 'java.lang.Object[][]'.
262   void print_as_signature_external_return_type(outputStream *os);
263   // Treating the symbol as a signature, print the parameter types
264   // seperated by ', ' to the outputStream.  Prints external names as
265   //  'double' or 'java.lang.Object[][]'.
266   void print_as_signature_external_parameters(outputStream *os);
267 
268   void metaspace_pointers_do(MetaspaceClosure* it);
269   MetaspaceObj::Type type() const { return SymbolType; }
270 
271   // Printing
272   void print_symbol_on(outputStream* st = NULL) const;
273   void print_utf8_on(outputStream* st) const;
274   void print_on(outputStream* st) const;         // First level print
275   void print_value_on(outputStream* st) const;   // Second level print.

276 
277   // printing on default output stream
278   void print() const;
279   void print_value() const;
280 
281   static bool is_valid(Symbol* s);
282 
283   static bool is_valid_id(vmSymbolID vm_symbol_id) PRODUCT_RETURN_(return true;);
284 
285   static Symbol* vm_symbol_at(vmSymbolID vm_symbol_id) {
286     assert(is_valid_id(vm_symbol_id), "must be");
287     return _vm_symbols[static_cast<int>(vm_symbol_id)];
288   }
289 
290 #ifndef PRODUCT
291   // Empty constructor to create a dummy symbol object on stack
292   // only for getting its vtable pointer.
293   Symbol() { }
294 
295   static size_t _total_count;

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     return contains_utf8_at(0, str, len);
193   }
194   bool equals(const char* str) const { return equals(str, (int) strlen(str)); }
195 
196   // Tests if the symbol starts with the given prefix.
197   bool starts_with(const char* prefix, int len) const {
198     return contains_utf8_at(0, prefix, len);
199   }
200   bool starts_with(const char* prefix) const {
201     return starts_with(prefix, (int) strlen(prefix));
202   }
203   bool starts_with(char prefix_char) const {
204     return contains_byte_at(0, prefix_char);
205   }
206   // Tests if the symbol ends with the given suffix.
207   bool ends_with(const char* suffix, int len) const {
208     return contains_utf8_at(utf8_length() - len, suffix, len);
209   }
210   bool ends_with(const char* suffix) const {
211     return ends_with(suffix, (int) strlen(suffix));
212   }
213   bool ends_with(int suffix_char) const {
214     return contains_byte_at(utf8_length() - 1, suffix_char);
215   }
216 
217   // Tests if the symbol contains the given utf8 substring
218   // at the given byte position.
219   bool contains_utf8_at(int position, const char* substring, int len) const {
220     assert(len >= 0 && substring != NULL, "substring must be valid");
221     if (position < 0)  return false;  // can happen with ends_with
222     if (position + len > utf8_length()) return false;
223     return (memcmp((char*)base() + position, substring, len) == 0);
224   }
225 
226   // Tests if the symbol contains the given byte at the given position.
227   bool contains_byte_at(int position, char code_byte) const {
228     if (position < 0)  return false;  // can happen with ends_with
229     if (position >= utf8_length()) return false;
230     return code_byte == char_at(position);
231   }
232 
233   // True if this is a descriptor for a method with void return.
234   // (Assumes it is a valid descriptor.)
235   bool is_void_method_signature() const {
236     return starts_with('(') && ends_with('V');
237   }
238 
239   bool is_Q_signature() const;
240   bool is_Q_array_signature() const;
241   bool is_Q_method_signature() const;
242   Symbol* fundamental_name(TRAPS);
243   bool is_same_fundamental_type(Symbol*) const;
244 
245   // Tests if the symbol starts with the given prefix.
246   int index_of_at(int i, const char* str, int len) const;
247 
248   // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
249   // note that the ordering is not alfabetical
250   inline int fast_compare(const Symbol* other) const;
251 
252   // Returns receiver converted to null-terminated UTF-8 string; string is
253   // allocated in resource area, or in the char buffer provided by caller.
254   char* as_C_string() const;
255   char* as_C_string(char* buf, int size) const;
256 
257   // Returns an escaped form of a Java string.
258   char* as_quoted_ascii() const;
259 
260   // Returns a null terminated utf8 string in a resource array
261   char* as_utf8() const { return as_C_string(); }
262 
263   jchar* as_unicode(int& length) const;
264 

268   const char* as_klass_external_name() const;
269   const char* as_klass_external_name(char* buf, int size) const;
270 
271   // Treating the symbol as a signature, print the return
272   // type to the outputStream. Prints external names as 'double' or
273   // 'java.lang.Object[][]'.
274   void print_as_signature_external_return_type(outputStream *os);
275   // Treating the symbol as a signature, print the parameter types
276   // seperated by ', ' to the outputStream.  Prints external names as
277   //  'double' or 'java.lang.Object[][]'.
278   void print_as_signature_external_parameters(outputStream *os);
279 
280   void metaspace_pointers_do(MetaspaceClosure* it);
281   MetaspaceObj::Type type() const { return SymbolType; }
282 
283   // Printing
284   void print_symbol_on(outputStream* st = NULL) const;
285   void print_utf8_on(outputStream* st) const;
286   void print_on(outputStream* st) const;         // First level print
287   void print_value_on(outputStream* st) const;   // Second level print.
288   void print_Qvalue_on(outputStream* st) const;  // Second level print for Q-types.
289 
290   // printing on default output stream
291   void print() const;
292   void print_value() const;
293 
294   static bool is_valid(Symbol* s);
295 
296   static bool is_valid_id(vmSymbolID vm_symbol_id) PRODUCT_RETURN_(return true;);
297 
298   static Symbol* vm_symbol_at(vmSymbolID vm_symbol_id) {
299     assert(is_valid_id(vm_symbol_id), "must be");
300     return _vm_symbols[static_cast<int>(vm_symbol_id)];
301   }
302 
303 #ifndef PRODUCT
304   // Empty constructor to create a dummy symbol object on stack
305   // only for getting its vtable pointer.
306   Symbol() { }
307 
308   static size_t _total_count;
< prev index next >