src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/AltHashing.java
branchJDK-8200758-branch
changeset 56822 49b4e7203b4b
parent 56821 565d54ca1f41
parent 50944 8cc36fac7f3d
child 56829 f8fc6399a54f
equal deleted inserted replaced
56821:565d54ca1f41 56822:49b4e7203b4b
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 package sun.jvm.hotspot.memory;
       
    26 
       
    27 public class AltHashing {
       
    28     public static long murmur3_32(long seed, byte[] data) {
       
    29       long h1 = seed;
       
    30       int len = data.length;
       
    31       int count = len;
       
    32 
       
    33       int offset = 0;
       
    34 
       
    35       // body
       
    36       while (count >= 4) {
       
    37           long k1 = (data[offset] & 0x0FF)
       
    38               | (data[offset + 1] & 0x0FF) << 8
       
    39               | (data[offset + 2] & 0x0FF) << 16
       
    40               | data[offset + 3] << 24;
       
    41 
       
    42           count -= 4;
       
    43           offset += 4;
       
    44 
       
    45           k1 *= 0xcc9e2d51;
       
    46           k1 = Integer.rotateLeft((int)k1, 15);
       
    47           k1 *= 0x1b873593;
       
    48           k1 &= 0xFFFFFFFFL;
       
    49 
       
    50           h1 ^= k1;
       
    51           h1 = Integer.rotateLeft((int)h1, 13);
       
    52           h1 = h1 * 5 + 0xe6546b64;
       
    53           h1 &= 0xFFFFFFFFL;
       
    54       }
       
    55 
       
    56       //tail
       
    57       if (count > 0) {
       
    58           long k1 = 0;
       
    59 
       
    60           switch (count) {
       
    61               case 3:
       
    62                   k1 ^= (data[offset + 2] & 0xff) << 16;
       
    63                   // fall through
       
    64               case 2:
       
    65                   k1 ^= (data[offset + 1] & 0xff) << 8;
       
    66                   // fall through
       
    67               case 1:
       
    68                   k1 ^= (data[offset] & 0xff);
       
    69                   // fall through
       
    70               default:
       
    71                   k1 *= 0xcc9e2d51;
       
    72                   k1 = Integer.rotateLeft((int)k1, 15);
       
    73                   k1 *= 0x1b873593;
       
    74                   k1 &= 0xFFFFFFFFL;
       
    75                   h1 ^= k1;
       
    76                   h1 &= 0xFFFFFFFFL;
       
    77           }
       
    78       }
       
    79 
       
    80       // finalization
       
    81       h1 ^= len;
       
    82 
       
    83       // finalization mix force all bits of a hash block to avalanche
       
    84       h1 ^= h1 >> 16;
       
    85       h1 *= 0x85ebca6b;
       
    86       h1 &= 0xFFFFFFFFL;
       
    87       h1 ^= h1 >> 13;
       
    88       h1 *= 0xc2b2ae35;
       
    89       h1 &= 0xFFFFFFFFL;
       
    90       h1 ^= h1 >> 16;
       
    91 
       
    92       return h1 & 0xFFFFFFFFL;
       
    93   }
       
    94 }