sa-jdi

    throws IOException
  {
    writeObjectHeader(instance);
    Klass reflectedType = OopUtilities.classOopToKlass(instance);
    boolean isInstanceKlass = reflectedType instanceof InstanceKlass;
    if (reflectedType != null)
    {
      Symbol name = reflectedType.getName();
      if (name != null) {
        writeAttribute("class-name", "string", name.asString());
      }
      if (isInstanceKlass)
      {
        long sizeInBytes = reflectedType.getLayoutHelper();
        writeAttribute("object-size", "int", Long.toString(sizeInBytes));
        
        writeObjectFields(reflectedType);
      }
    }
    out.println("</node>");
    Iterator itr;
    if (reflectedType != null)
    {
      Klass superType = reflectedType.getSuper();
      Oop superMirror = superType == null ? null : superType.getJavaMirror();
      
      writeEdge(instance, superMirror, "extends");
      if (isInstanceKlass)
      {
        InstanceKlass ik = (InstanceKlass)reflectedType;
        ObjArray interfaces = ik.getLocalInterfaces();
        int len = (int)interfaces.getLength();
        for (int i = 0; i < len; i++)
        {
          Klass k = (Klass)interfaces.getObjAt(i);
          writeEdge(instance, k.getJavaMirror(), "implements");
        }
        Oop loader = ik.getClassLoader();
        writeEdge(instance, loader, "loaded-by");
        
        Oop signers = ik.getSigners();
        writeEdge(instance, signers, "signed-by");
        
        Oop protectionDomain = ik.getProtectionDomain();
        writeEdge(instance, protectionDomain, "protection-domain");
        for (itr = refFields.iterator(); itr.hasNext();)
        {
          OopField field = (OopField)itr.next();
          Oop ref = field.getValue(reflectedType);
          String name = field.getID().getName();
          writeEdge(instance, ref, identifierToXMLName(name));
        }
      }
    }
    refFields = null;
  }
  
  protected void writeReferenceField(Oop oop, OopField field)
    throws IOException
  {
    refFields.add(field);
  }
  
  protected void writeByteField(Oop oop, ByteField field)
    throws IOException
  {
    writeField(field, "int", "B", Byte.toString(field.getValue(oop)));
  }
  
  protected void writeCharField(Oop oop, CharField field)
    throws IOException
  {
    writeField(field, "string", "C", escapeXMLChars(Character.toString(field.getValue(oop))));
  }
  
  protected void writeBooleanField(Oop oop, BooleanField field)
    throws IOException
  {
    writeField(field, "bool", "Z", Boolean.toString(field.getValue(oop)));
  }
  
  protected void writeShortField(Oop oop, ShortField field)
    throws IOException
  {
    writeField(field, "int", "S", Short.toString(field.getValue(oop)));
  }
  
  protected void writeIntField(Oop oop, IntField field)
    throws IOException
  {
    writeField(field, "int", "I", Integer.toString(field.getValue(oop)));
  }
  
  protected void writeLongField(Oop oop, LongField field)
    throws IOException
  {
    writeField(field, "int", "J", Long.toString(field.getValue(oop)));
  }
  
  protected void writeFloatField(Oop oop, FloatField field)
    throws IOException
  {
    writeField(field, "float", "F", Float.toString(field.getValue(oop)));
  }
  
  protected void writeDoubleField(Oop oop, DoubleField field)
    throws IOException
  {
    writeField(field, "float", "D", Double.toString(field.getValue(oop)));
  }
  
  protected void writeHeapFooter()
    throws IOException
  {
    out.println("</graph>");
    out.println("</gxl>");
  }
  
  private static String identifierToXMLName(String name)
  {
    return name.replace('$', '_');
  }
  
  private static String escapeXMLChars(String s)
  {
    StringBuffer result = null;
    int i = 0;int max = s.length();
    for (int delta = 0; i < max; i++)
    {
      char c = s.charAt(i);
      String replacement = null;
      if (c == '&') {
        replacement = "&amp;";
      } else if (c == '<') {
        replacement = "&lt;";
      } else if (c == '>') {
        replacement = "&gt;";
      } else if (c == '"') {
        replacement = "&quot;";
      } else if (c == '\'') {
        replacement = "&apos;";
      } else if ((c < ' ') || ((c > 55295) && (c < 57344)) || (c == 65534) || (c == 65535)) {
        replacement = "<![CDATA[&#x" + Integer.toHexString(c) + ";]]>";
      }
      if (replacement != null)
      {
        if (result == null) {
          result = new StringBuffer(s);
        }
        result.replace(i + delta, i + delta + 1, replacement);
        delta += replacement.length() - 1;
      }
    }
    if (result == null) {
      return s;
    }
    return result.toString();
  }
  
  private static String getID(Oop oop)
  {
    if (oop == null) {
      return "ID_NULL";
    }
    return "ID_" + oop.getHandle().toString();
  }
  
  private void writeArrayLength(Array array)
    throws IOException
  {
    writeAttribute("length", "int", Integer.toString((int)array.getLength()));
  }
  
  private void writeAttribute(String name, String type, String value)
  {
    out.print("\t<attr name='");
    out.print(name);
    out.print("'><");
    out.print(type);
    out.print('>');
    out.print(value);
    out.print("</");
    out.print(type);
    out.println("></attr>");
  }
  
  private void writeEdge(Oop from, Oop to, String name)
    throws IOException
  {
    out.print("<edge from='");
    out.print(getID(from));
    out.print("' to='");
    out.print(getID(to));
    out.println("'>");
    writeAttribute("name", "string", name);
    out.println("</edge>");
  }
  
  private void writeField(Field field, String type, String kind, String value)
    throws IOException
  {
    if (isArray)
    {
      out.print('\t');
    }
    else
    {
      out.print("\t<attr name='");
      String name = field.getID().getName();
      out.print(identifierToXMLName(name));
      out.print("' kind='");
      out.print(kind);
      out.print("'>");
    }
    out.print('<');
    out.print(type);
    out.print('>');
    out.print(value);
    out.print("</");
    out.print(type);
    out.print('>');
    if (isArray) {
      out.println();
    } else {
      out.println("</attr>");
    }
  }
  
  private void writeVMInfo()
    throws IOException
  {
    VM vm = VM.getVM();
    writeAttribute("vm-version", "string", vm.getVMRelease());
    writeAttribute("vm-type", "string", vm.isServerCompiler() ? "server" : vm.isClientCompiler() ? "client" : "core");
    
    writeAttribute("os", "string", vm.getOS());
    writeAttribute("cpu", "string", vm.getCPU());
    writeAttribute("pointer-size", "string", Integer.toString((int)vm.getOopSize() * 8));
  }
}

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

