< prev index next >

src/hotspot/share/oops/symbol.cpp

Print this page

 97   assert(((Symbol*)p)->refcount() == 0, "should not call this");
 98   FreeHeap(p);
 99 }
100 
101 #if INCLUDE_CDS
102 void Symbol::update_identity_hash() {
103   // This is called at a safepoint during dumping of a static CDS archive. The caller should have
104   // called os::init_random() with a deterministic seed and then iterate all archived Symbols in
105   // a deterministic order.
106   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
107   _hash_and_refcount =  pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
108 }
109 
110 void Symbol::set_permanent() {
111   // This is called at a safepoint during dumping of a dynamic CDS archive.
112   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
113   _hash_and_refcount =  pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
114 }
115 #endif
116 











































































117 // ------------------------------------------------------------------
118 // Symbol::index_of
119 //
120 // Finds if the given string is a substring of this symbol's utf8 bytes.
121 // Return -1 on failure.  Otherwise return the first index where str occurs.
122 int Symbol::index_of_at(int i, const char* str, int len) const {
123   assert(i >= 0 && i <= utf8_length(), "oob");
124   if (len <= 0)  return 0;
125   char first_char = str[0];
126   address bytes = (address) ((Symbol*)this)->base();
127   address limit = bytes + utf8_length() - len;  // inclusive limit
128   address scan = bytes + i;
129   if (scan > limit)
130     return -1;
131   for (; scan <= limit; scan++) {
132     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
133     if (scan == NULL)
134       return -1;  // not found
135     assert(scan >= bytes+i && scan <= limit, "scan oob");
136     if (len <= 2

401 }
402 
403 void Symbol::print_value() const { print_value_on(tty); }
404 
405 bool Symbol::is_valid(Symbol* s) {
406   if (!is_aligned(s, sizeof(MetaWord))) return false;
407   if ((size_t)s < os::min_page_size()) return false;
408 
409   if (!os::is_readable_range(s, s + 1)) return false;
410 
411   // Symbols are not allocated in Java heap.
412   if (Universe::heap()->is_in(s)) return false;
413 
414   int len = s->utf8_length();
415   if (len < 0) return false;
416 
417   jbyte* bytes = (jbyte*) s->bytes();
418   return os::is_readable_range(bytes, bytes + len);
419 }
420 












421 // SymbolTable prints this in its statistics
422 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
423 
424 #ifndef PRODUCT
425 bool Symbol::is_valid_id(vmSymbolID vm_symbol_id) {
426   return vmSymbols::is_valid_id(vm_symbol_id);
427 }
428 #endif

 97   assert(((Symbol*)p)->refcount() == 0, "should not call this");
 98   FreeHeap(p);
 99 }
100 
101 #if INCLUDE_CDS
102 void Symbol::update_identity_hash() {
103   // This is called at a safepoint during dumping of a static CDS archive. The caller should have
104   // called os::init_random() with a deterministic seed and then iterate all archived Symbols in
105   // a deterministic order.
106   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
107   _hash_and_refcount =  pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
108 }
109 
110 void Symbol::set_permanent() {
111   // This is called at a safepoint during dumping of a dynamic CDS archive.
112   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
113   _hash_and_refcount =  pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
114 }
115 #endif
116 
117 bool Symbol::is_Q_signature() const {
118   int len = utf8_length();
119   return len > 2 && char_at(0) == JVM_SIGNATURE_INLINE_TYPE && char_at(len - 1) == JVM_SIGNATURE_ENDCLASS;
120 }
121 
122 bool Symbol::is_Q_array_signature() const {
123   int l = utf8_length();
124   if (l < 2 || char_at(0) != JVM_SIGNATURE_ARRAY || char_at(l - 1) != JVM_SIGNATURE_ENDCLASS) {
125     return false;
126   }
127   for (int i = 1; i < (l - 2); i++) {
128     char c = char_at(i);
129     if (c == JVM_SIGNATURE_INLINE_TYPE) {
130       return true;
131     }
132     if (c != JVM_SIGNATURE_ARRAY) {
133       return false;
134     }
135   }
136   return false;
137 }
138 
139 bool Symbol::is_Q_method_signature() const {
140   assert(SignatureVerifier::is_valid_method_signature(this), "must be");
141   int len = utf8_length();
142   if (len > 4 && char_at(0) == JVM_SIGNATURE_FUNC) {
143     for (int i=1; i<len-3; i++) { // Must end with ")Qx;", where x is at least one character or more.
144       if (char_at(i) == JVM_SIGNATURE_ENDFUNC && char_at(i+1) == JVM_SIGNATURE_INLINE_TYPE) {
145         return true;
146       }
147     }
148   }
149   return false;
150 }
151 
152 Symbol* Symbol::fundamental_name(TRAPS) {
153   if ((char_at(0) == JVM_SIGNATURE_INLINE_TYPE || char_at(0) == JVM_SIGNATURE_CLASS) && ends_with(JVM_SIGNATURE_ENDCLASS)) {
154     return SymbolTable::new_symbol(this, 1, utf8_length() - 1);
155   } else {
156     // reference count is incremented to be consistent with the behavior with
157     // the SymbolTable::new_symbol() call above
158     this->increment_refcount();
159     return this;
160   }
161 }
162 
163 bool Symbol::is_same_fundamental_type(Symbol* s) const {
164   if (this == s) return true;
165   if (utf8_length() < 3) return false;
166   int offset1, offset2, len;
167   if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
168     if (char_at(0) != JVM_SIGNATURE_INLINE_TYPE && char_at(0) != JVM_SIGNATURE_CLASS) return false;
169     offset1 = 1;
170     len = utf8_length() - 2;
171   } else {
172     offset1 = 0;
173     len = utf8_length();
174   }
175   if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
176     if (s->char_at(0) != JVM_SIGNATURE_INLINE_TYPE && s->char_at(0) != JVM_SIGNATURE_CLASS) return false;
177     offset2 = 1;
178   } else {
179     offset2 = 0;
180   }
181   if ((offset2 + len) > s->utf8_length()) return false;
182   if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
183     return false;
184   int l = len;
185   while (l-- > 0) {
186     if (char_at(offset1 + l) != s->char_at(offset2 + l))
187       return false;
188   }
189   return true;
190 }
191 
192 // ------------------------------------------------------------------
193 // Symbol::index_of
194 //
195 // Finds if the given string is a substring of this symbol's utf8 bytes.
196 // Return -1 on failure.  Otherwise return the first index where str occurs.
197 int Symbol::index_of_at(int i, const char* str, int len) const {
198   assert(i >= 0 && i <= utf8_length(), "oob");
199   if (len <= 0)  return 0;
200   char first_char = str[0];
201   address bytes = (address) ((Symbol*)this)->base();
202   address limit = bytes + utf8_length() - len;  // inclusive limit
203   address scan = bytes + i;
204   if (scan > limit)
205     return -1;
206   for (; scan <= limit; scan++) {
207     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
208     if (scan == NULL)
209       return -1;  // not found
210     assert(scan >= bytes+i && scan <= limit, "scan oob");
211     if (len <= 2

476 }
477 
478 void Symbol::print_value() const { print_value_on(tty); }
479 
480 bool Symbol::is_valid(Symbol* s) {
481   if (!is_aligned(s, sizeof(MetaWord))) return false;
482   if ((size_t)s < os::min_page_size()) return false;
483 
484   if (!os::is_readable_range(s, s + 1)) return false;
485 
486   // Symbols are not allocated in Java heap.
487   if (Universe::heap()->is_in(s)) return false;
488 
489   int len = s->utf8_length();
490   if (len < 0) return false;
491 
492   jbyte* bytes = (jbyte*) s->bytes();
493   return os::is_readable_range(bytes, bytes + len);
494 }
495 
496 void Symbol::print_Qvalue_on(outputStream* st) const {
497   if (this == NULL) {
498     st->print("NULL");
499   } else {
500     st->print("'Q");
501     for (int i = 0; i < utf8_length(); i++) {
502       st->print("%c", char_at(i));
503     }
504     st->print(";'");
505   }
506 }
507 
508 // SymbolTable prints this in its statistics
509 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
510 
511 #ifndef PRODUCT
512 bool Symbol::is_valid_id(vmSymbolID vm_symbol_id) {
513   return vmSymbols::is_valid_id(vm_symbol_id);
514 }
515 #endif
< prev index next >