< prev index next >

src/hotspot/share/oops/symbol.cpp

Print this page

 71   _length = s1._length;
 72   memcpy(_body, s1._body, _length);
 73 }
 74 
 75 #if INCLUDE_CDS
 76 void Symbol::update_identity_hash() {
 77   // This is called at a safepoint during dumping of a static CDS archive. The caller should have
 78   // called os::init_random() with a deterministic seed and then iterate all archived Symbols in
 79   // a deterministic order.
 80   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 81   _hash_and_refcount =  pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
 82 }
 83 
 84 void Symbol::set_permanent() {
 85   // This is called at a safepoint during dumping of a dynamic CDS archive.
 86   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 87   _hash_and_refcount =  pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
 88 }
 89 #endif
 90 











































































 91 // ------------------------------------------------------------------
 92 // Symbol::index_of
 93 //
 94 // Test if we have the give substring at or after the i-th char of this
 95 // symbol's utf8 bytes.
 96 // Return -1 on failure.  Otherwise return the first index where substr occurs.
 97 int Symbol::index_of_at(int i, const char* substr, int substr_len) const {
 98   assert(i >= 0 && i <= utf8_length(), "oob");
 99   if (substr_len <= 0)  return 0;
100   char first_char = substr[0];
101   address bytes = (address) ((Symbol*)this)->base();
102   address limit = bytes + utf8_length() - substr_len;  // inclusive limit
103   address scan = bytes + i;
104   if (scan > limit)
105     return -1;
106   for (; scan <= limit; scan++) {
107     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
108     if (scan == nullptr)
109       return -1;  // not found
110     assert(scan >= bytes+i && scan <= limit, "scan oob");

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








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

 71   _length = s1._length;
 72   memcpy(_body, s1._body, _length);
 73 }
 74 
 75 #if INCLUDE_CDS
 76 void Symbol::update_identity_hash() {
 77   // This is called at a safepoint during dumping of a static CDS archive. The caller should have
 78   // called os::init_random() with a deterministic seed and then iterate all archived Symbols in
 79   // a deterministic order.
 80   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 81   _hash_and_refcount =  pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
 82 }
 83 
 84 void Symbol::set_permanent() {
 85   // This is called at a safepoint during dumping of a dynamic CDS archive.
 86   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 87   _hash_and_refcount =  pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
 88 }
 89 #endif
 90 
 91 bool Symbol::is_Q_signature() const {
 92   int len = utf8_length();
 93   return len > 2 && char_at(0) == JVM_SIGNATURE_PRIMITIVE_OBJECT && char_at(len - 1) == JVM_SIGNATURE_ENDCLASS;
 94 }
 95 
 96 bool Symbol::is_Q_array_signature() const {
 97   int l = utf8_length();
 98   if (l < 2 || char_at(0) != JVM_SIGNATURE_ARRAY || char_at(l - 1) != JVM_SIGNATURE_ENDCLASS) {
 99     return false;
100   }
101   for (int i = 1; i < (l - 2); i++) {
102     char c = char_at(i);
103     if (c == JVM_SIGNATURE_PRIMITIVE_OBJECT) {
104       return true;
105     }
106     if (c != JVM_SIGNATURE_ARRAY) {
107       return false;
108     }
109   }
110   return false;
111 }
112 
113 bool Symbol::is_Q_method_signature() const {
114   assert(SignatureVerifier::is_valid_method_signature(this), "must be");
115   int len = utf8_length();
116   if (len > 4 && char_at(0) == JVM_SIGNATURE_FUNC) {
117     for (int i=1; i<len-3; i++) { // Must end with ")Qx;", where x is at least one character or more.
118       if (char_at(i) == JVM_SIGNATURE_ENDFUNC && char_at(i+1) == JVM_SIGNATURE_PRIMITIVE_OBJECT) {
119         return true;
120       }
121     }
122   }
123   return false;
124 }
125 
126 Symbol* Symbol::fundamental_name(TRAPS) {
127   if ((char_at(0) == JVM_SIGNATURE_PRIMITIVE_OBJECT || char_at(0) == JVM_SIGNATURE_CLASS) && ends_with(JVM_SIGNATURE_ENDCLASS)) {
128     return SymbolTable::new_symbol(this, 1, utf8_length() - 1);
129   } else {
130     // reference count is incremented to be consistent with the behavior with
131     // the SymbolTable::new_symbol() call above
132     this->increment_refcount();
133     return this;
134   }
135 }
136 
137 bool Symbol::is_same_fundamental_type(Symbol* s) const {
138   if (this == s) return true;
139   if (utf8_length() < 3) return false;
140   int offset1, offset2, len;
141   if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
142     if (char_at(0) != JVM_SIGNATURE_PRIMITIVE_OBJECT && char_at(0) != JVM_SIGNATURE_CLASS) return false;
143     offset1 = 1;
144     len = utf8_length() - 2;
145   } else {
146     offset1 = 0;
147     len = utf8_length();
148   }
149   if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
150     if (s->char_at(0) != JVM_SIGNATURE_PRIMITIVE_OBJECT && s->char_at(0) != JVM_SIGNATURE_CLASS) return false;
151     offset2 = 1;
152   } else {
153     offset2 = 0;
154   }
155   if ((offset2 + len) > s->utf8_length()) return false;
156   if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
157     return false;
158   int l = len;
159   while (l-- > 0) {
160     if (char_at(offset1 + l) != s->char_at(offset2 + l))
161       return false;
162   }
163   return true;
164 }
165 
166 // ------------------------------------------------------------------
167 // Symbol::index_of
168 //
169 // Test if we have the give substring at or after the i-th char of this
170 // symbol's utf8 bytes.
171 // Return -1 on failure.  Otherwise return the first index where substr occurs.
172 int Symbol::index_of_at(int i, const char* substr, int substr_len) const {
173   assert(i >= 0 && i <= utf8_length(), "oob");
174   if (substr_len <= 0)  return 0;
175   char first_char = substr[0];
176   address bytes = (address) ((Symbol*)this)->base();
177   address limit = bytes + utf8_length() - substr_len;  // inclusive limit
178   address scan = bytes + i;
179   if (scan > limit)
180     return -1;
181   for (; scan <= limit; scan++) {
182     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
183     if (scan == nullptr)
184       return -1;  // not found
185     assert(scan >= bytes+i && scan <= limit, "scan oob");

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