Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java @ 10229:f6a055fcf47d
8005038: remove crufty '_g' support from SA
Reviewed-by: coleenp, mgronlun, rbackman
author | sla |
---|---|
date | Tue, 07 May 2013 14:33:09 +0200 |
parents | 1d1603768966 |
children |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 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 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
37 public class Symbol extends VMObject { |
0 | 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 { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
47 Type type = db.lookupType("Symbol"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
48 length = type.getCIntegerField("_length"); |
0 | 49 baseOffset = type.getField("_body").getOffset(); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
50 idHash = type.getCIntegerField("_identity_hash"); |
0 | 51 } |
52 | |
53 // Format: | |
54 // [header] | |
55 // [klass ] | |
56 // [length] byte size of uft8 string | |
57 // ..body.. | |
58 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
59 public static Symbol create(Address addr) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
60 if (addr == null) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
61 return null; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
62 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
63 return new Symbol(addr); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
64 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
65 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
66 Symbol(Address addr) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
67 super(addr); |
0 | 68 } |
69 | |
70 public boolean isSymbol() { return true; } | |
71 | |
72 private static long baseOffset; // tells where the array part starts | |
73 | |
74 // Fields | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
75 private static CIntegerField length; |
0 | 76 |
77 // Accessors for declared fields | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
78 public long getLength() { return length.getValue(this.addr); } |
0 | 79 |
80 public byte getByteAt(long index) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
81 return addr.getJByteAt(baseOffset + index); |
0 | 82 } |
83 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
84 private static CIntegerField idHash; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
85 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
86 public int identityHash() { return (int)idHash.getValue(this.addr); } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
87 |
0 | 88 public boolean equals(byte[] modUTF8Chars) { |
89 int l = (int) getLength(); | |
90 if (l != modUTF8Chars.length) return false; | |
91 while (l-- > 0) { | |
92 if (modUTF8Chars[l] != getByteAt(l)) return false; | |
93 } | |
94 if (Assert.ASSERTS_ENABLED) { | |
95 Assert.that(l == -1, "we should be at the beginning"); | |
96 } | |
97 return true; | |
98 } | |
99 | |
100 public byte[] asByteArray() { | |
101 int length = (int) getLength(); | |
102 byte [] result = new byte [length]; | |
103 for (int index = 0; index < length; index++) { | |
104 result[index] = getByteAt(index); | |
105 } | |
106 return result; | |
107 } | |
108 | |
109 public String asString() { | |
110 // Decode the byte array and return the string. | |
111 try { | |
112 return readModifiedUTF8(asByteArray()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
113 } catch(Exception e) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
114 System.err.println(addr); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
115 e.printStackTrace(); |
0 | 116 return null; |
117 } | |
118 } | |
119 | |
120 public boolean startsWith(String str) { | |
121 return asString().startsWith(str); | |
122 } | |
123 | |
124 public void printValueOn(PrintStream tty) { | |
125 tty.print("#" + asString()); | |
126 } | |
127 | |
128 /** Note: this comparison is used for vtable sorting only; it | |
129 doesn't matter what order it defines, as long as it is a total, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
130 time-invariant order Since Symbol* are in C_HEAP, their |
0 | 131 relative order in memory never changes, so use address |
132 comparison for speed. */ | |
133 public int fastCompare(Symbol other) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
134 return (int) addr.minus(other.addr); |
0 | 135 } |
136 | |
137 private static String readModifiedUTF8(byte[] buf) throws IOException { | |
138 final int len = buf.length; | |
139 byte[] tmp = new byte[len + 2]; | |
140 // write modified UTF-8 length as short in big endian | |
141 tmp[0] = (byte) ((len >>> 8) & 0xFF); | |
142 tmp[1] = (byte) ((len >>> 0) & 0xFF); | |
143 // copy the data | |
144 System.arraycopy(buf, 0, tmp, 2, len); | |
145 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(tmp)); | |
146 return dis.readUTF(); | |
147 } | |
148 } |