sa-jdi

n = codelet.getDescription();
            }
            if (description == null) {
              anno = anno + "\n(Unknown interpreter codelet)";
            } else {
              anno = anno + "\nExecuting in codelet \"" + description + "\" at PC = " + curFrame.getPC();
            }
          }
          else if (curVFrame.isCompiledFrame())
          {
            anno = anno + "\nExecuting at PC = " + curFrame.getPC();
          }
          if (startAddr == null) {
            startAddr = curFrame.getSP();
          }
          boolean shouldSkipOopMaps = false;
          if (curVFrame.isCompiledFrame())
          {
            CodeBlob cb = VM.getVM().getCodeCache().findBlob(curFrame.getPC());
            OopMapSet maps = cb.getOopMaps();
            if ((maps == null) || (maps.getSize() == 0L)) {
              shouldSkipOopMaps = true;
            }
          }
          HSDB.SignalInfo sigInfo = (HSDB.SignalInfo)interruptedFrameMap.get(curFrame);
          if (sigInfo != null) {
            anno = anno + "\n*** INTERRUPTED BY SIGNAL " + Integer.toString(sigNum) + " (" + sigName + ")";
          }
          JavaVFrame nextVFrame = curVFrame;
          Frame nextFrame = curFrame;
          do
          {
            curVFrame = nextVFrame;
            curFrame = nextFrame;
            try
            {
              Method method = curVFrame.getMethod();
              if ((interpreterFrameMethod == null) && (curVFrame.isInterpretedFrame())) {
                interpreterFrameMethod = method;
              }
              int bci = curVFrame.getBCI();
              String lineNumberAnno = "";
              if (method.hasLineNumberTable()) {
                if ((bci == -1) || ((bci >= 0) && (bci < method.getCodeSize()))) {
                  lineNumberAnno = ", line " + method.getLineNumberFromBCI(bci);
                } else {
                  lineNumberAnno = " (INVALID BCI)";
                }
              }
              anno = anno + "\n" + method.getMethodHolder().getName().asString() + "." + method.getName().asString() + method.getSignature().asString() + "\n@bci " + bci + lineNumberAnno;
            }
            catch (Exception e)
            {
              anno = anno + "\n(ERROR while iterating vframes for frame " + curFrame + ")";
            }
            nextVFrame = curVFrame.javaSender();
            if (nextVFrame != null) {
              nextFrame = nextVFrame.getFrame();
            }
          } while ((nextVFrame != null) && (nextFrame.equals(curFrame)));
          if (shouldSkipOopMaps) {
            anno = anno + "\nNOTE: null or empty OopMapSet found for this CodeBlob";
          }
          if (curFrame.getFP() != null)
          {
            annoPanel.addAnnotation(new Annotation(curFrame.getSP(), curFrame.getFP(), anno));
          }
          else if ((VM.getVM().getCPU().equals("x86")) || (VM.getVM().getCPU().equals("amd64")))
          {
            CodeBlob cb = VM.getVM().getCodeCache().findBlob(curFrame.getPC());
            Address sp = curFrame.getSP();
            if (Assert.ASSERTS_ENABLED) {
              Assert.that(cb.getFrameSize() > 0L, "CodeBlob must have non-zero frame size");
            }
            annoPanel.addAnnotation(new Annotation(sp, sp.addOffsetTo(cb.getFrameSize()), anno));
          }
          else
          {
            Assert.that(VM.getVM().getCPU().equals("ia64"), "only ia64 should reach here");
          }
          if (curFrame.isInterpretedFrame())
          {
            annoPanel.addAnnotation(new Annotation(curFrame.addressOfInterpreterFrameExpressionStack(), curFrame.addressOfInterpreterFrameTOS(), "Interpreter expression stack"));
            
            Address monBegin = curFrame.interpreterFrameMonitorBegin().address();
            Address monEnd = curFrame.interpreterFrameMonitorEnd().address();
            if (!monBegin.equals(monEnd)) {
              annoPanel.addAnnotation(new Annotation(monBegin, monEnd, "BasicObjectLocks"));
            }
            if (interpreterFrameMethod != null)
            {
              int offset = 1;
              annoPanel.addAnnotation(new Annotation(curFrame.addressOfInterpreterFrameLocal(offset), curFrame.addressOfInterpreterFrameLocal((int)interpreterFrameMethod.getMaxLocals() + offset), "Interpreter locals area for frame with SP = " + curFrame.getSP()));
            }
            String methodAnno = "Interpreter frame methodOop";
            if (interpreterFrameMethod == null) {
              methodAnno = methodAnno + " (BAD OOP)";
            }
            Address a = curFrame.addressOfInterpreterFrameMethod();
            annoPanel.addAnnotation(new Annotation(a, a.addOffsetTo(addressSize), methodAnno));
            a = curFrame.addressOfInterpreterFrameCPCache();
            annoPanel.addAnnotation(new Annotation(a, a.addOffsetTo(addressSize), "Interpreter constant pool cache"));
          }
          RegisterMap rm = (RegisterMap)vf.getRegisterMap().clone();
          if (!shouldSkipOopMaps) {
            try
            {
              curFrame.oopsDo(new AddressVisitor()
              {
                public void visitAddress(Address addr)
                {
                  if (Assert.ASSERTS_ENABLED) {
                    Assert.that(addr.andWithMask(VM.getVM().getAddressSize() - 1L) == null, "Address " + addr + "should have been aligned");
                  }
                  OopHandle handle = addr.getOopHandleAt(0L);
                  addAnnotation(addr, handle);
                }
                
                public void visitCompOopAddress(Address addr)
                {
                  if (Assert.ASSERTS_ENABLED) {
                    Assert.that(addr.andWithMask(VM.getVM().getAddressSize() - 1L) == null, "Address " + addr + "should have been aligned");
                  }
                  OopHandle handle = addr.getCompOopHandleAt(0L);
                  addAnnotation(addr, handle);
                }
                
                public void addAnnotation(Address addr, OopHandle handle)
                {
                  String anno = "null oop";
                  if (handle != null)
                  {
                    CollectedHeap collHeap = VM.getVM().getUniverse().heap();
                    boolean bad = true;
                    anno = "BAD OOP";
                    if ((collHeap instanceof GenCollectedHeap))
                    {
                      GenCollectedHeap heap = (GenCollectedHeap)collHeap;
                      for (int i = 0; i < heap.nGens(); i++) {
                        if (heap.getGen(i).isIn(handle))
                        {
                          if (i == 0) {
                            anno = "NewGen ";
                          } else if (i == 1) {
                            anno = "OldGen ";
                          } else {
                            anno = "Gen " + i + " ";
                          }
                          bad = false;
                          break;
                        }
                      }
                      if (bad) {
                        if (heap.permGen().isIn(handle))
                        {
                          anno = "PermGen ";
                          bad = false;
                        }
                      }
                    }
                    else if ((collHeap instanceof ParallelScavengeHeap))
                    {
                      ParallelScavengeHeap heap = (ParallelScavengeHeap)collHeap;
                      if (heap.youngGen().isIn(handle))
                      {
                        anno = "PSYoungGen ";
                        bad = false;
                      }
                      else if (heap.oldGen().isIn(handle))
                      {
                        anno = "PSOldGen ";
                        bad = false;
                      }
                      else if (heap.permGen().isIn(handle))
                      {
                        anno = "PSPermGen ";
                        bad = false;
                      }
                    }
                    else
                    {
                      anno = "[Unknown generation] ";
                      bad = false;
                    }
                    if (!bad) {
                      try
                      {
                        Oop oop = VM.getVM().getObjectHeap().newOop(handle);
                        if ((oop instanceof Instance))
                        {
                          anno = anno + oop.getKlass().getName().asString();
                        }
                        else
                        {
                          ByteArrayOutputStream bos = new ByteArrayOutputStream();
                          Oop.printOopValueOn(oop, new PrintStream(bos));
                          anno = anno + bos.toString();
                        }
                      }
                      catch (AddressException e)
                      {
                        anno = anno + "CORRUPT OOP";
                      }
                      catch (NullPointerException e)
                      {
                        anno = anno + "CORRUPT OOP (null pointer)";
                      }
                    }
                  }
                  annoPanel.addAnnotation(new Annotation(addr, addr.addOffsetTo(val$addressSize), anno));
                }
              }, rm);
            }
            catch (Exception e)
            {
              System.err.println("Error while performing oopsDo for frame " + curFrame);
              e.printStackTrace();
            }
          }
          vf = nextVFrame;
        }
        annoPanel.makeVisible(startAddr);
        annoPanel.repaint();
      }
    });
  }
  
  private void attach(String pidText)
  {
    try
    {
      this.pidText = pidText;
      pid = Integer.parseInt(pidText);
    }
    catch (NumberFormatException e)
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          HSDB.this.setMenuItemsEnabled(attachMenuItems, true);
          JOptionPane.showInternalMessageDialog(desktop, "Unable to parse process ID \"" + pidText + "\".\nPlease enter a number.", "Parse error", 2);
        }
      });
      return;
    }
    Runnable remover = new Runnable()
    {
      public void run()
      {
        attachWaitDialog.setVisible(false);
        desktop.remove(attachWaitDialog);
        attachWaitDialog = null;
      }
    };
    try
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          JOptionPane pane = new JOptionPane("Attaching to process " + pid + ", please wait...", 1);
          pane.setOptions(new Object[0]);
          attachWaitDialog = pane.createInternalFrame(desktop, "Attaching to Process");
          attachWaitDialog.show();
        }
      });
      agent.attach(pid);
      if (agent.getDebugger().hasConsole()) {
        showDbgConsoleMenuItem.setEnabled(true);
      }
      attached = true;
      SwingUtilities.invokeLater(remover);
    }
    catch (DebuggerException e)
    {
      SwingUtilities.invokeLater(remover);
      final String errMsg = formatMessage(e.getMessage(), 80);
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          HSDB.this.setMenuItemsEnabled(attachMenuItems, true);
          JOptionPane.showInternalMessageDialog(desktop, "Unable to connect to process ID " + pid + ":\n\n" + errMsg, "Unable to Connect", 2);
        }
      });
      agent.detach();
      return;
    }
    showThreadsDialog();
  }
  
  private void attach(String executablePath, final String corePath)
  {
    Runnable remover = new Runnable()
    {
      public void run()
      {
        attachWaitDialog.setVisible(false);
        desktop.remove(attachWaitDialog);
        attachWaitDialog = null;
      }
    };
    try
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          JOptionPane pane = new JOptionPane("Opening core file, please wait...", 1);
          pane.setOptions(new Object[0]);
          attachWaitDialog = pane.createInternalFrame(desktop, "Opening Core File");
          attachWaitDialog.show();
        }
      });
      agent.attach(executablePath, corePath);
      if (agent.getDebugger().hasConsole()) {
        showDbgConsoleMenuItem.setEnabled(true);
      }
      attached = true;
      SwingUtilities.invokeLater(remover);
    }
    catch (DebuggerException e)
    {
      SwingUtilities.invokeLater(remover);
      final String errMsg = formatMessage(e.getMessage(), 80);
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          HSDB.this.setMenuItemsEnabled(attachMenuItems, true);
          JOptionPane.showInternalMessageDialog(desktop, "Unable to open core file\n" + corePath + ":\n\n" + errMsg, "Unable to Open Core File", 2);
        }
      });
      agent.detach();
      return;
    }
    showThreadsDialog();
  }
  
  private void connect(final String remoteMachineName)
  {
    Runnable remover = new Runnable()
    {
      public void run()
      {
        attachWaitDialog.setVisible(false);
        desktop.remove(attachWaitDialog);
        attachWaitDialog = null;
      }
    };
    try
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          JOptionPane pane = new JOptionPane("Connecting to debug server, please wait...", 1);
          pane.setOptions(new Object[0]);
          attachWaitDialog = pane.createInternalFrame(desktop, "Connecting to Debug Server");
          attachWaitDialog.show();
        }
      });
      agent.attach(remoteMachineName);
      if (agent.getDebugger().hasConsole()) {
        showDbgConsoleMenuItem.setEnabled(true);
      }
      attached = true;
      SwingUtilities.invokeLater(remover);
    }
    catch (DebuggerException e)
    {
      SwingUtilities.invokeLater(remover);
      final String errMsg = formatMessage(e.getMessage(), 80);
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          HSDB.this.setMenuItemsEnabled(attachMenuItems, true);
          JOptionPane.showInternalMessageDialog(desktop, "Unable to connect to machine \"" + remoteMachineName + "\":\n\n" + errMsg, "Unable to Connect", 2);
        }
      });
      agent.detach();
      return;
    }
    showThreadsDialog();
  }
  
  private void detachDebugger()
  {
    if (!attached) {
      return;
    }
    agent.detach();
    attached = false;
  }
  
  private void detach()
  {
    detachDebugger();
    attachWaitDialog = null;
    threadsFrame = null;
    consoleFrame = null;
    setMenuItemsEnabled(attachMenuItems, true);
    setMenuItemsEnabled(detachMenuItems, false);
    toolsMenu.setEnabled(false);
    showDbgConsoleMenuItem.setEnabled(false);
    
    desktop.removeAll();
    desktop.invalidate();
    desktop.validate();
    desktop.repaint();
  }
  
  private void showThreadsDialog()
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        threadsFrame = new JInternalFrame("Java Threads");
        threadsFrame.setResizable(true);
        threadsFrame.setIconifiable(true);
        JavaThreadsPanel threadsPanel = new JavaThreadsPanel();
        threadsPanel.addPanelListener(HSDB.this);
        threadsFrame.getContentPane().add(threadsPanel);
        threadsFrame.setSize(500, 300);
        threadsFrame.pack();
        desktop.add(threadsFrame);
        GraphicsUtilities.moveToInContainer(threadsFrame, 0.75F, 0.25F, 0, 20);
        threadsFrame.show();
        HSDB.this.setMenuItemsEnabled(attachMenuItems, false);
        HSDB.this.setMenuItemsEnabled(detachMenuItems, true);
        toolsMenu.setEnabled(true);
        VM.registerVMInitializedObserver(new Observer()
        {
          public void update(Observable o, Object data)
          {
            computeRevPtrsMenuItem.setEnabled(true);
          }
        });
      }
    });
  }
  
  private void showObjectHistogram()
  {
    ObjectHistogram histo = new ObjectHistogram();
    ObjectHistogramCleanupThunk cleanup = new ObjectHistogramCleanupThunk(histo);
    
    doHeapIteration("Object Histogram", "Generating histogram...", histo, cleanup);
  }
  
  class ObjectHistogramCleanupThunk
    implements HSDB.CleanupThunk
  {
    ObjectHistogram histo;
    
    ObjectHistogramCleanupThunk(ObjectHistogram histo)
    {
      this.histo = histo;
    }
    
    public void heapIterationComplete()
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          JInternalFrame histoFrame = new JInternalFrame("Object Histogram");
          histoFrame.setResizable(true);
          histoFrame.setClosable(true);
          histoFrame.setIconifiable(true);
          histoFrame.getContentPane().setLayout(new BorderLayout());
          ObjectHistogramPanel panel = new ObjectHistogramPanel(histo);
          panel.addPanelListener(HSDB.this);
          histoFrame.getContentPane().add(panel);
          desktop.add(histoFrame);
          GraphicsUtilities.reshapeToAspectRatio(histoFrame, 1.3333334F, 0.6F, histoFrame.getParent().getSize());
          
          GraphicsUtilities.centerInContainer(histoFrame);
          histoFrame.show();
        }
      });
    }
  }
  
  public void showObjectsOfType(Klass type)
  {
    FindObjectByType finder = new FindObjectByType(type);
    FindObjectByTypeCleanupThunk cleanup = new FindObjectByTypeCleanupThunk(finder);
    
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    type.printValueOn(new PrintStream(bos));
    String typeName = bos.toString();
    doHeapIteration("Show Objects Of Type", "Finding instances of \"" + typeName + "\"", finder, cleanup);
  }
  
  class FindObjectByTypeCleanupThunk
    implements HSDB.CleanupThunk
  {
    FindObjectByType finder;
    
    FindObjectByTypeCleanupThunk(FindObjectByType finder)
    {
      this.finder = finder;
    }
    
    public void heapIterationComplete()
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          JInternalFrame finderFrame = new JInternalFrame("Show Objects of Type");
          finderFrame.getContentPane().setLayout(new BorderLayout());
          finderFrame.setResizable(true);
          finderFrame.setClosable(true);
          finderFrame.setIconifiable(true);
          ObjectListPanel panel = new ObjectListPanel(finder.getResults(), new HSDB.HeapProgress(HSDB.this, "Reverse Pointers Analysis"));
          
          panel.addPanelListener(HSDB.this);
          finderFrame.getContentPane().add(panel);
          desktop.add(finderFrame);
          GraphicsUtilities.reshapeToAspectRatio(finderFrame, 1.3333334F, 0.6F, finderFrame.getParent().getSize());
          
          GraphicsUtilities.centerInContainer(finderFrame);
          finderFrame.show();
        }
      });
    }
  }
  
  private void showDebuggerConsole()
  {
    if (consoleFrame == null)
    {
      consoleFrame = new JInternalFrame("Debugger Console");
      consoleFrame.setResizable(true);
      consoleFrame.setClosable(true);
      consoleFrame.setIconifiable(true);
      consoleFrame.getContentPane().setLayout(new BorderLayout());
      consoleFrame.getContentPane().add(new DebuggerConsolePanel(agent.getDebugger()), "Center");
      GraphicsUtilities.reshapeToAspectRatio(consoleFrame, 5.0F, 0.9F, desktop.getSize());
    }
    if (consoleFrame.getParent() == null) {
      desktop.add(consoleFrame);
    }
    consoleFrame.setVisible(true);
    consoleFrame.show();
    consoleFrame.getContentPane().getComponent(0).requestFocus();
  }
  
  private void showConsole()
  {
    CommandProcessor.DebuggerInterface di = new CommandProcessor.DebuggerInterface()
    {
      public HotSpotAgent getAgent()
      {
        return agent;
      }
      
      public boolean isAttached()
      {
        return attached;
      }
      
      public void attach(String pid)
      {
        attach(pid);
      }
      
      public void attach(String java, String core) {}
      
      public void detach()
      {
        HSDB.this.detachDebugger();
      }
      
      public void reattach()
      {
        if (attached) {
          HSDB.this.detachDebugger();
        }
        if (pidText != null) {
          attach(pidText);
        } else {
          attach(execPath, coreFilename);
        }
      }
    };
    showPanel("Command Line", new CommandProcessorPanel(new CommandProcessor(di, null, null, null)));
  }
  
  private void showFindByQueryPanel()
  {
    showPanel("Find Object by Query", new FindByQueryPanel());
  }
  
  private void showFindPanel()
  {
    showPanel("Find Pointer", new FindPanel());
  }
  
  private void showFindInHeapPanel()
  {
    showPanel("Find Address In Heap", new FindInHeapPanel());
  }
  
  private void showFindInCodeCachePanel()
  {
    showPanel("Find Address In Code Cache", new FindInCodeCachePanel());
  }
  
  private void showHeapParametersPanel()
  {
    showPanel("Heap Parameters", new HeapParametersPanel());
  }
  
  public void showThreadInfo(JavaThread thread)
  {
    showPanel("Info for " + thread.getThreadName(), new ThreadInfoPanel(thread));
  }
  
  public void showJavaStackTrace(JavaThread thread)
  {
    JavaStackTracePanel jstp = new JavaStackTracePanel();
    showPanel("Java stack trace for " + thread.getThreadName(), jstp);
    jstp.setJavaThread(thread);
  }
  
  private void showDeadlockDetectionPanel()
  {
    showPanel("Deadlock Detection", new DeadlockDetectionPanel());
  }
  
  private void showMonitorCacheDumpPanel()
  {
    showPanel("Monitor Cache Dump", new MonitorCacheDumpPanel());
  }
  
  public void showClassBrowser()
  {
    final JInternalFrame progressFrame = new JInternalFrame("Class Browser");
    progressFrame.setResizable(true);
    progressFrame.setClosable(true);
    progressFrame.setIconifiable(true);
    progressFrame.getContentPane().setLayout(new BorderLayout());
    ProgressBarPanel bar = new ProgressBarPanel("Generating class list ..");
    bar.setIndeterminate(true);
    progressFrame.getContentPane().add(bar, "Center");
    desktop.add(progressFrame);
    progressFrame.pack();
    GraphicsUtilities.centerInContainer(progressFrame);
    progressFrame.show();
    
    workerThread.invokeLater(new Runnable()
    {
      public void run()
      {
        HTMLGenerator htmlGen = new HTMLGenerator();
        InstanceKlass[] klasses = SystemDictionaryHelper.getAllInstanceKlasses();
        final String htmlText = htmlGen.genHTMLForKlassNames(klasses);
        SwingUtilities.invokeLater(new Runnable()
        {
          public void run()
          {
            JInternalFrame cbFrame = new JInternalFrame("Class Browser");
            cbFrame.getContentPane().setLayout(new BorderLayout());
            cbFrame.setResizable(true);
            cbFrame.setClosable(true);
            cbFrame.setIconifiable(true);
            ClassBrowserPanel cbPanel = new ClassBrowserPanel();
            cbFrame.getContentPane().add(cbPanel, "Center");
            desktop.remove(val$progressFrame);
            desktop.repaint();
            desktop.add(cbFrame);
            GraphicsUtilities.reshapeToAspectRatio(cbFrame, 1.25F, 0.85F, cbFrame.getParent().getSize());
            
            cbFrame.show();
            cbPanel.setClassesText(htmlText);
          }
        });
      }
    });
  }
  
  public void showCodeViewer()
  {
    showPanel("Code Viewer", new CodeViewerPanel(), 1.25F, 0.85F);
  }
  
  public void showCodeViewer(final Address address)
  {
    final CodeViewerPanel panel = new CodeViewerPanel();
    showPanel("Code Viewer", panel, 1.25F, 0.85F);
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        panel.viewAddress(address);
      }
    });
  }
  
  public void showMemoryViewer()
  {
    showPanel("Memory Viewer", new MemoryViewer(agent.getDebugger(), agent.getTypeDataBase().getAddressSize() == 8L));
  }
  
  public void showCommandLineFlags()
  {
    showPanel("Command Line Flags", new VMFlagsPanel());
  }
  
  public void showVMVersion()
  {
    showPanel("VM Version Info", new VMVersionInfoPanel());
  }
  
  public void showSystemProperties()
  {
    showPanel("System Properties", new SysPropsPanel());
  }
  
  private void showPanel(String name, JPanel panel)
  {
    showPanel(name, panel, 1.6666666F, 0.4F);
  }
  
  private void showPanel(String name, JPanel panel, float aspectRatio, float fillRatio)
  {
    JInternalFrame frame = new JInternalFrame(name);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.setResizable(true);
    frame.setClosable(true);
    frame.setIconifiable(true);
    frame.setMaximizable(true);
    frame.getContentPane().add(panel, "Center");
    desktop.add(frame);
    GraphicsUtilities.reshapeToAspectRatio(frame, aspectRatio, fillRatio, frame.getParent().getSize());
    GraphicsUtilities.randomLocation(frame);
    frame.show();
    if ((panel instanceof SAPanel)) {
      ((SAPanel)panel).addPanelListener(this);
    }
  }
  
  static abstract interface CleanupThunk
  {
    public abstract void heapIterationComplete();
  }
  
  class HeapProgress
    implements HeapProgressThunk
  {
    private JInternalFrame frame;
    private ProgressBarPanel bar;
    private String windowTitle;
    private String progressBarTitle;
    private HSDB.CleanupThunk cleanup;
    
    HeapProgress(String windowTitle)
    {
      this(windowTitle, "Percentage of heap visited", null);
    }
    
    HeapProgress(String windowTitle, String progressBarTitle)
    {
      this(windowTitle, progressBarTitle, null);
    }
    
    HeapProgress(String windowTitle, String progressBarTitle, HSDB.CleanupThunk cleanup)
    {
      this.windowTitle = windowTitle;
      this.progressBarTitle = progressBarTitle;
      this.cleanup = cleanup;
    }
    
    public void heapIterationFractionUpdate(final double fractionOfHeapVisited)
    {
      if (frame == null) {
        SwingUtilities.invokeLater(new Runnable()
        {
          public void run()
          {
            frame = new JInternalFrame(windowTitle);
            frame.setResizable(true);
            frame.setIconifiable(true);
            frame.getContentPane().setLayout(new BorderLayout());
            bar = new ProgressBarPanel(progressBarTitle);
            frame.getContentPane().add(bar, "Center");
            desktop.add(frame);
            frame.pack();
            GraphicsUtilities.constrainToSize(frame, frame.getParent().getSize());
            GraphicsUtilities.centerInContainer(frame);
            frame.show();
          }
        });
      }
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          bar.setValue(fractionOfHeapVisited);
        }
      });
    }
    
    public void heapIterationComplete()
    {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          desktop.remove(frame);
          desktop.repaint();
          if (VM.getVM().getRevPtrs() != null) {
            computeRevPtrsMenuItem.setEnabled(false);
          }
        }
      });
      if (cleanup != null) {
        cleanup.heapIterationComplete();
      }
    }
  }
  
  class VisitHeap
    implements Runnable
  {
    HeapVisitor visitor;
    
    VisitHeap(HeapVisitor visitor)
    {
      this.visitor = visitor;
    }
    
    public void run()
    {
      VM.getVM().getObjectHeap().iterate(visitor);
    }
  }
  
  private void doHeapIteration(String frameTitle, String progressBarText, HeapVisitor visitor, CleanupThunk cleanup)
  {
    ObjectHistogram histo = new ObjectHistogram();
    HeapProgress progress = new HeapProgress(frameTitle, progressBarText, cleanup);
    
    HeapVisitor progVisitor = new ProgressiveHeapVisitor(visitor, progress);
    workerThread.invokeLater(new VisitHeap(progVisitor));
  }
  
  private static JavaVFrame getLastJavaVFrame(JavaThread cur)
  {
    RegisterMap regMap = cur.newRegisterMap(true);
    Frame f = cur.getCurrentFrameGuess();
    if (f == null) {
      return null;
    }
    boolean imprecise = true;
    if ((f.isInterpretedFrame()) && (!f.isInterpretedFrameValid()))
    {
      System.err.println("Correcting for invalid interpreter frame");
      f = f.sender(regMap);
      imprecise = false;
    }
    VFrame vf = VFrame.newVFrame(f, regMap, cur, true, imprecise);
    if (vf == null)
    {
      System.err.println(" (Unable to create vframe for topmost frame guess)");
      return null;
    }
    if (vf.isJavaFrame()) {
      return (JavaVFrame)vf;
    }
    return vf.javaSender();
  }
  
  private static void dumpStack(JavaThread cur)
  {
    RegisterMap regMap = cur.newRegisterMap(true);
    Frame f = cur.getCurrentFrameGuess();
    PrintStream tty = System.err;
    while (f != null)
    {
      tty.print("Found ");
      if (f.isInterpretedFrame()) {
        tty.print("interpreted");
      } else if (f.isCompiledFrame()) {
        tty.print("compiled");
      } else if (f.isEntryFrame()) {
        tty.print("entry");
      } else if (f.isNativeFrame()) {
        tty.print("native");
      } else if (f.isGlueFrame()) {
        tty.print("glue");
      } else {
        tty.print("external");
      }
      tty.print(" frame with PC = " + f.getPC() + ", SP = " + f.getSP() + ", FP = " + f.getFP());
      if (f.isSignalHandlerFrameDbg()) {
        tty.print(" (SIGNAL HANDLER)");
      }
      tty.println();
      if (!f.isFirstFrame()) {
        f = f.sender(regMap);
      } else {
        f = null;
      }
    }
  }
  
  private static JMenuItem createMenuItem(String name, ActionListener l)
  {
    JMenuItem item = new JMenuItem(name);
    item.addActionListener(l);
    return item;
  }
  
  private String formatMessage(String message, int charsPerLine)
  {
    StringBuffer buf = new StringBuffer(message.length());
    StringTokenizer tokenizer = new StringTokenizer(message);
    int curLineLength = 0;
    while (tokenizer.hasMoreTokens())
    {
      String tok = tokenizer.nextToken();
      if (curLineLength + tok.length() > charsPerLine)
      {
        buf.append('\n');
        curLineLength = 0;
      }
      else if (curLineLength != 0)
      {
        buf.append(' ');
        curLineLength++;
      }
      buf.append(tok);
      curLineLength += tok.length();
    }
    return buf.toString();
  }
  
  private void setMenuItemsEnabled(List items, boolean enabled)
  {
    for (Iterator iter = items.iterator(); iter.hasNext();) {
      ((JMenuItem)iter.next()).setEnabled(enabled);
    }
  }
}

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

