Skip to content

Commit

Permalink
8242312: use reproducible random in hotspot gc tests
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
Backport-of: 5efa545
  • Loading branch information
GoeLin committed Apr 9, 2022
1 parent e8fbaad commit 7a02166
Show file tree
Hide file tree
Showing 51 changed files with 258 additions and 177 deletions.
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/gc/TestSoftReferencesBehaviorOnOOME.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,7 +25,7 @@

/**
* @test TestSoftReferencesBehaviorOnOOME
* @key gc
* @key gc randomness
* @summary Tests that all SoftReferences has been cleared at time of OOM.
* @requires vm.gc != "Z"
* @library /test/lib
Expand Down
10 changes: 5 additions & 5 deletions test/hotspot/jtreg/gc/epsilon/TestByteArrays.java
Expand Up @@ -25,9 +25,10 @@

/**
* @test TestByteArrays
* @key gc
* @key gc randomness
* @requires vm.gc.Epsilon & !vm.graal.enabled
* @summary Epsilon is able to allocate arrays, and does not corrupt their state
* @library /test/lib
*
* @run main/othervm -XX:+UseTLAB -Xmx256m
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
Expand Down Expand Up @@ -69,16 +70,15 @@
*/

import java.util.Random;
import jdk.test.lib.Utils;