import java.io.IOException;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.oops.Klass;

final class HeapHprofBinWriter$1
  implements SystemDictionary.ClassVisitor
{
  private final HeapHprofBinWriter this$0;
  
  HeapHprofBinWriter$1(HeapHprofBinWriter paramHeapHprofBinWriter) {}
  
  public void visit(Klass k)
  {
    try
    {
      HeapHprofBinWriter.access$000(this$0, k);
    }
    catch (IOException e)
    {
      throw new RuntimeException(e);
    }
  }
}

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

import java.io.DataOutputStream;
import java.io.IOException;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.oops.ObjectHeap;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.runtime.AddressVisitor;

final class HeapHprofBinWriter$2
  implements AddressVisitor
{
  private final HeapHprofBinWriter this$0;
  
  HeapHprofBinWriter$2(HeapHprofBinWriter paramHeapHprofBinWriter, int paramInt) {}
  
  public void visitAddress(Address handleAddr)
  {
    try
    {
      if (handleAddr != null)
      {
        OopHandle oopHandle = handleAddr.getOopHandleAt(0L);
        Oop oop = HeapHprofBinWriter.access$100(this$0).newOop(oopHandle);
        if ((oop != null) && (this$0.isJavaVisible(oop)))
        {
          HeapHprofBinWriter.access$200(this$0).writeByte(2);
          HeapHprofBinWriter.access$300(this$0, oop);
          HeapHprofBinWriter.access$200(this$0).writeInt(val$threadIndex);
          HeapHprofBinWriter.access$200(this$0).writeInt(-1);
        }
      }
    }
    catch (IOException exp)
    {
      throw new RuntimeException(exp);
    }
  }
  
  public void visitCompOopAddress(Address handleAddr)
  {
    throw new RuntimeException(" Should not reach here. JNIHandles are not compressed \n");
  }
}

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

import java.io.IOException;
import sun.jvm.hotspot.memory.SymbolTable.SymbolVisitor;
import sun.jvm.hotspot.oops.Symbol;

final class HeapHprofBinWriter$3
  implements SymbolTable.SymbolVisitor
{
  private final HeapHprofBinWriter this$0;
  
  HeapHprofBinWriter$3(HeapHprofBinWriter paramHeapHprofBinWriter) {}
  
  public void visit(Symbol sym)
  {
    try
    {
      HeapHprofBinWriter.access$400(this$0, sym);
    }
    catch (IOException exp)
    {
      throw new RuntimeException(exp);
    }
  }
}

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

import java.io.DataOutputStream;
import java.io.IOException;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.oops.Instance;
import sun.jvm.hotspot.oops.Klass;

