Skip to content
Permalink
Browse files
8265137: java.util.Random suddenly has new public methods nowhere doc…
…umented

Reviewed-by: uschindler, darcy, smarks
  • Loading branch information
JimLaskey committed May 4, 2021
1 parent aa90df6 commit 05e601748a35de02a33721199a00a3d6c335c6d9
@@ -27,15 +27,12 @@

import java.io.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import jdk.internal.util.random.RandomSupport.*;

import jdk.internal.util.random.RandomSupport.AbstractSpliteratorGenerator;
import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
import jdk.internal.util.random.RandomSupport.RandomIntsSpliterator;
import jdk.internal.util.random.RandomSupport.RandomLongsSpliterator;
import jdk.internal.util.random.RandomSupport.RandomDoublesSpliterator;
import static jdk.internal.util.random.RandomSupport.*;

import jdk.internal.misc.Unsafe;
@@ -85,8 +82,7 @@
i = 48, j = 0, k = 0,
equidistribution = 0
)
public class Random extends AbstractSpliteratorGenerator
implements java.io.Serializable {
public class Random implements RandomGenerator, java.io.Serializable {
/** use serialVersionUID from JDK 1.1 for interoperability */
@java.io.Serial
static final long serialVersionUID = 3905348978240129619L;
@@ -615,32 +611,6 @@ private void resetSeed(long seedVal) {
unsafe.putReferenceVolatile(this, seedOffset, new AtomicLong(seedVal));
}

// Methods required by class AbstractSpliteratorGenerator

/**
* @hidden
*/
@Override
public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
return new RandomIntsSpliterator(this, index, fence, origin, bound);
}

/**
* @hidden
*/
@Override
public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
return new RandomLongsSpliterator(this, index, fence, origin, bound);
}

/**
* @hidden
*/
@Override
public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
return new RandomDoublesSpliterator(this, index, fence, origin, bound);
}

/**
* Returns a stream producing the given {@code streamSize} number of
* pseudorandom {@code int} values.
@@ -656,7 +626,7 @@ private void resetSeed(long seedVal) {
*/
@Override
public IntStream ints(long streamSize) {
return super.ints(streamSize);
return AbstractSpliteratorGenerator.ints(this, streamSize);
}

/**
@@ -674,7 +644,7 @@ public IntStream ints(long streamSize) {
*/
@Override
public IntStream ints() {
return super.ints();
return AbstractSpliteratorGenerator.ints(this);
}

/**
@@ -711,7 +681,7 @@ public IntStream ints() {
*/
@Override
public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
return super.ints(streamSize, randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.ints(this, streamSize, randomNumberOrigin, randomNumberBound);
}

/**
@@ -749,7 +719,7 @@ public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberB
*/
@Override
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
return super.ints(randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.ints(this, randomNumberOrigin, randomNumberBound);
}

/**
@@ -767,7 +737,7 @@ public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
*/
@Override
public LongStream longs(long streamSize) {
return super.longs(streamSize);
return AbstractSpliteratorGenerator.longs(this, streamSize);
}

/**
@@ -785,7 +755,7 @@ public LongStream longs(long streamSize) {
*/
@Override
public LongStream longs() {
return super.longs();
return AbstractSpliteratorGenerator.longs(this);
}

/**
@@ -827,7 +797,7 @@ public LongStream longs() {
*/
@Override
public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) {
return super.longs(streamSize, randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.longs(this, streamSize, randomNumberOrigin, randomNumberBound);
}

/**
@@ -870,7 +840,7 @@ public LongStream longs(long streamSize, long randomNumberOrigin, long randomNum
*/
@Override
public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
return super.longs(randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.longs(this, randomNumberOrigin, randomNumberBound);
}

/**
@@ -889,7 +859,7 @@ public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
*/
@Override
public DoubleStream doubles(long streamSize) {
return super.doubles(streamSize);
return AbstractSpliteratorGenerator.doubles(this, streamSize);
}

/**
@@ -908,7 +878,7 @@ public DoubleStream doubles(long streamSize) {
*/
@Override
public DoubleStream doubles() {
return super.doubles();
return AbstractSpliteratorGenerator.doubles(this);
}

/**
@@ -940,7 +910,7 @@ public DoubleStream doubles() {
*/
@Override
public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) {
return super.doubles(streamSize, randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.doubles(this, streamSize, randomNumberOrigin, randomNumberBound);
}

/**
@@ -972,6 +942,6 @@ public DoubleStream doubles(long streamSize, double randomNumberOrigin, double r
*/
@Override
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
return super.doubles(randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.doubles(this, randomNumberOrigin, randomNumberBound);
}
}
@@ -280,30 +280,6 @@ public SplittableRandom split(SplittableGenerator source) {
return new SplittableRandom(source.nextLong(), mixGamma(source.nextLong()));
}

/**
* @hidden
*/
@Override
public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
return super.makeIntsSpliterator(index, fence, origin, bound);
}

