Ejemplo n.º 1
0
  public void showURL(String urls) {
    if (urls.startsWith(OPEN_THREADS_URL)) {
      urls = urls.substring(OPEN_THREADS_URL.length());
      String parts[] = urls.split("\\|"); // NOI18N
      String className = parts[0];
      String method = parts[1];
      int linenumber = Integer.parseInt(parts[2]);
      GoToSource.openSource(heapFragmentWalker.getHeapDumpProject(), className, method, linenumber);
    } else if (urls.startsWith(INSTANCE_URL_PREFIX)) {
      urls = urls.substring(INSTANCE_URL_PREFIX.length());

      String[] id = urls.split("/"); // NOI18N
      long instanceId = Long.parseLong(id[2]);
      Instance i = heapFragmentWalker.getHeapFragment().getInstanceByID(instanceId);

      if (i != null) {
        heapFragmentWalker.getClassesController().showInstance(i);
      } else {
        ProfilerDialogs.displayError(
            Bundle.AnalysisController_CannotResolveInstanceMsg(id[1], id[0]));
      }
    } else if (urls.startsWith(CLASS_URL_PREFIX)) {
      urls = urls.substring(CLASS_URL_PREFIX.length());
      String[] id = urls.split("/"); // NOI18N
      long jclsid = Long.parseLong(id[1]);

      JavaClass c = heapFragmentWalker.getHeapFragment().getJavaClassByID(jclsid);

      if (c != null) {
        heapFragmentWalker.getClassesController().showClass(c);
      } else {
        ProfilerDialogs.displayError(Bundle.AnalysisController_CannotResolveClassMsg(id[0]));
      }
    } else if (urls.startsWith(THREAD_URL_PREFIX)) {
      urls = urls.substring(THREAD_URL_PREFIX.length());
      String[] id = urls.split("/"); // NOI18N
      long threadid = Long.parseLong(id[1]);

      showInThreads(heapFragmentWalker.getHeapFragment().getInstanceByID(threadid));
    }
  }
