sa-jdi

 char[] chars = new char[data.length];
      for (int i = 0; i < data.length; i++) {
        chars[i] = ((char)data[i]);
      }
      String helloWorldStr = new String(chars);
      
      System.out.println("Successfully read string \"" + helloWorldStr + "\" from target process\n");
      
      byte expectedByteValue = -124;
      short expectedShortValue = 27890;
      int expectedIntValue = 1020304050;
      long expectedLongValue = 102030405060708090L;
      float expectedFloatValue = 35.4F;
      double expectedDoubleValue = 1.23456789D;
      byte byteValue = 0;
      short shortValue = 0;
      int intValue = 0;
      long longValue = 0L;
      float floatValue = 0.0F;
      double doubleValue = 0.0D;
      
      addr = debugger.lookup(loadObjectName, "testByte");
      if (addr == null)
      {
        System.err.println("Error looking up symbol \"testByte\" in context \"" + loadObjectName + "\"");
        
        System.exit(1);
      }
      byteValue = addr.getJByteAt(0L);
      if (byteValue != expectedByteValue)
      {
        System.err.println("Error: unexpected byte value (got " + byteValue + ", expected " + expectedByteValue + ")");
        
        System.exit(1);
      }
      addr = debugger.lookup(loadObjectName, "testShort");
      if (addr == null)
      {
        System.err.println("Error looking up symbol \"testShort\" in context \"" + loadObjectName + "\"");
        
        System.exit(1);
      }
      shortValue = addr.getJShortAt(0L);
      if (shortValue != expectedShortValue)
      {
        System.err.println("Error: unexpected short value (got " + shortValue + ", expected " + expectedShortValue + ")");
        
        System.exit(1);
      }
      addr = debugger.lookup(loadObjectName, "testInt");
      if (addr == null)
      {
        System.err.println("Error looking up symbol \"testInt\" in context \"" + loadObjectName + "\"");
        
        System.exit(1);
      }
      intValue = addr.getJIntAt(0L);
      if (intValue != expectedIntValue)
      {
        System.err.println("Error: unexpected int value (got " + intValue + ", expected " + expectedIntValue + ")");
        
        System.exit(1);
      }
      addr = debugger.lookup(loadObjectName, "testLong");
      if (addr == null)
      {
        System.err.println("Error looking up symbol \"testLong\" in context \"" + loadObjectName + "\"");
        
        System.exit(1);
      }
      longValue = addr.getJLongAt(0L);
      if (longValue != expectedLongValue)
      {
        System.err.println("Error: unexpected long value (got " + longValue + ", expected " + expectedLongValue + ")");
        
        System.exit(1);
      }
      addr = debugger.lookup(loadObjectName, "testFloat");
      if (addr == null)
      {
        System.err.println("Error looking up symbol \"testFloat\" in context \"" + loadObjectName + "\"");
        
        System.exit(1);
      }
      floatValue = addr.getJFloatAt(0L);
      if (floatValue != expectedFloatValue)
      {
        System.err.println("Error: unexpected float value (got " + floatValue + ", expected " + expectedFloatValue + ")");
        
        System.exit(1);
      }
      addr = debugger.lookup(loadObjectName, "testDouble");
      if (addr == null)
      {
        System.err.println("Error looking up symbol \"testDouble\" in context \"" + loadObjectName + "\"");
        
        System.exit(1);
      }
      doubleValue = addr.getJDoubleAt(0L);
      if (doubleValue != expectedDoubleValue)
      {
        System.err.println("Error: unexpected double value (got " + doubleValue + ", expected " + expectedDoubleValue + ")");
        
        System.exit(1);
      }
      System.err.println("All tests passed successfully.");
      
      debugger.detach();
    }
    catch (AddressException e)
    {
      System.err.println("Error occurred during test:");
      e.printStackTrace();
      System.exit(1);
    }
  }
}

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

import sun.jvm.hotspot.oops.DefaultOopVisitor;
import sun.jvm.hotspot.oops.FieldIdentifier;
import sun.jvm.hotspot.oops.OopField;

final class FinalizerInfo$1
  extends DefaultOopVisitor
{
  private final FinalizerInfo this$0;
  
  FinalizerInfo$1(FinalizerInfo paramFinalizerInfo, OopField[] paramArrayOfOopField) {}
  
  public void doOop(OopField field, boolean isVMField)
  {
    String name = field.getID().getName();
    if (name.equals("queue")) {
      val$queueField[0] = field;
    }
  }
}

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

import java.util.Comparator;
import sun.jvm.hotspot.oops.ObjectHistogramElement;

