8044186: Introduce a reproducible random generator
Reviewed-by: kvn, iveresov, iignatyev
Contributed-by: sergei.kovalev@oracle.com
--- a/hotspot/test/compiler/6896617/Test6896617.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/6896617/Test6896617.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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,13 +25,20 @@
* @test
* @bug 6896617
* @summary Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() with SSE instructions on x86
+ * @library /testlibrary
* @run main/othervm/timeout=1200 -Xbatch -Xmx256m Test6896617
*
*/
-import java.util.*;
-import java.nio.*;
-import java.nio.charset.*;
+import com.oracle.java.testlibrary.Utils;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+import java.util.Arrays;
+import java.util.Random;
public class Test6896617 {
final static int SIZE = 256;
@@ -54,7 +61,7 @@
sun.nio.cs.ArrayDecoder arrdec = (sun.nio.cs.ArrayDecoder)dec;
// Populate char[] with chars which can be encoded by ISO_8859_1 (<= 0xFF)
- Random rnd = new Random(0);
+ Random rnd = Utils.getRandomInstance();
int maxchar = 0xFF;
char[] a = new char[SIZE];
byte[] b = new byte[SIZE];
--- a/hotspot/test/compiler/7100757/Test7100757.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/7100757/Test7100757.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, 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,11 +26,13 @@
* @test
* @bug 7100757
* @summary The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
- *
+ * @library /testlibrary
* @run main/timeout=300 Test7100757
*/
-import java.util.*;
+import com.oracle.java.testlibrary.Utils;
+import java.util.BitSet;
+import java.util.Random;
public class Test7100757 {
@@ -39,7 +41,7 @@
public static void main(String[] args) {
BitSet bs = new BitSet(NBITS);
- Random rnd = new Random();
+ Random rnd = Utils.getRandomInstance();
long[] ra = new long[(NBITS+63)/64];
for(int l=0; l < 5000000; l++) {
--- a/hotspot/test/compiler/7177917/Test7177917.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/7177917/Test7177917.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, 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,13 +26,14 @@
* Micro-benchmark for Math.pow() and Math.exp()
*/
-import java.util.*;
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
public class Test7177917 {
static double d;
- static Random r = new Random(0);
+ static final Random R = Utils.getRandomInstance();
static long m_pow(double[][] values) {
double res = 0;
@@ -59,10 +60,10 @@
static double[][] pow_values(int nb) {
double[][] res = new double[nb][2];
for (int i = 0; i < nb; i++) {
- double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
- double x = Math.abs(Double.longBitsToDouble(r.nextLong()));
+ double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
+ double x = Math.abs(Double.longBitsToDouble(R.nextLong()));
while (x != x) {
- x = Math.abs(Double.longBitsToDouble(r.nextLong()));
+ x = Math.abs(Double.longBitsToDouble(R.nextLong()));
}
double logx = Math.log(x) / Math.log(2);
double y = ylogx / logx;
@@ -76,7 +77,7 @@
static double[] exp_values(int nb) {
double[] res = new double[nb];
for (int i = 0; i < nb; i++) {
- double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
+ double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
double x = Math.E;
double logx = Math.log(x) / Math.log(2);
double y = ylogx / logx;
--- a/hotspot/test/compiler/7184394/TestAESBase.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/7184394/TestAESBase.java Sun Nov 02 18:43:38 2014 +0300
@@ -26,15 +26,13 @@
* @author Tom Deneau
*/
+import com.oracle.java.testlibrary.Utils;
+import java.security.AlgorithmParameters;
+import java.util.Random;
import javax.crypto.Cipher;
-import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
-import java.security.AlgorithmParameters;
-
-import java.util.Random;
-import java.util.Arrays;
abstract public class TestAESBase {
int msgSize = Integer.getInteger("msgSize", 646);
@@ -59,7 +57,7 @@
byte[] expectedEncode;
byte[] decode;
byte[] expectedDecode;
- Random random = new Random(0);
+ final Random random = Utils.getRandomInstance();
Cipher cipher;
Cipher dCipher;
AlgorithmParameters algParams;
--- a/hotspot/test/compiler/7184394/TestAESMain.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/7184394/TestAESMain.java Sun Nov 02 18:43:38 2014 +0300
@@ -26,6 +26,7 @@
* @test
* @bug 7184394
* @summary add intrinsics to use AES instructions
+ * @library /testlibrary
*
* @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC TestAESMain
* @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 TestAESMain
--- a/hotspot/test/compiler/8005956/PolynomialRoot.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/8005956/PolynomialRoot.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,4 +1,3 @@
-//package com.polytechnik.utils;
/*
* (C) Vladislav Malyshkin 2010
* This file is under GPL version 3.
@@ -14,10 +13,14 @@
* @test
* @bug 8005956
* @summary C2: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG defined in this block
-*
+* @library /testlibrary
* @run main/timeout=300 PolynomialRoot
*/
+import com.oracle.java.testlibrary.Utils;
+import java.util.Arrays;
+import java.util.Random;
+
public class PolynomialRoot {
@@ -57,7 +60,7 @@
public static int root4(final double [] p,final double [] re_root,final double [] im_root)
{
- if(PRINT_DEBUG) System.err.println("=====================root4:p="+java.util.Arrays.toString(p));
+ if (PRINT_DEBUG) { System.err.println("=====================root4:p=" + Arrays.toString(p)); }
final double vs=p[4];
if(PRINT_DEBUG) System.err.println("p[4]="+p[4]);
if(!(Math.abs(vs)>EPS))
@@ -367,7 +370,7 @@
- static void setRandomP(final double [] p,final int n,java.util.Random r)
+ static void setRandomP(final double [] p, final int n, Random r)
{
if(r.nextDouble()<0.1)
{
@@ -465,7 +468,7 @@
static void testRoots(final int n,
final int n_tests,
- final java.util.Random rn,
+ final Random rn,
final double eps)
{
final double [] p=new double [n+1];
@@ -763,7 +766,7 @@
final long t0=System.currentTimeMillis();
final double eps=1e-6;
//checkRoots();
- final java.util.Random r=new java.util.Random(-1381923);
+ final Random r = Utils.getRandomInstance();
printSpecialValues();
final int n_tests=100000;
--- a/hotspot/test/compiler/intrinsics/bmi/BMITestRunner.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/bmi/BMITestRunner.java Sun Nov 02 18:43:38 2014 +0300
@@ -22,13 +22,17 @@
*
*/
-import java.util.*;
+import com.oracle.java.testlibrary.Asserts;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.nio.charset.StandardCharsets;
-
-import com.oracle.java.testlibrary.*;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
/**
* Test runner that invokes all methods implemented by particular Expr
@@ -69,7 +73,7 @@
String... additionalVMOpts)
throws Throwable {
- int seed = new Random().nextInt();
+ int seed = Utils.getRandomInstance().nextInt();
int iterations = DEFAULT_ITERATIONS_COUNT;
for (String testOption : testOpts) {
@@ -81,8 +85,6 @@
}
}
- System.out.println("Running test with seed: " + seed);
-
OutputAnalyzer intOutput = runTest(expr, VMMode.INT,
additionalVMOpts,
seed, iterations);
@@ -139,9 +141,9 @@
Collections.addAll(vmOpts, new String[] {
"-XX:+DisplayVMOutputToStderr",
+ "-D" + Utils.SEED_PROPERTY_NAME + "=" + seed,
Executor.class.getName(),
expr.getName(),
- new Integer(seed).toString(),
new Integer(iterations).toString()
});
@@ -179,16 +181,15 @@
public static class Executor {
/**
- * Usage: BMITestRunner$Executor <ExprClassName> <seed> <iterations>
+ * Usage: BMITestRunner$Executor <ExprClassName> <iterations>
*/
public static void main(String args[]) throws Exception {
@SuppressWarnings("unchecked")
Class<? extends Expr> exprClass =
(Class<? extends Expr>)Class.forName(args[0]);
Expr expr = exprClass.getConstructor().newInstance();
- Random rng = new Random(Integer.valueOf(args[1]));
- int iterations = Integer.valueOf(args[2]);
- runTests(expr, iterations, rng);
+ int iterations = Integer.valueOf(args[1]);
+ runTests(expr, iterations, Utils.getRandomInstance());
}
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactIConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactIConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8024924
* @summary Test constant addExact
+ * @library /testlibrary
* @compile AddExactIConstantTest.java Verify.java
* @run main AddExactIConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactILoadTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactILoadTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8024924
* @summary Test non constant addExact
+ * @library /testlibrary
* @compile AddExactILoadTest.java Verify.java
* @run main AddExactILoadTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactILoopDependentTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactILoopDependentTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8024924
* @summary Test non constant addExact
+ * @library /testlibrary
* @compile AddExactILoopDependentTest.java Verify.java
* @run main AddExactILoopDependentTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactINonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactINonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8024924
* @summary Test non constant addExact
+ * @library /testlibrary
* @compile AddExactINonConstantTest.java Verify.java
* @run main AddExactINonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactIRepeatTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactIRepeatTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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,11 +25,15 @@
* @test
* @bug 8025657
* @summary Test repeating addExact
+ * @library /testlibrary
* @compile AddExactIRepeatTest.java Verify.java
* @run main AddExactIRepeatTest
*
*/
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
+
public class AddExactIRepeatTest {
public static void main(String[] args) {
runTest(new Verify.AddExactI());
@@ -44,7 +48,7 @@
}
public static void runTest(Verify.BinaryMethod method) {
- java.util.Random rnd = new java.util.Random();
+ Random rnd = Utils.getRandomInstance();
for (int i = 0; i < 50000; ++i) {
int x = Integer.MAX_VALUE - 10;
int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactLConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactLConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant addExact
+ * @library /testlibrary
* @compile AddExactLConstantTest.java Verify.java
* @run main AddExactLConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactLNonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactLNonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant addExact
+ * @library /testlibrary
* @compile AddExactLNonConstantTest.java Verify.java
* @run main AddExactLNonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/DecExactITest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/DecExactITest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test decrementExact
+ * @library /testlibrary
* @compile DecExactITest.java Verify.java
* @run main DecExactITest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/DecExactLTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/DecExactLTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test decrementExact
+ * @library /testlibrary
* @compile DecExactLTest.java Verify.java
* @run main DecExactLTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/IncExactITest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/IncExactITest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test incrementExact
+ * @library /testlibrary
* @compile IncExactITest.java Verify.java
* @run main IncExactITest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/IncExactLTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/IncExactLTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test incrementExact
+ * @library /testlibrary
* @compile IncExactLTest.java Verify.java
* @run main IncExactLTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactIConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactIConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant multiplyExact
+ * @library /testlibrary
* @compile MulExactIConstantTest.java Verify.java
* @run main MulExactIConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactILoadTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactILoadTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test multiplyExact
+ * @library /testlibrary
* @compile MulExactILoadTest.java Verify.java
* @run main MulExactILoadTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactILoopDependentTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactILoopDependentTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test loop dependent multiplyExact
+ * @library /testlibrary
* @compile MulExactILoopDependentTest.java Verify.java
* @run main MulExactILoopDependentTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactINonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactINonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant multiplyExact
+ * @library /testlibrary
* @compile MulExactINonConstantTest.java Verify.java
* @run main MulExactINonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactIRepeatTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactIRepeatTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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,11 +25,15 @@
* @test
* @bug 8026844
* @summary Test repeating multiplyExact
+ * @library /testlibrary
* @compile MulExactIRepeatTest.java Verify.java
* @run main MulExactIRepeatTest
*
*/
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
+
public class MulExactIRepeatTest {
public static void main(String[] args) {
runTest(new Verify.MulExactI());
@@ -44,7 +48,7 @@
}
public static void runTest(Verify.BinaryMethod method) {
- java.util.Random rnd = new java.util.Random();
+ Random rnd = Utils.getRandomInstance();
for (int i = 0; i < 50000; ++i) {
int x = Integer.MAX_VALUE - 10;
int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactLConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactLConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant mulExact
+ * @library /testlibrary
* @compile MulExactLConstantTest.java Verify.java
* @run main MulExactLConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactLNonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactLNonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant mulExact
+ * @library /testlibrary
* @compile MulExactLNonConstantTest.java Verify.java
* @run main MulExactLNonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactIConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactIConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant negExact
+ * @library /testlibrary
* @compile NegExactIConstantTest.java Verify.java
* @run main NegExactIConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactILoadTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactILoadTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test negExact
+ * @library /testlibrary
* @compile NegExactILoadTest.java Verify.java
* @run main NegExactILoadTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactILoopDependentTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactILoopDependentTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test negExact loop dependent
+ * @library /testlibrary
* @compile NegExactILoopDependentTest.java Verify.java
* @run main NegExactILoopDependentTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactINonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactINonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant negExact
+ * @library /testlibrary
* @compile NegExactINonConstantTest.java Verify.java
* @run main NegExactINonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactLConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactLConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant negExact
+ * @library /testlibrary
* @compile NegExactLConstantTest.java Verify.java
* @run main NegExactLConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactLNonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactLNonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant negExact
+ * @library /testlibrary
* @compile NegExactLNonConstantTest.java Verify.java
* @run main NegExactLNonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactICondTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactICondTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test subtractExact as condition
+ * @library /testlibrary
* @compile SubExactICondTest.java Verify.java
* @run main SubExactICondTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactIConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactIConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test constant subtractExact
+ * @library /testlibrary
* @compile SubExactIConstantTest.java Verify.java
* @run main SubExactIConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactILoadTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactILoadTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant subtractExact
+ * @library /testlibrary
* @compile SubExactILoadTest.java Verify.java
* @run main SubExactILoadTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactILoopDependentTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactILoopDependentTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant subtractExact
+ * @library /testlibrary
* @compile SubExactILoopDependentTest.java Verify.java
* @run main SubExactILoopDependentTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactINonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactINonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @test
* @bug 8026844
* @summary Test non constant subtractExact
+ * @library /testlibrary
* @compile SubExactINonConstantTest.java Verify.java
* @run main SubExactINonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactIRepeatTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactIRepeatTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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,12 +25,14 @@
* @test
* @bug 8026844
* @summary Test repeating subtractExact
+ * @library /testlibrary
* @compile SubExactIRepeatTest.java Verify.java
* @run main SubExactIRepeatTest
*
*/
-import java.lang.ArithmeticException;
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
public class SubExactIRepeatTest {
public static void main(String[] args) {
@@ -46,7 +48,7 @@
}
public static void runTest(Verify.BinaryMethod method) {
- java.util.Random rnd = new java.util.Random();
+ Random rnd = Utils.getRandomInstance();
for (int i = 0; i < 50000; ++i) {
int x = Integer.MIN_VALUE + 10;
int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactLConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactLConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @bug 8026844
* @bug 8027353
* @summary Test constant subtractExact
+ * @library /testlibrary
* @compile SubExactLConstantTest.java Verify.java
* @run main SubExactLConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactLNonConstantTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactLNonConstantTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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 @@
* @bug 8026844
* @bug 8027353
* @summary Test non constant subtractExact
+ * @library /testlibrary
* @compile SubExactLNonConstantTest.java Verify.java
* @run main SubExactLNonConstantTest
*
--- a/hotspot/test/compiler/intrinsics/mathexact/Verify.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/intrinsics/mathexact/Verify.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -21,6 +21,13 @@
* questions.
*/
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
+
+/**
+ * The class depends on Utils class from testlibrary package.
+ * It uses factory method that obtains random generator.
+ */
public class Verify {
public static String throwWord(boolean threw) {
return (threw ? "threw" : "didn't throw");
@@ -134,7 +141,7 @@
public static class LoadTest {
- public static java.util.Random rnd = new java.util.Random();
+ public static Random rnd = Utils.getRandomInstance();
public static int[] values = new int[256];
public static void init() {
@@ -159,7 +166,7 @@
}
public static class NonConstantTest {
- public static java.util.Random rnd = new java.util.Random();
+ public static Random rnd = Utils.getRandomInstance();
public static int[] values = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE };
public static void verify(BinaryMethod method) {
@@ -180,7 +187,7 @@
public static class NonConstantLongTest {
public static long[] values = { Long.MIN_VALUE, Long.MAX_VALUE, 0, Long.MAX_VALUE - 1831 };
- public static java.util.Random rnd = new java.util.Random();
+ public static Random rnd = Utils.getRandomInstance();
public static void verify(BinaryLongMethod method) {
for (int i = 0; i < 50000; ++i) {
@@ -199,7 +206,7 @@
}
public static class LoopDependentTest {
- public static java.util.Random rnd = new java.util.Random();
+ public static Random rnd = Utils.getRandomInstance();
public static void verify(BinaryMethod method) {
int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt();
--- a/hotspot/test/compiler/jsr292/ConcurrentClassLoadingTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/jsr292/ConcurrentClassLoadingTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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,18 +25,21 @@
* @test
* @bug 8022595
* @summary JSR292: deadlock during class loading of MethodHandles, MethodHandleImpl & MethodHandleNatives
- *
+ * @library /testlibrary
* @run main/othervm ConcurrentClassLoadingTest
*/
-import java.util.*;
+import com.oracle.java.testlibrary.Utils;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
public class ConcurrentClassLoadingTest {
int numThreads = 0;
- long seed = 0;
CyclicBarrier l;
- Random rand;
+ private static final Random rand = Utils.getRandomInstance();
public static void main(String[] args) throws Throwable {
ConcurrentClassLoadingTest test = new ConcurrentClassLoadingTest();
@@ -49,9 +52,6 @@
while (i < args.length) {
String flag = args[i];
switch(flag) {
- case "-seed":
- seed = Long.parseLong(args[++i]);
- break;
case "-numThreads":
numThreads = Integer.parseInt(args[++i]);
break;
@@ -67,15 +67,9 @@
numThreads = Runtime.getRuntime().availableProcessors();
}
- if (seed == 0) {
- seed = (new Random()).nextLong();
- }
- rand = new Random(seed);
-
l = new CyclicBarrier(numThreads + 1);
System.out.printf("Threads: %d\n", numThreads);
- System.out.printf("Seed: %d\n", seed);
}
final List<Loader> loaders = new ArrayList<>();
@@ -90,7 +84,9 @@
System.out.printf("Thread #%d:\n", t);
for (int i = 0; i < count; i++) {
- if (c.size() == 0) break;
+ if (c.isEmpty()) {
+ break;
+ }
int k = rand.nextInt(c.size());
String elem = c.remove(k);
--- a/hotspot/test/compiler/types/correctness/OffTest.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/types/correctness/OffTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -36,10 +36,10 @@
import com.oracle.java.testlibrary.OutputAnalyzer;
import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
import scenarios.ProfilingType;
-import java.util.Random;
-
public class OffTest {
private static final String[] OPTIONS = {
"-Xbootclasspath/a:.",
@@ -63,14 +63,7 @@
private static final int PROFILING_TYPE_INDEX = OPTIONS.length - 1;
private static final int TYPE_PROFILE_INDEX = OPTIONS.length - 4;
private static final int USE_TYPE_SPECULATION_INDEX = OPTIONS.length - 3;
- private static final Random RNG;
-
- static {
- String str = System.getProperty("seed");
- long seed = str != null ? Long.parseLong(str) : new Random().nextLong();
- RNG = new Random(seed);
- System.out.printf("-Dseed=%d%n", seed);
- }
+ private static final Random RNG = Utils.getRandomInstance();
public static void main(String[] args) throws Exception {
int count = DEFAULT_COUNT;
--- a/hotspot/test/compiler/unsafe/UnsafeRaw.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/compiler/unsafe/UnsafeRaw.java Sun Nov 02 18:43:38 2014 +0300
@@ -80,7 +80,7 @@
final int element_size = 4;
final int magic = 0x12345678;
- Random rnd = new Random();
+ Random rnd = Utils.getRandomInstance();
long array = unsafe.allocateMemory(array_size * element_size); // 128 ints
long addr = array + array_size * element_size / 2; // something in the middle to work with
--- a/hotspot/test/serviceability/threads/TestFalseDeadLock.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/serviceability/threads/TestFalseDeadLock.java Sun Nov 02 18:43:38 2014 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -21,6 +21,7 @@
* questions.
*/
+import com.oracle.java.testlibrary.Utils;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.Random;
@@ -29,6 +30,7 @@
* @test
* @bug 8016304
* @summary Make sure no deadlock is reported for this program which has no deadlocks.
+ * @library /testlibrary
* @run main/othervm TestFalseDeadLock
*/
@@ -65,7 +67,7 @@
public static class Test implements Runnable {
public void run() {
- Random r = new Random();
+ Random r = Utils.getRandomInstance();
while (running) {
try {
synchronized (this) {
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java Sun Nov 02 18:43:00 2014 +0300
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java Sun Nov 02 18:43:38 2014 +0300
@@ -24,21 +24,21 @@
package com.oracle.java.testlibrary;
import static com.oracle.java.testlibrary.Asserts.assertTrue;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.List;
import java.util.Arrays;
import java.util.Collections;
-import java.util.regex.Pattern;
+import java.util.List;
+import java.util.Random;
import java.util.regex.Matcher;
-import java.lang.reflect.Field;
+import java.util.regex.Pattern;
import sun.misc.Unsafe;
/**
@@ -64,6 +64,21 @@
private static Unsafe unsafe = null;
/**
+ * Defines property name for seed value.
+ */
+ public static final String SEED_PROPERTY_NAME = "com.oracle.java.testlibrary.random.seed";
+
+ /* (non-javadoc)
+ * Random generator with (or without) predefined seed. Depends on
+ * "com.oracle.java.testlibrary.random.seed" property value.
+ */
+ private static volatile Random RANDOM_GENERATOR;
+
+ /**
+ * Contains the seed value used for {@link java.util.Random} creation.
+ */
+ public static final long SEED = Long.getLong(SEED_PROPERTY_NAME, new Random().nextLong());
+ /**
* Returns the value of 'test.timeout.factor' system property
* converted to {@code double}.
*/
@@ -332,4 +347,24 @@
}
return new String(hexView);
}
+
+ /**
+ * Returns {@link java.util.Random} generator initialized with particular seed.
+ * The seed could be provided via system property {@link Utils#SEED_PROPERTY_NAME}
+ * In case no seed is provided, the method uses a random number.
+ * The used seed printed to stdout.
+ * @return {@link java.util.Random} generator with particular seed.
+ */
+ public static Random getRandomInstance() {
+ if (RANDOM_GENERATOR == null) {
+ synchronized (Utils.class) {
+ if (RANDOM_GENERATOR == null) {
+ RANDOM_GENERATOR = new Random(SEED);
+ System.out.printf("For random generator using seed: %d%n", SEED);
+ System.out.printf("To re-run test with same seed value please add \"-D%s=%d\" to command line.%n", SEED_PROPERTY_NAME, SEED);
+ }
+ }
+ }
+ return RANDOM_GENERATOR;
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/testlibrary_tests/RandomGeneratorTest.java Sun Nov 02 18:43:38 2014 +0300
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Verify correctnes of the random generator from Utility.java
+ * @library /testlibrary
+ * @run driver RandomGeneratorTest SAME_SEED
+ * @run driver RandomGeneratorTest NO_SEED
+ * @run driver RandomGeneratorTest DIFFERENT_SEED
+ */
+
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * The test verifies correctness of work {@link com.oracle.java.testlibrary.Utils#getRandomInstance()}.
+ * Test works in three modes: same seed provided, no seed provided and
+ * different seed provided. In the first case the test expects that all random numbers
+ * will be repeated in all next iterations. For other two modes test expects that
+ * randomly generated numbers differ from original.
+ */
+public class RandomGeneratorTest {
+ private static final String SEED_VM_OPTION = "-D" + Utils.SEED_PROPERTY_NAME + "=";
+
+ public static void main( String[] args) throws Throwable {
+ if (args.length == 0) {
+ throw new Error("TESTBUG: No test mode provided.");
+ }
+ SeedOption seedOpt = SeedOption.valueOf(args[0]);
+ List<String> jvmArgs = new ArrayList<String>();
+ String optStr = seedOpt.getSeedOption();
+ if (optStr != null) {
+ jvmArgs.add(optStr);
+ }
+ jvmArgs.add(RandomRunner.class.getName());
+ String[] cmdLineArgs = jvmArgs.toArray(new String[jvmArgs.size()]);
+ String etalon = ProcessTools.executeTestJvm(cmdLineArgs).getOutput().trim();
+ seedOpt.verify(etalon, cmdLineArgs);
+ }
+
+ /**
+ * The utility enum helps to generate an appropriate string that should be passed
+ * to the command line depends on the testing mode. It is also responsible for the result
+ * validation.
+ */
+ private enum SeedOption {
+ SAME_SEED {
+ @Override
+ public String getSeedOption() {
+ return SEED_VM_OPTION + Utils.SEED;
+ }
+
+ @Override
+ protected boolean isOutputExpected(String orig, String output) {
+ return output.equals(orig);
+ }
+ },
+ DIFFERENT_SEED {
+ @Override
+ public String getSeedOption() {
+ return SEED_VM_OPTION + Utils.getRandomInstance().nextLong();
+ }
+
+ @Override
+ public void verify(String orig, String[] cmdLine) {
+ cmdLine[0] = getSeedOption();
+ super.verify(orig, cmdLine);
+ }
+ },
+ NO_SEED {
+ @Override
+ public String getSeedOption() {
+ return null;
+ }
+ };
+
+ /**
+ * Generates a string to be added as a command line argument.
+ * It contains "-D" prefix, system property name, '=' sign
+ * and seed value.
+ * @return command line argument
+ */
+ public abstract String getSeedOption();
+
+ protected boolean isOutputExpected(String orig, String output) {
+ return !output.equals(orig);
+ }
+
+ /**
+ * Verifies that the original output meets expectations
+ * depending on the test mode. It compares the output of second execution
+ * to original one.
+ * @param orig original output
+ * @param cmdLine command line arguments
+ * @throws Throwable - Throws an exception in case test failure.
+ */
+ public void verify(String orig, String[] cmdLine) {
+ String lastLineOrig = getLastLine(orig);
+ String lastLine;
+ try {
+ lastLine = getLastLine(ProcessTools.executeTestJvm(cmdLine).getOutput().trim());
+ } catch (Throwable t) {
+ throw new Error("TESTBUG: Unexpedted exception during jvm execution.", t);
+ }
+ if (!isOutputExpected(lastLineOrig, lastLine)) {
+ throw new AssertionError("Unexpected random number sequence for mode: " + this.name());
+ }
+ }
+
+ private static String getLastLine(String output) {
+ return output.substring(output.lastIndexOf(Utils.NEW_LINE)).trim();
+ }
+ }
+
+ /**
+ * The helper class generates several random numbers
+ * and prints them out.
+ */
+ public static class RandomRunner {
+ private static final int COUNT = 10;
+ public static void main(String[] args) {
+ StringBuilder sb = new StringBuilder();
+ Random rng = Utils.getRandomInstance();
+ for (int i = 0; i < COUNT; i++) {
+ sb.append(rng.nextLong()).append(' ');
+ }
+ System.out.println(sb.toString());
+ }
+ }
+}