import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.utilities.Bits;

public class Bytecode
{
  Method method;
  int bci;
  static final int jintSize = 4;
  static final String spaces = " ";
  static final String comma = ", ";
  
  Bytecode(Method method, int bci)
  {
    this.method = method;
    this.bci = bci;
  }
  
  int alignedOffset(int offset)
  {
    return Bits.roundTo(bci + offset, 4) - bci;
  }
  
  int javaSignedWordAt(int offset)
  {
    return method.getBytecodeIntArg(bci + offset);
  }
  
  short javaShortAt(int offset)
  {
    return method.getBytecodeShortArg(bci + offset);
  }
  
  byte javaByteAt(int offset)
  {
    return method.getBytecodeByteArg(bci + offset);
  }
  
  public Method method()
  {
    return method;
  }
  
  public int bci()
  {
    return bci;
  }
  
  public int code()
  {
    return Bytecodes.codeAt(method(), bci());
  }
  
  public int javaCode()
  {
    return Bytecodes.javaCode(code());
  }
  
  public String getBytecodeName()
  {
    return Bytecodes.name(code());
  }
  
  public String getJavaBytecodeName()
  {
    return Bytecodes.name(javaCode());
  }
  
  public int getLength()
  {
    return Bytecodes.lengthAt(method(), bci());
  }
  
