8242313: use reproducible random in hotspot svc tests

Reviewed-by: cjplummer
This commit is contained in:
Igor Ignatyev 2020-04-13 12:31:34 -07:00
parent 15464b36c3
commit 116fe806c3
3 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
@ -22,13 +22,16 @@
* questions.
*/
import java.util.Random;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Utils;
public class LingeredAppWithNativeMethod extends LingeredApp {
public static final String THREAD_NAME = "NoFramePointerJNIFib";
private static final int UPPER_BOUND = 55;
private static final int LOWER_BOUND = 40;
private static final Random RNG = Utils.getRandomInstance();
static {
// JNI library compiled with no frame pointer info
@ -43,9 +46,9 @@ public class LingeredAppWithNativeMethod extends LingeredApp {
// Results of fibonacci calculation from JNI are
// reported via callback(). That's where the process
// of calculating fibonacci restarts.
int num = (int) (Math.random() * UPPER_BOUND);
int num = (int) (RNG.nextDouble() * UPPER_BOUND);
while (num < LOWER_BOUND) {
num = (int) (Math.random() * UPPER_BOUND);
num = (int) (RNG.nextDouble() * UPPER_BOUND);
}
System.out.print("fib(" + num + ") = ");
callJNI(this, num);

View File

@ -34,6 +34,7 @@ import jdk.test.lib.process.OutputAnalyzer;
/**
* @test
* @key randomness
* @bug 8208091
* @requires (os.family == "linux") & (vm.hasSA)
* @library /test/lib

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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,6 +28,7 @@ import java.util.Random;
/*
* @test
* @key randomness
* @bug 8016304
* @summary Make sure no deadlock is reported for this program which has no deadlocks.
* @modules java.base/jdk.internal.misc
@ -48,8 +49,9 @@ public class TestFalseDeadLock {
public static void main(String[] args) throws Exception {
bean = ManagementFactory.getThreadMXBean();
Thread[] threads = new Thread[500];
Random random = Utils.getRandomInstance();
for (int i = 0; i < threads.length; i++) {
Test t = new Test();
Test t = new Test(random.nextLong());
threads[i] = new Thread(t);
threads[i].start();
}
@ -67,8 +69,12 @@ public class TestFalseDeadLock {
}
public static class Test implements Runnable {
private final long seed;
public Test(long seed) {
this.seed = seed;
}
public void run() {
Random r = Utils.getRandomInstance();
Random r = new Random(seed);
while (running) {
try {
synchronized (this) {