25 #include "precompiled.hpp" 26 #include "classfile/altHashing.hpp" 27 #include "classfile/symbolTable.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "oops/markOop.hpp" 30 #include "runtime/thread.hpp" 31 32 // Get the hash code of the classes mirror if it exists, otherwise just 33 // return a random number, which is one of the possible hash code used for 34 // objects. We don't want to call the synchronizer hash code to install 35 // this value because it may safepoint. 36 static intptr_t object_hash(Klass* k) { 37 intptr_t hc = k->java_mirror()->mark()->hash(); 38 return hc != markOopDesc::no_hash ? hc : os::random(); 39 } 40 41 // Seed value used for each alternative hash calculated. 42 juint AltHashing::compute_seed() { 43 jlong nanos = os::javaTimeNanos(); 44 jlong now = os::javaTimeMillis(); 45 int SEED_MATERIAL[8] = { 46 (int) object_hash(SystemDictionary::String_klass()), 47 (int) object_hash(SystemDictionary::System_klass()), 48 os::random(), // current thread isn't a java thread 49 (int) (((julong)nanos) >> 32), 50 (int) nanos, 51 (int) (((julong)now) >> 32), 52 (int) now, 53 (int) (os::javaTimeNanos() >> 2) 54 }; 55 56 return murmur3_32(SEED_MATERIAL, 8); 57 } 58 59 60 // Murmur3 hashing for Symbol 61 juint AltHashing::murmur3_32(juint seed, const jbyte* data, int len) { 62 juint h1 = seed; 63 int count = len; 64 int offset = 0; 65 66 // body 67 while (count >= 4) { 68 juint k1 = (data[offset] & 0x0FF) 69 | (data[offset + 1] & 0x0FF) << 8 70 | (data[offset + 2] & 0x0FF) << 16 71 | data[offset + 3] << 24; 72 73 count -= 4; 150 k1 *= 0xcc9e2d51; 151 k1 = Integer_rotateLeft(k1, 15); 152 k1 *= 0x1b873593; 153 h1 ^= k1; 154 } 155 156 // finalization 157 h1 ^= len * 2; // (Character.SIZE / Byte.SIZE); 158 159 // finalization mix force all bits of a hash block to avalanche 160 h1 ^= h1 >> 16; 161 h1 *= 0x85ebca6b; 162 h1 ^= h1 >> 13; 163 h1 *= 0xc2b2ae35; 164 h1 ^= h1 >> 16; 165 166 return h1; 167 } 168 169 // Hash used for the seed. 170 juint AltHashing::murmur3_32(juint seed, const int* data, int len) { 171 juint h1 = seed; 172 173 int off = 0; 174 int end = len; 175 176 // body 177 while (off < end) { 178 juint k1 = (juint)data[off++]; 179 180 k1 *= 0xcc9e2d51; 181 k1 = Integer_rotateLeft(k1, 15); 182 k1 *= 0x1b873593; 183 184 h1 ^= k1; 185 h1 = Integer_rotateLeft(h1, 13); 186 h1 = h1 * 5 + 0xe6546b64; 187 } 188 189 // tail (always empty, as body is always 32-bit chunks) 190 191 // finalization 192 193 h1 ^= len * 4; // (Integer.SIZE / Byte.SIZE); 194 195 // finalization mix force all bits of a hash block to avalanche 196 h1 ^= h1 >> 16; 197 h1 *= 0x85ebca6b; 198 h1 ^= h1 >> 13; 199 h1 *= 0xc2b2ae35; 200 h1 ^= h1 >> 16; 201 202 return h1; 203 } 204 205 juint AltHashing::murmur3_32(const int* data, int len) { 206 return murmur3_32(0, data, len); 207 } | 25 #include "precompiled.hpp" 26 #include "classfile/altHashing.hpp" 27 #include "classfile/symbolTable.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "oops/markOop.hpp" 30 #include "runtime/thread.hpp" 31 32 // Get the hash code of the classes mirror if it exists, otherwise just 33 // return a random number, which is one of the possible hash code used for 34 // objects. We don't want to call the synchronizer hash code to install 35 // this value because it may safepoint. 36 static intptr_t object_hash(Klass* k) { 37 intptr_t hc = k->java_mirror()->mark()->hash(); 38 return hc != markOopDesc::no_hash ? hc : os::random(); 39 } 40 41 // Seed value used for each alternative hash calculated. 42 juint AltHashing::compute_seed() { 43 jlong nanos = os::javaTimeNanos(); 44 jlong now = os::javaTimeMillis(); 45 jint SEED_MATERIAL[8] = { 46 (jint) object_hash(SystemDictionary::String_klass()), 47 (jint) object_hash(SystemDictionary::System_klass()), 48 (jint) os::random(), // current thread isn't a java thread 49 (jint) (((julong)nanos) >> 32), 50 (jint) nanos, 51 (jint) (((julong)now) >> 32), 52 (jint) now, 53 (jint) (os::javaTimeNanos() >> 2) 54 }; 55 56 return murmur3_32(SEED_MATERIAL, 8); 57 } 58 59 60 // Murmur3 hashing for Symbol 61 juint AltHashing::murmur3_32(juint seed, const jbyte* data, int len) { 62 juint h1 = seed; 63 int count = len; 64 int offset = 0; 65 66 // body 67 while (count >= 4) { 68 juint k1 = (data[offset] & 0x0FF) 69 | (data[offset + 1] & 0x0FF) << 8 70 | (data[offset + 2] & 0x0FF) << 16 71 | data[offset + 3] << 24; 72 73 count -= 4; 150 k1 *= 0xcc9e2d51; 151 k1 = Integer_rotateLeft(k1, 15); 152 k1 *= 0x1b873593; 153 h1 ^= k1; 154 } 155 156 // finalization 157 h1 ^= len * 2; // (Character.SIZE / Byte.SIZE); 158 159 // finalization mix force all bits of a hash block to avalanche 160 h1 ^= h1 >> 16; 161 h1 *= 0x85ebca6b; 162 h1 ^= h1 >> 13; 163 h1 *= 0xc2b2ae35; 164 h1 ^= h1 >> 16; 165 166 return h1; 167 } 168 169 // Hash used for the seed. 170 juint AltHashing::murmur3_32(juint seed, const jint* data, int len) { 171 juint h1 = seed; 172 173 int off = 0; 174 int end = len; 175 176 // body 177 while (off < end) { 178 juint k1 = (juint)data[off++]; 179 180 k1 *= 0xcc9e2d51; 181 k1 = Integer_rotateLeft(k1, 15); 182 k1 *= 0x1b873593; 183 184 h1 ^= k1; 185 h1 = Integer_rotateLeft(h1, 13); 186 h1 = h1 * 5 + 0xe6546b64; 187 } 188 189 // tail (always empty, as body is always 32-bit chunks) 190 191 // finalization 192 193 h1 ^= len * 4; // (Integer.SIZE / Byte.SIZE); 194 195 // finalization mix force all bits of a hash block to avalanche 196 h1 ^= h1 >> 16; 197 h1 *= 0x85ebca6b; 198 h1 ^= h1 >> 13; 199 h1 *= 0xc2b2ae35; 200 h1 ^= h1 >> 16; 201 202 return h1; 203 } 204 205 juint AltHashing::murmur3_32(const jint* data, int len) { 206 return murmur3_32(0, data, len); 207 } |