  public int getJavaLength()
  {
    return Bytecodes.javaLengthAt(method(), bci());
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer(getJavaBytecodeName());
    if (code() != javaCode())
    {
      buf.append(" ");
      buf.append('[');
      buf.append(getBytecodeName());
      buf.append(']');
    }
    return buf.toString();
  }
}

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

import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.utilities.Assert;

public class BytecodeANewArray
  extends BytecodeWithKlass
{
  BytecodeANewArray(Method method, int bci)
  {
    super(method, bci);
  }
  
  public Klass getKlass()
  {
    return super.getKlass();
  }
  
  public void verify()
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(isValid(), "check anewarray");
    }
  }
  
  public boolean isValid()
  {
    return javaCode() == 189;
  }
  
  public static BytecodeANewArray at(Method method, int bci)
  {
    BytecodeANewArray b = new BytecodeANewArray(method, bci);
    if (Assert.ASSERTS_ENABLED) {
      b.verify();
    }
    return b;
  }
  
  public static BytecodeANewArray atCheck(Method method, int bci)
  {
    BytecodeANewArray b = new BytecodeANewArray(method, bci);
    return b.isValid() ? b : null;
  }
  
  public static BytecodeANewArray at(BytecodeStream bcs)
  {
    return new BytecodeANewArray(bcs.method(), bcs.bci());
  }
}

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

