RFR(M): 8044186 Introduce a reproducible random generator
Sergei Kovalev
sergei.kovalev at oracle.com
Mon Sep 22 14:09:23 UTC 2014
Not exactly.
previous algorithm:
72: int seed = new Random().nextInt(); ///<-- No seed provided//. No
chance to reproduce issue with same seed/
86: runTest( << some VM options >>, seed)/// run test with one set of VM
options/
89: 86: runTest( << other VM options >>, seed) /// run test with other
VM options but with same seed/
144: new Integer(seed).toString(),/// add seed to command line/
189: Random rng = new Random(Integer.valueOf(args[1])); /// <-- here
args[1] == new Integer(seed).toString()/
In previous version seed passes via command line. In new version:
74: int seed = Utils.getRandomInstance().nextInt(); /// We able to get
same seed for different runs. Just provide system property./
90: runTest( << some VM options >>, seed)/// run test with one set of VM
options/
93: 86: runTest( << other VM options >>, seed) /// run test with other
VM options but with same seed/
146: "-D" + Utils.SEED_PROPERTY_NAME + "=" + seed, // Pass seed into
system property for subsequent calls
194: runTests(expr, iterations, Utils.getRandomInstance()); // using
seed that passed in line 146.
On 20.09.2014 00:58, David Chase wrote:
> I looked hard at Utils.java, that code looks fine.
>
> A question about BMITestRunner.java — I see
> 76 int seed = Utils.getRandomInstance().nextInt();
> …
> 146 "-D" + Utils.SEED_PROPERTY_NAME + "=" + seed,
>
> But is it guaranteed that
> (new Random(seed)).nextInt() == seed?
> which is what I think this accomplishes?
>
> I just checked, it seems not to be true, so this is not correct re-run advice.
Did you add -Dc.o.j.testlibrary.random.seed=<somevalue> to the command line?
To verify please run below class:
public class NewClass {
static long seed = -1;
public static void main(String[] args) {
System.out.println(new Random(seed).nextInt());
}
}
In my case it always printing out value: 1155099827
> Should Utils.java provide a method for obtaining the seed that was used
> so it may be queried, also?
>
> David (not a Reviewer)
>
> On 2014-09-19, at 9:57 AM, Sergei Kovalev <sergei.kovalev at oracle.com> wrote:
>
>> Hi All,
>>
>> I'm working for CR https://bugs.openjdk.java.net/browse/JDK-8044186 that submitted against tests.
>>
>> There's the several tests which use randomly generated numbers. It's needed to introduce a way that provide a common manner to reproduce the same random sequence, set seed.
>>
>> There are two possible way to provide seed value:
>> - system property
>> - command line arguments.
>>
>> I chose system property to provide seed value because it could be obtained in any part of code without additional effort. In case passing seed value as command line argument we have to introduce additional logic (and unwanted code) to pass this value in appropriate method.
>>
>> I introduced factory method getRandomInstance in the file Utility.java and make reference to this method in all applicable tests.
>> There is other utility class: Verifier.java. It used in several other testcases from test/compiler/intrinsics/mathexact/ package. Therefore many files contains modifications only for jtreg annotations.
>>
>> I've tested all related tests locally. All tests passed and seed value printed to the logs.
>>
>> links:
>> bug: https://bugs.openjdk.java.net/browse/JDK-8044186
>> webrev: http://cr.openjdk.java.net/~vlivanov/kovalev/8044186/webrev.00/
>>
>> --
>> With best regards,
>> Sergei
>>
--
With best regards,
Sergei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20140922/2a550370/attachment.html>
More information about the hotspot-compiler-dev
mailing list