author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 37995 | hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/CompactHashTable.java@92aec042a43b |
child 50476 | 30d5bca69eae |
permissions | -rw-r--r-- |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
1 |
/* |
37995 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
4 |
* |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
8 |
* |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
13 |
* accompanied this code). |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
14 |
* |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
18 |
* |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
21 |
* questions. |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
22 |
* |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
23 |
*/ |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
24 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
25 |
package sun.jvm.hotspot.utilities; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
26 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
27 |
import java.util.*; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
28 |
import sun.jvm.hotspot.debugger.*; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
29 |
import sun.jvm.hotspot.oops.*; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
30 |
import sun.jvm.hotspot.types.*; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
31 |
import sun.jvm.hotspot.runtime.*; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
32 |
import sun.jvm.hotspot.utilities.*; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
33 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
34 |
public class CompactHashTable extends VMObject { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
35 |
static { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
36 |
VM.registerVMInitializedObserver(new Observer() { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
37 |
public void update(Observable o, Object data) { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
38 |
initialize(VM.getVM().getTypeDataBase()); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
39 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
40 |
}); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
41 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
42 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
43 |
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
44 |
Type type = db.lookupType("SymbolCompactHashTable"); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
45 |
baseAddressField = type.getAddressField("_base_address"); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
46 |
bucketCountField = type.getCIntegerField("_bucket_count"); |
37995 | 47 |
entryCountField = type.getCIntegerField("_entry_count"); |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
48 |
bucketsField = type.getAddressField("_buckets"); |
37995 | 49 |
entriesField = type.getAddressField("_entries"); |
50 |
uintSize = db.lookupType("u4").getSize(); |
|
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
51 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
52 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
53 |
// Fields |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
54 |
private static CIntegerField bucketCountField; |
37995 | 55 |
private static CIntegerField entryCountField; |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
56 |
private static AddressField baseAddressField; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
57 |
private static AddressField bucketsField; |
37995 | 58 |
private static AddressField entriesField; |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
59 |
private static long uintSize; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
60 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
61 |
private static int BUCKET_OFFSET_MASK = 0x3FFFFFFF; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
62 |
private static int BUCKET_TYPE_SHIFT = 30; |
37995 | 63 |
private static int VALUE_ONLY_BUCKET_TYPE = 1; |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
64 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
65 |
public CompactHashTable(Address addr) { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
66 |
super(addr); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
67 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
68 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
69 |
private int bucketCount() { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
70 |
return (int)bucketCountField.getValue(addr); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
71 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
72 |
|
37995 | 73 |
private boolean isValueOnlyBucket(int bucket_info) { |
74 |
return (bucket_info >> BUCKET_TYPE_SHIFT) == VALUE_ONLY_BUCKET_TYPE; |
|
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
75 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
76 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
77 |
private int bucketOffset(int bucket_info) { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
78 |
return bucket_info & BUCKET_OFFSET_MASK; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
79 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
80 |
|
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
81 |
public Symbol probe(byte[] name, long hash) { |
37995 | 82 |
if (bucketCount() <= 0) { |
83 |
// This CompactHashTable is not in use |
|
37086
e152767075ce
8151368: SA: Unexpected ArithmeticException in CompactHashTable
dsamersoff
parents:
35217
diff
changeset
|
84 |
return null; |
e152767075ce
8151368: SA: Unexpected ArithmeticException in CompactHashTable
dsamersoff
parents:
35217
diff
changeset
|
85 |
} |
e152767075ce
8151368: SA: Unexpected ArithmeticException in CompactHashTable
dsamersoff
parents:
35217
diff
changeset
|
86 |
|
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
87 |
long symOffset; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
88 |
Symbol sym; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
89 |
Address baseAddress = baseAddressField.getValue(addr); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
90 |
Address bucket = bucketsField.getValue(addr); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
91 |
long index = hash % bucketCount(); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
92 |
int bucketInfo = (int)bucket.getCIntegerAt(index * uintSize, uintSize, true); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
93 |
int bucketOffset = bucketOffset(bucketInfo); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
94 |
int nextBucketInfo = (int)bucket.getCIntegerAt((index+1) * uintSize, uintSize, true); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
95 |
int nextBucketOffset = bucketOffset(nextBucketInfo); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
96 |
|
37995 | 97 |
Address entry = entriesField.getValue(addr).addOffsetTo(bucketOffset * uintSize); |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
98 |
|
37995 | 99 |
if (isValueOnlyBucket(bucketInfo)) { |
100 |
symOffset = entry.getCIntegerAt(0, uintSize, true); |
|
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
101 |
sym = Symbol.create(baseAddress.addOffsetTo(symOffset)); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
102 |
if (sym.equals(name)) { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
103 |
return sym; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
104 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
105 |
} else { |
37995 | 106 |
Address entryMax = entriesField.getValue(addr).addOffsetTo(nextBucketOffset * uintSize); |
107 |
while (entry.lessThan(entryMax)) { |
|
108 |
long symHash = entry.getCIntegerAt(0, uintSize, true); |
|
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
109 |
if (symHash == hash) { |
37995 | 110 |
symOffset = entry.getCIntegerAt(uintSize, uintSize, true); |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
111 |
Address symAddr = baseAddress.addOffsetTo(symOffset); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
112 |
sym = Symbol.create(symAddr); |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
113 |
if (sym.equals(name)) { |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
114 |
return sym; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
115 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
116 |
} |
37995 | 117 |
entry = entry.addOffsetTo(2 * uintSize); |
28822
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
118 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
119 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
120 |
return null; |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
121 |
} |
fa57694ade05
8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents:
diff
changeset
|
122 |
} |