< 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 // Test if we have the give substring at or after the i-th char of this
121 // symbol's utf8 bytes.
122 // Return -1 on failure.  Otherwise return the first index where substr occurs.
123 int Symbol::index_of_at(int i, const char* substr, int substr_len) const {
124   assert(i >= 0 && i <= utf8_length(), "oob");
125   if (substr_len <= 0)  return 0;
126   char first_char = substr[0];
127   address bytes = (address) ((Symbol*)this)->base();
128   address limit = bytes + utf8_length() - substr_len;  // inclusive limit
129   address scan = bytes + i;
130   if (scan > limit)
131     return -1;
132   for (; scan <= limit; scan++) {
133     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
134     if (scan == NULL)
135       return -1;  // not found
136     assert(scan >= bytes+i && scan <= limit, "scan oob");

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












422 // SymbolTable prints this in its statistics
423 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
424 
425 #ifndef PRODUCT
426 bool Symbol::is_valid_id(vmSymbolID vm_symbol_id) {
427   return vmSymbols::is_valid_id(vm_symbol_id);
428 }
429 #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_PRIMITIVE_OBJECT && 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_PRIMITIVE_OBJECT) {
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_PRIMITIVE_OBJECT) {
145         return true;
146       }
147     }
148   }
149   return false;
150 }
151 
152 Symbol* Symbol::fundamental_name(TRAPS) {
153   if ((char_at(0) == JVM_SIGNATURE_PRIMITIVE_OBJECT || 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_PRIMITIVE_OBJECT && 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_PRIMITIVE_OBJECT && 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 // Test if we have the give substring at or after the i-th char of this
196 // symbol's utf8 bytes.
197 // Return -1 on failure.  Otherwise return the first index where substr occurs.
198 int Symbol::index_of_at(int i, const char* substr, int substr_len) const {
199   assert(i >= 0 && i <= utf8_length(), "oob");
200   if (substr_len <= 0)  return 0;
201   char first_char = substr[0];
202   address bytes = (address) ((Symbol*)this)->base();
203   address limit = bytes + utf8_length() - substr_len;  // inclusive limit
204   address scan = bytes + i;
205   if (scan > limit)
206     return -1;
207   for (; scan <= limit; scan++) {
208     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
209     if (scan == NULL)
210       return -1;  // not found
211     assert(scan >= bytes+i && scan <= limit, "scan oob");

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