private long computeFinalizers(Heap heap) { JavaClass finalizerClass = heap.getJavaClassByName("java.lang.ref.Finalizer"); // NOI18N if (finalizerClass != null) { Instance queue = (Instance) finalizerClass.getValueOfStaticField("queue"); // NOI18N if (queue != null) { Long len = (Long) queue.getValueOfField("queueLength"); // NOI18N if (len != null) { return len.longValue(); } } } return -1; }
private String printInstance(Instance in) { String className; JavaClass jcls = in.getJavaClass(); if (jcls == null) { return "unknown instance #" + in.getInstanceId(); // NOI18N } if (jcls.equals(getJavaClass())) { JavaClass javaClass = heapFragmentWalker.getHeapFragment().getJavaClassByID(in.getInstanceId()); if (javaClass != null) { className = javaClass.getName(); return "<a href='" + CLASS_URL_PREFIX + className + "/" + javaClass.getJavaClassId() + "'>class " + className + "</a>"; // NOI18N } } className = jcls.getName(); return "<a href='" + INSTANCE_URL_PREFIX + className + "/" + in.getInstanceNumber() + "/" + in.getInstanceId() + "' name='" + in.getInstanceId() + "'>" + className + '#' + in.getInstanceNumber() + "</a>"; // NOI18N }
private String getThreadName(final Instance threadInstance) { Object threadName = threadInstance.getValueOfField("name"); // NOI18N PrimitiveArrayInstance chars; int offset = 0; int len; if (threadName == null) { return "*null*"; // NOI18N } if (threadName instanceof PrimitiveArrayInstance) { chars = (PrimitiveArrayInstance) threadName; len = chars.getLength(); } else { Instance stringInstance = (Instance) threadName; assert stringInstance.getJavaClass().getName().equals(String.class.getName()); chars = (PrimitiveArrayInstance) stringInstance.getValueOfField("value"); // NOI18N if (chars != null) { Integer oi = (Integer) stringInstance.getValueOfField("offset"); // NOI18N Integer ci = (Integer) stringInstance.getValueOfField("count"); // NOI18N if (oi != null) { offset = oi.intValue(); } if (ci != null) { len = ci.intValue(); } else { len = chars.getLength(); } } else { return "*null*"; // NOI18N } } List<String> charsList = chars.getValues(); List<String> stringList = charsList.subList(offset, offset + len); char charArr[] = new char[stringList.size()]; int j = 0; for (String ch : stringList) { charArr[j++] = ch.charAt(0); } return new String(charArr); }
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(" <span style=\"color: #0033CC\">"); // NOI18N sb.append(" <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 = " <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(" Unknown thread"); // NOI18N } sb.append("<br>"); // NOI18N } } sb.append("</pre>"); // NOI18N stackTrace = sb.toString(); } return stackTrace; }
public String computeSummary() { File file = heapFragmentWalker.getHeapDumpFile(); Heap heap = heapFragmentWalker.getHeapFragment(); HeapSummary hsummary = heap.getSummary(); long finalizers = computeFinalizers(heap); int nclassloaders = 0; JavaClass cl = heap.getJavaClassByName("java.lang.ClassLoader"); // NOI18N NumberFormat numberFormat = (NumberFormat) NumberFormat.getInstance().clone(); numberFormat.setMaximumFractionDigits(1); oome = getOOMEThread(heap); if (cl != null) { nclassloaders = cl.getInstancesCount(); Collection<JavaClass> jcs = cl.getSubClasses(); for (JavaClass jc : jcs) { nclassloaders += jc.getInstancesCount(); } } String filename = " " // NOI18N + Bundle.OverviewController_FileItemString( file != null && file.exists() ? file.getAbsolutePath() : Bundle.OverviewController_NotAvailableMsg()); String filesize = " " // NOI18N + Bundle.OverviewController_FileSizeItemString( file != null && file.exists() ? numberFormat.format(file.length() / (1024 * 1024.0)) + " MB" : // NOI18N Bundle.OverviewController_NotAvailableMsg()); String dateTaken = " " // NOI18N + Bundle.OverviewController_DateTakenItemString( new Date(hsummary.getTime()).toString()); String liveBytes = " " // NOI18N + Bundle.OverviewController_TotalBytesItemString( numberFormat.format(hsummary.getTotalLiveBytes())); String liveClasses = " " // NOI18N + Bundle.OverviewController_TotalClassesItemString( numberFormat.format(heap.getAllClasses().size())); String liveInstances = " " // NOI18N + Bundle.OverviewController_TotalInstancesItemString( numberFormat.format(hsummary.getTotalLiveInstances())); String classloaders = " " // NOI18N + Bundle.OverviewController_ClassloadersItemString(numberFormat.format(nclassloaders)); String gcroots = " " // NOI18N + Bundle.OverviewController_GcRootsItemString( numberFormat.format(heap.getGCRoots().size())); String finalizersInfo = " " // NOI18N + Bundle.OverviewController_FinalizersItemString(numberFormat.format(finalizers)); String oomeString = ""; if (oome != null) { Instance thread = oome.getInstance(); String threadName = htmlize(getThreadName(thread)); String threadUrl = "<a href='" + THREAD_URL_PREFIX + thread.getJavaClass().getName() + "/" + thread.getInstanceId() + "'>" + threadName + "</a>"; // NOI18N oomeString = "<br><br> " // NOI18N + Bundle.OverviewController_OOMELabelString() + "<br> " + Bundle.OverviewController_OOMEItemString(threadUrl); } String memoryRes = Icons.getResource(ProfilerIcons.HEAP_DUMP); return "<b><img border='0' align='bottom' src='nbresloc:/" + memoryRes + "'> " // NOI18N + Bundle.OverviewController_SummaryString() + "</b><br><hr>" + dateTaken + "<br>" + filename + "<br>" + filesize + "<br><br>" + liveBytes // NOI18N + "<br>" + liveClasses + "<br>" + liveInstances + "<br>" + classloaders + "<br>" + gcroots + "<br>" + finalizersInfo + oomeString; // NOI18N }