< prev index next >

src/hotspot/share/oops/symbol.cpp

Print this page

 69 // This copies the symbol when it is added to the ConcurrentHashTable.
 70 Symbol::Symbol(const Symbol& s1) {
 71   _hash_and_refcount = s1._hash_and_refcount;
 72   _length = s1._length;
 73   memcpy(_body, s1._body, _length);
 74 }
 75 
 76 #if INCLUDE_CDS
 77 void Symbol::update_identity_hash() {
 78   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 79   _hash_and_refcount =  pack_hash_and_refcount((short)ArchiveBuilder::current()->entropy(), PERM_REFCOUNT);
 80 }
 81 
 82 void Symbol::set_permanent() {
 83   // This is called at a safepoint during dumping of a dynamic CDS archive.
 84   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 85   _hash_and_refcount =  pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
 86 }
 87 #endif
 88 








































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

 69 // This copies the symbol when it is added to the ConcurrentHashTable.
 70 Symbol::Symbol(const Symbol& s1) {
 71   _hash_and_refcount = s1._hash_and_refcount;
 72   _length = s1._length;
 73   memcpy(_body, s1._body, _length);
 74 }
 75 
 76 #if INCLUDE_CDS
 77 void Symbol::update_identity_hash() {
 78   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 79   _hash_and_refcount =  pack_hash_and_refcount((short)ArchiveBuilder::current()->entropy(), PERM_REFCOUNT);
 80 }
 81 
 82 void Symbol::set_permanent() {
 83   // This is called at a safepoint during dumping of a dynamic CDS archive.
 84   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
 85   _hash_and_refcount =  pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
 86 }
 87 #endif
 88 
 89 Symbol* Symbol::fundamental_name(TRAPS) {
 90   if (char_at(0) == JVM_SIGNATURE_CLASS && ends_with(JVM_SIGNATURE_ENDCLASS)) {
 91     return SymbolTable::new_symbol(this, 1, utf8_length() - 1);
 92   } else {
 93     // reference count is incremented to be consistent with the behavior with
 94     // the SymbolTable::new_symbol() call above
 95     this->increment_refcount();
 96     return this;
 97   }
 98 }
 99 
100 bool Symbol::is_same_fundamental_type(Symbol* s) const {
101   if (this == s) return true;
102   if (utf8_length() < 3) return false;
103   int offset1, offset2, len;
104   if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
105     if (char_at(0) != JVM_SIGNATURE_CLASS) return false;
106     offset1 = 1;
107     len = utf8_length() - 2;
108   } else {
109     offset1 = 0;
110     len = utf8_length();
111   }
112   if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
113     if (s->char_at(0) != JVM_SIGNATURE_CLASS) return false;
114     offset2 = 1;
115   } else {
116     offset2 = 0;
117   }
118   if ((offset2 + len) > s->utf8_length()) return false;
119   if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
120     return false;
121   int l = len;
122   while (l-- > 0) {
123     if (char_at(offset1 + l) != s->char_at(offset2 + l))
124       return false;
125   }
126   return true;
127 }
128 
129 // ------------------------------------------------------------------
130 // Symbol::index_of
131 //
132 // Test if we have the give substring at or after the i-th char of this
133 // symbol's utf8 bytes.
134 // Return -1 on failure.  Otherwise return the first index where substr occurs.
135 int Symbol::index_of_at(int i, const char* substr, int substr_len) const {
136   assert(i >= 0 && i <= utf8_length(), "oob");
137   if (substr_len <= 0)  return 0;
138   char first_char = substr[0];
139   address bytes = (address) ((Symbol*)this)->base();
140   address limit = bytes + utf8_length() - substr_len;  // inclusive limit
141   address scan = bytes + i;
142   if (scan > limit)
143     return -1;
144   for (; scan <= limit; scan++) {
145     scan = (address) memchr(scan, first_char, (limit + 1 - scan));
146     if (scan == nullptr)
147       return -1;  // not found
148     assert(scan >= bytes+i && scan <= limit, "scan oob");
< prev index next >