import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.utilities.Assert;

public class BytecodeBipush
  extends Bytecode
{
  BytecodeBipush(Method method, int bci)
  {
    super(method, bci);
  }
  
  public byte getValue()
  {
    return javaByteAt(1);
  }
  
  public void verify()
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(isValid(), "check bipush");
    }
  }
  
  public boolean isValid()
  {
    return javaCode() == 16;
  }
  
  public static BytecodeBipush at(Method method, int bci)
  {
    BytecodeBipush b = new BytecodeBipush(method, bci);
    if (Assert.ASSERTS_ENABLED) {
      b.verify();
    }
    return b;
  }
  
  public static BytecodeBipush atCheck(Method method, int bci)
  {
    BytecodeBipush b = new BytecodeBipush(method, bci);
    return b.isValid() ? b : null;
  }
  
  public static BytecodeBipush at(BytecodeStream bcs)
  {
    return new BytecodeBipush(bcs.method(), bcs.bci());
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append("bipush");
    buf.append(" ");
    buf.append(Byte.toString(getValue()));
    return buf.toString();
  }
}

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

import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.utilities.Assert;

public class BytecodeCheckCast
  extends BytecodeWithKlass
{
  BytecodeCheckCast(Method method, int bci)
  {
    super(method, bci);
  }
  
  public InstanceKlass getCheckCastKlass()
  {
    return (InstanceKlass)getKlass();
  }
  
  public void verify()
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(isValid(), "check checkcast");
    }
  }
  
  public boolean isValid()
  {
    return javaCode() == 192;
  }
  
  public static BytecodeCheckCast at(Method method, int bci)
  {
    BytecodeCheckCast b = new BytecodeCheckCast(method, bci);
    if (Assert.ASSERTS_ENABLED) {
      b.verify();
    }
    return b;
  }
  
  public static BytecodeCheckCast atCheck(Method method, int bci)
  {
    BytecodeCheckCast b = new BytecodeCheckCast(method, bci);
    return b.isValid() ? b : null;
  }
  
  public static BytecodeCheckCast at(BytecodeStream bcs)
  {
    return new BytecodeCheckCast(bcs.method(), bcs.bci());
  }
}

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

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.utilities.Assert;

