8222936: mlvm/anonloader/stress/randomBytecodes/Test.java fails due to "ERROR: There were 1 hangups during parsing."
authorhseigel
Fri, 31 May 2019 13:09:15 -0400
changeset 55130 e6e4de80e058
parent 55129 baad58d0cbfe
child 55131 9889f5e3ba00
8222936: mlvm/anonloader/stress/randomBytecodes/Test.java fails due to "ERROR: There were 1 hangups during parsing." Summary: Prevent false failures by blocking the test until either it times out or the loading thread finishes Reviewed-by: dholmes, coleenp
test/hotspot/jtreg/vmTestbase/vm/mlvm/anonloader/share/StressClassLoadingTest.java
--- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/anonloader/share/StressClassLoadingTest.java	Fri May 31 09:26:27 2019 -0700
+++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/anonloader/share/StressClassLoadingTest.java	Fri May 31 13:09:15 2019 -0400
@@ -27,6 +27,7 @@
 import java.util.Objects;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import nsk.share.test.Stresser;
 import vm.share.options.Option;
@@ -75,7 +76,7 @@
  */
 public abstract class StressClassLoadingTest extends MlvmTest {
     private static final String RESCUE_FILE_NAME = "_AnonkTestee01.class";
-    private static final String HUNG_CLASS_FILE_NAME = "hang%02d.class";
+    private static final String HUNG_CLASS_FILE_NAME = "hang.class";
 
     @Option(name = "iterations", default_value = "100000",
             description = "How many times generate a class and parse it")
@@ -135,8 +136,6 @@
     public boolean run() throws Exception {
         setupOptions(this);
 
-        int hangNum = 0;
-
         Stresser stresser = createStresser();
         stresser.start(iterations);
 
@@ -176,39 +175,39 @@
                 }
             };
 
-            parserThread.setDaemon(true);
             parserThread.start();
             parserThread.join(parseTimeout);
 
             if (parserThread.isAlive()) {
-                Env.complain("Killing parser thread");
+                Env.traceImportant("parser thread may be hung!");
                 StackTraceElement[] stack = parserThread.getStackTrace();
+                Env.traceImportant("parser thread stack len: " + stack.length);
                 Env.traceImportant(parserThread + " stack trace:");
                 for (int i = 0; i < stack.length; ++i) {
                     Env.traceImportant(parserThread + "\tat " + stack[i]);
                 }
 
+                Path savedClassPath = Paths.get(fileNamePrefix + HUNG_CLASS_FILE_NAME);
+
                 if (saveClassFile) {
-                    Files.move(rescueFile.toPath(), Paths.get(fileNamePrefix
-                            + String.format(HUNG_CLASS_FILE_NAME, hangNum)));
+                    Files.move(rescueFile.toPath(), savedClassPath);
+                    Env.traceImportant("There was a possible hangup during parsing."
+                        + " The class file, which produced the possible hangup, was saved as "
+                        + fileNamePrefix + HUNG_CLASS_FILE_NAME
+                        + "... in the test directory. You may want to analyse it "
+                        + "if this test times out.");
                 }
-                ++hangNum;
+
+                parserThread.join(); // Wait until either thread finishes or test times out.
+                if (saveClassFile) {
+                    savedClassPath.toFile().delete();
+                }
             } else if (saveClassFile) {
                 rescueFile.delete();
             }
         }
 
         stresser.finish();
-
-        if (hangNum > 0) {
-            Env.complain("There were " + hangNum + " hangups during parsing."
-                    + " The class files, which produced hangup were saved as "
-                    + fileNamePrefix + String.format(HUNG_CLASS_FILE_NAME, 0)
-                    + "... in the test directory. You may want to analyse them."
-                    + " Failing this test because of hangups.");
-            return false;
-        }
-
         return true;
     }