final class HeapHprofBinWriter$4
  implements SystemDictionary.ClassVisitor
{
  private int serialNum = 1;
  private final HeapHprofBinWriter this$0;
  
  HeapHprofBinWriter$4(HeapHprofBinWriter paramHeapHprofBinWriter) {}
  
  public void visit(Klass k)
  {
    try
    {
      Instance clazz = k.getJavaMirror();
      HeapHprofBinWriter.access$600(this$0, 2, 2 * (HeapHprofBinWriter.access$500(this$0) + 4));
      HeapHprofBinWriter.access$200(this$0).writeInt(serialNum);
      HeapHprofBinWriter.access$300(this$0, clazz);
      HeapHprofBinWriter.access$200(this$0).writeInt(1);
      HeapHprofBinWriter.access$300(this$0, k.getName());
      serialNum += 1;
    }
    catch (IOException exp)
    {
      throw new RuntimeException(exp);
    }
  }
}

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

import java.util.List;

class HeapHprofBinWriter$ClassData
{
  int instSize;
  List fields;
  
  HeapHprofBinWriter$ClassData(int instSize, List fields)
  {
    this.instSize = instSize;
    this.fields = fields;
  }
}

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

import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.Debugger;
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.memory.SymbolTable;
import sun.jvm.hotspot.memory.SymbolTable.SymbolVisitor;
import sun.jvm.hotspot.memory.SystemDictionary;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.oops.BooleanField;
import sun.jvm.hotspot.oops.ByteField;
import sun.jvm.hotspot.oops.CharField;
import sun.jvm.hotspot.oops.DoubleField;
import sun.jvm.hotspot.oops.Field;
import sun.jvm.hotspot.oops.FieldIdentifier;
import sun.jvm.hotspot.oops.FloatField;
import sun.jvm.hotspot.oops.Instance;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.IntField;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.LongField;
import sun.jvm.hotspot.oops.NarrowOopField;
import sun.jvm.hotspot.oops.ObjArray;
import sun.jvm.hotspot.oops.ObjArrayKlass;
import sun.jvm.hotspot.oops.ObjectHeap;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.oops.OopField;
import sun.jvm.hotspot.oops.OopUtilities;
import sun.jvm.hotspot.oops.ShortField;
import sun.jvm.hotspot.oops.Symbol;
import sun.jvm.hotspot.oops.TypeArray;
import sun.jvm.hotspot.oops.TypeArrayKlass;
import sun.jvm.hotspot.runtime.AddressVisitor;
import sun.jvm.hotspot.runtime.BasicType;
import sun.jvm.hotspot.runtime.JNIHandleBlock;
import sun.jvm.hotspot.runtime.JavaThread;
import sun.jvm.hotspot.runtime.VM;

