< prev index next >

src/hotspot/share/oops/symbol.cpp

Print this page




  70 void Symbol::operator delete(void *p) {
  71   assert(((Symbol*)p)->refcount() == 0, "should not call this");
  72   FreeHeap(p);
  73 }
  74 
  75 // ------------------------------------------------------------------
  76 // Symbol::starts_with
  77 //
  78 // Tests if the symbol starts with the specified prefix of the given
  79 // length.
  80 bool Symbol::starts_with(const char* prefix, int len) const {
  81   if (len > utf8_length()) return false;
  82   while (len-- > 0) {
  83     if (prefix[len] != char_at(len))
  84       return false;
  85   }
  86   assert(len == -1, "we should be at the beginning");
  87   return true;
  88 }
  89 











































  90 
  91 // ------------------------------------------------------------------
  92 // Symbol::index_of
  93 //
  94 // Finds if the given string is a substring of this symbol's utf8 bytes.
  95 // Return -1 on failure.  Otherwise return the first index where str occurs.
  96 int Symbol::index_of_at(int i, const char* str, int len) const {
  97   assert(i >= 0 && i <= utf8_length(), "oob");
  98   if (len <= 0)  return 0;
  99   char first_char = str[0];
 100   address bytes = (address) ((Symbol*)this)->base();
 101   address limit = bytes + utf8_length() - len;  // inclusive limit
 102   address scan = bytes + i;
 103   if (scan > limit)
 104     return -1;
 105   for (; scan <= limit; scan++) {
 106     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
 107     if (scan == NULL)
 108       return -1;  // not found
 109     assert(scan >= bytes+i && scan <= limit, "scan oob");


 287   for (int i = 0; i < utf8_length(); i++) {
 288     st->print("%c", char_at(i));
 289   }
 290   st->print("'");
 291 }
 292 
 293 bool Symbol::is_valid(Symbol* s) {
 294   if (!is_aligned(s, sizeof(MetaWord))) return false;
 295   if ((size_t)s < os::min_page_size()) return false;
 296 
 297   if (!os::is_readable_range(s, s + 1)) return false;
 298 
 299   // Symbols are not allocated in Java heap.
 300   if (Universe::heap()->is_in_reserved(s)) return false;
 301 
 302   int len = s->utf8_length();
 303   if (len < 0) return false;
 304 
 305   jbyte* bytes = (jbyte*) s->bytes();
 306   return os::is_readable_range(bytes, bytes + len);












 307 }
 308 
 309 // SymbolTable prints this in its statistics
 310 NOT_PRODUCT(size_t Symbol::_total_count = 0;)


  70 void Symbol::operator delete(void *p) {
  71   assert(((Symbol*)p)->refcount() == 0, "should not call this");
  72   FreeHeap(p);
  73 }
  74 
  75 // ------------------------------------------------------------------
  76 // Symbol::starts_with
  77 //
  78 // Tests if the symbol starts with the specified prefix of the given
  79 // length.
  80 bool Symbol::starts_with(const char* prefix, int len) const {
  81   if (len > utf8_length()) return false;
  82   while (len-- > 0) {
  83     if (prefix[len] != char_at(len))
  84       return false;
  85   }
  86   assert(len == -1, "we should be at the beginning");
  87   return true;
  88 }
  89 
  90 bool Symbol::is_Q_signature() const {
  91   return utf8_length() > 2 && char_at(0) == 'Q' && char_at(utf8_length() - 1) == ';';
  92 }
  93 
  94 Symbol* Symbol::fundamental_name(TRAPS) {
  95   if ((char_at(0) == 'Q' || char_at(0) == 'L') && char_at(utf8_length() - 1) == ';') {
  96     return SymbolTable::lookup(this, 1, utf8_length() - 1, CHECK_NULL);
  97   } else {
  98     // reference count is incremented to be consistent with the behavior with
  99     // the SymbolTable::lookup() call above
 100     this->increment_refcount();
 101     return this;
 102   }
 103 }
 104 
 105 bool Symbol::is_same_fundamental_type(Symbol* s) const {
 106   if (this == s) return true;
 107   if (utf8_length() < 3) return false;
 108   int offset1, offset2, len;
 109   if (char_at(utf8_length() - 1) == ';') {
 110     if (char_at(0) != 'Q' && char_at(0) != 'L') return false;
 111     offset1 = 1;
 112     len = utf8_length() - 2;
 113   } else {
 114     offset1 = 0;
 115     len = utf8_length();
 116   }
 117   if (s->char_at(s->utf8_length() - 1) == ';') {
 118     if (s->char_at(0) != 'Q' && s->char_at(0) != 'L') return false;
 119     offset2 = 1;
 120   } else {
 121     offset2 = 0;
 122   }
 123   if ((offset2 + len) > s->utf8_length()) return false;
 124   if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
 125     return false;
 126   int l = len;
 127   while (l-- > 0) {
 128     if (char_at(offset1 + l) != s->char_at(offset2 + l))
 129       return false;
 130   }
 131   return true;
 132 }
 133 
 134 // ------------------------------------------------------------------
 135 // Symbol::index_of
 136 //
 137 // Finds if the given string is a substring of this symbol's utf8 bytes.
 138 // Return -1 on failure.  Otherwise return the first index where str occurs.
 139 int Symbol::index_of_at(int i, const char* str, int len) const {
 140   assert(i >= 0 && i <= utf8_length(), "oob");
 141   if (len <= 0)  return 0;
 142   char first_char = str[0];
 143   address bytes = (address) ((Symbol*)this)->base();
 144   address limit = bytes + utf8_length() - len;  // inclusive limit
 145   address scan = bytes + i;
 146   if (scan > limit)
 147     return -1;
 148   for (; scan <= limit; scan++) {
 149     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
 150     if (scan == NULL)
 151       return -1;  // not found
 152     assert(scan >= bytes+i && scan <= limit, "scan oob");


 330   for (int i = 0; i < utf8_length(); i++) {
 331     st->print("%c", char_at(i));
 332   }
 333   st->print("'");
 334 }
 335 
 336 bool Symbol::is_valid(Symbol* s) {
 337   if (!is_aligned(s, sizeof(MetaWord))) return false;
 338   if ((size_t)s < os::min_page_size()) return false;
 339 
 340   if (!os::is_readable_range(s, s + 1)) return false;
 341 
 342   // Symbols are not allocated in Java heap.
 343   if (Universe::heap()->is_in_reserved(s)) return false;
 344 
 345   int len = s->utf8_length();
 346   if (len < 0) return false;
 347 
 348   jbyte* bytes = (jbyte*) s->bytes();
 349   return os::is_readable_range(bytes, bytes + len);
 350 }
 351 
 352 void Symbol::print_Qvalue_on(outputStream* st) const {
 353   if (this == NULL) {
 354     st->print("NULL");
 355   } else {
 356     st->print("'Q");
 357     for (int i = 0; i < utf8_length(); i++) {
 358       st->print("%c", char_at(i));
 359     }
 360     st->print(";'");
 361   }
 362 }
 363 
 364 // SymbolTable prints this in its statistics
 365 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
< prev index next >