Skip to content

Commit 933a776

Browse files
shivshah-oracleSendaoYan
authored andcommitted
8317124: use reproducible random in HotSpot tests
Reviewed-by: lmesnik, epavlova
1 parent 22b4687 commit 933a776

15 files changed

Lines changed: 62 additions & 24 deletions

test/hotspot/jtreg/compiler/c2/cmove/TestScalarConditionalMoveCmpObj.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2025, Rivos Inc. All rights reserved.
3+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +31,7 @@
3031

3132
/*
3233
* @test
34+
* @key randomness
3335
* @summary Test conditional move + compare object.
3436
* @library /test/lib /
3537
* @run driver ${test.main.class}
@@ -300,7 +302,7 @@ private static void shuffle(Object[] a, Object[] b) {
300302
for (int i = 0; i < a.length; i++) {
301303
b[i] = a[i];
302304
}
303-
Random rand = new Random();
305+
Random rand = Utils.getRandomInstance();
304306
for (int i = 0; i < SIZE; i++) {
305307
if (rand.nextInt(5) == 0) {
306308
Object t = b[i];

test/hotspot/jtreg/compiler/c2/gvn/TestBoolNodeGVN.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2024 Red Hat and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -26,9 +27,11 @@
2627
import compiler.lib.ir_framework.*;
2728

2829
import java.util.Random;
30+
import jdk.test.lib.Utils;
2931

3032
/**
3133
* @test
34+
* @key randomness
3235
* @bug 8327381
3336
* @summary Refactor boolean node tautology transformations
3437
* @library /test/lib /
@@ -139,7 +142,7 @@ public static boolean testShouldHaveCpmUCase4(int x, int m) {
139142
private static void testCorrectness() {
140143
int[] values = {
141144
-100, -42, -16, -8, -5, -1, 0, 1, 5, 8, 16, 42, 100,
142-
new Random().nextInt(), Integer.MAX_VALUE, Integer.MIN_VALUE
145+
Utils.getRandomInstance().nextInt(), Integer.MAX_VALUE, Integer.MIN_VALUE
143146
};
144147

145148
for (int x : values) {

test/hotspot/jtreg/compiler/conversions/TestMoveConvI2LOrCastIIThruAddIs.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,12 @@
2525

2626
import java.util.Objects;
2727
import java.util.Random;
28+
import jdk.test.lib.Utils;
2829
import jdk.test.lib.Asserts;
2930

3031
/*
3132
* @test
33+
* @key randomness
3234
* @bug 8254317 8256730
3335
* @requires vm.compiler2.enabled
3436
* @summary Exercises the optimization that moves integer-to-long conversions
@@ -157,7 +159,7 @@ public static void main(String[] args) {
157159
// We use a random number generator to avoid constant propagation in C2
158160
// and produce a variable ("a" in the different tests) with a finite,
159161
// small value range.
160-
Random rnd = new Random();
162+
Random rnd = Utils.getRandomInstance();
161163
switch(args[0]) {
162164
case "functional":
163165
// Small, functional tests.

test/hotspot/jtreg/compiler/gallery/NormalMapping.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
3333
import java.awt.image.DataBufferInt;
3434
import java.io.IOException;
3535
import java.util.Random;
36+
import jdk.test.lib.Utils;
3637
import javax.swing.JPanel;
3738
import java.awt.Font;
3839

@@ -78,7 +79,7 @@
7879
* - MyDrawingPanel: drawing all the parts to the screen.
7980
*/
8081
public class NormalMapping {
81-
public static Random RANDOM = new Random();
82+
public static Random RANDOM = Utils.getRandomInstance();
8283

8384
// Increasing this number will make the demo slower.
8485
public static final int NUMBER_OF_LIGHTS = 5;

test/hotspot/jtreg/compiler/hotcode/StressHotCodeCollector.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +25,7 @@
2425

2526
/*
2627
* @test
28+
* @key randomness
2729
* @library /test/lib /
2830
* @build jdk.test.whitebox.WhiteBox
2931
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
@@ -38,6 +40,7 @@
3840
import java.lang.reflect.Method;
3941
import java.util.ArrayList;
4042
import java.util.Random;
43+
import jdk.test.lib.Utils;
4144

4245
import jdk.test.lib.compiler.InMemoryJavaCompiler;
4346
import jdk.test.whitebox.WhiteBox;
@@ -89,7 +92,7 @@ public static void main(String[] args) throws Exception {
8992
generateCode();
9093

9194
long start = System.currentTimeMillis();
92-
Random random = new Random();
95+
Random random = Utils.getRandomInstance();
9396

9497
while (System.currentTimeMillis() - start < RUN_MILLIS) {
9598
for (TestMethod m : methods) {

test/hotspot/jtreg/compiler/intrinsics/float16/Binary16ConversionNaN_2.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2025, Rivos Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -24,6 +24,7 @@
2424

2525
/*
2626
* @test
27+
* @key randomness
2728
* @bug 8365206
2829
* @summary Verify NaN sign and significand bits are preserved across conversions,
2930
* float -> float16 -> float
@@ -55,6 +56,7 @@
5556
import jdk.test.whitebox.WhiteBox;
5657
import java.lang.reflect.Method;
5758
import java.util.Random;
59+
import jdk.test.lib.Utils;
5860

5961
public class Binary16ConversionNaN_2 {
6062

@@ -77,7 +79,7 @@ public static void main(String... argv) throws NoSuchMethodException {
7779
float[] nVal = new float[1024];
7880
float[] nRes = new float[1024];
7981

80-
Random rand = new Random();
82+
Random rand = Utils.getRandomInstance();
8183

8284
// A NaN has a nonzero significand
8385
for (int i = 1; i <= 0x3ff; i++) {

test/hotspot/jtreg/compiler/loopopts/TestPartialPeelAtUnsignedTestsNegativeLimit.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,17 +23,21 @@
2323

2424
/*
2525
* @test id=Xbatch
26+
* @key randomness
2627
* @bug 8332920
2728
* @summary Tests partial peeling at unsigned tests with limit being negative in exit tests "i >u limit".
29+
* @library /test/lib
2830
* @run main/othervm/timeout=480 -Xbatch -XX:-TieredCompilation
2931
* -XX:CompileOnly=*TestPartialPeel*::original*,*TestPartialPeel*::test*
3032
* compiler.loopopts.TestPartialPeelAtUnsignedTestsNegativeLimit
3133
*/
3234

3335
/*
3436
* @test id=Xcomp-run-inline
37+
* @key randomness
3538
* @bug 8332920
3639
* @summary Tests partial peeling at unsigned tests with limit being negative in exit tests "i >u limit".
40+
* @library /test/lib
3741
* @run main/othervm/timeout=480 -Xcomp -XX:-TieredCompilation
3842
* -XX:CompileOnly=*TestPartialPeel*::original*,*TestPartialPeel*::run*,*TestPartialPeel*::test*
3943
* -XX:CompileCommand=inline,*TestPartialPeelAtUnsignedTestsNegativeLimit::test*
@@ -43,24 +47,29 @@
4347

4448
/*
4549
* @test id=Xcomp-compile-test
50+
* @key randomness
4651
* @bug 8332920
4752
* @summary Tests partial peeling at unsigned tests with limit being negative in exit tests "i >u limit".
53+
* @library /test/lib
4854
* @run main/othervm/timeout=480 -Xcomp -XX:-TieredCompilation -XX:CompileOnly=*TestPartialPeel*::original*,*TestPartialPeel*::test*
4955
* compiler.loopopts.TestPartialPeelAtUnsignedTestsNegativeLimit
5056
*/
5157

5258
/*
5359
* @test id=vanilla
60+
* @key randomness
5461
* @bug 8332920
5562
* @requires vm.flavor == "server" & (vm.opt.TieredStopAtLevel == null | vm.opt.TieredStopAtLevel == 4)
5663
* @summary Tests partial peeling at unsigned tests with limit being negative in exit tests "i >u limit".
5764
* Only run this test with C2 since it is time-consuming and only tests a C2 issue.
65+
* @library /test/lib
5866
* @run main/timeout=480 compiler.loopopts.TestPartialPeelAtUnsignedTestsNegativeLimit
5967
*/
6068

6169
package compiler.loopopts;
6270

6371
import java.util.Random;
72+
import jdk.test.lib.Utils;
6473

6574
import static java.lang.Integer.*;
6675

@@ -69,7 +78,7 @@ public class TestPartialPeelAtUnsignedTestsNegativeLimit {
6978
static int iterations = 0;
7079
static int iFld2;
7180
static boolean flag;
72-
final static Random RANDOM = new Random();
81+
final static Random RANDOM = Utils.getRandomInstance();
7382

7483
public static void main(String[] args) {
7584
compareUnsigned(3, 3); // Load Integer class for -Xcomp

test/hotspot/jtreg/compiler/loopopts/superword/TestLargeCompilation.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,18 +25,21 @@
2525

2626
/*
2727
* @test
28+
* @key randomness
2829
* @bug 8327978
2930
* @summary Test compile time for large compilation, where SuperWord takes especially much time.
31+
* @library /test/lib
3032
* @run main/othervm/timeout=30 -Xbatch
3133
* -XX:CompileCommand=compileonly,compiler.loopopts.superword.TestLargeCompilation::test*
3234
* -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=1000
3335
* compiler.loopopts.superword.TestLargeCompilation
3436
*/
3537

3638
import java.util.Random;
39+
import jdk.test.lib.Utils;
3740

3841
public class TestLargeCompilation {
39-
private static final Random random = new Random();
42+
private static final Random random = Utils.getRandomInstance();
4043
static final int RANGE_CON = 1024 * 8;
4144

4245
static int init = 593436;

test/hotspot/jtreg/compiler/vectorapi/TestVectorMaskTrueCount.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2023, Arm Limited. All rights reserved.
3+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -46,7 +47,7 @@ public class TestVectorMaskTrueCount {
4647
private static final VectorSpecies<Double> SPECIES_D = DoubleVector.SPECIES_128;
4748
private static final VectorSpecies<Integer> SPECIES_I = IntVector.SPECIES_128;
4849
private static final int LENGTH = 1024;
49-
private static final Random RD = new Random();
50+
private static final Random RD = Utils.getRandomInstance();
5051
private static boolean[] ba;
5152
private static boolean[] bb;
5253

test/hotspot/jtreg/compiler/vectorization/TestRoundVectorDoubleRandom.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2024, Rivos Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -37,6 +37,7 @@
3737
package compiler.vectorization;
3838

3939
import java.util.Random;
40+
import jdk.test.lib.Utils;
4041
import static compiler.lib.golden.GoldenRound.golden_round;
4142
import compiler.lib.ir_framework.IR;
4243
import compiler.lib.ir_framework.IRNode;
@@ -47,7 +48,7 @@
4748
import compiler.lib.ir_framework.Warmup;
4849

4950
public class TestRoundVectorDoubleRandom {
50-
private static final Random rand = new Random();
51+
private static final Random rand = Utils.getRandomInstance();
5152

5253
private static final int ITERS = 11000;
5354
private static final int ARRLEN = rand.nextInt(4096-997) + 997;

0 commit comments

Comments
 (0)