< prev index next >

test/lib/jdk/test/lib/hprof/parser/HprofReader.java

Print this page
rev 58388 : 8237354: Add option to jcmd to write a gzipped heap dump
Reviewed-by:
   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 139     // (with / converted to .)
 140     private Hashtable<Long, String> classNameFromObjectID;
 141 
 142     // Hashtable<Integer, Integer>, maps class serial # to class object ID
 143     private Hashtable<Integer, String> classNameFromSerialNo;
 144 
 145     // Hashtable<Long, StackFrame> maps stack frame ID to StackFrame.
 146     // Null if we're not tracking them.
 147     private Hashtable<Long, StackFrame> stackFrames;
 148 
 149     // Hashtable<Integer, StackTrace> maps stack frame ID to StackTrace
 150     // Null if we're not tracking them.
 151     private Hashtable<Integer, StackTrace> stackTraces;
 152 
 153     private Snapshot snapshot;
 154 
 155     public static boolean verifyMagicNumber(int numberRead) {
 156         return (numberRead == MAGIC_NUMBER);
 157     }
 158 
 159     public HprofReader(String fileName, PositionDataInputStream in,
 160                        int dumpNumber, boolean callStack, int debugLevel)
 161                        throws IOException {
 162         super(in);
 163         RandomAccessFile file = new RandomAccessFile(fileName, "r");
 164         this.snapshot = new Snapshot(MappedReadBuffer.create(file));
 165         this.dumpsToSkip = dumpNumber - 1;
 166         this.callStack = callStack;
 167         this.debugLevel = debugLevel;
 168         names = new Hashtable<Long, String>();
 169         threadObjects = new Hashtable<Integer, ThreadObject>(43);
 170         classNameFromObjectID = new Hashtable<Long, String>();
 171         if (callStack) {
 172             stackFrames = new Hashtable<Long, StackFrame>(43);
 173             stackTraces = new Hashtable<Integer, StackTrace>(43);
 174             classNameFromSerialNo = new Hashtable<Integer, String>();
 175         }







 176     }
 177 
 178     public Snapshot read() throws IOException {
 179         currPos = 4;    // 4 because of the magic number
 180         version = readVersionHeader();
 181         identifierSize = in.readInt();
 182         snapshot.setIdentifierSize(identifierSize);
 183         if (version >= VERSION_JDK12BETA4) {
 184             snapshot.setNewStyleArrayClass(true);
 185         } else {
 186             snapshot.setNewStyleArrayClass(false);
 187         }
 188 
 189         currPos += 4;
 190         if (identifierSize != 4 && identifierSize != 8) {
 191             throw new IOException("I'm sorry, but I can't deal with an identifier size of " + identifierSize + ".  I can only deal with 4 or 8.");
 192         }
 193         System.out.println("Dump file created " + (new Date(in.readLong())));
 194         currPos += 8;
 195 


   1 /*
   2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 139     // (with / converted to .)
 140     private Hashtable<Long, String> classNameFromObjectID;
 141 
 142     // Hashtable<Integer, Integer>, maps class serial # to class object ID
 143     private Hashtable<Integer, String> classNameFromSerialNo;
 144 
 145     // Hashtable<Long, StackFrame> maps stack frame ID to StackFrame.
 146     // Null if we're not tracking them.
 147     private Hashtable<Long, StackFrame> stackFrames;
 148 
 149     // Hashtable<Integer, StackTrace> maps stack frame ID to StackTrace
 150     // Null if we're not tracking them.
 151     private Hashtable<Integer, StackTrace> stackTraces;
 152 
 153     private Snapshot snapshot;
 154 
 155     public static boolean verifyMagicNumber(int numberRead) {
 156         return (numberRead == MAGIC_NUMBER);
 157     }
 158 
 159     public HprofReader(ReadBuffer readBuffer, PositionDataInputStream in,
 160                        int dumpNumber, boolean callStack, int debugLevel)
 161                        throws IOException {
 162         super(in);
 163         this.snapshot = new Snapshot(readBuffer);

 164         this.dumpsToSkip = dumpNumber - 1;
 165         this.callStack = callStack;
 166         this.debugLevel = debugLevel;
 167         names = new Hashtable<Long, String>();
 168         threadObjects = new Hashtable<Integer, ThreadObject>(43);
 169         classNameFromObjectID = new Hashtable<Long, String>();
 170         if (callStack) {
 171             stackFrames = new Hashtable<Long, StackFrame>(43);
 172             stackTraces = new Hashtable<Integer, StackTrace>(43);
 173             classNameFromSerialNo = new Hashtable<Integer, String>();
 174         }
 175     }
 176 
 177     public HprofReader(String fileName, PositionDataInputStream in,
 178                        int dumpNumber, boolean callStack, int debugLevel)
 179                        throws IOException {
 180         this(MappedReadBuffer.create(new RandomAccessFile(fileName, "r")),
 181             in, dumpNumber, callStack, debugLevel);
 182     }
 183 
 184     public Snapshot read() throws IOException {
 185         currPos = 4;    // 4 because of the magic number
 186         version = readVersionHeader();
 187         identifierSize = in.readInt();
 188         snapshot.setIdentifierSize(identifierSize);
 189         if (version >= VERSION_JDK12BETA4) {
 190             snapshot.setNewStyleArrayClass(true);
 191         } else {
 192             snapshot.setNewStyleArrayClass(false);
 193         }
 194 
 195         currPos += 4;
 196         if (identifierSize != 4 && identifierSize != 8) {
 197             throw new IOException("I'm sorry, but I can't deal with an identifier size of " + identifierSize + ".  I can only deal with 4 or 8.");
 198         }
 199         System.out.println("Dump file created " + (new Date(in.readLong())));
 200         currPos += 8;
 201 


< prev index next >