com-sun-tools-visualvm-attach

16:33:44.069 INFO  jd.cli.Main - Decompiling com-sun-tools-visualvm-attach.jar
package com.sun.tools.visualvm.attach;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.tools.attach.AttachModel;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.tools.attach.HotSpotVirtualMachine;

public class AttachModelImpl
  extends AttachModel
{
  static final String LIVE_OBJECTS_OPTION = "-live";
  static final String ALL_OBJECTS_OPTION = "-all";
  static final Logger LOGGER = Logger.getLogger(AttachModelImpl.class.getName());
  String pid;
  HotSpotVirtualMachine vm;
  
  AttachModelImpl(Application app)
  {
    pid = Integer.toString(app.getPid());
  }
  
  public synchronized Properties getSystemProperties()
  {
    try
    {
      return getVirtualMachine().getSystemProperties();
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "getSystemProperties", ex);
    }
    return null;
  }
  
  public synchronized boolean takeHeapDump(String fileName)
  {
    try
    {
      InputStream in = getVirtualMachine().dumpHeap(new Object[] { fileName, "-live" });
      String out = readToEOF(in);
      if (out.length() > 0) {
        LOGGER.log(Level.INFO, "takeHeapDump", out);
      }
      return true;
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "takeHeapDump", ex);
    }
    return false;
  }
  
  public synchronized String takeThreadDump()
  {
    try
    {
      InputStream in = getVirtualMachine().remoteDataDump(new Object[] { "-l" });
      return readToEOF(in);
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "takeThreadDump", ex);
    }
    return null;
  }
  
  public synchronized String printFlag(String name)
  {
    try
    {
      InputStream in = getVirtualMachine().printFlag(name);
      return readToEOF(in);
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "printFlag", ex);
    }
    return null;
  }
  
  public synchronized void setFlag(String name, String value)
  {
    try
    {
      InputStream in = getVirtualMachine().setFlag(name, value);
      String out = readToEOF(in);
      if (out.length() > 0) {
        LOGGER.log(Level.INFO, "setFlag", out);
      }
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "setFlag", ex);
    }
  }
  
  public synchronized HeapHistogramImpl takeHeapHistogram()
  {
    try
    {
      InputStream in = getVirtualMachine().heapHisto(new Object[] { "-all" });
      HeapHistogramImpl h = new HeapHistogramImpl(in);
      in.close();
      return h;
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "takeHeapHistogram", ex);
    }
    return null;
  }
  
  HotSpotVirtualMachine getVirtualMachine()
    throws IOException
  {
    if (vm == null) {
      try
      {
        vm = ((HotSpotVirtualMachine)VirtualMachine.attach(pid));
      }
      catch (Exception x)
      {
        throw new IOException(x.getLocalizedMessage(), x);
      }
    }
    return vm;
  }
  
  private String readToEOF(InputStream in)
    throws IOException
  {
    StringBuffer buffer = new StringBuffer(1024);
    byte[] b = new byte['?'];
    int n;
    do
    {
      n = in.read(b);
      if (n > 0)
      {
        String s = new String(b, 0, n, "UTF-8");
        
        buffer.append(s);
      }
    } while (n > 0);
    in.close();
    return buffer.toString();
  }
  
  protected void finalize()
    throws Throwable
  {
    vm.detach();
    super.finalize();
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.AttachModelImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.model.AbstractModelProvider;
import com.sun.tools.visualvm.host.Host;
import com.sun.tools.visualvm.tools.attach.AttachModel;
import com.sun.tools.visualvm.tools.jvmstat.JvmJvmstatModel;
import com.sun.tools.visualvm.tools.jvmstat.JvmJvmstatModelFactory;
import org.openide.util.Utilities;

public final class AttachModelProvider
  extends AbstractModelProvider<AttachModel, Application>
{
  public AttachModel createModelFor(Application app)
  {
    JvmJvmstatModel jvmstat;
    String pid;
    if (Host.LOCALHOST.equals(app.getHost()))
    {
      jvmstat = JvmJvmstatModelFactory.getJvmstatModelFor(app);
      if ((jvmstat != null) && (jvmstat.isAttachable()))
      {
        if (Utilities.isWindows())
        {
          Boolean this64bitArch = is64BitArchitecture();
          Boolean app64bitArch = is64BitArchitecture(jvmstat);
          if ((this64bitArch != null) && (app64bitArch != null) && 
            (!this64bitArch.equals(app64bitArch))) {
            return null;
          }
        }
        pid = String.valueOf(app.getPid());
        for (VirtualMachineDescriptor descr : VirtualMachine.list()) {
          if (pid.equals(descr.id()))
          {
            String vmName = jvmstat.getVmName();
            if (vmName != null)
            {
              if ("BEA JRockit(R)".equals(vmName)) {
                return new JRockitAttachModelImpl(app);
              }
              if ("Oracle JRockit(R)".equals(vmName)) {
                return new OracleJRockitAttachModelImpl(app);
              }
            }
            return new AttachModelImpl(app);
          }
        }
      }
    }
    return null;
  }
  
  private static Boolean is64BitArchitecture(JvmJvmstatModel jvmstat)
  {
    String name = jvmstat.getVmName();
    if (name != null) {
      return Boolean.valueOf(name.toLowerCase().contains("64-bit"));
    }
    return null;
  }
  
  private static Boolean is64BitArchitecture()
  {
    String thisArch = System.getProperty("sun.arch.data.model");
    if (thisArch != null) {
      return Boolean.valueOf("64".equals(thisArch));
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.AttachModelProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import com.sun.tools.visualvm.application.jvm.HeapHistogram.ClassInfo;
import java.io.PrintStream;
import java.util.Map;
import java.util.Scanner;

class HeapHistogramImpl$ClassInfoImpl
  extends HeapHistogram.ClassInfo
{
  long instances;
  long bytes;
  String name;
  boolean permGen;
  
  HeapHistogramImpl$ClassInfoImpl() {}
  
  HeapHistogramImpl$ClassInfoImpl(Scanner sc)
  {
    sc.next();
    instances = sc.nextLong();
    bytes = sc.nextLong();
    String jvmName = sc.next();
    permGen = (jvmName.charAt(0) == '<');
    name = convertJVMName(jvmName);
  }
  
  public String getName()
  {
    return name;
  }
  
  public long getInstancesCount()
  {
    return instances;
  }
  
  public long getBytes()
  {
    return bytes;
  }
  
  public int hashCode()
  {
    return getName().hashCode();
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof ClassInfoImpl)) {
      return getName().equals(((ClassInfoImpl)obj).getName());
    }
    return false;
  }
  
  private boolean isPermGen()
  {
    return permGen;
  }
  
  String convertJVMName(String jvmName)
  {
    String name = null;
    int index = jvmName.lastIndexOf('[');
    if (index != -1)
    {
      switch (jvmName.charAt(index + 1))
      {
      case 'Z': 
        name = "boolean";
        break;
      case 'C': 
        name = "char";
        break;
      case 'B': 
        name = "byte";
        break;
      case 'S': 
        name = "short";
        break;
      case 'I': 
        name = "int";
        break;
      case 'J': 
        name = "long";
        break;
      case 'F': 
        name = "float";
        break;
      case 'D': 
        name = "double";
        break;
      case 'L': 
        name = jvmName.substring(index + 2, jvmName.length() - 1);
        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: 
        System.err.println("Uknown name " + jvmName);
        name = jvmName;
      }
      for (int i = 0; i <= index; i++) {
        name = name + "[]";
      }
    }
    else if (isPermGen())
    {
      name = (String)HeapHistogramImpl.access$100().get(jvmName);
    }
    if (name == null) {
      name = jvmName;
    }
    return name.intern();
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.HeapHistogramImpl.ClassInfoImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import com.sun.tools.visualvm.application.jvm.HeapHistogram;
import com.sun.tools.visualvm.application.jvm.HeapHistogram.ClassInfo;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class HeapHistogramImpl
  extends HeapHistogram
{
  private static final String BOOLEAN_TEXT = "boolean";
  private static final String CHAR_TEXT = "char";
  private static final String BYTE_TEXT = "byte";
  private static final String SHORT_TEXT = "short";
  private static final String INT_TEXT = "int";
  private static final String LONG_TEXT = "long";
  private static final String FLOAT_TEXT = "float";
  private static final String DOUBLE_TEXT = "double";
  private static final String VOID_TEXT = "void";
  private static final char BOOLEAN_CODE = 'Z';
  private static final char CHAR_CODE = 'C';
  private static final char BYTE_CODE = 'B';
  private static final char SHORT_CODE = 'S';
  private static final char INT_CODE = 'I';
  private static final char LONG_CODE = 'J';
  private static final char FLOAT_CODE = 'F';
  private static final char DOUBLE_CODE = 'D';
  private static final char OBJECT_CODE = 'L';
  private static final Map<String, String> permGenNames = new HashMap();
  Set<HeapHistogram.ClassInfo> classes;
  Set<HeapHistogram.ClassInfo> permGenClasses;
  Date time;
  long totalBytes;
  long totalInstances;
  long totalHeapBytes;
  long totalHeapInstances;
  long totalPermGenBytes;
  long totalPermgenInstances;
  
  static
  {
    permGenNames.put("<methodKlass>", "Read-Write Method Metadata");
    permGenNames.put("<constMethodKlass>", "Read-Only Method Metadata");
    permGenNames.put("<methodDataKlass>", "Method Profiling Information");
    permGenNames.put("<constantPoolKlass>", "Constant Pool Metadata");
    permGenNames.put("<constantPoolCacheKlass>", "Class Resolution Optimization Metadata");
    permGenNames.put("<symbolKlass>", "VM Symbol Metadata");
    permGenNames.put("<compiledICHolderKlass>", "Inline Cache Metadata");
    permGenNames.put("<instanceKlassKlass>", "Instance Class Metadata");
    permGenNames.put("<objArrayKlassKlass>", "Object Array Class Metadata");
    permGenNames.put("<typeArrayKlassKlass>", "Scalar Array Class Metadata");
    permGenNames.put("<klassKlass>", "Base Class Metadata");
    permGenNames.put("<arrayKlassKlass>", "Base Array Class Metadata");
  }
  
  HeapHistogramImpl(InputStream in)
  {
    Map<String, ClassInfoImpl> classesMap = new HashMap(1024);
    Map<String, ClassInfoImpl> permGenMap = new HashMap(1024);
    time = new Date();
    Scanner sc = new Scanner(in, "UTF-8");
    sc.useRadix(10);
    sc.nextLine();
    sc.nextLine();
    sc.skip("-+");
    sc.nextLine();
    while (sc.hasNext("[0-9]+:"))
    {
      ClassInfoImpl newClInfo = new ClassInfoImpl(sc);
      if (newClInfo.isPermGen())
      {
        storeClassInfo(newClInfo, permGenMap);
        totalPermGenBytes += newClInfo.getBytes();
        totalPermgenInstances += newClInfo.getInstancesCount();
      }
      else
      {
        storeClassInfo(newClInfo, classesMap);
        totalHeapBytes += newClInfo.getBytes();
        totalHeapInstances += newClInfo.getInstancesCount();
      }
    }
    sc.next("Total");
    totalInstances = sc.nextLong();
    totalBytes = sc.nextLong();
    classes = new HashSet(classesMap.values());
    permGenClasses = new HashSet(permGenMap.values());
  }
  
  void storeClassInfo(ClassInfoImpl newClInfo, Map<String, ClassInfoImpl> map)
  {
    ClassInfoImpl oldClInfo = (ClassInfoImpl)map.get(newClInfo.getName());
    if (oldClInfo == null)
    {
      map.put(newClInfo.getName(), newClInfo);
    }
    else
    {
      bytes += newClInfo.getBytes();
      instances += newClInfo.getInstancesCount();
    }
  }
  
  public Date getTime()
  {
    return (Date)time.clone();
  }
  
  public Set<HeapHistogram.ClassInfo> getHeapHistogram()
  {
    return classes;
  }
  
  public long getTotalInstances()
  {
    return totalInstances;
  }
  
  public long getTotalBytes()
  {
    return totalBytes;
  }
  
  public long getTotalHeapInstances()
  {
    return totalHeapInstances;
  }
  
  public long getTotalHeapBytes()
  {
    return totalHeapBytes;
  }
  
  public Set<HeapHistogram.ClassInfo> getPermGenHistogram()
  {
    return permGenClasses;
  }
  
  public long getTotalPerGenInstances()
  {
    return totalPermgenInstances;
  }
  
  public long getTotalPermGenHeapBytes()
  {
    return totalPermGenBytes;
  }
  
  HeapHistogramImpl() {}
  
  static class ClassInfoImpl
    extends HeapHistogram.ClassInfo
  {
    long instances;
    long bytes;
    String name;
    boolean permGen;
    
    ClassInfoImpl() {}
    
    ClassInfoImpl(Scanner sc)
    {
      sc.next();
      instances = sc.nextLong();
      bytes = sc.nextLong();
      String jvmName = sc.next();
      permGen = (jvmName.charAt(0) == '<');
      name = convertJVMName(jvmName);
    }
    
    public String getName()
    {
      return name;
    }
    
    public long getInstancesCount()
    {
      return instances;
    }
    
    public long getBytes()
    {
      return bytes;
    }
    
    public int hashCode()
    {
      return getName().hashCode();
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof ClassInfoImpl)) {
        return getName().equals(((ClassInfoImpl)obj).getName());
      }
      return false;
    }
    
    private boolean isPermGen()
    {
      return permGen;
    }
    
    String convertJVMName(String jvmName)
    {
      String name = null;
      int index = jvmName.lastIndexOf('[');
      if (index != -1)
      {
        switch (jvmName.charAt(index + 1))
        {
        case 'Z': 
          name = "boolean";
          break;
        case 'C': 
          name = "char";
          break;
        case 'B': 
          name = "byte";
          break;
        case 'S': 
          name = "short";
          break;
        case 'I': 
          name = "int";
          break;
        case 'J': 
          name = "long";
          break;
        case 'F': 
          name = "float";
          break;
        case 'D': 
          name = "double";
          break;
        case 'L': 
          name = jvmName.substring(index + 2, jvmName.length() - 1);
          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: 
          System.err.println("Uknown name " + jvmName);
          name = jvmName;
        }
        for (int i = 0; i <= index; i++) {
          name = name + "[]";
        }
      }
      else if (isPermGen())
      {
        name = (String)HeapHistogramImpl.permGenNames.get(jvmName);
      }
      if (name == null) {
        name = jvmName;
      }
      return name.intern();
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.HeapHistogramImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import com.sun.tools.visualvm.tools.attach.AttachModelFactory;
import org.openide.modules.ModuleInstall;

final class Installer
  extends ModuleInstall
{
  public void restored()
  {
    AttachModelFactory.getDefault().registerProvider(new AttachModelProvider());
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.Installer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import com.sun.tools.visualvm.application.Application;

public class JRockitAttachModelImpl
  extends OracleJRockitAttachModelImpl
{
  JRockitAttachModelImpl(Application app)
  {
    super(app);
  }
  
  public synchronized boolean takeHeapDump(String fileName)
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.JRockitAttachModelImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import java.util.Scanner;

class JRockitHeapHistogramImpl$JRockitClassInfoImpl
  extends HeapHistogramImpl.ClassInfoImpl
{
  JRockitHeapHistogramImpl$JRockitClassInfoImpl(Scanner sc)
  {
    sc.next();
    bytes = computeBytes(sc.next());
    instances = sc.nextLong();
    sc.next();
    String jvmName = sc.next();
    name = convertJVMName(jvmName.replace('/', '.'));
  }
  
  private long computeBytes(String size)
  {
    String multi = size.substring(size.length() - 1);
    long bytes = Long.parseLong(size.substring(0, size.length() - 1));
    if ("K".equalsIgnoreCase(multi)) {
      bytes *= 1024L;
    } else if ("M".equalsIgnoreCase(multi)) {
      bytes *= 1048576L;
    } else if ("G".equalsIgnoreCase(multi)) {
      bytes *= 1073741824L;
    }
    return bytes;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.JRockitHeapHistogramImpl.JRockitClassInfoImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import java.io.InputStream;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class JRockitHeapHistogramImpl
  extends HeapHistogramImpl
{
  JRockitHeapHistogramImpl(InputStream in)
  {
    Map<String, HeapHistogramImpl.ClassInfoImpl> classesMap = new HashMap(1024);
    time = new Date();
    Scanner sc = new Scanner(in, "UTF-8");
    sc.useRadix(10);
    sc.nextLine();
    sc.skip("-+");
    sc.nextLine();
    while (sc.hasNext("[0-9]+\\.[0-9]%"))
    {
      JRockitClassInfoImpl newClInfo = new JRockitClassInfoImpl(sc);
      storeClassInfo(newClInfo, classesMap);
      totalHeapBytes += newClInfo.getBytes();
      totalHeapInstances += newClInfo.getInstancesCount();
    }
    totalInstances = totalHeapInstances;
    totalBytes = totalHeapBytes;
    classes = new HashSet(classesMap.values());
    permGenClasses = Collections.EMPTY_SET;
  }
  
  static class JRockitClassInfoImpl
    extends HeapHistogramImpl.ClassInfoImpl
  {
    JRockitClassInfoImpl(Scanner sc)
    {
      sc.next();
      bytes = computeBytes(sc.next());
      instances = sc.nextLong();
      sc.next();
      String jvmName = sc.next();
      name = convertJVMName(jvmName.replace('/', '.'));
    }
    
    private long computeBytes(String size)
    {
      String multi = size.substring(size.length() - 1);
      long bytes = Long.parseLong(size.substring(0, size.length() - 1));
      if ("K".equalsIgnoreCase(multi)) {
        bytes *= 1024L;
      } else if ("M".equalsIgnoreCase(multi)) {
        bytes *= 1048576L;
      } else if ("G".equalsIgnoreCase(multi)) {
        bytes *= 1073741824L;
      }
      return bytes;
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.JRockitHeapHistogramImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.attach;

import com.sun.tools.visualvm.application.Application;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.tools.attach.HotSpotVirtualMachine;

public class OracleJRockitAttachModelImpl
  extends AttachModelImpl
{
  OracleJRockitAttachModelImpl(Application app)
  {
    super(app);
  }
  
  public synchronized HeapHistogramImpl takeHeapHistogram()
  {
    try
    {
      InputStream in = getVirtualMachine().heapHisto(new Object[] { "-all" });
      HeapHistogramImpl h = new JRockitHeapHistogramImpl(in);
      in.close();
      return h;
    }
    catch (IOException ex)
    {
      LOGGER.log(Level.INFO, "takeHeapHistogram", ex);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.attach.OracleJRockitAttachModelImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

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-2017. Infinite Loop Ltd