final class FinalizerInfo$2
  implements Comparator
{
  private final FinalizerInfo this$0;
  
  FinalizerInfo$2(FinalizerInfo paramFinalizerInfo) {}
  
  public int compare(Object o1, Object o2)
  {
    return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2);
  }
}

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

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import sun.jvm.hotspot.oops.DefaultOopVisitor;
import sun.jvm.hotspot.oops.FieldIdentifier;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.LongField;
import sun.jvm.hotspot.oops.ObjectHistogramElement;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.oops.OopField;
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;

public class FinalizerInfo
  extends Tool
{
  public static void main(String[] args)
  {
    FinalizerInfo finfo = new FinalizerInfo();
    finfo.start(args);
    finfo.stop();
  }
  
  public void run()
  {
    InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer");
    
    final OopField[] queueField = new OopField[1];
    ik.iterateFields(new DefaultOopVisitor()
    {
      public void doOop(OopField field, boolean isVMField)
      {
        String name = field.getID().getName();
        if (name.equals("queue")) {
          queueField[0] = field;
        }
      }
    }, false);
    
    Oop queue = queueField[0].getValue(ik);
    
    InstanceKlass k = (InstanceKlass)queue.getKlass();
    
    LongField queueLengthField = (LongField)k.findField("queueLength", "J");
    long queueLength = queueLengthField.getValue(queue);
    
    OopField headField = (OopField)k.findField("head", "Ljava/lang/ref/Reference;");
    Oop head = headField.getValue(queue);
    
    System.out.println("Number of objects pending for finalization: " + queueLength);
    if (head != null)
    {
      k = (InstanceKlass)head.getKlass();
      OopField referentField = (OopField)k.findField("referent", "Ljava/lang/Object;");
      
      OopField nextField = (OopField)k.findField("next", "Ljava/lang/ref/Reference;");
      
      HashMap map = new HashMap();
      for (;;)
      {
        Oop referent = referentField.getValue(head);
        
        Klass klass = referent.getKlass();
        if (!map.containsKey(klass)) {
          map.put(klass, new ObjectHistogramElement(klass));
        }
        ((ObjectHistogramElement)map.get(klass)).updateWith(referent);
        
        Oop next = nextField.getValue(head);
        if ((next == null) || (next.equals(head))) {
          break;
        }
        head = next;
      }
      ArrayList 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);
        }
      });
      System.out.println("");
      System.out.println("Count\tClass description");
      System.out.println("-------------------------------------------------------");
      for (int i = 0; i < list.size(); i++)
      {
        ObjectHistogramElement e = (ObjectHistogramElement)list.get(i);
        System.out.println(e.getCount() + "\t" + e.getDescription());
      }
    }
  }
}

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

import java.io.PrintStream;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VM.Flag;

public class FlagDumper
  extends Tool
{
  public void run()
  {
    VM.Flag[] flags = VM.getVM().getCommandLineFlags();
    PrintStream out = System.out;
    if (flags == null) {
      out.println("Command Flags info not available! (use 1.4.1_03 or later)");
    } else {
      for (int f = 0; f < flags.length; f++)
      {
        out.print(flags[f].getName());
        out.print(" = ");
        out.println(flags[f].getValue());
      }
    }
  }
  
  public static void main(String[] args)
  {
    FlagDumper fd = new FlagDumper();
    fd.start(args);
    fd.stop();
  }
}

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

import java.io.IOException;
import java.io.PrintStream;
import sun.jvm.hotspot.utilities.HeapHprofBinWriter;

public class HeapDumper
  extends Tool
{
  private static String DEFAULT_DUMP_FILE = "heap.bin";
  private String dumpFile;
  
  public HeapDumper(String dumpFile)
  {
    this.dumpFile = dumpFile;
  }
  
  protected void printFlagsUsage()
  {
    System.out.println("    <no option>\tto dump heap to " + DEFAULT_DUMP_FILE);
    
    System.out.println("    -f <file>\tto dump heap to <file>");
    super.printFlagsUsage();
  }
  
  public void run()
  {
    System.out.println("Dumping heap to " + dumpFile + " ...");
    try
    {
      new HeapHprofBinWriter().write(dumpFile);
      System.out.println("Heap dump file created");
    }
    catch (IOException ioe)
    {
      System.err.println(ioe.getMessage());
    }
  }
  
  public static void main(String[] args)
  {
    String file = DEFAULT_DUMP_FILE;
    if ((args.length > 2) && 
      (args[0].equals("-f")))
    {
      file = args[1];
      String[] newargs = new String[args.length - 2];
      System.arraycopy(args, 2, newargs, 0, args.length - 2);
      args = newargs;
    }
    HeapDumper dumper = new HeapDumper(file);
    dumper.start(args);
    dumper.stop();
  }
}

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

import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
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.ContiguousSpace;
import sun.jvm.hotspot.memory.DefNewGeneration;
import sun.jvm.hotspot.memory.GenCollectedHeap;
import sun.jvm.hotspot.memory.Generation;
import sun.jvm.hotspot.memory.Universe;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VM.Flag;

