src/hotspot/share/classfile/altHashing.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 57811 947252a54b98
child 58679 9c3209ff7550
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     1
/*
46587
6c97f34cb194 8182554: Code for os::random() assumes long is 32 bits
coleenp
parents: 40900
diff changeset
     2
 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     4
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     8
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    13
 * accompanied this code).
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    14
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    18
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    21
 * questions.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    22
 *
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    23
 */
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    24
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    26
#include "classfile/altHashing.hpp"
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    27
#include "classfile/symbolTable.hpp"
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    28
#include "classfile/systemDictionary.hpp"
57811
947252a54b98 8229838: Rename markOop files to markWord
stefank
parents: 57777
diff changeset
    29
#include "oops/markWord.hpp"
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47765
diff changeset
    30
#include "oops/oop.inline.hpp"
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    31
#include "runtime/thread.hpp"
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    32
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    33
// Get the hash code of the classes mirror if it exists, otherwise just
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    34
// return a random number, which is one of the possible hash code used for
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    35
// objects.  We don't want to call the synchronizer hash code to install
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    36
// this value because it may safepoint.
46587
6c97f34cb194 8182554: Code for os::random() assumes long is 32 bits
coleenp
parents: 40900
diff changeset
    37
static intptr_t object_hash(Klass* k) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    38
  intptr_t hc = k->java_mirror()->mark().hash();
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    39
  return hc != markWord::no_hash ? hc : os::random();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    40
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    41
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    42
// Seed value used for each alternative hash calculated.
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
    43
juint AltHashing::compute_seed() {
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    44
  jlong nanos = os::javaTimeNanos();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    45
  jlong now = os::javaTimeMillis();
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    46
  jint SEED_MATERIAL[8] = {
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    47
            (jint) object_hash(SystemDictionary::String_klass()),
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    48
            (jint) object_hash(SystemDictionary::System_klass()),
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    49
            (jint) os::random(),  // current thread isn't a java thread
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    50
            (jint) (((julong)nanos) >> 32),
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    51
            (jint) nanos,
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    52
            (jint) (((julong)now) >> 32),
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    53
            (jint) now,
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    54
            (jint) (os::javaTimeNanos() >> 2)
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    55
  };
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    56
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    57
  return murmur3_32(SEED_MATERIAL, 8);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    58
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    59
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    60
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    61
// Murmur3 hashing for Symbol
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
    62
juint AltHashing::murmur3_32(juint seed, const jbyte* data, int len) {
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
    63
  juint h1 = seed;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    64
  int count = len;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    65
  int offset = 0;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    66
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    67
  // body
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    68
  while (count >= 4) {
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
    69
    juint k1 = (data[offset] & 0x0FF)
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    70
        | (data[offset + 1] & 0x0FF) << 8
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    71
        | (data[offset + 2] & 0x0FF) << 16
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    72
        | data[offset + 3] << 24;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    73
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    74
    count -= 4;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    75
    offset += 4;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    76
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    77
    k1 *= 0xcc9e2d51;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    78
    k1 = Integer_rotateLeft(k1, 15);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    79
    k1 *= 0x1b873593;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    80
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    81
    h1 ^= k1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    82
    h1 = Integer_rotateLeft(h1, 13);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    83
    h1 = h1 * 5 + 0xe6546b64;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    84
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    85
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    86
  // tail
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    87
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    88
  if (count > 0) {
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
    89
    juint k1 = 0;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    90
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    91
    switch (count) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    92
      case 3:
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    93
        k1 ^= (data[offset + 2] & 0xff) << 16;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    94
      // fall through
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    95
      case 2:
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    96
        k1 ^= (data[offset + 1] & 0xff) << 8;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    97
      // fall through
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    98
      case 1:
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
    99
        k1 ^= (data[offset] & 0xff);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   100
      // fall through
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   101
      default:
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   102
        k1 *= 0xcc9e2d51;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   103
        k1 = Integer_rotateLeft(k1, 15);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   104
        k1 *= 0x1b873593;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   105
        h1 ^= k1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   106
    }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   107
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   108
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   109
  // finalization
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   110
  h1 ^= len;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   111
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   112
  // finalization mix force all bits of a hash block to avalanche
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   113
  h1 ^= h1 >> 16;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   114
  h1 *= 0x85ebca6b;
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   115
  h1 ^= h1 >> 13;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   116
  h1 *= 0xc2b2ae35;
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   117
  h1 ^= h1 >> 16;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   118
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   119
  return h1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   120
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   121
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   122
// Murmur3 hashing for Strings
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   123
juint AltHashing::murmur3_32(juint seed, const jchar* data, int len) {
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   124
  juint h1 = seed;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   125
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   126
  int off = 0;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   127
  int count = len;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   128
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   129
  // body
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   130
  while (count >= 2) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   131
    jchar d1 = data[off++] & 0xFFFF;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   132
    jchar d2 = data[off++];
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   133
    juint k1 = (d1 | d2 << 16);
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   134
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   135
    count -= 2;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   136
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   137
    k1 *= 0xcc9e2d51;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   138
    k1 = Integer_rotateLeft(k1, 15);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   139
    k1 *= 0x1b873593;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   140
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   141
    h1 ^= k1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   142
    h1 = Integer_rotateLeft(h1, 13);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   143
    h1 = h1 * 5 + 0xe6546b64;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   144
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   145
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   146
  // tail
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   147
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   148
  if (count > 0) {
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   149
    juint k1 = (juint)data[off];
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   150
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   151
    k1 *= 0xcc9e2d51;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   152
    k1 = Integer_rotateLeft(k1, 15);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   153
    k1 *= 0x1b873593;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   154
    h1 ^= k1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   155
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   156
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   157
  // finalization
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   158
  h1 ^= len * 2; // (Character.SIZE / Byte.SIZE);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   159
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   160
  // finalization mix force all bits of a hash block to avalanche
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   161
  h1 ^= h1 >> 16;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   162
  h1 *= 0x85ebca6b;
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   163
  h1 ^= h1 >> 13;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   164
  h1 *= 0xc2b2ae35;
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   165
  h1 ^= h1 >> 16;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   166
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   167
  return h1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   168
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   169
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   170
// Hash used for the seed.
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   171
juint AltHashing::murmur3_32(juint seed, const jint* data, int len) {
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   172
  juint h1 = seed;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   173
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   174
  int off = 0;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   175
  int end = len;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   176
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   177
  // body
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   178
  while (off < end) {
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   179
    juint k1 = (juint)data[off++];
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   180
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   181
    k1 *= 0xcc9e2d51;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   182
    k1 = Integer_rotateLeft(k1, 15);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   183
    k1 *= 0x1b873593;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   184
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   185
    h1 ^= k1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   186
    h1 = Integer_rotateLeft(h1, 13);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   187
    h1 = h1 * 5 + 0xe6546b64;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   188
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   189
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   190
  // tail (always empty, as body is always 32-bit chunks)
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   191
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   192
  // finalization
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   193
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   194
  h1 ^= len * 4; // (Integer.SIZE / Byte.SIZE);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   195
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   196
  // finalization mix force all bits of a hash block to avalanche
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   197
  h1 ^= h1 >> 16;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   198
  h1 *= 0x85ebca6b;
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   199
  h1 ^= h1 >> 13;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   200
  h1 *= 0xc2b2ae35;
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 17376
diff changeset
   201
  h1 ^= h1 >> 16;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   202
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   203
  return h1;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   204
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   205
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   206
juint AltHashing::murmur3_32(const jint* data, int len) {
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   207
  return murmur3_32(0, data, len);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
   208
}