Skip to content
Permalink
Browse files
8242313: use reproducible random in hotspot svc tests
Reviewed-by: cjplummer
  • Loading branch information
iignatev committed Apr 13, 2020
1 parent 15464b3 commit 116fe806c3008680cfb21484f6469a5ccb638c5d
Showing 3 changed files with 16 additions and 6 deletions.
@@ -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 void callNative() {
// 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);
@@ -34,6 +34,7 @@

/**
* @test
* @key randomness
* @bug 8208091
* @requires (os.family == "linux") & (vm.hasSA)
* @library /test/lib
@@ -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 @@

/*
* @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 static void main(String[] args) throws Exception {
}

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) {

0 comments on commit 116fe80

Please sign in to comment.