public class HeapHprofBinWriter
  extends AbstractHeapGraphWriter
{
  private static final String HPROF_HEADER = "JAVA PROFILE 1.0.1";
  private static final int HPROF_UTF8 = 1;
  private static final int HPROF_LOAD_CLASS = 2;
  private static final int HPROF_UNLOAD_CLASS = 3;
  private static final int HPROF_FRAME = 4;
  private static final int HPROF_TRACE = 5;
  private static final int HPROF_ALLOC_SITES = 6;
  private static final int HPROF_HEAP_SUMMARY = 7;
  private static final int HPROF_START_THREAD = 10;
  private static final int HPROF_END_THREAD = 11;
  private static final int HPROF_HEAP_DUMP = 12;
  private static final int HPROF_CPU_SAMPLES = 13;
  private static final int HPROF_CONTROL_SETTINGS = 14;
  private static final int HPROF_GC_ROOT_UNKNOWN = 255;
  private static final int HPROF_GC_ROOT_JNI_GLOBAL = 1;
  private static final int HPROF_GC_ROOT_JNI_LOCAL = 2;
  private static final int HPROF_GC_ROOT_JAVA_FRAME = 3;
  private static final int HPROF_GC_ROOT_NATIVE_STACK = 4;
  private static final int HPROF_GC_ROOT_STICKY_CLASS = 5;
  private static final int HPROF_GC_ROOT_THREAD_BLOCK = 6;
  private static final int HPROF_GC_ROOT_MONITOR_USED = 7;
  private static final int HPROF_GC_ROOT_THREAD_OBJ = 8;
  private static final int HPROF_GC_CLASS_DUMP = 32;
  private static final int HPROF_GC_INSTANCE_DUMP = 33;
  private static final int HPROF_GC_OBJ_ARRAY_DUMP = 34;
  private static final int HPROF_GC_PRIM_ARRAY_DUMP = 35;
  private static final int HPROF_ARRAY_OBJECT = 1;
  private static final int HPROF_NORMAL_OBJECT = 2;
  private static final int HPROF_BOOLEAN = 4;
  private static final int HPROF_CHAR = 5;
  private static final int HPROF_FLOAT = 6;
  private static final int HPROF_DOUBLE = 7;
  private static final int HPROF_BYTE = 8;
  private static final int HPROF_SHORT = 9;
  private static final int HPROF_INT = 10;
  private static final int HPROF_LONG = 11;
  private static final int JVM_SIGNATURE_BOOLEAN = 90;
  private static final int JVM_SIGNATURE_CHAR = 67;
  private static final int JVM_SIGNATURE_BYTE = 66;
  private static final int JVM_SIGNATURE_SHORT = 83;
  private static final int JVM_SIGNATURE_INT = 73;
  private static final int JVM_SIGNATURE_LONG = 74;
  private static final int JVM_SIGNATURE_FLOAT = 70;
  private static final int JVM_SIGNATURE_DOUBLE = 68;
  private static final int JVM_SIGNATURE_ARRAY = 91;
  private static final int JVM_SIGNATURE_CLASS = 76;
  private static final int DUMMY_STACK_TRACE_ID = 1;
  private static final int EMPTY_FRAME_DEPTH = -1;
  private DataOutputStream out;
  private Debugger dbg;
  private ObjectHeap objectHeap;
  private SymbolTable symTbl;
  private int OBJ_ID_SIZE;
  private long BOOLEAN_BASE_OFFSET;
  private long BYTE_BASE_OFFSET;
  private long CHAR_BASE_OFFSET;
  private long SHORT_BASE_OFFSET;
  private long INT_BASE_OFFSET;
  private long LONG_BASE_OFFSET;
  private long FLOAT_BASE_OFFSET;
  private long DOUBLE_BASE_OFFSET;
  private long OBJECT_BASE_OFFSET;
  private long BOOLEAN_SIZE;
  private long BYTE_SIZE;
  private long CHAR_SIZE;
  private long SHORT_SIZE;
  private long INT_SIZE;
  private long LONG_SIZE;
  private long FLOAT_SIZE;
  private long DOUBLE_SIZE;
  
  public synchronized void write(String fileName)
    throws IOException
  {
    FileOutputStream fos = new FileOutputStream(fileName);
    FileChannel chn = fos.getChannel();
    out = new DataOutputStream(new BufferedOutputStream(fos));
    
    VM vm = VM.getVM();
    dbg = vm.getDebugger();
    objectHeap = vm.getObjectHeap();
    symTbl = vm.getSymbolTable();
    
    OBJ_ID_SIZE = ((int)vm.getOopSize());
    
    BOOLEAN_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BOOLEAN);
    BYTE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BYTE);
    CHAR_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_CHAR);
    SHORT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_SHORT);
    INT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_INT);
    LONG_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_LONG);
    FLOAT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_FLOAT);
    DOUBLE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_DOUBLE);
    OBJECT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_OBJECT);
    
    BOOLEAN_SIZE = objectHeap.getBooleanSize();
    BYTE_SIZE = objectHeap.getByteSize();
    CHAR_SIZE = objectHeap.getCharSize();
    SHORT_SIZE = objectHeap.getShortSize();
    INT_SIZE = objectHeap.getIntSize();
    LONG_SIZE = objectHeap.getLongSize();
    FLOAT_SIZE = objectHeap.getFloatSize();
    DOUBLE_SIZE = objectHeap.getDoubleSize();
    
    writeFileHeader();
    
    writeDummyTrace();
    
    writeSymbols();
    
    writeClasses();
    
    out.writeByte(12);
    out.writeInt(0);
    
    out.flush();
    long dumpStart = chn.position();
    
    out.writeInt(0);
    
    writeClassDumpRecords();
    
    super.write();
    
    out.flush();
    out = null;
    
    long dumpEnd = chn.position();
    
    int dumpLen = (int)(dumpEnd - dumpStart - 4L);
    
    chn.position(dumpStart);
    
    fos.write(dumpLen >>> 24 & 0xFF);
    fos.write(dumpLen >>> 16 & 0xFF);
    fos.write(dumpLen >>> 8 & 0xFF);
    fos.write(dumpLen >>> 0 & 0xFF);
    
    fos.close();
  }
  
  private void writeClassDumpRecords()
    throws IOException
  {
    SystemDictionary sysDict = VM.getVM().getSystemDictionary();
    try
    {
      sysDict.allClassesDo(new SystemDictionary.ClassVisitor()
      {
        public void visit(Klass k)
        {
          try
          {
            HeapHprofBinWriter.this.writeClassDumpRecord(k);
          }
          catch (IOException e)
          {
            throw new RuntimeException(e);
          }
        }
      });
    }
    catch (RuntimeException re)
    {
      handleRuntimeException(re);
    }
  }
  
  protected void writeClass(Instance instance)
    throws IOException
  {
    Klass reflectedKlass = OopUtilities.classOopToKlass(instance);
    if (reflectedKlass == null) {
      writeInstance(instance);
    }
  }
  
  private void writeClassDumpRecord(Klass k)
    throws IOException
  {
    out.writeByte(32);
    writeObjectID(k.getJavaMirror());
    out.writeInt(1);
    Klass superKlass = k.getJavaSuper();
    if (superKlass != null) {
      writeObjectID(superKlass.getJavaMirror());
    } else {
      writeObjectID(null);
    }
    if ((k instanceof InstanceKlass))
    {
      InstanceKlass ik = (InstanceKlass)k;
      writeObjectID(ik.getClassLoader());
      writeObjectID(ik.getSigners());
      writeObjectID(ik.getProtectionDomain());
      
      writeObjectID(null);
      writeObjectID(null);
      List fields = getInstanceFields(ik);
      int instSize = getSizeForFields(fields);
      classDataCache.put(ik, new ClassData(instSize, fields));
      out.writeInt(instSize);
      
      out.writeShort(0);
      
      List declaredFields = ik.getImmediateFields();
      List staticFields = new ArrayList();
      List instanceFields = new ArrayList();
      Iterator itr = null;
      for (itr = declaredFields.iterator(); itr.hasNext();)
      {
        Field field = (Field)itr.next();
        if (field.isStatic()) {
          staticFields.add(field);
        } else {
          instanceFields.add(field);
        }
      }
      writeFieldDescriptors(staticFields, ik);
      
      writeFieldDescriptors(instanceFields, null);
    }
    else
    {
      if ((k instanceof ObjArrayKlass))
      {
        ObjArrayKlass oak = (ObjArrayKlass)k;
        Klass bottomKlass = oak.getBottomKlass();
        if ((bottomKlass instanceof InstanceKlass))
        {
          InstanceKlass ik = (InstanceKlass)bottomKlass;
          writeObjectID(ik.getClassLoader());
          writeObjectID(ik.getSigners());
          writeObjectID(ik.getProtectionDomain());
        }
        else
        {
          writeObjectID(null);
          writeObjectID(null);
          writeObjectID(null);
        }
      }
      else
      {
        writeObjectID(null);
        writeObjectID(null);
        writeObjectID(null);
      }
      writeObjectID(null);
      writeObjectID(null);
      
      out.writeInt(0);
      
      out.writeShort(0);
      
      out.writeShort(0);
      
      out.writeShort(0);
    }
  }
  
  protected void writeJavaThread(JavaThread jt, int index)
    throws IOException
  {
    out.writeByte(8);
    writeObjectID(jt.getThreadObj());
    out.writeInt(index);
    out.writeInt(1);
    writeLocalJNIHandles(jt, index);
  }
  
  protected void writeLocalJNIHandles(JavaThread jt, int index)
    throws IOException
  {
    final int threadIndex = index;
    JNIHandleBlock blk = jt.activeHandles();
    if (blk != null) {
      try
      {
        blk.oopsDo(new AddressVisitor()
        {
          public void visitAddress(Address handleAddr)
          {
            try
            {
              if (handleAddr != null)
              {
                OopHandle oopHandle = handleAddr.getOopHandleAt(0L);
                Oop oop = objectHeap.newOop(oopHandle);
                if ((oop != null) && (isJavaVisible(oop)))
                {
                  out.writeByte(2);
                  HeapHprofBinWriter.this.writeObjectID(oop);
                  out.writeInt(threadIndex);
                  out.writeInt(-1);
                }
              }
            }
            catch (IOException exp)
            {
              throw new RuntimeException(exp);
            }
          }
          
          public void visitCompOopAddress(Address handleAddr)
          {
            throw new RuntimeException(" Should not reach here. JNIHandles are not compressed \n");
          }
        });
      }
      catch (RuntimeException re)
      {
        handleRuntimeException(re);
      }
    }
  }
  
  protected void writeGlobalJNIHandle(Address handleAddr)
    throws IOException
  {
    OopHandle oopHandle = handleAddr.getOopHandleAt(0L);
    Oop oop = objectHeap.newOop(oopHandle);
    if ((oop != null) && (isJavaVisible(oop)))
    {
      out.writeByte(1);
      writeObjectID(oop);
      
      writeObjectID(getAddressValue(handleAddr));
    }
  }
  
  protected void writeObjectArray(ObjArray array)
    throws IOException
  {
    out.writeByte(34);
    writeObjectID(array);
    out.writeInt(1);
    out.writeInt((int)array.getLength());
    writeObjectID(array.getKlass().getJavaMirror());
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      OopHandle handle = array.getOopHandleAt(index);
      writeObjectID(getAddressValue(handle));
    }
  }
  
  protected void writePrimitiveArray(TypeArray array)
    throws IOException
  {
    out.writeByte(35);
    writeObjectID(array);
    out.writeInt(1);
    out.writeInt((int)array.getLength());
    TypeArrayKlass tak = (TypeArrayKlass)array.getKlass();
    int type = tak.getElementType();
    out.writeByte((byte)type);
    switch (type)
    {
    case 4: 
      writeBooleanArray(array);
      break;
    case 5: 
      writeCharArray(array);
      break;
    case 6: 
      writeFloatArray(array);
      break;
    case 7: 
      writeDoubleArray(array);
      break;
    case 8: 
      writeByteArray(array);
      break;
    case 9: 
      writeShortArray(array);
      break;
    case 10: 
      writeIntArray(array);
      break;
    case 11: 
      writeLongArray(array);
      break;
    default: 
      throw new RuntimeException("should not reach here");
    }
  }
  
  private void writeBooleanArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE;
      out.writeBoolean(array.getHandle().getJBooleanAt(offset));
    }
  }
  
  private void writeByteArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = BYTE_BASE_OFFSET + index * BYTE_SIZE;
      out.writeByte(array.getHandle().getJByteAt(offset));
    }
  }
  
  private void writeShortArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = SHORT_BASE_OFFSET + index * SHORT_SIZE;
      out.writeShort(array.getHandle().getJShortAt(offset));
    }
  }
  
  private void writeIntArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = INT_BASE_OFFSET + index * INT_SIZE;
      out.writeInt(array.getHandle().getJIntAt(offset));
    }
  }
  
  private void writeLongArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = LONG_BASE_OFFSET + index * LONG_SIZE;
      out.writeLong(array.getHandle().getJLongAt(offset));
    }
  }
  
  private void writeCharArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = CHAR_BASE_OFFSET + index * CHAR_SIZE;
      out.writeChar(array.getHandle().getJCharAt(offset));
    }
  }
  
  private void writeFloatArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = FLOAT_BASE_OFFSET + index * FLOAT_SIZE;
      out.writeFloat(array.getHandle().getJFloatAt(offset));
    }
  }
  
  private void writeDoubleArray(TypeArray array)
    throws IOException
  {
    int length = (int)array.getLength();
    for (int index = 0; index < length; index++)
    {
      long offset = DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE;
      out.writeDouble(array.getHandle().getJDoubleAt(offset));
    }
  }
  
  protected void writeInstance(Instance instance)
    throws IOException
  {
    out.writeByte(33);
    writeObjectID(instance);
    out.writeInt(1);
    Klass klass = instance.getKlass();
    writeObjectID(klass.getJavaMirror());
    
    ClassData cd = (ClassData)classDataCache.get(klass);
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(cd != null, "can not get class data for " + klass.getName().asString() + klass.getHandle());
    }
    List fields = fields;
    int size = instSize;
    out.writeInt(size);
    for (Iterator itr = fields.iterator(); itr.hasNext();) {
      writeField((Field)itr.next(), instance);
    }
  }
  
  private void writeFieldDescriptors(List fields, InstanceKlass ik)
    throws IOException
  {
    out.writeShort((short)fields.size());
    for (Iterator itr = fields.iterator(); itr.hasNext();)
    {
      Field field = (Field)itr.next();
      Symbol name = symTbl.probe(field.getID().getName());
      writeObjectID(name);
      char typeCode = (char)field.getSignature().getByteAt(0L);
      int kind = signatureToHprofKind(typeCode);
      out.writeByte((byte)kind);
      if (ik != null) {
        writeField(field, ik);
      }
    }
  }
  
  public static int signatureToHprofKind(char ch)
  {
    switch (ch)
    {
    case 'L': 
    case '[': 
      return 2;
    case 'Z': 
      return 4;
    case 'C': 
      return 5;
    case 'F': 
      return 6;
    case 'D': 
      return 7;
    case 'B': 
      return 8;
    case 'S': 
      return 9;
    case 'I': 
      return 10;
    case 'J': 
      return 11;
    }
    throw new RuntimeException("should not reach here");
  }
  
  private void writeField(Field field, Oop oop)
    throws IOException
  {
    char typeCode = (char)field.getSignature().getByteAt(0L);
    switch (typeCode)
    {
    case 'Z': 
      out.writeBoolean(((BooleanField)field).getValue(oop));
      break;
    case 'C': 
      out.writeChar(((CharField)field).getValue(oop));
      break;
    case 'B': 
      out.writeByte(((ByteField)field).getValue(oop));
      break;
    case 'S': 
      out.writeShort(((ShortField)field).getValue(oop));
      break;
    case 'I': 
      out.writeInt(((IntField)field).getValue(oop));
      break;
    case 'J': 
      out.writeLong(((LongField)field).getValue(oop));
      break;
    case 'F': 
      out.writeFloat(((FloatField)field).getValue(oop));
      break;
    case 'D': 
      out.writeDouble(((DoubleField)field).getValue(oop));
      break;
    case 'L': 
    case '[': 
      if (VM.getVM().isCompressedOopsEnabled())
      {
        OopHandle handle = ((NarrowOopField)field).getValueAsOopHandle(oop);
        writeObjectID(getAddressValue(handle));
      }
      else
      {
        OopHandle handle = ((OopField)field).getValueAsOopHandle(oop);
        writeObjectID(getAddressValue(handle));
      }
      break;
    case 'E': 
    case 'G': 
    case 'H': 
    case 'K': 
    case 'M': 
    case 'N': 
    case 'O': 
    case 'P': 
    case 'Q': 
    case 'R': 
    case 'T': 
    case 'U': 
    case 'V': 
    case 'W': 
    case 'X': 
    case 'Y': 
    default: 
      throw new RuntimeException("should not reach here");
    }
  }
  
  private void writeHeader(int tag, int len)
    throws IOException
  {
    out.writeByte((byte)tag);
    out.writeInt(0);
    out.writeInt(len);
  }
  
  private void writeDummyTrace()
    throws IOException
  {
    writeHeader(5, 12);
    out.writeInt(1);
    out.writeInt(0);
    out.writeInt(0);
  }
  
  private void writeSymbols()
    throws IOException
  {
    try
    {
      symTbl.symbolsDo(new SymbolTable.SymbolVisitor()
      {
        public void visit(Symbol sym)
        {
          try
          {
            HeapHprofBinWriter.this.writeSymbol(sym);
          }
          catch (IOException exp)
          {
            throw new RuntimeException(exp);
          }
        }
      });
    }
    catch (RuntimeException re)
    {
      handleRuntimeException(re);
    }
  }
  
  private void writeSymbol(Symbol sym)
    throws IOException
  {
    byte[] buf = sym.asString().getBytes("UTF-8");
    writeHeader(1, buf.length + OBJ_ID_SIZE);
    writeObjectID(sym);
    out.write(buf);
  }
  
  private void writeClasses()
    throws IOException
  {
    SystemDictionary sysDict = VM.getVM().getSystemDictionary();
    try
    {
      sysDict.allClassesDo(new SystemDictionary.ClassVisitor()
      {
        private int serialNum = 1;
        
        public void visit(Klass k)
        {
          try
          {
            Instance clazz = k.getJavaMirror();
            HeapHprofBinWriter.this.writeHeader(2, 2 * (OBJ_ID_SIZE + 4));
            out.writeInt(serialNum);
            HeapHprofBinWriter.this.writeObjectID(clazz);
            out.writeInt(1);
            HeapHprofBinWriter.this.writeObjectID(k.getName());
            serialNum += 1;
          }
          catch (IOException exp)
          {
            throw new RuntimeException(exp);
          }
        }
      });
    }
    catch (RuntimeException re)
    {
      handleRuntimeException(re);
    }
  }
  
  private void writeFileHeader()
    throws IOException
  {
    out.writeBytes("JAVA PROFILE 1.0.1");
    out.writeByte(0);
    
    out.writeInt(OBJ_ID_SIZE);
    
    out.writeLong(System.currentTimeMillis());
  }
  
  private void writeObjectID(Oop oop)
    throws IOException
  {
    OopHandle handle = oop != null ? oop.getHandle() : null;
    long address = getAddressValue(handle);
    writeObjectID(address);
  }
  
  private void writeObjectID(long address)
    throws IOException
  {
    if (OBJ_ID_SIZE == 4) {
      out.writeInt((int)address);
    } else {
      out.writeLong(address);
    }
  }
  
  private long getAddressValue(Address addr)
  {
    return addr == null ? 0L : dbg.getAddressValue(addr);
  }
  
  private static List getInstanceFields(InstanceKlass ik)
  {
    InstanceKlass klass = ik;
    List res = new ArrayList();
    while (klass != null)
    {
      List curFields = klass.getImmediateFields();
      for (Iterator itr = curFields.iterator(); itr.hasNext();)
      {
        Field f = (Field)itr.next();
        if (!f.isStatic()) {
          res.add(f);
        }
      }
      klass = (InstanceKlass)klass.getSuper();
    }
    return res;
  }
  
  private int getSizeForFields(List fields)
  {
    int size = 0;
    for (Iterator itr = fields.iterator(); itr.hasNext();)
    {
      Field field = (Field)itr.next();
      char typeCode = (char)field.getSignature().getByteAt(0L);
      switch (typeCode)
      {
      case 'B': 
      case 'Z': 
        size++;
        break;
      case 'C': 
      case 'S': 
        size += 2;
        break;
      case 'F': 
      case 'I': 
        size += 4;
        break;
      case 'L': 
      case '[': 
        size += OBJ_ID_SIZE;
        break;
      case 'D': 
      case 'J': 
        size += 8;
        break;
      case 'E': 
      case 'G': 
      case 'H': 
      case 'K': 
      case 'M': 
      case 'N': 
      case 'O': 
      case 'P': 
      case 'Q': 
      case 'R': 
      case 'T': 
      case 'U': 
      case 'V': 
      case 'W': 
      case 'X': 
      case 'Y': 
      default: 
        throw new RuntimeException("should not reach here");
      }
    }
    return size;
  }
  
  private static class ClassData
  {
    int instSize;
    List fields;
    
    ClassData(int instSize, List fields)
    {
      this.instSize = instSize;
      this.fields = fields;
    }
  }
  
  private Map classDataCache = new HashMap();
}

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

