Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Johnson2018-11-21 06:48:46 -0500
committerAndrew Johnson2018-11-21 06:50:11 -0500
commit684367ca98d93fade53b4a28500f191c023b16cc (patch)
tree9d889720466adcac1863fdf86672cd5a67a34265
parent954adb3dfd99626f0943069ac253ce134f2c7272 (diff)
downloadorg.eclipse.mat-684367ca98d93fade53b4a28500f191c023b16cc.tar.gz
org.eclipse.mat-684367ca98d93fade53b4a28500f191c023b16cc.tar.xz
org.eclipse.mat-684367ca98d93fade53b4a28500f191c023b16cc.zip
[317289] Extract information from Exception objects in the heap dumps
Simple resolver and a test Change-Id: I75348c81d618c1530f38302ce5e99ad4f710af8c
-rw-r--r--plugins/org.eclipse.mat.api/plugin.xml4
-rw-r--r--plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java39
-rw-r--r--plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java34
3 files changed, 72 insertions, 5 deletions
diff --git a/plugins/org.eclipse.mat.api/plugin.xml b/plugins/org.eclipse.mat.api/plugin.xml
index b3295922..ebe275f5 100644
--- a/plugins/org.eclipse.mat.api/plugin.xml
+++ b/plugins/org.eclipse.mat.api/plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?> <!--
- Copyright (c) 2008, 2010 SAP AG.
+ Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
Contributors:
SAP AG - initial API and implementation
+ Andrew Johnson/IBM Corporation - additional queries and resolvers
-->
<plugin>
@@ -110,6 +111,7 @@
<resolver impl="org.eclipse.mat.inspections.CommonNameResolver$MethodResolver" />
<resolver impl="org.eclipse.mat.inspections.CommonNameResolver$ConstructorResolver" />
<resolver impl="org.eclipse.mat.inspections.CommonNameResolver$ClassTypeResolver" />
+ <resolver impl="org.eclipse.mat.inspections.CommonNameResolver$StackTraceElementResolver" />
<!-- eclipse -->
<resolver impl="org.eclipse.mat.inspections.eclipse.EclipseNameResolver$EclipseClassLoaderResolver" />
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java
index 63c32d30..7c6bc046 100644
--- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java
+++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java
@@ -425,4 +425,43 @@ public class CommonNameResolver
return r.toString();
}
}
+
+ @Subject("java.lang.StackTraceElement")
+ public static class StackTraceElementResolver implements IClassSpecificNameResolver
+ {
+ public String resolve(IObject obj) throws SnapshotException
+ {
+ IObject cls = (IObject)obj.resolveValue("declaringClass");
+ IObject methodName = (IObject)obj.resolveValue("methodName");
+ if (cls == null || methodName == null)
+ return null;
+ int line = (Integer)obj.resolveValue("lineNumber");
+ IObject fn = (IObject)obj.resolveValue("fileName");
+ String ln;
+ if (line == -2)
+ ln = "(Compiled Code)";
+ else if (line == -3)
+ ln = "(Native Method)";
+ else if (line == -1)
+ ln = "";
+ else if (line == 0)
+ ln = "";
+ else
+ ln = Integer.toString(line);
+ String name;
+ if (fn == null)
+ if (line > 0)
+ name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "() " + ln;
+ else
+ name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "()";
+ else
+ if (line > 0)
+ name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "() ("
+ + fn.getClassSpecificName() + ":" + ln + ")";
+ else
+ name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "() ("
+ + fn.getClassSpecificName() + ")";
+ return name;
+ }
+ }
}
diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java
index 2337e7f7..061e1c37 100644
--- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java
+++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
@@ -455,7 +456,7 @@ public class GeneralSnapshotTests
}
/**
- * Test value of Strings
+ * Test value of {@link java.lang.String}
*/
@Test
public void stringToString() throws SnapshotException
@@ -488,7 +489,7 @@ public class GeneralSnapshotTests
}
/**
- * Test value of Strings
+ * Test value of {@link java.lang.StringBuilder}
*/
@Test
public void stringBuilderToString() throws SnapshotException
@@ -512,7 +513,7 @@ public class GeneralSnapshotTests
}
/**
- * Test value of StringBuffers
+ * Test value of {@link java.lang.StringBuffer}
*/
@Test
public void stringBufferToString() throws SnapshotException
@@ -534,7 +535,32 @@ public class GeneralSnapshotTests
}
assertThat(printables, greaterThanOrEqualTo(objects * 2 / 3));
}
-
+
+ /**
+ * Test value of {@link java.lang.StackTraceElement}
+ */
+ @Test
+ public void stackFrameElementResolver() throws SnapshotException
+ {
+ int objects = 0;
+ int printables = 0;
+ assumeThat(snapshot.getSnapshotInfo().getProperty("$heapFormat"), not(equalTo((Serializable)"DTFJ-PHD")));
+ Collection<IClass>tClasses = snapshot.getClassesByName("java.lang.StackTraceElement", true);
+ assumeNotNull(tClasses);
+ for (IClass cls : tClasses)
+ {
+ for (int id : cls.getObjectIds()) {
+ IObject o = snapshot.getObject(id);
+ String cn = o.getClassSpecificName();
+ if (cn != null && cn.length() > 0)
+ {
+ ++printables;
+ }
+ }
+ }
+ assertThat(printables, greaterThanOrEqualTo(objects * 2 / 3));
+ }
+
/**
* Test caching of snapshots
* @throws SnapshotException

Back to the top