8242312: use reproducible random in hotspot gc tests

Reviewed-by: kbarrett, tschatzl
This commit is contained in:
Igor Ignatyev 2020-04-14 12:50:09 -07:00
parent 1ad4834807
commit 5efa545d48
50 changed files with 259 additions and 180 deletions
test
hotspot/jtreg/gc
jdk/jdk/jfr/event/gc/detailed

@ -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
@ -25,7 +25,7 @@ package gc;
/**
* @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

@ -25,9 +25,10 @@ package gc.epsilon;
/**
* @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 -Xmx1g -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays
* @run main/othervm -Xmx1g -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays
@ -43,16 +44,15 @@ package gc.epsilon;
*/
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", 3000); // ~500 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++) {
@ -62,7 +62,7 @@ public class TestByteArrays {
}
}
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)) {

@ -25,9 +25,10 @@ package gc.epsilon;
/**
* @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 -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-EpsilonElasticTLAB gc.epsilon.TestElasticTLAB
* @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=1 gc.epsilon.TestElasticTLAB
@ -38,16 +39,15 @@ package gc.epsilon;
*/
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", 3000); // ~500 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++) {
@ -57,7 +57,7 @@ public class TestElasticTLAB {
}
}
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)) {

@ -25,9 +25,10 @@ package gc.epsilon;
/**
* @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 -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:-EpsilonElasticTLABDecay gc.epsilon.TestElasticTLABDecay
* @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:+EpsilonElasticTLABDecay -XX:EpsilonTLABDecayTime=1 gc.epsilon.TestElasticTLABDecay
@ -35,16 +36,15 @@ package gc.epsilon;
*/
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", 3000); // ~500 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++) {
@ -55,7 +55,7 @@ public class TestElasticTLABDecay {
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)) {

@ -25,9 +25,10 @@ package gc.epsilon;
/**
* @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 -Xmx128m -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects
* @run main/othervm -Xmx128m -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects
@ -43,23 +44,22 @@ package gc.epsilon;
*/
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();

@ -25,7 +25,7 @@ package gc.epsilon;
/**
* @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
@ -44,16 +44,15 @@ package gc.epsilon;
*/
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", 1000); // ~500 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++) {
@ -63,7 +62,7 @@ public class TestRefArrays {
}
}
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)) {

@ -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
@ -28,7 +28,7 @@ package gc.g1;
* @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
@ -42,6 +42,7 @@ import java.util.Random;
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 {
@ -75,7 +76,7 @@ class TestEagerReclaimHumongousRegionsClearMarkBitsReclaimRegionFast {
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));

@ -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
@ -25,6 +25,7 @@ package gc.g1;
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 jtreg.SkippedException;
@ -38,10 +39,12 @@ import java.util.ArrayList;
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;
@ -213,7 +216,7 @@ public class TestShrinkAuxiliaryData {
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);
}
}
}
@ -294,12 +297,12 @@ public class TestShrinkAuxiliaryData {
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)));
}
}