public abstract interface HeapProgressThunk
{
  public abstract void heapIterationFractionUpdate(double paramDouble);
  
  public abstract void heapIterationComplete();
}

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

public class IntegerEnum
{
  private int value;
  
  protected IntegerEnum(int value)
  {
    this.value = value;
  }
  
  public int getValue()
  {
    return value;
  }
}

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

import java.util.Comparator;

public class Interval
{
  private Object lowEndpoint;
  private Object highEndpoint;
  
  public Interval(Object lowEndpoint, Object highEndpoint)
  {
    this.lowEndpoint = lowEndpoint;
    this.highEndpoint = highEndpoint;
  }
  
  public Object getLowEndpoint()
  {
    return lowEndpoint;
  }
  
  public Object getHighEndpoint()
  {
    return highEndpoint;
  }
  
  public boolean overlaps(Interval arg, Comparator endpointComparator)
  {
    return overlaps(arg.getLowEndpoint(), arg.getHighEndpoint(), endpointComparator);
  }
  
  public boolean overlaps(Object otherLowEndpoint, Object otherHighEndpoint, Comparator endpointComparator)
  {
    if (endpointComparator.compare(highEndpoint, otherLowEndpoint) <= 0) {
      return false;
    }
    if (endpointComparator.compare(lowEndpoint, otherHighEndpoint) >= 0) {
      return false;
    }
    return true;
  }
  
