< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java

Print this page




  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.utilities;
  26 
  27 import java.io.*;
  28 import java.nio.channels.*;
  29 import java.util.*;
  30 import sun.jvm.hotspot.debugger.*;
  31 import sun.jvm.hotspot.memory.*;
  32 import sun.jvm.hotspot.oops.*;
  33 import sun.jvm.hotspot.runtime.*;
  34 import sun.jvm.hotspot.classfile.*;

  35 
  36 /*
  37  * This class writes Java heap in hprof binary format. This format is
  38  * used by Heap Analysis Tool (HAT). The class is heavily influenced
  39  * by 'hprof_io.c' of 1.5 new hprof implementation.
  40  */
  41 
  42 /* hprof binary format: (result either written to a file or sent over
  43  * the network).
  44  *
  45  * WARNING: This format is still under development, and is subject to
  46  * change without notice.
  47  *
  48  * header     "JAVA PROFILE 1.0.2" (0-terminated)
  49  * u4         size of identifiers. Identifiers are used to represent
  50  *            UTF8 strings, objects, stack traces, etc. They usually
  51  *            have the same size as host pointers. For example, on
  52  *            Solaris and Win32, the size is 4.
  53  * u4         high word
  54  * u4         low word    number of milliseconds since 0:00 GMT, 1/1/70


 376     private static final int JVM_SIGNATURE_LONG    = 'J';
 377     private static final int JVM_SIGNATURE_FLOAT   = 'F';
 378     private static final int JVM_SIGNATURE_DOUBLE  = 'D';
 379     private static final int JVM_SIGNATURE_ARRAY   = '[';
 380     private static final int JVM_SIGNATURE_CLASS   = 'L';
 381 
 382     private static final long MAX_U4_VALUE = 0xFFFFFFFFL;
 383     int serialNum = 1;
 384 
 385     public HeapHprofBinWriter() {
 386         this.KlassMap = new ArrayList<Klass>();
 387         this.names = new HashSet<Symbol>();
 388     }
 389 
 390     public synchronized void write(String fileName) throws IOException {
 391         // open file stream and create buffered data output stream
 392         fos = new FileOutputStream(fileName);
 393         out = new DataOutputStream(new BufferedOutputStream(fos));
 394 
 395         VM vm = VM.getVM();




 396         dbg = vm.getDebugger();
 397         objectHeap = vm.getObjectHeap();
 398 
 399         OBJ_ID_SIZE = (int) vm.getOopSize();
 400 
 401         BOOLEAN_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BOOLEAN);
 402         BYTE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BYTE);
 403         CHAR_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_CHAR);
 404         SHORT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_SHORT);
 405         INT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_INT);
 406         LONG_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_LONG);
 407         FLOAT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_FLOAT);
 408         DOUBLE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_DOUBLE);
 409         OBJECT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_OBJECT);
 410 
 411         BOOLEAN_SIZE = objectHeap.getBooleanSize();
 412         BYTE_SIZE = objectHeap.getByteSize();
 413         CHAR_SIZE = objectHeap.getCharSize();
 414         SHORT_SIZE = objectHeap.getShortSize();
 415         INT_SIZE = objectHeap.getIntSize();




  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.utilities;
  26 
  27 import java.io.*;
  28 import java.nio.channels.*;
  29 import java.util.*;
  30 import sun.jvm.hotspot.debugger.*;
  31 import sun.jvm.hotspot.memory.*;
  32 import sun.jvm.hotspot.oops.*;
  33 import sun.jvm.hotspot.runtime.*;
  34 import sun.jvm.hotspot.classfile.*;
  35 import sun.jvm.hotspot.gc.z.ZCollectedHeap;
  36 
  37 /*
  38  * This class writes Java heap in hprof binary format. This format is
  39  * used by Heap Analysis Tool (HAT). The class is heavily influenced
  40  * by 'hprof_io.c' of 1.5 new hprof implementation.
  41  */
  42 
  43 /* hprof binary format: (result either written to a file or sent over
  44  * the network).
  45  *
  46  * WARNING: This format is still under development, and is subject to
  47  * change without notice.
  48  *
  49  * header     "JAVA PROFILE 1.0.2" (0-terminated)
  50  * u4         size of identifiers. Identifiers are used to represent
  51  *            UTF8 strings, objects, stack traces, etc. They usually
  52  *            have the same size as host pointers. For example, on
  53  *            Solaris and Win32, the size is 4.
  54  * u4         high word
  55  * u4         low word    number of milliseconds since 0:00 GMT, 1/1/70


 377     private static final int JVM_SIGNATURE_LONG    = 'J';
 378     private static final int JVM_SIGNATURE_FLOAT   = 'F';
 379     private static final int JVM_SIGNATURE_DOUBLE  = 'D';
 380     private static final int JVM_SIGNATURE_ARRAY   = '[';
 381     private static final int JVM_SIGNATURE_CLASS   = 'L';
 382 
 383     private static final long MAX_U4_VALUE = 0xFFFFFFFFL;
 384     int serialNum = 1;
 385 
 386     public HeapHprofBinWriter() {
 387         this.KlassMap = new ArrayList<Klass>();
 388         this.names = new HashSet<Symbol>();
 389     }
 390 
 391     public synchronized void write(String fileName) throws IOException {
 392         // open file stream and create buffered data output stream
 393         fos = new FileOutputStream(fileName);
 394         out = new DataOutputStream(new BufferedOutputStream(fos));
 395 
 396         VM vm = VM.getVM();
 397         if (vm.getUniverse().heap() instanceof ZCollectedHeap) {
 398             throw new RuntimeException("This operation is not supported with ZGC.");
 399         }
 400 
 401         dbg = vm.getDebugger();
 402         objectHeap = vm.getObjectHeap();
 403 
 404         OBJ_ID_SIZE = (int) vm.getOopSize();
 405 
 406         BOOLEAN_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BOOLEAN);
 407         BYTE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BYTE);
 408         CHAR_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_CHAR);
 409         SHORT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_SHORT);
 410         INT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_INT);
 411         LONG_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_LONG);
 412         FLOAT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_FLOAT);
 413         DOUBLE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_DOUBLE);
 414         OBJECT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_OBJECT);
 415 
 416         BOOLEAN_SIZE = objectHeap.getBooleanSize();
 417         BYTE_SIZE = objectHeap.getByteSize();
 418         CHAR_SIZE = objectHeap.getCharSize();
 419         SHORT_SIZE = objectHeap.getShortSize();
 420         INT_SIZE = objectHeap.getIntSize();


< prev index next >