Skip to content

Commit 5f1918d

Browse files
coleenpslowhog
authored andcommitted
8244955: Additional Fix for JDK-8240124
Reviewed-by: rehn, pliden, smarks
1 parent 798bfb3 commit 5f1918d

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
@@ -95,7 +95,7 @@ static uint64_t _alt_hash_seed = 0;
9595

9696
uintx hash_string(const jchar* s, int len, bool useAlt) {
9797
return useAlt ?
98-
AltHashing::halfsiphash_64(_alt_hash_seed, s, len) :
98+
AltHashing::halfsiphash_32(_alt_hash_seed, s, len) :
9999
java_lang_String::hash_code(s, len);
100100
}
101101

src/hotspot/share/classfile/symbolTable.cpp

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

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

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

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

161161
if (_cached[worker_id].length() < _max_list_length) {
162162
// Cache is not full
@@ -246,14 +246,11 @@ void StringDedupTable::create() {
246246
_table = new StringDedupTable(_min_size);
247247
}
248248

249-
void StringDedupTable::add(typeArrayOop value, bool latin1, uint64_t hash, StringDedupEntry** list) {
249+
void StringDedupTable::add(typeArrayOop value, bool latin1, unsigned int hash, StringDedupEntry** list) {
250250
StringDedupEntry* entry = _entry_cache->alloc();
251251
entry->set_obj(value);
252-
if (use_java_hash()) {
253-
entry->set_java_hash((unsigned int)hash, latin1);
254-
} else {
255-
entry->set_alt_hash(hash);
256-
}
252+
entry->set_hash(hash);
253+
entry->set_latin1(latin1);
257254
entry->set_next(*list);
258255
*list = entry;
259256
_entries++;
@@ -268,18 +265,17 @@ void StringDedupTable::remove(StringDedupEntry** pentry, uint worker_id) {
268265
void StringDedupTable::transfer(StringDedupEntry** pentry, StringDedupTable* dest) {
269266
StringDedupEntry* entry = *pentry;
270267
*pentry = entry->next();
271-
uint64_t hash = use_java_hash() ? entry->java_hash() : entry->alt_hash();
268+
unsigned int hash = entry->hash();
272269
size_t index = dest->hash_to_index(hash);
273270
StringDedupEntry** list = dest->bucket(index);
274271
entry->set_next(*list);
275272
*list = entry;
276273
}
277274

278-
typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, uint64_t hash,
275+
typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, unsigned int hash,
279276
StringDedupEntry** list, uintx &count) {
280277
for (StringDedupEntry* entry = *list; entry != NULL; entry = entry->next()) {
281-
if ((use_java_hash() && entry->java_hash() == hash && entry->java_hash_latin1() == latin1) ||
282-
(!use_java_hash() && entry->alt_hash() == hash)) {
278+
if (entry->hash() == hash && entry->latin1() == latin1) {
283279
oop* obj_addr = (oop*)entry->obj_addr();
284280
oop obj = NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(obj_addr);
285281
if (obj != NULL && java_lang_String::value_equals(value, static_cast<typeArrayOop>(obj))) {
@@ -294,7 +290,7 @@ typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, uint64_t
294290
return NULL;
295291
}
296292

297-
typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool latin1, uint64_t hash) {
293+
typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool latin1, unsigned int hash) {
298294
size_t index = hash_to_index(hash);
299295
StringDedupEntry** list = bucket(index);
300296
uintx count = 0;
@@ -318,31 +314,29 @@ typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool lati
318314
return existing_value;
319315
}
320316

321-
unsigned int StringDedupTable::java_hash_code(typeArrayOop value, bool latin1) {
322-
assert(use_java_hash(), "Should not use java hash code");
323-
317+
unsigned int StringDedupTable::hash_code(typeArrayOop value, bool latin1) {
324318
unsigned int hash;
325319
int length = value->length();
326320
if (latin1) {
327321
const jbyte* data = (jbyte*)value->base(T_BYTE);
328-
hash = java_lang_String::hash_code(data, length);
322+
if (use_java_hash()) {
323+
hash = java_lang_String::hash_code(data, length);
324+
} else {
325+
hash = AltHashing::halfsiphash_32(_table->_hash_seed, (const uint8_t*)data, length);
326+
}
329327
} else {
330328
length /= sizeof(jchar) / sizeof(jbyte); // Convert number of bytes to number of chars
331329
const jchar* data = (jchar*)value->base(T_CHAR);
332-
hash = java_lang_String::hash_code(data, length);
330+
if (use_java_hash()) {
331+
hash = java_lang_String::hash_code(data, length);
332+
} else {
333+
hash = AltHashing::halfsiphash_32(_table->_hash_seed, (const uint16_t*)data, length);
334+
}
333335
}
334336

335337
return hash;
336338
}
337339

338-
uint64_t StringDedupTable::alt_hash_code(typeArrayOop value) {
339-
assert(!use_java_hash(), "Should not use alt hash code");
340-
341-
int length = value->length();
342-
const jbyte* data = (jbyte*)value->base(T_BYTE);
343-
return AltHashing::halfsiphash_64(_table->_hash_seed, (const int8_t*)data, length);
344-
}
345-
346340
void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
347341
assert(java_lang_String::is_instance(java_string), "Must be a string");
348342
NoSafepointVerifier nsv;
@@ -357,7 +351,7 @@ void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
357351
}
358352

359353
bool latin1 = java_lang_String::is_latin1(java_string);
360-
uint64_t hash = 0;
354+
unsigned int hash = 0;
361355

362356
if (use_java_hash()) {
363357
if (!java_lang_String::hash_is_set(java_string)) {
@@ -366,7 +360,7 @@ void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
366360
hash = java_lang_String::hash_code(java_string);
367361
} else {
368362
// Compute hash
369-
hash = alt_hash_code(value);
363+
hash = hash_code(value, latin1);
370364
stat->inc_hashed();
371365
}
372366

@@ -516,9 +510,9 @@ uintx StringDedupTable::unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl,
516510
// destination partitions. finish_rehash() will do a single
517511
// threaded transfer of all entries.
518512
typeArrayOop value = (typeArrayOop)*p;
519-
assert(!use_java_hash(), "Should not be using Java hash");
520-
uint64_t hash = alt_hash_code(value);
521-
(*entry)->set_alt_hash(hash);
513+
bool latin1 = (*entry)->latin1();
514+
unsigned int hash = hash_code(value, latin1);
515+
(*entry)->set_hash(hash);
522516
}
523517

524518
// Move to next entry
@@ -612,14 +606,9 @@ void StringDedupTable::verify() {
612606
guarantee(Universe::heap()->is_in(value), "Object must be on the heap");
613607
guarantee(!value->is_forwarded(), "Object must not be forwarded");
614608
guarantee(value->is_typeArray(), "Object must be a typeArrayOop");
615-
uint64_t hash;
616-
if (use_java_hash()) {
617-
hash = (*entry)->java_hash();
618-
guarantee(java_hash_code(value, (*entry)->java_hash_latin1()) == hash, "Table entry has incorrect hash");
619-
} else {
620-
hash = (*entry)->alt_hash();
621-
guarantee(alt_hash_code(value) == hash, "Table entry has incorrect hash");
622-
}
609+
bool latin1 = (*entry)->latin1();
610+
unsigned int hash = hash_code(value, latin1);
611+
guarantee((*entry)->hash() == hash, "Table entry has inorrect hash");
623612
guarantee(_table->hash_to_index(hash) == bucket, "Table entry has incorrect index");
624613
entry = (*entry)->next_addr();
625614
}
@@ -631,14 +620,12 @@ void StringDedupTable::verify() {
631620
StringDedupEntry** entry1 = _table->bucket(bucket);
632621
while (*entry1 != NULL) {
633622
typeArrayOop value1 = (*entry1)->obj();
623+
bool latin1_1 = (*entry1)->latin1();
634624
StringDedupEntry** entry2 = (*entry1)->next_addr();
635625
while (*entry2 != NULL) {
636626
typeArrayOop value2 = (*entry2)->obj();
637-
guarantee(value1 != value2, "Table entries must not have the same array");
638-
if (use_java_hash()) {
639-
guarantee((*entry1)->java_hash_latin1() != (*entry2)->java_hash_latin1() ||
640-
!java_lang_String::value_equals(value1, value2), "Table entries must not have identical arrays");
641-
}
627+
bool latin1_2 = (*entry2)->latin1();
628+
guarantee(latin1_1 != latin1_2 || !java_lang_String::value_equals(value1, value2), "Table entries must not have identical arrays");
642629
entry2 = (*entry2)->next_addr();
643630
}
644631
entry1 = (*entry1)->next_addr();
@@ -660,6 +647,6 @@ void StringDedupTable::print_statistics() {
660647
_table->_entries, percent_of((size_t)_table->_entries, _table->_size), _entry_cache->size(), _entries_added, _entries_removed);
661648
log.debug(" Resize Count: " UINTX_FORMAT ", Shrink Threshold: " UINTX_FORMAT "(" STRDEDUP_PERCENT_FORMAT_NS "), Grow Threshold: " UINTX_FORMAT "(" STRDEDUP_PERCENT_FORMAT_NS ")",
662649
_resize_count, _table->_shrink_threshold, _shrink_load_factor * 100.0, _table->_grow_threshold, _grow_load_factor * 100.0);
663-
log.debug(" Rehash Count: " UINTX_FORMAT ", Rehash Threshold: " UINTX_FORMAT ", Hash Seed: " UINT64_FORMAT_X, _rehash_count, _rehash_threshold, _table->_hash_seed);
650+
log.debug(" Rehash Count: " UINTX_FORMAT ", Rehash Threshold: " UINTX_FORMAT ", Hash Seed: " UINT64_FORMAT, _rehash_count, _rehash_threshold, _table->_hash_seed);
664651
log.debug(" Age Threshold: " UINTX_FORMAT, StringDeduplicationAgeThreshold);
665652
}

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
@@ -150,13 +150,13 @@ template <int N> static void get_header_version(char (&header_version) [N]) {
150150
} else {
151151
// Get the hash value. Use a static seed because the hash needs to return the same
152152
// value over multiple jvm invocations.
153-
uint64_t hash = AltHashing::halfsiphash_64(8191, (const int8_t*)vm_version, version_len);
153+
uint32_t hash = AltHashing::halfsiphash_32(8191, (const uint8_t*)vm_version, version_len);
154154

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

158-
// Append the hash code as 16 hex digits.
159-
sprintf(&header_version[JVM_IDENT_MAX-17], "%016" PRIx64, hash);
158+
// Append the hash code as eight hex digits.
159+
sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash);
160160
header_version[JVM_IDENT_MAX-1] = 0; // Null terminate.
161161
}
162162

0 commit comments

Comments
 (0)