public class TestByteArrays {

static long SEED = Long.getLong("seed", System.nanoTime());
static int COUNT = Integer.getInteger("count", 500); // ~100 MB allocation

static byte[][] arr;

public static void main(String[] args) throws Exception {
Random r = new Random(SEED);
Random r = Utils.getRandomInstance();

arr = new byte[COUNT * 100][];
for (int c = 0; c < COUNT; c++) {
Expand All @@ -88,7 +88,7 @@ public static void main(String[] args) throws Exception {
}
}

r = new Random(SEED);
r = new Random(Utils.SEED);
for (int c = 0; c < COUNT; c++) {
byte[] b = arr[c];
if (b.length != (c * 100)) {
Expand Down
9 changes: 5 additions & 4 deletions test/hotspot/jtreg/gc/epsilon/TestElasticTLAB.java
Expand Up @@ -25,9 +25,10 @@

/**
* @test TestElasticTLAB
* @key gc
* @key gc randomness
* @requires vm.gc.Epsilon & !vm.graal.enabled
* @summary Epsilon is able to work with/without elastic TLABs
* @library /test/lib
*
* @run main/othervm -Xmx256m
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
Expand Down Expand Up @@ -56,16 +57,16 @@
*/

import java.util.Random;
import jdk.test.lib.Utils;

public class TestElasticTLAB {

static long SEED = Long.getLong("seed", System.nanoTime());
static int COUNT = Integer.getInteger("count", 500); // ~100 MB allocation

static byte[][] arr;

public static void main(String[] args) throws Exception {
Random r = new Random(SEED);
Random r = Utils.getRandomInstance();

arr = new byte[COUNT * 100][];
for (int c = 0; c < COUNT; c++) {
Expand All @@ -75,7 +76,7 @@ public static void main(String[] args) throws Exception {
}
}

r = new Random(SEED);
r = new Random(Utils.SEED);
for (int c = 0; c < COUNT; c++) {
byte[] b = arr[c];
if (b.length != (c * 100)) {
Expand Down
10 changes: 5 additions & 5 deletions test/hotspot/jtreg/gc/epsilon/TestElasticTLABDecay.java
Expand Up @@ -25,9 +25,10 @@

/**
* @test TestElasticTLABDecay
* @key gc
* @key gc randomness
* @requires vm.gc.Epsilon & !vm.graal.enabled
* @summary Epsilon is able to work with/without elastic TLABs
* @library /test/lib
*
* @run main/othervm -Xmx256m
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
Expand All @@ -46,16 +47,15 @@
*/

import java.util.Random;
import jdk.test.lib.Utils;

public class TestElasticTLABDecay {

static long SEED = Long.getLong("seed", System.nanoTime());
static int COUNT = Integer.getInteger("count", 500); // ~100 MB allocation

static byte[][] arr;

public static void main(String[] args) throws Exception {
Random r = new Random(SEED);
Random r = Utils.getRandomInstance();

arr = new byte[COUNT * 100][];
for (int c = 0; c < COUNT; c++) {
Expand All @@ -66,7 +66,7 @@ public static void main(String[] args) throws Exception {
Thread.sleep(5);
}

r = new Random(SEED);
r = new Random(Utils.SEED);
for (int c = 0; c < COUNT; c++) {
byte[] b = arr[c];
if (b.length != (c * 100)) {
Expand Down
10 changes: 5 additions & 5 deletions test/hotspot/jtreg/gc/epsilon/TestObjects.java
Expand Up @@ -25,9 +25,10 @@

/**
* @test TestObjects
* @key gc
* @key gc randomness
* @requires vm.gc.Epsilon & !vm.graal.enabled
* @summary Epsilon is able to allocate objects, and does not corrupt their state
* @library /test/lib
*
* @run main/othervm -XX:+UseTLAB -Xmx256m
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
Expand Down Expand Up @@ -69,23 +70,22 @@
*/

import java.util.Random;
import jdk.test.lib.Utils;

public class TestObjects {

static long SEED = Long.getLong("seed", System.nanoTime());
static int COUNT = Integer.getInteger("count", 1_000_000); // ~24 MB allocation

static MyObject[] arr;

public static void main(String[] args) throws Exception {
Random r = new Random(SEED);
Random r = Utils.getRandomInstance();

arr = new MyObject[COUNT];
for (int c = 0; c < COUNT; c++) {
arr[c] = new MyObject(r.nextInt());
}

r = new Random(SEED);
r = new Random(Utils.SEED);
for (int c = 0; c < COUNT; c++) {
int expected = r.nextInt();
int actual = arr[c].id();
Expand Down
9 changes: 4 additions & 5 deletions test/hotspot/jtreg/gc/epsilon/TestRefArrays.java
Expand Up @@ -25,7 +25,7 @@

/**
* @test TestRefArrays
* @key gc
* @key gc randomness
* @requires vm.gc.Epsilon & !vm.graal.enabled
* @summary Epsilon is able to allocate arrays, and does not corrupt their state
* @library /test/lib
Expand Down Expand Up @@ -70,16 +70,15 @@
*/

import java.util.Random;
import jdk.test.lib.Utils;

public class TestRefArrays {

static long SEED = Long.getLong("seed", System.nanoTime());
static int COUNT = Integer.getInteger("count", 200); // ~100 MB allocation

static MyObject[][] arr;

public static void main(String[] args) throws Exception {
Random r = new Random(SEED);
Random r = Utils.getRandomInstance();

arr = new MyObject[COUNT * 100][];
for (int c = 0; c < COUNT; c++) {
Expand All @@ -89,7 +88,7 @@ public static void main(String[] args) throws Exception {
}
}

r = new Random(SEED);
r = new Random(Utils.SEED);
for (int c = 0; c < COUNT; c++) {
MyObject[] b = arr[c];
if (b.length != (c * 100)) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand Down Expand Up @@ -28,7 +28,7 @@
* @bug 8051973
* @summary Test to make sure that eager reclaim of humongous objects correctly clears
* mark bitmaps at reclaim.
* @key gc
* @key gc randomness
* @requires vm.gc.G1
* @library /test/lib
* @modules java.base/jdk.internal.misc
Expand All @@ -42,6 +42,7 @@

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;

// An object that has a few references to other instances to slow down marking.
class ObjectWithSomeRefs {
Expand Down Expand Up @@ -75,7 +76,7 @@ public static void main(String[] args) {
longList.add(new ObjectWithSomeRefs());
}

Random rnd = new Random();
Random rnd = Utils.getRandomInstance();
for (int i = 0; i < longList.size(); i++) {
int len = longList.size();
longList.get(i).other1 = longList.get(rnd.nextInt(len));
Expand Down
11 changes: 7 additions & 4 deletions test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,6 +25,7 @@

import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Utils;
Expand All @@ -40,10 +41,12 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import jdk.internal.misc.Unsafe; // for ADDRESS_SIZE
import sun.hotspot.WhiteBox;

public class TestShrinkAuxiliaryData {
private static final Random RNG = Utils.getRandomInstance();

private static final int REGION_SIZE = 1024 * 1024;

Expand Down Expand Up @@ -215,7 +218,7 @@ public void addRef(GarbageObject g) {

public void mutate() {
if (!payload.isEmpty() && payload.get(0).length > 0) {
payload.get(0)[0] = (byte) (Math.random() * Byte.MAX_VALUE);
payload.get(0)[0] = (byte) (RNG.nextDouble() * Byte.MAX_VALUE);
}
}
}
Expand Down Expand Up @@ -296,12 +299,12 @@ private void link() {
for (int i = 0; i < NUM_LINKS; i++) {
int regionToLink;
do {
regionToLink = (int) (Math.random() * REGIONS_TO_ALLOCATE);
regionToLink = (int) (RNG.nextDouble() * REGIONS_TO_ALLOCATE);
} while (regionToLink == regionNumber);

// get random garbage object from random region
garbage.get(ig).addRef(garbage.get(regionToLink
* NUM_OBJECTS_PER_REGION + (int) (Math.random()
* NUM_OBJECTS_PER_REGION + (int) (RNG.nextDouble()
* NUM_OBJECTS_PER_REGION)));
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData00.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,6 +25,7 @@

/**
* @test TestShrinkAuxiliaryData00
* @key randomness
* @bug 8038423 8061715
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData05.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,6 +25,7 @@

/**
* @test TestShrinkAuxiliaryData05
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData10.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,6 +25,7 @@

/**
* @test TestShrinkAuxiliaryData10
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData15.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -26,6 +26,7 @@
/**
* @test TestShrinkAuxiliaryData15
* @bug 8038423 8061715 8078405
* @key randomness
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values
* @requires vm.gc.G1
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData20.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,6 +25,7 @@

/**
* @test TestShrinkAuxiliaryData20
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/gc/g1/TestShrinkAuxiliaryData25.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,6 +25,7 @@

/**
* @test TestShrinkAuxiliaryData25
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values
Expand Down

1 comment on commit 7a02166

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.