sa-jdi

ion: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.util.Comparator;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.utilities.AddressOps;

final class ObjectHeap$3
  implements Comparator
{
  private final ObjectHeap this$0;
  
  ObjectHeap$3(ObjectHeap paramObjectHeap) {}
  
  public int compare(Object o1, Object o2)
  {
    Address a1 = (Address)o1;
    Address a2 = (Address)o2;
    if (AddressOps.lt(a1, a2)) {
      return -1;
    }
    if (AddressOps.gt(a1, a2)) {
      return 1;
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHeap.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.util.List;
import sun.jvm.hotspot.memory.Space;
import sun.jvm.hotspot.memory.SpaceClosure;

class ObjectHeap$LiveRegionsCollector
  implements SpaceClosure
{
  private List liveRegions;
  private final ObjectHeap this$0;
  
  ObjectHeap$LiveRegionsCollector(ObjectHeap paramObjectHeap, List l)
  {
    liveRegions = l;
  }
  
  public void doSpace(Space s)
  {
    ObjectHeap.access$000(this$0, s.getLiveRegions(), liveRegions);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHeap.LiveRegionsCollector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

public abstract interface ObjectHeap$ObjectFilter
{
  public abstract boolean canInclude(Oop paramOop);
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHeap.ObjectFilter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.AddressException;
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.gc_implementation.parallelScavenge.PSOldGen;
import sun.jvm.hotspot.gc_implementation.parallelScavenge.PSPermGen;
import sun.jvm.hotspot.gc_implementation.parallelScavenge.PSYoungGen;
import sun.jvm.hotspot.gc_implementation.parallelScavenge.ParallelScavengeHeap;
import sun.jvm.hotspot.gc_implementation.shared.MutableSpace;
import sun.jvm.hotspot.gc_interface.CollectedHeap;
import sun.jvm.hotspot.memory.CMSCollector;
import sun.jvm.hotspot.memory.CompactibleFreeListSpace;
import sun.jvm.hotspot.memory.ConcurrentMarkSweepGeneration;
import sun.jvm.hotspot.memory.GenCollectedHeap;
import sun.jvm.hotspot.memory.Generation;
import sun.jvm.hotspot.memory.MemRegion;
import sun.jvm.hotspot.memory.Space;
import sun.jvm.hotspot.memory.SpaceClosure;
import sun.jvm.hotspot.memory.Universe;
import sun.jvm.hotspot.runtime.BasicType;
import sun.jvm.hotspot.runtime.JavaThread;
import sun.jvm.hotspot.runtime.ThreadLocalAllocBuffer;
import sun.jvm.hotspot.runtime.Threads;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.types.OopField;
import sun.jvm.hotspot.types.Type;
import sun.jvm.hotspot.types.TypeDataBase;
import sun.jvm.hotspot.types.WrongTypeException;
import sun.jvm.hotspot.utilities.AddressOps;
import sun.jvm.hotspot.utilities.Assert;

public class ObjectHeap
{
  private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.oops.ObjectHeap.DEBUG") != null;
  private OopHandle symbolKlassHandle;
  private OopHandle methodKlassHandle;
  private OopHandle constMethodKlassHandle;
  private OopHandle methodDataKlassHandle;
  private OopHandle constantPoolKlassHandle;
  private OopHandle constantPoolCacheKlassHandle;
  private OopHandle klassKlassHandle;
  private OopHandle instanceKlassKlassHandle;
  private OopHandle typeArrayKlassKlassHandle;
  private OopHandle objArrayKlassKlassHandle;
  private OopHandle boolArrayKlassHandle;
  private OopHandle byteArrayKlassHandle;
  private OopHandle charArrayKlassHandle;
  private OopHandle intArrayKlassHandle;
  private OopHandle shortArrayKlassHandle;
  private OopHandle longArrayKlassHandle;
  private OopHandle singleArrayKlassHandle;
  private OopHandle doubleArrayKlassHandle;
  private OopHandle arrayKlassKlassHandle;
  private OopHandle compiledICHolderKlassHandle;
  private SymbolKlass symbolKlassObj;
  private MethodKlass methodKlassObj;
  private ConstMethodKlass constMethodKlassObj;
  private MethodDataKlass methodDataKlassObj;
  private ConstantPoolKlass constantPoolKlassObj;
  private ConstantPoolCacheKlass constantPoolCacheKlassObj;
  private KlassKlass klassKlassObj;
  private InstanceKlassKlass instanceKlassKlassObj;
  private TypeArrayKlassKlass typeArrayKlassKlassObj;
  private ObjArrayKlassKlass objArrayKlassKlassObj;
  private TypeArrayKlass boolArrayKlassObj;
  private TypeArrayKlass byteArrayKlassObj;
  private TypeArrayKlass charArrayKlassObj;
  private TypeArrayKlass intArrayKlassObj;
  private TypeArrayKlass shortArrayKlassObj;
  private TypeArrayKlass longArrayKlassObj;
  private TypeArrayKlass singleArrayKlassObj;
  private TypeArrayKlass doubleArrayKlassObj;
  private ArrayKlassKlass arrayKlassKlassObj;
  private CompiledICHolderKlass compiledICHolderKlassObj;
  private long oopSize;
  private long byteSize;
  private long charSize;
  private long booleanSize;
  private long intSize;
  private long shortSize;
  private long longSize;
  private long floatSize;
  private long doubleSize;
  
  public void initialize(TypeDataBase db)
    throws WrongTypeException
  {
    Type universeType = db.lookupType("Universe");
    
    symbolKlassHandle = universeType.getOopField("_symbolKlassObj").getValue();
    symbolKlassObj = new SymbolKlass(symbolKlassHandle, this);
    
    methodKlassHandle = universeType.getOopField("_methodKlassObj").getValue();
    methodKlassObj = new MethodKlass(methodKlassHandle, this);
    
    constMethodKlassHandle = universeType.getOopField("_constMethodKlassObj").getValue();
    constMethodKlassObj = new ConstMethodKlass(constMethodKlassHandle, this);
    
    constantPoolKlassHandle = universeType.getOopField("_constantPoolKlassObj").getValue();
    constantPoolKlassObj = new ConstantPoolKlass(constantPoolKlassHandle, this);
    
    constantPoolCacheKlassHandle = universeType.getOopField("_constantPoolCacheKlassObj").getValue();
    constantPoolCacheKlassObj = new ConstantPoolCacheKlass(constantPoolCacheKlassHandle, this);
    
    klassKlassHandle = universeType.getOopField("_klassKlassObj").getValue();
    klassKlassObj = new KlassKlass(klassKlassHandle, this);
    
    arrayKlassKlassHandle = universeType.getOopField("_arrayKlassKlassObj").getValue();
    arrayKlassKlassObj = new ArrayKlassKlass(arrayKlassKlassHandle, this);
    
    instanceKlassKlassHandle = universeType.getOopField("_instanceKlassKlassObj").getValue();
    instanceKlassKlassObj = new InstanceKlassKlass(instanceKlassKlassHandle, this);
    
    typeArrayKlassKlassHandle = universeType.getOopField("_typeArrayKlassKlassObj").getValue();
    typeArrayKlassKlassObj = new TypeArrayKlassKlass(typeArrayKlassKlassHandle, this);
    
    objArrayKlassKlassHandle = universeType.getOopField("_objArrayKlassKlassObj").getValue();
    objArrayKlassKlassObj = new ObjArrayKlassKlass(objArrayKlassKlassHandle, this);
    
    boolArrayKlassHandle = universeType.getOopField("_boolArrayKlassObj").getValue();
    boolArrayKlassObj = new TypeArrayKlass(boolArrayKlassHandle, this);
    
    byteArrayKlassHandle = universeType.getOopField("_byteArrayKlassObj").getValue();
    byteArrayKlassObj = new TypeArrayKlass(byteArrayKlassHandle, this);
    
    charArrayKlassHandle = universeType.getOopField("_charArrayKlassObj").getValue();
    charArrayKlassObj = new TypeArrayKlass(charArrayKlassHandle, this);
    
    intArrayKlassHandle = universeType.getOopField("_intArrayKlassObj").getValue();
    intArrayKlassObj = new TypeArrayKlass(intArrayKlassHandle, this);
    
    shortArrayKlassHandle = universeType.getOopField("_shortArrayKlassObj").getValue();
    shortArrayKlassObj = new TypeArrayKlass(shortArrayKlassHandle, this);
    
    longArrayKlassHandle = universeType.getOopField("_longArrayKlassObj").getValue();
    longArrayKlassObj = new TypeArrayKlass(longArrayKlassHandle, this);
    
    singleArrayKlassHandle = universeType.getOopField("_singleArrayKlassObj").getValue();
    singleArrayKlassObj = new TypeArrayKlass(singleArrayKlassHandle, this);
    
    doubleArrayKlassHandle = universeType.getOopField("_doubleArrayKlassObj").getValue();
    doubleArrayKlassObj = new TypeArrayKlass(doubleArrayKlassHandle, this);
    if (!VM.getVM().isCore())
    {
      methodDataKlassHandle = universeType.getOopField("_methodDataKlassObj").getValue();
      methodDataKlassObj = new MethodDataKlass(methodDataKlassHandle, this);
      
      compiledICHolderKlassHandle = universeType.getOopField("_compiledICHolderKlassObj").getValue();
      compiledICHolderKlassObj = new CompiledICHolderKlass(compiledICHolderKlassHandle, this);
    }
  }
  
  public ObjectHeap(TypeDataBase db)
    throws WrongTypeException
  {
    oopSize = VM.getVM().getOopSize();
    byteSize = db.getJByteType().getSize();
    charSize = db.getJCharType().getSize();
    booleanSize = db.getJBooleanType().getSize();
    intSize = db.getJIntType().getSize();
    shortSize = db.getJShortType().getSize();
    longSize = db.getJLongType().getSize();
    floatSize = db.getJFloatType().getSize();
    doubleSize = db.getJDoubleType().getSize();
    
    initialize(db);
  }
  
  public boolean equal(Oop o1, Oop o2)
  {
    if (o1 != null) {
      return o1.equals(o2);
    }
    return o2 == null;
  }
  
  public long getOopSize()
  {
    return oopSize;
  }
  
  public long getByteSize()
  {
    return byteSize;
  }
  
  public long getCharSize()
  {
    return charSize;
  }
  
  public long getBooleanSize()
  {
    return booleanSize;
  }
  
  public long getIntSize()
  {
    return intSize;
  }
  
  public long getShortSize()
  {
    return shortSize;
  }
  
  public long getLongSize()
  {
    return longSize;
  }
  
  public long getFloatSize()
  {
    return floatSize;
  }
  
  public long getDoubleSize()
  {
    return doubleSize;
  }
  
  public SymbolKlass getSymbolKlassObj()
  {
    return symbolKlassObj;
  }
  
  public MethodKlass getMethodKlassObj()
  {
    return methodKlassObj;
  }
  
  public ConstMethodKlass getConstMethodKlassObj()
  {
    return constMethodKlassObj;
  }
  
  public MethodDataKlass getMethodDataKlassObj()
  {
    return methodDataKlassObj;
  }
  
  public ConstantPoolKlass getConstantPoolKlassObj()
  {
    return constantPoolKlassObj;
  }
  
  public ConstantPoolCacheKlass getConstantPoolCacheKlassObj()
  {
    return constantPoolCacheKlassObj;
  }
  
  public KlassKlass getKlassKlassObj()
  {
    return klassKlassObj;
  }
  
  public ArrayKlassKlass getArrayKlassKlassObj()
  {
    return arrayKlassKlassObj;
  }
  
  public InstanceKlassKlass getInstanceKlassKlassObj()
  {
    return instanceKlassKlassObj;
  }
  
  public ObjArrayKlassKlass getObjArrayKlassKlassObj()
  {
    return objArrayKlassKlassObj;
  }
  
  public TypeArrayKlassKlass getTypeArrayKlassKlassObj()
  {
    return typeArrayKlassKlassObj;
  }
  
  public TypeArrayKlass getBoolArrayKlassObj()
  {
    return boolArrayKlassObj;
  }
  
  public TypeArrayKlass getByteArrayKlassObj()
  {
    return byteArrayKlassObj;
  }
  
  public TypeArrayKlass getCharArrayKlassObj()
  {
    return charArrayKlassObj;
  }
  
  public TypeArrayKlass getIntArrayKlassObj()
  {
    return intArrayKlassObj;
  }
  
  public TypeArrayKlass getShortArrayKlassObj()
  {
    return shortArrayKlassObj;
  }
  
  public TypeArrayKlass getLongArrayKlassObj()
  {
    return longArrayKlassObj;
  }
  
  public TypeArrayKlass getSingleArrayKlassObj()
  {
    return singleArrayKlassObj;
  }
  
  public TypeArrayKlass getDoubleArrayKlassObj()
  {
    return doubleArrayKlassObj;
  }
  
  public CompiledICHolderKlass getCompiledICHolderKlassObj()
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(!VM.getVM().isCore(), "must not be called for core build");
    }
    return compiledICHolderKlassObj;
  }
  
  public Klass typeArrayKlassObj(int t)
  {
    if (t == BasicType.getTBoolean()) {
      return getBoolArrayKlassObj();
    }
    if (t == BasicType.getTChar()) {
      return getCharArrayKlassObj();
    }
    if (t == BasicType.getTFloat()) {
      return getSingleArrayKlassObj();
    }
    if (t == BasicType.getTDouble()) {
      return getDoubleArrayKlassObj();
    }
    if (t == BasicType.getTByte()) {
      return getByteArrayKlassObj();
    }
    if (t == BasicType.getTShort()) {
      return getShortArrayKlassObj();
    }
    if (t == BasicType.getTInt()) {
      return getIntArrayKlassObj();
    }
    if (t == BasicType.getTLong()) {
      return getLongArrayKlassObj();
    }
    throw new RuntimeException("Illegal basic type " + t);
  }
  
  public void iterate(HeapVisitor visitor)
  {
    iterateLiveRegions(collectLiveRegions(), visitor, null);
  }
  
  public void iterate(HeapVisitor visitor, ObjectFilter of)
  {
    iterateLiveRegions(collectLiveRegions(), visitor, of);
  }
  
  public void iterateObjectsOfKlass(HeapVisitor visitor, Klass k, boolean includeSubtypes)
  {
    if (includeSubtypes)
    {
      if (k.isFinal()) {
        iterateExact(visitor, k);
      } else {
        iterateSubtypes(visitor, k);
      }
    }
    else if ((!k.isAbstract()) && (!k.isInterface())) {
      iterateExact(visitor, k);
    }
  }
  
  public void iterateObjectsOfKlass(HeapVisitor visitor, Klass k)
  {
    iterateObjectsOfKlass(visitor, k, true);
  }
  
  public void iterateRaw(RawHeapVisitor visitor)
  {
    List liveRegions = collectLiveRegions();
    
    long totalSize = 0L;
    for (int i = 0; i < liveRegions.size(); i += 2)
    {
      Address bottom = (Address)liveRegions.get(i);
      Address top = (Address)liveRegions.get(i + 1);
      totalSize += top.minus(bottom);
    }
    visitor.prologue(totalSize);
    for (int i = 0; i < liveRegions.size(); i += 2)
    {
      Address bottom = (Address)liveRegions.get(i);
      Address top = (Address)liveRegions.get(i + 1);
      while (bottom.lessThan(top))
      {
        visitor.visitAddress(bottom);
        bottom = bottom.addOffsetTo(VM.getVM().getAddressSize());
      }
    }
    visitor.epilogue();
  }
  
  public void iteratePerm(HeapVisitor visitor)
  {
    CollectedHeap heap = VM.getVM().getUniverse().heap();
    List liveRegions = new ArrayList();
    addPermGenLiveRegions(liveRegions, heap);
    sortLiveRegions(liveRegions);
    iterateLiveRegions(liveRegions, visitor, null);
  }
  
  public boolean isValidMethod(OopHandle handle)
  {
    OopHandle klass = Oop.getKlassForOopHandle(handle);
    if ((klass != null) && (klass.equals(methodKlassHandle))) {
      return true;
    }
    return false;
  }
  
  public Oop newOop(OopHandle handle)
  {
    if (handle == null) {
      return null;
    }
    if (handle.equals(methodKlassHandle)) {
      return getMethodKlassObj();
    }
    if (handle.equals(constMethodKlassHandle)) {
      return getConstMethodKlassObj();
    }
    if (handle.equals(symbolKlassHandle)) {
      return getSymbolKlassObj();
    }
    if (handle.equals(constantPoolKlassHandle)) {
      return getConstantPoolKlassObj();
    }
    if (handle.equals(constantPoolCacheKlassHandle)) {
      return getConstantPoolCacheKlassObj();
    }
    if (handle.equals(instanceKlassKlassHandle)) {
      return getInstanceKlassKlassObj();
    }
    if (handle.equals(objArrayKlassKlassHandle)) {
      return getObjArrayKlassKlassObj();
    }
    if (handle.equals(klassKlassHandle)) {
      return getKlassKlassObj();
    }
    if (handle.equals(arrayKlassKlassHandle)) {
      return getArrayKlassKlassObj();
    }
    if (handle.equals(typeArrayKlassKlassHandle)) {
      return getTypeArrayKlassKlassObj();
    }
    if (handle.equals(boolArrayKlassHandle)) {
      return getBoolArrayKlassObj();
    }
    if (handle.equals(byteArrayKlassHandle)) {
      return getByteArrayKlassObj();
    }
    if (handle.equals(charArrayKlassHandle)) {
      return getCharArrayKlassObj();
    }
    if (handle.equals(intArrayKlassHandle)) {
      return getIntArrayKlassObj();
    }
    if (handle.equals(shortArrayKlassHandle)) {
      return getShortArrayKlassObj();
    }
    if (handle.equals(longArrayKlassHandle)) {
      return getLongArrayKlassObj();
    }
    if (handle.equals(singleArrayKlassHandle)) {
      return getSingleArrayKlassObj();
    }
    if (handle.equals(doubleArrayKlassHandle)) {
      return getDoubleArrayKlassObj();
    }
    if (!VM.getVM().isCore())
    {
      if (handle.equals(compiledICHolderKlassHandle)) {
        return getCompiledICHolderKlassObj();
      }
      if (handle.equals(methodDataKlassHandle)) {
        return getMethodDataKlassObj();
      }
    }
    OopHandle klass = Oop.getKlassForOopHandle(handle);
    if (klass != null)
    {
      if (klass.equals(methodKlassHandle)) {
        return new Method(handle, this);
      }
      if (klass.equals(constMethodKlassHandle)) {
        return new ConstMethod(handle, this);
      }
      if (klass.equals(symbolKlassHandle)) {
        return new Symbol(handle, this);
      }
      if (klass.equals(constantPoolKlassHandle)) {
        return new ConstantPool(handle, this);
      }
      if (klass.equals(constantPoolCacheKlassHandle)) {
        return new ConstantPoolCache(handle, this);
      }
      if (!VM.getVM().isCore())
      {
        if (klass.equals(compiledICHolderKlassHandle)) {
          return new CompiledICHolder(handle, this);
        }
        if (klass.equals(methodDataKlassHandle)) {
          return new MethodData(handle, this);
        }
      }
      if (klass.equals(instanceKlassKlassHandle)) {
        return new InstanceKlass(handle, this);
      }
      if (klass.equals(objArrayKlassKlassHandle)) {
        return new ObjArrayKlass(handle, this);
      }
      if (klass.equals(typeArrayKlassKlassHandle)) {
        return new TypeArrayKlass(handle, this);
      }
      OopHandle klassKlass = Oop.getKlassForOopHandle(klass);
      if (klassKlass != null)
      {
        if (klassKlass.equals(instanceKlassKlassHandle)) {
          return new Instance(handle, this);
        }
        if (klassKlass.equals(objArrayKlassKlassHandle)) {
          return new ObjArray(handle, this);
        }
        if (klassKlass.equals(typeArrayKlassKlassHandle)) {
          return new TypeArray(handle, this);
        }
      }
    }
    if (DEBUG)
    {
      System.err.println("Unknown oop at " + handle);
      System.err.println("Oop's klass is " + klass);
    }
    throw new UnknownOopException();
  }
  
  public void print()
  {
    HeapPrinter printer = new HeapPrinter(System.out);
    iterate(printer);
  }
  
  private void iterateExact(HeapVisitor visitor, final Klass k)
  {
    iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter()
    {
      public boolean canInclude(Oop obj)
      {
        Klass tk = obj.getKlass();
        
        return (tk != null) && (tk.equals(k));
      }
    });
  }
  
  private void iterateSubtypes(HeapVisitor visitor, final Klass k)
  {
    iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter()
    {
      public boolean canInclude(Oop obj)
      {
        Klass tk = obj.getKlass();
        
        return (tk != null) && (tk.isSubtypeOf(k));
      }
    });
  }
  
  private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of)
  {
    long totalSize = 0L;
    for (int i = 0; i < liveRegions.size(); i += 2)
    {
      Address bottom = (Address)liveRegions.get(i);
      Address top = (Address)liveRegions.get(i + 1);
      totalSize += top.minus(bottom);
    }
    visitor.prologue(totalSize);
    
    CompactibleFreeListSpace cmsSpaceOld = null;
    CompactibleFreeListSpace cmsSpacePerm = null;
    CollectedHeap heap = VM.getVM().getUniverse().heap();
    if ((heap instanceof GenCollectedHeap))
    {
      GenCollectedHeap genHeap = (GenCollectedHeap)heap;
      Generation genOld = genHeap.getGen(1);
      Generation genPerm = genHeap.permGen();
      if ((genOld instanceof ConcurrentMarkSweepGeneration))
      {
        ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld;
        cmsSpaceOld = concGen.cmsSpace();
      }
      if ((genPerm instanceof ConcurrentMarkSweepGeneration))
      {
        ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genPerm;
        cmsSpacePerm = concGen.cmsSpace();
      }
    }
    for (int i = 0; i < liveRegions.size(); i += 2)
    {
      Address bottom = (Address)liveRegions.get(i);
      Address top = (Address)liveRegions.get(i + 1);
      try
      {
        OopHandle handle = bottom.addOffsetToAsOopHandle(0L);
        while (handle.lessThan(top))
        {
          Oop obj = null;
          try
          {
            obj = newOop(handle);
          }
          catch (UnknownOopException exp)
          {
            if (DEBUG) {
              throw new RuntimeException(" UnknownOopException  " + exp);
            }
          }
          if (obj == null)
          {
            System.err.println("Finding object size using Printezis bits and skipping over...");
            long size = 0L;
            if ((cmsSpaceOld != null) && (cmsSpaceOld.contains(handle))) {
              size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle);
            } else if ((cmsSpacePerm != null) && (cmsSpacePerm.contains(handle))) {
              size = cmsSpacePerm.collector().blockSizeUsingPrintezisBits(handle);
            }
            if (size <= 0L) {
              throw new UnknownOopException();
            }
            handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size));
          }
          else
          {
            if (((of == null) || (of.canInclude(obj))) && 
              (visitor.doObj(obj))) {
              break;
            }
            if (((cmsSpaceOld != null) && (cmsSpaceOld.contains(handle))) || ((cmsSpacePerm != null) && (cmsSpacePerm.contains(handle)))) {
              handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()));
            } else {
              handle = handle.addOffsetToAsOopHandle(obj.getObjectSize());
            }
          }
        }
      }
      catch (AddressException e) {}catch (UnknownOopException e) {}
    }
    visitor.epilogue();
  }
  
  private void addPermGenLiveRegions(List output, CollectedHeap heap)
  {
    LiveRegionsCollector lrc = new LiveRegionsCollector(output);
    if ((heap instanceof GenCollectedHeap))
    {
      GenCollectedHeap genHeap = (GenCollectedHeap)heap;
      Generation gen = genHeap.permGen();
      gen.spaceIterate(lrc, true);
    }
    else if ((heap instanceof ParallelScavengeHeap))
    {
      ParallelScavengeHeap psh = (ParallelScavengeHeap)heap;
      PSPermGen permGen = psh.permGen();
      addLiveRegions(permGen.objectSpace().getLiveRegions(), output);
    }
    else if (Assert.ASSERTS_ENABLED)
    {
      Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " + heap.getClass().getName());
    }
  }
  
  private void addLiveRegions(List input, List output)
  {
    for (Iterator itr = input.iterator(); itr.hasNext();)
    {
      MemRegion reg = (MemRegion)itr.next();
      Address top = reg.end();
      Address bottom = reg.start();
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(top != null, "top address in a live region should not be null");
      }
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(bottom != null, "bottom address in a live region should not be null");
      }
      output.add(top);
      output.add(bottom);
    }
  }
  
  private class LiveRegionsCollector
    implements SpaceClosure
  {
    private List liveRegions;
    
    LiveRegionsCollector(List l)
    {
      liveRegions = l;
    }
    
    public void doSpace(Space s)
    {
      ObjectHeap.this.addLiveRegions(s.getLiveRegions(), liveRegions);
    }
  }
  
  private List collectLiveRegions()
  {
    List liveRegions = new ArrayList();
    LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions);
    
    CollectedHeap heap = VM.getVM().getUniverse().heap();
    if ((heap instanceof GenCollectedHeap))
    {
      GenCollectedHeap genHeap = (GenCollectedHeap)heap;
      for (int i = 0; i < genHeap.nGens(); i++)
      {
        Generation gen = genHeap.getGen(i);
        gen.spaceIterate(lrc, true);
      }
    }
    else if ((heap instanceof ParallelScavengeHeap))
    {
      ParallelScavengeHeap psh = (ParallelScavengeHeap)heap;
      PSYoungGen youngGen = psh.youngGen();
      
      addLiveRegions(youngGen.edenSpace().getLiveRegions(), liveRegions);
      
      addLiveRegions(youngGen.fromSpace().getLiveRegions(), liveRegions);
      PSOldGen oldGen = psh.oldGen();
      addLiveRegions(oldGen.objectSpace().getLiveRegions(), liveRegions);
    }
    else if (Assert.ASSERTS_ENABLED)
    {
      Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " + heap.getClass().getName());
    }
    addPermGenLiveRegions(liveRegions, heap);
    if (VM.getVM().getUseTLAB()) {
      for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) {
        if (thread.isJavaThread())
        {
          ThreadLocalAllocBuffer tlab = thread.tlab();
          if (tlab.start() != null) {
            if ((tlab.top() == null) || (tlab.end() == null))
            {
              System.err.print("Warning: skipping invalid TLAB for thread ");
              thread.printThreadIDOn(System.err);
              System.err.println();
            }
            else
            {
              liveRegions.add(tlab.start());
              liveRegions.add(tlab.start());
              liveRegions.add(tlab.top());
              liveRegions.add(tlab.end());
            }
          }
        }
      }
    }
    sortLiveRegions(liveRegions);
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries");
    }
    return liveRegions;
  }
  
  private void sortLiveRegions(List liveRegions)
  {
    Collections.sort(liveRegions, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        Address a1 = (Address)o1;
        Address a2 = (Address)o2;
        if (AddressOps.lt(a1, a2)) {
          return -1;
        }
        if (AddressOps.gt(a1, a2)) {
          return 1;
        }
        return 0;
      }
    });
  }
  
  public static abstract interface ObjectFilter
  {
    public abstract boolean canInclude(Oop paramOop);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHeap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.util.Comparator;

final class ObjectHistogram$1
  implements Comparator
{
  private final ObjectHistogram this$0;
  
  ObjectHistogram$1(ObjectHistogram paramObjectHistogram) {}
  
  public int compare(Object o1, Object o2)
  {
    return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHistogram.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class ObjectHistogram
  implements HeapVisitor
{
  private HashMap map = new HashMap();
  
  public void prologue(long size) {}
  
  public boolean doObj(Oop obj)
  {
    Klass klass = obj.getKlass();
    if (!map.containsKey(klass)) {
      map.put(klass, new ObjectHistogramElement(klass));
    }
    ((ObjectHistogramElement)map.get(klass)).updateWith(obj);
    return false;
  }
  
  public void epilogue() {}
  
  public List getElements()
  {
    List list = new ArrayList();
    list.addAll(map.values());
    Collections.sort(list, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2);
      }
    });
    return list;
  }
  
  public void print()
  {
    printOn(System.out);
  }
  
  public void printOn(PrintStream tty)
  {
    List list = getElements();
    ObjectHistogramElement.titleOn(tty);
    Iterator iterator = list.listIterator();
    int num = 0;
    int totalCount = 0;
    int totalSize = 0;
    while (iterator.hasNext())
    {
      ObjectHistogramElement el = (ObjectHistogramElement)iterator.next();
      num++;
      totalCount = (int)(totalCount + el.getCount());
      totalSize = (int)(totalSize + el.getSize());
      tty.print(num + ":" + "\t\t");
      el.printOn(tty);
    }
    tty.println("Total : \t" + totalCount + "\t" + totalSize);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHistogram
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import sun.jvm.hotspot.memory.Universe;
import sun.jvm.hotspot.runtime.VM;

public class ObjectHistogramElement
{
  private Klass klass;
  private long count;
  private long size;
  
  public ObjectHistogramElement(Klass k)
  {
    klass = k;
    count = 0L;
    size = 0L;
  }
  
  public void updateWith(Oop obj)
  {
    count += 1L;
    size += obj.getObjectSize();
  }
  
  public int compare(ObjectHistogramElement other)
  {
    return (int)(size - size);
  }
  
  public Klass getKlass()
  {
    return klass;
  }
  
  public long getCount()
  {
    return count;
  }
  
  public long getSize()
  {
    return size;
  }
  
  private String getInternalName(Klass k)
  {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    getKlass().printValueOn(new PrintStream(bos));
    
    return "* " + bos.toString();
  }
  
  public String getDescription()
  {
    Klass k = getKlass();
    if ((k instanceof InstanceKlass)) {
      return k.getName().asString().replace('/', '.');
    }
    if ((k instanceof ArrayKlass))
    {
      ArrayKlass ak = (ArrayKlass)k;
      if ((k instanceof TypeArrayKlass))
      {
        TypeArrayKlass tak = (TypeArrayKlass)ak;
        return tak.getElementTypeName() + "[]";
      }
      if ((k instanceof ObjArrayKlass))
      {
        ObjArrayKlass oak = (ObjArrayKlass)ak;
        if (oak.equals(VM.getVM().getUniverse().systemObjArrayKlassObj())) {
          return "* System ObjArray";
        }
        Klass bottom = oak.getBottomKlass();
        int dim = (int)oak.getDimension();
        StringBuffer buf = new StringBuffer();
        if ((bottom instanceof TypeArrayKlass)) {
          buf.append(((TypeArrayKlass)bottom).getElementTypeName());
        } else if ((bottom instanceof InstanceKlass)) {
          buf.append(bottom.getName().asString().replace('/', '.'));
        } else {
          throw new RuntimeException("should not reach here");
        }
        for (int i = 0; i < dim; i++) {
          buf.append("[]");
        }
        return buf.toString();
      }
    }
    return getInternalName(k);
  }
  
  public static void titleOn(PrintStream tty)
  {
    tty.println("Object Histogram:");
    tty.println();
    tty.println("num \t  #instances\t#bytes\tClass description");
    tty.println("--------------------------------------------------------------------------");
  }
  
  public void printOn(PrintStream tty)
  {
    tty.print(count + "\t" + size + "\t");
    tty.print(getDescription());
    tty.println();
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.ObjectHistogramElement
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.util.Observable;
import java.util.Observer;
import sun.jvm.hotspot.runtime.VM;

final class Oop$1
  implements Observer
{
  public void update(Observable o, Object data)
  {
    Oop.access$000(VM.getVM().getTypeDataBase());
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.Oop.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.io.PrintStream;
import java.util.Observable;
import java.util.Observer;
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.memory.CompactingPermGenGen;
import sun.jvm.hotspot.runtime.ObjectSynchronizer;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.types.Type;
import sun.jvm.hotspot.types.TypeDataBase;
import sun.jvm.hotspot.types.WrongTypeException;

public class Oop
{
  private OopHandle handle;
  private ObjectHeap heap;
  private static long headerSize;
  private static CIntField mark;
  private static OopField klass;
  private static NarrowOopField compressedKlass;
  
  static
  {
    VM.registerVMInitializedObserver(new Observer()
    {
      public void update(Observable o, Object data)
      {
        Oop.initialize(VM.getVM().getTypeDataBase());
      }
    });
  }
  
  private static synchronized void initialize(TypeDataBase db)
    throws WrongTypeException
  {
    Type type = db.lookupType("oopDesc");
    mark = new CIntField(type.getCIntegerField("_mark"), 0L);
    klass = new OopField(type.getOopField("_metadata._klass"), 0L);
    compressedKlass = new NarrowOopField(type.getOopField("_metadata._compressed_klass"), 0L);
    headerSize = type.getSize();
  }
  
  Oop(OopHandle handle, ObjectHeap heap)
  {
    this.handle = handle;
    this.heap = heap;
  }
  
  ObjectHeap getHeap()
  {
    return heap;
  }
  
  public OopHandle getHandle()
  {
    return handle;
  }
  
  public static long getHeaderSize()
  {
    return headerSize;
  }
  
  public boolean isShared()
  {
    return CompactingPermGenGen.isShared(handle);
  }
  
  public boolean isSharedReadOnly()
  {
    return CompactingPermGenGen.isSharedReadOnly(handle);
  }
  
  public boolean isSharedReadWrite()
  {
    return CompactingPermGenGen.isSharedReadWrite(handle);
  }
  
  public Mark getMark()
  {
    return new Mark(getHandle());
  }
  
  public Klass getKlass()
  {
    if (VM.getVM().isCompressedOopsEnabled()) {
      return (Klass)compressedKlass.getValue(this);
    }
    return (Klass)klass.getValue(this);
  }
  
  public boolean isA(Klass k)
  {
    return getKlass().isSubtypeOf(k);
  }
  
  public long getObjectSize()
  {
    Klass k = getKlass();
    if ((k instanceof InstanceKlass)) {
      return ((InstanceKlass)k).getSizeHelper() * VM.getVM().getAddressSize();
    }
    return getHeaderSize();
  }
  
  public boolean isInstance()
  {
    return false;
  }
  
  public boolean isInstanceRef()
  {
    return false;
  }
  
  public boolean isArray()
  {
    return false;
  }
  
  public boolean isObjArray()
  {
    return false;
  }
  
  public boolean isTypeArray()
  {
    return false;
  }
  
  public boolean isSymbol()
  {
    return false;
  }
  
  public boolean isKlass()
  {
    return false;
  }
  
  public boolean isThread()
  {
    return false;
  }
  
  public boolean isMethod()
  {
    return false;
  }
  
  public boolean isMethodData()
  {
    return false;
  }
  
  public boolean isConstantPool()
  {
    return false;
  }
  
  public boolean isConstantPoolCache()
  {
    return false;
  }
  
  public boolean isCompiledICHolder()
  {
    return false;
  }
  
  public static long alignObjectSize(long size)
  {
    return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes());
  }
  
  public static long alignObjectOffset(long offset)
  {
    return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
  }
  
  public boolean equals(Object obj)
  {
    if ((obj != null) && ((obj instanceof Oop))) {
      return getHandle().equals(((Oop)obj).getHandle());
    }
    return false;
  }
  
  public int hashCode()
  {
    return getHandle().hashCode();
  }
  
  public long identityHash()
  {
    Mark mark = getMark();
    if ((mark.isUnlocked()) && (!mark.hasNoHash())) {
      return (int)mark.hash();
    }
    if (mark.isMarked()) {
      return (int)mark.hash();
    }
    return slowIdentityHash();
  }
  
  public long slowIdentityHash()
  {
    return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
  }
  
  public void iterate(OopVisitor visitor, boolean doVMFields)
  {
    visitor.setObj(this);
    visitor.prologue();
    iterateFields(visitor, doVMFields);
    visitor.epilogue();
  }
  
  void iterateFields(OopVisitor visitor, boolean doVMFields)
  {
    if (doVMFields)
    {
      visitor.doCInt(mark, true);
      if (VM.getVM().isCompressedOopsEnabled()) {
        visitor.doOop(compressedKlass, true);
      } else {
        visitor.doOop(klass, true);
      }
    }
  }
  
  public void print()
  {
    printOn(System.out);
  }
  
  public void printValue()
  {
    printValueOn(System.out);
  }
  
  public void printRaw()
  {
    printRawOn(System.out);
  }
  
  public static void printOopValueOn(Oop obj, PrintStream tty)
  {
    if (obj == null)
    {
      tty.print("null");
    }
    else
    {
      obj.printValueOn(tty);
      tty.print(" @ " + obj.getHandle());
    }
  }
  
  public static void printOopAddressOn(Oop obj, PrintStream tty)
  {
    if (obj == null) {
      tty.print("null");
    } else {
      tty.print(obj.getHandle().toString());
    }
  }
  
  public void printOn(PrintStream tty)
  {
    OopPrinter printer = new OopPrinter(tty);
    iterate(printer, true);
  }
  
  public void printValueOn(PrintStream tty)
  {
    try
    {
      tty.print("Oop for " + getKlass().getName().asString());
    }
    catch (NullPointerException e)
    {
      tty.print("Oop");
    }
  }
  
  public void printRawOn(PrintStream tty)
  {
    tty.print("Dumping raw memory for ");
    printValueOn(tty);
    tty.println();
    long size = getObjectSize() * 4L;
    for (long i = 0L; i < size; i += 4L)
    {
      long memVal = getHandle().getCIntegerAt(i, 4L, true);
      tty.println(Long.toHexString(memVal));
    }
  }
  
  public boolean verify()
  {
    return true;
  }
  
  static OopHandle getKlassForOopHandle(OopHandle handle)
  {
    if (handle == null) {
      return null;
    }
    if (VM.getVM().isCompressedOopsEnabled()) {
      return handle.getCompOopHandleAt(compressedKlass.getOffset());
    }
    return handle.getOopHandleAt(klass.getOffset());
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.Oop
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import sun.jvm.hotspot.debugger.OopHandle;

public class OopField
  extends Field
{
  public OopField(FieldIdentifier id, long offset, boolean isVMField)
  {
    super(id, offset, isVMField);
  }
  
  public OopField(sun.jvm.hotspot.types.OopField vmField, long startOffset)
  {
    super(new NamedFieldIdentifier(vmField.getName()), vmField.getOffset() + startOffset, true);
  }
  
  public OopField(InstanceKlass holder, int fieldArrayIndex)
  {
    super(holder, fieldArrayIndex);
  }
  
  public Oop getValue(Oop obj)
  {
    return obj.getHeap().newOop(getValueAsOopHandle(obj));
  }
  
  public OopHandle getValueAsOopHandle(Oop obj)
  {
    return obj.getHandle().getOopHandleAt(getOffset());
  }
  
  public void setValue(Oop obj)
    throws MutationException
  {}
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.oops.OopField
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.oops;

import java.io.PrintStream;

public class OopPrinter
  implements OopVisitor
{
  PrintStream tty;
  private Oop obj;
  
  public OopPrinter(PrintStream tty)
  {
    this.tty = tty;
  }
  
  public void prologue()
  {
    Oop.printOopValueOn(getObj(), tty);
    tty.println(" (object size = " + getObj().getObjectSize() + ")");
  }
  
  public void epilogue()
  {
    tty.println();
  }
  
  public void setObj(Oop obj)
  {
  
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd