< prev index next >

src/share/vm/classfile/altHashing.cpp

Print this page




 245   jbyte vector[256];
 246   jbyte hashes[4 * 256];
 247 
 248   for (int i = 0; i < 256; i++) {
 249     vector[i] = (jbyte) i;
 250   }
 251 
 252   // Hash subranges {}, {0}, {0,1}, {0,1,2}, ..., {0,...,255}
 253   for (int i = 0; i < 256; i++) {
 254     juint hash = murmur3_32(256 - i, vector, i);
 255     hashes[i * 4] = (jbyte) hash;
 256     hashes[i * 4 + 1] = (jbyte)(hash >> 8);
 257     hashes[i * 4 + 2] = (jbyte)(hash >> 16);
 258     hashes[i * 4 + 3] = (jbyte)(hash >> 24);
 259   }
 260 
 261   // hash to get const result.
 262   juint final_hash = murmur3_32(hashes, 4*256);
 263 
 264   assert (MURMUR3_32_X86_CHECK_VALUE == final_hash,
 265     err_msg(
 266         "Calculated hash result not as expected. Expected %08X got %08X\n",
 267         MURMUR3_32_X86_CHECK_VALUE,
 268         final_hash));
 269 }
 270 
 271 void AltHashing::testEquivalentHashes() {
 272   juint jbytes, jchars, ints;
 273 
 274   // printf("testEquivalentHashes\n");
 275 
 276   jbytes = murmur3_32(TWO_BYTE, 2);
 277   jchars = murmur3_32(ONE_CHAR, 1);
 278   assert (jbytes == jchars,
 279     err_msg("Hashes did not match. b:%08x != c:%08x\n", jbytes, jchars));
 280 
 281   jbytes = murmur3_32(FOUR_BYTE, 4);
 282   jchars = murmur3_32(TWO_CHAR, 2);
 283   ints = murmur3_32(ONE_INT, 1);
 284   assert ((jbytes == jchars) && (jbytes == ints),
 285     err_msg("Hashes did not match. b:%08x != c:%08x != i:%08x\n", jbytes, jchars, ints));
 286 
 287   jbytes = murmur3_32(SIX_BYTE, 6);
 288   jchars = murmur3_32(THREE_CHAR, 3);
 289   assert (jbytes == jchars,
 290     err_msg("Hashes did not match. b:%08x != c:%08x\n", jbytes, jchars));
 291 
 292   jbytes = murmur3_32(EIGHT_BYTE, 8);
 293   jchars = murmur3_32(FOUR_CHAR, 4);
 294   ints = murmur3_32(TWO_INT, 2);
 295   assert ((jbytes == jchars) && (jbytes == ints),
 296     err_msg("Hashes did not match. b:%08x != c:%08x != i:%08x\n", jbytes, jchars, ints));
 297 }
 298 
 299 // Returns true if the alternate hashcode is correct
 300 void AltHashing::test_alt_hash() {
 301   testMurmur3_32_ByteArray();
 302   testEquivalentHashes();
 303 }
 304 #endif // PRODUCT


 245   jbyte vector[256];
 246   jbyte hashes[4 * 256];
 247 
 248   for (int i = 0; i < 256; i++) {
 249     vector[i] = (jbyte) i;
 250   }
 251 
 252   // Hash subranges {}, {0}, {0,1}, {0,1,2}, ..., {0,...,255}
 253   for (int i = 0; i < 256; i++) {
 254     juint hash = murmur3_32(256 - i, vector, i);
 255     hashes[i * 4] = (jbyte) hash;
 256     hashes[i * 4 + 1] = (jbyte)(hash >> 8);
 257     hashes[i * 4 + 2] = (jbyte)(hash >> 16);
 258     hashes[i * 4 + 3] = (jbyte)(hash >> 24);
 259   }
 260 
 261   // hash to get const result.
 262   juint final_hash = murmur3_32(hashes, 4*256);
 263 
 264   assert (MURMUR3_32_X86_CHECK_VALUE == final_hash,

 265           "Calculated hash result not as expected. Expected %08X got %08X\n",
 266           MURMUR3_32_X86_CHECK_VALUE,
 267           final_hash);
 268 }
 269 
 270 void AltHashing::testEquivalentHashes() {
 271   juint jbytes, jchars, ints;
 272 
 273   // printf("testEquivalentHashes\n");
 274 
 275   jbytes = murmur3_32(TWO_BYTE, 2);
 276   jchars = murmur3_32(ONE_CHAR, 1);
 277   assert (jbytes == jchars,
 278           "Hashes did not match. b:%08x != c:%08x\n", jbytes, jchars);
 279 
 280   jbytes = murmur3_32(FOUR_BYTE, 4);
 281   jchars = murmur3_32(TWO_CHAR, 2);
 282   ints = murmur3_32(ONE_INT, 1);
 283   assert ((jbytes == jchars) && (jbytes == ints),
 284           "Hashes did not match. b:%08x != c:%08x != i:%08x\n", jbytes, jchars, ints);
 285 
 286   jbytes = murmur3_32(SIX_BYTE, 6);
 287   jchars = murmur3_32(THREE_CHAR, 3);
 288   assert (jbytes == jchars,
 289          "Hashes did not match. b:%08x != c:%08x\n", jbytes, jchars);
 290 
 291   jbytes = murmur3_32(EIGHT_BYTE, 8);
 292   jchars = murmur3_32(FOUR_CHAR, 4);
 293   ints = murmur3_32(TWO_INT, 2);
 294   assert ((jbytes == jchars) && (jbytes == ints),
 295           "Hashes did not match. b:%08x != c:%08x != i:%08x\n", jbytes, jchars, ints);
 296 }
 297 
 298 // Returns true if the alternate hashcode is correct
 299 void AltHashing::test_alt_hash() {
 300   testMurmur3_32_ByteArray();
 301   testEquivalentHashes();
 302 }
 303 #endif // PRODUCT
< prev index next >