com-sun-tools-visualvm-heapdump

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

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.snapshot.Snapshot;
import com.sun.tools.visualvm.core.snapshot.SnapshotsSupport;
import java.io.File;
import org.openide.util.NbBundle;

public abstract class HeapDump
  extends Snapshot
{
  public HeapDump(File file)
  {
    this(file, null);
  }
  
  public HeapDump(File file, DataSource master)
  {
    super(file, HeapDumpSupport.getInstance().getCategory(), master);
  }
  
  public boolean supportsSaveAs()
  {
    return true;
  }
  
  public void saveAs()
  {
    SnapshotsSupport.getInstance().saveAs(this, NbBundle.getMessage(HeapDump.class, "LBL_Save_Heap_Dump_As"));
  }
}

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

import com.sun.tools.visualvm.core.snapshot.SnapshotDescriptor;
import com.sun.tools.visualvm.core.snapshot.SnapshotsSupport;
import java.awt.Image;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;

public class HeapDumpDescriptor
  extends SnapshotDescriptor<HeapDump>
{
  private static final Image ICON = SnapshotsSupport.getInstance().createSnapshotIcon(ImageUtilities.loadImage("com/sun/tools/visualvm/heapdump/resources/heapdumpBase.png", true));
  
  public HeapDumpDescriptor(HeapDump heapDump)
  {
    super(heapDump, NbBundle.getMessage(HeapDumpDescriptor.class, "DESCR_HeapDump"), ICON);
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.snapshot.RegisteredSnapshotCategories;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.PluggableDataSourceViewProvider;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.heapdump.impl.HeapDumpCategory;
import com.sun.tools.visualvm.heapdump.impl.HeapDumpDescriptorProvider;
import com.sun.tools.visualvm.heapdump.impl.HeapDumpProvider;
import com.sun.tools.visualvm.heapdump.impl.HeapDumpViewProvider;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;

public final class HeapDumpSupport
{
  private static HeapDumpSupport instance;
  private final SnapshotCategory category = new HeapDumpCategory();
  private final HeapDumpProvider heapDumpProvider;
  private final HeapDumpViewProvider heapDumpViewProvider;
  
  public static synchronized HeapDumpSupport getInstance()
  {
    if (instance == null) {
      instance = new HeapDumpSupport();
    }
    return instance;
  }
  
  public SnapshotCategory getCategory()
  {
    return category;
  }
  
  public boolean supportsHeapDump(Application application)
  {
    if (application.getState() != 1) {
      return false;
    }
    return JvmFactory.getJVMFor(application).isTakeHeapDumpSupported();
  }
  
  public void takeHeapDump(Application application, boolean openView)
  {
    heapDumpProvider.createHeapDump(application, openView);
  }
  
  public boolean supportsRemoteHeapDump(Application application)
  {
    if (application.getState() != 1) {
      return false;
    }
    if (application.isLocalApplication()) {
      return false;
    }
    JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);
    return jmxModel == null ? false : jmxModel.isTakeHeapDumpSupported();
  }
  
  public void takeRemoteHeapDump(Application application, String dumpFile, boolean customizeDumpFile)
  {
    heapDumpProvider.createRemoteHeapDump(application, dumpFile, customizeDumpFile);
  }
  
  public void takeHeapDump(CoreDump coreDump, boolean openView)
  {
    heapDumpProvider.createHeapDump(coreDump, openView);
  }
  
  public PluggableDataSourceViewProvider<HeapDump> getHeapDumpView()
  {
    return heapDumpViewProvider;
  }
  
  private HeapDumpSupport()
  {
    DataSourceDescriptorFactory.getDefault().registerProvider(new HeapDumpDescriptorProvider());
    heapDumpProvider = new HeapDumpProvider();
    heapDumpProvider.initialize();
    
    heapDumpViewProvider = new HeapDumpViewProvider();
    RegisteredSnapshotCategories.sharedInstance().registerCategory(category);
    
    heapDumpViewProvider.initialize();
  }
}

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

import org.openide.modules.ModuleInstall;

final class Installer
  extends ModuleInstall
{
  public void restored()
  {
    HeapDumpSupport.getInstance();
  }
}

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

import com.sun.tools.visualvm.core.ui.actions.ActionUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

class HeapDumpAction$1
  implements PropertyChangeListener
{
  HeapDumpAction$1(HeapDumpAction paramHeapDumpAction) {}
  
  public void propertyChange(PropertyChangeEvent evt)
  {
    this$0.updateState(ActionUtils.getSelectedDataSources());
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.ui.actions.ActionUtils;
import com.sun.tools.visualvm.core.ui.actions.MultiDataSourceAction;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.heapdump.HeapDumpSupport;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashSet;
import java.util.Set;
import org.openide.util.NbBundle;

class HeapDumpAction
  extends MultiDataSourceAction<DataSource>
{
  private Set<Application> lastSelectedApplications = new HashSet();
  private final PropertyChangeListener stateListener = new PropertyChangeListener()
  {
    public void propertyChange(PropertyChangeEvent evt)
    {
      updateState(ActionUtils.getSelectedDataSources());
    }
  };
  private static HeapDumpAction INSTANCE;
  
  public static synchronized HeapDumpAction instance()
  {
    if (INSTANCE == null) {
      INSTANCE = new HeapDumpAction();
    }
    return INSTANCE;
  }
  
  protected void actionPerformed(Set<DataSource> dataSources, ActionEvent actionEvent)
  {
    HeapDumpSupport support = HeapDumpSupport.getInstance();
    for (DataSource dataSource : dataSources) {
      if ((dataSource instanceof Application))
      {
        Application application = (Application)dataSource;
        boolean tagged = (actionEvent.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
        if (application.isLocalApplication()) {
          support.takeHeapDump(application, !tagged);
        } else {
          support.takeRemoteHeapDump(application, null, !tagged);
        }
      }
      else if ((dataSource instanceof CoreDump))
      {
        CoreDump coreDump = (CoreDump)dataSource;
        support.takeHeapDump(coreDump, (actionEvent.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) == 0);
      }
    }
  }
  
  protected boolean isEnabled(Set<DataSource> dataSources)
  {
    HeapDumpSupport support = HeapDumpSupport.getInstance();
    for (DataSource dataSource : dataSources) {
      if ((dataSource instanceof Application))
      {
        Application application = (Application)dataSource;
        lastSelectedApplications.add(application);
        application.addPropertyChangeListener("prop_state", stateListener);
        if (application.getState() != 1) {
          return false;
        }
        if (application.isLocalApplication())
        {
          if (!support.supportsHeapDump(application)) {
            return false;
          }
        }
        else if (!support.supportsRemoteHeapDump(application)) {
          return false;
        }
      }
      else if (!(dataSource instanceof CoreDump))
      {
        return false;
      }
    }
    return true;
  }
  
  protected void updateState(Set<DataSource> dataSources)
  {
    if (!lastSelectedApplications.isEmpty()) {
      for (Application application : lastSelectedApplications) {
        application.removePropertyChangeListener("prop_state", stateListener);
      }
    }
    lastSelectedApplications.clear();
    super.updateState(dataSources);
  }
  
  private HeapDumpAction()
  {
    super(DataSource.class);
    putValue("Name", NbBundle.getMessage(HeapDumpAction.class, "MSG_Heap_Dump"));
    putValue("ShortDescription", NbBundle.getMessage(HeapDumpAction.class, "LBL_Heap_Dump"));
  }
}

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

import java.io.File;
import javax.swing.filechooser.FileFilter;

class HeapDumpCategory$1
  extends FileFilter
{
  HeapDumpCategory$1(HeapDumpCategory paramHeapDumpCategory) {}
  
  public boolean accept(File f)
  {
    return (f.isDirectory()) || (this$0.isSnapshot(f));
  }
  
  public String getDescription()
  {
    String suff = HeapDumpCategory.access$000(this$0);
    return this$0.getName() + (suff != null ? " (*" + suff + ", *.*" + ")" : "");
  }
}

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

import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.heapdump.HeapDump;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import javax.swing.filechooser.FileFilter;
import org.openide.util.NbBundle;

public class HeapDumpCategory
  extends SnapshotCategory<HeapDump>
{
  private static final String HPROF_HEADER = "JAVA PROFILE 1.0";
  private static final long MIN_HPROF_SIZE = 1048576L;
  private static final String NAME = NbBundle.getMessage(HeapDumpCategory.class, "LBL_Heap_Dumps");
  private static final String PREFIX = "heapdump";
  private static final String SUFFIX = ".hprof";
  
  public HeapDumpCategory()
  {
    super(NAME, HeapDump.class, "heapdump", ".hprof", 20);
  }
  
  public boolean supportsOpenSnapshot()
  {
    return true;
  }
  
  public void openSnapshot(File file)
  {
    DataSourceWindowManager.sharedInstance().openDataSource(new HeapDumpImpl(file, null));
  }
  
  protected boolean isSnapshot(File file)
  {
    if (super.isSnapshot(file)) {
      return true;
    }
    return checkHprofFile(file);
  }
  
  private boolean checkHprofFile(File file)
  {
    try
    {
      if ((file.isFile()) && (file.canRead()) && (file.length() > 1048576L))
      {
        byte[] prefix = new byte["JAVA PROFILE 1.0".length() + 4];
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        raf.readFully(prefix);
        if (new String(prefix).startsWith("JAVA PROFILE 1.0")) {
          return true;
        }
      }
    }
    catch (FileNotFoundException ex)
    {
      return false;
    }
    catch (IOException ex)
    {
      return false;
    }
    return false;
  }
  
  public FileFilter getFileFilter()
  {
    new FileFilter()
    {
      public boolean accept(File f)
      {
        return (f.isDirectory()) || (isSnapshot(f));
      }
      
      public String getDescription()
      {
        String suff = getSuffix();
        return getName() + (suff != null ? " (*" + suff + ", *.*" + ")" : "");
      }
    };
  }
}

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

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.model.AbstractModelProvider;
import com.sun.tools.visualvm.heapdump.HeapDump;
import com.sun.tools.visualvm.heapdump.HeapDumpDescriptor;

public class HeapDumpDescriptorProvider
  extends AbstractModelProvider<DataSourceDescriptor, DataSource>
{
  public DataSourceDescriptor createModelFor(DataSource ds)
  {
    if ((ds instanceof HeapDump)) {
      return new HeapDumpDescriptor((HeapDump)ds);
    }
    return null;
  }
}

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

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.heapdump.HeapDump;
import java.io.File;

public final class HeapDumpImpl
  extends HeapDump
{
  public HeapDumpImpl(File file, DataSource master)
  {
    super(file, master);
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.ui.actions.ActionUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

class HeapDumpOnOOMEAction$1
  implements PropertyChangeListener
{
  HeapDumpOnOOMEAction$1(HeapDumpOnOOMEAction paramHeapDumpOnOOMEAction) {}
  
  public void propertyChange(PropertyChangeEvent evt)
  {
    this$0.updateState(ActionUtils.getSelectedDataSources(Application.class));
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.ui.actions.ActionUtils;
import com.sun.tools.visualvm.core.ui.actions.SingleDataSourceAction;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Set;
import org.openide.util.NbBundle;

class HeapDumpOnOOMEAction
  extends SingleDataSourceAction<Application>
{
  private boolean oomeEnabled;
  private Application lastSelectedApplication;
  private final PropertyChangeListener stateListener = new PropertyChangeListener()
  {
    public void propertyChange(PropertyChangeEvent evt)
    {
      updateState(ActionUtils.getSelectedDataSources(Application.class));
    }
  };
  private static HeapDumpOnOOMEAction instance;
  
  public static synchronized HeapDumpOnOOMEAction instance()
  {
    if (instance == null) {
      instance = new HeapDumpOnOOMEAction();
    }
    return instance;
  }
  
  protected void actionPerformed(Application application, ActionEvent actionEvent)
  {
    Jvm jvm = JvmFactory.getJVMFor(application);
    jvm.setDumpOnOOMEnabled(!oomeEnabled);
    updateState(jvm);
  }
  
  protected boolean isEnabled(Application application)
  {
    lastSelectedApplication = application;
    lastSelectedApplication.addPropertyChangeListener("prop_state", stateListener);
    if (application.getState() != 1) {
      return false;
    }
    Jvm jvm = JvmFactory.getJVMFor(application);
    if (!jvm.isDumpOnOOMEnabledSupported()) {
      return false;
    }
    updateState(jvm);
    return true;
  }
  
  private void updateState(Jvm jvm)
  {
    oomeEnabled = jvm.isDumpOnOOMEnabled();
    if (oomeEnabled)
    {
      putValue("Name", NbBundle.getMessage(HeapDumpOnOOMEAction.class, "LBL_Disable_Heap_Dump_on_OOME"));
      putValue("ShortDescription", NbBundle.getMessage(HeapDumpOnOOMEAction.class, "DESCR_Disable_Heap_Dump_on_OOME"));
    }
    else
    {
      putValue("Name", NbBundle.getMessage(HeapDumpOnOOMEAction.class, "LBL_Enable_Heap_Dump_on_OOME"));
      putValue("ShortDescription", NbBundle.getMessage(HeapDumpOnOOMEAction.class, "DESCR_Enable_Heap_Dump_on_OOME"));
    }
  }
  
  protected void updateState(Set<Application> applications)
  {
    if (lastSelectedApplication != null)
    {
      lastSelectedApplication.removePropertyChangeListener("prop_state", stateListener);
      lastSelectedApplication = null;
    }
    super.updateState(applications);
  }
  
  private HeapDumpOnOOMEAction()
  {
    super(Application.class);
  }
}

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

import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;

class HeapDumpProvider$1$1
  implements Runnable
{
  HeapDumpProvider$1$1(HeapDumpProvider.1 param1, HeapDumpImpl paramHeapDumpImpl) {}
  
  public void run()
  {
    DataSourceWindowManager.sharedInstance().openDataSource(val$heapDump);
  }
}

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

import org.netbeans.api.progress.ProgressHandle;

class HeapDumpProvider$1$2
  implements Runnable
{
  HeapDumpProvider$1$2(HeapDumpProvider.1 param1, ProgressHandle paramProgressHandle) {}
  
  public void run()
  {
    if (val$pHandleF != null) {
      val$pHandleF.finish();
    }
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.datasource.DataSourceContainer;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor.Message;
import org.openide.util.NbBundle;

class HeapDumpProvider$1
  implements Runnable
{
  HeapDumpProvider$1(HeapDumpProvider paramHeapDumpProvider, Application paramApplication, boolean paramBoolean) {}
  
  public void run()
  {
    Jvm jvm = JvmFactory.getJVMFor(val$application);
    if (!jvm.isTakeHeapDumpSupported())
    {
      DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Cannot_take_heap_dump") + DataSourceDescriptorFactory.getDescriptor(val$application).getName(), 0));
      
      return;
    }
    ProgressHandle pHandle = null;
    try
    {
      pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(HeapDumpProvider.class, "LBL_Creating_Heap_Dump"));
      
      pHandle.setInitialDelay(0);
      pHandle.start();
      try
      {
        File file = jvm.takeHeapDump();
        if ((file != null) && (file.isFile()))
        {
          final HeapDumpImpl heapDump = new HeapDumpImpl(file, val$application);
          val$application.getRepository().addDataSource(heapDump);
          if (val$openView) {
            SwingUtilities.invokeLater(new Runnable()
            {
              public void run()
              {
                DataSourceWindowManager.sharedInstance().openDataSource(heapDump);
              }
            });
          }
        }
        else
        {
          HeapDumpProvider.access$000(this$0, val$application);
        }
      }
      catch (IOException ex)
      {
        HeapDumpProvider.access$100().log(Level.INFO, "createHeapDump-Application", ex);
        HeapDumpProvider.access$000(this$0, val$application);
      }
    }
    finally
    {
      final ProgressHandle pHandleF;
      ProgressHandle pHandleF = pHandle;
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          if (pHandleF != null) {
            pHandleF.finish();
          }
        }
      });
    }
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor.Message;
import org.openide.util.NbBundle;

class HeapDumpProvider$2
  implements Runnable
{
  HeapDumpProvider$2(HeapDumpProvider paramHeapDumpProvider, Application paramApplication, String paramString, boolean paramBoolean) {}
  
  public void run()
  {
    JmxModel model = JmxModelFactory.getJmxModelFor(val$application);
    if ((model == null) || (!model.isTakeHeapDumpSupported()))
    {
      DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Dump_failed"), 0));
      
      return;
    }
    String file = val$dumpFile;
    if (file == null) {
      file = HeapDumpProvider.access$200(model, val$customizeDumpFile);
    }
    if (file == null) {
      return;
    }
    if (model.takeHeapDump(file)) {
      DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Dump_ok", file), 1));
    } else {
      DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Dump_save_failed", file), 0));
    }
  }
}

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

import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.awt.Mnemonics;
import org.openide.util.NbBundle;

final class HeapDumpProvider$3
  implements Runnable
{
  HeapDumpProvider$3(String[] paramArrayOfString) {}
  
  public void run()
  {
    JLabel label = new JLabel();
    Mnemonics.setLocalizedText(label, NbBundle.getMessage(HeapDumpProvider.class, "MSG_Remote_heap_dump"));
    
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
    JTextField field = new JTextField();
    label.setLabelFor(field);
    field.setText(val$path[0]);
    Dimension dim = field.getPreferredSize();
    width = 350;
    field.setPreferredSize(dim);
    field.selectAll();
    JPanel selector = new JPanel(new BorderLayout());
    selector.setBorder(BorderFactory.createEmptyBorder(15, 10, 5, 10));
    selector.add(label, "North");
    selector.add(field, "South");
    
    DialogDescriptor dd = new DialogDescriptor(selector, NbBundle.getMessage(HeapDumpProvider.class, "CAPTION_Remote_heap_dump"), true, null);
    
    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
    d.pack();
    d.setVisible(true);
    
    val$path[0] = (dd.getValue() == DialogDescriptor.OK_OPTION ? field.getText() : null);
  }
}

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

import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;

class HeapDumpProvider$4$1
  implements Runnable
{
  HeapDumpProvider$4$1(HeapDumpProvider.4 param4, HeapDumpImpl paramHeapDumpImpl) {}
  
  public void run()
  {
    DataSourceWindowManager.sharedInstance().openDataSource(val$heapDump);
  }
}

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

import org.netbeans.api.progress.ProgressHandle;

class HeapDumpProvider$4$2
  implements Runnable
{
  HeapDumpProvider$4$2(HeapDumpProvider.4 param4, ProgressHandle paramProgressHandle) {}
  
  public void run()
  {
    if (val$pHandleF != null) {
      val$pHandleF.finish();
    }
  }
}

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

import com.sun.tools.visualvm.core.datasource.DataSourceContainer;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.heapdump.HeapDumpSupport;
import com.sun.tools.visualvm.tools.sa.SaModel;
import com.sun.tools.visualvm.tools.sa.SaModelFactory;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.util.NbBundle;

class HeapDumpProvider$4
  implements Runnable
{
  HeapDumpProvider$4(HeapDumpProvider paramHeapDumpProvider, CoreDump paramCoreDump, boolean paramBoolean) {}
  
  public void run()
  {
    ProgressHandle pHandle = null;
    try
    {
      pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(HeapDumpProvider.class, "LBL_Creating_Heap_Dump"));
      
      pHandle.setInitialDelay(0);
      pHandle.start();
      File snapshotDir = val$coreDump.getStorage().getDirectory();
      String name = HeapDumpSupport.getInstance().getCategory().createFileName();
      File dumpFile = new File(snapshotDir, name);
      SaModel saAget = SaModelFactory.getSAAgentFor(val$coreDump);
      try
      {
        if (saAget.takeHeapDump(dumpFile.getAbsolutePath()))
        {
          final HeapDumpImpl heapDump = new HeapDumpImpl(dumpFile, val$coreDump);
          val$coreDump.getRepository().addDataSource(heapDump);
          if (val$openView) {
            SwingUtilities.invokeLater(new Runnable()
            {
              public void run()
              {
                DataSourceWindowManager.sharedInstance().openDataSource(heapDump);
              }
            });
          }
        }
        else
        {
          HeapDumpProvider.access$000(this$0, val$coreDump);
        }
      }
      catch (Exception ex)
      {
        HeapDumpProvider.access$100().log(Level.INFO, "createHeapDump-CoreDump", ex);
        HeapDumpProvider.access$000(this$0, val$coreDump);
      }
    }
    finally
    {
      final ProgressHandle pHandleF;
      ProgressHandle pHandleF = pHandle;
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          if (pHandleF != null) {
            pHandleF.finish();
          }
        }
      });
    }
  }
}

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

import com.sun.tools.visualvm.application.Application;
import java.util.Iterator;
import java.util.Set;

class HeapDumpProvider$ApplicationListener$1
  implements Runnable
{
  HeapDumpProvider$ApplicationListener$1(HeapDumpProvider.ApplicationListener paramApplicationListener, Set paramSet) {}
  
  public void run()
  {
    Application application;
    for (Iterator i$ = val$applications.iterator(); i$.hasNext(); HeapDumpProvider.access$600(this$1.this$0, application)) {
      application = (Application)i$.next();
    }
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import java.util.Iterator;
import java.util.Set;
import org.openide.util.RequestProcessor;

class HeapDumpProvider$ApplicationListener
  implements DataChangeListener<Application>
{
  private HeapDumpProvider$ApplicationListener(HeapDumpProvider paramHeapDumpProvider) {}
  
  public void dataChanged(DataChangeEvent<Application> event)
  {
    final Set<Application> applications = event.getAdded();
    if (!applications.isEmpty()) {
      RequestProcessor.getDefault().post(new Runnable()
      {
        public void run()
        {
          Application application;
          for (Iterator i$ = applications.iterator(); i$.hasNext(); HeapDumpProvider.access$600(this$0, application)) {
            application = (Application)i$.next();
          }
        }
      });
    }
  }
}

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

import com.sun.tools.visualvm.core.snapshot.Snapshot;
import java.util.Iterator;
import java.util.Set;

class HeapDumpProvider$SnapshotListener$1
  implements Runnable
{
  HeapDumpProvider$SnapshotListener$1(HeapDumpProvider.SnapshotListener paramSnapshotListener, Set paramSet) {}
  
  public void run()
  {
    Snapshot snapshot;
    for (Iterator i$ = val$snapshots.iterator(); i$.hasNext(); HeapDumpProvider.access$500(this$1.this$0, snapshot)) {
      snapshot = (Snapshot)i$.next();
    }
  }
}

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

import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import com.sun.tools.visualvm.core.snapshot.Snapshot;
import java.util.Iterator;
import java.util.Set;
import org.openide.util.RequestProcessor;

class HeapDumpProvider$SnapshotListener
  implements DataChangeListener<Snapshot>
{
  private HeapDumpProvider$SnapshotListener(HeapDumpProvider paramHeapDumpProvider) {}
  
  public void dataChanged(DataChangeEvent<Snapshot> event)
  {
    final Set<Snapshot> snapshots = event.getAdded();
    if (!snapshots.isEmpty()) {
      RequestProcessor.getDefault().post(new Runnable()
      {
        public void run()
        {
          Snapshot snapshot;
          for (Iterator i$ = snapshots.iterator(); i$.hasNext(); HeapDumpProvider.access$500(this$0, snapshot)) {
            snapshot = (Snapshot)i$.next();
          }
        }
      });
    }
  }
}

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

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.datasource.DataSourceContainer;
import com.sun.tools.visualvm.core.datasource.DataSourceRepository;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import com.sun.tools.visualvm.core.snapshot.Snapshot;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.heapdump.HeapDumpSupport;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import com.sun.tools.visualvm.tools.sa.SaModel;
import com.sun.tools.visualvm.tools.sa.SaModelFactory;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor.Message;
import org.openide.awt.Mnemonics;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

public class HeapDumpProvider
{
  private static final Logger LOGGER = Logger.getLogger(HeapDumpProvider.class.getName());
  
  public void createHeapDump(final Application application, final boolean openView)
  {
    RequestProcessor.getDefault().post(new Runnable()
    {
      public void run()
      {
        Jvm jvm = JvmFactory.getJVMFor(application);
        if (!jvm.isTakeHeapDumpSupported())
        {
          DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Cannot_take_heap_dump") + DataSourceDescriptorFactory.getDescriptor(application).getName(), 0));
          
          return;
        }
        ProgressHandle pHandle = null;
        try
        {
          pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(HeapDumpProvider.class, "LBL_Creating_Heap_Dump"));
          
          pHandle.setInitialDelay(0);
          pHandle.start();
          try
          {
            File file = jvm.takeHeapDump();
            if ((file != null) && (file.isFile()))
            {
              final HeapDumpImpl heapDump = new HeapDumpImpl(file, application);
              application.getRepository().addDataSource(heapDump);
              if (openView) {
                SwingUtilities.invokeLater(new Runnable()
                {
                  public void run()
                  {
                    DataSourceWindowManager.sharedInstance().openDataSource(heapDump);
                  }
                });
              }
            }
            else
            {
              HeapDumpProvider.this.notifyHeapDumpFailed(application);
            }
          }
          catch (IOException ex)
          {
            HeapDumpProvider.LOGGER.log(Level.INFO, "createHeapDump-Application", ex);
            HeapDumpProvider.this.notifyHeapDumpFailed(application);
          }
        }
        finally
        {
          final ProgressHandle pHandleF;
          ProgressHandle pHandleF = pHandle;
          SwingUtilities.invokeLater(new Runnable()
          {
            public void run()
            {
              if (pHandleF != null) {
                pHandleF.finish();
              }
            }
          });
        }
      }
    });
  }
  
  public void createRemoteHeapDump(final Application application, final String dumpFile, final boolean customizeDumpFile)
  {
    RequestProcessor.getDefault().post(new Runnable()
    {
      public void run()
      {
        JmxModel model = JmxModelFactory.getJmxModelFor(application);
        if ((model == null) || (!model.isTakeHeapDumpSupported()))
        {
          DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Dump_failed"), 0));
          
          return;
        }
        String file = dumpFile;
        if (file == null) {
          file = HeapDumpProvider.defineRemoteFile(model, customizeDumpFile);
        }
        if (file == null) {
          return;
        }
        if (model.takeHeapDump(file)) {
          DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Dump_ok", file), 1));
        } else {
          DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(HeapDumpProvider.class, "MSG_Dump_save_failed", file), 0));
        }
      }
    });
  }
  
  private static String defineRemoteFile(JmxModel model, boolean customizeDumpFile)
  {
    String[] path = new String[1];
    path[0] = defaultHeapDumpPath(model);
    if (customizeDumpFile) {
      try
      {
        SwingUtilities.invokeAndWait(new Runnable()
        {
          public void run()
          {
            JLabel label = new JLabel();
            Mnemonics.setLocalizedText(label, NbBundle.getMessage(HeapDumpProvider.class, "MSG_Remote_heap_dump"));
            
            label.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
            JTextField field = new JTextField();
            label.setLabelFor(field);
            field.setText(val$path[0]);
            Dimension dim = field.getPreferredSize();
            width = 350;
            field.setPreferredSize(dim);
            field.selectAll();
            JPanel selector = new JPanel(new BorderLayout());
            selector.setBorder(BorderFactory.createEmptyBorder(15, 10, 5, 10));
            selector.add(label, "North");
            selector.add(field, "South");
            
            DialogDescriptor dd = new DialogDescriptor(selector, NbBundle.getMessage(HeapDumpProvider.class, "CAPTION_Remote_heap_dump"), true, null);
            
            Dialog d = DialogDisplayer.getDefault().createDialog(dd);
            d.pack();
            d.setVisible(true);
            
            val$path[0] = (dd.getValue() == DialogDescriptor.OK_OPTION ? field.getText() : null);
          }
        });
      }
      catch (Throwable t)
      {
        path[0] = null;
      }
    }
    return path[0];
  }
  
  private static String defaultHeapDumpPath(JmxModel model)
  {
    String fileName = HeapDumpSupport.getInstance().getCategory().createFileName();
    
    Properties sysprops = model.getSystemProperties();
    if (sysprops == null) {
      return fileName;
    }
    String heapDumpTarget = getHeapDumpTarget(sysprops);
    if ((heapDumpTarget == null) || (heapDumpTarget.isEmpty())) {
      return fileName;
    }
    String pathsep = sysprops.getProperty("file.separator");
    if (!heapDumpTarget.endsWith(pathsep)) {
      heapDumpTarget = heapDumpTarget + pathsep;
    }
    return heapDumpTarget + fileName;
  }
  
  private static String getHeapDumpTarget(Properties sysprops)
  {
    String targetDir = null;
    
    String osName = sysprops.getProperty("os.name");
    if (osName != null)
    {
1 2

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