Skip to content
Permalink
Browse files
8271471: [IR Framework] Rare occurrence of "<!-- safepoint while prin…
…ting -->" in PrintIdeal/PrintOptoAssembly can let tests fail

Reviewed-by: kvn, thartmann
  • Loading branch information
chhagedorn committed Aug 16, 2021
1 parent 0a03481 commit 3677734584859e1b4bea65f6719e839f949c9236
@@ -39,6 +39,8 @@
* Parse the hotspot pid file of the test VM to match all @IR rules.
*/
public class IRMatcher {
public static final String SAFEPOINT_WHILE_PRINTING_MESSAGE = "<!-- safepoint while printing -->";

private static final boolean PRINT_IR_ENCODING = Boolean.parseBoolean(System.getProperty("PrintIREncoding", "false"));
private static final Pattern IR_ENCODING_PATTERN =
Pattern.compile("(?<=" + IREncodingPrinter.START + "\r?\n)[\\s\\S]*(?=" + IREncodingPrinter.END + ")");
@@ -487,7 +489,16 @@ private void reportFailuresIfAny() {
+ "-".repeat(String.valueOf(failures).length()) + System.lineSeparator());
failuresBuilder.append(">>> Check stdout for compilation output of the failed methods")
.append(System.lineSeparator()).append(System.lineSeparator());
throw new IRViolationException(failuresBuilder.toString(), compilationsBuilder.toString());

// In some very rare cases, the VM output to regex match on contains "<!-- safepoint while printing -->"
// (emitted by ttyLocker::break_tty_for_safepoint) which might be the reason for a matching error.
// Do not throw an exception in this case (i.e. bailout).
String compilations = compilationsBuilder.toString();
if (!compilations.contains(SAFEPOINT_WHILE_PRINTING_MESSAGE)) {
throw new IRViolationException(failuresBuilder.toString(), compilationsBuilder.toString());
} else {
System.out.println("Found " + SAFEPOINT_WHILE_PRINTING_MESSAGE + ", bail out of IR matching");
}
}
}
}
@@ -42,7 +42,7 @@
* @requires vm.debug == true & vm.compMode != "Xint" & vm.compiler2.enabled & vm.flagless
* @summary Test IR matcher with different default IR node regexes. Use -DPrintIREncoding.
* Normally, the framework should be called with driver.
* @library /test/lib /
* @library /test/lib /testlibrary_tests /
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=240 -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
@@ -224,7 +224,7 @@ public static void main(String[] args) {

try {
runWithArgumentsFail(CompilationOutputOfFails.class);
shouldNotReach();
Utils.shouldHaveThrownException();
} catch (IRViolationException e) {
try {
boolean failed = false;
@@ -321,7 +321,7 @@ private static void runWithArgumentsFail(Class<?> clazz, String... args) {
private static void runCheck(String[] args , Constraint... constraints) {
try {
new TestFramework(constraints[0].getKlass()).addFlags(args).start(); // All constraints have the same class.
shouldNotReach();
Utils.shouldHaveThrownException();
} catch (IRViolationException e) {
checkConstraints(e, constraints);
} catch (Exception e) {
@@ -332,7 +332,7 @@ private static void runCheck(String[] args , Constraint... constraints) {
private static void runCheck(Constraint... constraints) {
try {
TestFramework.run(constraints[0].getKlass()); // All constraints have the same class.
shouldNotReach();
Utils.shouldHaveThrownException();
} catch (IRViolationException e) {
checkConstraints(e, constraints);
} catch (Exception e) {
@@ -357,7 +357,7 @@ private static void checkConstraints(IRViolationException e, Constraint[] constr
private static void runFailOnTestsArgs(Constraint constraint, String... args) {
try {
new TestFramework(constraint.getKlass()).addFlags(args).start(); // All constraints have the same class.
shouldNotReach();
Utils.shouldHaveThrownException();
} catch (IRViolationException e) {
try {
constraint.checkConstraint(e);
@@ -369,10 +369,6 @@ private static void runFailOnTestsArgs(Constraint constraint, String... args) {
}
}

public static void shouldNotReach() {
throw new ShouldNotReachException("Framework did not fail but it should have!");
}

public static void findIrIds(String output, String method, int... numbers) {
StringBuilder builder = new StringBuilder();
builder.append(method);
@@ -1412,12 +1408,6 @@ private void dontInline() {}
static int iFldStatic;
}

class ShouldNotReachException extends RuntimeException {
ShouldNotReachException(String s) {
super(s);
}
}


// Base class for any kind of constraint that is used to verify if the framework reports the correct IR failures.
abstract class Constraint {
@@ -34,7 +34,7 @@
* @test
* @requires vm.debug == true & vm.compMode != "Xint" & vm.compiler2.enabled & vm.flagless
* @summary Test different custom run tests.
* @library /test/lib /
* @library /test/lib /testlibrary_tests /
* @run driver ir_framework.tests.TestRunTests
*/

@@ -44,7 +44,7 @@ public static void main(String[] args) {
TestFramework.run();
try {
TestFramework.run(BadStandalone.class);
throw new RuntimeException("Should not reach");
Utils.shouldHaveThrownException();
} catch (IRViolationException e) {
String[] matches = { "test(int)", "test2(int)", "Failed IR Rules (2)"};
Arrays.stream(matches).forEach(m -> Asserts.assertTrue(e.getExceptionInfo().contains(m)));
@@ -31,7 +31,7 @@
* @test
* @requires vm.debug == true & vm.compMode != "Xint" & vm.compiler2.enabled & vm.flagless
* @summary Test scenarios with the framework.
* @library /test/lib /
* @library /test/lib /testlibrary_tests /
* @run driver ir_framework.tests.TestScenarios
*/

@@ -44,15 +44,27 @@ public static void main(String[] args) {
Scenario s3dup = new Scenario(3, "-XX:TLABRefillWasteFraction=53");
try {
new TestFramework().addScenarios(sDefault, s1, s2, s3).start();
Asserts.fail("Should not reach");
if (Utils.notAllBailedOut(sDefault, s1, s3)) {
// Not all scenarios had a bailout which means that at least one exception should have been thrown.
Asserts.fail("Should have thrown an exception");
}
} catch (TestRunException e) {
Asserts.assertTrue(e.getMessage().contains("The following scenarios have failed: #0, #1, #3"), e.getMessage());
if (!e.getMessage().contains("The following scenarios have failed: #0, #1, #3")) {
// Was there a bailout in a scenario? If not fail.
Asserts.assertTrue(Utils.anyBailedOut(sDefault, s1, s3), e.getMessage());
}
}
try {
new TestFramework().addScenarios(s1, s2, s3).start();
Asserts.fail("Should not reach");
if (Utils.notAllBailedOut(s1, s3)) {
// Not all scenarios had a bailout which means that at least one exception should have been thrown.
Asserts.fail("Should have thrown an exception");
}
} catch (TestRunException e) {
Asserts.assertTrue(e.getMessage().contains("The following scenarios have failed: #1, #3"), e.getMessage());
if (!e.getMessage().contains("The following scenarios have failed: #1, #3")) {
// Was there a bailout in a scenario? If not fail.
Asserts.assertTrue(Utils.anyBailedOut(sDefault, s1, s3), e.getMessage());
}
}
new TestFramework(ScenarioTest.class).addScenarios(s1, s2, s3).start();
try {
@@ -71,7 +83,6 @@ public static void main(String[] args) {
} catch (Exception e) {
Asserts.fail("Should not catch other exceptions");
}

}

@Test
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package ir_framework.tests;

import compiler.lib.ir_framework.Scenario;
import compiler.lib.ir_framework.driver.IRMatcher;
import compiler.lib.ir_framework.driver.TestVMProcess;
import jdk.test.lib.Asserts;

import java.util.Arrays;

public class Utils {
public static void shouldHaveThrownException() {
// Do not throw an exception if we hit a safepoint while printing which could possibly let the IR matching fail.
// This happens very rarely. If there is a problem with the test, then we will catch that on the next test invocation.
if (!TestVMProcess.getLastTestVMOutput().contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE)) {
Asserts.fail("Should have thrown exception");
}
}

/**
* Is there at least one scenario which hit a safepoint while printing (i.e. a bailout)?
*/
public static boolean anyBailedOut(Scenario... scenarios) {
return Arrays.stream(scenarios).anyMatch(s -> s.getTestVMOutput().contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE));
}

/**
* Is there at least one scenario which did not hit a safepoint while printing (i.e. a bailout)?
*/
public static boolean notAllBailedOut(Scenario... scenarios) {
return Arrays.stream(scenarios).anyMatch(s -> !s.getTestVMOutput().contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE));
}
}

1 comment on commit 3677734

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 3677734 Aug 16, 2021

Please sign in to comment.