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