89 assert(((Symbol*)p)->refcount() == 0, "should not call this");
90 FreeHeap(p);
91 }
92
93 #if INCLUDE_CDS
94 void Symbol::update_identity_hash() {
95 // This is called at a safepoint during dumping of a static CDS archive. The caller should have
96 // called os::init_random() with a deterministic seed and then iterate all archived Symbols in
97 // a deterministic order.
98 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
99 _hash_and_refcount = pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
100 }
101
102 void Symbol::set_permanent() {
103 // This is called at a safepoint during dumping of a dynamic CDS archive.
104 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
105 _hash_and_refcount = pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
106 }
107 #endif
108
109 // ------------------------------------------------------------------
110 // Symbol::index_of
111 //
112 // Finds if the given string is a substring of this symbol's utf8 bytes.
113 // Return -1 on failure. Otherwise return the first index where str occurs.
114 int Symbol::index_of_at(int i, const char* str, int len) const {
115 assert(i >= 0 && i <= utf8_length(), "oob");
116 if (len <= 0) return 0;
117 char first_char = str[0];
118 address bytes = (address) ((Symbol*)this)->base();
119 address limit = bytes + utf8_length() - len; // inclusive limit
120 address scan = bytes + i;
121 if (scan > limit)
122 return -1;
123 for (; scan <= limit; scan++) {
124 scan = (address) memchr(scan, first_char, (limit + 1 - scan));
125 if (scan == NULL)
126 return -1; // not found
127 assert(scan >= bytes+i && scan <= limit, "scan oob");
128 if (len <= 2
393 }
394
395 void Symbol::print_value() const { print_value_on(tty); }
396
397 bool Symbol::is_valid(Symbol* s) {
398 if (!is_aligned(s, sizeof(MetaWord))) return false;
399 if ((size_t)s < os::min_page_size()) return false;
400
401 if (!os::is_readable_range(s, s + 1)) return false;
402
403 // Symbols are not allocated in Java heap.
404 if (Universe::heap()->is_in(s)) return false;
405
406 int len = s->utf8_length();
407 if (len < 0) return false;
408
409 jbyte* bytes = (jbyte*) s->bytes();
410 return os::is_readable_range(bytes, bytes + len);
411 }
412
413 // SymbolTable prints this in its statistics
414 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
|
89 assert(((Symbol*)p)->refcount() == 0, "should not call this");
90 FreeHeap(p);
91 }
92
93 #if INCLUDE_CDS
94 void Symbol::update_identity_hash() {
95 // This is called at a safepoint during dumping of a static CDS archive. The caller should have
96 // called os::init_random() with a deterministic seed and then iterate all archived Symbols in
97 // a deterministic order.
98 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
99 _hash_and_refcount = pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
100 }
101
102 void Symbol::set_permanent() {
103 // This is called at a safepoint during dumping of a dynamic CDS archive.
104 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
105 _hash_and_refcount = pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT);
106 }
107 #endif
108
109 bool Symbol::is_Q_signature() const {
110 int len = utf8_length();
111 return len > 2 && char_at(0) == JVM_SIGNATURE_INLINE_TYPE && char_at(len - 1) == JVM_SIGNATURE_ENDCLASS;
112 }
113
114 bool Symbol::is_Q_array_signature() const {
115 int l = utf8_length();
116 if (l < 2 || char_at(0) != JVM_SIGNATURE_ARRAY || char_at(l - 1) != JVM_SIGNATURE_ENDCLASS) {
117 return false;
118 }
119 for (int i = 1; i < (l - 2); i++) {
120 char c = char_at(i);
121 if (c == JVM_SIGNATURE_INLINE_TYPE) {
122 return true;
123 }
124 if (c != JVM_SIGNATURE_ARRAY) {
125 return false;
126 }
127 }
128 return false;
129 }
130
131 bool Symbol::is_Q_method_signature() const {
132 assert(SignatureVerifier::is_valid_method_signature(this), "must be");
133 int len = utf8_length();
134 if (len > 4 && char_at(0) == JVM_SIGNATURE_FUNC) {
135 for (int i=1; i<len-3; i++) { // Must end with ")Qx;", where x is at least one character or more.
136 if (char_at(i) == JVM_SIGNATURE_ENDFUNC && char_at(i+1) == JVM_SIGNATURE_INLINE_TYPE) {
137 return true;
138 }
139 }
140 }
141 return false;
142 }
143
144 Symbol* Symbol::fundamental_name(TRAPS) {
145 if ((char_at(0) == JVM_SIGNATURE_INLINE_TYPE || char_at(0) == JVM_SIGNATURE_CLASS) && ends_with(JVM_SIGNATURE_ENDCLASS)) {
146 return SymbolTable::new_symbol(this, 1, utf8_length() - 1);
147 } else {
148 // reference count is incremented to be consistent with the behavior with
149 // the SymbolTable::new_symbol() call above
150 this->increment_refcount();
151 return this;
152 }
153 }
154
155 bool Symbol::is_same_fundamental_type(Symbol* s) const {
156 if (this == s) return true;
157 if (utf8_length() < 3) return false;
158 int offset1, offset2, len;
159 if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
160 if (char_at(0) != JVM_SIGNATURE_INLINE_TYPE && char_at(0) != JVM_SIGNATURE_CLASS) return false;
161 offset1 = 1;
162 len = utf8_length() - 2;
163 } else {
164 offset1 = 0;
165 len = utf8_length();
166 }
167 if (ends_with(JVM_SIGNATURE_ENDCLASS)) {
168 if (s->char_at(0) != JVM_SIGNATURE_INLINE_TYPE && s->char_at(0) != JVM_SIGNATURE_CLASS) return false;
169 offset2 = 1;
170 } else {
171 offset2 = 0;
172 }
173 if ((offset2 + len) > s->utf8_length()) return false;
174 if ((utf8_length() - offset1 * 2) != (s->utf8_length() - offset2 * 2))
175 return false;
176 int l = len;
177 while (l-- > 0) {
178 if (char_at(offset1 + l) != s->char_at(offset2 + l))
179 return false;
180 }
181 return true;
182 }
183
184 // ------------------------------------------------------------------
185 // Symbol::index_of
186 //
187 // Finds if the given string is a substring of this symbol's utf8 bytes.
188 // Return -1 on failure. Otherwise return the first index where str occurs.
189 int Symbol::index_of_at(int i, const char* str, int len) const {
190 assert(i >= 0 && i <= utf8_length(), "oob");
191 if (len <= 0) return 0;
192 char first_char = str[0];
193 address bytes = (address) ((Symbol*)this)->base();
194 address limit = bytes + utf8_length() - len; // inclusive limit
195 address scan = bytes + i;
196 if (scan > limit)
197 return -1;
198 for (; scan <= limit; scan++) {
199 scan = (address) memchr(scan, first_char, (limit + 1 - scan));
200 if (scan == NULL)
201 return -1; // not found
202 assert(scan >= bytes+i && scan <= limit, "scan oob");
203 if (len <= 2
468 }
469
470 void Symbol::print_value() const { print_value_on(tty); }
471
472 bool Symbol::is_valid(Symbol* s) {
473 if (!is_aligned(s, sizeof(MetaWord))) return false;
474 if ((size_t)s < os::min_page_size()) return false;
475
476 if (!os::is_readable_range(s, s + 1)) return false;
477
478 // Symbols are not allocated in Java heap.
479 if (Universe::heap()->is_in(s)) return false;
480
481 int len = s->utf8_length();
482 if (len < 0) return false;
483
484 jbyte* bytes = (jbyte*) s->bytes();
485 return os::is_readable_range(bytes, bytes + len);
486 }
487
488 void Symbol::print_Qvalue_on(outputStream* st) const {
489 if (this == NULL) {
490 st->print("NULL");
491 } else {
492 st->print("'Q");
493 for (int i = 0; i < utf8_length(); i++) {
494 st->print("%c", char_at(i));
495 }
496 st->print(";'");
497 }
498 }
499
500 // SymbolTable prints this in its statistics
501 NOT_PRODUCT(size_t Symbol::_total_count = 0;)
|