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