Adding a flag to a jtreg test

Christian Hagedorn christian.hagedorn at oracle.com
Wed Apr 17 06:34:42 UTC 2024


Hi Joshua

For an IR test, you need to pass VM flags with `runWithFlags()` or `addFlags()`
[1] (also see [2] as en example). This will pass the flags to the dedicated test
VM that is spawned to run the tests.

Options specified in the `@run main/othervm` line are ignored. Apart from
explicitly adding flags with IR framework methods (e.g. `runWithFlags()`), the
test VM only takes VM flags that are passed from the outside with -javaoptions
and -vmoptions to jtreg which allows us to run the test with more flags in the
CI (the IR framework additionally reads the -Dtest.java.opts and -Dtest.vm.opts
properties to set up the test VM flags).

It is generally recommended to use `@run driver` for IR tests to ignore other
flags and not to stress the driver VM which only spawns the test VM and performs
IR matching afterward.

Best regards,
Christian


[1]
https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/README.md#23-test-vm-flags-and-scenarios
[2]
https://github.com/openjdk/jdk/blob/2fe2f3aff82f41a3b7942861e29ccbd3bcc68661/test/hotspot/jtreg/compiler/c2/irTests/TestSkeletonPredicates.java#L39-L40


On 16.04.24 23:55, Cao, Joshua wrote:
> I am writing a jtreg testcase that reproduces the issue in
> 
> https://bugs.openjdk.org/browse/JDK-8329797
> <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?
> 
> 


More information about the hotspot-compiler-dev mailing list