public class HeapSummary
  extends Tool
{
  public static void main(String[] args)
  {
    HeapSummary hs = new HeapSummary();
    hs.start(args);
    hs.stop();
  }
  
  public void run()
  {
    CollectedHeap heap = VM.getVM().getUniverse().heap();
    VM.Flag[] flags = VM.getVM().getCommandLineFlags();
    Map flagMap = new HashMap();
    if (flags == null) {
      System.out.println("WARNING: command line flags are not available");
    } else {
      for (int f = 0; f < flags.length; f++) {
        flagMap.put(flags[f].getName(), flags[f]);
      }
    }
    System.out.println();
    printGCAlgorithm(flagMap);
    System.out.println();
    System.out.println("Heap Configuration:");
    printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap));
    printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap));
    printValMB("MaxHeapSize      = ", getFlagValue("MaxHeapSize", flagMap));
    printValMB("NewSize          = ", getFlagValue("NewSize", flagMap));
    printValMB("MaxNewSize       = ", getFlagValue("MaxNewSize", flagMap));
    printValMB("OldSize          = ", getFlagValue("OldSize", flagMap));
    printValue("NewRatio         = ", getFlagValue("NewRatio", flagMap));
    printValue("SurvivorRatio    = ", getFlagValue("SurvivorRatio", flagMap));
    printValMB("PermSize         = ", getFlagValue("PermSize", flagMap));
    printValMB("MaxPermSize      = ", getFlagValue("MaxPermSize", flagMap));
    
    System.out.println();
    System.out.println("Heap Usage:");
    if ((heap instanceof GenCollectedHeap))
    {
      GenCollectedHeap genHeap = (GenCollectedHeap)heap;
      for (int n = 0; n < genHeap.nGens(); n++)
      {
        Generation gen = genHeap.getGen(n);
        if ((gen instanceof DefNewGeneration))
        {
          System.out.println("New Generation (Eden + 1 Survivor Space):");
          printGen(gen);
          
          ContiguousSpace eden = ((DefNewGeneration)gen).eden();
          System.out.println("Eden Space:");
          printSpace(eden);
          
          ContiguousSpace from = ((DefNewGeneration)gen).from();
          System.out.println("From Space:");
          printSpace(from);
          
          ContiguousSpace to = ((DefNewGeneration)gen).to();
          System.out.println("To Space:");
          printSpace(to);
        }
        else
        {
          System.out.println(gen.name() + ":");
          printGen(gen);
        }
      }
      Generation permGen = genHeap.permGen();
      System.out.println("Perm Generation:");
      printGen(permGen);
    }
    else if ((heap instanceof ParallelScavengeHeap))
    {
      ParallelScavengeHeap psh = (ParallelScavengeHeap)heap;
      PSYoungGen youngGen = psh.youngGen();
      printPSYoungGen(youngGen);
      
      PSOldGen oldGen = psh.oldGen();
      long oldFree = oldGen.capacity() - oldGen.used();
      System.out.println("PS Old Generation");
      printValMB("capacity = ", oldGen.capacity());
      printValMB("used     = ", oldGen.used());
      printValMB("free     = ", oldFree);
      System.out.println(alignment + oldGen.used() * 100.0D / oldGen.capacity() + "% used");
      
      PSPermGen permGen = psh.permGen();
      long permFree = permGen.capacity() - permGen.used();
      System.out.println("PS Perm Generation");
      printValMB("capacity = ", permGen.capacity());
      printValMB("used     = ", permGen.used());
      printValMB("free     = ", permFree);
      System.out.println(alignment + permGen.used() * 100.0D / permGen.capacity() + "% used");
    }
    else
    {
      throw new RuntimeException("unknown heap type : " + heap.getClass());
    }
  }
  
  private void printGCAlgorithm(Map flagMap)
  {
    long l = getFlagValue("UseParNewGC", flagMap);
    if (l == 1L) {
      System.out.println("using parallel threads in the new generation.");
    }
    l = getFlagValue("UseTLAB", flagMap);
    if (l == 1L) {
      System.out.println("using thread-local object allocation.");
    }
    l = getFlagValue("UseConcMarkSweepGC", flagMap);
    if (l == 1L)
    {
      System.out.println("Concurrent Mark-Sweep GC");
      return;
    }
    l = getFlagValue("UseParallelGC", flagMap);
    if (l == 1L)
    {
      System.out.print("Parallel GC ");
      l = getFlagValue("ParallelGCThreads", flagMap);
      System.out.println("with " + l + " thread(s)");
      return;
    }
    System.out.println("Mark Sweep Compact GC");
  }
  
  private void printPSYoungGen(PSYoungGen youngGen)
  {
    System.out.println("PS Young Generation");
    MutableSpace eden = youngGen.edenSpace();
    System.out.println("Eden Space:");
    printMutableSpace(eden);
    MutableSpace from = youngGen.fromSpace();
    System.out.println("From Space:");
    printMutableSpace(from);
    MutableSpace to = youngGen.toSpace();
    System.out.println("To Space:");
    printMutableSpace(to);
  }
  
  private void printMutableSpace(MutableSpace space)
  {
    printValMB("capacity = ", space.capacity());
    printValMB("used     = ", space.used());
    long free = space.capacity() - space.used();
    printValMB("free     = ", free);
    System.out.println(alignment + space.used() * 100.0D / space.capacity() + "% used");
  }
  
  private static String alignment = "   ";
  private static final double FACTOR = 1048576.0D;
  
  private void printGen(Generation gen)
  {
    printValMB("capacity = ", gen.capacity());
    printValMB("used     = ", gen.used());
    printValMB("free     = ", gen.free());
    System.out.println(alignment + gen.used() * 100.0D / gen.capacity() + "% used");
  }
  
  private void printSpace(ContiguousSpace space)
  {
    printValMB("capacity = ", space.capacity());
    printValMB("used     = ", space.used());
    printValMB("free     = ", space.free());
    System.out.println(alignment + space.used() * 100.0D / space.capacity() + "% used");
  }
  
  private void printValMB(String title, long value)
  {
    if (value < 0L)
    {
      System.out.println(alignment + title + (value >>> 20) + " MB");
    }
    else
    {
      double mb = value / 1048576.0D;
      System.out.println(alignment + title + value + " (" + mb + "MB)");
    }
  }
  
  private void printValue(String title, long value)
  {
    System.out.println(alignment + title + value);
  }
  
  private long getFlagValue(String name, Map flagMap)
  {
    VM.Flag f = (VM.Flag)flagMap.get(name);
    if (f != null)
    {
      if (f.isBool()) {
        return f.getBool() ? 1L : 0L;
      }
      return Long.parseLong(f.getValue());
    }
    return -1L;
  }
}

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

