24 |
24 |
25 #ifndef SHARE_VM_CLASSFILE_ALTHASHING_HPP |
25 #ifndef SHARE_VM_CLASSFILE_ALTHASHING_HPP |
26 #define SHARE_VM_CLASSFILE_ALTHASHING_HPP |
26 #define SHARE_VM_CLASSFILE_ALTHASHING_HPP |
27 |
27 |
28 #include "prims/jni.h" |
28 #include "prims/jni.h" |
29 #include "classfile/symbolTable.hpp" |
29 #include "memory/allocation.hpp" |
30 |
30 |
31 /** |
31 /** |
32 * Hashing utilities. |
32 * Implementation of alternate more secure hashing. |
33 * |
|
34 * Implementation of Murmur3 hashing. |
|
35 * This code was translated from src/share/classes/sun/misc/Hashing.java |
|
36 * code in the JDK. |
|
37 */ |
33 */ |
38 |
34 |
39 class AltHashing : AllStatic { |
35 class AltHashing : AllStatic { |
40 |
36 |
41 // utility function copied from java/lang/Integer |
37 // For the seed computation |
42 static juint Integer_rotateLeft(juint i, int distance) { |
38 static uint64_t halfsiphash_64(const uint32_t* data, int len); |
43 return (i << distance) | (i >> (32-distance)); |
39 static uint64_t halfsiphash_64(uint64_t seed, const uint32_t* data, int len); |
44 } |
40 #ifndef PRODUCT |
45 static juint murmur3_32(const int* data, int len); |
41 // Hashing functions used for internal testing |
46 static juint murmur3_32(juint seed, const int* data, int len); |
42 static void testHalfsiphash_32_ByteArray(); |
|
43 static void testHalfsiphash_32_CharArray(); |
|
44 static void testHalfsiphash_64_FromReference(); |
|
45 #endif // PRODUCT |
|
46 public: |
|
47 static uint64_t compute_seed(); |
47 |
48 |
48 #ifndef PRODUCT |
49 // For Symbols |
49 // Hashing functions used for internal testing |
50 static uint32_t halfsiphash_32(uint64_t seed, const uint8_t* data, int len); |
50 static juint murmur3_32(const jbyte* data, int len); |
51 // For Strings |
51 static juint murmur3_32(const jchar* data, int len); |
52 static uint32_t halfsiphash_32(uint64_t seed, const uint16_t* data, int len); |
52 static void testMurmur3_32_ByteArray(); |
|
53 static void testEquivalentHashes(); |
|
54 #endif // PRODUCT |
|
55 |
|
56 public: |
|
57 static juint compute_seed(); |
|
58 static juint murmur3_32(juint seed, const jbyte* data, int len); |
|
59 static juint murmur3_32(juint seed, const jchar* data, int len); |
|
60 NOT_PRODUCT(static void test_alt_hash();) |
53 NOT_PRODUCT(static void test_alt_hash();) |
61 }; |
54 }; |
62 #endif // SHARE_VM_CLASSFILE_ALTHASHING_HPP |
55 #endif // SHARE_VM_CLASSFILE_ALTHASHING_HPP |