  public String toString()
  {
    return "[ " + getLowEndpoint().toString() + ", " + getHighEndpoint().toString() + ")";
  }
}

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

import java.util.Comparator;

public class IntervalNode
  extends RBNode
{
  private Interval interval;
  private Comparator endpointComparator;
  private Object minEndpoint;
  private Object maxEndpoint;
  
  public IntervalNode(Interval interval, Comparator endpointComparator, Object data)
  {
    super(data);
    this.interval = interval;
    this.endpointComparator = endpointComparator;
  }
  
  public void copyFrom(RBNode arg)
  {
    IntervalNode argNode = (IntervalNode)arg;
    interval = interval;
  }
  
  public Interval getInterval()
  {
    return interval;
  }
  
  public Object getMinEndpoint()
  {
    return minEndpoint;
  }
  
  public Object getMaxEndpoint()
  {
    return maxEndpoint;
  }
  
  public boolean update()
  {
    Object newMaxEndpoint = computeMaxEndpoint();
    Object newMinEndpoint = computeMinEndpoint();
    if ((maxEndpoint != newMaxEndpoint) || (minEndpoint != newMinEndpoint))
    {
      maxEndpoint = newMaxEndpoint;
      minEndpoint = newMinEndpoint;
      return true;
    }
    return false;
  }
  
  public Object computeMinEndpoint()
  {
    IntervalNode left = (IntervalNode)getLeft();
    if (left != null) {
      return left.getMinEndpoint();
    }
    return interval.getLowEndpoint();
  }
  
  public Object computeMaxEndpoint()
  {
    Object curMax = interval.getHighEndpoint();
    if (getLeft() != null)
    {
      IntervalNode left = (IntervalNode)getLeft();
      if (endpointComparator.compare(left.getMaxEndpoint(), curMax) > 0) {
        curMax = left.getMaxEndpoint();
      }
    }
    if (getRight() != null)
    {
      IntervalNode right = (IntervalNode)getRight();
      if (endpointComparator.compare(right.getMaxEndpoint(), curMax) > 0) {
        curMax = right.getMaxEndpoint();
      }
    }
    return curMax;
  }
  
  public String toString()
  {
    String res = interval.toString();
    Object d = getData();
    if (d != null) {
      res = res + " " + d;
    }
    return res;
  }
}

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

import java.util.Comparator;

class IntervalTree$IntervalComparator
  implements Comparator
{
  private Comparator endpointComparator;
  
  public IntervalTree$IntervalComparator(Comparator endpointComparator)
  {
    this.endpointComparator = endpointComparator;
  }
  
  public int compare(Object o1, Object o2)
  {
    Interval i1 = (Interval)o1;
    Interval i2 = (Interval)o2;
    return endpointComparator.compare(i1.getLowEndpoint(), i2.getLowEndpoint());
  }
}

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

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class IntervalTree
  extends RBTree
{
  private Comparator endpointComparator;
  
  public IntervalTree(Comparator endpointComparator)
  {
    super(new IntervalComparator(endpointComparator));
    this.endpointComparator = endpointComparator;
  }
  
  public void insert(Interval interval, Object data)
  {
    IntervalNode node = new IntervalNode(interval, endpointComparator, data);
    insertNode(node);
  }
  
  public List findAllNodesIntersecting(Interval interval)
  {
    List retList = new ArrayList();
    searchForIntersectingNodesFrom((IntervalNode)getRoot(), in
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