/**
* @hidden
*/
@Override
public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
return super.makeLongsSpliterator(index, fence, origin, bound);
}

/**
* @hidden
*/
@Override
public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
return super.makeDoublesSpliterator(index, fence, origin, bound);
}

@Override
public int nextInt() {
return mix32(nextSeed());
@@ -51,11 +51,7 @@
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import jdk.internal.util.random.RandomSupport;
import jdk.internal.util.random.RandomSupport.AbstractSpliteratorGenerator;
import jdk.internal.util.random.RandomSupport.RandomIntsSpliterator;
import jdk.internal.util.random.RandomSupport.RandomLongsSpliterator;
import jdk.internal.util.random.RandomSupport.RandomDoublesSpliterator;
import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
import jdk.internal.util.random.RandomSupport.*;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;

@@ -396,48 +392,6 @@ private Object readResolve() {
/** The common ThreadLocalRandom */
private static final ThreadLocalRandom instance = new ThreadLocalRandom();

private static final class ThreadLocalRandomProxy extends Random {
@java.io.Serial
static final long serialVersionUID = 0L;


static final AbstractSpliteratorGenerator proxy = new ThreadLocalRandomProxy();


public int nextInt() {
return ThreadLocalRandom.current().nextInt();
}

public long nextLong() {
return ThreadLocalRandom.current().nextLong();
}
}

// Methods required by class AbstractSpliteratorGenerator
/**
* @hidden
*/
@Override
public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
return new RandomIntsSpliterator(ThreadLocalRandomProxy.proxy, index, fence, origin, bound);
}

/**
* @hidden
*/
@Override
public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
return new RandomLongsSpliterator(ThreadLocalRandomProxy.proxy, index, fence, origin, bound);
}

/**
* @hidden
*/
@Override
public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
return new RandomDoublesSpliterator(ThreadLocalRandomProxy.proxy, index, fence, origin, bound);
}

/**
* The next seed for default constructors.
*/
@@ -457,6 +411,19 @@ public long nextLong() {
}
}

@SuppressWarnings("serial")
private static final class ThreadLocalRandomProxy extends Random {
static final Random PROXY = new ThreadLocalRandomProxy();

public int nextInt() {
return ThreadLocalRandom.current().nextInt();
}

public long nextLong() {
return ThreadLocalRandom.current().nextLong();
}
}

/**
* {@inheritDoc}
*/
@@ -579,7 +546,7 @@ public double nextDouble(double origin, double bound) {
*/
@Override
public IntStream ints(long streamSize) {
return super.ints(streamSize);
return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY, streamSize);
}

/**
@@ -590,7 +557,7 @@ public IntStream ints(long streamSize) {
*/
@Override
public IntStream ints() {
return super.ints();
return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY);
}

/**
@@ -600,7 +567,7 @@ public IntStream ints() {
*/
@Override
public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
return super.ints(streamSize, randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY, streamSize, randomNumberOrigin, randomNumberBound);
}

/**
@@ -612,7 +579,7 @@ public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberB
*/
@Override
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
return super.ints(randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY, randomNumberOrigin, randomNumberBound);
}

/**
@@ -622,7 +589,7 @@ public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
*/
@Override
public LongStream longs(long streamSize) {
return super.longs(streamSize);
return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY, streamSize);
}

/**
@@ -633,7 +600,7 @@ public LongStream longs(long streamSize) {
*/
@Override
public LongStream longs() {
return super.longs();
return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY);
}

/**
@@ -643,7 +610,7 @@ public LongStream longs() {
*/
@Override
public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) {
return super.longs(streamSize, randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY, streamSize, randomNumberOrigin, randomNumberBound);
}

/**
@@ -655,7 +622,7 @@ public LongStream longs(long streamSize, long randomNumberOrigin, long randomNum
*/
@Override
public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
return super.longs(randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY, randomNumberOrigin, randomNumberBound);
}

/**
@@ -665,7 +632,7 @@ public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
*/
@Override
public DoubleStream doubles(long streamSize) {
return super.doubles(streamSize);
return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY, streamSize);
}

/**
@@ -676,7 +643,7 @@ public DoubleStream doubles(long streamSize) {
*/
@Override
public DoubleStream doubles() {
return super.doubles();
return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY);
}

/**
@@ -686,7 +653,7 @@ public DoubleStream doubles() {
*/
@Override
public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) {
return super.doubles(streamSize, randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY, streamSize, randomNumberOrigin, randomNumberBound);
}

/**
@@ -698,7 +665,7 @@ public DoubleStream doubles(long streamSize, double randomNumberOrigin, double r
*/
@Override
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
return super.doubles(randomNumberOrigin, randomNumberBound);
return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY, randomNumberOrigin, randomNumberBound);
}

}

0 comments on commit 05e6017

Please sign in to comment.