annotate agent/src/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents ba764ed4b6f2
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 113
diff changeset
2 * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.utilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
34 * This is abstract base class for heap graph writers. This class does
a61af66fc99e Initial load
duke
parents:
diff changeset
35 * not assume any file format for the heap graph. It hides heap
a61af66fc99e Initial load
duke
parents:
diff changeset
36 * iteration, object (fields) iteration mechanism from derived
a61af66fc99e Initial load
duke
parents:
diff changeset
37 * classes. This class does not even accept OutputStream etc. so that
a61af66fc99e Initial load
duke
parents:
diff changeset
38 * derived class can construct specific writer/filter from input
a61af66fc99e Initial load
duke
parents:
diff changeset
39 * stream.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 */
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 public abstract class AbstractHeapGraphWriter implements HeapGraphWriter {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // the function iterates heap and calls Oop type specific writers
a61af66fc99e Initial load
duke
parents:
diff changeset
44 protected void write() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 SymbolTable symTbl = VM.getVM().getSymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 javaLangClass = symTbl.probe("java/lang/Class");
a61af66fc99e Initial load
duke
parents:
diff changeset
47 javaLangString = symTbl.probe("java/lang/String");
a61af66fc99e Initial load
duke
parents:
diff changeset
48 javaLangThread = symTbl.probe("java/lang/Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
49 ObjectHeap heap = VM.getVM().getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
50 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 heap.iterate(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public void prologue(long usedSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 writeHeapHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if (oop instanceof TypeArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 writePrimitiveArray((TypeArray)oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 } else if (oop instanceof ObjArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Klass klass = oop.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 ObjArrayKlass oak = (ObjArrayKlass) klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 Klass bottomType = oak.getBottomKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 if (bottomType instanceof InstanceKlass ||
a61af66fc99e Initial load
duke
parents:
diff changeset
69 bottomType instanceof TypeArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 writeObjectArray((ObjArray)oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 writeInternalObject(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 } else if (oop instanceof Instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Instance instance = (Instance) oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 Klass klass = instance.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 Symbol name = klass.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 if (name.equals(javaLangString)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 writeString(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 } else if (name.equals(javaLangClass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 writeClass(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 } else if (name.equals(javaLangThread)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 writeThread(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 klass = klass.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 while (klass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 name = klass.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (name.equals(javaLangThread)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 writeThread(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 klass = klass.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 writeInstance(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // not-a-Java-visible oop
a61af66fc99e Initial load
duke
parents:
diff changeset
98 writeInternalObject(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public void epilogue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 writeHeapFooter();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 });
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // write JavaThreads
a61af66fc99e Initial load
duke
parents:
diff changeset
116 writeJavaThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // write JNI global handles
a61af66fc99e Initial load
duke
parents:
diff changeset
119 writeGlobalJNIHandles();
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 } catch (RuntimeException re) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 handleRuntimeException(re);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 protected void writeJavaThreads() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 JavaThread jt = threads.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 int index = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 while (jt != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (jt.getThreadObj() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Note that the thread serial number range is 1-to-N
a61af66fc99e Initial load
duke
parents:
diff changeset
133 writeJavaThread(jt, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 jt = jt.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 protected void writeJavaThread(JavaThread jt, int index)
a61af66fc99e Initial load
duke
parents:
diff changeset
141 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 protected void writeGlobalJNIHandles() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 JNIHandles handles = VM.getVM().getJNIHandles();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 JNIHandleBlock blk = handles.globalHandles();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (blk != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 blk.oopsDo(new AddressVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public void visitAddress(Address handleAddr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (handleAddr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 writeGlobalJNIHandle(handleAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
159 public void visitCompOopAddress(Address handleAddr) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
160 throw new RuntimeException("Should not reach here. JNIHandles are not compressed");
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
161 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 });
a61af66fc99e Initial load
duke
parents:
diff changeset
163 } catch (RuntimeException re) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 handleRuntimeException(re);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 protected void writeGlobalJNIHandle(Address handleAddr) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 protected void writeHeapHeader() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // write non-Java-visible (hotspot internal) object
a61af66fc99e Initial load
duke
parents:
diff changeset
176 protected void writeInternalObject(Oop oop) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // write Java primitive array
a61af66fc99e Initial load
duke
parents:
diff changeset
180 protected void writePrimitiveArray(TypeArray array) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 writeObject(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // write Java object array
a61af66fc99e Initial load
duke
parents:
diff changeset
185 protected void writeObjectArray(ObjArray array) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 writeObject(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 protected void writeInstance(Instance instance) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 writeObject(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 protected void writeString(Instance instance) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 writeInstance(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 protected void writeClass(Instance instance) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 writeInstance(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 protected void writeThread(Instance instance) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 writeInstance(instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 protected void writeObject(Oop oop) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 writeObjectHeader(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 writeObjectFields(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 writeObjectFooter(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 protected void writeObjectHeader(Oop oop) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // write instance fields of given object
a61af66fc99e Initial load
duke
parents:
diff changeset
215 protected void writeObjectFields(final Oop oop) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 oop.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 Oop ref = field.getValue(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (ref instanceof TypeArray ||
a61af66fc99e Initial load
duke
parents:
diff changeset
222 ref instanceof ObjArray ||
a61af66fc99e Initial load
duke
parents:
diff changeset
223 ref instanceof Instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 writeReferenceField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 writeInternalReferenceField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 public void doByte(ByteField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 writeByteField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public void doChar(CharField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 writeCharField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 public void doBoolean(BooleanField field, boolean vField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 writeBooleanField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 public void doShort(ShortField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 writeShortField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public void doInt(IntField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 writeIntField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 public void doLong(LongField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 writeLongField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 public void doFloat(FloatField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 writeFloatField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 public void doDouble(DoubleField field, boolean vField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 writeDoubleField(oop, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
292 } catch (IOException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 throw new RuntimeException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 } catch (RuntimeException re) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 handleRuntimeException(re);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // object field writers
a61af66fc99e Initial load
duke
parents:
diff changeset
303 protected void writeInternalReferenceField(Oop oop, OopField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
304 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 protected void writeReferenceField(Oop oop, OopField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
308 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310
a61af66fc99e Initial load
duke
parents:
diff changeset
311 protected void writeByteField(Oop oop, ByteField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
312 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 protected void writeCharField(Oop oop, CharField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
316 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 protected void writeBooleanField(Oop oop, BooleanField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
320 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 protected void writeShortField(Oop oop, ShortField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
324 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 protected void writeIntField(Oop oop, IntField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
328 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 protected void writeLongField(Oop oop, LongField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
332 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 protected void writeFloatField(Oop oop, FloatField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
336 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 protected void writeDoubleField(Oop oop, DoubleField field)
a61af66fc99e Initial load
duke
parents:
diff changeset
340 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 protected void writeObjectFooter(Oop oop) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 protected void writeHeapFooter() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // HeapVisitor, OopVisitor methods can't throw any non-runtime
a61af66fc99e Initial load
duke
parents:
diff changeset
350 // exception. But, derived class write methods (which are called
a61af66fc99e Initial load
duke
parents:
diff changeset
351 // from visitor callbacks) may throw IOException. Hence, we throw
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // RuntimeException with origianal IOException as cause from the
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // visitor methods. This method gets back the original IOException
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // (if any) and re-throws the same.
a61af66fc99e Initial load
duke
parents:
diff changeset
355 protected void handleRuntimeException(RuntimeException re)
a61af66fc99e Initial load
duke
parents:
diff changeset
356 throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 Throwable cause = re.getCause();
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (cause != null && cause instanceof IOException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 throw (IOException) cause;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // some other RuntimeException, just re-throw
a61af66fc99e Initial load
duke
parents:
diff changeset
362 throw re;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // whether a given oop is Java visible or hotspot internal?
a61af66fc99e Initial load
duke
parents:
diff changeset
367 protected boolean isJavaVisible(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 if (oop instanceof Instance || oop instanceof TypeArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 } else if (oop instanceof ObjArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 ObjArrayKlass oak = (ObjArrayKlass) oop.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
372 Klass bottomKlass = oak.getBottomKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
373 return bottomKlass instanceof InstanceKlass ||
a61af66fc99e Initial load
duke
parents:
diff changeset
374 bottomKlass instanceof TypeArrayKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379
a61af66fc99e Initial load
duke
parents:
diff changeset
380 protected Symbol javaLangClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 protected Symbol javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 protected Symbol javaLangThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }