< prev index next >

test/hotspot/jtreg/runtime/RedefineTests/RedefineRunningMethodsWithBacktrace.java

Print this page
rev 50608 : imported patch jep181-rev5

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -21,11 +21,11 @@
  * questions.
  */
 
 /*
  * @test
- * @bug 8087315
+ * @bug 8087315 8010319
  * @summary Get old method's stack trace elements after GC
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
  * @modules java.compiler
  *          java.instrument

@@ -34,55 +34,20 @@
  * @run main/othervm -javaagent:redefineagent.jar RedefineRunningMethodsWithBacktrace
  */
 
 import static jdk.test.lib.Asserts.*;
 
-public class RedefineRunningMethodsWithBacktrace {
-
-    public static String newB =
-                "class RedefineRunningMethodsWithBacktrace$B {" +
-                "   static int count1 = 0;" +
-                "   static int count2 = 0;" +
-                "   public static volatile boolean stop = false;" +
-                "  static void localSleep() { " +
-                "    try{ " +
-                "      Thread.currentThread().sleep(10);" +
-                "    } catch(InterruptedException ie) { " +
-                "    } " +
-                " } " +
-                "   public static void infinite() { " +
-                "       System.out.println(\"infinite called\");" +
-                "   }" +
-                "   public static void throwable() { " +
-                "       throw new RuntimeException(\"throwable called\");" +
-                "   }" +
-                "}";
+// package access top-level class to avoid problem with RedefineClassHelper
+// and nested types.
 
-    public static String evenNewerB =
-                "class RedefineRunningMethodsWithBacktrace$B {" +
-                "   static int count1 = 0;" +
-                "   static int count2 = 0;" +
-                "   public static volatile boolean stop = false;" +
-                "  static void localSleep() { " +
-                "    try{ " +
-                "      Thread.currentThread().sleep(1);" +
-                "    } catch(InterruptedException ie) { " +
-                "    } " +
-                " } " +
-                "   public static void infinite() { }" +
-                "   public static void throwable() { " +
-                "       throw new RuntimeException(\"throwable called\");" +
-                "   }" +
-                "}";
-
-    static class B {
+class RedefineRunningMethodsWithBacktrace_B {
         static int count1 = 0;
         static int count2 = 0;
         public static volatile boolean stop = false;
         static void localSleep() {
             try {
-                Thread.currentThread().sleep(10);//sleep for 10 ms
+            Thread.sleep(10);//sleep for 10 ms
             } catch(InterruptedException ie) {
             }
         }
 
         public static void infinite() {

@@ -109,11 +74,49 @@
             String s17 = new String ("string17");
             String s18 = new String ("string18");
             String s19 = new String ("string19");
             throw new RuntimeException("throwable called");
         }
-    }
+}
+
+public class RedefineRunningMethodsWithBacktrace {
+
+    public static String newB =
+                "class RedefineRunningMethodsWithBacktrace_B {" +
+                "   static int count1 = 0;" +
+                "   static int count2 = 0;" +
+                "   public static volatile boolean stop = false;" +
+                "  static void localSleep() { " +
+                "    try{ " +
+                "      Thread.sleep(10);" +
+                "    } catch(InterruptedException ie) { " +
+                "    } " +
+                " } " +
+                "   public static void infinite() { " +
+                "       System.out.println(\"infinite called\");" +
+                "   }" +
+                "   public static void throwable() { " +
+                "       throw new RuntimeException(\"throwable called\");" +
+                "   }" +
+                "}";
+
+    public static String evenNewerB =
+                "class RedefineRunningMethodsWithBacktrace_B {" +
+                "   static int count1 = 0;" +
+                "   static int count2 = 0;" +
+                "   public static volatile boolean stop = false;" +
+                "  static void localSleep() { " +
+                "    try{ " +
+                "      Thread.sleep(1);" +
+                "    } catch(InterruptedException ie) { " +
+                "    } " +
+                " } " +
+                "   public static void infinite() { }" +
+                "   public static void throwable() { " +
+                "       throw new RuntimeException(\"throwable called\");" +
+                "   }" +
+                "}";
 
     private static void touchRedefinedMethodInBacktrace(Throwable throwable) {
         System.out.println("touchRedefinedMethodInBacktrace: ");
         throwable.printStackTrace();  // this actually crashes with the bug in
                                       // java_lang_StackTraceElement::create()

@@ -131,11 +134,11 @@
     }
 
     private static Throwable getThrowableInB() {
         Throwable t = null;
         try {
-            B.throwable();
+            RedefineRunningMethodsWithBacktrace_B.throwable();
         } catch (Exception e) {
             t = e;
             // Don't print here because Throwable will cache the constructed stacktrace
             // e.printStackTrace();
         }

@@ -145,49 +148,49 @@
 
     public static void main(String[] args) throws Exception {
 
         new Thread() {
             public void run() {
-                B.infinite();
+                RedefineRunningMethodsWithBacktrace_B.infinite();
             }
         }.start();
 
         Throwable t1 = getThrowableInB();
 
-        RedefineClassHelper.redefineClass(B.class, newB);
+        RedefineClassHelper.redefineClass(RedefineRunningMethodsWithBacktrace_B.class, newB);
 
         System.gc();
 
         Throwable t2 = getThrowableInB();
 
-        B.infinite();
+        RedefineRunningMethodsWithBacktrace_B.infinite();
 
         for (int i = 0; i < 20 ; i++) {
             String s = new String("some garbage");
             System.gc();
         }
 
-        RedefineClassHelper.redefineClass(B.class, evenNewerB);
+        RedefineClassHelper.redefineClass(RedefineRunningMethodsWithBacktrace_B.class, evenNewerB);
         System.gc();
 
         Throwable t3 = getThrowableInB();
 
         for (int i = 0; i < 20 ; i++) {
-            B.infinite();
+            RedefineRunningMethodsWithBacktrace_B.infinite();
             String s = new String("some garbage");
             System.gc();
         }
 
         touchRedefinedMethodInBacktrace(t1);
         touchRedefinedMethodInBacktrace(t2);
         touchRedefinedMethodInBacktrace(t3);
 
         // purge should clean everything up.
-        B.stop = true;
+        RedefineRunningMethodsWithBacktrace_B.stop = true;
 
         for (int i = 0; i < 20 ; i++) {
-            B.infinite();
+            RedefineRunningMethodsWithBacktrace_B.infinite();
             String s = new String("some garbage");
             System.gc();
         }
     }
 }
< prev index next >