com-sun-tools-visualvm-jvm

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

import com.sun.tools.visualvm.application.jvm.JvmFactory;
import org.openide.modules.ModuleInstall;

public class Installer
  extends ModuleInstall
{
  public void restored()
  {
    JvmFactory.getDefault().registerProvider(new JvmProvider());
    JvmFactory.getDefault().registerProvider(new JRockitJvmProvider());
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatModel;

public class JRockitJVMImpl
  extends JVMImpl
{
  JRockitJVMImpl(Application app, JvmstatModel jvms)
  {
    super(app, jvms);
  }
  
  JRockitJVMImpl(Application app)
  {
    super(app);
  }
  
  public boolean is14()
  {
    String ver = getVmVersion();
    if ((ver != null) && (ver.contains("1.4.2"))) {
      return true;
    }
    return false;
  }
  
  public boolean is15()
  {
    String ver = getVmVersion();
    if ((ver != null) && (ver.contains("1.5.0"))) {
      return true;
    }
    return false;
  }
  
  public boolean is16()
  {
    String ver = getVmVersion();
    if ((ver != null) && (ver.contains("1.6.0"))) {
      return true;
    }
    return false;
  }
  
  public boolean is17()
  {
    return false;
  }
  
  public boolean isDumpOnOOMEnabled()
  {
    return false;
  }
  
  public boolean isGetSystemPropertiesSupported()
  {
    return ((is16()) && (getAttach() != null)) || (jmxSupport.getRuntime() != null);
  }
  
  public boolean isDumpOnOOMEnabledSupported()
  {
    return false;
  }
  
  public boolean isTakeHeapDumpSupported()
  {
    return false;
  }
  
  public boolean isTakeThreadDumpSupported()
  {
    if (getAttach() != null) {
      return true;
    }
    JmxModel jmx = getJmxModel();
    if (jmx == null) {
      return false;
    }
    return jmx.isTakeThreadDumpSupported();
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModel.ConnectionState;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeansFactory;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatModel;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatModelFactory;
import java.lang.management.RuntimeMXBean;

public class JRockitJvmProvider
  extends JvmProvider
{
  private static final String JROCKIT_VM_NAME = "BEA JRockit(R)";
  private static final String VM_NAME = "java.property.java.vm.name";
  
  public Jvm createModelFor(Application app)
  {
    Jvm jvm = null;
    JvmstatModel jvmstat = JvmstatModelFactory.getJvmstatFor(app);
    if (jvmstat != null)
    {
      String vmName = jvmstat.findByName("java.property.java.vm.name");
      if ("BEA JRockit(R)".equals(vmName)) {
        jvm = new JRockitJVMImpl(app, jvmstat);
      }
    }
    else
    {
      JmxModel jmxModel = JmxModelFactory.getJmxModelFor(app);
      if ((jmxModel != null) && (jmxModel.getConnectionState() == JmxModel.ConnectionState.CONNECTED))
      {
        JvmMXBeans mxbeans = JvmMXBeansFactory.getJvmMXBeans(jmxModel);
        if (mxbeans != null)
        {
          RuntimeMXBean runtime = mxbeans.getRuntimeMXBean();
          if ((runtime != null) && ("BEA JRockit(R)".equals(runtime.getVmName()))) {
            jvm = new JRockitJVMImpl(app);
          }
        }
      }
    }
    return jvm;
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.MonitoredData;
import com.sun.tools.visualvm.application.jvm.MonitoredDataListener;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.heapdump.HeapDumpSupport;
import com.sun.tools.visualvm.host.Host;
import com.sun.tools.visualvm.threaddump.ThreadDumpSupport;
import com.sun.tools.visualvm.tools.attach.AttachModel;
import com.sun.tools.visualvm.tools.attach.AttachModelFactory;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import com.sun.tools.visualvm.tools.jvmstat.JvmJvmstatModel;
import com.sun.tools.visualvm.tools.jvmstat.JvmJvmstatModelFactory;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatListener;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatModel;
import com.sun.tools.visualvm.tools.sa.SaModel;
import com.sun.tools.visualvm.tools.sa.SaModelFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.openide.util.NbBundle;

public class JVMImpl
  extends Jvm
  implements JvmstatListener
{
  private static final String HEAP_DUMP_ON_OOME = "HeapDumpOnOutOfMemoryError";
  private static final String HEAP_DUMP_PATH = "HeapDumpPath";
  Application application;
  Boolean isDumpOnOOMEnabled;
  JvmstatModel monitoredVm;
  JvmJvmstatModel jvmstatModel;
  Set<MonitoredDataListener> listeners;
  JmxSupport jmxSupport;
  private boolean staticDataInitialized;
  private Object staticDataLock = new Object();
  private String commandLine;
  private String jvmArgs;
  private String jvmFlags;
  private String mainArgs;
  private String mainClass;
  private String vmVersion;
  private String javaVersion;
  private String javaHome;
  private String vmInfo;
  private String vmName;
  private String vmVendor;
  
  JVMImpl(Application app, JvmstatModel jvms)
  {
    application = app;
    monitoredVm = jvms;
    jvmstatModel = JvmJvmstatModelFactory.getJvmstatModelFor(app);
    jmxSupport = new JmxSupport(app, this);
    listeners = new HashSet();
  }
  
  JVMImpl(Application app)
  {
    application = app;
    jmxSupport = new JmxSupport(app, this);
    listeners = new HashSet();
  }
  
  public boolean isAttachable()
  {
    if (jvmstatModel != null)
    {
      if (!jvmstatModel.isAttachable()) {
        return false;
      }
      return getAttach() != null;
    }
    return false;
  }
  
  public boolean isBasicInfoSupported()
  {
    return true;
  }
  
  public String getCommandLine()
  {
    initStaticData();
    return commandLine;
  }
  
  public String getJvmArgs()
  {
    initStaticData();
    return jvmArgs;
  }
  
  public String getJvmFlags()
  {
    initStaticData();
    return jvmFlags;
  }
  
  public String getMainArgs()
  {
    initStaticData();
    return mainArgs;
  }
  
  public String getMainClass()
  {
    initStaticData();
    return mainClass;
  }
  
  public String getVmVersion()
  {
    initStaticData();
    return vmVersion;
  }
  
  public String getJavaVersion()
  {
    initStaticData();
    if (javaVersion != null) {
      return javaVersion;
    }
    return vmVersion;
  }
  
  public String getJavaHome()
  {
    initStaticData();
    return javaHome;
  }
  
  public String getVmInfo()
  {
    initStaticData();
    return vmInfo;
  }
  
  public String getVmName()
  {
    initStaticData();
    return vmName;
  }
  
  public String getVmVendor()
  {
    initStaticData();
    return vmVendor;
  }
  
  public boolean is14()
  {
    String ver = getVmVersion();
    if ((ver != null) && (ver.startsWith("1.4."))) {
      return true;
    }
    return false;
  }
  
  public boolean is15()
  {
    String ver = getJavaVersion();
    if ((ver != null) && (ver.startsWith("1.5."))) {
      return true;
    }
    return false;
  }
  
  public boolean is16()
  {
    String ver = getJavaVersion();
    if ((ver != null) && ((ver.startsWith("1.6.")) || (ver.startsWith("10.")) || (ver.startsWith("11.")))) {
      return true;
    }
    return false;
  }
  
  public boolean is17()
  {
    String ver = getJavaVersion();
    if ((ver != null) && ((ver.startsWith("1.7.")) || (ver.startsWith("12.")) || (ver.startsWith("13.")) || (ver.startsWith("14.")))) {
      return true;
    }
    return false;
  }
  
  public boolean isDumpOnOOMEnabled()
  {
    if (isDumpOnOOMEnabled == null)
    {
      AttachModel attach = getAttach();
      String args = null;
      if (attach != null) {
        args = attach.printFlag("HeapDumpOnOutOfMemoryError");
      }
      if (args == null)
      {
        JmxModel jmx = getJmxModel();
        if ((jmx != null) && (jmx.isTakeHeapDumpSupported()) && (!jmxSupport.isReadOnlyConnection()))
        {
          String value = jmx.getFlagValue("HeapDumpOnOutOfMemoryError");
          isDumpOnOOMEnabled = Boolean.valueOf(value);
          return isDumpOnOOMEnabled.booleanValue();
        }
      }
      if ((args == null) && (monitoredVm != null)) {
        args = getJvmFlags().concat(getJvmArgs());
      }
      if ((args != null) && (args.contains("-XX:+HeapDumpOnOutOfMemoryError"))) {
        isDumpOnOOMEnabled = Boolean.TRUE;
      } else {
        isDumpOnOOMEnabled = Boolean.FALSE;
      }
    }
    return isDumpOnOOMEnabled.booleanValue();
  }
  
  public void addMonitoredDataListener(MonitoredDataListener l)
  {
    synchronized (listeners)
    {
      if (listeners.add(l)) {
        if (monitoredVm != null)
        {
          if (jmxSupport != null) {
            jmxSupport.disableTimer();
          }
          monitoredVm.addJvmstatListener(this);
        }
        else if (jmxSupport != null)
        {
          jmxSupport.initTimer();
        }
      }
    }
  }
  
  public void removeMonitoredDataListener(MonitoredDataListener l)
  {
    synchronized (listeners)
    {
      if ((listeners.remove(l)) && 
        (listeners.isEmpty())) {
        if (monitoredVm != null) {
          monitoredVm.removeJvmstatListener(this);
        } else if (jmxSupport != null) {
          jmxSupport.disableTimer();
        }
      }
    }
  }
  
  public boolean isMonitoringSupported()
  {
    return (isClassMonitoringSupported()) || (isThreadMonitoringSupported()) || (isMemoryMonitoringSupported());
  }
  
  public boolean isClassMonitoringSupported()
  {
    return (monitoredVm != null) || (jmxSupport.getRuntime() != null);
  }
  
  public boolean isThreadMonitoringSupported()
  {
    return ((!is14()) && (monitoredVm != null)) || (jmxSupport.getRuntime() != null);
  }
  
  public boolean isMemoryMonitoringSupported()
  {
    return (monitoredVm != null) || (jmxSupport.getRuntime() != null);
  }
  
  public boolean isGetSystemPropertiesSupported()
  {
    return (getAttach() != null) || (jmxSupport.getRuntime() != null) || (getSAAgent() != null);
  }
  
  public Properties getSystemProperties()
  {
    AttachModel attach = getAttach();
    Properties prop = null;
    if (attach != null) {
      prop = attach.getSystemProperties();
    }
    if (prop != null) {
      return prop;
    }
    JmxModel jmx = getJmxModel();
    if (jmx != null) {
      prop = jmx.getSystemProperties();
    }
    if (prop != null) {
      return prop;
    }
    SaModel saAgent = getSAAgent();
    if (saAgent != null) {
      return saAgent.getSystemProperties();
    }
    if (!isGetSystemPropertiesSupported()) {
      throw new UnsupportedOperationException();
    }
    return null;
  }
  
  public boolean isDumpOnOOMEnabledSupported()
  {
    if (getAttach() != null) {
      return true;
    }
    JmxModel jmx = getJmxModel();
    if ((Host.LOCALHOST.equals(application.getHost())) && (jmx != null) && (jmx.isTakeHeapDumpSupported())) {
      return true;
    }
    return false;
  }
  
  public synchronized void setDumpOnOOMEnabled(boolean enabled)
  {
    if (!isDumpOnOOMEnabledSupported()) {
      throw new UnsupportedOperationException();
    }
    AttachModel attach = getAttach();
    if (attach != null)
    {
      attach.setFlag("HeapDumpOnOutOfMemoryError", enabled ? "1" : "0");
      if (enabled) {
        attach.setFlag("HeapDumpPath", application.getStorage().getDirectory().getAbsolutePath());
      }
    }
    else
    {
      JmxModel jmx = getJmxModel();
      jmx.setFlagValue("HeapDumpOnOutOfMemoryError", Boolean.toString(enabled));
      if (enabled) {
        jmx.setFlagValue("HeapDumpPath", application.getStorage().getDirectory().getAbsolutePath());
      }
    }
    Boolean oldVlue = isDumpOnOOMEnabled;
    isDumpOnOOMEnabled = Boolean.valueOf(enabled);
    firePropertyChange("prop_oome", oldVlue, isDumpOnOOMEnabled);
  }
  
  public boolean isTakeHeapDumpSupported()
  {
    if (getAttach() != null) {
      return true;
    }
    JmxModel jmx = getJmxModel();
    if ((Host.LOCALHOST.equals(application.getHost())) && (jmx != null) && (jmx.isTakeHeapDumpSupported())) {
      return true;
    }
    return false;
  }
  
  public File takeHeapDump()
    throws IOException
  {
    if (!isTakeHeapDumpSupported()) {
      throw new UnsupportedOperationException();
    }
    File snapshotDir = application.getStorage().getDirectory();
    String name = HeapDumpSupport.getInstance().getCategory().createFileName();
    File dumpFile = new File(snapshotDir, name);
    AttachModel attach = getAttach();
    if (attach != null)
    {
      if (attach.takeHeapDump(dumpFile.getAbsolutePath())) {
        return dumpFile;
      }
      return null;
    }
    if (getJmxModel().takeHeapDump(dumpFile.getAbsolutePath())) {
      return dumpFile;
    }
    return null;
  }
  
  public boolean isTakeThreadDumpSupported()
  {
    if (getAttach() != null) {
      return true;
    }
    JmxModel jmx = getJmxModel();
    if ((jmx != null) && (jmx.isTakeThreadDumpSupported())) {
      return true;
    }
    return getSAAgent() != null;
  }
  
  public File takeThreadDump()
    throws IOException
  {
    AttachModel attach = getAttach();
    String threadDump = null;
    if (attach != null) {
      threadDump = attach.takeThreadDump();
    }
    if (threadDump == null)
    {
      JmxModel jmx = getJmxModel();
      if (jmx != null) {
        threadDump = jmx.takeThreadDump();
      }
    }
    if (threadDump == null)
    {
      SaModel sa = getSAAgent();
      if (sa != null) {
        threadDump = sa.takeThreadDump();
      }
    }
    if (threadDump == null)
    {
      if (!isTakeThreadDumpSupported()) {
        throw new UnsupportedOperationException();
      }
      threadDump = NbBundle.getMessage(JVMImpl.class, "MSG_ThreadDumpfailed");
    }
    File snapshotDir = application.getStorage().getDirectory();
    String name = ThreadDumpSupport.getInstance().getCategory().createFileName();
    File dumpFile = new File(snapshotDir, name);
    OutputStream os = new FileOutputStream(dumpFile);
    os.write(threadDump.getBytes("UTF-8"));
    os.close();
    return dumpFile;
  }
  
  public boolean isCpuMonitoringSupported()
  {
    return jmxSupport.hasProcessCPUTimeAttribute();
  }
  
  public boolean isCollectionTimeSupported()
  {
    Collection gcList = jmxSupport.getGarbageCollectorMXBeans();
    return (gcList != null) && (!gcList.isEmpty());
  }
  
  public MonitoredData getMonitoredData()
  {
    if (application.getState() == 1)
    {
      if (monitoredVm != null) {
        return new MonitoredDataImpl(this, jvmstatModel, jmxSupport);
      }
      if (jmxSupport != null)
      {
        JvmMXBeans jmx = jmxSupport.getJvmMXBeans();
        if (jmx != null) {
          return new MonitoredDataImpl(this, jmxSupport, jmx);
        }
      }
    }
    return null;
  }
  
  protected AttachModel getAttach()
  {
    return AttachModelFactory.getAttachFor(application);
  }
  
  protected SaModel getSAAgent()
  {
    return SaModelFactory.getSAAgentFor(application);
  }
  
  protected JmxModel getJmxModel()
  {
    return JmxModelFactory.getJmxModelFor(application);
  }
  
  protected void initStaticData()
  {
    synchronized (staticDataLock)
    {
      if (staticDataInitialized) {
        return;
      }
      if (jvmstatModel != null)
      {
        commandLine = jvmstatModel.getCommandLine();
        jvmArgs = getJvmArgsJvmstat();
        jvmFlags = jvmstatModel.getJvmFlags();
        mainArgs = jvmstatModel.getMainArgs();
        mainClass = jvmstatModel.getMainClass();
        vmVersion = jvmstatModel.getVmVersion();
        javaVersion = monitoredVm.findByName("java.property.java.version");
        javaHome = jvmstatModel.getJavaHome();
        vmInfo = jvmstatModel.getVmInfo();
        vmName = jvmstatModel.getVmName();
        vmVendor = jvmstatModel.getVmVendor();
      }
      else
      {
        jvmArgs = jmxSupport.getJvmArgs();
        Properties prop = getJmxModel().getSystemProperties();
        if (prop != null)
        {
          vmVersion = prop.getProperty("java.vm.version");
          javaVersion = prop.getProperty("java.version");
          javaHome = prop.getProperty("java.home");
          vmInfo = prop.getProperty("java.vm.info");
          vmName = prop.getProperty("java.vm.name");
          vmVendor = prop.getProperty("java.vm.vendor");
        }
      }
      staticDataInitialized = true;
    }
  }
  
  private String getJvmArgsJvmstat()
  {
    String args = jvmstatModel.getJvmArgs();
    if (args.length() == 1024)
    {
      args = jmxSupport.getJvmArgs();
      if (args == null)
      {
        SaModel sa = getSAAgent();
        if (sa != null) {
          args = sa.getJvmArgs();
        }
      }
      if ((args == null) || (args.length() == 0)) {
        args = jvmstatModel.getJvmArgs();
      }
    }
    return args;
  }
  
  public void dataChanged(JvmstatModel stat)
  {
    assert (stat == monitoredVm);
    MonitoredData data = new MonitoredDataImpl(this, jvmstatModel, jmxSupport);
    notifyListeners(data);
  }
  
  void notifyListeners(MonitoredData data)
  {
    List<MonitoredDataListener> listenersCopy;
    synchronized (listeners)
    {
      listenersCopy = new ArrayList(listeners);
    }
    for (MonitoredDataListener listener : listenersCopy) {
      listener.monitoredDataEvent(data);
    }
  }
}

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

import com.sun.tools.visualvm.application.jvm.MonitoredData;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.TimerTask;
import java.util.logging.Logger;

class JmxSupport$1
  extends TimerTask
{
  JmxSupport$1(JmxSupport paramJmxSupport, JvmMXBeans paramJvmMXBeans) {}
  
  public void run()
  {
    try
    {
      MonitoredData data = new MonitoredDataImpl(JmxSupport.access$000(this$0), this$0, val$jmx);
      JmxSupport.access$000(this$0).notifyListeners(data);
    }
    catch (UndeclaredThrowableException e)
    {
      JmxSupport.access$100().throwing(JmxSupport.class.getName(), "MonitoredDataImpl<init>", e);
    }
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.MonitoredData;
import com.sun.tools.visualvm.core.datasupport.DataRemovedListener;
import com.sun.tools.visualvm.core.options.GlobalPreferences;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModel.ConnectionState;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeansFactory;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryType;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadMXBean;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collection;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

public class JmxSupport
  implements DataRemovedListener
{
  private static final Logger LOGGER = Logger.getLogger(JmxSupport.class.getName());
  private static final String PROCESS_CPU_TIME_ATTR = "ProcessCpuTime";
  private static final String PROCESSING_CAPACITY_ATTR = "ProcessingCapacity";
  private static final String PERM_GEN = "Perm Gen";
  private static final String PS_PERM_GEN = "PS Perm Gen";
  private static final String CMS_PERM_GEN = "CMS Perm Gen";
  private static final String IBM_PERM_GEN = "class storage";
  private static final ObjectName osName = getOSName();
  private static long INITIAL_DELAY = 100L;
  private Application application;
  private JvmMXBeans mxbeans;
  private JVMImpl jvm;
  private Object processCPUTimeAttributeLock = new Object();
  private Boolean processCPUTimeAttribute;
  private long processCPUTimeMultiplier;
  private Boolean readOnlyConnection;
  private Timer timer;
  private MemoryPoolMXBean permGenPool;
  private Collection<GarbageCollectorMXBean> gcList;
  
  JmxSupport(Application app, JVMImpl vm)
  {
    jvm = vm;
    application = app;
    app.notifyWhenRemoved(this);
  }
  
  RuntimeMXBean getRuntime()
  {
    JvmMXBeans jmx = getJvmMXBeans();
    if (jmx != null) {
      return jmx.getRuntimeMXBean();
    }
    return null;
  }
  
  boolean hasProcessCPUTimeAttribute()
  {
    synchronized (processCPUTimeAttributeLock)
    {
      if (processCPUTimeAttribute != null) {
        return processCPUTimeAttribute.booleanValue();
      }
      processCPUTimeAttribute = Boolean.FALSE;
      JmxModel jmx = JmxModelFactory.getJmxModelFor(application);
      if ((jmx != null) && (jmx.getConnectionState().equals(JmxModel.ConnectionState.CONNECTED)))
      {
        MBeanServerConnection conn = jmx.getMBeanServerConnection();
        if (conn != null) {
          try
          {
            MBeanInfo info = conn.getMBeanInfo(osName);
            MBeanAttributeInfo[] attrs = info.getAttributes();
            
            processCPUTimeMultiplier = 1L;
            for (MBeanAttributeInfo attr : attrs)
            {
              String name = attr.getName();
              if ("ProcessCpuTime".equals(name)) {
                processCPUTimeAttribute = Boolean.TRUE;
              }
              if ("ProcessingCapacity".equals(name))
              {
                Number mul = (Number)conn.getAttribute(osName, "ProcessingCapacity");
                processCPUTimeMultiplier = mul.longValue();
              }
            }
          }
          catch (Exception ex)
          {
            LOGGER.throwing(JmxSupport.class.getName(), "hasProcessCPUTimeAttribute", ex);
          }
        }
      }
      return processCPUTimeAttribute.booleanValue();
    }
  }
  
  long getProcessCPUTime()
  {
    if (!hasProcessCPUTimeAttribute()) {
      throw new UnsupportedOperationException();
    }
    JmxModel jmx = JmxModelFactory.getJmxModelFor(application);
    if ((jmx != null) && (jmx.getConnectionState().equals(JmxModel.ConnectionState.CONNECTED)))
    {
      MBeanServerConnection conn = jmx.getMBeanServerConnection();
      if (conn != null) {
        try
        {
          Long cputime = (Long)conn.getAttribute(osName, "ProcessCpuTime");
          
          return cputime.longValue() * processCPUTimeMultiplier;
        }
        catch (Exception ex)
        {
          LOGGER.throwing(JmxSupport.class.getName(), "hasProcessCPUTimeAttribute", ex);
        }
      }
    }
    return -1L;
  }
  
  synchronized JvmMXBeans getJvmMXBeans()
  {
    if (mxbeans == null)
    {
      JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);
      if ((jmxModel != null) && (jmxModel.getConnectionState() == JmxModel.ConnectionState.CONNECTED)) {
        mxbeans = JvmMXBeansFactory.getJvmMXBeans(jmxModel);
      }
    }
    return mxbeans;
  }
  
  synchronized boolean isReadOnlyConnection()
  {
    if (readOnlyConnection == null)
    {
      readOnlyConnection = Boolean.FALSE;
      JvmMXBeans mxbeans = getJvmMXBeans();
      if (mxbeans != null)
      {
        ThreadMXBean threads = mxbeans.getThreadMXBean();
        if (threads != null) {
          try
          {
            threads.getThreadInfo(1L);
          }
          catch (SecurityException ex)
          {
            readOnlyConnection = Boolean.TRUE;
          }
        }
      }
    }
    return readOnlyConnection.booleanValue();
  }
  
  synchronized Collection<GarbageCollectorMXBean> getGarbageCollectorMXBeans()
  {
    if (gcList == null)
    {
      JvmMXBeans jmx = getJvmMXBeans();
      if (jmx != null) {
        gcList = jmx.getGarbageCollectorMXBeans();
      }
    }
    return gcList;
  }
  
  String getJvmArgs()
  {
    try
    {
      RuntimeMXBean runtime = getRuntime();
      if (runtime != null)
      {
        StringBuilder buf = new StringBuilder();
        List<String> args = runtime.getInputArguments();
        for (String arg : args) {
          buf.append(arg).append(' ');
        }
        return buf.toString();
      }
      return null;
    }
    catch (Exception e)
    {
      LOGGER.throwing(JmxSupport.class.getName(), "getJvmArgs", e);
    }
    return null;
  }
  
  MemoryPoolMXBean getPermGenPool()
  {
    try
    {
      if (permGenPool == null)
      {
        JvmMXBeans jmx = getJvmMXBeans();
        if (jmx != null)
        {
          Collection<MemoryPoolMXBean> pools = jmx.getMemoryPoolMXBeans();
          for (MemoryPoolMXBean pool : pools)
          {
            MemoryType type = pool.getType();
            String name = pool.getName();
            if ((MemoryType.NON_HEAP.equals(type)) && (("Perm Gen".equals(name)) || ("PS Perm Gen".equals(name)) || ("CMS Perm Gen".equals(name)) || ("class storage".equals(name))))
            {
              permGenPool = pool;
              break;
            }
          }
        }
      }
      return permGenPool;
    }
    catch (Exception e)
    {
      LOGGER.throwing(JmxSupport.class.getName(), "getPermGenPool", e);
    }
    return null;
  }
  
  void initTimer()
  {
    int interval = GlobalPreferences.sharedInstance().getMonitoredDataPoll() * 1000;
    final JvmMXBeans jmx = getJvmMXBeans();
    if (jmx != null)
    {
      TimerTask task = new TimerTask()
      {
        public void run()
        {
          try
          {
            MonitoredData data = new MonitoredDataImpl(jvm, JmxSupport.this, jmx);
            jvm.notifyListeners(data);
          }
          catch (UndeclaredThrowableException e)
          {
            JmxSupport.LOGGER.throwing(JmxSupport.class.getName(), "MonitoredDataImpl<init>", e);
          }
        }
      };
      timer = new Timer("JMX MonitoredData timer for " + application.getId());
      timer.schedule(task, INITIAL_DELAY, interval);
    }
  }
  
  void disableTimer()
  {
    if (timer != null) {
      timer.cancel();
    }
  }
  
  private static ObjectName getOSName()
  {
    try
    {
      return new ObjectName("java.lang:type=OperatingSystem");
    }
    catch (MalformedObjectNameException ex)
    {
      throw new RuntimeException(ex);
    }
  }
  
  public void dataRemoved(Object dataSource)
  {
    disableTimer();
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.core.model.AbstractModelProvider;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModel.ConnectionState;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeansFactory;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatModel;
import com.sun.tools.visualvm.tools.jvmstat.JvmstatModelFactory;

public class JvmProvider
  extends AbstractModelProvider<Jvm, Application>
{
  public Jvm createModelFor(Application app)
  {
    JvmstatModel jvmstat = JvmstatModelFactory.getJvmstatFor(app);
    JVMImpl jvm = null;
    if (jvmstat != null)
    {
      jvm = new JVMImpl(app, jvmstat);
    }
    else
    {
      JmxModel jmxModel = JmxModelFactory.getJmxModelFor(app);
      if ((jmxModel != null) && (jmxModel.getConnectionState() == JmxModel.ConnectionState.CONNECTED))
      {
        JvmMXBeans jmx = JvmMXBeansFactory.getJvmMXBeans(jmxModel);
        if ((jmx != null) && (jmx.getRuntimeMXBean() != null)) {
          jvm = new JVMImpl(app);
        }
      }
    }
    return jvm;
  }
}

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

import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.MonitoredData;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import com.sun.tools.visualvm.tools.jvmstat.JvmJvmstatModel;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadMXBean;
import java.util.Collection;
import java.util.logging.Logger;
import sun.jvmstat.monitor.LongMonitor;

public class MonitoredDataImpl
  extends MonitoredData
{
  private static final Logger LOGGER = Logger.getLogger(MonitoredDataImpl.class.getName());
  private final Jvm jvm;
  
  private MonitoredDataImpl(Jvm vm, JmxSupport jmxSupport)
  {
    try
    {
      Collection<GarbageCollectorMXBean> gcList = jmxSupport.getGarbageCollectorMXBeans();
      if (jmxSupport.hasProcessCPUTimeAttribute()) {
        processCpuTime = jmxSupport.getProcessCPUTime();
      }
      if ((gcList != null) && (!gcList.isEmpty())) {
        for (GarbageCollectorMXBean gcBean : gcList) {
          collectionTime += gcBean.getCollectionTime();
        }
      }
    }
    catch (Exception ex)
    {
      LOGGER.throwing(MonitoredDataImpl.class.getName(), "MonitoredDataImpl.<init>", ex);
    }
    jvm = vm;
  }
  
  MonitoredDataImpl(Jvm vm, JvmJvmstatModel jvmstatModel, JmxSupport jmxSupport)
  {
    this(vm, jmxSupport);
    loadedClasses = jvmstatModel.getLoadedClasses();
    sharedLoadedClasses = jvmstatModel.getSharedLoadedClasses();
    sharedUnloadedClasses = jvmstatModel.getSharedUnloadedClasses();
    unloadedClasses = jvmstatModel.getUnloadedClasses();
    threadsDaemon = jvmstatModel.getThreadsDaemon();
    threadsLive = jvmstatModel.getThreadsLive();
    threadsLivePeak = jvmstatModel.getThreadsLivePeak();
    threadsStarted = jvmstatModel.getThreadsStarted();
    applicationTime = (1000L * jvmstatModel.getApplicationTime() / jvmstatModel.getOsFrequency());
    upTime = (1000L * jvmstatModel.getUpTime() / jvmstatModel.getOsFrequency());
    genCapacity = jvmstatModel.getGenCapacity();
    genUsed = jvmstatModel.getGenUsed();
    genMaxCapacity = jvmstatModel.getGenMaxCapacity();
  }
  
  MonitoredDataImpl(Jvm vm, JmxSupport jmxSupport, JvmMXBeans jmxModel)
  {
    this(vm, jmxSupport);
    RuntimeMXBean runtimeBean = jmxModel.getRuntimeMXBean();
    upTime = runtimeBean.getUptime();
    ClassLoadingMXBean classBean = jmxModel.getClassLoadingMXBean();
    ThreadMXBean threadBean = jmxModel.getThreadMXBean();
    MemoryUsage mem = jmxModel.getMemoryMXBean().getHeapMemoryUsage();
    MemoryPoolMXBean permBean = jmxSupport.getPermGenPool();
    unloadedClasses = classBean.getUnloadedClassCount();
    loadedClasses = (classBean.getLoadedClassCount() + unloadedClasses);
    sharedLoadedClasses = 0L;
    sharedUnloadedClasses = 0L;
    threadsDaemon = threadBean.getDaemonThreadCount();
    threadsLive = threadBean.getThreadCount();
    threadsLivePeak = threadBean.getPeakThreadCount();
    threadsStarted = threadBean.getTotalStartedThreadCount();
    applicationTime = 0L;
    genCapacity = new long[2];
    genUsed = new long[2];
    genMaxCapacity = new long[2];
    genCapacity[0] = mem.getCommitted();
    genUsed[0] = mem.getUsed();
    genMaxCapacity[0] = mem.getMax();
    if (permBean != null)
    {
      MemoryUsage perm = permBean.getUsage();
      genCapacity[1] = perm.getCommitted();
      genUsed[1] = perm.getUsed();
      genMaxCapacity[1] = perm.getMax();
    }
  }
  
  private long getLongValue(LongMonitor mon)
  {
    if (mon != null) {
      return mon.longValue();
    }
    return 0L;
  }
  
  public Jvm getJVM()
  {
    return jvm;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jvm.MonitoredDataImpl
 * 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-2019. Infinite Loop Ltd