Merge
authordcubed
Fri, 20 Mar 2015 15:21:51 -0700
changeset 30328 a498dfbdce21
parent 29610 2cc3189821f7 (current diff)
parent 30327 14a05668b003 (diff)
child 30329 f483f76692f6
child 30330 923bbad32c58
Merge
--- a/jdk/test/java/lang/instrument/RedefineMethodInBacktrace.sh	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/java/lang/instrument/RedefineMethodInBacktrace.sh	Fri Mar 20 15:21:51 2015 -0700
@@ -77,7 +77,7 @@
 
 cat output.log
 
-MESG="Exception"
+MESG="Test failed"
 grep "$MESG" output.log
 result=$?
 if [ "$result" = 0 ]; then
--- a/jdk/test/java/lang/instrument/RedefineMethodInBacktraceApp.java	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/java/lang/instrument/RedefineMethodInBacktraceApp.java	Fri Mar 20 15:21:51 2015 -0700
@@ -46,12 +46,15 @@
  * could be freed, since class redefinition didn't know about the backtraces.
  */
 public class RedefineMethodInBacktraceApp {
+    static boolean failed = false;
+
     public static void main(String args[]) throws Exception {
         System.out.println("Hello from RedefineMethodInBacktraceApp!");
-
         new RedefineMethodInBacktraceApp().doTest();
 
-        System.exit(0);
+        if (failed) {
+            throw new Exception("ERROR: RedefineMethodInBacktraceApp failed.");
+        }
     }
 
     public static CountDownLatch stop = new CountDownLatch(1);
@@ -63,13 +66,18 @@
     }
 
     private void doMethodInBacktraceTest() throws Exception {
-        Throwable t = getThrowableFromMethodToRedefine();
+        Throwable t1 = getThrowableFromMethodToRedefine();
+        Throwable t2 = getThrowableFromMethodToDelete();
 
         doRedefine(RedefineMethodInBacktraceTarget.class);
 
         doClassUnloading();
 
-        touchRedefinedMethodInBacktrace(t);
+        System.out.println("checking backtrace for throwable from methodToRedefine");
+        touchRedefinedMethodInBacktrace(t1);
+
+        System.out.println("checking backtrace for throwable from methodToDelete");
+        touchRedefinedMethodInBacktrace(t2);
     }
 
     private void doMethodInBacktraceTestB() throws Exception {
@@ -115,6 +123,10 @@
             if (!(thrownFromMethodToRedefine instanceof RuntimeException)) {
                 throw e;
             }
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println("\nTest failed: unexpected exception: " + e.toString());
+            failed = true;
         }
         method = null;
         c = null;
@@ -122,15 +134,49 @@
         return thrownFromMethodToRedefine;
     }
 
+    private static Throwable getThrowableFromMethodToDelete() throws Exception {
+        Class<RedefineMethodInBacktraceTarget> c =
+                RedefineMethodInBacktraceTarget.class;
+        Method method = c.getMethod("callMethodToDelete");
+
+        Throwable thrownFromMethodToDelete = null;
+        try {
+            method.invoke(null);
+        } catch (InvocationTargetException e) {
+            thrownFromMethodToDelete = e.getCause();
+            if (!(thrownFromMethodToDelete instanceof RuntimeException)) {
+                throw e;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println("\nTest failed: unexpected exception: " + e.toString());
+            failed = true;
+        }
+        return thrownFromMethodToDelete;
+    }
+
+
     private static void doClassUnloading() {
         // This will clean out old, unused redefined methods.
         System.gc();
     }
 
     private static void touchRedefinedMethodInBacktrace(Throwable throwable) {
+        throwable.printStackTrace();
         // Make sure that we can convert the backtrace, which is referring to
         // the redefined method, to a  StrackTraceElement[] without crashing.
-        throwable.getStackTrace();
+        StackTraceElement[] stackTrace = throwable.getStackTrace();
+        for (int i = 0; i < stackTrace.length; i++) {
+          StackTraceElement frame = stackTrace[i];
+          if (frame.getClassName() == null) {
+              System.out.println("\nTest failed: trace[" + i + "].getClassName() returned null");
+              failed = true;
+          }
+          if (frame.getMethodName() == null) {
+              System.out.println("\nTest failed: trace[" + i + "].getMethodName() returned null");
+              failed = true;
+          }
+        }
     }
 
     private static void doRedefine(Class<?> clazz) throws Exception {
--- a/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTarget.java	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTarget.java	Fri Mar 20 15:21:51 2015 -0700
@@ -29,4 +29,13 @@
     public static void methodToRedefine() {
         throw new RuntimeException("Test exception");
     }
+
+    public static void callMethodToDelete() {
+        methodToDelete();
+    }
+
+    private static void methodToDelete() {
+        throw new RuntimeException("Test exception in methodToDelete");
+    }
+
 }
--- a/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTargetB.java	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTargetB.java	Fri Mar 20 15:21:51 2015 -0700
@@ -37,4 +37,16 @@
             // ignore, test will fail
         }
     }
+
+    public static void callMethodToDelete() {
+        try {
+            // signal that we are here
+            RedefineMethodInBacktraceApp.called.countDown();
+
+            // wait until test is done
+            RedefineMethodInBacktraceApp.stop.await();
+        } catch (InterruptedException ex) {
+            // ignore, test will fail
+        }
+    }
 }
--- a/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTargetB_2.java	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTargetB_2.java	Fri Mar 20 15:21:51 2015 -0700
@@ -28,4 +28,7 @@
 public class RedefineMethodInBacktraceTargetB {
     public static void methodToRedefine() {
     }
+
+    public static void callMethodToDelete() {
+    }
 }
--- a/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTarget_2.java	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/java/lang/instrument/RedefineMethodInBacktraceTarget_2.java	Fri Mar 20 15:21:51 2015 -0700
@@ -29,4 +29,8 @@
     public static void methodToRedefine() {
         throw new RuntimeException("Test exception 2");
     }
+
+    public static void callMethodToDelete() {
+        throw new RuntimeException("Test exception 2 in callMethodToDelete");
+    }
 }
--- a/jdk/test/sun/tools/jps/JpsHelper.java	Thu Mar 19 15:00:51 2015 -0700
+++ b/jdk/test/sun/tools/jps/JpsHelper.java	Fri Mar 20 15:21:51 2015 -0700
@@ -151,6 +151,7 @@
      */
     public static OutputAnalyzer jps(List<String> vmArgs, List<String> toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
+        launcher.addVMArg("-XX:+UsePerfData");
         if (vmArgs != null) {
             for (String vmArg : vmArgs) {
                 launcher.addVMArg(vmArg);