Skip to content

Commit c152474

Browse files
committed
8242311: use reproducible random in hotspot runtime tests
Reviewed-by: mdoerr Backport-of: c73934d
1 parent d064d8e commit c152474

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

test/hotspot/jtreg/runtime/NMT/HugeArenaTracking.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/*
2626
* @test
27-
* @key nmt jcmd
27+
* @key nmt jcmd randomness
2828
* @library /test/lib
2929
* @requires vm.bits == 64
3030
* @modules java.base/jdk.internal.misc
@@ -39,6 +39,7 @@
3939
import jdk.test.lib.process.ProcessTools;
4040
import jdk.test.lib.process.OutputAnalyzer;
4141
import jdk.test.lib.JDKToolFinder;
42+
import jdk.test.lib.Utils;
4243
import sun.hotspot.WhiteBox;
4344

4445
public class HugeArenaTracking {
@@ -60,7 +61,7 @@ public static void main(String args[]) throws Exception {
6061
output = new OutputAnalyzer(pb.start());
6162
output.shouldContain("Test (reserved=2KB, committed=2KB)");
6263

63-
Random rand = new Random();
64+
Random rand = Utils.getRandomInstance();
6465

6566
// Allocate 2GB+ from arena
6667
long total = 0;

test/hotspot/jtreg/runtime/NMT/MallocStressTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, 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
@@ -24,7 +24,7 @@
2424
/*
2525
* @test
2626
* @summary Stress test for malloc tracking
27-
* @key nmt jcmd stress
27+
* @key nmt jcmd stress randomness
2828
* @library /test/lib
2929
* @modules java.base/jdk.internal.misc
3030
* java.management
@@ -39,6 +39,7 @@
3939
import java.util.Random;
4040
import jdk.test.lib.JDKToolFinder;
4141
import jdk.test.lib.Platform;
42+
import jdk.test.lib.Utils;
4243
import jdk.test.lib.process.ProcessTools;
4344
import jdk.test.lib.process.OutputAnalyzer;
4445
import sun.hotspot.WhiteBox;
@@ -159,14 +160,14 @@ static class MallocMemory {
159160
}
160161

161162
static class AllocThread extends Thread {
163+
private final Random random = new Random(Utils.getRandomInstance().nextLong());
162164
AllocThread() {
163165
this.setName("MallocThread");
164166
this.start();
165167
}
166168

167169
// AllocThread only runs "Alloc" phase
168170
public void run() {
169-
Random random = new Random();
170171
// MallocStressTest.phase == TestPhase.alloc
171172
for (int loops = 0; loops < 100; loops++) {
172173
int r = random.nextInt(Integer.MAX_VALUE);
@@ -201,7 +202,7 @@ public void run() {
201202
}
202203

203204
static class ReleaseThread extends Thread {
204-
private Random random = new Random();
205+
private final Random random = new Random(Utils.getRandomInstance().nextLong());
205206
ReleaseThread() {
206207
this.setName("ReleaseThread");
207208
this.start();

test/hotspot/jtreg/runtime/NMT/MallocTrackingVerify.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, 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,7 +25,7 @@
2525
* @test
2626
* @bug 8054836
2727
* @summary Test to verify correctness of malloc tracking
28-
* @key nmt jcmd
28+
* @key nmt jcmd randomness
2929
* @library /test/lib
3030
* @modules java.base/jdk.internal.misc
3131
* java.management
@@ -41,6 +41,7 @@
4141
import jdk.test.lib.process.ProcessTools;
4242
import jdk.test.lib.process.OutputAnalyzer;
4343
import jdk.test.lib.JDKToolFinder;
44+
import jdk.test.lib.Utils;
4445

4546
import sun.hotspot.WhiteBox;
4647

@@ -58,7 +59,7 @@ public static void main(String args[]) throws Exception {
5859
String pid = Long.toString(ProcessTools.getProcessId());
5960
ProcessBuilder pb = new ProcessBuilder();
6061

61-
Random random = new Random();
62+
Random random = Utils.getRandomInstance();
6263
// Allocate small amounts of memory with random pseudo call stack
6364
while (mallocd_total < MAX_ALLOC) {
6465
int size = random.nextInt(31) + 1;

test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
/*
2626
* @test
27+
* @key randomness
2728
* @summary SharedArchiveConsistency
2829
* @requires vm.cds
2930
* @library /test/lib

test/hotspot/jtreg/runtime/appcds/cacheObject/GCStressApp.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, 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
@@ -24,6 +24,7 @@
2424

2525
import java.io.*;
2626
import java.util.*;
27+
import jdk.test.lib.Utils;
2728
import sun.hotspot.WhiteBox;
2829

2930
// All strings in archived classes are shared
@@ -43,7 +44,7 @@ static String get_shared_string1() {
4344

4445
static void allocAlot() {
4546
try {
46-
Random random = new Random();
47+
Random random = Utils.getRandomInstance();
4748
for (int i = 0; i < 1024 * 1024; i++) {
4849
int len = random.nextInt(10000);
4950
arr = new int[len];

test/hotspot/jtreg/runtime/appcds/cacheObject/GCStressTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, 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
@@ -24,15 +24,16 @@
2424

2525
/*
2626
* @test
27+
* @key randomness
2728
* @summary
2829
* @requires vm.cds.archived.java.heap
2930
* @library /test/lib /test/hotspot/jtreg/runtime/appcds
3031
* @modules java.base/jdk.internal.misc
3132
* @modules java.management
3233
* jdk.jartool/sun.tools.jar
33-
* @build sun.hotspot.WhiteBox
34+
* @build sun.hotspot.WhiteBox jdk.test.lib.Utils
3435
* @compile GCStressApp.java
35-
* @run driver ClassFileInstaller -jar gcstress.jar GCStressApp
36+
* @run driver ClassFileInstaller -jar gcstress.jar GCStressApp jdk.test.lib.Utils
3637
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
3738
* @run main GCStressTest
3839
*/

0 commit comments

Comments
 (0)