6614052: jhat fails to read heap dump > 2GB.
authorswamyv
Fri, 29 Aug 2008 14:33:05 -0700
changeset 1149 1e32392ecafa
parent 1148 1e917f49e503
child 1150 972c77670265
child 1151 4070cecdb99d
6614052: jhat fails to read heap dump > 2GB. Summary: Modified the jhat code to use long for unsigned int. This is a forward port of changes from Kevin Walls. Reviewed-by: jjh
jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java
--- a/jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java	Fri Aug 29 17:46:45 2008 +0100
+++ b/jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java	Fri Aug 29 14:33:05 2008 -0700
@@ -120,7 +120,7 @@
     private int version;        // The version of .hprof being read
 
     private int debugLevel;
-    private int currPos;        // Current position in the file
+    private long currPos;        // Current position in the file
 
     private int dumpsToSkip;
     private boolean callStack;  // If true, read the call stack of objects
@@ -196,7 +196,9 @@
                 break;
             }
             in.readInt();       // Timestamp of this record
-            int length = in.readInt();
+            // Length of record: readInt() will return negative value for record
+            // length >2GB.  so store 32bit value in long to keep it unsigned.
+            long length = in.readInt() & 0xffffffffL;
             if (debugLevel > 0) {
                 System.out.println("Read record type " + type
                                    + ", length " + length
@@ -211,7 +213,7 @@
             switch (type) {
                 case HPROF_UTF8: {
                     long id = readID();
-                    byte[] chars = new byte[length - identifierSize];
+                    byte[] chars = new byte[(int)length - identifierSize];
                     in.readFully(chars);
                     names.put(new Long(id), new String(chars));
                     break;
@@ -351,8 +353,8 @@
         return snapshot;
     }
 
-    private void skipBytes(int length) throws IOException {
-        in.skipBytes(length);
+    private void skipBytes(long length) throws IOException {
+        in.skipBytes((int)length);
     }
 
     private int readVersionHeader() throws IOException {
@@ -381,7 +383,7 @@
         throw new IOException("Version string not recognized at byte " + (pos+3));
     }
 
-    private void readHeapDump(int bytesLeft, int posAtEnd) throws IOException {
+    private void readHeapDump(long bytesLeft, long posAtEnd) throws IOException {
         while (bytesLeft > 0) {
             int type = in.readUnsignedByte();
             if (debugLevel > 0) {