annotate src/share/vm/classfile/altHashing.cpp @ 10130:6f817ce50129

8010992: Remove calls to global ::operator new[] and new Summary: disable use of global operator new and new[] which could cause unexpected exception and escape from NMT tracking. Reviewed-by: coleenp, dholmes, zgu Contributed-by: yumin.qi@oracle.com
author minqi
date Fri, 19 Apr 2013 11:08:52 -0700
parents da91efe96a93
children 5a9fa2ba85f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
1 /*
10130
6f817ce50129 8010992: Remove calls to global ::operator new[] and new
minqi
parents: 6725
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
4 *
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
7 * published by the Free Software Foundation.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
8 *
e9140bf80b4a 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
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e9140bf80b4a 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
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
13 * accompanied this code).
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
14 *
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
18 *
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
21 * questions.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
22 *
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
23 */
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
24
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
25 #include "precompiled.hpp"
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
26 #include "classfile/altHashing.hpp"
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
27 #include "classfile/symbolTable.hpp"
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
28 #include "classfile/systemDictionary.hpp"
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
29 #include "oops/markOop.hpp"
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
30 #include "runtime/thread.hpp"
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
31
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
32 // Get the hash code of the classes mirror if it exists, otherwise just
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
33 // return a random number, which is one of the possible hash code used for
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
34 // objects. We don't want to call the synchronizer hash code to install
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
35 // this value because it may safepoint.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6162
diff changeset
36 intptr_t object_hash(Klass* k) {
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
37 intptr_t hc = k->java_mirror()->mark()->hash();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
38 return hc != markOopDesc::no_hash ? hc : os::random();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
39 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
40
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
41 // Seed value used for each alternative hash calculated.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
42 jint AltHashing::compute_seed() {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
43 jlong nanos = os::javaTimeNanos();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
44 jlong now = os::javaTimeMillis();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
45 jint SEED_MATERIAL[8] = {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
46 (jint) object_hash(SystemDictionary::String_klass()),
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
47 (jint) object_hash(SystemDictionary::System_klass()),
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
48 (jint) os::random(), // current thread isn't a java thread
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
49 (jint) (((julong)nanos) >> 32),
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
50 (jint) nanos,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
51 (jint) (((julong)now) >> 32),
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
52 (jint) now,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
53 (jint) (os::javaTimeNanos() >> 2)
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
54 };
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
55
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
56 return murmur3_32(SEED_MATERIAL, 8);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
57 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
58
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
59
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
60 // Murmur3 hashing for Symbol
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
61 jint AltHashing::murmur3_32(jint seed, const jbyte* data, int len) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
62 jint h1 = seed;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
63 int count = len;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
64 int offset = 0;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
65
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
66 // body
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
67 while (count >= 4) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
68 jint k1 = (data[offset] & 0x0FF)
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
69 | (data[offset + 1] & 0x0FF) << 8
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
70 | (data[offset + 2] & 0x0FF) << 16
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
71 | data[offset + 3] << 24;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
72
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
73 count -= 4;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
74 offset += 4;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
75
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
76 k1 *= 0xcc9e2d51;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
77 k1 = Integer_rotateLeft(k1, 15);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
78 k1 *= 0x1b873593;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
79
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
80 h1 ^= k1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
81 h1 = Integer_rotateLeft(h1, 13);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
82 h1 = h1 * 5 + 0xe6546b64;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
83 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
84
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
85 // tail
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
86
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
87 if (count > 0) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
88 jint k1 = 0;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
89
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
90 switch (count) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
91 case 3:
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
92 k1 ^= (data[offset + 2] & 0xff) << 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
93 // fall through
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
94 case 2:
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
95 k1 ^= (data[offset + 1] & 0xff) << 8;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
96 // fall through
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
97 case 1:
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
98 k1 ^= (data[offset] & 0xff);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
99 // fall through
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
100 default:
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
101 k1 *= 0xcc9e2d51;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
102 k1 = Integer_rotateLeft(k1, 15);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
103 k1 *= 0x1b873593;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
104 h1 ^= k1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
105 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
106 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
107
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
108 // finalization
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
109 h1 ^= len;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
110
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
111 // finalization mix force all bits of a hash block to avalanche
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
112 h1 ^= ((unsigned int)h1) >> 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
113 h1 *= 0x85ebca6b;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
114 h1 ^= ((unsigned int)h1) >> 13;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
115 h1 *= 0xc2b2ae35;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
116 h1 ^= ((unsigned int)h1) >> 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
117
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
118 return h1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
119 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
120
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
121 // Murmur3 hashing for Strings
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
122 jint AltHashing::murmur3_32(jint seed, const jchar* data, int len) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
123 jint h1 = seed;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
124
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
125 int off = 0;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
126 int count = len;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
127
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
128 // body
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
129 while (count >= 2) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
130 jchar d1 = data[off++] & 0xFFFF;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
131 jchar d2 = data[off++];
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
132 jint k1 = (d1 | d2 << 16);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
133
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
134 count -= 2;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
135
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
136 k1 *= 0xcc9e2d51;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
137 k1 = Integer_rotateLeft(k1, 15);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
138 k1 *= 0x1b873593;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
139
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
140 h1 ^= k1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
141 h1 = Integer_rotateLeft(h1, 13);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
142 h1 = h1 * 5 + 0xe6546b64;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
143 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
144
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
145 // tail
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
146
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
147 if (count > 0) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
148 int k1 = data[off];
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
149
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
150 k1 *= 0xcc9e2d51;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
151 k1 = Integer_rotateLeft(k1, 15);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
152 k1 *= 0x1b873593;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
153 h1 ^= k1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
154 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
155
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
156 // finalization
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
157 h1 ^= len * 2; // (Character.SIZE / Byte.SIZE);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
158
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
159 // finalization mix force all bits of a hash block to avalanche
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
160 h1 ^= ((unsigned int)h1) >> 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
161 h1 *= 0x85ebca6b;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
162 h1 ^= ((unsigned int)h1) >> 13;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
163 h1 *= 0xc2b2ae35;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
164 h1 ^= ((unsigned int)h1) >> 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
165
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
166 return h1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
167 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
168
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
169 // Hash used for the seed.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
170 jint AltHashing::murmur3_32(jint seed, const int* data, int len) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
171 jint h1 = seed;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
172
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
173 int off = 0;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
174 int end = len;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
175
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
176 // body
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
177 while (off < end) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
178 jint k1 = data[off++];
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
179
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
180 k1 *= 0xcc9e2d51;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
181 k1 = Integer_rotateLeft(k1, 15);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
182 k1 *= 0x1b873593;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
183
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
184 h1 ^= k1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
185 h1 = Integer_rotateLeft(h1, 13);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
186 h1 = h1 * 5 + 0xe6546b64;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
187 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
188
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
189 // tail (always empty, as body is always 32-bit chunks)
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
190
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
191 // finalization
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
192
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
193 h1 ^= len * 4; // (Integer.SIZE / Byte.SIZE);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
194
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
195 // finalization mix force all bits of a hash block to avalanche
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
196 h1 ^= ((juint)h1) >> 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
197 h1 *= 0x85ebca6b;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
198 h1 ^= ((juint)h1) >> 13;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
199 h1 *= 0xc2b2ae35;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
200 h1 ^= ((juint)h1) >> 16;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
201
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
202 return h1;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
203 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
204
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
205 jint AltHashing::murmur3_32(const int* data, int len) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
206 return murmur3_32(0, data, len);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
207 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
208
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
209 #ifndef PRODUCT
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
210 // Overloaded versions for internal test.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
211 jint AltHashing::murmur3_32(const jbyte* data, int len) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
212 return murmur3_32(0, data, len);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
213 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
214
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
215 jint AltHashing::murmur3_32(const jchar* data, int len) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
216 return murmur3_32(0, data, len);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
217 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
218
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
219 // Internal test for alternate hashing. Translated from JDK version
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
220 // test/sun/misc/Hashing.java
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
221 static const jbyte ONE_BYTE[] = { (jbyte) 0x80};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
222 static const jbyte TWO_BYTE[] = { (jbyte) 0x80, (jbyte) 0x81};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
223 static const jchar ONE_CHAR[] = { (jchar) 0x8180};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
224 static const jbyte THREE_BYTE[] = { (jbyte) 0x80, (jbyte) 0x81, (jbyte) 0x82};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
225 static const jbyte FOUR_BYTE[] = { (jbyte) 0x80, (jbyte) 0x81, (jbyte) 0x82, (jbyte) 0x83};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
226 static const jchar TWO_CHAR[] = { (jchar) 0x8180, (jchar) 0x8382};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
227 static const jint ONE_INT[] = { 0x83828180};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
228 static const jbyte SIX_BYTE[] = { (jbyte) 0x80, (jbyte) 0x81, (jbyte) 0x82, (jbyte) 0x83, (jbyte) 0x84, (jbyte) 0x85};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
229 static const jchar THREE_CHAR[] = { (jchar) 0x8180, (jchar) 0x8382, (jchar) 0x8584};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
230 static const jbyte EIGHT_BYTE[] = {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
231 (jbyte) 0x80, (jbyte) 0x81, (jbyte) 0x82,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
232 (jbyte) 0x83, (jbyte) 0x84, (jbyte) 0x85,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
233 (jbyte) 0x86, (jbyte) 0x87};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
234 static const jchar FOUR_CHAR[] = {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
235 (jchar) 0x8180, (jchar) 0x8382,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
236 (jchar) 0x8584, (jchar) 0x8786};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
237
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
238 static const jint TWO_INT[] = { 0x83828180, 0x87868584};
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
239
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
240 static const juint MURMUR3_32_X86_CHECK_VALUE = 0xB0F57EE3;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
241
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
242 void AltHashing::testMurmur3_32_ByteArray() {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
243 // printf("testMurmur3_32_ByteArray\n");
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
244
10130
6f817ce50129 8010992: Remove calls to global ::operator new[] and new
minqi
parents: 6725
diff changeset
245 jbyte vector[256];
6f817ce50129 8010992: Remove calls to global ::operator new[] and new
minqi
parents: 6725
diff changeset
246 jbyte hashes[4 * 256];
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
247
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
248 for (int i = 0; i < 256; i++) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
249 vector[i] = (jbyte) i;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
250 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
251
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
252 // Hash subranges {}, {0}, {0,1}, {0,1,2}, ..., {0,...,255}
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
253 for (int i = 0; i < 256; i++) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
254 jint hash = murmur3_32(256 - i, vector, i);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
255 hashes[i * 4] = (jbyte) hash;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
256 hashes[i * 4 + 1] = (jbyte) (((juint)hash) >> 8);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
257 hashes[i * 4 + 2] = (jbyte) (((juint)hash) >> 16);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
258 hashes[i * 4 + 3] = (jbyte) (((juint)hash) >> 24);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
259 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
260
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
261 // hash to get const result.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
262 juint final_hash = murmur3_32(hashes, 4*256);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
263
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
264 assert (MURMUR3_32_X86_CHECK_VALUE == final_hash,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
265 err_msg(
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
266 "Calculated hash result not as expected. Expected %08X got %08X\n",
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
267 MURMUR3_32_X86_CHECK_VALUE,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
268 final_hash));
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
269 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
270
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
271 void AltHashing::testEquivalentHashes() {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
272 jint jbytes, jchars, ints;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
273
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
274 // printf("testEquivalentHashes\n");
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
275
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
276 jbytes = murmur3_32(TWO_BYTE, 2);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
277 jchars = murmur3_32(ONE_CHAR, 1);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
278 assert (jbytes == jchars,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
279 err_msg("Hashes did not match. b:%08x != c:%08x\n", jbytes, jchars));
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
280
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
281 jbytes = murmur3_32(FOUR_BYTE, 4);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
282 jchars = murmur3_32(TWO_CHAR, 2);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
283 ints = murmur3_32(ONE_INT, 1);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
284 assert ((jbytes == jchars) && (jbytes == ints),
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
285 err_msg("Hashes did not match. b:%08x != c:%08x != i:%08x\n", jbytes, jchars, ints));
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
286
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
287 jbytes = murmur3_32(SIX_BYTE, 6);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
288 jchars = murmur3_32(THREE_CHAR, 3);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
289 assert (jbytes == jchars,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
290 err_msg("Hashes did not match. b:%08x != c:%08x\n", jbytes, jchars));
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
291
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
292 jbytes = murmur3_32(EIGHT_BYTE, 8);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
293 jchars = murmur3_32(FOUR_CHAR, 4);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
294 ints = murmur3_32(TWO_INT, 2);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
295 assert ((jbytes == jchars) && (jbytes == ints),
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
296 err_msg("Hashes did not match. b:%08x != c:%08x != i:%08x\n", jbytes, jchars, ints));
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
297 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
298
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
299 // Returns true if the alternate hashcode is correct
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
300 void AltHashing::test_alt_hash() {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
301 testMurmur3_32_ByteArray();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
302 testEquivalentHashes();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
303 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents:
diff changeset
304 #endif // PRODUCT