author | coleenp |
Tue, 03 Jul 2018 13:41:18 -0400 | |
changeset 50929 | ef57cfcd22ff |
parent 47216 | 71c04702a3d5 |
child 51179 | 516acf6956a2 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
50929
ef57cfcd22ff
8205534: Remove SymbolTable dependency from serviceability agent
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.oops; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
import sun.jvm.hotspot.debugger.*; |
|
30 |
import sun.jvm.hotspot.runtime.*; |
|
31 |
import sun.jvm.hotspot.types.*; |
|
32 |
import sun.jvm.hotspot.utilities.*; |
|
33 |
||
34 |
// A Symbol is a canonicalized string. |
|
35 |
// All Symbols reside in global symbolTable. |
|
36 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
37 |
public class Symbol extends VMObject { |
1 | 38 |
static { |
39 |
VM.registerVMInitializedObserver(new Observer() { |
|
40 |
public void update(Observable o, Object data) { |
|
41 |
initialize(VM.getVM().getTypeDataBase()); |
|
42 |
} |
|
43 |
}); |
|
44 |
} |
|
45 |
||
46 |
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
47 |
Type type = db.lookupType("Symbol"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
48 |
length = type.getCIntegerField("_length"); |
1 | 49 |
baseOffset = type.getField("_body").getOffset(); |
31616
01c68517607d
8130135: backout 8087143 due to failures in 8130115
dcubed
parents:
31614
diff
changeset
|
50 |
idHash = type.getCIntegerField("_identity_hash"); |
1 | 51 |
} |
52 |
||
53 |
// Format: |
|
54 |
// [header] |
|
55 |
// [klass ] |
|
56 |
// [length] byte size of uft8 string |
|
57 |
// ..body.. |
|
58 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
59 |
public static Symbol create(Address addr) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
60 |
if (addr == null) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
61 |
return null; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
62 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
63 |
return new Symbol(addr); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
64 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
65 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
66 |
Symbol(Address addr) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
67 |
super(addr); |
1 | 68 |
} |
69 |
||
70 |
public boolean isSymbol() { return true; } |
|
71 |
||
72 |
private static long baseOffset; // tells where the array part starts |
|
73 |
||
74 |
// Fields |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
75 |
private static CIntegerField length; |
1 | 76 |
|
77 |
// Accessors for declared fields |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
78 |
public long getLength() { return length.getValue(this.addr); } |
1 | 79 |
|
80 |
public byte getByteAt(long index) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
81 |
return addr.getJByteAt(baseOffset + index); |
1 | 82 |
} |
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
83 |
// _identity_hash is a short |
31616
01c68517607d
8130135: backout 8087143 due to failures in 8130115
dcubed
parents:
31614
diff
changeset
|
84 |
private static CIntegerField idHash; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
85 |
|
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
86 |
public int identityHash() { |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
87 |
long addr_value = getAddress().asLongValue(); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
88 |
int addr_bits = (int)(addr_value >> (VM.getVM().getLogMinObjAlignmentInBytes() + 3)); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
89 |
int length = (int)getLength(); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
90 |
int byte0 = getByteAt(0); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
91 |
int byte1 = getByteAt(1); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
92 |
int id_hash = (int)(0xffff & idHash.getValue(this.addr)); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
93 |
return id_hash | |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
94 |
((addr_bits ^ (length << 8) ^ ((byte0 << 8) | byte1)) << 16); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
95 |
} |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
96 |
|
1 | 97 |
public boolean equals(byte[] modUTF8Chars) { |
98 |
int l = (int) getLength(); |
|
99 |
if (l != modUTF8Chars.length) return false; |
|
100 |
while (l-- > 0) { |
|
101 |
if (modUTF8Chars[l] != getByteAt(l)) return false; |
|
102 |
} |
|
103 |
if (Assert.ASSERTS_ENABLED) { |
|
104 |
Assert.that(l == -1, "we should be at the beginning"); |
|
105 |
} |
|
106 |
return true; |
|
107 |
} |
|
108 |
||
50929
ef57cfcd22ff
8205534: Remove SymbolTable dependency from serviceability agent
coleenp
parents:
47216
diff
changeset
|
109 |
public boolean equals(String string) { |
ef57cfcd22ff
8205534: Remove SymbolTable dependency from serviceability agent
coleenp
parents:
47216
diff
changeset
|
110 |
return asString().equals(string); |
ef57cfcd22ff
8205534: Remove SymbolTable dependency from serviceability agent
coleenp
parents:
47216
diff
changeset
|
111 |
} |
ef57cfcd22ff
8205534: Remove SymbolTable dependency from serviceability agent
coleenp
parents:
47216
diff
changeset
|
112 |
|
1 | 113 |
public byte[] asByteArray() { |
114 |
int length = (int) getLength(); |
|
115 |
byte [] result = new byte [length]; |
|
116 |
for (int index = 0; index < length; index++) { |
|
117 |
result[index] = getByteAt(index); |
|
118 |
} |
|
119 |
return result; |
|
120 |
} |
|
121 |
||
122 |
public String asString() { |
|
123 |
// Decode the byte array and return the string. |
|
124 |
try { |
|
125 |
return readModifiedUTF8(asByteArray()); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
126 |
} catch(Exception e) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
127 |
System.err.println(addr); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
128 |
e.printStackTrace(); |
1 | 129 |
return null; |
130 |
} |
|
131 |
} |
|
132 |
||
133 |
public boolean startsWith(String str) { |
|
134 |
return asString().startsWith(str); |
|
135 |
} |
|
136 |
||
137 |
public void printValueOn(PrintStream tty) { |
|
138 |
tty.print("#" + asString()); |
|
139 |
} |
|
140 |
||
141 |
/** Note: this comparison is used for vtable sorting only; it |
|
142 |
doesn't matter what order it defines, as long as it is a total, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
143 |
time-invariant order Since Symbol* are in C_HEAP, their |
1 | 144 |
relative order in memory never changes, so use address |
145 |
comparison for speed. */ |
|
42590
48d874bf85fb
8169232: SA: TestCpoolForInvokeDynamic.java fails with sun.jvm.hotspot.debugger.DebuggerException: binary search bug: should have found entry 1
vtewari
parents:
35217
diff
changeset
|
146 |
public long fastCompare(Symbol other) { |
48d874bf85fb
8169232: SA: TestCpoolForInvokeDynamic.java fails with sun.jvm.hotspot.debugger.DebuggerException: binary search bug: should have found entry 1
vtewari
parents:
35217
diff
changeset
|
147 |
return addr.minus(other.addr); |
1 | 148 |
} |
149 |
||
150 |
private static String readModifiedUTF8(byte[] buf) throws IOException { |
|
151 |
final int len = buf.length; |
|
152 |
byte[] tmp = new byte[len + 2]; |
|
153 |
// write modified UTF-8 length as short in big endian |
|
154 |
tmp[0] = (byte) ((len >>> 8) & 0xFF); |
|
155 |
tmp[1] = (byte) ((len >>> 0) & 0xFF); |
|
156 |
// copy the data |
|
157 |
System.arraycopy(buf, 0, tmp, 2, len); |
|
158 |
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(tmp)); |
|
159 |
return dis.readUTF(); |
|
160 |
} |
|
161 |
} |