8242311: use reproducible random in hotspot runtime tests
Reviewed-by: iklam, mseledtsov
This commit is contained in:
parent
116fe806c3
commit
c73934d8c8
@ -24,7 +24,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key nmt jcmd
|
||||
* @key nmt jcmd randomness
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.management
|
||||
@ -38,6 +38,7 @@ import java.util.Random;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.Utils;
|
||||
import sun.hotspot.WhiteBox;
|
||||
|
||||
public class HugeArenaTracking {
|
||||
@ -59,7 +60,7 @@ public class HugeArenaTracking {
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Test (reserved=2KB, committed=2KB)");
|
||||
|
||||
Random rand = new Random();
|
||||
Random rand = Utils.getRandomInstance();
|
||||
|
||||
// Allocate 2GB+ from arena
|
||||
long total = 0;
|
||||
|
@ -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
|
||||
@ -24,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @summary Stress test for malloc tracking
|
||||
* @key nmt jcmd stress
|
||||
* @key nmt jcmd stress randomness
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.management
|
||||
@ -39,6 +39,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import sun.hotspot.WhiteBox;
|
||||
@ -159,6 +160,7 @@ public class MallocStressTest {
|
||||
}
|
||||
|
||||
static class AllocThread extends Thread {
|
||||
private final Random random = new Random(Utils.getRandomInstance().nextLong());
|
||||
AllocThread() {
|
||||
this.setName("MallocThread");
|
||||
this.start();
|
||||
@ -166,7 +168,6 @@ public class MallocStressTest {
|
||||
|
||||
// AllocThread only runs "Alloc" phase
|
||||
public void run() {
|
||||
Random random = new Random();
|
||||
// MallocStressTest.phase == TestPhase.alloc
|
||||
for (int loops = 0; loops < 100; loops++) {
|
||||
int r = random.nextInt(Integer.MAX_VALUE);
|
||||
@ -201,7 +202,7 @@ public class MallocStressTest {
|
||||
}
|
||||
|
||||
static class ReleaseThread extends Thread {
|
||||
private Random random = new Random();
|
||||
private final Random random = new Random(Utils.getRandomInstance().nextLong());
|
||||
ReleaseThread() {
|
||||
this.setName("ReleaseThread");
|
||||
this.start();
|
||||
|
@ -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
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @bug 8054836
|
||||
* @summary Test to verify correctness of malloc tracking
|
||||
* @key nmt jcmd
|
||||
* @key nmt jcmd randomness
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.management
|
||||
@ -41,6 +41,7 @@ import java.util.Random;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
import sun.hotspot.WhiteBox;
|
||||
|
||||
@ -58,7 +59,7 @@ public class MallocTrackingVerify {
|
||||
String pid = Long.toString(ProcessTools.getProcessId());
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
|
||||
Random random = new Random();
|
||||
Random random = Utils.getRandomInstance();
|
||||
// Allocate small amounts of memory with random pseudo call stack
|
||||
while (mallocd_total < MAX_ALLOC) {
|
||||
int size = random.nextInt(31) + 1;
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key randomness
|
||||
* @summary SharedArchiveConsistency
|
||||
* @requires vm.cds
|
||||
* @library /test/lib
|
||||
|
@ -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
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import jdk.test.lib.Utils;
|
||||
import sun.hotspot.WhiteBox;
|
||||
|
||||
// All strings in archived classes are shared
|
||||
@ -43,7 +44,7 @@ public class GCStressApp {
|
||||
|
||||
static void allocAlot() {
|
||||
try {
|
||||
Random random = new Random();
|
||||
Random random = Utils.getRandomInstance();
|
||||
for (int i = 0; i < 1024 * 1024; i++) {
|
||||
int len = random.nextInt(10000);
|
||||
arr = new int[len];
|
||||
|
@ -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
|
||||
@ -24,12 +24,13 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key randomness
|
||||
* @summary
|
||||
* @requires vm.cds.archived.java.heap
|
||||
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
|
||||
* @build sun.hotspot.WhiteBox
|
||||
* @build sun.hotspot.WhiteBox jdk.test.lib.Utils
|
||||
* @compile GCStressApp.java
|
||||
* @run driver ClassFileInstaller -jar gcstress.jar GCStressApp
|
||||
* @run driver ClassFileInstaller -jar gcstress.jar GCStressApp jdk.test.lib.Utils
|
||||
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
|
||||
* @run driver GCStressTest
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019 SAP SE. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key randomness
|
||||
* @summary Test extended NullPointerException message for
|
||||
* classfiles generated with debug information. In this case the name
|
||||
* of the variable containing the array is printed.
|
||||
@ -36,6 +37,7 @@
|
||||
*/
|
||||
/**
|
||||
* @test
|
||||
* @key randomness
|
||||
* @summary Test extended NullPointerException message for class
|
||||
* files generated without debugging information. The message lists
|
||||
* detailed information about the entity that is null.
|
||||
@ -53,11 +55,13 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.invoke.MethodHandles.Lookup;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.Label;
|
||||
import jdk.internal.org.objectweb.asm.MethodVisitor;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
import static java.lang.invoke.MethodHandles.lookup;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
|
||||
@ -89,6 +93,7 @@ public class NullPointerExceptionTest {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
ArrayList<String> curr;
|
||||
static boolean hasDebugInfo = false;
|
||||
static final Random rng = Utils.getRandomInstance();
|
||||
|
||||
static {
|
||||
staticArray = new int[1][][][];
|
||||
@ -1421,9 +1426,9 @@ public class NullPointerExceptionTest {
|
||||
// is null. Make sure we don't print the wrong value.
|
||||
String s = null;
|
||||
@SuppressWarnings("unused")
|
||||
byte[] val = (Math.random() < 0.5 ? s : (new String[1])[0]).getBytes();
|
||||
byte[] val = (rng.nextDouble() < 0.5 ? s : (new String[1])[0]).getBytes();
|
||||
} catch (NullPointerException e) {
|
||||
checkMessage(e, "byte[] val = (Math.random() < 0.5 ? s : (new String[1])[0]).getBytes();", e.getMessage(),
|
||||
checkMessage(e, "byte[] val = (rng.nextDouble() < 0.5 ? s : (new String[1])[0]).getBytes();", e.getMessage(),
|
||||
"Cannot invoke \"String.getBytes()\"");
|
||||
}
|
||||
|
||||
@ -1435,9 +1440,9 @@ public class NullPointerExceptionTest {
|
||||
int[][] b = new int[2][];
|
||||
long index = 0;
|
||||
@SuppressWarnings("unused")
|
||||
int val = (Math.random() < 0.5 ? a[(int)index] : b[(int)index])[13];
|
||||
int val = (rng.nextDouble() < 0.5 ? a[(int)index] : b[(int)index])[13];
|
||||
} catch (NullPointerException e) {
|
||||
checkMessage(e, "int val = (Math.random() < 0.5 ? a[(int)index] : b[(int)index])[13]", e.getMessage(),
|
||||
checkMessage(e, "int val = (rng.nextDouble() < 0.5 ? a[(int)index] : b[(int)index])[13]", e.getMessage(),
|
||||
"Cannot load from int array");
|
||||
}
|
||||
|
||||
@ -1448,18 +1453,18 @@ public class NullPointerExceptionTest {
|
||||
int[][] a = new int[1][];
|
||||
int[][] b = new int[2][];
|
||||
long index = 0;
|
||||
int val = (Math.random() < 0.5 ? a : b)[(int)index][13];
|
||||
int val = (rng.nextDouble() < 0.5 ? a : b)[(int)index][13];
|
||||
} catch (NullPointerException e) {
|
||||
checkMessage(e, "int val = (Math.random() < 0.5 ? a : b)[(int)index][13]", e.getMessage(),
|
||||
checkMessage(e, "int val = (rng.nextDouble() < 0.5 ? a : b)[(int)index][13]", e.getMessage(),
|
||||
"Cannot load from int array because \"<array>[...]\" is null");
|
||||
}
|
||||
|
||||
try {
|
||||
C c1 = new C();
|
||||
C c2 = new C();
|
||||
(Math.random() < 0.5 ? c1 : c2).to_d.num = 77;
|
||||
(rng.nextDouble() < 0.5 ? c1 : c2).to_d.num = 77;
|
||||
} catch (NullPointerException e) {
|
||||
checkMessage(e, "(Math.random() < 0.5 ? c1 : c2).to_d.num = 77;", e.getMessage(),
|
||||
checkMessage(e, "(rng.nextDouble() < 0.5 ? c1 : c2).to_d.num = 77;", e.getMessage(),
|
||||
"Cannot assign field \"num\" because \"to_d\" is null");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user