< prev index next >

src/hotspot/share/oops/symbol.cpp

Print this page
rev 55090 : secret-sfac


  57 }
  58 
  59 void* Symbol::operator new(size_t sz, int len, TRAPS) throw() {
  60   int alloc_size = size(len)*wordSize;
  61   address res = (address) AllocateHeap(alloc_size, mtSymbol);
  62   return res;
  63 }
  64 
  65 void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) throw() {
  66   int alloc_size = size(len)*wordSize;
  67   address res = (address)arena->Amalloc_4(alloc_size);
  68   return res;
  69 }
  70 
  71 void Symbol::operator delete(void *p) {
  72   assert(((Symbol*)p)->refcount() == 0, "should not call this");
  73   FreeHeap(p);
  74 }
  75 
  76 // ------------------------------------------------------------------
  77 // Symbol::starts_with
  78 //
  79 // Tests if the symbol starts with the specified prefix of the given
  80 // length.
  81 bool Symbol::starts_with(const char* prefix, int len) const {
  82   if (len > utf8_length()) return false;














  83   while (len-- > 0) {
  84     if (prefix[len] != char_at(len))
  85       return false;
  86   }
  87   assert(len == -1, "we should be at the beginning");
  88   return true;
  89 }
  90 
  91 bool Symbol::is_Q_signature() const {
  92   return utf8_length() > 2 && char_at(0) == 'Q' && char_at(utf8_length() - 1) == ';';
  93 }
  94 
  95 Symbol* Symbol::fundamental_name(TRAPS) {
  96   if ((char_at(0) == 'Q' || char_at(0) == 'L') && char_at(utf8_length() - 1) == ';') {
  97     return SymbolTable::lookup(this, 1, utf8_length() - 1, CHECK_NULL);
  98   } else {
  99     // reference count is incremented to be consistent with the behavior with
 100     // the SymbolTable::lookup() call above
 101     this->increment_refcount();
 102     return this;
 103   }
 104 }
 105 
 106 bool Symbol::is_same_fundamental_type(Symbol* s) const {
 107   if (this == s) return true;
 108   if (utf8_length() < 3) return false;
 109   int offset1, offset2, len;
 110   if (char_at(utf8_length() - 1) == ';') {
 111     if (char_at(0) != 'Q' && char_at(0) != 'L') return false;
 112     offset1 = 1;
 113     len = utf8_length() - 2;
 114   } else {
 115     offset1 = 0;
 116     len = utf8_length();
 117   }
 118   if (s->char_at(s->utf8_length() - 1) == ';') {
 119     if (s->char_at(0) != 'Q' && s->char_at(0) != 'L') return false;
 120     offset2 = 1;
 121   } else {
 122     offset2 = 0;
 123   }
 124   if ((offset2 + len) > s->utf8_length()) return false;
 125   if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
 126     return false;
 127   int l = len;
 128   while (l-- > 0) {
 129     if (char_at(offset1 + l) != s->char_at(offset2 + l))
 130       return false;
 131   }
 132   return true;
 133 }
 134 
 135 // ------------------------------------------------------------------
 136 // Symbol::index_of
 137 //
 138 // Finds if the given string is a substring of this symbol's utf8 bytes.




  57 }
  58 
  59 void* Symbol::operator new(size_t sz, int len, TRAPS) throw() {
  60   int alloc_size = size(len)*wordSize;
  61   address res = (address) AllocateHeap(alloc_size, mtSymbol);
  62   return res;
  63 }
  64 
  65 void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) throw() {
  66   int alloc_size = size(len)*wordSize;
  67   address res = (address)arena->Amalloc_4(alloc_size);
  68   return res;
  69 }
  70 
  71 void Symbol::operator delete(void *p) {
  72   assert(((Symbol*)p)->refcount() == 0, "should not call this");
  73   FreeHeap(p);
  74 }
  75 
  76 // ------------------------------------------------------------------
  77 // Symbol::contains_byte_at
  78 //
  79 // Tests if the symbol contains the given byte at the given position.
  80 bool Symbol::contains_byte_at(int position, char code_byte) const {
  81   if (position < 0)  return false;  // can happen with ends_with
  82   if (position >= utf8_length()) return false;
  83   return code_byte == char_at(position);
  84 }
  85 
  86 // ------------------------------------------------------------------
  87 // Symbol::contains_utf8_at
  88 //
  89 // Tests if the symbol contains the given utf8 substring
  90 // at the given byte position.
  91 bool Symbol::contains_utf8_at(int position, const char* substring, int len) const {
  92   assert(len > 0 && substring != NULL && (int) strlen(substring) >= len,
  93          "substring must be valid");
  94   if (len == 1)  return contains_byte_at(position, substring[0]);
  95   if (position < 0)  return false;  // can happen with ends_with
  96   if (position + len > utf8_length()) return false;
  97   while (len-- > 0) {
  98     if (substring[len] != char_at(position + len))
  99       return false;
 100   }
 101   assert(len == -1, "we should be at the beginning");
 102   return true;
 103 }
 104 
 105 bool Symbol::is_Q_signature() const {
 106   return utf8_length() > 2 && char_at(0) == 'Q' && ends_with(';');
 107 }
 108 
 109 Symbol* Symbol::fundamental_name(TRAPS) {
 110   if ((char_at(0) == 'Q' || char_at(0) == 'L') && ends_with(';')) {
 111     return SymbolTable::lookup(this, 1, utf8_length() - 1, CHECK_NULL);
 112   } else {
 113     // reference count is incremented to be consistent with the behavior with
 114     // the SymbolTable::lookup() call above
 115     this->increment_refcount();
 116     return this;
 117   }
 118 }
 119 
 120 bool Symbol::is_same_fundamental_type(Symbol* s) const {
 121   if (this == s) return true;
 122   if (utf8_length() < 3) return false;
 123   int offset1, offset2, len;
 124   if (ends_with(';')) {
 125     if (char_at(0) != 'Q' && char_at(0) != 'L') return false;
 126     offset1 = 1;
 127     len = utf8_length() - 2;
 128   } else {
 129     offset1 = 0;
 130     len = utf8_length();
 131   }
 132   if (ends_with(';')) {
 133     if (s->char_at(0) != 'Q' && s->char_at(0) != 'L') return false;
 134     offset2 = 1;
 135   } else {
 136     offset2 = 0;
 137   }
 138   if ((offset2 + len) > s->utf8_length()) return false;
 139   if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
 140     return false;
 141   int l = len;
 142   while (l-- > 0) {
 143     if (char_at(offset1 + l) != s->char_at(offset2 + l))
 144       return false;
 145   }
 146   return true;
 147 }
 148 
 149 // ------------------------------------------------------------------
 150 // Symbol::index_of
 151 //
 152 // Finds if the given string is a substring of this symbol's utf8 bytes.


< prev index next >