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