@ -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
@ -25,6 +25,7 @@ package gc.g1;
/**
* @test TestShrinkAuxiliaryData00
* @key randomness
* @bug 8038423 8061715
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values

@ -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
@ -25,6 +25,7 @@ package gc.g1;
/**
* @test TestShrinkAuxiliaryData05
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values

@ -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
@ -25,6 +25,7 @@ package gc.g1;
/**
* @test TestShrinkAuxiliaryData10
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values

@ -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
@ -26,6 +26,7 @@ package gc.g1;
/**
* @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

@ -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
@ -25,6 +25,7 @@ package gc.g1;
/**
* @test TestShrinkAuxiliaryData20
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values

@ -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
@ -25,6 +25,7 @@ package gc.g1;
/**
* @test TestShrinkAuxiliaryData25
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values

@ -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
@ -25,6 +25,7 @@ package gc.g1;
/**
* @test TestShrinkAuxiliaryData30
* @key randomness
* @bug 8038423 8061715 8078405
* @summary Checks that decommitment occurs for JVM with different
* G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -37,6 +37,7 @@ import java.util.stream.Collectors;
/**
* @test TestHumongousMovement
* @key randomness
* @summary Checks that Humongous objects are not moved during GC
* @requires vm.gc.G1
* @library /test/lib /

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
@ -35,6 +35,7 @@ import java.util.stream.Collectors;
/**
* @test TestNoAllocationsInHRegions
* @key randomness
* @summary Checks that no additional allocations are made in humongous regions
* @requires vm.gc.G1
* @library /test/lib /
@ -73,7 +74,7 @@ public class TestNoAllocationsInHRegions {
private static volatile Error error = null;
static class Allocator implements Runnable {
private final Random random;
private final List<byte[]> liveObjects = new LinkedList<>();
private int usedMemory = 0;
public final Runnable[] actions;
@ -89,12 +90,12 @@ public class TestNoAllocationsInHRegions {
private static final int DEAD_OBJECT_MAX_SIZE = G1_REGION_SIZE / 10;
public Allocator(int maxAllocationMemory) {
random = new Random(RND.nextLong());
actions = new Runnable[]{
// Allocation
() -> {
if (maxAllocationMemory - usedMemory != 0) {
int arraySize = RND.nextInt(Math.min(maxAllocationMemory - usedMemory,
int arraySize = random.nextInt(Math.min(maxAllocationMemory - usedMemory,
MAX_ALLOCATION_SIZE));
if (arraySize != 0) {
@ -131,7 +132,7 @@ public class TestNoAllocationsInHRegions {
// Deallocation
() -> {
if (liveObjects.size() != 0) {
int elementNum = RND.nextInt(liveObjects.size());
int elementNum = random.nextInt(liveObjects.size());
int shouldFree = liveObjects.get(elementNum).length;
liveObjects.remove(elementNum);
usedMemory -= shouldFree;
@ -140,7 +141,7 @@ public class TestNoAllocationsInHRegions {
// Dead object allocation
() -> {
int size = RND.nextInt(DEAD_OBJECT_MAX_SIZE);
int size = random.nextInt(DEAD_OBJECT_MAX_SIZE);
blackHole(new byte[size]);
},
@ -165,7 +166,7 @@ public class TestNoAllocationsInHRegions {
@Override
public void run() {
while (!shouldStop) {
actions[RND.nextInt(actions.length)].run();
actions[random.nextInt(actions.length)].run();
Thread.yield();
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
@ -42,7 +42,7 @@ import java.util.Random;
/**
* @test TestUnifiedLoggingSwitchStress
* @key gc stress
* @key gc stress randomness
* @summary Switches gc log level on fly while stressing memory/gc
* @requires !vm.flightRecorder
* @requires vm.gc != "Z"
@ -79,7 +79,7 @@ class MemoryStresser implements Runnable {
* Maximum size of dead (i.e. one which is made unreachable right after allocation) object
*/
private static final int DEAD_OBJECT_MAX_SIZE = G1_REGION_SIZE / 10;
private static final Random RND = Utils.getRandomInstance();
private final Random rnd = new Random(Utils.getRandomInstance().nextLong());
/**
* @param maxMemory maximum memory that could be allocated
@ -92,7 +92,7 @@ class MemoryStresser implements Runnable {
// Huge allocation
() -> {
if (liveHObjects.size() < H_ALLOCATION_MAX_COUNT) {
int allocationSize = RND.nextInt((int) (G1_REGION_SIZE * (H_ALLOCATION_REGION_SIZE - 0.5)
int allocationSize = rnd.nextInt((int) (G1_REGION_SIZE * (H_ALLOCATION_REGION_SIZE - 0.5)
* 0.9));
liveHObjects.add(new byte[allocationSize + G1_REGION_SIZE / 2]);
}
@ -101,7 +101,7 @@ class MemoryStresser implements Runnable {
// Huge deallocation
() -> {
if (liveHObjects.size() > 0) {
int elementNum = RND.nextInt(liveHObjects.size());
int elementNum = rnd.nextInt(liveHObjects.size());
liveHObjects.remove(elementNum);
}
},
@ -109,7 +109,7 @@ class MemoryStresser implements Runnable {
// Simple allocation
() -> {
if (maxSimpleAllocationMemory - usedMemory != 0) {
int arraySize = RND.nextInt(Math.min(maxSimpleAllocationMemory - usedMemory,
int arraySize = rnd.nextInt(Math.min(maxSimpleAllocationMemory - usedMemory,
MAX_SIMPLE_ALLOCATION_SIZE));
if (arraySize != 0) {
liveObjects.add(new byte[arraySize]);
@ -121,7 +121,7 @@ class MemoryStresser implements Runnable {
// Simple deallocation
() -> {
if (liveObjects.size() != 0) {
int elementNum = RND.nextInt(liveObjects.size());
int elementNum = rnd.nextInt(liveObjects.size());
int shouldFree = liveObjects.get(elementNum).length;
liveObjects.remove(elementNum);
usedMemory -= shouldFree;
@ -130,7 +130,7 @@ class MemoryStresser implements Runnable {
// Dead object allocation
() -> {
int size = RND.nextInt(DEAD_OBJECT_MAX_SIZE);
int size = rnd.nextInt(DEAD_OBJECT_MAX_SIZE);
blackHole(new byte[size]);
}
};
@ -138,7 +138,7 @@ class MemoryStresser implements Runnable {
@Override
public void run() {
while (!shouldStop) {
actions[RND.nextInt(actions.length)].run();
actions[rnd.nextInt(actions.length)].run();
Thread.yield();
}
@ -151,7 +151,7 @@ class LogLevelSwitcher implements Runnable {
public static volatile boolean shouldStop = false;
private final int logCount; // how many various log files will be used
private final String logFilePrefix; // name of log file will be logFilePrefix + index
private final Random RND = Utils.getRandomInstance();
private final Random rnd;
private final MBeanServer MBS = ManagementFactory.getPlatformMBeanServer();
/**
@ -161,7 +161,7 @@ class LogLevelSwitcher implements Runnable {
public LogLevelSwitcher(String logFilePrefix, int logCount) {
this.logCount = logCount;
this.logFilePrefix = logFilePrefix;
this.rnd = new Random(Utils.getRandomInstance().nextLong());
}
private static final String[] LOG_LEVELS = {"error", "warning", "info", "debug", "trace"};
@ -170,8 +170,8 @@ class LogLevelSwitcher implements Runnable {
public void run() {
while (!shouldStop) {
int fileNum = RND.nextInt(logCount);
int logLevel = RND.nextInt(LOG_LEVELS.length);
int fileNum = rnd.nextInt(logCount);
int logLevel = rnd.nextInt(LOG_LEVELS.length);
String outputCommand = String.format("output=%s_%d.log", logFilePrefix, fileNum);
String logLevelCommand = "what='gc*=" + LOG_LEVELS[logLevel] + "'";

@ -25,8 +25,9 @@
/*
* @test TestAllocHumongousFragment
* @summary Make sure Shenandoah can recover from humongous allocation fragmentation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -52,8 +53,9 @@
/*
* @test TestAllocHumongousFragment
* @summary Make sure Shenandoah can recover from humongous allocation fragmentation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
@ -96,8 +98,9 @@
/*
* @test TestAllocHumongousFragment
* @summary Make sure Shenandoah can recover from humongous allocation fragmentation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
@ -130,7 +133,7 @@
*/
import java.util.*;
import java.util.concurrent.*;
import jdk.test.lib.Utils;
public class TestAllocHumongousFragment {
@ -149,15 +152,15 @@ public class TestAllocHumongousFragment {
objects = new ArrayList<>();
long current = 0;
Random r = new Random();
Random rng = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
while (current > LIVE_MB * 1024 * 1024) {
int idx = ThreadLocalRandom.current().nextInt(objects.size());
int idx = rng.nextInt(objects.size());
int[] remove = objects.remove(idx);
current -= remove.length * 4 + 16;
}
int[] newObj = new int[min + r.nextInt(max - min)];
int[] newObj = new int[min + rng.nextInt(max - min)];
current += newObj.length * 4 + 16;
objects.add(newObj);
sink = new Object();

@ -25,8 +25,9 @@
/*
* @test TestAllocIntArrays
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -52,8 +53,9 @@
/*
* @test TestAllocIntArrays
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
@ -105,8 +107,9 @@
/*
* @test TestAllocIntArrays
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
@ -143,6 +146,7 @@
*/
import java.util.Random;
import jdk.test.lib.Utils;
public class TestAllocIntArrays {
@ -155,7 +159,7 @@ public class TestAllocIntArrays {
final int max = 384 * 1024;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
Random r = new Random();
Random r = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
sink = new int[min + r.nextInt(max - min)];
}

@ -25,8 +25,9 @@
/*
* @test TestAllocObjectArrays
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -47,12 +48,14 @@
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
* -XX:-ShenandoahDegeneratedGC
* TestAllocObjectArrays
*/
/*
* @test TestAllocObjectArrays
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
@ -104,8 +107,9 @@
/*
* @test TestAllocObjectArrays
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
@ -142,6 +146,7 @@
*/
import java.util.Random;
import jdk.test.lib.Utils;
public class TestAllocObjectArrays {
@ -154,7 +159,7 @@ public class TestAllocObjectArrays {
final int max = 384 * 1024;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
Random r = new Random();
Random r = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
sink = new Object[min + r.nextInt(max - min)];
}

@ -162,8 +162,6 @@
* TestAllocObjects
*/
import java.util.Random;
public class TestAllocObjects {
static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation

@ -22,12 +22,14 @@
*
*/
import java.util.concurrent.*;
import java.util.Random;
import jdk.test.lib.Utils;
/*
* @test TestArrayCopyStress
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:TieredStopAtLevel=0 -Xmx16m TestArrayCopyStress
*/
@ -57,10 +59,10 @@ public class TestArrayCopyStress {
for (int i = 0; i < ARRAY_SIZE; i++) {
array[i] = new Foo(i);
}
int src_idx = ThreadLocalRandom.current().nextInt(0, ARRAY_SIZE);
int dst_idx = ThreadLocalRandom.current().nextInt(0, ARRAY_SIZE);
int len = ThreadLocalRandom.current().nextInt(0, Math.min(ARRAY_SIZE - src_idx, ARRAY_SIZE - dst_idx));
Random rng = Utils.getRandomInstance();
int src_idx = rng.nextInt(ARRAY_SIZE);
int dst_idx = rng.nextInt(ARRAY_SIZE);
int len = rng.nextInt(Math.min(ARRAY_SIZE - src_idx, ARRAY_SIZE - dst_idx));
System.arraycopy(array, src_idx, array, dst_idx, len);
for (int i = 0; i < ARRAY_SIZE; i++) {

@ -24,8 +24,10 @@
/*
* @test TestElasticTLAB
* @key randomness
* @summary Test that Shenandoah is able to work with elastic TLABs
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:-UseTLAB -XX:-ShenandoahElasticTLAB -XX:+ShenandoahVerify TestElasticTLAB
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:-UseTLAB -XX:-ShenandoahElasticTLAB TestElasticTLAB
@ -38,6 +40,7 @@
*/
import java.util.Random;
import jdk.test.lib.Utils;
public class TestElasticTLAB {
@ -50,7 +53,7 @@ public class TestElasticTLAB {
final int max = 384 * 1024;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
Random r = new Random();
Random r = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
sink = new int[min + r.nextInt(max - min)];
}

@ -25,8 +25,9 @@
/*
* @test TestHeapUncommit
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -52,8 +53,9 @@
/*
* @test TestHeapUncommit
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
@ -85,8 +87,9 @@
/*
* @test TestHeapUncommit
* @summary Acceptance tests: collector can withstand allocation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
@ -104,8 +107,9 @@
/*
* @test TestHeapUncommit
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
* @library /test/lib
*
* @run main/othervm -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:+UseLargePages
* -XX:+UseShenandoahGC
@ -123,6 +127,7 @@
*/
import java.util.Random;
import jdk.test.lib.Utils;
public class TestHeapUncommit {
@ -135,7 +140,7 @@ public class TestHeapUncommit {
final int max = 384 * 1024;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
Random r = new Random();
Random r = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
sink = new int[min + r.nextInt(max - min)];
}

@ -24,8 +24,9 @@
/*
* @test TestHumongousThreshold
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g
* -XX:+ShenandoahVerify
@ -69,8 +70,9 @@
/*
* @test TestHumongousThreshold
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g
* -XX:ObjectAlignmentInBytes=16 -XX:+ShenandoahVerify
@ -106,6 +108,7 @@
*/
import java.util.Random;
import jdk.test.lib.Utils;
public class TestHumongousThreshold {
@ -118,7 +121,7 @@ public class TestHumongousThreshold {
final int max = 384 * 1024;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
Random r = new Random();
Random r = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
sink = new int[min + r.nextInt(max - min)];
}

@ -25,8 +25,9 @@
/*
* @test TestLargeObjectAlignment
* @summary Shenandoah crashes with -XX:ObjectAlignmentInBytes=16
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
* @library /test/lib
*
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xint TestLargeObjectAlignment
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -XX:-TieredCompilation TestLargeObjectAlignment
@ -36,7 +37,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.Random;
import jdk.test.lib.Utils;
public class TestLargeObjectAlignment {
@ -50,8 +52,9 @@ public class TestLargeObjectAlignment {
objects = new Object[SLABS_COUNT];
long start = System.nanoTime();
Random rng = Utils.getRandomInstance();
while (System.nanoTime() - start < TIME_NS) {
objects[ThreadLocalRandom.current().nextInt(SLABS_COUNT)] = createSome();
objects[rng.nextInt(SLABS_COUNT)] = createSome();
}
}

@ -25,8 +25,9 @@
/*
* @test TestSieveObjects
* @summary Acceptance tests: collector can deal with retained objects
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -52,8 +53,9 @@
/*
* @test TestSieveObjects
* @summary Acceptance tests: collector can deal with retained objects
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
@ -95,8 +97,9 @@
/*
* @test TestSieveObjects
* @summary Acceptance tests: collector can deal with retained objects
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
@ -122,7 +125,8 @@
* TestSieveObjects
*/
import java.util.concurrent.ThreadLocalRandom;
import java.util.Random;
import jdk.test.lib.Utils;
public class TestSieveObjects {
@ -134,17 +138,18 @@ public class TestSieveObjects {
public static void main(String[] args) throws Exception {
int rIdx = 0;
Random rng = Utils.getRandomInstance();
for (int c = 0; c < COUNT; c++) {
MyObject v = arr[rIdx];
if (v != null) {
if (v.x != rIdx) {
throw new IllegalStateException("Illegal value at index " + rIdx + ": " + v.x);
}
if (ThreadLocalRandom.current().nextInt(1000) > 100) {
if (rng.nextInt(1000) > 100) {
arr[rIdx] = null;
}
} else {
if (ThreadLocalRandom.current().nextInt(1000) > 500) {
if (rng.nextInt(1000) > 500) {
arr[rIdx] = new MyObject(rIdx);
}
}

@ -25,7 +25,7 @@
/*
* @test TestStringDedup
* @summary Test Shenandoah string deduplication implementation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc:open
@ -46,7 +46,7 @@
/*
* @test TestStringDedup
* @summary Test Shenandoah string deduplication implementation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc:open
@ -69,7 +69,7 @@
/*
* @test TestStringDedup
* @summary Test Shenandoah string deduplication implementation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc:open
@ -87,6 +87,7 @@
import java.lang.reflect.*;
import java.util.*;
import jdk.test.lib.Utils;
import sun.misc.*;
@ -136,7 +137,7 @@ public class TestStringDedup {
}
private static void generateStrings(ArrayList<StringAndId> strs, int unique_strs) {
Random rn = new Random();
Random rn = Utils.getRandomInstance();
for (int u = 0; u < unique_strs; u++) {
int n = rn.nextInt() % 10;
n = Math.max(n, 2);

@ -25,7 +25,7 @@
/*
* @test TestStringDedupStress
* @summary Test Shenandoah string deduplication implementation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc:open
@ -46,7 +46,7 @@
/*
* @test TestStringDedupStress
* @summary Test Shenandoah string deduplication implementation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc:open
@ -77,7 +77,7 @@
/*
* @test TestStringDedupStress
* @summary Test Shenandoah string deduplication implementation
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc:open
@ -109,6 +109,7 @@
import java.lang.management.*;
import java.lang.reflect.*;
import java.util.*;
import jdk.test.lib.Utils;
import sun.misc.*;
@ -163,7 +164,7 @@ public class TestStringDedupStress {
// Generate uniqueStrings number of strings
private static void generateStrings(ArrayList<StringAndId> strs, int uniqueStrings) {
Random rn = new Random();
Random rn = Utils.getRandomInstance();
for (int u = 0; u < uniqueStrings; u++) {
int n = rn.nextInt(uniqueStrings);
strs.add(new StringAndId("Unique String " + n, n));
@ -200,7 +201,7 @@ public class TestStringDedupStress {
static GarbageCollectorMXBean gcCycleMBean;
public static void main(String[] args) {
Random rn = new Random();
Random rn = Utils.getRandomInstance();
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
if ("Shenandoah Cycles".equals(bean.getName())) {

@ -24,12 +24,16 @@
/* @test TestC1VectorizedMismatch
* @summary test C1 vectorized mismatch intrinsic
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:TieredStopAtLevel=1 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestC1VectorizedMismatch
*/
import java.util.Arrays;
import java.util.Random;
import jdk.test.lib.Utils;
public class TestC1VectorizedMismatch {
@ -57,8 +61,9 @@ public class TestC1VectorizedMismatch {
}
private static void fillArray(int[] array) {
Random r = Utils.getRandomInstance();
for (int i = 0; i < ARRAY_SIZE; i++) {
int val = (int) (Math.random() * Integer.MAX_VALUE);
int val = (int) (r.nextDouble() * Integer.MAX_VALUE);
array[i] = val;
}
}

@ -24,14 +24,17 @@
/* @test TestJNICritical
* @summary test JNI critical arrays support in Shenandoah
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahVerify TestJNICritical
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestJNICritical
*/
import java.util.Arrays;
import java.util.Random;
import jdk.test.lib.Utils;
public class TestJNICritical {
static {
@ -65,8 +68,9 @@ public class TestJNICritical {
}
private static void fillArray(int[] array) {
Random r = Utils.getRandomInstance();
for (int i = 0; i < ARRAY_SIZE; i++) {
int val = (int) (Math.random() * Integer.MAX_VALUE);
int val = (int) (r.nextDouble() * Integer.MAX_VALUE);
array[i] = val;
}
}

@ -24,8 +24,9 @@
/* @test TestPinnedGarbage
* @summary Test that garbage in the pinned region does not crash VM
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx512m
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -40,8 +41,9 @@
/* @test TestPinnedGarbage
* @summary Test that garbage in the pinned region does not crash VM
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx512m
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
@ -54,7 +56,8 @@
*/
import java.util.Arrays;
import java.util.concurrent.*;
import java.util.Random;
import jdk.test.lib.Utils;
public class TestPinnedGarbage {
static {
@ -81,12 +84,13 @@ public class TestPinnedGarbage {
}
int[] cog = new int[10];
int cogIdx = ThreadLocalRandom.current().nextInt(OBJS_COUNT);
Random rng = Utils.getRandomInstance();
int cogIdx = rng.nextInt(OBJS_COUNT);
objs[cogIdx] = cog;
pin(cog);
for (int i = 0; i < GARBAGE_COUNT; i++) {
int rIdx = ThreadLocalRandom.current().nextInt(OBJS_COUNT);
int rIdx = rng.nextInt(OBJS_COUNT);
if (rIdx != cogIdx) {
objs[rIdx] = new MyClass();
}

@ -25,8 +25,9 @@
/*
* @test TestHumongousMoves
* @summary Check Shenandoah reacts on setting humongous moves correctly
* @key gc
* @key gc randomness
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @library /test/lib
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
@ -42,6 +43,7 @@
*/
import java.util.Random;
import jdk.test.lib.Utils;
public class TestHumongousMoves {
@ -54,7 +56,7 @@ public class TestHumongousMoves {
final int max = 384 * 1024;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
Random r = new Random();
Random r = Utils.getRandomInstance();
for (long c = 0; c < count; c++) {
sink = new int[min + r.nextInt(max - min)];
}

@ -26,12 +26,13 @@ package gc.stress;
import java.util.Random;
import gc.CriticalNative;
import jdk.test.lib.Utils;
/*
* @test CriticalNativeStressEpsilon
* @key gc
* @key gc randomness
* @bug 8199868
* @library /
* @library / /test/lib
* @requires (os.arch =="x86_64" | os.arch == "amd64" | os.arch=="x86" | os.arch=="i386") & vm.gc.Epsilon & !vm.graal.enabled
* @summary test argument pinning by nmethod wrapper of critical native method
* @run main/othervm/native -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xcomp -Xmx1G -XX:+CriticalJNINatives gc.stress.CriticalNativeStress
@ -39,9 +40,9 @@ import gc.CriticalNative;
/*
* @test CriticalNativeStressShenandoah
* @key gc
* @key gc randomness
* @bug 8199868
* @library /
* @library / /test/lib
* @requires (os.arch =="x86_64" | os.arch == "amd64" | os.arch=="x86" | os.arch=="i386") & vm.gc.Shenandoah & !vm.graal.enabled
* @summary test argument pinning by nmethod wrapper of critical native method
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive -XX:-ShenandoahDegeneratedGC -Xcomp -Xmx512M -XX:+CriticalJNINatives gc.stress.CriticalNativeStress
@ -53,8 +54,6 @@ import gc.CriticalNative;
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive -Xcomp -Xmx512M -XX:+CriticalJNINatives gc.stress.CriticalNativeStress
*/
public class CriticalNativeStress {
private static Random rand = new Random();
// CYCLES and THREAD_PER_CASE are used to tune the tests for different GC settings,
// so that they can execrise enough GC cycles and not OOM
private static int CYCLES = Integer.getInteger("cycles", 3);
@ -96,7 +95,7 @@ public class CriticalNativeStress {
// arbitrary values, then calcuate sum of the array
// elements with critical native JNI methods and java
// methods, and compare the results for correctness.
static void run_test_case1() {
static void run_test_case1(Random rand) {
// Create testing arary with arbitrary length and
// values
int length = rand.nextInt(50) + 1;
@ -121,7 +120,7 @@ public class CriticalNativeStress {
}
}
static void run_test_case2() {
static void run_test_case2(Random rand) {
// Create testing arary with arbitrary length and
// values
int index;
@ -168,25 +167,29 @@ public class CriticalNativeStress {
}
static class Case1Runner extends Thread {
private final Random rand;
public Case1Runner() {
rand = new Random(Utils.getRandomInstance().nextLong());
start();
}
public void run() {
for (int index = 0; index < CYCLES; index ++) {
run_test_case1();
run_test_case1(rand);
}
}
}
static class Case2Runner extends Thread {
private final Random rand;
public Case2Runner() {
rand = new Random(Utils.getRandomInstance().nextLong());
start();
}
public void run() {
for (int index = 0; index < CYCLES; index ++) {
run_test_case2();
run_test_case2(rand);
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, SAP SE and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -27,14 +27,18 @@ package gc.stress.TestJNIBlockFullGC;
/*
* @test TestJNIBlockFullGC
* @summary Check that in G1 a Full GC to reclaim space can not be blocked out by the GC locker.
* @key gc
* @key gc randomness
* @requires vm.gc.G1
* @library /test/lib
* @run main/othervm/native -Xmx64m -XX:+UseG1GC -Xlog:gc=info,gc+alloc=trace -XX:MaxGCPauseMillis=10 gc.stress.TestJNIBlockFullGC.TestJNIBlockFullGC 10 10000 10000 10000 30000 10000 0.7
*/
import java.lang.ref.SoftReference;
import java.util.Random;
import jdk.test.lib.Utils;
public class TestJNIBlockFullGC {
private static final Random rng = Utils.getRandomInstance();
static {
System.loadLibrary("TestJNIBlockFullGC");
@ -58,12 +62,13 @@ public class TestJNIBlockFullGC {
}
}
public static void warmUp(long warmupEndTime, int size) {
public static void warmUp(long warmupEndTime, int size, long seed) {
Random r = new Random(seed);
// First let the GC assume most of our objects will die.
Node[] roots = new Node[size];
while (System.currentTimeMillis() < warmupEndTime) {
int index = (int) (Math.random() * roots.length);
int index = (int) (r.nextDouble() * roots.length);
roots[index] = new Node(1);
}
@ -73,7 +78,8 @@ public class TestJNIBlockFullGC {
}
}
public static void runTest(long endTime, int size, double alive) {
public static void runTest(long endTime, int size, double alive, long seed) {
Random r = new Random(seed);
final int length = 10000;
int[] array1 = new int[length];
for (int x = 1; x < length; x++) {
@ -88,10 +94,10 @@ public class TestJNIBlockFullGC {
while (!hadError && (System.currentTimeMillis() < endTime)) {
int test_val1 = TestCriticalArray0(array1);
if (Math.random() > alive) {
if (r.nextDouble() > alive) {
tmp = new Node(test_val1);
} else {
index = (int) (Math.random() * roots.length);
index = (int) (r.nextDouble() * roots.length);
if (roots[index] != null) {
Node node = new Node(test_val1);
@ -150,9 +156,10 @@ public class TestJNIBlockFullGC {
System.out.println("Start warm-up threads!");
long warmupStartTime = System.currentTimeMillis();
for (int i = 0; i < warmupThreads; i++) {
long seed = rng.nextLong();
threads[i] = new Thread() {
public void run() {
warmUp(warmupStartTime + warmupDuration, warmupIterations);
warmUp(warmupStartTime + warmupDuration, warmupIterations, seed);
};
};
threads[i].start();
@ -165,9 +172,10 @@ public class TestJNIBlockFullGC {
long startTime = System.currentTimeMillis();
for (int i = 0; i < mainThreads; i++) {
long seed = rng.nextLong();
threads[i] = new Thread() {
public void run() {
runTest(startTime + mainDuration, mainIterations, liveFrac);
runTest(startTime + mainDuration, mainIterations, liveFrac, seed);
};
};
threads[i].start();

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
@ -29,10 +29,11 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import sun.hotspot.WhiteBox;
import jdk.test.lib.Utils;
/*
* @test TestMultiThreadStressRSet.java
* @key stress
* @key stress randomness
* @requires vm.gc.G1
* @requires os.maxMemory > 2G
* @requires vm.opt.MaxGCPauseMillis == "null"
@ -57,7 +58,6 @@ import sun.hotspot.WhiteBox;
*/
public class TestMultiThreadStressRSet {
private static final Random RND = new Random(2015 * 2016);
private static final WhiteBox WB = WhiteBox.getWhiteBox();
private static final int REF_SIZE = WB.getHeapOopSize();
private static final int REGION_SIZE = WB.g1RegionSize();
@ -214,8 +214,8 @@ public class TestMultiThreadStressRSet {
*
* @return a random element from the current window within the storage.
*/
private Object getRandomObject() {
int index = (windowStart + RND.nextInt(windowSize)) % N;
private Object getRandomObject(Random rnd) {
int index = (windowStart + rnd.nextInt(windowSize)) % N;
return STORAGE.get(index);
}
@ -233,7 +233,7 @@ public class TestMultiThreadStressRSet {
* Thread to create a number of references from BUFFER to STORAGE.
*/
private static class Worker extends Thread {
final Random rnd;
final TestMultiThreadStressRSet boss;
final int refs; // number of refs to OldGen
@ -244,6 +244,7 @@ public class TestMultiThreadStressRSet {
Worker(TestMultiThreadStressRSet boss, int refsToOldGen) {
this.boss = boss;
this.refs = refsToOldGen;
this.rnd = new Random(Utils.getRandomInstance().nextLong());
}
@Override
@ -253,7 +254,7 @@ public class TestMultiThreadStressRSet {
Object[] objs = boss.getFromBuffer();
int step = objs.length / refs;
for (int i = 0; i < refs; i += step) {
objs[i] = boss.getRandomObject();
objs[i] = boss.getRandomObject(rnd);
}
boss.counter++;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,8 @@ package gc.stress.gcold;
import java.text.*;
import java.util.Random;
import jdk.test.lib.Utils;
class TreeNode {
public TreeNode left, right;
public int val; // will always be the height of the tree
@ -86,7 +88,7 @@ public class TestGCOld {
private static TreeNode[] trees;
private static int where = 0; // roving index into trees
private static Random rnd = new Random();
private static Random rnd = Utils.getRandomInstance();
// Returns the height of the given tree.

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -26,8 +26,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithG1
* @key gc
* @library /
* @key gc randomness
* @library / /test/lib
* @requires vm.gc.G1
* @summary Stress the G1 GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseG1GC gc.stress.gcold.TestGCOldWithG1 50 1 20 10 10000

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -26,8 +26,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithParallel
* @key gc
* @library /
* @key gc randomness
* @library / /test/lib
* @requires vm.gc.Parallel
* @summary Stress the Parallel GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseParallelGC gc.stress.gcold.TestGCOld 50 1 20 10 10000

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -26,8 +26,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithSerial
* @key gc
* @library /
* @key gc randomness
* @library / /test/lib
* @requires vm.gc.Serial
* @summary Stress the Serial GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseSerialGC gc.stress.gcold.TestGCOldWithSerial 50 1 20 10 10000

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
@ -25,9 +25,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithShenandoah
* @key gc
* @key stress
* @library /
* @key gc stress randomness
* @library / /test/lib
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @summary Stress the GC by trying to make old objects more likely to be garbage than young objects.
*
@ -54,9 +53,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithShenandoah
* @key gc
* @key stress
* @library /
* @key gc stress randomness
* @library / /test/lib
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @summary Stress the GC by trying to make old objects more likely to be garbage than young objects.
*
@ -90,9 +88,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithShenandoah
* @key gc
* @key stress
* @library /
* @key gc stress randomness
* @library / /test/lib
* @requires vm.gc.Shenandoah & !vm.graal.enabled
* @summary Stress the GC by trying to make old objects more likely to be garbage than young objects.
*

@ -26,8 +26,8 @@ package gc.stress.gcold;
/*
* @test TestGCOldWithZ
* @key gc
* @library /
* @key gc randomness
* @library / /test/lib
* @requires vm.gc.Z & !vm.graal.enabled
* @summary Stress the Z
* @run main/othervm -Xmx384M -XX:+UseZGC gc.stress.gcold.TestGCOldWithZ 50 1 20 10 10000

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,7 @@ package jdk.jfr.event.gc.detailed;
/**
* @test
* @key randomness
* @requires vm.hasJFR
* @requires vm.gc == "null" | vm.gc == "Serial"
* @library /test/lib /test/jdk

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,7 @@ package jdk.jfr.event.gc.detailed;
/**
* @test
* @key randomness
* @requires vm.hasJFR
* @requires vm.gc == "null" | vm.gc == "G1"
* @library /test/lib /test/jdk

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,7 @@ package jdk.jfr.event.gc.detailed;
/**
* @test
* @key randomness
* @requires vm.hasJFR
* @requires vm.gc == "null" | vm.gc == "Parallel"
* @library /test/lib /test/jdk

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,7 @@ package jdk.jfr.event.gc.detailed;
/**
* @test
* @key randomness
* @requires vm.hasJFR
* @requires vm.gc == "null" | vm.gc == "Serial"
* @library /test/lib /test/jdk

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,7 @@ package jdk.jfr.event.gc.detailed;
/**
* @test
* @key randomness
* @summary Test allocates humongous objects with G1 GC. Objects
* considered humongous when it allocates equals or more than one region. As
* we're passing the size of byte array we need adjust it that entire structure

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -26,6 +26,7 @@ package jdk.jfr.event.gc.detailed;
/**
* @test
* @key randomness
* @requires vm.hasJFR
* @requires vm.gc == "null" | vm.gc == "Parallel"
* @library /test/lib /test/jdk

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -27,6 +27,7 @@ package jdk.jfr.event.gc.detailed;
import static jdk.test.lib.Asserts.assertEquals;
import static jdk.test.lib.Asserts.assertNotEquals;
import static jdk.test.lib.Asserts.assertTrue;
import jdk.test.lib.Utils;
import java.util.List;
import java.util.Random;
@ -105,6 +106,7 @@ public class StressAllocationGCEvents {
this.OBJ_SIZE = obj_size;
this.OLD_OBJ_COUNT = Math.max(1, (int) ((float) Runtime.getRuntime().maxMemory() / 2 / THREAD_COUNT / OBJ_SIZE));
this.old_garbage = new Object[OLD_OBJ_COUNT];
this.r = new Random(Utils.getRandomInstance().nextLong());
System.out.println(String.format("In \"%s\" old objects count = %d, recursion depth = %d",
this.getName(), OLD_OBJ_COUNT, RECURSION_DEPTH));
@ -122,7 +124,6 @@ public class StressAllocationGCEvents {
diver(stack - 1);
} else {
long endTime = startTime + (SECONDS_TO_RUN * 1000);
Random r = new Random(startTime);
while (endTime > System.currentTimeMillis()) {
byte[] garbage = new byte[OBJ_SIZE];
if (r.nextInt(100) > OLD_GEN_RATE) {
@ -136,6 +137,7 @@ public class StressAllocationGCEvents {
private final Object[] old_garbage;
private final int OBJ_SIZE;
private final int OLD_OBJ_COUNT;
private final Random r;
}
///< check stacktrace depth