Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java @ 1913:3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands.
Reviewed-by: twisti
author | jrose |
---|---|
date | Sat, 30 Oct 2010 13:08:23 -0700 |
parents | e9ff18c4ace7 |
children | 0a8e0d4345b3 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
2 * Copyright (c) 2000, 2008, 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:
196
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
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:
196
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.utilities.*; | |
30 import sun.jvm.hotspot.debugger.*; | |
31 import sun.jvm.hotspot.runtime.*; | |
32 import sun.jvm.hotspot.types.*; | |
33 import sun.jvm.hotspot.memory.CompactingPermGenGen; | |
34 | |
35 // Oop represents the superclass for all types of | |
36 // objects in the HotSpot object heap. | |
37 | |
38 public class Oop { | |
39 static { | |
40 VM.registerVMInitializedObserver(new Observer() { | |
41 public void update(Observable o, Object data) { | |
42 initialize(VM.getVM().getTypeDataBase()); | |
43 } | |
44 }); | |
45 } | |
46 | |
47 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { | |
48 Type type = db.lookupType("oopDesc"); | |
49 mark = new CIntField(type.getCIntegerField("_mark"), 0); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
50 klass = new OopField(type.getOopField("_metadata._klass"), 0); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
51 compressedKlass = new NarrowOopField(type.getOopField("_metadata._compressed_klass"), 0); |
0 | 52 headerSize = type.getSize(); |
53 } | |
54 | |
55 private OopHandle handle; | |
56 private ObjectHeap heap; | |
57 | |
58 Oop(OopHandle handle, ObjectHeap heap) { | |
59 this.handle = handle; | |
60 this.heap = heap; | |
61 } | |
62 | |
63 ObjectHeap getHeap() { return heap; } | |
64 | |
65 /** Should not be used or needed by most clients outside this | |
66 package; is needed, however, by {@link | |
67 sun.jvm.hotspot.utilities.MarkBits}. */ | |
68 public OopHandle getHandle() { return handle; } | |
69 | |
70 private static long headerSize; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
71 public static long getHeaderSize() { return headerSize; } // Header size in bytes. |
0 | 72 |
73 private static CIntField mark; | |
74 private static OopField klass; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
75 private static NarrowOopField compressedKlass; |
0 | 76 |
77 public boolean isShared() { | |
78 return CompactingPermGenGen.isShared(handle); | |
79 } | |
80 | |
81 public boolean isSharedReadOnly() { | |
82 return CompactingPermGenGen.isSharedReadOnly(handle); | |
83 } | |
84 | |
85 public boolean isSharedReadWrite() { | |
86 return CompactingPermGenGen.isSharedReadWrite(handle); | |
87 } | |
88 | |
89 // Accessors for declared fields | |
90 public Mark getMark() { return new Mark(getHandle()); } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
91 public Klass getKlass() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
92 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
93 return (Klass) compressedKlass.getValue(this); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
94 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
95 return (Klass) klass.getValue(this); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
96 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
97 } |
0 | 98 |
99 public boolean isA(Klass k) { | |
100 return getKlass().isSubtypeOf(k); | |
101 } | |
102 | |
103 // Returns the byte size of this object | |
104 public long getObjectSize() { | |
105 Klass k = getKlass(); | |
106 if (k instanceof InstanceKlass) { | |
107 return ((InstanceKlass)k).getSizeHelper() | |
108 * VM.getVM().getAddressSize(); | |
109 } | |
110 // If it is not an instance, this method should be replaced. | |
111 return getHeaderSize(); | |
112 } | |
113 | |
114 // Type test operations | |
115 public boolean isInstance() { return false; } | |
116 public boolean isInstanceRef() { return false; } | |
117 public boolean isArray() { return false; } | |
118 public boolean isObjArray() { return false; } | |
119 public boolean isTypeArray() { return false; } | |
120 public boolean isSymbol() { return false; } | |
121 public boolean isKlass() { return false; } | |
122 public boolean isThread() { return false; } | |
123 public boolean isMethod() { return false; } | |
124 public boolean isMethodData() { return false; } | |
125 public boolean isConstantPool() { return false; } | |
126 public boolean isConstantPoolCache() { return false; } | |
127 public boolean isCompiledICHolder() { return false; } | |
128 | |
129 // Align the object size. | |
130 public static long alignObjectSize(long size) { | |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
131 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes()); |
0 | 132 } |
133 | |
134 // All vm's align longs, so pad out certain offsets. | |
135 public static long alignObjectOffset(long offset) { | |
136 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong()); | |
137 } | |
138 | |
139 public boolean equals(Object obj) { | |
140 if (obj != null && (obj instanceof Oop)) { | |
141 return getHandle().equals(((Oop) obj).getHandle()); | |
142 } | |
143 return false; | |
144 } | |
145 | |
146 public int hashCode() { return getHandle().hashCode(); } | |
147 | |
148 /** Identity hash in the target VM */ | |
149 public long identityHash() { | |
150 Mark mark = getMark(); | |
151 if (mark.isUnlocked() && (!mark.hasNoHash())) { | |
152 return (int) mark.hash(); | |
153 } else if (mark.isMarked()) { | |
154 return (int) mark.hash(); | |
155 } else { | |
156 return slowIdentityHash(); | |
157 } | |
158 } | |
159 | |
160 public long slowIdentityHash() { | |
161 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this); | |
162 } | |
163 | |
164 public void iterate(OopVisitor visitor, boolean doVMFields) { | |
165 visitor.setObj(this); | |
166 visitor.prologue(); | |
167 iterateFields(visitor, doVMFields); | |
168 visitor.epilogue(); | |
169 } | |
170 | |
171 void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
172 if (doVMFields) { | |
173 visitor.doCInt(mark, true); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
174 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
175 visitor.doOop(compressedKlass, true); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
176 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
177 visitor.doOop(klass, true); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
178 } |
0 | 179 } |
180 } | |
181 | |
182 public void print() { printOn(System.out); } | |
183 public void printValue() { printValueOn(System.out); } | |
184 public void printRaw() { printRawOn(System.out); } | |
185 | |
186 public static void printOopValueOn(Oop obj, PrintStream tty) { | |
187 if (obj == null) { | |
188 tty.print("null"); | |
189 } else { | |
190 obj.printValueOn(tty); | |
191 tty.print(" @ " + obj.getHandle()); | |
192 } | |
193 } | |
194 | |
195 public static void printOopAddressOn(Oop obj, PrintStream tty) { | |
196 if (obj == null) { | |
197 tty.print("null"); | |
198 } else { | |
199 tty.print(obj.getHandle().toString()); | |
200 } | |
201 } | |
202 | |
203 public void printOn(PrintStream tty) { | |
204 OopPrinter printer = new OopPrinter(tty); | |
205 iterate(printer, true); | |
206 } | |
207 | |
208 public void printValueOn(PrintStream tty) { | |
209 try { | |
210 tty.print("Oop for " + getKlass().getName().asString()); | |
211 } catch (java.lang.NullPointerException e) { | |
212 tty.print("Oop"); | |
213 } | |
214 } | |
215 | |
216 public void printRawOn(PrintStream tty) { | |
217 tty.print("Dumping raw memory for "); | |
218 printValueOn(tty); | |
219 tty.println(); | |
220 long size = getObjectSize() * 4; | |
221 for (long i = 0; i < size; i += 4) { | |
222 long memVal = getHandle().getCIntegerAt(i, 4, true); | |
223 tty.println(Long.toHexString(memVal)); | |
224 } | |
225 } | |
226 | |
227 public boolean verify() { return true;} | |
228 | |
229 // Package-private routine to speed up ObjectHeap.newOop | |
230 static OopHandle getKlassForOopHandle(OopHandle handle) { | |
231 if (handle == null) { | |
232 return null; | |
233 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
234 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
235 return handle.getCompOopHandleAt(compressedKlass.getOffset()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
236 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
237 return handle.getOopHandleAt(klass.getOffset()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
238 } |
0 | 239 } |
240 }; |