< prev index next >

src/hotspot/share/oops/symbol.cpp

Print this page

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











































































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

412 }
413 
414 void Symbol::print_value() const { print_value_on(tty); }
415 
416 bool Symbol::is_valid(Symbol* s) {
417   if (!is_aligned(s, sizeof(MetaWord))) return false;
418   if ((size_t)s < os::min_page_size()) return false;
419 
420   if (!os::is_readable_range(s, s + 1)) return false;
421 
422   // Symbols are not allocated in Java heap.
423   if (Universe::heap()->is_in(s)) return false;
424 
425   int len = s->utf8_length();
426   if (len < 0) return false;
427 
428   jbyte* bytes = (jbyte*) s->bytes();
429   return os::is_readable_range(bytes, bytes + len);
430 }
431 








432 // SymbolTable prints this in its statistics
433 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
434 
435 #ifndef PRODUCT
436 bool Symbol::is_valid_id(vmSymbolID vm_symbol_id) {
437   return vmSymbols::is_valid_id(vm_symbol_id);
438 }
439 #endif

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

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