/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
*/
/**
*
* @author Bill Foote
*/
/**
* Represents a snapshot of the Java objects in the VM at one instant.
* This is the top-level "model" object read out of a single .hprof or .bod
* file.
*/
public class Snapshot {
// all heap objects
// all Roots in this Snapshot
// name-to-class map
// new objects relative to a baseline - lazily initialized
// allocation site traces for all objects - lazily initialized
// object-to-Root map for all objects
// soft cache of finalizeable objects - lazily initialized
// represents null reference
// java.lang.ref.Reference class
// index of 'referent' field in java.lang.ref.Reference class
private int referentFieldIndex;
// java.lang.Class class
// java.lang.String class
// java.lang.ClassLoader class
// unknown "other" array class
// Stuff to exclude from reachable query
// the underlying heap dump buffer
// True iff some heap objects have isNew set
private boolean hasNewSet;
private boolean unresolvedObjectsOK;
// whether object array instances have new style class or
// old style (element) class.
private boolean newStyleArrayClass;
// object id size in the heap dump
// minimum object size - accounts for object header in
// most Java virtual machines - we assume 2 identifierSize
// (which is true for Sun's hotspot JVM).
private int minimumObjectSize;
}
}
}
if (siteTraces != null) {
} else {
return null;
}
}
}
public boolean isNewStyleArrayClass() {
return newStyleArrayClass;
}
}
public int getIdentifierSize() {
return identifierSize;
}
public int getMinimumObjectSize() {
return minimumObjectSize;
}
}
roots.addElement(r);
}
addHeapObject(id, c);
putInClassesMap(c);
}
// Create a fake class name based on ID.
// Create fake fields convering the given instance size.
// Create as many as int type fields and for the left over
// size create byte type fields.
int i;
for (i = 0; i < numInts; i++) {
}
for (i = 0; i < numBytes; i++) {
i + numInts, "B");
}
// Create fake instance class
// Add the class
return c;
}
/**
* @return true iff it's possible that some JavaThing instances might
* isNew set
*
* @see JavaThing.isNew()
*/
public boolean getHasNewSet() {
return hasNewSet;
}
//
// Used in the body of resolve()
//
}
}
// To show heap parsing progress, we print a '.' after this limit
/**
* Called after reading complete, to initialize the structure
*/
// First, resolve the classes. All classes must be resolved before
// we try any objects, because the objects use classes in their
// resolution.
if (javaLangClass == null) {
}
if (javaLangString == null) {
}
if (javaLangClassLoader == null) {
}
if (t instanceof JavaClass) {
t.resolve(this);
}
}
// Now, resolve everything else.
if (!(t instanceof JavaClass)) {
t.resolve(this);
}
}
fakeClasses.clear();
referentFieldIndex = 0;
} else {
referentFieldIndex = i;
break;
}
}
}
if (calculateRefs) {
// This println refers to the *next* step
}
int count = 0;
t.setupReferers();
++count;
}
}
if (calculateRefs) {
}
// to ensure that Iterator.remove() on getClasses()
// result will throw exception..
}
private void calculateReferencesToObjects() {
int count = 0;
visitor.t = t;
// call addReferenceFrom(t) on all objects t references:
++count;
}
}
r.resolve(this);
if (t != null) {
t.addReferenceFromRoot(r);
}
}
}
hasNewSet = true;
boolean isNew;
isNew = false;
} else {
isNew = true;
} else {
}
}
}
}
return heapObjects.elements();
}
}
}
} else {
}
}
/**
* Return an Iterator of all of the classes in this snapshot.
**/
// note that because classes is a TreeMap
// classes are already sorted by name
}
return res;
}
if (finalizablesCache != null &&
}
if (tmp != getNullThing()) {
while (true) {
break;
}
}
}
return finalizables.elements();
}
}
return res;
}
}
public ReferenceChain[]
Vector<ReferenceChain> fifo = new Vector<ReferenceChain>(); // This is slow... A real fifo would help
// Must be a fifo to go breadth-first
Hashtable<JavaHeapObject, JavaHeapObject> visited = new Hashtable<JavaHeapObject, JavaHeapObject>();
// Objects are added here right after being added to fifo.
// Even though curr is in the rootset, we want to explore its
// referers, because they might be more interesting.
}
while (referers.hasMoreElements()) {
}
}
}
}
}
return realResult;
}
public boolean getUnresolvedObjectsOK() {
return unresolvedObjectsOK;
}
public void setUnresolvedObjectsOK(boolean v) {
unresolvedObjectsOK = v;
}
return weakReferenceClass;
}
public int getReferentFieldIndex() {
return referentFieldIndex;
}
return nullThing;
}
reachableExcludes = e;
}
return reachableExcludes;
}
// package privates
} else {
}
}
}
return javaLangClass;
}
return javaLangString;
}
return javaLangClassLoader;
}
if (otherArrayType == null) {
synchronized(this) {
if (otherArrayType == null) {
0));
}
}
}
return otherArrayType;
}
synchronized(classes) {
// This is needed because the JDK only creates Class structures
// for array element types, not the arrays themselves. For
// analysis, though, we need to pretend that there's a
// JavaClass for the array type, too.
}
}
return clazz;
}
return readBuf;
}
if (isNew) {
}
}
if (newObjects != null) {
} else {
return false;
}
}
// Internals only below this point
if (identifierSize == 4) {
} else {
}
}
// more than one class can have the same name
// if so, create a unique name by appending
// - and id string to it.
}
}
putInClassesMap(c);
c.resolve(this);
}
addFakeClass(c);
}
private synchronized void initNewObjects() {
if (newObjects == null) {
synchronized (this) {
if (newObjects == null) {
}
}
}
}
private synchronized void initSiteTraces() {
if (siteTraces == null) {
synchronized (this) {
if (siteTraces == null) {
}
}
}
}
}