Mercurial > hg > openjdk > jdk7u > hotspot
changeset 5888:b878345a2866
8244955: Additional Fix for JDK-8240124
Reviewed-by: bae, yan
author | vkempik |
---|---|
date | Wed, 23 Sep 2020 17:34:10 +0300 |
parents | 3a09ec20ba0d |
children | 5e770b08bd33 |
files | src/share/vm/classfile/altHashing.cpp src/share/vm/classfile/altHashing.hpp src/share/vm/classfile/symbolTable.cpp src/share/vm/utilities/hashtable.cpp |
diffstat | 4 files changed, 55 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/vm/classfile/altHashing.cpp Wed Sep 23 17:23:54 2020 +0300 +++ b/src/share/vm/classfile/altHashing.cpp Wed Sep 23 17:34:10 2020 +0300 @@ -115,6 +115,12 @@ v[1] ^= 0xee; } +uint32_t halfsiphash_finish32(uint32_t v[4], int rounds) { + v[2] ^= 0xff; + halfsiphash_rounds(v, rounds); + return (v[1] ^ v[3]); +} + static uint64_t halfsiphash_finish64(uint32_t v[4], int rounds) { uint64_t rv; v[2] ^= 0xee; @@ -126,14 +132,14 @@ return rv; } -// HalfSipHash-2-4 (64-bit output) for Symbols -uint64_t AltHashing::halfsiphash_64(uint64_t seed, const int8_t* data, int len) { +// HalfSipHash-2-4 (32-bit output) for Symbols +uint32_t AltHashing::halfsiphash_32(uint64_t seed, const uint8_t* data, int len) { uint32_t v[4]; uint32_t newdata; int off = 0; int count = len; - halfsiphash_init64(v, seed); + halfsiphash_init32(v, seed); // body while (count >= 4) { // Avoid sign extension with 0x0ff @@ -168,17 +174,17 @@ halfsiphash_adddata(v, newdata, 2); // finalization - return halfsiphash_finish64(v, 4); + return halfsiphash_finish32(v, 4); } -// HalfSipHash-2-4 (64-bit output) for Strings -uint64_t AltHashing::halfsiphash_64(uint64_t seed, const uint16_t* data, int len) { +// HalfSipHash-2-4 (32-bit output) for Strings +uint32_t AltHashing::halfsiphash_32(uint64_t seed, const uint16_t* data, int len) { uint32_t v[4]; uint32_t newdata; int off = 0; int count = len; - halfsiphash_init64(v, seed); + halfsiphash_init32(v, seed); // body while (count >= 2) { @@ -199,7 +205,7 @@ halfsiphash_adddata(v, newdata, 2); // finalization - return halfsiphash_finish64(v, 4); + return halfsiphash_finish32(v, 4); } // HalfSipHash-2-4 (64-bit output) for integers (used to create seed) @@ -229,44 +235,44 @@ } #ifndef PRODUCT - void AltHashing::testHalfsiphash_64_ByteArray() { - // printf("testHalfsiphash_64_CharArray\n"); + void AltHashing::testHalfsiphash_32_ByteArray() { const int factor = 4; - int8_t vector[256]; - int8_t hashes[factor * 256]; + uint8_t vector[256]; + uint8_t hashes[factor * 256]; for (int i = 0; i < 256; i++) { - vector[i] = (int8_t) i; + vector[i] = (uint8_t) i; } // Hash subranges {}, {0}, {0,1}, {0,1,2}, ..., {0,...,255} for (int i = 0; i < 256; i++) { - uint64_t hash = AltHashing::halfsiphash_64(256 - i, vector, i); - hashes[i * factor] = (int8_t) hash; - hashes[i * factor + 1] = (int8_t)(hash >> 8); - hashes[i * factor + 2] = (int8_t)(hash >> 16); - hashes[i * factor + 3] = (int8_t)(hash >> 24); + uint32_t hash = AltHashing::halfsiphash_32(256 - i, vector, i); + hashes[i * factor] = (uint8_t) hash; + hashes[i * factor + 1] = (uint8_t)(hash >> 8); + hashes[i * factor + 2] = (uint8_t)(hash >> 16); + hashes[i * factor + 3] = (uint8_t)(hash >> 24); } // hash to get const result. - uint64_t final_hash = AltHashing::halfsiphash_64(0, hashes, factor*256); + uint32_t final_hash = AltHashing::halfsiphash_32(0, hashes, factor*256); // Value found using reference implementation for the hashes array. - // halfsiphash((const uint8_t*)hashes, factor*256, (const uint8_t *)&k, - // (uint8_t*)&reference, 8); - - static const uint64_t HALFSIPHASH_64_BYTE_CHECK_VALUE = 0x15a7911e30917ee8; + //uint64_t k = 0; // seed + //uint32_t reference; + //halfsiphash((const uint8_t*)hashes, factor*256, (const uint8_t *)&k, (uint8_t*)&reference, 4); + //printf("0x%x", reference); - assert (HALFSIPHASH_64_BYTE_CHECK_VALUE == final_hash, + static const uint32_t HALFSIPHASH_32_BYTE_CHECK_VALUE = 0xd2be7fd8; + + assert (HALFSIPHASH_32_BYTE_CHECK_VALUE == final_hash, err_msg( - "Calculated hash result not as expected. Expected " UINT64_FORMAT " got " UINT64_FORMAT, - HALFSIPHASH_64_BYTE_CHECK_VALUE, + "Calculated hash result not as expected. Expected " UINT32_FORMAT " got " UINT32_FORMAT, + HALFSIPHASH_32_BYTE_CHECK_VALUE, final_hash)); } - void AltHashing::testHalfsiphash_64_CharArray() { - // printf("testHalfsiphash_64_CharArray\n"); + void AltHashing::testHalfsiphash_32_CharArray() { const int factor = 2; uint16_t vector[256]; @@ -278,30 +284,32 @@ // Hash subranges {}, {0}, {0,1}, {0,1,2}, ..., {0,...,255} for (int i = 0; i < 256; i++) { - uint64_t hash = AltHashing::halfsiphash_64(256 - i, vector, i); + uint32_t hash = AltHashing::halfsiphash_32(256 - i, vector, i); hashes[i * factor] = (uint16_t) hash; hashes[i * factor + 1] = (uint16_t)(hash >> 16); } // hash to get const result. - uint64_t final_hash = AltHashing::halfsiphash_64(0, hashes, factor*256); + uint32_t final_hash = AltHashing::halfsiphash_32(0, hashes, factor*256); // Value found using reference implementation for the hashes array. - // halfsiphash((const uint8_t*)hashes, 2*factor*256, (const uint8_t *)&k, - // (uint8_t*)&reference, 8); - static const uint64_t HALFSIPHASH_64_CHAR_CHECK_VALUE = 0xf392d8a6a9e24103; + //uint64_t k = 0; // seed + //uint32_t reference; + //halfsiphash((const uint8_t*)hashes, 2*factor*256, (const uint8_t *)&k, (uint8_t*)&reference, 4); + //printf("0x%x", reference); - assert(HALFSIPHASH_64_CHAR_CHECK_VALUE == final_hash, + static const uint32_t HALFSIPHASH_32_CHAR_CHECK_VALUE = 0x428bf8a5; + + assert(HALFSIPHASH_32_CHAR_CHECK_VALUE == final_hash, err_msg( - "Calculated hash result not as expected. Expected " UINT64_FORMAT " got " UINT64_FORMAT, - HALFSIPHASH_64_CHAR_CHECK_VALUE, + "Calculated hash result not as expected. Expected " UINT32_FORMAT " got " UINT32_FORMAT, + HALFSIPHASH_32_CHAR_CHECK_VALUE, final_hash)); } // Test against sample hashes published with the reference implementation: // https://github.com/veorq/SipHash void AltHashing::testHalfsiphash_64_FromReference() { - // printf("testHalfsiphash_64_FromReference\n"); const uint64_t seed = 0x0706050403020100; const uint64_t results[16] = { @@ -332,8 +340,8 @@ } void AltHashing::test_alt_hash() { - testHalfsiphash_64_ByteArray(); - testHalfsiphash_64_CharArray(); + testHalfsiphash_32_ByteArray(); + testHalfsiphash_32_CharArray(); testHalfsiphash_64_FromReference(); } #endif // PRODUCT
--- a/src/share/vm/classfile/altHashing.hpp Wed Sep 23 17:23:54 2020 +0300 +++ b/src/share/vm/classfile/altHashing.hpp Wed Sep 23 17:34:10 2020 +0300 @@ -39,17 +39,17 @@ static uint64_t halfsiphash_64(uint64_t seed, const uint32_t* data, int len); #ifndef PRODUCT // Hashing functions used for internal testing - static void testHalfsiphash_64_ByteArray(); - static void testHalfsiphash_64_CharArray(); + static void testHalfsiphash_32_ByteArray(); + static void testHalfsiphash_32_CharArray(); static void testHalfsiphash_64_FromReference(); #endif // PRODUCT public: static uint64_t compute_seed(); // For Symbols - static uint64_t halfsiphash_64(uint64_t seed, const int8_t* data, int len); + static uint32_t halfsiphash_32(uint64_t seed, const uint8_t* data, int len); // For Strings - static uint64_t halfsiphash_64(uint64_t seed, const uint16_t* data, int len); + static uint32_t halfsiphash_32(uint64_t seed, const uint16_t* data, int len); NOT_PRODUCT(static void test_alt_hash();) }; #endif // SHARE_VM_CLASSFILE_ALTHASHING_HPP
--- a/src/share/vm/classfile/symbolTable.cpp Wed Sep 23 17:23:54 2020 +0300 +++ b/src/share/vm/classfile/symbolTable.cpp Wed Sep 23 17:34:10 2020 +0300 @@ -216,7 +216,7 @@ // Pick hashing algorithm. unsigned int SymbolTable::hash_symbol(const char* s, int len) { return use_alternate_hashcode() ? - AltHashing::halfsiphash_64(seed(), (const int8_t*)s, len) : + AltHashing::halfsiphash_32(seed(), (const uint8_t*)s, len) : java_lang_String::to_hash(s, len); } @@ -656,7 +656,7 @@ // Pick hashing algorithm unsigned int StringTable::hash_string(const jchar* s, int len) { - return use_alternate_hashcode() ? AltHashing::halfsiphash_64(seed(), s, len) : + return use_alternate_hashcode() ? AltHashing::halfsiphash_32(seed(), s, len) : java_lang_String::to_hash(s, len); }
--- a/src/share/vm/utilities/hashtable.cpp Wed Sep 23 17:23:54 2020 +0300 +++ b/src/share/vm/utilities/hashtable.cpp Wed Sep 23 17:34:10 2020 +0300 @@ -97,7 +97,7 @@ template <class T, MEMFLAGS F> unsigned int Hashtable<T, F>::new_hash(Symbol* sym) { ResourceMark rm; // Use alternate hashing algorithm on this symbol. - return AltHashing::halfsiphash_64(seed(), (const int8_t*)sym->as_C_string(), sym->utf8_length()); + return AltHashing::halfsiphash_32(seed(), (const uint8_t*)sym->as_C_string(), sym->utf8_length()); } template <class T, MEMFLAGS F> unsigned int Hashtable<T, F>::new_hash(oop string) { @@ -105,7 +105,7 @@ int length; jchar* chars = java_lang_String::as_unicode_string(string, length); // Use alternate hashing algorithm on the string - return AltHashing::halfsiphash_64(seed(), chars, length); + return AltHashing::halfsiphash_32(seed(), chars, length); } // Create a new table and using alternate hash code, populate the new table