Ejemplo n.º 2
0
  private synchronized String getStackTrace() {
    if (stackTrace == null) {
      boolean gotoSourceAvailable =
          heapFragmentWalker.getHeapDumpProject() != null && GoToSource.isAvailable();
      StringBuilder sb = new StringBuilder();
      Heap h = heapFragmentWalker.getHeapFragment();
      Collection<GCRoot> roots = h.getGCRoots();
      Map<ThreadObjectGCRoot, Map<Integer, List<JavaFrameGCRoot>>> javaFrameMap =
          computeJavaFrameMap(roots);
      // Use this to enable VisualVM color scheme for threads dumps:
      // sw.append("<pre style='color: #cc3300;'>"); // NOI18N
      sb.append("<pre>"); // NOI18N
      for (GCRoot root : roots) {
        if (root.getKind().equals(GCRoot.THREAD_OBJECT)) {
          ThreadObjectGCRoot threadRoot = (ThreadObjectGCRoot) root;
          Instance threadInstance = threadRoot.getInstance();
          if (threadInstance != null) {
            String threadName = getThreadName(threadInstance);
            Boolean daemon = (Boolean) threadInstance.getValueOfField("daemon"); // NOI18N
            Integer priority = (Integer) threadInstance.getValueOfField("priority"); // NOI18N
            Long threadId = (Long) threadInstance.getValueOfField("tid"); // NOI18N
            Integer threadStatus =
                (Integer) threadInstance.getValueOfField("threadStatus"); // NOI18N
            StackTraceElement stack[] = threadRoot.getStackTrace();
            Map<Integer, List<JavaFrameGCRoot>> localsMap = javaFrameMap.get(threadRoot);
            String style = "";

            if (threadRoot.equals(oome)) {
              style = "style=\"color: #FF0000\"";
            }
            // --- Use this to enable VisualVM color scheme for threads dumps: ---
            // sw.append("&nbsp;&nbsp;<span style=\"color: #0033CC\">"); // NOI18N
            sb.append("&nbsp;&nbsp;<a name=")
                .append(threadInstance.getInstanceId())
                .append("></a><b ")
                .append(style)
                .append(">"); // NOI18N
            // -------------------------------------------------------------------
            sb.append("\"")
                .append(htmlize(threadName))
                .append("\"")
                .append(daemon.booleanValue() ? " daemon" : "")
                .append(" prio=")
                .append(priority); // NOI18N
            if (threadId != null) {
              sb.append(" tid=").append(threadId); // NOI18N
            }
            if (threadStatus != null) {
              State tState = sun.misc.VM.toThreadState(threadStatus.intValue());
              sb.append(" ").append(tState); // NOI18N
            }
            // --- Use this to enable VisualVM color scheme for threads dumps: ---
            // sw.append("</span><br>"); // NOI18N
            sb.append("</b><br>"); // NOI18N
            // -------------------------------------------------------------------
            if (stack != null) {
              for (int i = 0; i < stack.length; i++) {
                String stackElHref;
                StackTraceElement stackElement = stack[i];
                String stackElementText = htmlize(stackElement.toString());

                if (gotoSourceAvailable) {
                  String className = stackElement.getClassName();
                  String method = stackElement.getMethodName();
                  int lineNo = stackElement.getLineNumber();
                  String stackUrl =
                      OPEN_THREADS_URL + className + "|" + method + "|" + lineNo; // NOI18N

                  // --- Use this to enable VisualVM color scheme for threads dumps: ---
                  // stackElHref = "&nbsp;&nbsp;<a style=\"color: #CC3300;\"
                  // href=\""+stackUrl+"\">"+stackElement+"</a>"; // NOI18N
                  stackElHref =
                      "<a href=\"" + stackUrl + "\">" + stackElementText + "</a>"; // NOI18N
                  // -------------------------------------------------------------------
                } else {
                  stackElHref = stackElementText;
                }
                sb.append("\tat ").append(stackElHref).append("<br>"); // NOI18N
                if (localsMap != null) {
                  List<JavaFrameGCRoot> locals = localsMap.get(Integer.valueOf(i));

                  if (locals != null) {
                    for (JavaFrameGCRoot localVar : locals) {
                      Instance localInstance = localVar.getInstance();

                      if (localInstance != null) {
                        sb.append("\t   Local Variable: ")
                            .append(printInstance(localInstance))
                            .append("<br>"); // NOI18N
                      } else {
                        sb.append(
                            "\t   Unknown Local Variable<br>"); // NOI18N
                      }
                    }
                  }
                }
              }
            }
          } else {
            sb.append("&nbsp;&nbsp;Unknown thread"); // NOI18N
          }
          sb.append("<br>"); // NOI18N
        }
      }
      sb.append("</pre>"); // NOI18N
      stackTrace = sb.toString();
    }
    return stackTrace;
  }
  private JPopupMenu createTablePopup() {
    JPopupMenu popup = new JPopupMenu();

    showInstanceItem = new JMenuItem(Bundle.ReferencesBrowserControllerUI_ShowInstanceItemText());
    showInstanceItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            performDefaultAction();
          }
        });
    showInstanceItem.setFont(popup.getFont().deriveFont(Font.BOLD));

    //        showClassItem = new JMenuItem(SHOW_IN_CLASSES_ITEM_TEXT);
    //        showClassItem.addActionListener(new ActionListener() {
    //                public void actionPerformed(ActionEvent e) {
    //                    int row = fieldsListTable.getSelectedRow();
    //
    //                    if (row != -1) {
    //                        HeapWalkerNode node = (HeapWalkerNode)
    // fieldsListTable.getTree().getPathForRow(row).getLastPathComponent();
    //
    //                        if (node instanceof HeapWalkerInstanceNode) {
    //                            HeapWalkerInstanceNode instanceNode = (HeapWalkerInstanceNode)
    // node;
    //
    //                            if (instanceNode instanceof ObjectFieldNode && ((ObjectFieldNode)
    // instanceNode).isStatic()) {
    //                                referencesBrowserController.navigateToClass(((ObjectFieldNode)
    // instanceNode).getFieldValue()
    //
    // .getField().getDeclaringClass());
    //                            } else if (instanceNode.hasInstance()) {
    //
    // referencesBrowserController.navigateToClass(instanceNode.getInstance().getJavaClass());
    //                            }
    //                        }
    //                    }
    //                }
    //            });

    showGcRootItem = new JMenuItem(Bundle.ReferencesBrowserControllerUI_ShowGcRootItemText());
    showGcRootItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int row = fieldsListTable.getSelectedRow();

            if (row != -1) {
              HeapWalkerNode node =
                  (HeapWalkerNode)
                      fieldsListTable.getTree().getPathForRow(row).getLastPathComponent();

              if (node instanceof InstanceNode) {
                InstanceNode instanceNode = (InstanceNode) node;

                if (instanceNode.hasInstance()) {
                  referencesBrowserController.navigateToNearestGCRoot(instanceNode);
                }
              }
            }
          }
        });

    showLoopOriginItem = new JMenuItem(Bundle.ReferencesBrowserControllerUI_ShowLoopItemText());
    showLoopOriginItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int row = fieldsListTable.getSelectedRow();

            if (row != -1) {
              HeapWalkerNode node =
                  (HeapWalkerNode)
                      fieldsListTable.getTree().getPathForRow(row).getLastPathComponent();

              if (node instanceof HeapWalkerInstanceNode
                  && ((HeapWalkerInstanceNode) node).isLoop()) {
                selectNode(((HeapWalkerInstanceNode) node).getLoopTo());
              }
            }
          }
        });

    // Copy Path From Root
    copyPathFromRootItem = new JMenuItem(Bundle.ReferencesBrowserControllerUI_CopyPathFromRoot());
    copyPathFromRootItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int row = fieldsListTable.getSelectedRow();
            if (row != -1) {
              TreePath path = fieldsListTable.getTree().getPathForRow(row);
              BrowserUtils.copyPathFromRoot(path);
            }
          };
        });

    if (GoToSource.isAvailable()) {
      showSourceItem = new JMenuItem(Bundle.ReferencesBrowserControllerUI_GoToSourceItemText());
      showSourceItem.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              int row = fieldsListTable.getSelectedRow();

              if (row != -1) {
                HeapWalkerNode node =
                    (HeapWalkerNode)
                        fieldsListTable.getTree().getPathForRow(row).getLastPathComponent();
                String className = node.getType();

                while (className.endsWith("[]")) {
                  className = className.substring(0, className.length() - 2); // NOI18N
                }
                Lookup.Provider p =
                    referencesBrowserController
                        .getReferencesControllerHandler()
                        .getHeapFragmentWalker()
                        .getHeapDumpProject();
                GoToSource.openSource(p, className, null, null);
              }
            }
          });
    }

    showInThreadsItem = new JMenuItem(Bundle.ReferencesBrowserControllerUI_ShowInThreadsItemText());
    showInThreadsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int row = fieldsListTable.getSelectedRow();

            if (row != -1) {
              HeapWalkerNode node =
                  (HeapWalkerNode)
                      fieldsListTable.getTree().getPathForRow(row).getLastPathComponent();
              if (node instanceof HeapWalkerInstanceNode) {
                Instance instance = ((HeapWalkerInstanceNode) node).getInstance();
                referencesBrowserController.showInThreads(instance);
              }
            }
          }
        });

    popup.add(showInstanceItem);
    //        popup.add(showClassItem);
    popup.add(showGcRootItem);
    popup.add(showInThreadsItem);
    popup.addSeparator();
    popup.add(copyPathFromRootItem);
    popup.addSeparator();
    popup.add(showLoopOriginItem);
    if (showSourceItem != null) popup.add(showSourceItem);

    return popup;
  }