public class BytecodeDisassembler
{
  private Method method;
  private static Map bytecode2Class = new HashMap();
  
  private static void addBytecodeClass(int bytecode, Class clazz)
  {
    bytecode2Class.put(new Integer(bytecode), clazz);
  }
  
  private static Class getBytecodeClass(int bytecode)
  {
    return (Class)bytecode2Class.get(new Integer(bytecode));
  }
  
  static
  {
    addBytecodeClass(189, BytecodeANewArray.class);
    addBytecodeClass(16, BytecodeBipush.class);
    addBytecodeClass(192, BytecodeCheckCast.class);
    addBytecodeClass(180, BytecodeGetField.class);
    addBytecodeClass(178, BytecodeGetStatic.class);
    addBytecodeClass(167, BytecodeGoto.class);
    addBytecodeClass(200, BytecodeGotoW.class);
    addBytecodeClass(153, BytecodeIf.class);
    addBytecodeClass(154, BytecodeIf.class);
    addBytecodeClass(155, BytecodeIf.class);
    addBytecodeClass(156, BytecodeIf.class);
    addBytecodeClass(157, BytecodeIf.class);
    addBytecodeClass(158, BytecodeIf.class);
    addBytecodeClass(159, BytecodeIf.class);
    addBytecodeClass(160, BytecodeIf.class);
    addBytecodeClass(161, BytecodeIf.class);
    addBytecodeClass(162, BytecodeIf.class);
    addBytecodeClass(163, BytecodeIf.class);
    addBytecodeClass(164, BytecodeIf.class);
    addBytecodeClass(165, BytecodeIf.class);
    addBytecodeClass(166, BytecodeIf.class);
    addBytecodeClass(198, BytecodeIf.class);
    addBytecodeClass(199, BytecodeIf.class);
    addBytecodeClass(132, BytecodeIinc.class);
    addBytecodeClass(193, BytecodeInstanceOf.class);
    addBytecodeClass(182, BytecodeInvoke.class);
    addBytecodeClass(184, BytecodeInvoke.class);
    addBytecodeClass(183, BytecodeInvoke.class);
    addBytecodeClass(185, BytecodeInvoke.class);
    addBytecodeClass(186, BytecodeInvoke.class);
    addBytecodeClass(168, BytecodeJsr.class);
    addBytecodeClass(201, BytecodeJsrW.class);
    addBytecodeClass(21, BytecodeLoad.class);
    addBytecodeClass(22, BytecodeLoad.class);
    addBytecodeClass(23, BytecodeLoad.class);
    addBytecodeClass(24, BytecodeLoad.class);
    addBytecodeClass(25, BytecodeLoad.class);
    addBytecodeClass(18, BytecodeLoadConstant.class);
    addBytecodeClass(19, BytecodeLoadConstant.class);
    addBytecodeClass(20, BytecodeLoadConstant.class);
    addBytecodeClass(171, BytecodeLookupswitch.class);
    addBytecodeClass(197, BytecodeMultiANewArray.class);
    addBytecodeClass(187, BytecodeNew.class);
    addBytecodeClass(188, BytecodeNewArray.class);
    addBytecodeClass(181, BytecodePutField.class);
    addBytecodeClass(179, BytecodePutStatic.class);
    addBytecodeClass(169, BytecodeRet.class);
    addBytecodeClass(17, BytecodeSipush.class);
    addBytecodeClass(54, BytecodeStore.class);
    addBytecodeClass(55, BytecodeStore.class);
    addBytecodeClass(56, BytecodeStore.class);
    addBytecodeClass(57, BytecodeStore.class);
    addBytecodeClass(58, BytecodeStore.class);
    addBytecodeClass(170, BytecodeTableswitch.class);
  }
  
  public BytecodeDisassembler(Method method)
  {
    this.method = method;
  }
  
  public Method getMethod()
  {
    return method;
  }
  
  public void decode(BytecodeVisitor visitor)
  {
    visitor.prologue(method);
    
    BytecodeStream stream = new BytecodeStream(method);
    int javacode = -1;
    while ((javacode = stream.next()) != -1)
    {
      int bci = stream.bci();
      int hotspotcode = method.getBytecodeOrBPAt(bci);
      Class clazz = getBytecodeClass(javacode);
      if (clazz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd