Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 2e60627

Browse files
committed
8244955: Additional Fix for JDK-8240124
Reviewed-by: rehn, pliden, smarks
1 parent de4a373 commit 2e60627

File tree

8 files changed

+103
-117
lines changed

8 files changed

+103
-117
lines changed

src/hotspot/share/classfile/altHashing.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ static void halfsiphash_init64(uint32_t v[4], uint64_t seed) {
116116
v[1] ^= 0xee;
117117
}
118118

119+
uint32_t halfsiphash_finish32(uint32_t v[4], int rounds) {
120+
v[2] ^= 0xff;
121+
halfsiphash_rounds(v, rounds);
122+
return (v[1] ^ v[3]);
123+
}
124+
119125
static uint64_t halfsiphash_finish64(uint32_t v[4], int rounds) {
120126
uint64_t rv;
121127
v[2] ^= 0xee;
@@ -127,14 +133,14 @@ static uint64_t halfsiphash_finish64(uint32_t v[4], int rounds) {
127133
return rv;
128134
}
129135

130-
// HalfSipHash-2-4 (64-bit output) for Symbols
131-
uint64_t AltHashing::halfsiphash_64(uint64_t seed, const int8_t* data, int len) {
136+
// HalfSipHash-2-4 (32-bit output) for Symbols
137+
uint32_t AltHashing::halfsiphash_32(uint64_t seed, const uint8_t* data, int len) {
132138
uint32_t v[4];
133139
uint32_t newdata;
134140
int off = 0;
135141
int count = len;
136142

137-
halfsiphash_init64(v, seed);
143+
halfsiphash_init32(v, seed);
138144

139145
// body
140146
while (count >= 4) {
@@ -171,17 +177,17 @@ uint64_t AltHashing::halfsiphash_64(uint64_t seed, const int8_t* data, int len)
171177
halfsiphash_adddata(v, newdata, 2);
172178

173179
// finalization
174-
return halfsiphash_finish64(v, 4);
180+
return halfsiphash_finish32(v, 4);
175181
}
176182

177-
// HalfSipHash-2-4 (64-bit output) for Strings
178-
uint64_t AltHashing::halfsiphash_64(uint64_t seed, const uint16_t* data, int len) {
183+
// HalfSipHash-2-4 (32-bit output) for Strings
184+
uint32_t AltHashing::halfsiphash_32(uint64_t seed, const uint16_t* data, int len) {
179185
uint32_t v[4];
180186
uint32_t newdata;
181187
int off = 0;
182188
int count = len;
183189

184-
halfsiphash_init64(v, seed);
190+
halfsiphash_init32(v, seed);
185191

186192
// body
187193
while (count >= 2) {
@@ -202,7 +208,7 @@ uint64_t AltHashing::halfsiphash_64(uint64_t seed, const uint16_t* data, int len
202208
halfsiphash_adddata(v, newdata, 2);
203209

204210
// finalization
205-
return halfsiphash_finish64(v, 4);
211+
return halfsiphash_finish32(v, 4);
206212
}
207213

208214
// HalfSipHash-2-4 (64-bit output) for integers (used to create seed)

src/hotspot/share/classfile/altHashing.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class AltHashing : AllStatic {
4343
static uint64_t compute_seed();
4444

4545
// For Symbols
46-
static uint64_t halfsiphash_64(uint64_t seed, const int8_t* data, int len);
46+
static uint32_t halfsiphash_32(uint64_t seed, const uint8_t* data, int len);
4747
// For Strings
48-
static uint64_t halfsiphash_64(uint64_t seed, const uint16_t* data, int len);
48+
static uint32_t halfsiphash_32(uint64_t seed, const uint16_t* data, int len);
4949
};
5050
#endif // SHARE_CLASSFILE_ALTHASHING_HPP

src/hotspot/share/classfile/stringTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static uint64_t _alt_hash_seed = 0;
9797

9898
uintx hash_string(const jchar* s, int len, bool useAlt) {
9999
return useAlt ?
100-
AltHashing::halfsiphash_64(_alt_hash_seed, s, len) :
100+
AltHashing::halfsiphash_32(_alt_hash_seed, s, len) :
101101
java_lang_String::hash_code(s, len);
102102
}
103103

src/hotspot/share/classfile/symbolTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static inline void log_trace_symboltable_helper(Symbol* sym, const char* msg) {
111111
// Pick hashing algorithm.
112112
static uintx hash_symbol(const char* s, int len, bool useAlt) {
113113
return useAlt ?
114-
AltHashing::halfsiphash_64(_alt_hash_seed, (const int8_t*)s, len) :
114+
AltHashing::halfsiphash_32(_alt_hash_seed, (const uint8_t*)s, len) :
115115
java_lang_String::hash_code((const jbyte*)s, len);
116116
}
117117

src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void StringDedupEntryCache::free(StringDedupEntry* entry, uint worker_id) {
154154
assert(worker_id < _nlists, "Invalid worker id");
155155

156156
entry->set_obj(NULL);
157-
entry->set_java_hash(0, false /* latin1 */);
157+
entry->set_hash(0);
158158

159159
if (_cached[worker_id].length() < _max_list_length) {
160160
// Cache is not full
@@ -244,14 +244,11 @@ void StringDedupTable::create() {
244244
_table = new StringDedupTable(_min_size);
245245
}
246246

247-
void StringDedupTable::add(typeArrayOop value, bool latin1, uint64_t hash, StringDedupEntry** list) {
247+
void StringDedupTable::add(typeArrayOop value, bool latin1, unsigned int hash, StringDedupEntry** list) {
248248
StringDedupEntry* entry = _entry_cache->alloc();
249249
entry->set_obj(value);
250-
if (use_java_hash()) {
251-
entry->set_java_hash((unsigned int)hash, latin1);
252-
} else {
253-
entry->set_alt_hash(hash);
254-
}
250+
entry->set_hash(hash);
251+
entry->set_latin1(latin1);
255252
entry->set_next(*list);
256253
*list = entry;
257254
_entries++;
@@ -266,18 +263,17 @@ void StringDedupTable::remove(StringDedupEntry** pentry, uint worker_id) {
266263
void StringDedupTable::transfer(StringDedupEntry** pentry, StringDedupTable* dest) {
267264
StringDedupEntry* entry = *pentry;
268265
*pentry = entry->next();
269-
uint64_t hash = use_java_hash() ? entry->java_hash() : entry->alt_hash();
266+
unsigned int hash = entry->hash();
270267
size_t index = dest->hash_to_index(hash);
271268
StringDedupEntry** list = dest->bucket(index);
272269
entry->set_next(*list);
273270
*list = entry;
274271
}
275272

276-
typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, uint64_t hash,
273+
typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, unsigned int hash,
277274
StringDedupEntry** list, uintx &count) {
278275
for (StringDedupEntry* entry = *list; entry != NULL; entry = entry->next()) {
279-
if ((use_java_hash() && entry->java_hash() == hash && entry->java_hash_latin1() == latin1) ||
280-
(!use_java_hash() && entry->alt_hash() == hash)) {
276+
if (entry->hash() == hash && entry->latin1() == latin1) {
281277
oop* obj_addr = (oop*)entry->obj_addr();
282278
oop obj = NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(obj_addr);
283279
if (java_lang_String::value_equals(value, static_cast<typeArrayOop>(obj))) {
@@ -292,7 +288,7 @@ typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, uint64_t
292288
return NULL;
293289
}
294290

295-
typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool latin1, uint64_t hash) {
291+
typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool latin1, unsigned int hash) {
296292
size_t index = hash_to_index(hash);
297293
StringDedupEntry** list = bucket(index);
298294
uintx count = 0;
@@ -316,31 +312,29 @@ typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool lati
316312
return existing_value;
317313
}
318314

319-
unsigned int StringDedupTable::java_hash_code(typeArrayOop value, bool latin1) {
320-
assert(use_java_hash(), "Should not use java hash code");
321-
315+
unsigned int StringDedupTable::hash_code(typeArrayOop value, bool latin1) {
322316
unsigned int hash;
323317
int length = value->length();
324318
if (latin1) {
325319
const jbyte* data = (jbyte*)value->base(T_BYTE);
326-
hash = java_lang_String::hash_code(data, length);
320+
if (use_java_hash()) {
321+
hash = java_lang_String::hash_code(data, length);
322+
} else {
323+
hash = AltHashing::halfsiphash_32(_table->_hash_seed, (const uint8_t*)data, length);
324+
}
327325
} else {
328326
length /= sizeof(jchar) / sizeof(jbyte); // Convert number of bytes to number of chars
329327
const jchar* data = (jchar*)value->base(T_CHAR);
330-
hash = java_lang_String::hash_code(data, length);
328+
if (use_java_hash()) {
329+
hash = java_lang_String::hash_code(data, length);
330+
} else {
331+
hash = AltHashing::halfsiphash_32(_table->_hash_seed, (const uint16_t*)data, length);
332+
}
331333
}
332334

333335
return hash;
334336
}
335337

336-
uint64_t StringDedupTable::alt_hash_code(typeArrayOop value) {
337-
assert(!use_java_hash(), "Should not use alt hash code");
338-
339-
int length = value->length();
340-
const jbyte* data = (jbyte*)value->base(T_BYTE);
341-
return AltHashing::halfsiphash_64(_table->_hash_seed, (const int8_t*)data, length);
342-
}
343-
344338
void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
345339
assert(java_lang_String::is_instance(java_string), "Must be a string");
346340
NoSafepointVerifier nsv;
@@ -355,7 +349,7 @@ void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
355349
}
356350

357351
bool latin1 = java_lang_String::is_latin1(java_string);
358-
uint64_t hash = 0;
352+
unsigned int hash = 0;
359353

360354
if (use_java_hash()) {
361355
if (!java_lang_String::hash_is_set(java_string)) {
@@ -364,7 +358,7 @@ void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
364358
hash = java_lang_String::hash_code(java_string);
365359
} else {
366360
// Compute hash
367-
hash = alt_hash_code(value);
361+
hash = hash_code(value, latin1);
368362
stat->inc_hashed();
369363
}
370364

@@ -512,9 +506,9 @@ uintx StringDedupTable::unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl,
512506
// destination partitions. finish_rehash() will do a single
513507
// threaded transfer of all entries.
514508
typeArrayOop value = (typeArrayOop)*p;
515-
assert(!use_java_hash(), "Should not be using Java hash");
516-
uint64_t hash = alt_hash_code(value);
517-
(*entry)->set_alt_hash(hash);
509+
bool latin1 = (*entry)->latin1();
510+
unsigned int hash = hash_code(value, latin1);
511+
(*entry)->set_hash(hash);
518512
}
519513

520514
// Move to next entry
@@ -608,14 +602,9 @@ void StringDedupTable::verify() {
608602
guarantee(Universe::heap()->is_in_reserved(value), "Object must be on the heap");
609603
guarantee(!value->is_forwarded(), "Object must not be forwarded");
610604
guarantee(value->is_typeArray(), "Object must be a typeArrayOop");
611-
uint64_t hash;
612-
if (use_java_hash()) {
613-
hash = (*entry)->java_hash();
614-
guarantee(java_hash_code(value, (*entry)->java_hash_latin1()) == hash, "Table entry has incorrect hash");
615-
} else {
616-
hash = (*entry)->alt_hash();
617-
guarantee(alt_hash_code(value) == hash, "Table entry has incorrect hash");
618-
}
605+
bool latin1 = (*entry)->latin1();
606+
unsigned int hash = hash_code(value, latin1);
607+
guarantee((*entry)->hash() == hash, "Table entry has inorrect hash");
619608
guarantee(_table->hash_to_index(hash) == bucket, "Table entry has incorrect index");
620609
entry = (*entry)->next_addr();
621610
}
@@ -627,14 +616,12 @@ void StringDedupTable::verify() {
627616
StringDedupEntry** entry1 = _table->bucket(bucket);
628617
while (*entry1 != NULL) {
629618
typeArrayOop value1 = (*entry1)->obj();
619+
bool latin1_1 = (*entry1)->latin1();
630620
StringDedupEntry** entry2 = (*entry1)->next_addr();
631621
while (*entry2 != NULL) {
632622
typeArrayOop value2 = (*entry2)->obj();
633-
guarantee(value1 != value2, "Table entries must not have the same array");
634-
if (use_java_hash()) {
635-
guarantee((*entry1)->java_hash_latin1() != (*entry2)->java_hash_latin1() ||
636-
!java_lang_String::value_equals(value1, value2), "Table entries must not have identical arrays");
637-
}
623+
bool latin1_2 = (*entry2)->latin1();
624+
guarantee(latin1_1 != latin1_2 || !java_lang_String::value_equals(value1, value2), "Table entries must not have identical arrays");
638625
entry2 = (*entry2)->next_addr();
639626
}
640627
entry1 = (*entry1)->next_addr();
@@ -656,6 +643,6 @@ void StringDedupTable::print_statistics() {
656643
_table->_entries, percent_of((size_t)_table->_entries, _table->_size), _entry_cache->size(), _entries_added, _entries_removed);
657644
log.debug(" Resize Count: " UINTX_FORMAT ", Shrink Threshold: " UINTX_FORMAT "(" STRDEDUP_PERCENT_FORMAT_NS "), Grow Threshold: " UINTX_FORMAT "(" STRDEDUP_PERCENT_FORMAT_NS ")",
658645
_resize_count, _table->_shrink_threshold, _shrink_load_factor * 100.0, _table->_grow_threshold, _grow_load_factor * 100.0);
659-
log.debug(" Rehash Count: " UINTX_FORMAT ", Rehash Threshold: " UINTX_FORMAT ", Hash Seed: " UINT64_FORMAT_X, _rehash_count, _rehash_threshold, _table->_hash_seed);
646+
log.debug(" Rehash Count: " UINTX_FORMAT ", Rehash Threshold: " UINTX_FORMAT ", Hash Seed: " UINT64_FORMAT, _rehash_count, _rehash_threshold, _table->_hash_seed);
660647
log.debug(" Age Threshold: " UINTX_FORMAT, StringDeduplicationAgeThreshold);
661648
}

src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ class StringDedupUnlinkOrOopsDoClosure;
3939
class StringDedupEntry : public CHeapObj<mtGC> {
4040
private:
4141
StringDedupEntry* _next;
42-
uint64_t _hash;
42+
unsigned int _hash;
43+
bool _latin1;
4344
typeArrayOop _obj;
4445

45-
static const uint64_t java_hash_mask = ((uint64_t)1 << 32) - 1;
46-
static const uint64_t java_latin1_mask = (uint64_t)1 << 63;
47-
4846
public:
4947
StringDedupEntry() :
5048
_next(NULL),
5149
_hash(0),
50+
_latin1(false),
5251
_obj(NULL) {
5352
}
5453

@@ -64,27 +63,20 @@ class StringDedupEntry : public CHeapObj<mtGC> {
6463
_next = next;
6564
}
6665

67-
unsigned int java_hash() {
68-
return (unsigned int)(_hash & java_hash_mask);
69-
}
70-
71-
bool java_hash_latin1() {
72-
return (_hash & java_latin1_mask) != 0;
66+
unsigned int hash() {
67+
return _hash;
7368
}
7469

75-
void set_java_hash(unsigned int hash, bool latin1) {
70+
void set_hash(unsigned int hash) {
7671
_hash = hash;
77-
if (latin1) {
78-
_hash |= java_latin1_mask;
79-
}
8072
}
8173

82-
uint64_t alt_hash() {
83-
return _hash;
74+
bool latin1() {
75+
return _latin1;
8476
}
8577

86-
void set_alt_hash(uint64_t hash) {
87-
_hash = hash;
78+
void set_latin1(bool latin1) {
79+
_latin1 = latin1;
8880
}
8981

9082
typeArrayOop obj() {
@@ -138,7 +130,7 @@ class StringDedupTable : public CHeapObj<mtGC> {
138130
// The hash seed also dictates which hash function to use. A
139131
// zero hash seed means we will use the Java compatible hash
140132
// function (which doesn't use a seed), and a non-zero hash
141-
// seed means we use the alternate and better hash function.
133+
// seed means we use the murmur3 hash function.
142134
uint64_t _hash_seed;
143135

144136
// Constants governing table resize/rehash/cache.
@@ -170,12 +162,12 @@ class StringDedupTable : public CHeapObj<mtGC> {
170162
}
171163

172164
// Returns the hash bucket index for the given hash code.
173-
size_t hash_to_index(uint64_t hash) {
165+
size_t hash_to_index(unsigned int hash) {
174166
return (size_t)hash & (_size - 1);
175167
}
176168

177169
// Adds a new table entry to the given hash bucket.
178-
void add(typeArrayOop value, bool latin1, uint64_t hash, StringDedupEntry** list);
170+
void add(typeArrayOop value, bool latin1, unsigned int hash, StringDedupEntry** list);
179171

180172
// Removes the given table entry from the table.
181173
void remove(StringDedupEntry** pentry, uint worker_id);
@@ -185,15 +177,15 @@ class StringDedupTable : public CHeapObj<mtGC> {
185177

186178
// Returns an existing character array in the given hash bucket, or NULL
187179
// if no matching character array exists.
188-
typeArrayOop lookup(typeArrayOop value, bool latin1, uint64_t hash,
180+
typeArrayOop lookup(typeArrayOop value, bool latin1, unsigned int hash,
189181
StringDedupEntry** list, uintx &count);
190182

191183
// Returns an existing character array in the table, or inserts a new
192184
// table entry if no matching character array exists.
193-
typeArrayOop lookup_or_add_inner(typeArrayOop value, bool latin1, uint64_t hash);
185+
typeArrayOop lookup_or_add_inner(typeArrayOop value, bool latin1, unsigned int hash);
194186

195187
// Thread safe lookup or add of table entry
196-
static typeArrayOop lookup_or_add(typeArrayOop value, bool latin1, uint64_t hash) {
188+
static typeArrayOop lookup_or_add(typeArrayOop value, bool latin1, unsigned int hash) {
197189
// Protect the table from concurrent access. Also note that this lock
198190
// acts as a fence for _table, which could have been replaced by a new
199191
// instance if the table was resized or rehashed.
@@ -209,8 +201,7 @@ class StringDedupTable : public CHeapObj<mtGC> {
209201

210202
// Computes the hash code for the given character array, using the
211203
// currently active hash function and hash seed.
212-
static unsigned int java_hash_code(typeArrayOop value, bool latin1);
213-
static uint64_t alt_hash_code(typeArrayOop value);
204+
static unsigned int hash_code(typeArrayOop value, bool latin1);
214205

215206
static uintx unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl,
216207
size_t partition_begin,

src/hotspot/share/memory/filemap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ template <int N> static void get_header_version(char (&header_version) [N]) {
163163
} else {
164164
// Get the hash value. Use a static seed because the hash needs to return the same
165165
// value over multiple jvm invocations.
166-
uint64_t hash = AltHashing::halfsiphash_64(8191, (const int8_t*)vm_version, version_len);
166+
uint32_t hash = AltHashing::halfsiphash_32(8191, (const uint8_t*)vm_version, version_len);
167167

168-
// Truncate the ident, saving room for the 16 hex character hash value.
169-
strncpy(header_version, vm_version, JVM_IDENT_MAX-17);
168+
// Truncate the ident, saving room for the 8 hex character hash value.
169+
strncpy(header_version, vm_version, JVM_IDENT_MAX-9);
170170

171-
// Append the hash code as 16 hex digits.
172-
sprintf(&header_version[JVM_IDENT_MAX-17], "%016" PRIx64, hash);
171+
// Append the hash code as eight hex digits.
172+
sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash);
173173
header_version[JVM_IDENT_MAX-1] = 0; // Null terminate.
174174
}
175175

0 commit comments

Comments
 (0)