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