import java.io.PrintStream;
import sun.jvm.hotspot.interpreter.Bytecodes;
import sun.jvm.hotspot.oops.ConstantPool;
import sun.jvm.hotspot.oops.ConstantPoolCache;
import sun.jvm.hotspot.oops.ConstantPoolCacheEntry;
import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.runtime.Bytes;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.utilities.Assert;

public class ByteCodeRewriter
{
  private Method method;
  private ConstantPool cpool;
  private ConstantPoolCache cpCache;
  private byte[] code;
  private Bytes bytes;
  public static final boolean DEBUG = false;
  private static final int jintSize = 4;
  
  protected void debugMessage(String message)
  {
    System.out.println(message);
  }
  
  public ByteCodeRewriter(Method method, ConstantPool cpool, byte[] code)
  {
    this.method = method;
    this.cpool = cpool;
    cpCache = cpool.getCache();
    this.code = code;
    bytes = VM.getVM().getBytes();
  }
  
  protected short getConstantPoolIndex(int rawcode, int bci)
  {
    String fmt = Bytecodes.format(rawcode);
    int cpCacheIndex;
    int cpCacheIndex;
    switch (fmt.length())
    {
    case 2: 
      cpCacheIndex = method.getBytecodeByteArg(bci); break;
    case 3: 
      cpCacheIndex = method.getBytecodeShortArg(bci); break;
    case 5: 
      if (fmt.indexOf("__") >= 0) {
        cpCacheIndex = method.getBytecodeShortArg(bci);
      } else {
        cpCacheIndex = method.getBytecodeIntArg(bci);
      }
      break;
    case 4: 
    default: 
      throw new IllegalArgumentException();
    }
    if (cpCache == null) {
      return (short)cpCacheIndex;
    }
    if (fmt.indexOf("JJJJ") >= 0) {
      return (short)cpCache.getMainEntryAt(bytes.swapInt(cpCacheIndex)).getConstantPoolIndex();
    }
    if (fmt.indexOf("JJ") >= 0) {
      return (short)cpCache.getEntryAt(0xFFFF & bytes.swapShort((short)cpCacheIndex)).getConstantPoolIndex();
    }
    if (fmt.indexOf("j") >= 0) {
      return (short)cpCache.getEntryAt(0xFF & cpCacheIndex).getConstantPoolIndex();
    }
    return (short)cpCacheIndex;
  }
  
  private static void writeShort(byte[] buf, int index, short value)
  {
    buf[index] = ((byte)(value >> 8 & 0xFF));
    buf[(index + 1)] = ((byte)(value & 0xFF));
  }
  
