< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/TestCommon.java

Print this page

@@ -660,6 +660,26 @@
              }
              Files.createSymbolicLink(linkedJar.toPath(), origJar.toPath());
          }
          return linkedJar;
     }
+
+    // Remove all UL log messages from a JVM's STDOUT (such as those printed by -Xlog:cds)
+    static Pattern logPattern = Pattern.compile("^\\[[0-9. ]*s\\].*");
+    public static String filterOutLogs(String stdout) {
+        StringBuilder sb = new StringBuilder();
+        String prefix = "";
+        for (String line : stdout.split("\n")) {
+            if (logPattern.matcher(line).matches()) {
+                continue;
+            }
+            sb.append(prefix);
+            sb.append(line);
+            prefix = "\n";
+        }
+        if (stdout.endsWith("\n")) {
+            // String.split("A\n") returns {"A"}, not {"A", ""}.
+            sb.append("\n");
+        }
+        return sb.toString();
+    }
 }
< prev index next >