Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java @ 1552:c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
author | trims |
---|---|
date | Thu, 27 May 2010 19:08:38 -0700 |
parents | a61af66fc99e |
children | 3582bf76420e |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 2000, 2004, 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 | |
37 public class Symbol extends Oop { | |
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 { | |
47 Type type = db.lookupType("symbolOopDesc"); | |
48 length = new CIntField(type.getCIntegerField("_length"), 0); | |
49 baseOffset = type.getField("_body").getOffset(); | |
50 } | |
51 | |
52 // Format: | |
53 // [header] | |
54 // [klass ] | |
55 // [length] byte size of uft8 string | |
56 // ..body.. | |
57 | |
58 Symbol(OopHandle handle, ObjectHeap heap) { | |
59 super(handle, heap); | |
60 } | |
61 | |
62 public boolean isSymbol() { return true; } | |
63 | |
64 private static long baseOffset; // tells where the array part starts | |
65 | |
66 // Fields | |
67 private static CIntField length; | |
68 | |
69 // Accessors for declared fields | |
70 public long getLength() { return length.getValue(this); } | |
71 | |
72 public byte getByteAt(long index) { | |
73 return getHandle().getJByteAt(baseOffset + index); | |
74 } | |
75 | |
76 public boolean equals(byte[] modUTF8Chars) { | |
77 int l = (int) getLength(); | |
78 if (l != modUTF8Chars.length) return false; | |
79 while (l-- > 0) { | |
80 if (modUTF8Chars[l] != getByteAt(l)) return false; | |
81 } | |
82 if (Assert.ASSERTS_ENABLED) { | |
83 Assert.that(l == -1, "we should be at the beginning"); | |
84 } | |
85 return true; | |
86 } | |
87 | |
88 public byte[] asByteArray() { | |
89 int length = (int) getLength(); | |
90 byte [] result = new byte [length]; | |
91 for (int index = 0; index < length; index++) { | |
92 result[index] = getByteAt(index); | |
93 } | |
94 return result; | |
95 } | |
96 | |
97 public String asString() { | |
98 // Decode the byte array and return the string. | |
99 try { | |
100 return readModifiedUTF8(asByteArray()); | |
101 } catch(IOException e) { | |
102 return null; | |
103 } | |
104 } | |
105 | |
106 public boolean startsWith(String str) { | |
107 return asString().startsWith(str); | |
108 } | |
109 | |
110 public void printValueOn(PrintStream tty) { | |
111 tty.print("#" + asString()); | |
112 } | |
113 | |
114 public long getObjectSize() { | |
115 return alignObjectSize(baseOffset + getLength()); | |
116 } | |
117 | |
118 void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
119 super.iterateFields(visitor, doVMFields); | |
120 if (doVMFields) { | |
121 visitor.doCInt(length, true); | |
122 int length = (int) getLength(); | |
123 for (int index = 0; index < length; index++) { | |
124 visitor.doByte(new ByteField(new IndexableFieldIdentifier(index), baseOffset + index, false), true); | |
125 } | |
126 } | |
127 } | |
128 | |
129 /** Note: this comparison is used for vtable sorting only; it | |
130 doesn't matter what order it defines, as long as it is a total, | |
131 time-invariant order Since symbolOops are in permSpace, their | |
132 relative order in memory never changes, so use address | |
133 comparison for speed. */ | |
134 public int fastCompare(Symbol other) { | |
135 return (int) getHandle().minus(other.getHandle()); | |
136 } | |
137 | |
138 private static String readModifiedUTF8(byte[] buf) throws IOException { | |
139 final int len = buf.length; | |
140 byte[] tmp = new byte[len + 2]; | |
141 // write modified UTF-8 length as short in big endian | |
142 tmp[0] = (byte) ((len >>> 8) & 0xFF); | |
143 tmp[1] = (byte) ((len >>> 0) & 0xFF); | |
144 // copy the data | |
145 System.arraycopy(buf, 0, tmp, 2, len); | |
146 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(tmp)); | |
147 return dis.readUTF(); | |
148 } | |
149 } |