  public void rewrite()
  {
    int bytecode = -1;
    int hotspotcode = -1;
    int len = 0;
    for (int bci = 0; bci < code.length;)
    {
      hotspotcode = Bytecodes.codeAt(method, bci);
      bytecode = Bytecodes.javaCode(hotspotcode);
      if (Assert.ASSERTS_ENABLED)
      {
        int code_from_buffer = 0xFF & code[bci];
        Assert.that((code_from_buffer == hotspotcode) || (code_from_buffer == 202), "Unexpected bytecode found in method bytecode buffer!");
      }
      code[bci] = ((byte)(0xFF & bytecode));
      
      short cpoolIndex = 0;
      switch (bytecode)
      {
      case 178: 
      case 179: 
      case 180: 
      case 181: 
      case 182: 
      case 183: 
      case 184: 
      case 185: 
        cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
        writeShort(code, bci + 1, cpoolIndex);
        break;
      case 186: 
        cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
        writeShort(code, bci + 1, cpoolIndex);
        writeShort(code, bci + 3, (short)0);
        break;
      case 19: 
        if (hotspotcode != bytecode)
        {
          cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
          writeShort(code, bci + 1, cpoolIndex);
        }
        break;
      case 18: 
        if (hotspotcode != bytecode)
        {
          cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
          code[(bci + 1)] = ((byte)cpoolIndex);
        }
        break;
      }
      len = Bytecodes.lengthFor(bytecode);
      if (len <= 0) {
        len = Bytecodes.lengthAt(method, bci);
      }
      bci += len;
    }
  }
}

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

import java.io.PrintStream;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.Symbol;

final class ClassDump$1
  implements SystemDictionary.ClassVisitor
{
  private final ClassDump this$0;
  
  ClassDump$1(ClassDump paramClassDump) {}
  
  public void visit(Klass k)
  {
    if ((k instanceof InstanceKlass)) {
      try
      {
        ClassDump.access$000(this$0, (InstanceKlass)k);
      }
      catch (Exception e)
      {
        System.out.println(k.getName().asString());
        e.printStackTrace();
      }
    }
  }
}

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

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import sun.jvm.hotspot.debugger.AddressException;
import sun.jvm.hotspot.memory.SystemDictionary;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.Symbol;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.tools.Tool;

public class ClassDump
  extends Tool
{
  private ClassFilter classFilter;
  private String outputDirectory;
  
  public void run()
  {
    try
    {
      String filterClassName = System.getProperty("sun.jvm.hotspot.tools.jcore.filter");
      if (filterClassName != null) {
        try
        {
          Class filterClass = Class.forName(filterClassName);
          classFilter = ((ClassFilter)filterClass.newInstance());
        }
        catch (Exception exp)
        {
          System.err.println("Warning: Can not create class filter!");
        }
      }
      outputDirectory = System.getProperty("sun.jvm.hotspot.tools.jcore.outputDir");
      if (outputDirectory == null) {
        outputDirectory = ".";
      }
      SystemDictionary dict = VM.getVM().getSystemDictionary();
      dict.classesDo(new SystemDictionary.ClassVisitor()
      {
        public void visit(Klass k)
        {
          if ((k instanceof InstanceKlass)) {
            try
            {
              ClassDump.this.dumpKlass((InstanceKlass)k);
            }
            catch (Exception e)
            {
              System.out.println(k.getName().asString());
              e.printStackTrace();
            }
          }
        }
      });
    }
    catch (AddressException e)
    {
      System.err.println("Error accessing address 0x" + Long.toHexString(e.getAddress()));
      
      e.printStackTrace();
    }
  }
  
  public String getName()
  {
    return "jcore";
  }
  
  private void dumpKlass(InstanceKlass kls)
  {
    if ((classFilter != null) && (!classFilter.canInclude(kls))) {
      return;
    }
    String klassName = kls.getName().asString();
    klassName = klassName.replace('/', File.separatorChar);
    int index = klassName.lastIndexOf(File.separatorChar);
    File dir = null;
    if (index != -1)
    {
      String dirName = klassName.substring(0, index);
      dir = new File(outputDirectory, dirName);
    }
    else
    {
      dir = new File(outputDirectory);
    }
    dir.mkdirs();
    File f = new File(dir, klassName.substring(klassName.lastIndexOf(File.separatorChar) + 1) + ".class");
    try
    {
      f.createNewFile();
      OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
      try
      {
        ClassWriter cw = new ClassWriter(kls, os);
        cw.write();
      }
      finally
      {
        os.close();
      }
    }
    catch (IOException exp)
    {
      exp.printStackTrace();
    }
  }
  
  public static void main(String[] args)
  {
    ClassDump cd = new ClassDump();
    cd.start(args);
    cd.stop();
  }
}

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

import sun.jvm.hotspot.oops.InstanceKlass;

