Adding a flag to a jtreg test

Cao, Joshua joshcao at amazon.com
Tue Apr 16 21:55:31 UTC 2024


I am writing a jtreg testcase that reproduces the issue in

https://bugs.openjdk.org/browse/JDK-8329797


```

diff --git a/test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java b/test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java
index 80dda306d3b..97b92c63744 100644
--- a/test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java
+++ b/test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java
@@ -34,7 +34,7 @@
  * @summary Test that if expressions are properly folded into min/max nodes
  * @requires os.arch != "riscv64"
  * @library /test/lib /
- * @run main compiler.c2.irTests.TestIfMinMax
+ * @run main/othervm -XX:+UseShenandoahGC compiler.c2.irTests.TestIfMinMax
  */
 public class TestIfMinMax {
     private static final Random RANDOM = Utils.getRandomInstance();
@@ -139,6 +139,31 @@ public long testMaxL2E(long a, long b) {
         return a <= b ? b : a;
     }

+    public class Dummy {
+        long l;
+        public Dummy(long l) { this.l = l; }
+    }
+
+    @Setup
+    Object[] setupDummyArray() {
+        Dummy[] arr = new Dummy[512];
+        for (int i = 0; i < 512; i++) {
+            arr[i] = new Dummy(RANDOM.nextLong());
+        }
+        return new Object[] { arr };
+    }
+
+    @Test
+    @Arguments(setup = "setupDummyArray")
+    @IR(failOn = { IRNode.MAX_L })
+    public long testMaxLAndBarrierInLoop(Dummy[] arr) {
+        long result = 0;
+        for (int i = 0; i < arr.length; ++i) {
+            result += Math.max(arr[i].l, 1);
+        }
+        return result;
+    }
+
     @Setup
     static Object[] setupIntArrays() {
         int[] a = new int[512];
```

If I run the test usually with `make CONF=linux-x86_64-server-fastdebug run-test
TEST=test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java`, the program
does not crash and the reproducer does not work. However, if I specify to use
`-XX:+UseShenandoahGC` from the command line, the crash is successfully
reproduced `make CONF=linux-x86_64-server-fastdebug run-test
TEST=test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java
JTREG="JAVA_OPTIONS=-XX:+UseShenandoahGC`. So I guess there is inconsistency
between the command line JVM arguments and those passed through `@run`.


Without the command line action, the logs show


```

/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/images/jdk/bin/java \\
        -Dtest.vm.opts='-XX:MaxRAMPercentage=1.25 -Dtest.boot.jdk=/home/joshcao/.sdkman/candidates/java/current -Djava.io.tmpdir=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/tmp' \\
        -Dtest.tool.vm.opts='-J-XX:MaxRAMPercentage=1.25 -J-Dtest.boot.jdk=/home/joshcao/.sdkman/candidates/java/current -J-Djava.io.tmpdir=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/tmp' \\
        -Dtest.compiler.opts= \\
        -Dtest.java.opts= \\
        -Dtest.jdk=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/images/jdk \\
        -Dcompile.jdk=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/images/jdk \\
        -Dtest.timeout.factor=4.0 \\
        -Dtest.nativepath=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/images/test/hotspot/jtreg/native \\
        -Dtest.root=/local/home/joshcao/jdk/jdk/test/hotspot/jtreg \\
        -Dtest.name=compiler/c2/irTests/TestIfMinMax.java \\
        -Dtest.file=/local/home/joshcao/jdk/jdk/test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java \\
        -Dtest.src=/local/home/joshcao/jdk/jdk/test/hotspot/jtreg/compiler/c2/irTests \\
        -Dtest.src.path=/local/home/joshcao/jdk/jdk/test/hotspot/jtreg/compiler/c2/irTests:/local/home/joshcao/jdk/jdk/test/lib:/local/home/joshcao/jdk/jdk/test/hotspot/jtreg \\
        -Dtest.classes=/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0/compiler/c2/irTests/TestIfMinMax.d \\
        -Dtest.class.path=/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0/compiler/c2/irTests/TestIfMinMax.d:/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0/test/lib:/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0 \\
        -Dtest.class.path.prefix=/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0/compiler/c2/irTests/TestIfMinMax.d:/local/home/joshcao/jdk/jdk/test/hotspot/jtreg/compiler/c2/irTests:/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0/test/lib:/local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/classes/0 \\
        -XX:MaxRAMPercentage=1.25 \\
        -Dtest.boot.jdk=/home/joshcao/.sdkman/candidates/java/current \\
        -Djava.io.tmpdir=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/tmp \\
        -Djava.library.path=/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/images/test/hotspot/jtreg/native \\
        -XX:+UseShenandoahGC \\
        com.sun.javatest.regtest.agent.MainWrapper /local/home/joshcao/jdk/jdk/build/linux-x86_64-server-fastdebug/test-support/jtreg_test_hotspot_jtreg_compiler_c2_irTests_TestIfMinMax_java/compiler/c2/irTests/TestIfMinMax.d/main.0.jta
result: Passed. Execution successful
```


When specifying `-XX:+UseShendoahGC`, I see
`-Dtest.java.opts=-XX:+UseShenandoahGC`. I would have expected that the
`-XX:+UseShenandoahGC` would propagate to the test VM. Any recommendations on
how to add Shenandoah flags to the jtreg test?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/hotspot-compiler-dev/attachments/20240416/67f025d5/attachment-0001.htm>


More information about the hotspot-compiler-dev mailing list