public abstract interface ClassFilter
{
  public abstract boolean canInclude(InstanceKlass paramInstanceKlass);
}

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

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import sun.jvm.hotspot.oops.CheckedExceptionElement;
import sun.jvm.hotspot.oops.ConstantPool;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.LineNumberTableElement;
import sun.jvm.hotspot.oops.LocalVariableTableElement;
import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.oops.ObjArray;
import sun.jvm.hotspot.oops.OopUtilities;
import sun.jvm.hotspot.oops.Symbol;
import sun.jvm.hotspot.oops.TypeArray;
import sun.jvm.hotspot.runtime.ClassConstants;

public class ClassWriter
  implements ClassConstants
{
  public static final boolean DEBUG = false;
  protected InstanceKlass klass;
  protected DataOutputStream dos;
  protected ConstantPool cpool;
  
  protected void debugMessage(String message)
  {
    System.out.println(message);
  }
  
  protected Map classToIndex = new HashMap();
  protected Map utf8ToIndex = new HashMap();
  protected short _sourceFileIndex;
  protected short _innerClassesIndex;
  protected short _syntheticIndex;
  protected short _deprecatedIndex;
  protected short _constantValueIndex;
  protected short _codeIndex;
  protected short _exceptionsIndex;
  protected short _lineNumberTableIndex;
  protected short _localVariableTableIndex;
  protected short _signatureIndex;
  
  protected static int extractHighShortFromInt(int val)
  {
    return val >> 16 & 0xFFFF;
  }
  
  protected static int extractLowShortFromInt(int val)
  {
    return val & 0xFFFF;
  }
  
  public ClassWriter(InstanceKlass kls, OutputStream os)
  {
    klass = kls;
    dos = new DataOutputStream(os);
    cpool = klass.getConstants();
  }
  
  public void write()
    throws IOException
  {
    dos.writeInt(-889275714);
    
    writeVersion();
    writeConstantPool();
    writeClassAccessFlags();
    writeThisClass();
    writeSuperClass();
    writeInterfaces();
    writeFields();
    writeMethods();
    writeClassAttributes();
    
    dos.flush();
  }
  
  protected void writeVersion()
    throws IOException
  {
    dos.writeShort((short)(int)klass.minorVersion());
    dos.writeShort((short)(int)klass.majorVersion());
  }
  
  protected void writeIndex(int index)
    throws IOException
  {
    if (index == 0) {
      throw new InternalError();
    }
    dos.writeShort(index);
  }
  
  protected void writeConstantPool()
    throws IOException
  {
    TypeArray tags = cpool.getTags();
    long len = tags.getLength();
    dos.writeShort((short)(int)len);
    
    int ci = 0;
    for (ci = 1; ci < len; ci++)
    {
      byte cpConstType = tags.getByteAt(ci);
      if (cpConstType == 1)
      {
        Symbol sym = cpool.getSymbolAt(ci);
        utf8ToIndex.put(sym.asString(), new Short((short)ci));
      }
      else if ((cpConstType == 5) || (cpConstType == 6))
      {
        ci++;
      }
    }
    Short sourceFileIndex = (Short)utf8ToIndex.get("SourceFile");
    _sourceFileIndex = (sourceFileIndex != null ? sourceFileIndex.shortValue() : 0);
    
    Short innerClassesIndex = (Short)utf8ToIndex.get("InnerClasses");
    _innerClassesIndex = (innerClassesIndex != null ? innerClassesIndex.shortValue() : 0);
    
    Short constantValueIndex = (Short)utf8ToIndex.get("ConstantValue");
    _constantValueIndex = (constantValueIndex != null ? constantValueIndex.shortValue() : 0);
    
    Short syntheticIndex = (Short)utf8ToIndex.get("Synthetic");
    _syntheticIndex = (syntheticIndex != null ? syntheticIndex.shortValue() : 0);
    
    Short deprecatedIndex = (Short)utf8ToIndex.get("Deprecated");
    _deprecatedIndex = (deprecatedIndex != null ? deprecatedIndex.shortValue() : 0);
    
    Short codeIndex = (Short)utf8ToIndex.get("Code");
    _codeIndex = (codeIndex != null ? codeIndex.shortValue() : 0);
    
    Short exceptionsIndex = (Short)utf8ToIndex.get("Exceptions");
    _exceptionsIndex = (exceptionsIndex != null ? exceptionsIndex.shortValue() : 0);
    
    Short lineNumberTableIndex = (Short)utf8ToIndex.get("LineNumberTable");
    _lineNumberTableIndex = (lineNumberTableIndex != null ? lineNumberTableIndex.shortValue() : 0);
    
    Short localVariableTableIndex = (Short)utf8ToIndex.get("LocalVariableTable");
    _localVariableTableIndex = (localVariableTableIndex != null ? localVariableTableIndex.shortValue() : 0);
    
    Short signatureIdx = (Short)utf8ToIndex.get("Signature");
    _signatureIndex = (signatureIdx != null ? signatureIdx.shortValue() : 0);
    for (ci = 1; ci < len; ci++)
    {
      byte cpConstType = tags.getByteAt(ci);
      switch (cpConstType)
      {
      case 1: 
        dos.writeByte(cpConstType);
        Symbol sym = cpool.getSymbolAt(ci);
        dos.writeShort((short)(int)sym.getLength());
        dos.write(sym.asByteArray());
        
        break;
      case 2: 
        throw new IllegalArgumentException("Unicode constant!");
      case 3: 
        dos.writeByte(cpConstType);
        dos.writeInt(cpool.getIntAt(ci));
        
        break;
      case 4: 
        dos.writeByte(cpConstType);
        dos.writeFloat(cpool.getFloatAt(ci));
        
        break;
      case 5: 
        dos.writeByte(cpConstType);
        long l = cpool.getLongAt(ci);
        
        ci++;
        dos.writeLong(l);
        break;
      case 6: 
        dos.writeByte(cpConstType);
        dos.writeDouble(cpool.getDoubleAt(ci));
        
        ci++;
        break;
      case 7: 
        dos.writeByte(cpConstType);
        
        Klass refKls = (Klass)cpool.getObjAt(ci);
        String klassName = refKls.getName().asString();
        
        Short s = (Short)utf8ToIndex.get(klassName);
        classToIndex.put(klassName, new Short((short)ci));
        dos.writeShort(s.shortValue());
        
        break;
      case 100: 
      case 104: 
        dos.writeByte(7);
        String klassName = cpool.getSymbolAt(ci).asString();
        
        Short s = (Short)utf8ToIndex.get(klassName);
        classToIndex.put(klassName, new Short((short)ci));
        
        dos.writeShort(s.shortValue());
        
        break;
      case 8: 
        dos.writeByte(cpConstType);
        String str = OopUtilities.stringOopToString(cpool.getObjAt(ci));
        Short s = (Short)utf8ToIndex.get(str);
        dos.writeShort(s.shortValue());
        
        break;
      case 102: 
        dos.writeByte(8);
        String val = cpool.getSymbolAt(ci).asString();
        
        Short s = (Short)utf8ToIndex.get(val);
        dos.writeShort(s.shortValue());
        
        break;
      case 9: 
      case 10: 
      case 11: 
        dos.writeByte(cpConstType);
        int value = cpool.getIntAt(ci);
        short klassIndex = (short)extractLowShortFromInt(value);
        short nameAndTypeIndex = (short)extractHighShortFromInt(value);
        dos.writeShort(klassIndex);
        dos.writeShort(nameAndTypeIndex);
        
        break;
      case 12: 
        dos.writeByte(cpConstType);
        int value = cpool.getIntAt(ci);
        short nameIndex = (short)extractLowShortFromInt(value);
        short signatureIndex = (short)extractHighShortFromInt(value);
        dos.writeShort(nameIndex);
        dos.writeShort(signatureIndex);
        
        break;
      case 15: 
        dos.writeByte(cpConstType);
        int value = cpool.getIntAt(ci);
        byte refKind = (byte)extractLowShortFromInt(value);
        short memberIndex = (short)extractHighShortFromInt(value);
        dos.writeByte(refKind);
        dos.writeShort(memberIndex);
        
        break;
      case 16: 
        dos.writeByte(cpConstType);
        int value = cpool.getIntAt(ci);
        short refIndex = (short)value;
        dos.writeShort(refIndex);
        
        break;
      case 17: 
      case 18: 
        dos.writeByte(cpConstType);
        int value = cpool.getIntAt(ci);
        short bsmIndex = (short)extractLowShortFromInt(value);
        short nameAndTypeIndex = (short)extractHighShortFromInt(value);
        dos.writeShort(bsmIndex);
        dos.writeShort(nameAndTypeIndex);
        
        break;
      default: 
        throw new InternalError("Unknown tag: " + cpConstType);
      }
    }
  }
  
  protected void writeClassAccessFlags()
    throws IOException
  {
    int flags = (int)(klass.getAccessFlags() & 0x7631);
    dos.writeShort((short)flags);
  }
  
  protected void writeThisClass()
    throws IOException
  {
    String klassName = klass.getName().asString();
    Short index = (Short)classToIndex.get(klassName);
    dos.writeShort(index.shortValue());
  }
  
  protected void writeSuperClass()
    throws IOException
  {
    Klass superKlass = klass.getSuper();
    if (superKlass != null)
    {
      String superName = superKlass.getName().asString();
      Short index = (Short)classToIndex.get(superName);
      
      dos.writeShort(index.shortValue());
    }
    else
    {
      dos.writeShort(0);
    }
  }
  
  protected void writeInterfaces()
    throws IOException
  {
    ObjArray interfaces = klass.getLocalInterfaces();
    int len = (int)interfaces.getLength();
    
    dos.writeShort((short)len);
    for (int i = 0; i < len; i++)
    {
      Klass k = (Klass)interfaces.getObjAt(i);
      Short index = (Short)classToIndex.get(k.getName().asString());
      dos.writeShort(index.shortValue());
    }
  }
  
  protected void writeFields()
    throws IOException
  {
    TypeArray fields = klass.getFields();
    int length = (int)fields.getLength();
    
    dos.writeShort((short)(length / InstanceKlass.NEXT_OFFSET));
    for (int index = 0; index < length; index += InstanceKlass.NEXT_OFFSET)
    {
      short accessFlags = fields.getShortAt(index + InstanceKlass.ACCESS_FLAGS_OFFSET);
      dos.writeShort(accessFlags & 0x50DF);
      
      short nameIndex = fields.getShortAt(index + InstanceKlass.NAME_INDEX_OFFSET);
      dos.writeShort(nameIndex);
      
      short signatureIndex = fields.getShortAt(index + InstanceKlass.SIGNATURE_INDEX_OFFSET);
      dos.writeShort(signatureIndex);
      
      short fieldAttributeCount = 0;
      boolean hasSyn = hasSyntheticAttribute(accessFlags);
      if (hasSyn) {
        fieldAttributeCount = (short)(fieldAttributeCount + 1);
      }
      short initvalIndex = fields.getShortAt(index + InstanceKlass.INITVAL_INDEX_OFFSET);
      if (initvalIndex != 0) {
        fieldAttributeCount = (short)(fieldAttributeCount + 1);
      }
      short genSigIndex = fields.getShortAt(index + InstanceKlass.GENERIC_SIGNATURE_INDEX_OFFSET);
      if (genSigIndex != 0) {
        fieldAttributeCount = (short)(fieldAttributeCount + 1);
      }
      dos.writeShort(fieldAttributeCount);
      if (hasSyn) {
        writeSynthetic();
      }
      if (initvalIndex != 0)
      {
        writeIndex(_constantValueIndex);
        dos.writeInt(2);
        dos.writeShort(initvalIndex);
      }
      if (genSigIndex != 0)
      {
        writeIndex(_signatureIndex);
        dos.writeInt(2);
        dos.writeShort(genSigIndex);
      }
    }
  }
  
  protected boolean isSynthetic(short accessFlags)
  {
    return (accessFlags & 0x1000) != 0;
  }
  
  protected boolean hasSyntheticAttribute(short accessFlags)
  {
    return (isSynthetic(accessFlags)) && (_syntheticIndex != 0);
  }
  
  protected void writeSynthetic()
    throws IOException
  {
    writeIndex(_syntheticIndex);
    dos.writeInt(0);
  }
  
  protected void writeMethods()
    throws IOException
  {
    ObjArray methods = klass.getMethods();
    int len = (int)methods.getLength();
    
    dos.writeShort((short)len);
    for (int m = 0; m < len; m++) {
      writeMethod((Method)methods.getObjAt(m));
    }
  }
  
  protected void writeMethod(Method m)
    throws IOException
  {
    long accessFlags = m.getAccessFlags();
    dos.writeShort((short)(int)(accessFlags & 0x1DFF));
    dos.writeShort((short)(int)m.getNameIndex());
    dos.writeShort((short)(int)m.getSignatureIndex());
    
    boolean isNative = (accessFlags & 0x100) != 0L;
    boolean isAbstract = (accessFlags & 0x400) != 0L;
    
    short methodAttributeCount = 0;
    
    boolean hasSyn = hasSyntheticAttribute((short)(int)accessFlags);
    if (hasSyn) {
      methodAttributeCount = (short)(methodAttributeCount + 1);
    }
    boolean hasCheckedExceptions = m.hasCheckedExceptions();
    if (hasCheckedExceptions) {
      methodAttributeCount = (short)(methodAttributeCount + 1);
    }
    boolean isCodeAvailable = (!isNative) && (!isAbstract);
    if (isCodeAvailable) {
      methodAttributeCount = (short)(methodAttributeCount + 1);
    }
    boolean isGeneric = m.getGenericSignature() != null;
    if (isGeneric) {
      methodAttributeCount = (short)(methodAttributeCount + 1);
    }
    dos.writeShort(methodAttributeCount);
    if (hasSyn) {
      writeSynthetic();
    }
    if (isCodeAvailable)
    {
      byte[] code = m.getByteCode();
      short codeAttrCount = 0;
      int codeSize = 8 + code.length + 2 + 2;
      
      TypeArray exceptionTable = m.getExceptionTable();
      int exceptionTableLen = (int)exceptionTable.getLength();
      if (exceptionTableLen != 0) {
        codeSize += exception
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