Merge
This commit is contained in:
commit
98d46c08be
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -43,8 +43,6 @@ FILES_java = \
|
|||||||
com/sun/security/auth/UserPrincipal.java \
|
com/sun/security/auth/UserPrincipal.java \
|
||||||
com/sun/security/auth/LdapPrincipal.java \
|
com/sun/security/auth/LdapPrincipal.java \
|
||||||
com/sun/security/auth/PolicyFile.java \
|
com/sun/security/auth/PolicyFile.java \
|
||||||
com/sun/security/auth/SubjectCodeSource.java \
|
|
||||||
com/sun/security/auth/PolicyParser.java \
|
|
||||||
com/sun/security/auth/PrincipalComparator.java \
|
com/sun/security/auth/PrincipalComparator.java \
|
||||||
com/sun/security/auth/callback/TextCallbackHandler.java \
|
com/sun/security/auth/callback/TextCallbackHandler.java \
|
||||||
com/sun/security/auth/callback/DialogCallbackHandler.java
|
com/sun/security/auth/callback/DialogCallbackHandler.java
|
||||||
|
@ -65,10 +65,6 @@ PROFILE_2_JARS := \
|
|||||||
$(if $(PROFILE_2_JRE_JAR_FILES), $(addprefix $(IMAGES_OUTPUTDIR)/lib/, $(PROFILE_2_JRE_JAR_FILES))) \
|
$(if $(PROFILE_2_JRE_JAR_FILES), $(addprefix $(IMAGES_OUTPUTDIR)/lib/, $(PROFILE_2_JRE_JAR_FILES))) \
|
||||||
$(PROFILE_1_JARS)
|
$(PROFILE_1_JARS)
|
||||||
|
|
||||||
ifneq ($(ENABLE_JFR), true)
|
|
||||||
PROFILE_3_JRE_JAR_FILES := $(filter-out jfr.jar, $(PROFILE_3_JRE_JAR_FILES))
|
|
||||||
endif
|
|
||||||
|
|
||||||
PROFILE_3_JARS := \
|
PROFILE_3_JARS := \
|
||||||
$(addprefix $(IMAGES_OUTPUTDIR)/lib/, $(PROFILE_3_JRE_JAR_FILES)) \
|
$(addprefix $(IMAGES_OUTPUTDIR)/lib/, $(PROFILE_3_JRE_JAR_FILES)) \
|
||||||
$(PROFILE_2_JARS)
|
$(PROFILE_2_JARS)
|
||||||
@ -77,6 +73,10 @@ ifdef OPENJDK
|
|||||||
FULL_JRE_JAR_FILES := $(filter-out alt-rt.jar, $(FULL_JRE_JAR_FILES))
|
FULL_JRE_JAR_FILES := $(filter-out alt-rt.jar, $(FULL_JRE_JAR_FILES))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(ENABLE_JFR), true)
|
||||||
|
FULL_JRE_JAR_FILES := $(filter-out jfr.jar, $(FULL_JRE_JAR_FILES))
|
||||||
|
endif
|
||||||
|
|
||||||
FULL_JRE_JARS := \
|
FULL_JRE_JARS := \
|
||||||
$(addprefix $(IMAGES_OUTPUTDIR)/lib/, $(FULL_JRE_JAR_FILES)) \
|
$(addprefix $(IMAGES_OUTPUTDIR)/lib/, $(FULL_JRE_JAR_FILES)) \
|
||||||
$(PROFILE_3_JARS)
|
$(PROFILE_3_JARS)
|
||||||
|
@ -87,6 +87,7 @@ class KQueueArrayWrapper {
|
|||||||
private int incomingInterruptFD;
|
private int incomingInterruptFD;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
IOUtil.load();
|
||||||
initStructSizes();
|
initStructSizes();
|
||||||
String datamodel = java.security.AccessController.doPrivileged(
|
String datamodel = java.security.AccessController.doPrivileged(
|
||||||
new sun.security.action.GetPropertyAction("sun.arch.data.model")
|
new sun.security.action.GetPropertyAction("sun.arch.data.model")
|
||||||
|
@ -246,9 +246,4 @@ class KQueueSelectorImpl
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
Util.load();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,12 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "SDE.h"
|
#include "SDE.h"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
/* use setjmp/longjmp versions that do not save/restore the signal mask */
|
||||||
|
#define setjmp _setjmp
|
||||||
|
#define longjmp _longjmp
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This SourceDebugExtension code does not
|
* This SourceDebugExtension code does not
|
||||||
* allow concurrent translation - due to caching method.
|
* allow concurrent translation - due to caching method.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -59,7 +59,7 @@ import java.io.IOException;
|
|||||||
* {@link java.lang.instrument} for a detailed description on how these agents
|
* {@link java.lang.instrument} for a detailed description on how these agents
|
||||||
* are loaded and started). The {@link #loadAgentLibrary loadAgentLibrary} and
|
* are loaded and started). The {@link #loadAgentLibrary loadAgentLibrary} and
|
||||||
* {@link #loadAgentPath loadAgentPath} methods are used to load agents that
|
* {@link #loadAgentPath loadAgentPath} methods are used to load agents that
|
||||||
* are deployed in a dynamic library and make use of the <a
|
* are deployed either in a dynamic library or statically linked into the VM and make use of the <a
|
||||||
* href="../../../../../../../../technotes/guides/jvmti/index.html">JVM Tools
|
* href="../../../../../../../../technotes/guides/jvmti/index.html">JVM Tools
|
||||||
* Interface</a>. </p>
|
* Interface</a>. </p>
|
||||||
*
|
*
|
||||||
@ -298,25 +298,29 @@ public abstract class VirtualMachine {
|
|||||||
* <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
|
* <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
|
||||||
* TI</a> client is called an <i>agent</i>. It is developed in a native language.
|
* TI</a> client is called an <i>agent</i>. It is developed in a native language.
|
||||||
* A JVM TI agent is deployed in a platform specific manner but it is typically the
|
* A JVM TI agent is deployed in a platform specific manner but it is typically the
|
||||||
* platform equivalent of a dynamic library. This method causes the given agent
|
* platform equivalent of a dynamic library. Alternatively, it may be statically linked into the VM.
|
||||||
* library to be loaded into the target VM (if not already loaded).
|
* This method causes the given agent library to be loaded into the target
|
||||||
|
* VM (if not already loaded or if not statically linked into the VM).
|
||||||
* It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
|
* It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
|
||||||
|
* or, for a statically linked agent named 'L', the <code>Agent_OnAttach_L</code> function
|
||||||
* as specified in the
|
* as specified in the
|
||||||
* <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
|
* <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
|
||||||
* Interface</a> specification. Note that the <code>Agent_OnAttach</code>
|
* Interface</a> specification. Note that the <code>Agent_OnAttach[_L]</code>
|
||||||
* function is invoked even if the agent library was loaded prior to invoking
|
* function is invoked even if the agent library was loaded prior to invoking
|
||||||
* this method.
|
* this method.
|
||||||
*
|
*
|
||||||
* <p> The agent library provided is the name of the agent library. It is interpreted
|
* <p> The agent library provided is the name of the agent library. It is interpreted
|
||||||
* in the target virtual machine in an implementation-dependent manner. Typically an
|
* in the target virtual machine in an implementation-dependent manner. Typically an
|
||||||
* implementation will expand the library name into an operating system specific file
|
* implementation will expand the library name into an operating system specific file
|
||||||
* name. For example, on UNIX systems, the name <tt>foo</tt> might be expanded to
|
* name. For example, on UNIX systems, the name <tt>L</tt> might be expanded to
|
||||||
* <tt>libfoo.so</tt>, and located using the search path specified by the
|
* <tt>libL.so</tt>, and located using the search path specified by the
|
||||||
* <tt>LD_LIBRARY_PATH</tt> environment variable.</p>
|
* <tt>LD_LIBRARY_PATH</tt> environment variable. If the agent named 'L' is
|
||||||
|
* statically linked into the VM then the VM must export a function named
|
||||||
|
* <code>Agent_OnAttach_L</code>.</p>
|
||||||
*
|
*
|
||||||
* <p> If the <code>Agent_OnAttach</code> function in the agent library returns
|
* <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
|
||||||
* an error then an {@link com.sun.tools.attach.AgentInitializationException} is
|
* an error then an {@link com.sun.tools.attach.AgentInitializationException} is
|
||||||
* thrown. The return value from the <code>Agent_OnAttach</code> can then be
|
* thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
|
||||||
* obtained by invoking the {@link
|
* obtained by invoking the {@link
|
||||||
* com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
|
* com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
|
||||||
* method on the exception. </p>
|
* method on the exception. </p>
|
||||||
@ -325,15 +329,16 @@ public abstract class VirtualMachine {
|
|||||||
* The name of the agent library.
|
* The name of the agent library.
|
||||||
*
|
*
|
||||||
* @param options
|
* @param options
|
||||||
* The options to provide to the <code>Agent_OnAttach</code>
|
* The options to provide to the <code>Agent_OnAttach[_L]</code>
|
||||||
* function (can be <code>null</code>).
|
* function (can be <code>null</code>).
|
||||||
*
|
*
|
||||||
* @throws AgentLoadException
|
* @throws AgentLoadException
|
||||||
* If the agent library does not exist, or cannot be loaded for
|
* If the agent library does not exist, the agent library is not
|
||||||
* another reason.
|
* statically linked with the VM, or the agent library cannot be
|
||||||
|
* loaded for another reason.
|
||||||
*
|
*
|
||||||
* @throws AgentInitializationException
|
* @throws AgentInitializationException
|
||||||
* If the <code>Agent_OnAttach</code> function returns an error
|
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* If an I/O error occurs
|
* If an I/O error occurs
|
||||||
@ -359,11 +364,12 @@ public abstract class VirtualMachine {
|
|||||||
* The name of the agent library.
|
* The name of the agent library.
|
||||||
*
|
*
|
||||||
* @throws AgentLoadException
|
* @throws AgentLoadException
|
||||||
* If the agent library does not exist, or cannot be loaded for
|
* If the agent library does not exist, the agent library is not
|
||||||
* another reason.
|
* statically linked with the VM, or the agent library cannot be
|
||||||
|
* loaded for another reason.
|
||||||
*
|
*
|
||||||
* @throws AgentInitializationException
|
* @throws AgentInitializationException
|
||||||
* If the <code>Agent_OnAttach</code> function returns an error
|
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* If an I/O error occurs
|
* If an I/O error occurs
|
||||||
@ -383,12 +389,23 @@ public abstract class VirtualMachine {
|
|||||||
* <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
|
* <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
|
||||||
* TI</a> client is called an <i>agent</i>. It is developed in a native language.
|
* TI</a> client is called an <i>agent</i>. It is developed in a native language.
|
||||||
* A JVM TI agent is deployed in a platform specific manner but it is typically the
|
* A JVM TI agent is deployed in a platform specific manner but it is typically the
|
||||||
* platform equivalent of a dynamic library. This method causes the given agent
|
* platform equivalent of a dynamic library. Alternatively, the native
|
||||||
* library to be loaded into the target VM (if not already loaded).
|
* library specified by the agentPath parameter may be statically
|
||||||
* It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
|
* linked with the VM. The parsing of the agentPath parameter into
|
||||||
* as specified in the
|
* a statically linked library name is done in a platform
|
||||||
|
* specific manner in the VM. For example, in UNIX, an agentPath parameter
|
||||||
|
* of <code>/a/b/libL.so</code> would name a library 'L'.
|
||||||
|
*
|
||||||
|
* See the JVM TI Specification for more details.
|
||||||
|
*
|
||||||
|
* This method causes the given agent library to be loaded into the target
|
||||||
|
* VM (if not already loaded or if not statically linked into the VM).
|
||||||
|
* It then causes the target VM to invoke the <code>Agent_OnAttach</code>
|
||||||
|
* function or, for a statically linked agent named 'L', the
|
||||||
|
* <code>Agent_OnAttach_L</code> function as specified in the
|
||||||
* <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
|
* <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
|
||||||
* Interface</a> specification. Note that the <code>Agent_OnAttach</code>
|
* Interface</a> specification.
|
||||||
|
* Note that the <code>Agent_OnAttach[_L]</code>
|
||||||
* function is invoked even if the agent library was loaded prior to invoking
|
* function is invoked even if the agent library was loaded prior to invoking
|
||||||
* this method.
|
* this method.
|
||||||
*
|
*
|
||||||
@ -396,9 +413,9 @@ public abstract class VirtualMachine {
|
|||||||
* agent library. Unlike {@link #loadAgentLibrary loadAgentLibrary}, the library name
|
* agent library. Unlike {@link #loadAgentLibrary loadAgentLibrary}, the library name
|
||||||
* is not expanded in the target virtual machine. </p>
|
* is not expanded in the target virtual machine. </p>
|
||||||
*
|
*
|
||||||
* <p> If the <code>Agent_OnAttach</code> function in the agent library returns
|
* <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
|
||||||
* an error then an {@link com.sun.tools.attach.AgentInitializationException} is
|
* an error then an {@link com.sun.tools.attach.AgentInitializationException} is
|
||||||
* thrown. The return value from the <code>Agent_OnAttach</code> can then be
|
* thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
|
||||||
* obtained by invoking the {@link
|
* obtained by invoking the {@link
|
||||||
* com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
|
* com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
|
||||||
* method on the exception. </p>
|
* method on the exception. </p>
|
||||||
@ -407,15 +424,16 @@ public abstract class VirtualMachine {
|
|||||||
* The full path of the agent library.
|
* The full path of the agent library.
|
||||||
*
|
*
|
||||||
* @param options
|
* @param options
|
||||||
* The options to provide to the <code>Agent_OnAttach</code>
|
* The options to provide to the <code>Agent_OnAttach[_L]</code>
|
||||||
* function (can be <code>null</code>).
|
* function (can be <code>null</code>).
|
||||||
*
|
*
|
||||||
* @throws AgentLoadException
|
* @throws AgentLoadException
|
||||||
* If the agent library does not exist, or cannot be loaded for
|
* If the agent library does not exist, the agent library is not
|
||||||
* another reason.
|
* statically linked with the VM, or the agent library cannot be
|
||||||
|
* loaded for another reason.
|
||||||
*
|
*
|
||||||
* @throws AgentInitializationException
|
* @throws AgentInitializationException
|
||||||
* If the <code>Agent_OnAttach</code> function returns an error
|
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* If an I/O error occurs
|
* If an I/O error occurs
|
||||||
@ -441,11 +459,12 @@ public abstract class VirtualMachine {
|
|||||||
* The full path to the agent library.
|
* The full path to the agent library.
|
||||||
*
|
*
|
||||||
* @throws AgentLoadException
|
* @throws AgentLoadException
|
||||||
* If the agent library does not exist, or cannot be loaded for
|
* If the agent library does not exist, the agent library is not
|
||||||
* another reason.
|
* statically linked with the VM, or the agent library cannot be
|
||||||
|
* loaded for another reason.
|
||||||
*
|
*
|
||||||
* @throws AgentInitializationException
|
* @throws AgentInitializationException
|
||||||
* If the <code>Agent_OnAttach</code> function returns an error
|
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* If an I/O error occurs
|
* If an I/O error occurs
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -50,7 +50,15 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
|||||||
public
|
public
|
||||||
class BufferedInputStream extends FilterInputStream {
|
class BufferedInputStream extends FilterInputStream {
|
||||||
|
|
||||||
private static int defaultBufferSize = 8192;
|
private static int DEFAULT_BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum size of array to allocate.
|
||||||
|
* Some VMs reserve some header words in an array.
|
||||||
|
* Attempts to allocate larger arrays may result in
|
||||||
|
* OutOfMemoryError: Requested array size exceeds VM limit
|
||||||
|
*/
|
||||||
|
private static int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal buffer array where the data is stored. When necessary,
|
* The internal buffer array where the data is stored. When necessary,
|
||||||
@ -172,7 +180,7 @@ class BufferedInputStream extends FilterInputStream {
|
|||||||
* @param in the underlying input stream.
|
* @param in the underlying input stream.
|
||||||
*/
|
*/
|
||||||
public BufferedInputStream(InputStream in) {
|
public BufferedInputStream(InputStream in) {
|
||||||
this(in, defaultBufferSize);
|
this(in, DEFAULT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -215,8 +223,11 @@ class BufferedInputStream extends FilterInputStream {
|
|||||||
} else if (buffer.length >= marklimit) {
|
} else if (buffer.length >= marklimit) {
|
||||||
markpos = -1; /* buffer got too big, invalidate mark */
|
markpos = -1; /* buffer got too big, invalidate mark */
|
||||||
pos = 0; /* drop buffer contents */
|
pos = 0; /* drop buffer contents */
|
||||||
|
} else if (buffer.length >= MAX_BUFFER_SIZE) {
|
||||||
|
throw new OutOfMemoryError("Required array size too large");
|
||||||
} else { /* grow buffer */
|
} else { /* grow buffer */
|
||||||
int nsz = pos * 2;
|
int nsz = (pos <= MAX_BUFFER_SIZE - pos) ?
|
||||||
|
pos * 2 : MAX_BUFFER_SIZE;
|
||||||
if (nsz > marklimit)
|
if (nsz > marklimit)
|
||||||
nsz = marklimit;
|
nsz = marklimit;
|
||||||
byte nbuf[] = new byte[nsz];
|
byte nbuf[] = new byte[nsz];
|
||||||
|
@ -1307,7 +1307,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
* specified substring, starting at the specified index. The integer
|
* specified substring, starting at the specified index. The integer
|
||||||
* returned is the smallest value {@code k} for which:
|
* returned is the smallest value {@code k} for which:
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
* k >= Math.min(fromIndex, str.length()) &&
|
* k >= Math.min(fromIndex, this.length()) &&
|
||||||
* this.toString().startsWith(str, k)
|
* this.toString().startsWith(str, k)
|
||||||
* </pre></blockquote>
|
* </pre></blockquote>
|
||||||
* If no such value of <i>k</i> exists, then -1 is returned.
|
* If no such value of <i>k</i> exists, then -1 is returned.
|
||||||
@ -1346,7 +1346,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
* specified substring. The integer returned is the largest value <i>k</i>
|
* specified substring. The integer returned is the largest value <i>k</i>
|
||||||
* such that:
|
* such that:
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
* k <= Math.min(fromIndex, str.length()) &&
|
* k <= Math.min(fromIndex, this.length()) &&
|
||||||
* this.toString().startsWith(str, k)
|
* this.toString().startsWith(str, k)
|
||||||
* </pre></blockquote>
|
* </pre></blockquote>
|
||||||
* If no such value of <i>k</i> exists, then -1 is returned.
|
* If no such value of <i>k</i> exists, then -1 is returned.
|
||||||
|
@ -3338,8 +3338,16 @@ public final class Class<T> implements java.io.Serializable,
|
|||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public AnnotatedType getAnnotatedSuperclass() {
|
public AnnotatedType getAnnotatedSuperclass() {
|
||||||
|
if (this == Object.class ||
|
||||||
|
isInterface() ||
|
||||||
|
isArray() ||
|
||||||
|
isPrimitive() ||
|
||||||
|
this == Void.TYPE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return TypeAnnotationParser.buildAnnotatedSuperclass(getRawTypeAnnotations(), getConstantPool(), this);
|
return TypeAnnotationParser.buildAnnotatedSuperclass(getRawTypeAnnotations(), getConstantPool(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of AnnotatedType objects that represent the use of types to
|
* Returns an array of AnnotatedType objects that represent the use of types to
|
||||||
|
@ -698,11 +698,8 @@ public final class Math {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Random randomNumberGenerator;
|
private static final class RandomNumberGeneratorHolder {
|
||||||
|
static final Random randomNumberGenerator = new Random();
|
||||||
private static synchronized Random initRNG() {
|
|
||||||
Random rnd = randomNumberGenerator;
|
|
||||||
return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -729,9 +726,7 @@ public final class Math {
|
|||||||
* @see Random#nextDouble()
|
* @see Random#nextDouble()
|
||||||
*/
|
*/
|
||||||
public static double random() {
|
public static double random() {
|
||||||
Random rnd = randomNumberGenerator;
|
return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();
|
||||||
if (rnd == null) rnd = initRNG();
|
|
||||||
return rnd.nextDouble();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.security.AccessControlException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -1033,9 +1032,9 @@ public final class ProcessBuilder
|
|||||||
// Can not disclose the fail reason for read-protected files.
|
// Can not disclose the fail reason for read-protected files.
|
||||||
try {
|
try {
|
||||||
security.checkRead(prog);
|
security.checkRead(prog);
|
||||||
} catch (AccessControlException ace) {
|
} catch (SecurityException se) {
|
||||||
exceptionInfo = "";
|
exceptionInfo = "";
|
||||||
cause = ace;
|
cause = se;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// It's much easier for us to create a high-quality error
|
// It's much easier for us to create a high-quality error
|
||||||
|
@ -678,11 +678,8 @@ public final class StrictMath {
|
|||||||
return Math.round(a);
|
return Math.round(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Random randomNumberGenerator;
|
private static final class RandomNumberGeneratorHolder {
|
||||||
|
static final Random randomNumberGenerator = new Random();
|
||||||
private static synchronized Random initRNG() {
|
|
||||||
Random rnd = randomNumberGenerator;
|
|
||||||
return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -709,9 +706,7 @@ public final class StrictMath {
|
|||||||
* @see Random#nextDouble()
|
* @see Random#nextDouble()
|
||||||
*/
|
*/
|
||||||
public static double random() {
|
public static double random() {
|
||||||
Random rnd = randomNumberGenerator;
|
return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();
|
||||||
if (rnd == null) rnd = initRNG();
|
|
||||||
return rnd.nextDouble();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2659,28 +2659,32 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
if (ys == 0)
|
if (ys == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int sdiff = this.scale - val.scale;
|
long sdiff = (long)this.scale - val.scale;
|
||||||
if (sdiff != 0) {
|
if (sdiff != 0) {
|
||||||
// Avoid matching scales if the (adjusted) exponents differ
|
// Avoid matching scales if the (adjusted) exponents differ
|
||||||
int xae = this.precision() - this.scale; // [-1]
|
long xae = (long)this.precision() - this.scale; // [-1]
|
||||||
int yae = val.precision() - val.scale; // [-1]
|
long yae = (long)val.precision() - val.scale; // [-1]
|
||||||
if (xae < yae)
|
if (xae < yae)
|
||||||
return -1;
|
return -1;
|
||||||
if (xae > yae)
|
if (xae > yae)
|
||||||
return 1;
|
return 1;
|
||||||
BigInteger rb = null;
|
BigInteger rb = null;
|
||||||
if (sdiff < 0) {
|
if (sdiff < 0) {
|
||||||
if ( (xs == INFLATED ||
|
// The cases sdiff <= Integer.MIN_VALUE intentionally fall through.
|
||||||
(xs = longMultiplyPowerTen(xs, -sdiff)) == INFLATED) &&
|
if ( sdiff > Integer.MIN_VALUE &&
|
||||||
|
(xs == INFLATED ||
|
||||||
|
(xs = longMultiplyPowerTen(xs, (int)-sdiff)) == INFLATED) &&
|
||||||
ys == INFLATED) {
|
ys == INFLATED) {
|
||||||
rb = bigMultiplyPowerTen(-sdiff);
|
rb = bigMultiplyPowerTen((int)-sdiff);
|
||||||
return rb.compareMagnitude(val.intVal);
|
return rb.compareMagnitude(val.intVal);
|
||||||
}
|
}
|
||||||
} else { // sdiff > 0
|
} else { // sdiff > 0
|
||||||
if ( (ys == INFLATED ||
|
// The cases sdiff > Integer.MAX_VALUE intentionally fall through.
|
||||||
(ys = longMultiplyPowerTen(ys, sdiff)) == INFLATED) &&
|
if ( sdiff <= Integer.MAX_VALUE &&
|
||||||
|
(ys == INFLATED ||
|
||||||
|
(ys = longMultiplyPowerTen(ys, (int)sdiff)) == INFLATED) &&
|
||||||
xs == INFLATED) {
|
xs == INFLATED) {
|
||||||
rb = val.bigMultiplyPowerTen(sdiff);
|
rb = val.bigMultiplyPowerTen((int)sdiff);
|
||||||
return this.intVal.compareMagnitude(rb);
|
return this.intVal.compareMagnitude(rb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4545,7 +4549,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
if(cmp > 0) { // satisfy constraint (b)
|
if(cmp > 0) { // satisfy constraint (b)
|
||||||
yscale -= 1; // [that is, divisor *= 10]
|
yscale -= 1; // [that is, divisor *= 10]
|
||||||
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
||||||
if (checkScaleNonZero((long) mcp + yscale) > xscale) {
|
if (checkScaleNonZero((long) mcp + yscale - xscale) > 0) {
|
||||||
// assert newScale >= xscale
|
// assert newScale >= xscale
|
||||||
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
||||||
long scaledXs;
|
long scaledXs;
|
||||||
@ -4626,7 +4630,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
// return BigDecimal object whose scale will be set to 'scl'.
|
// return BigDecimal object whose scale will be set to 'scl'.
|
||||||
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
||||||
BigDecimal quotient;
|
BigDecimal quotient;
|
||||||
if (checkScaleNonZero((long) mcp + yscale) > xscale) {
|
if (checkScaleNonZero((long) mcp + yscale - xscale) > 0) {
|
||||||
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
||||||
long scaledXs;
|
long scaledXs;
|
||||||
if ((scaledXs = longMultiplyPowerTen(xs, raise)) == INFLATED) {
|
if ((scaledXs = longMultiplyPowerTen(xs, raise)) == INFLATED) {
|
||||||
@ -4673,7 +4677,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
// return BigDecimal object whose scale will be set to 'scl'.
|
// return BigDecimal object whose scale will be set to 'scl'.
|
||||||
BigDecimal quotient;
|
BigDecimal quotient;
|
||||||
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
||||||
if (checkScaleNonZero((long) mcp + yscale) > xscale) {
|
if (checkScaleNonZero((long) mcp + yscale - xscale) > 0) {
|
||||||
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
||||||
BigInteger rb = bigMultiplyPowerTen(xs,raise);
|
BigInteger rb = bigMultiplyPowerTen(xs,raise);
|
||||||
quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
|
quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
|
||||||
@ -4714,7 +4718,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
// return BigDecimal object whose scale will be set to 'scl'.
|
// return BigDecimal object whose scale will be set to 'scl'.
|
||||||
BigDecimal quotient;
|
BigDecimal quotient;
|
||||||
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
||||||
if (checkScaleNonZero((long) mcp + yscale) > xscale) {
|
if (checkScaleNonZero((long) mcp + yscale - xscale) > 0) {
|
||||||
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
||||||
BigInteger rb = bigMultiplyPowerTen(xs,raise);
|
BigInteger rb = bigMultiplyPowerTen(xs,raise);
|
||||||
quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
|
quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
|
||||||
@ -4745,7 +4749,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
// return BigDecimal object whose scale will be set to 'scl'.
|
// return BigDecimal object whose scale will be set to 'scl'.
|
||||||
BigDecimal quotient;
|
BigDecimal quotient;
|
||||||
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
|
||||||
if (checkScaleNonZero((long) mcp + yscale) > xscale) {
|
if (checkScaleNonZero((long) mcp + yscale - xscale) > 0) {
|
||||||
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
int raise = checkScaleNonZero((long) mcp + yscale - xscale);
|
||||||
BigInteger rb = bigMultiplyPowerTen(xs,raise);
|
BigInteger rb = bigMultiplyPowerTen(xs,raise);
|
||||||
quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
|
quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
|
||||||
|
@ -2109,7 +2109,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||||||
// This is a quick way to approximate the size of the result,
|
// This is a quick way to approximate the size of the result,
|
||||||
// similar to doing log2[n] * exponent. This will give an upper bound
|
// similar to doing log2[n] * exponent. This will give an upper bound
|
||||||
// of how big the result can be, and which algorithm to use.
|
// of how big the result can be, and which algorithm to use.
|
||||||
int scaleFactor = remainingBits * exponent;
|
long scaleFactor = (long)remainingBits * exponent;
|
||||||
|
|
||||||
// Use slightly different algorithms for small and large operands.
|
// Use slightly different algorithms for small and large operands.
|
||||||
// See if the result will safely fit into a long. (Largest 2^63-1)
|
// See if the result will safely fit into a long. (Largest 2^63-1)
|
||||||
|
@ -50,13 +50,13 @@ import java.net.*;
|
|||||||
* @implNote
|
* @implNote
|
||||||
* <p>You can use the {@code RMISocketFactory} class to create a server socket that
|
* <p>You can use the {@code RMISocketFactory} class to create a server socket that
|
||||||
* is bound to a specific address, restricting the origin of requests. For example,
|
* is bound to a specific address, restricting the origin of requests. For example,
|
||||||
* the following code implements a socket factory that binds server sockets to the
|
* the following code implements a socket factory that binds server sockets to an IPv4
|
||||||
* loopback address. This restricts RMI to processing requests only from the local host.
|
* loopback address. This restricts RMI to processing requests only from the local host.
|
||||||
*
|
*
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
* class LoopbackSocketFactory extends RMISocketFactory {
|
* class LoopbackSocketFactory extends RMISocketFactory {
|
||||||
* public ServerSocket createServerSocket(int port) throws IOException {
|
* public ServerSocket createServerSocket(int port) throws IOException {
|
||||||
* return new ServerSocket(port, 5, InetAddress.getLoopbackAddress());
|
* return new ServerSocket(port, 5, InetAddress.getByName("127.0.0.1"));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* public Socket createSocket(String host, int port) throws IOException {
|
* public Socket createSocket(String host, int port) throws IOException {
|
||||||
@ -72,8 +72,8 @@ import java.net.*;
|
|||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
*
|
||||||
* Set the {@code java.rmi.server.hostname} system property
|
* Set the {@code java.rmi.server.hostname} system property
|
||||||
* to a host name (typically {@code localhost}) that resolves to the loopback
|
* to {@code 127.0.0.1} to ensure that the generated stubs connect to the right
|
||||||
* interface to ensure that the generated stubs use the right network interface.
|
* network interface.
|
||||||
*
|
*
|
||||||
* @author Ann Wollrath
|
* @author Ann Wollrath
|
||||||
* @author Peter Jones
|
* @author Peter Jones
|
||||||
|
@ -27,7 +27,6 @@ package java.util;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InvalidObjectException;
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -35,6 +34,7 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
@ -1148,7 +1148,16 @@ public class Collections {
|
|||||||
public Spliterator<E> spliterator() {
|
public Spliterator<E> spliterator() {
|
||||||
return (Spliterator<E>)c.spliterator();
|
return (Spliterator<E>)c.spliterator();
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Stream<E> stream() {
|
||||||
|
return (Stream<E>)c.stream();
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Stream<E> parallelStream() {
|
||||||
|
return (Stream<E>)c.parallelStream();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2009,8 +2018,8 @@ public class Collections {
|
|||||||
* through the returned collection.<p>
|
* through the returned collection.<p>
|
||||||
*
|
*
|
||||||
* It is imperative that the user manually synchronize on the returned
|
* It is imperative that the user manually synchronize on the returned
|
||||||
* collection when traversing it via {@link Iterator} or
|
* collection when traversing it via {@link Iterator}, {@link Spliterator}
|
||||||
* {@link Spliterator}:
|
* or {@link Stream}:
|
||||||
* <pre>
|
* <pre>
|
||||||
* Collection c = Collections.synchronizedCollection(myCollection);
|
* Collection c = Collections.synchronizedCollection(myCollection);
|
||||||
* ...
|
* ...
|
||||||
@ -2120,6 +2129,14 @@ public class Collections {
|
|||||||
public Spliterator<E> spliterator() {
|
public Spliterator<E> spliterator() {
|
||||||
return c.spliterator(); // Must be manually synched by user!
|
return c.spliterator(); // Must be manually synched by user!
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Stream<E> stream() {
|
||||||
|
return c.stream(); // Must be manually synched by user!
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Stream<E> parallelStream() {
|
||||||
|
return c.parallelStream(); // Must be manually synched by user!
|
||||||
|
}
|
||||||
private void writeObject(ObjectOutputStream s) throws IOException {
|
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||||
synchronized (mutex) {s.defaultWriteObject();}
|
synchronized (mutex) {s.defaultWriteObject();}
|
||||||
}
|
}
|
||||||
@ -3172,6 +3189,10 @@ public class Collections {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Spliterator<E> spliterator() {return c.spliterator();}
|
public Spliterator<E> spliterator() {return c.spliterator();}
|
||||||
|
@Override
|
||||||
|
public Stream<E> stream() {return c.stream();}
|
||||||
|
@Override
|
||||||
|
public Stream<E> parallelStream() {return c.parallelStream();}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5096,6 +5117,22 @@ public class Collections {
|
|||||||
") > toIndex(" + toIndex + ")");
|
") > toIndex(" + toIndex + ")");
|
||||||
return new CopiesList<>(toIndex - fromIndex, element);
|
return new CopiesList<>(toIndex - fromIndex, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override default methods in Collection
|
||||||
|
@Override
|
||||||
|
public Stream<E> stream() {
|
||||||
|
return IntStream.range(0, n).mapToObj(i -> element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<E> parallelStream() {
|
||||||
|
return IntStream.range(0, n).parallel().mapToObj(i -> element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Spliterator<E> spliterator() {
|
||||||
|
return stream().spliterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5503,6 +5540,10 @@ public class Collections {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Spliterator<E> spliterator() {return s.spliterator();}
|
public Spliterator<E> spliterator() {return s.spliterator();}
|
||||||
|
@Override
|
||||||
|
public Stream<E> stream() {return s.stream();}
|
||||||
|
@Override
|
||||||
|
public Stream<E> parallelStream() {return s.parallelStream();}
|
||||||
|
|
||||||
private static final long serialVersionUID = 2454657854757543876L;
|
private static final long serialVersionUID = 2454657854757543876L;
|
||||||
|
|
||||||
@ -5568,10 +5609,14 @@ public class Collections {
|
|||||||
@Override
|
@Override
|
||||||
public void forEach(Consumer<? super E> action) {q.forEach(action);}
|
public void forEach(Consumer<? super E> action) {q.forEach(action);}
|
||||||
@Override
|
@Override
|
||||||
public Spliterator<E> spliterator() {return q.spliterator();}
|
|
||||||
@Override
|
|
||||||
public boolean removeIf(Predicate<? super E> filter) {
|
public boolean removeIf(Predicate<? super E> filter) {
|
||||||
return q.removeIf(filter);
|
return q.removeIf(filter);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Spliterator<E> spliterator() {return q.spliterator();}
|
||||||
|
@Override
|
||||||
|
public Stream<E> stream() {return q.stream();}
|
||||||
|
@Override
|
||||||
|
public Stream<E> parallelStream() {return q.parallelStream();}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright 2009 Google Inc. All Rights Reserved.
|
* Copyright 2009 Google Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -146,7 +147,7 @@ class ComparableTimSort {
|
|||||||
*/
|
*/
|
||||||
int stackLen = (len < 120 ? 5 :
|
int stackLen = (len < 120 ? 5 :
|
||||||
len < 1542 ? 10 :
|
len < 1542 ? 10 :
|
||||||
len < 119151 ? 19 : 40);
|
len < 119151 ? 24 : 40);
|
||||||
runBase = new int[stackLen];
|
runBase = new int[stackLen];
|
||||||
runLen = new int[stackLen];
|
runLen = new int[stackLen];
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ public interface Comparator<T> {
|
|||||||
* composed using following code,
|
* composed using following code,
|
||||||
*
|
*
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
* Comparator<String> cmp = Comparator.comparing(String::length)
|
* Comparator<String> cmp = Comparator.comparingInt(String::length)
|
||||||
* .thenComparing(String.CASE_INSENSITIVE_ORDER);
|
* .thenComparing(String.CASE_INSENSITIVE_ORDER);
|
||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
*
|
||||||
@ -270,18 +270,18 @@ public interface Comparator<T> {
|
|||||||
* extracts a {@code int} sort key.
|
* extracts a {@code int} sort key.
|
||||||
*
|
*
|
||||||
* @implSpec This default implementation behaves as if {@code
|
* @implSpec This default implementation behaves as if {@code
|
||||||
* thenComparing(comparing(keyExtractor))}.
|
* thenComparing(comparingInt(keyExtractor))}.
|
||||||
*
|
*
|
||||||
* @param keyExtractor the function used to extract the integer sort key
|
* @param keyExtractor the function used to extract the integer sort key
|
||||||
* @return a lexicographic-order comparator composed of this and then the
|
* @return a lexicographic-order comparator composed of this and then the
|
||||||
* {@code int} sort key
|
* {@code int} sort key
|
||||||
* @throws NullPointerException if the argument is null.
|
* @throws NullPointerException if the argument is null.
|
||||||
* @see #comparing(ToIntFunction)
|
* @see #comparingInt(ToIntFunction)
|
||||||
* @see #thenComparing(Comparator)
|
* @see #thenComparing(Comparator)
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
default Comparator<T> thenComparing(ToIntFunction<? super T> keyExtractor) {
|
default Comparator<T> thenComparingInt(ToIntFunction<? super T> keyExtractor) {
|
||||||
return thenComparing(comparing(keyExtractor));
|
return thenComparing(comparingInt(keyExtractor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -289,18 +289,18 @@ public interface Comparator<T> {
|
|||||||
* extracts a {@code long} sort key.
|
* extracts a {@code long} sort key.
|
||||||
*
|
*
|
||||||
* @implSpec This default implementation behaves as if {@code
|
* @implSpec This default implementation behaves as if {@code
|
||||||
* thenComparing(comparing(keyExtractor))}.
|
* thenComparing(comparingLong(keyExtractor))}.
|
||||||
*
|
*
|
||||||
* @param keyExtractor the function used to extract the long sort key
|
* @param keyExtractor the function used to extract the long sort key
|
||||||
* @return a lexicographic-order comparator composed of this and then the
|
* @return a lexicographic-order comparator composed of this and then the
|
||||||
* {@code long} sort key
|
* {@code long} sort key
|
||||||
* @throws NullPointerException if the argument is null.
|
* @throws NullPointerException if the argument is null.
|
||||||
* @see #comparing(ToLongFunction)
|
* @see #comparingLong(ToLongFunction)
|
||||||
* @see #thenComparing(Comparator)
|
* @see #thenComparing(Comparator)
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
default Comparator<T> thenComparing(ToLongFunction<? super T> keyExtractor) {
|
default Comparator<T> thenComparingLong(ToLongFunction<? super T> keyExtractor) {
|
||||||
return thenComparing(comparing(keyExtractor));
|
return thenComparing(comparingLong(keyExtractor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,18 +308,18 @@ public interface Comparator<T> {
|
|||||||
* extracts a {@code double} sort key.
|
* extracts a {@code double} sort key.
|
||||||
*
|
*
|
||||||
* @implSpec This default implementation behaves as if {@code
|
* @implSpec This default implementation behaves as if {@code
|
||||||
* thenComparing(comparing(keyExtractor))}.
|
* thenComparing(comparingDouble(keyExtractor))}.
|
||||||
*
|
*
|
||||||
* @param keyExtractor the function used to extract the double sort key
|
* @param keyExtractor the function used to extract the double sort key
|
||||||
* @return a lexicographic-order comparator composed of this and then the
|
* @return a lexicographic-order comparator composed of this and then the
|
||||||
* {@code double} sort key
|
* {@code double} sort key
|
||||||
* @throws NullPointerException if the argument is null.
|
* @throws NullPointerException if the argument is null.
|
||||||
* @see #comparing(ToDoubleFunction)
|
* @see #comparingDouble(ToDoubleFunction)
|
||||||
* @see #thenComparing(Comparator)
|
* @see #thenComparing(Comparator)
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
default Comparator<T> thenComparing(ToDoubleFunction<? super T> keyExtractor) {
|
default Comparator<T> thenComparingDouble(ToDoubleFunction<? super T> keyExtractor) {
|
||||||
return thenComparing(comparing(keyExtractor));
|
return thenComparing(comparingDouble(keyExtractor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -484,7 +484,7 @@ public interface Comparator<T> {
|
|||||||
* @throws NullPointerException if the argument is null
|
* @throws NullPointerException if the argument is null
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public static <T> Comparator<T> comparing(ToIntFunction<? super T> keyExtractor) {
|
public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor) {
|
||||||
Objects.requireNonNull(keyExtractor);
|
Objects.requireNonNull(keyExtractor);
|
||||||
return (Comparator<T> & Serializable)
|
return (Comparator<T> & Serializable)
|
||||||
(c1, c2) -> Integer.compare(keyExtractor.applyAsInt(c1), keyExtractor.applyAsInt(c2));
|
(c1, c2) -> Integer.compare(keyExtractor.applyAsInt(c1), keyExtractor.applyAsInt(c2));
|
||||||
@ -505,7 +505,7 @@ public interface Comparator<T> {
|
|||||||
* @throws NullPointerException if the argument is null
|
* @throws NullPointerException if the argument is null
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public static <T> Comparator<T> comparing(ToLongFunction<? super T> keyExtractor) {
|
public static <T> Comparator<T> comparingLong(ToLongFunction<? super T> keyExtractor) {
|
||||||
Objects.requireNonNull(keyExtractor);
|
Objects.requireNonNull(keyExtractor);
|
||||||
return (Comparator<T> & Serializable)
|
return (Comparator<T> & Serializable)
|
||||||
(c1, c2) -> Long.compare(keyExtractor.applyAsLong(c1), keyExtractor.applyAsLong(c2));
|
(c1, c2) -> Long.compare(keyExtractor.applyAsLong(c1), keyExtractor.applyAsLong(c2));
|
||||||
@ -526,7 +526,7 @@ public interface Comparator<T> {
|
|||||||
* @throws NullPointerException if the argument is null
|
* @throws NullPointerException if the argument is null
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public static<T> Comparator<T> comparing(ToDoubleFunction<? super T> keyExtractor) {
|
public static<T> Comparator<T> comparingDouble(ToDoubleFunction<? super T> keyExtractor) {
|
||||||
Objects.requireNonNull(keyExtractor);
|
Objects.requireNonNull(keyExtractor);
|
||||||
return (Comparator<T> & Serializable)
|
return (Comparator<T> & Serializable)
|
||||||
(c1, c2) -> Double.compare(keyExtractor.applyAsDouble(c1), keyExtractor.applyAsDouble(c2));
|
(c1, c2) -> Double.compare(keyExtractor.applyAsDouble(c1), keyExtractor.applyAsDouble(c2));
|
||||||
|
@ -26,9 +26,13 @@
|
|||||||
package java.util;
|
package java.util;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.function.DoubleConsumer;
|
||||||
|
import java.util.function.IntConsumer;
|
||||||
|
import java.util.function.LongConsumer;
|
||||||
import java.util.stream.DoubleStream;
|
import java.util.stream.DoubleStream;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import java.util.stream.LongStream;
|
import java.util.stream.LongStream;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
import sun.misc.Unsafe;
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
@ -85,6 +89,13 @@ class Random implements java.io.Serializable {
|
|||||||
private static final long addend = 0xBL;
|
private static final long addend = 0xBL;
|
||||||
private static final long mask = (1L << 48) - 1;
|
private static final long mask = (1L << 48) - 1;
|
||||||
|
|
||||||
|
private static final double DOUBLE_UNIT = 1.0 / (1L << 53);
|
||||||
|
|
||||||
|
// IllegalArgumentException messages
|
||||||
|
static final String BadBound = "bound must be positive";
|
||||||
|
static final String BadRange = "bound must be greater than origin";
|
||||||
|
static final String BadSize = "size must be non-negative";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new random number generator. This constructor sets
|
* Creates a new random number generator. This constructor sets
|
||||||
* the seed of the random number generator to a value very likely
|
* the seed of the random number generator to a value very likely
|
||||||
@ -221,6 +232,82 @@ class Random implements java.io.Serializable {
|
|||||||
bytes[i++] = (byte)rnd;
|
bytes[i++] = (byte)rnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form of nextLong used by LongStream Spliterators. If
|
||||||
|
* origin is greater than bound, acts as unbounded form of
|
||||||
|
* nextLong, else as bounded form.
|
||||||
|
*
|
||||||
|
* @param origin the least value, unless greater than bound
|
||||||
|
* @param bound the upper bound (exclusive), must not equal origin
|
||||||
|
* @return a pseudorandom value
|
||||||
|
*/
|
||||||
|
final long internalNextLong(long origin, long bound) {
|
||||||
|
long r = nextLong();
|
||||||
|
if (origin < bound) {
|
||||||
|
long n = bound - origin, m = n - 1;
|
||||||
|
if ((n & m) == 0L) // power of two
|
||||||
|
r = (r & m) + origin;
|
||||||
|
else if (n > 0L) { // reject over-represented candidates
|
||||||
|
for (long u = r >>> 1; // ensure nonnegative
|
||||||
|
u + m - (r = u % n) < 0L; // rejection check
|
||||||
|
u = nextLong() >>> 1) // retry
|
||||||
|
;
|
||||||
|
r += origin;
|
||||||
|
}
|
||||||
|
else { // range not representable as long
|
||||||
|
while (r < origin || r >= bound)
|
||||||
|
r = nextLong();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form of nextInt used by IntStream Spliterators.
|
||||||
|
* For the unbounded case: uses nextInt().
|
||||||
|
* For the bounded case with representable range: uses nextInt(int bound)
|
||||||
|
* For the bounded case with unrepresentable range: uses nextInt()
|
||||||
|
*
|
||||||
|
* @param origin the least value, unless greater than bound
|
||||||
|
* @param bound the upper bound (exclusive), must not equal origin
|
||||||
|
* @return a pseudorandom value
|
||||||
|
*/
|
||||||
|
final int internalNextInt(int origin, int bound) {
|
||||||
|
if (origin < bound) {
|
||||||
|
int n = bound - origin;
|
||||||
|
if (n > 0) {
|
||||||
|
return nextInt(n) + origin;
|
||||||
|
}
|
||||||
|
else { // range not representable as int
|
||||||
|
int r;
|
||||||
|
do {
|
||||||
|
r = nextInt();
|
||||||
|
} while (r < origin || r >= bound);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form of nextDouble used by DoubleStream Spliterators.
|
||||||
|
*
|
||||||
|
* @param origin the least value, unless greater than bound
|
||||||
|
* @param bound the upper bound (exclusive), must not equal origin
|
||||||
|
* @return a pseudorandom value
|
||||||
|
*/
|
||||||
|
final double internalNextDouble(double origin, double bound) {
|
||||||
|
double r = nextDouble();
|
||||||
|
if (origin < bound) {
|
||||||
|
r = r * (bound - origin) + origin;
|
||||||
|
if (r >= bound) // correct for rounding
|
||||||
|
r = Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next pseudorandom, uniformly distributed {@code int}
|
* Returns the next pseudorandom, uniformly distributed {@code int}
|
||||||
* value from this random number generator's sequence. The general
|
* value from this random number generator's sequence. The general
|
||||||
@ -247,23 +334,23 @@ class Random implements java.io.Serializable {
|
|||||||
* between 0 (inclusive) and the specified value (exclusive), drawn from
|
* between 0 (inclusive) and the specified value (exclusive), drawn from
|
||||||
* this random number generator's sequence. The general contract of
|
* this random number generator's sequence. The general contract of
|
||||||
* {@code nextInt} is that one {@code int} value in the specified range
|
* {@code nextInt} is that one {@code int} value in the specified range
|
||||||
* is pseudorandomly generated and returned. All {@code n} possible
|
* is pseudorandomly generated and returned. All {@code bound} possible
|
||||||
* {@code int} values are produced with (approximately) equal
|
* {@code int} values are produced with (approximately) equal
|
||||||
* probability. The method {@code nextInt(int n)} is implemented by
|
* probability. The method {@code nextInt(int bound)} is implemented by
|
||||||
* class {@code Random} as if by:
|
* class {@code Random} as if by:
|
||||||
* <pre> {@code
|
* <pre> {@code
|
||||||
* public int nextInt(int n) {
|
* public int nextInt(int bound) {
|
||||||
* if (n <= 0)
|
* if (bound <= 0)
|
||||||
* throw new IllegalArgumentException("n must be positive");
|
* throw new IllegalArgumentException("bound must be positive");
|
||||||
*
|
*
|
||||||
* if ((n & -n) == n) // i.e., n is a power of 2
|
* if ((bound & -bound) == bound) // i.e., bound is a power of 2
|
||||||
* return (int)((n * (long)next(31)) >> 31);
|
* return (int)((bound * (long)next(31)) >> 31);
|
||||||
*
|
*
|
||||||
* int bits, val;
|
* int bits, val;
|
||||||
* do {
|
* do {
|
||||||
* bits = next(31);
|
* bits = next(31);
|
||||||
* val = bits % n;
|
* val = bits % bound;
|
||||||
* } while (bits - val + (n-1) < 0);
|
* } while (bits - val + (bound-1) < 0);
|
||||||
* return val;
|
* return val;
|
||||||
* }}</pre>
|
* }}</pre>
|
||||||
*
|
*
|
||||||
@ -289,28 +376,28 @@ class Random implements java.io.Serializable {
|
|||||||
* greatly increases the length of the sequence of values returned by
|
* greatly increases the length of the sequence of values returned by
|
||||||
* successive calls to this method if n is a small power of two.
|
* successive calls to this method if n is a small power of two.
|
||||||
*
|
*
|
||||||
* @param n the bound on the random number to be returned. Must be
|
* @param bound the upper bound (exclusive). Must be positive.
|
||||||
* positive.
|
|
||||||
* @return the next pseudorandom, uniformly distributed {@code int}
|
* @return the next pseudorandom, uniformly distributed {@code int}
|
||||||
* value between {@code 0} (inclusive) and {@code n} (exclusive)
|
* value between zero (inclusive) and {@code bound} (exclusive)
|
||||||
* from this random number generator's sequence
|
* from this random number generator's sequence
|
||||||
* @throws IllegalArgumentException if n is not positive
|
* @throws IllegalArgumentException if bound is not positive
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
|
public int nextInt(int bound) {
|
||||||
|
if (bound <= 0)
|
||||||
|
throw new IllegalArgumentException(BadBound);
|
||||||
|
|
||||||
public int nextInt(int n) {
|
int r = next(31);
|
||||||
if (n <= 0)
|
int m = bound - 1;
|
||||||
throw new IllegalArgumentException("n must be positive");
|
if ((bound & m) == 0) // i.e., bound is a power of 2
|
||||||
|
r = (int)((bound * (long)r) >> 31);
|
||||||
if ((n & -n) == n) // i.e., n is a power of 2
|
else {
|
||||||
return (int)((n * (long)next(31)) >> 31);
|
for (int u = r;
|
||||||
|
u - (r = u % bound) + m < 0;
|
||||||
int bits, val;
|
u = next(31))
|
||||||
do {
|
;
|
||||||
bits = next(31);
|
}
|
||||||
val = bits % n;
|
return r;
|
||||||
} while (bits - val + (n-1) < 0);
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -442,8 +529,7 @@ class Random implements java.io.Serializable {
|
|||||||
* @see Math#random
|
* @see Math#random
|
||||||
*/
|
*/
|
||||||
public double nextDouble() {
|
public double nextDouble() {
|
||||||
return (((long)(next(26)) << 27) + next(27))
|
return (((long)(next(26)) << 27) + next(27)) * DOUBLE_UNIT;
|
||||||
/ (double)(1L << 53);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double nextNextGaussian;
|
private double nextNextGaussian;
|
||||||
@ -513,57 +599,563 @@ class Random implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stream methods, coded in a way intended to better isolate for
|
||||||
|
// maintenance purposes the small differences across forms.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stream of pseudorandom, uniformly distributed
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
* {@code integer} values from this random number generator's
|
* pseudorandom {@code int} values.
|
||||||
* sequence. Values are obtained as needed by calling
|
|
||||||
* {@link #nextInt()}.
|
|
||||||
*
|
*
|
||||||
* @return an infinite stream of {@code integer} values
|
* <p>A pseudorandom {@code int} value is generated as if it's the result of
|
||||||
|
* calling the method {@link #nextInt()}.
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @return a stream of pseudorandom {@code int} values
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints(long streamSize) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(this, 0L, streamSize, Integer.MAX_VALUE, 0),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code int}
|
||||||
|
* values.
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code int} value is generated as if it's the result of
|
||||||
|
* calling the method {@link #nextInt()}.
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* ints(Long.MAX_VALUE)}.
|
||||||
|
*
|
||||||
|
* @return a stream of pseudorandom {@code int} values
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public IntStream ints() {
|
public IntStream ints() {
|
||||||
return IntStream.generate(this::nextInt);
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(this, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stream of pseudorandom, uniformly distributed
|
* Returns a stream producing the given {@code streamSize} number
|
||||||
* {@code long} values from this random number generator's
|
* of pseudorandom {@code int} values, each conforming to the given
|
||||||
* sequence. Values are obtained as needed by calling
|
* origin (inclusive) and bound (exclusive).
|
||||||
* {@link #nextLong()}.
|
|
||||||
*
|
*
|
||||||
* @return an infinite stream of {@code long} values
|
* <p>A pseudorandom {@code int} value is generated as if it's the result of
|
||||||
|
* calling the following method with the origin and bound:
|
||||||
|
* <pre> {@code
|
||||||
|
* int nextInt(int origin, int bound) {
|
||||||
|
* int n = bound - origin;
|
||||||
|
* if (n > 0) {
|
||||||
|
* return nextInt(n) + origin;
|
||||||
|
* }
|
||||||
|
* else { // range not representable as int
|
||||||
|
* int r;
|
||||||
|
* do {
|
||||||
|
* r = nextInt();
|
||||||
|
* } while (r < origin || r >= bound);
|
||||||
|
* return r;
|
||||||
|
* }
|
||||||
|
* }}</pre>
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code int} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero, or {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints(long streamSize, int randomNumberOrigin,
|
||||||
|
int randomNumberBound) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* int} values, each conforming to the given origin (inclusive) and bound
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code int} value is generated as if it's the result of
|
||||||
|
* calling the following method with the origin and bound:
|
||||||
|
* <pre> {@code
|
||||||
|
* int nextInt(int origin, int bound) {
|
||||||
|
* int n = bound - origin;
|
||||||
|
* if (n > 0) {
|
||||||
|
* return nextInt(n) + origin;
|
||||||
|
* }
|
||||||
|
* else { // range not representable as int
|
||||||
|
* int r;
|
||||||
|
* do {
|
||||||
|
* r = nextInt();
|
||||||
|
* } while (r < origin || r >= bound);
|
||||||
|
* return r;
|
||||||
|
* }
|
||||||
|
* }}</pre>
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
|
||||||
|
*
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code int} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code long} values.
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code long} value is generated as if it's the result
|
||||||
|
* of calling the method {@link #nextLong()}.
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @return a stream of pseudorandom {@code long} values
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs(long streamSize) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(this, 0L, streamSize, Long.MAX_VALUE, 0L),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code long}
|
||||||
|
* values.
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code long} value is generated as if it's the result
|
||||||
|
* of calling the method {@link #nextLong()}.
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* longs(Long.MAX_VALUE)}.
|
||||||
|
*
|
||||||
|
* @return a stream of pseudorandom {@code long} values
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public LongStream longs() {
|
public LongStream longs() {
|
||||||
return LongStream.generate(this::nextLong);
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(this, 0L, Long.MAX_VALUE, Long.MAX_VALUE, 0L),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stream of pseudorandom, uniformly distributed
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
* {@code double} values between {@code 0.0} and {@code 1.0}
|
* pseudorandom {@code long}, each conforming to the given origin
|
||||||
* from this random number generator's sequence. Values are
|
* (inclusive) and bound (exclusive).
|
||||||
* obtained as needed by calling {@link #nextDouble()}.
|
|
||||||
*
|
*
|
||||||
* @return an infinite stream of {@code double} values
|
* <p>A pseudorandom {@code long} value is generated as if it's the result
|
||||||
|
* of calling the following method with the origin and bound:
|
||||||
|
* <pre> {@code
|
||||||
|
* long nextLong(long origin, long bound) {
|
||||||
|
* long r = nextLong();
|
||||||
|
* long n = bound - origin, m = n - 1;
|
||||||
|
* if ((n & m) == 0L) // power of two
|
||||||
|
* r = (r & m) + origin;
|
||||||
|
* else if (n > 0L) { // reject over-represented candidates
|
||||||
|
* for (long u = r >>> 1; // ensure nonnegative
|
||||||
|
* u + m - (r = u % n) < 0L; // rejection check
|
||||||
|
* u = nextLong() >>> 1) // retry
|
||||||
|
* ;
|
||||||
|
* r += origin;
|
||||||
|
* }
|
||||||
|
* else { // range not representable as long
|
||||||
|
* while (r < origin || r >= bound)
|
||||||
|
* r = nextLong();
|
||||||
|
* }
|
||||||
|
* return r;
|
||||||
|
* }}</pre>
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code long} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero, or {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs(long streamSize, long randomNumberOrigin,
|
||||||
|
long randomNumberBound) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* long} values, each conforming to the given origin (inclusive) and bound
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code long} value is generated as if it's the result
|
||||||
|
* of calling the following method with the origin and bound:
|
||||||
|
* <pre> {@code
|
||||||
|
* long nextLong(long origin, long bound) {
|
||||||
|
* long r = nextLong();
|
||||||
|
* long n = bound - origin, m = n - 1;
|
||||||
|
* if ((n & m) == 0L) // power of two
|
||||||
|
* r = (r & m) + origin;
|
||||||
|
* else if (n > 0L) { // reject over-represented candidates
|
||||||
|
* for (long u = r >>> 1; // ensure nonnegative
|
||||||
|
* u + m - (r = u % n) < 0L; // rejection check
|
||||||
|
* u = nextLong() >>> 1) // retry
|
||||||
|
* ;
|
||||||
|
* r += origin;
|
||||||
|
* }
|
||||||
|
* else { // range not representable as long
|
||||||
|
* while (r < origin || r >= bound)
|
||||||
|
* r = nextLong();
|
||||||
|
* }
|
||||||
|
* return r;
|
||||||
|
* }}</pre>
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
|
||||||
|
*
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code long} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code double} values, each between zero
|
||||||
|
* (inclusive) and one (exclusive).
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code double} value is generated as if it's the result
|
||||||
|
* of calling the method {@link #nextDouble()}}.
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @return a stream of {@code double} values
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public DoubleStream doubles(long streamSize) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(this, 0L, streamSize, Double.MAX_VALUE, 0.0),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* double} values, each between zero (inclusive) and one
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code double} value is generated as if it's the result
|
||||||
|
* of calling the method {@link #nextDouble()}}.
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* doubles(Long.MAX_VALUE)}.
|
||||||
|
*
|
||||||
|
* @return a stream of pseudorandom {@code double} values
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public DoubleStream doubles() {
|
public DoubleStream doubles() {
|
||||||
return DoubleStream.generate(this::nextDouble);
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(this, 0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stream of pseudorandom, Gaussian ("normally")
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
* distributed {@code double} values with mean {@code 0.0}
|
* pseudorandom {@code double} values, each conforming to the given origin
|
||||||
* and standard deviation {@code 1.0} from this random number
|
* (inclusive) and bound (exclusive).
|
||||||
* generator's sequence. Values are obtained as needed by
|
|
||||||
* calling {@link #nextGaussian()}.
|
|
||||||
*
|
*
|
||||||
* @return an infinite stream of {@code double} values
|
* <p>A pseudorandom {@code double} value is generated as if it's the result
|
||||||
|
* of calling the following method with the origin and bound:
|
||||||
|
* <pre> {@code
|
||||||
|
* double nextDouble(double origin, double bound) {
|
||||||
|
* double r = nextDouble();
|
||||||
|
* r = r * (bound - origin) + origin;
|
||||||
|
* if (r >= bound) // correct for rounding
|
||||||
|
* r = Math.nextDown(bound);
|
||||||
|
* return r;
|
||||||
|
* }}</pre>
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code double} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public DoubleStream gaussians() {
|
public DoubleStream doubles(long streamSize, double randomNumberOrigin,
|
||||||
return DoubleStream.generate(this::nextGaussian);
|
double randomNumberBound) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
if (!(randomNumberOrigin < randomNumberBound))
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* double} values, each conforming to the given origin (inclusive) and bound
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* <p>A pseudorandom {@code double} value is generated as if it's the result
|
||||||
|
* of calling the following method with the origin and bound:
|
||||||
|
* <pre> {@code
|
||||||
|
* double nextDouble(double origin, double bound) {
|
||||||
|
* double r = nextDouble();
|
||||||
|
* r = r * (bound - origin) + origin;
|
||||||
|
* if (r >= bound) // correct for rounding
|
||||||
|
* r = Math.nextDown(bound);
|
||||||
|
* return r;
|
||||||
|
* }}</pre>
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
|
||||||
|
*
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code double} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
|
||||||
|
if (!(randomNumberOrigin < randomNumberBound))
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spliterator for int streams. We multiplex the four int
|
||||||
|
* versions into one class by treating a bound less than origin as
|
||||||
|
* unbounded, and also by treating "infinite" as equivalent to
|
||||||
|
* Long.MAX_VALUE. For splits, it uses the standard divide-by-two
|
||||||
|
* approach. The long and double versions of this class are
|
||||||
|
* identical except for types.
|
||||||
|
*/
|
||||||
|
static final class RandomIntsSpliterator implements Spliterator.OfInt {
|
||||||
|
final Random rng;
|
||||||
|
long index;
|
||||||
|
final long fence;
|
||||||
|
final int origin;
|
||||||
|
final int bound;
|
||||||
|
RandomIntsSpliterator(Random rng, long index, long fence,
|
||||||
|
int origin, int bound) {
|
||||||
|
this.rng = rng; this.index = index; this.fence = fence;
|
||||||
|
this.origin = origin; this.bound = bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RandomIntsSpliterator trySplit() {
|
||||||
|
long i = index, m = (i + fence) >>> 1;
|
||||||
|
return (m <= i) ? null :
|
||||||
|
new RandomIntsSpliterator(rng, i, index = m, origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long estimateSize() {
|
||||||
|
return fence - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int characteristics() {
|
||||||
|
return (Spliterator.SIZED | Spliterator.SUBSIZED |
|
||||||
|
Spliterator.NONNULL | Spliterator.IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAdvance(IntConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
consumer.accept(rng.internalNextInt(origin, bound));
|
||||||
|
index = i + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachRemaining(IntConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
index = f;
|
||||||
|
Random r = rng;
|
||||||
|
int o = origin, b = bound;
|
||||||
|
do {
|
||||||
|
consumer.accept(r.internalNextInt(o, b));
|
||||||
|
} while (++i < f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spliterator for long streams.
|
||||||
|
*/
|
||||||
|
static final class RandomLongsSpliterator implements Spliterator.OfLong {
|
||||||
|
final Random rng;
|
||||||
|
long index;
|
||||||
|
final long fence;
|
||||||
|
final long origin;
|
||||||
|
final long bound;
|
||||||
|
RandomLongsSpliterator(Random rng, long index, long fence,
|
||||||
|
long origin, long bound) {
|
||||||
|
this.rng = rng; this.index = index; this.fence = fence;
|
||||||
|
this.origin = origin; this.bound = bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RandomLongsSpliterator trySplit() {
|
||||||
|
long i = index, m = (i + fence) >>> 1;
|
||||||
|
return (m <= i) ? null :
|
||||||
|
new RandomLongsSpliterator(rng, i, index = m, origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long estimateSize() {
|
||||||
|
return fence - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int characteristics() {
|
||||||
|
return (Spliterator.SIZED | Spliterator.SUBSIZED |
|
||||||
|
Spliterator.NONNULL | Spliterator.IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAdvance(LongConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
consumer.accept(rng.internalNextLong(origin, bound));
|
||||||
|
index = i + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachRemaining(LongConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
index = f;
|
||||||
|
Random r = rng;
|
||||||
|
long o = origin, b = bound;
|
||||||
|
do {
|
||||||
|
consumer.accept(r.internalNextLong(o, b));
|
||||||
|
} while (++i < f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spliterator for double streams.
|
||||||
|
*/
|
||||||
|
static final class RandomDoublesSpliterator implements Spliterator.OfDouble {
|
||||||
|
final Random rng;
|
||||||
|
long index;
|
||||||
|
final long fence;
|
||||||
|
final double origin;
|
||||||
|
final double bound;
|
||||||
|
RandomDoublesSpliterator(Random rng, long index, long fence,
|
||||||
|
double origin, double bound) {
|
||||||
|
this.rng = rng; this.index = index; this.fence = fence;
|
||||||
|
this.origin = origin; this.bound = bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RandomDoublesSpliterator trySplit() {
|
||||||
|
long i = index, m = (i + fence) >>> 1;
|
||||||
|
return (m <= i) ? null :
|
||||||
|
new RandomDoublesSpliterator(rng, i, index = m, origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long estimateSize() {
|
||||||
|
return fence - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int characteristics() {
|
||||||
|
return (Spliterator.SIZED | Spliterator.SUBSIZED |
|
||||||
|
Spliterator.NONNULL | Spliterator.IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAdvance(DoubleConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
consumer.accept(rng.internalNextDouble(origin, bound));
|
||||||
|
index = i + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachRemaining(DoubleConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
index = f;
|
||||||
|
Random r = rng;
|
||||||
|
double o = origin, b = bound;
|
||||||
|
do {
|
||||||
|
consumer.accept(r.internalNextDouble(o, b));
|
||||||
|
} while (++i < f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
1002
jdk/src/share/classes/java/util/SplittableRandom.java
Normal file
1002
jdk/src/share/classes/java/util/SplittableRandom.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright 2009 Google Inc. All Rights Reserved.
|
* Copyright 2009 Google Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -176,7 +177,7 @@ class TimSort<T> {
|
|||||||
*/
|
*/
|
||||||
int stackLen = (len < 120 ? 5 :
|
int stackLen = (len < 120 ? 5 :
|
||||||
len < 1542 ? 10 :
|
len < 1542 ? 10 :
|
||||||
len < 119151 ? 19 : 40);
|
len < 119151 ? 24 : 40);
|
||||||
runBase = new int[stackLen];
|
runBase = new int[stackLen];
|
||||||
runLen = new int[stackLen];
|
runLen = new int[stackLen];
|
||||||
}
|
}
|
||||||
|
@ -972,6 +972,27 @@ public class TreeMap<K,V>
|
|||||||
return tailMap(fromKey, true);
|
return tailMap(fromKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean replace(K key, V oldValue, V newValue) {
|
||||||
|
Entry<K,V> p = getEntry(key);
|
||||||
|
if (p!=null && Objects.equals(oldValue, p.value)) {
|
||||||
|
p.value = newValue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V replace(K key, V value) {
|
||||||
|
Entry<K,V> p = getEntry(key);
|
||||||
|
if (p!=null) {
|
||||||
|
V oldValue = p.value;
|
||||||
|
p.value = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(BiConsumer<? super K, ? super V> action) {
|
public void forEach(BiConsumer<? super K, ? super V> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
|
@ -37,11 +37,16 @@ package java.util.concurrent;
|
|||||||
|
|
||||||
import java.io.ObjectStreamField;
|
import java.io.ObjectStreamField;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Spliterator;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.function.DoubleConsumer;
|
||||||
|
import java.util.function.IntConsumer;
|
||||||
|
import java.util.function.LongConsumer;
|
||||||
import java.util.stream.DoubleStream;
|
import java.util.stream.DoubleStream;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import java.util.stream.LongStream;
|
import java.util.stream.LongStream;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A random number generator isolated to the current thread. Like the
|
* A random number generator isolated to the current thread. Like the
|
||||||
@ -64,6 +69,10 @@ import java.util.stream.LongStream;
|
|||||||
* <p>This class also provides additional commonly used bounded random
|
* <p>This class also provides additional commonly used bounded random
|
||||||
* generation methods.
|
* generation methods.
|
||||||
*
|
*
|
||||||
|
* <p>Instances of {@code ThreadLocalRandom} are not cryptographically
|
||||||
|
* secure. Consider instead using {@link java.security.SecureRandom}
|
||||||
|
* in security-sensitive applications.
|
||||||
|
*
|
||||||
* @since 1.7
|
* @since 1.7
|
||||||
* @author Doug Lea
|
* @author Doug Lea
|
||||||
*/
|
*/
|
||||||
@ -85,28 +94,26 @@ public class ThreadLocalRandom extends Random {
|
|||||||
* application-level overhead and footprint of most concurrent
|
* application-level overhead and footprint of most concurrent
|
||||||
* programs.
|
* programs.
|
||||||
*
|
*
|
||||||
|
* Even though this class subclasses java.util.Random, it uses the
|
||||||
|
* same basic algorithm as java.util.SplittableRandom. (See its
|
||||||
|
* internal documentation for explanations, which are not repeated
|
||||||
|
* here.) Because ThreadLocalRandoms are not splittable
|
||||||
|
* though, we use only a single 64bit gamma.
|
||||||
|
*
|
||||||
* Because this class is in a different package than class Thread,
|
* Because this class is in a different package than class Thread,
|
||||||
* field access methods use Unsafe to bypass access control rules.
|
* field access methods use Unsafe to bypass access control rules.
|
||||||
* The base functionality of Random methods is conveniently
|
* To conform to the requirements of the Random superclass
|
||||||
* isolated in method next(bits), that just reads and writes the
|
* constructor, the common static ThreadLocalRandom maintains an
|
||||||
* Thread field rather than its own field. However, to conform to
|
* "initialized" field for the sake of rejecting user calls to
|
||||||
* the requirements of the Random superclass constructor, the
|
* setSeed while still allowing a call from constructor. Note
|
||||||
* common static ThreadLocalRandom maintains an "initialized"
|
* that serialization is completely unnecessary because there is
|
||||||
* field for the sake of rejecting user calls to setSeed while
|
* only a static singleton. But we generate a serial form
|
||||||
* still allowing a call from constructor. Note that
|
* containing "rnd" and "initialized" fields to ensure
|
||||||
* serialization is completely unnecessary because there is only a
|
* compatibility across versions.
|
||||||
* static singleton. But we generate a serial form containing
|
|
||||||
* "rnd" and "initialized" fields to ensure compatibility across
|
|
||||||
* versions.
|
|
||||||
*
|
*
|
||||||
* Per-thread initialization is similar to that in the no-arg
|
* Implementations of non-core methods are mostly the same as in
|
||||||
* Random constructor, but we avoid correlation among not only
|
* SplittableRandom, that were in part derived from a previous
|
||||||
* initial seeds of those created in different threads, but also
|
* version of this class.
|
||||||
* those created using class Random itself; while at the same time
|
|
||||||
* not changing any statistical properties. So we use the same
|
|
||||||
* underlying multiplicative sequence, but start the sequence far
|
|
||||||
* away from the base version, and then merge (xor) current time
|
|
||||||
* and per-thread probe bits to generate initial values.
|
|
||||||
*
|
*
|
||||||
* The nextLocalGaussian ThreadLocal supports the very rarely used
|
* The nextLocalGaussian ThreadLocal supports the very rarely used
|
||||||
* nextGaussian method by providing a holder for the second of a
|
* nextGaussian method by providing a holder for the second of a
|
||||||
@ -115,24 +122,51 @@ public class ThreadLocalRandom extends Random {
|
|||||||
* but we provide identical statistical properties.
|
* but we provide identical statistical properties.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// same constants as Random, but must be redeclared because private
|
|
||||||
private static final long multiplier = 0x5DEECE66DL;
|
|
||||||
private static final long addend = 0xBL;
|
|
||||||
private static final long mask = (1L << 48) - 1;
|
|
||||||
private static final int PROBE_INCREMENT = 0x61c88647;
|
|
||||||
|
|
||||||
/** Generates the basis for per-thread initial seed values */
|
|
||||||
private static final AtomicLong seedGenerator =
|
|
||||||
new AtomicLong(1269533684904616924L);
|
|
||||||
|
|
||||||
/** Generates per-thread initialization/probe field */
|
/** Generates per-thread initialization/probe field */
|
||||||
private static final AtomicInteger probeGenerator =
|
private static final AtomicInteger probeGenerator =
|
||||||
new AtomicInteger(0xe80f8647);
|
new AtomicInteger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The next seed for default constructors.
|
||||||
|
*/
|
||||||
|
private static final AtomicLong seeder =
|
||||||
|
new AtomicLong(mix64(System.currentTimeMillis()) ^
|
||||||
|
mix64(System.nanoTime()));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The seed increment
|
||||||
|
*/
|
||||||
|
private static final long GAMMA = 0x9e3779b97f4a7c15L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The increment for generating probe values
|
||||||
|
*/
|
||||||
|
private static final int PROBE_INCREMENT = 0x9e3779b9;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The increment of seeder per new instance
|
||||||
|
*/
|
||||||
|
private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
|
||||||
|
|
||||||
|
// Constants from SplittableRandom
|
||||||
|
private static final double DOUBLE_UNIT = 1.0 / (1L << 53);
|
||||||
|
private static final float FLOAT_UNIT = 1.0f / (1 << 24);
|
||||||
|
|
||||||
/** Rarely-used holder for the second of a pair of Gaussians */
|
/** Rarely-used holder for the second of a pair of Gaussians */
|
||||||
private static final ThreadLocal<Double> nextLocalGaussian =
|
private static final ThreadLocal<Double> nextLocalGaussian =
|
||||||
new ThreadLocal<Double>();
|
new ThreadLocal<Double>();
|
||||||
|
|
||||||
|
private static long mix64(long z) {
|
||||||
|
z = (z ^ (z >>> 33)) * 0xff51afd7ed558ccdL;
|
||||||
|
z = (z ^ (z >>> 33)) * 0xc4ceb9fe1a85ec53L;
|
||||||
|
return z ^ (z >>> 33);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int mix32(long z) {
|
||||||
|
z = (z ^ (z >>> 33)) * 0xff51afd7ed558ccdL;
|
||||||
|
return (int)(((z ^ (z >>> 33)) * 0xc4ceb9fe1a85ec53L) >>> 32);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Field used only during singleton initialization.
|
* Field used only during singleton initialization.
|
||||||
* True when constructor completes.
|
* True when constructor completes.
|
||||||
@ -155,16 +189,11 @@ public class ThreadLocalRandom extends Random {
|
|||||||
* rely on (static) atomic generators to initialize the values.
|
* rely on (static) atomic generators to initialize the values.
|
||||||
*/
|
*/
|
||||||
static final void localInit() {
|
static final void localInit() {
|
||||||
int p = probeGenerator.getAndAdd(PROBE_INCREMENT);
|
int p = probeGenerator.addAndGet(PROBE_INCREMENT);
|
||||||
int probe = (p == 0) ? 1 : p; // skip 0
|
int probe = (p == 0) ? 1 : p; // skip 0
|
||||||
long current, next;
|
long seed = mix64(seeder.getAndAdd(SEEDER_INCREMENT));
|
||||||
do { // same sequence as j.u.Random but different initial value
|
|
||||||
current = seedGenerator.get();
|
|
||||||
next = current * 181783497276652981L;
|
|
||||||
} while (!seedGenerator.compareAndSet(current, next));
|
|
||||||
long r = next ^ ((long)probe << 32) ^ System.nanoTime();
|
|
||||||
Thread t = Thread.currentThread();
|
Thread t = Thread.currentThread();
|
||||||
UNSAFE.putLong(t, SEED, r);
|
UNSAFE.putLong(t, SEED, seed);
|
||||||
UNSAFE.putInt(t, PROBE, probe);
|
UNSAFE.putInt(t, PROBE, probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,124 +220,264 @@ public class ThreadLocalRandom extends Random {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int next(int bits) {
|
final long nextSeed() {
|
||||||
Thread t; long r; // read and update per-thread seed
|
Thread t; long r; // read and update per-thread seed
|
||||||
UNSAFE.putLong
|
UNSAFE.putLong(t = Thread.currentThread(), SEED,
|
||||||
(t = Thread.currentThread(), SEED,
|
r = UNSAFE.getLong(t, SEED) + GAMMA);
|
||||||
r = (UNSAFE.getLong(t, SEED) * multiplier + addend) & mask);
|
return r;
|
||||||
return (int) (r >>> (48-bits));
|
}
|
||||||
|
|
||||||
|
// We must define this, but never use it.
|
||||||
|
protected int next(int bits) {
|
||||||
|
return (int)(mix64(nextSeed()) >>> (64 - bits));
|
||||||
|
}
|
||||||
|
|
||||||
|
// IllegalArgumentException messages
|
||||||
|
static final String BadBound = "bound must be positive";
|
||||||
|
static final String BadRange = "bound must be greater than origin";
|
||||||
|
static final String BadSize = "size must be non-negative";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form of nextLong used by LongStream Spliterators. If
|
||||||
|
* origin is greater than bound, acts as unbounded form of
|
||||||
|
* nextLong, else as bounded form.
|
||||||
|
*
|
||||||
|
* @param origin the least value, unless greater than bound
|
||||||
|
* @param bound the upper bound (exclusive), must not equal origin
|
||||||
|
* @return a pseudorandom value
|
||||||
|
*/
|
||||||
|
final long internalNextLong(long origin, long bound) {
|
||||||
|
long r = mix64(nextSeed());
|
||||||
|
if (origin < bound) {
|
||||||
|
long n = bound - origin, m = n - 1;
|
||||||
|
if ((n & m) == 0L) // power of two
|
||||||
|
r = (r & m) + origin;
|
||||||
|
else if (n > 0L) { // reject over-represented candidates
|
||||||
|
for (long u = r >>> 1; // ensure nonnegative
|
||||||
|
u + m - (r = u % n) < 0L; // rejection check
|
||||||
|
u = mix64(nextSeed()) >>> 1) // retry
|
||||||
|
;
|
||||||
|
r += origin;
|
||||||
|
}
|
||||||
|
else { // range not representable as long
|
||||||
|
while (r < origin || r >= bound)
|
||||||
|
r = mix64(nextSeed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pseudorandom, uniformly distributed value between the
|
* The form of nextInt used by IntStream Spliterators.
|
||||||
* given least value (inclusive) and bound (exclusive).
|
* Exactly the same as long version, except for types.
|
||||||
*
|
*
|
||||||
* @param least the least value returned
|
* @param origin the least value, unless greater than bound
|
||||||
|
* @param bound the upper bound (exclusive), must not equal origin
|
||||||
|
* @return a pseudorandom value
|
||||||
|
*/
|
||||||
|
final int internalNextInt(int origin, int bound) {
|
||||||
|
int r = mix32(nextSeed());
|
||||||
|
if (origin < bound) {
|
||||||
|
int n = bound - origin, m = n - 1;
|
||||||
|
if ((n & m) == 0)
|
||||||
|
r = (r & m) + origin;
|
||||||
|
else if (n > 0) {
|
||||||
|
for (int u = r >>> 1;
|
||||||
|
u + m - (r = u % n) < 0;
|
||||||
|
u = mix32(nextSeed()) >>> 1)
|
||||||
|
;
|
||||||
|
r += origin;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while (r < origin || r >= bound)
|
||||||
|
r = mix32(nextSeed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form of nextDouble used by DoubleStream Spliterators.
|
||||||
|
*
|
||||||
|
* @param origin the least value, unless greater than bound
|
||||||
|
* @param bound the upper bound (exclusive), must not equal origin
|
||||||
|
* @return a pseudorandom value
|
||||||
|
*/
|
||||||
|
final double internalNextDouble(double origin, double bound) {
|
||||||
|
double r = (nextLong() >>> 11) * DOUBLE_UNIT;
|
||||||
|
if (origin < bound) {
|
||||||
|
r = r * (bound - origin) + origin;
|
||||||
|
if (r >= bound) // correct for rounding
|
||||||
|
r = Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code int} value.
|
||||||
|
*
|
||||||
|
* @return a pseudorandom {@code int} value
|
||||||
|
*/
|
||||||
|
public int nextInt() {
|
||||||
|
return mix32(nextSeed());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code int} value between zero (inclusive)
|
||||||
|
* and the specified bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param bound the upper bound (exclusive). Must be positive.
|
||||||
|
* @return a pseudorandom {@code int} value between zero
|
||||||
|
* (inclusive) and the bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code bound} is not positive
|
||||||
|
*/
|
||||||
|
public int nextInt(int bound) {
|
||||||
|
if (bound <= 0)
|
||||||
|
throw new IllegalArgumentException(BadBound);
|
||||||
|
int r = mix32(nextSeed());
|
||||||
|
int m = bound - 1;
|
||||||
|
if ((bound & m) == 0) // power of two
|
||||||
|
r &= m;
|
||||||
|
else { // reject over-represented candidates
|
||||||
|
for (int u = r >>> 1;
|
||||||
|
u + m - (r = u % bound) < 0;
|
||||||
|
u = mix32(nextSeed()) >>> 1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code int} value between the specified
|
||||||
|
* origin (inclusive) and the specified bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param origin the least value returned
|
||||||
* @param bound the upper bound (exclusive)
|
* @param bound the upper bound (exclusive)
|
||||||
* @throws IllegalArgumentException if least greater than or equal
|
* @return a pseudorandom {@code int} value between the origin
|
||||||
* to bound
|
* (inclusive) and the bound (exclusive)
|
||||||
* @return the next value
|
* @throws IllegalArgumentException if {@code origin} is greater than
|
||||||
|
* or equal to {@code bound}
|
||||||
*/
|
*/
|
||||||
public int nextInt(int least, int bound) {
|
public int nextInt(int origin, int bound) {
|
||||||
if (least >= bound)
|
if (origin >= bound)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(BadRange);
|
||||||
return nextInt(bound - least) + least;
|
return internalNextInt(origin, bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pseudorandom, uniformly distributed value
|
* Returns a pseudorandom {@code long} value.
|
||||||
* between 0 (inclusive) and the specified value (exclusive).
|
|
||||||
*
|
*
|
||||||
* @param n the bound on the random number to be returned. Must be
|
* @return a pseudorandom {@code long} value
|
||||||
* positive.
|
|
||||||
* @return the next value
|
|
||||||
* @throws IllegalArgumentException if n is not positive
|
|
||||||
*/
|
*/
|
||||||
public long nextLong(long n) {
|
public long nextLong() {
|
||||||
if (n <= 0)
|
return mix64(nextSeed());
|
||||||
throw new IllegalArgumentException("n must be positive");
|
|
||||||
// Divide n by two until small enough for nextInt. On each
|
|
||||||
// iteration (at most 31 of them but usually much less),
|
|
||||||
// randomly choose both whether to include high bit in result
|
|
||||||
// (offset) and whether to continue with the lower vs upper
|
|
||||||
// half (which makes a difference only if odd).
|
|
||||||
long offset = 0;
|
|
||||||
while (n >= Integer.MAX_VALUE) {
|
|
||||||
int bits = next(2);
|
|
||||||
long half = n >>> 1;
|
|
||||||
long nextn = ((bits & 2) == 0) ? half : n - half;
|
|
||||||
if ((bits & 1) == 0)
|
|
||||||
offset += n - nextn;
|
|
||||||
n = nextn;
|
|
||||||
}
|
|
||||||
return offset + nextInt((int) n);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IntStream ints() {
|
|
||||||
return IntStream.generate(() -> current().nextInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LongStream longs() {
|
|
||||||
return LongStream.generate(() -> current().nextLong());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoubleStream doubles() {
|
|
||||||
return DoubleStream.generate(() -> current().nextDouble());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoubleStream gaussians() {
|
|
||||||
return DoubleStream.generate(() -> current().nextGaussian());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pseudorandom, uniformly distributed value between the
|
* Returns a pseudorandom {@code long} value between zero (inclusive)
|
||||||
* given least value (inclusive) and bound (exclusive).
|
* and the specified bound (exclusive).
|
||||||
*
|
*
|
||||||
* @param least the least value returned
|
* @param bound the upper bound (exclusive). Must be positive.
|
||||||
|
* @return a pseudorandom {@code long} value between zero
|
||||||
|
* (inclusive) and the bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code bound} is not positive
|
||||||
|
*/
|
||||||
|
public long nextLong(long bound) {
|
||||||
|
if (bound <= 0)
|
||||||
|
throw new IllegalArgumentException(BadBound);
|
||||||
|
long r = mix64(nextSeed());
|
||||||
|
long m = bound - 1;
|
||||||
|
if ((bound & m) == 0L) // power of two
|
||||||
|
r &= m;
|
||||||
|
else { // reject over-represented candidates
|
||||||
|
for (long u = r >>> 1;
|
||||||
|
u + m - (r = u % bound) < 0L;
|
||||||
|
u = mix64(nextSeed()) >>> 1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code long} value between the specified
|
||||||
|
* origin (inclusive) and the specified bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param origin the least value returned
|
||||||
* @param bound the upper bound (exclusive)
|
* @param bound the upper bound (exclusive)
|
||||||
* @return the next value
|
* @return a pseudorandom {@code long} value between the origin
|
||||||
* @throws IllegalArgumentException if least greater than or equal
|
* (inclusive) and the bound (exclusive)
|
||||||
* to bound
|
* @throws IllegalArgumentException if {@code origin} is greater than
|
||||||
|
* or equal to {@code bound}
|
||||||
*/
|
*/
|
||||||
public long nextLong(long least, long bound) {
|
public long nextLong(long origin, long bound) {
|
||||||
if (least >= bound)
|
if (origin >= bound)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(BadRange);
|
||||||
return nextLong(bound - least) + least;
|
return internalNextLong(origin, bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pseudorandom, uniformly distributed {@code double} value
|
* Returns a pseudorandom {@code double} value between zero
|
||||||
* between 0 (inclusive) and the specified value (exclusive).
|
* (inclusive) and one (exclusive).
|
||||||
*
|
*
|
||||||
* @param n the bound on the random number to be returned. Must be
|
* @return a pseudorandom {@code double} value between zero
|
||||||
* positive.
|
* (inclusive) and one (exclusive)
|
||||||
* @return the next value
|
|
||||||
* @throws IllegalArgumentException if n is not positive
|
|
||||||
*/
|
*/
|
||||||
public double nextDouble(double n) {
|
public double nextDouble() {
|
||||||
if (n <= 0)
|
return (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT;
|
||||||
throw new IllegalArgumentException("n must be positive");
|
|
||||||
return nextDouble() * n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pseudorandom, uniformly distributed value between the
|
* Returns a pseudorandom {@code double} value between 0.0
|
||||||
* given least value (inclusive) and bound (exclusive).
|
* (inclusive) and the specified bound (exclusive).
|
||||||
*
|
*
|
||||||
* @param least the least value returned
|
* @param bound the upper bound (exclusive). Must be positive.
|
||||||
|
* @return a pseudorandom {@code double} value between zero
|
||||||
|
* (inclusive) and the bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code bound} is not positive
|
||||||
|
*/
|
||||||
|
public double nextDouble(double bound) {
|
||||||
|
if (!(bound > 0.0))
|
||||||
|
throw new IllegalArgumentException(BadBound);
|
||||||
|
double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound;
|
||||||
|
return (result < bound) ? result : // correct for rounding
|
||||||
|
Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code double} value between the specified
|
||||||
|
* origin (inclusive) and bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param origin the least value returned
|
||||||
* @param bound the upper bound (exclusive)
|
* @param bound the upper bound (exclusive)
|
||||||
* @return the next value
|
* @return a pseudorandom {@code double} value between the origin
|
||||||
* @throws IllegalArgumentException if least greater than or equal
|
* (inclusive) and the bound (exclusive)
|
||||||
* to bound
|
* @throws IllegalArgumentException if {@code origin} is greater than
|
||||||
|
* or equal to {@code bound}
|
||||||
*/
|
*/
|
||||||
public double nextDouble(double least, double bound) {
|
public double nextDouble(double origin, double bound) {
|
||||||
if (least >= bound)
|
if (!(origin < bound))
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(BadRange);
|
||||||
return nextDouble() * (bound - least) + least;
|
return internalNextDouble(origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code boolean} value.
|
||||||
|
*
|
||||||
|
* @return a pseudorandom {@code boolean} value
|
||||||
|
*/
|
||||||
|
public boolean nextBoolean() {
|
||||||
|
return mix32(nextSeed()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pseudorandom {@code float} value between zero
|
||||||
|
* (inclusive) and one (exclusive).
|
||||||
|
*
|
||||||
|
* @return a pseudorandom {@code float} value between zero
|
||||||
|
* (inclusive) and one (exclusive)
|
||||||
|
*/
|
||||||
|
public float nextFloat() {
|
||||||
|
return (mix32(nextSeed()) >>> 8) * FLOAT_UNIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double nextGaussian() {
|
public double nextGaussian() {
|
||||||
@ -329,6 +498,445 @@ public class ThreadLocalRandom extends Random {
|
|||||||
return v1 * multiplier;
|
return v1 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stream methods, coded in a way intended to better isolate for
|
||||||
|
// maintenance purposes the small differences across forms.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code int} values.
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @return a stream of pseudorandom {@code int} values
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints(long streamSize) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(0L, streamSize, Integer.MAX_VALUE, 0),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code int}
|
||||||
|
* values.
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* ints(Long.MAX_VALUE)}.
|
||||||
|
*
|
||||||
|
* @return a stream of pseudorandom {@code int} values
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints() {
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number
|
||||||
|
* of pseudorandom {@code int} values, each conforming to the given
|
||||||
|
* origin (inclusive) and bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code int} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero, or {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints(long streamSize, int randomNumberOrigin,
|
||||||
|
int randomNumberBound) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(0L, streamSize, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* int} values, each conforming to the given origin (inclusive) and bound
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
|
||||||
|
*
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code int} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.intStream
|
||||||
|
(new RandomIntsSpliterator
|
||||||
|
(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code long} values.
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @return a stream of pseudorandom {@code long} values
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs(long streamSize) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(0L, streamSize, Long.MAX_VALUE, 0L),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code long}
|
||||||
|
* values.
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* longs(Long.MAX_VALUE)}.
|
||||||
|
*
|
||||||
|
* @return a stream of pseudorandom {@code long} values
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs() {
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(0L, Long.MAX_VALUE, Long.MAX_VALUE, 0L),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code long}, each conforming to the given origin
|
||||||
|
* (inclusive) and bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code long} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero, or {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs(long streamSize, long randomNumberOrigin,
|
||||||
|
long randomNumberBound) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(0L, streamSize, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* long} values, each conforming to the given origin (inclusive) and bound
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
|
||||||
|
*
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code long} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
|
||||||
|
if (randomNumberOrigin >= randomNumberBound)
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.longStream
|
||||||
|
(new RandomLongsSpliterator
|
||||||
|
(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code double} values, each between zero
|
||||||
|
* (inclusive) and one (exclusive).
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @return a stream of {@code double} values
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public DoubleStream doubles(long streamSize) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(0L, streamSize, Double.MAX_VALUE, 0.0),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* double} values, each between zero (inclusive) and one
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* doubles(Long.MAX_VALUE)}.
|
||||||
|
*
|
||||||
|
* @return a stream of pseudorandom {@code double} values
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public DoubleStream doubles() {
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream producing the given {@code streamSize} number of
|
||||||
|
* pseudorandom {@code double} values, each conforming to the given origin
|
||||||
|
* (inclusive) and bound (exclusive).
|
||||||
|
*
|
||||||
|
* @param streamSize the number of values to generate
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code double} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code streamSize} is
|
||||||
|
* less than zero
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public DoubleStream doubles(long streamSize, double randomNumberOrigin,
|
||||||
|
double randomNumberBound) {
|
||||||
|
if (streamSize < 0L)
|
||||||
|
throw new IllegalArgumentException(BadSize);
|
||||||
|
if (!(randomNumberOrigin < randomNumberBound))
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(0L, streamSize, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an effectively unlimited stream of pseudorandom {@code
|
||||||
|
* double} values, each conforming to the given origin (inclusive) and bound
|
||||||
|
* (exclusive).
|
||||||
|
*
|
||||||
|
* @implNote This method is implemented to be equivalent to {@code
|
||||||
|
* doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
|
||||||
|
*
|
||||||
|
* @param randomNumberOrigin the origin (inclusive) of each random value
|
||||||
|
* @param randomNumberBound the bound (exclusive) of each random value
|
||||||
|
* @return a stream of pseudorandom {@code double} values,
|
||||||
|
* each with the given origin (inclusive) and bound (exclusive)
|
||||||
|
* @throws IllegalArgumentException if {@code randomNumberOrigin}
|
||||||
|
* is greater than or equal to {@code randomNumberBound}
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
|
||||||
|
if (!(randomNumberOrigin < randomNumberBound))
|
||||||
|
throw new IllegalArgumentException(BadRange);
|
||||||
|
return StreamSupport.doubleStream
|
||||||
|
(new RandomDoublesSpliterator
|
||||||
|
(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spliterator for int streams. We multiplex the four int
|
||||||
|
* versions into one class by treating a bound less than origin as
|
||||||
|
* unbounded, and also by treating "infinite" as equivalent to
|
||||||
|
* Long.MAX_VALUE. For splits, it uses the standard divide-by-two
|
||||||
|
* approach. The long and double versions of this class are
|
||||||
|
* identical except for types.
|
||||||
|
*/
|
||||||
|
static final class RandomIntsSpliterator implements Spliterator.OfInt {
|
||||||
|
long index;
|
||||||
|
final long fence;
|
||||||
|
final int origin;
|
||||||
|
final int bound;
|
||||||
|
RandomIntsSpliterator(long index, long fence,
|
||||||
|
int origin, int bound) {
|
||||||
|
this.index = index; this.fence = fence;
|
||||||
|
this.origin = origin; this.bound = bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RandomIntsSpliterator trySplit() {
|
||||||
|
long i = index, m = (i + fence) >>> 1;
|
||||||
|
return (m <= i) ? null :
|
||||||
|
new RandomIntsSpliterator(i, index = m, origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long estimateSize() {
|
||||||
|
return fence - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int characteristics() {
|
||||||
|
return (Spliterator.SIZED | Spliterator.SUBSIZED |
|
||||||
|
Spliterator.NONNULL | Spliterator.IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAdvance(IntConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
consumer.accept(ThreadLocalRandom.current().internalNextInt(origin, bound));
|
||||||
|
index = i + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachRemaining(IntConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
index = f;
|
||||||
|
int o = origin, b = bound;
|
||||||
|
ThreadLocalRandom rng = ThreadLocalRandom.current();
|
||||||
|
do {
|
||||||
|
consumer.accept(rng.internalNextInt(o, b));
|
||||||
|
} while (++i < f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spliterator for long streams.
|
||||||
|
*/
|
||||||
|
static final class RandomLongsSpliterator implements Spliterator.OfLong {
|
||||||
|
long index;
|
||||||
|
final long fence;
|
||||||
|
final long origin;
|
||||||
|
final long bound;
|
||||||
|
RandomLongsSpliterator(long index, long fence,
|
||||||
|
long origin, long bound) {
|
||||||
|
this.index = index; this.fence = fence;
|
||||||
|
this.origin = origin; this.bound = bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RandomLongsSpliterator trySplit() {
|
||||||
|
long i = index, m = (i + fence) >>> 1;
|
||||||
|
return (m <= i) ? null :
|
||||||
|
new RandomLongsSpliterator(i, index = m, origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long estimateSize() {
|
||||||
|
return fence - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int characteristics() {
|
||||||
|
return (Spliterator.SIZED | Spliterator.SUBSIZED |
|
||||||
|
Spliterator.NONNULL | Spliterator.IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAdvance(LongConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
consumer.accept(ThreadLocalRandom.current().internalNextLong(origin, bound));
|
||||||
|
index = i + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachRemaining(LongConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
index = f;
|
||||||
|
long o = origin, b = bound;
|
||||||
|
ThreadLocalRandom rng = ThreadLocalRandom.current();
|
||||||
|
do {
|
||||||
|
consumer.accept(rng.internalNextLong(o, b));
|
||||||
|
} while (++i < f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spliterator for double streams.
|
||||||
|
*/
|
||||||
|
static final class RandomDoublesSpliterator implements Spliterator.OfDouble {
|
||||||
|
long index;
|
||||||
|
final long fence;
|
||||||
|
final double origin;
|
||||||
|
final double bound;
|
||||||
|
RandomDoublesSpliterator(long index, long fence,
|
||||||
|
double origin, double bound) {
|
||||||
|
this.index = index; this.fence = fence;
|
||||||
|
this.origin = origin; this.bound = bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RandomDoublesSpliterator trySplit() {
|
||||||
|
long i = index, m = (i + fence) >>> 1;
|
||||||
|
return (m <= i) ? null :
|
||||||
|
new RandomDoublesSpliterator(i, index = m, origin, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long estimateSize() {
|
||||||
|
return fence - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int characteristics() {
|
||||||
|
return (Spliterator.SIZED | Spliterator.SUBSIZED |
|
||||||
|
Spliterator.NONNULL | Spliterator.IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAdvance(DoubleConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
consumer.accept(ThreadLocalRandom.current().internalNextDouble(origin, bound));
|
||||||
|
index = i + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachRemaining(DoubleConsumer consumer) {
|
||||||
|
if (consumer == null) throw new NullPointerException();
|
||||||
|
long i = index, f = fence;
|
||||||
|
if (i < f) {
|
||||||
|
index = f;
|
||||||
|
double o = origin, b = bound;
|
||||||
|
ThreadLocalRandom rng = ThreadLocalRandom.current();
|
||||||
|
do {
|
||||||
|
consumer.accept(rng.internalNextDouble(o, b));
|
||||||
|
} while (++i < f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Within-package utilities
|
// Within-package utilities
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -401,23 +1009,26 @@ public class ThreadLocalRandom extends Random {
|
|||||||
*/
|
*/
|
||||||
private static final ObjectStreamField[] serialPersistentFields = {
|
private static final ObjectStreamField[] serialPersistentFields = {
|
||||||
new ObjectStreamField("rnd", long.class),
|
new ObjectStreamField("rnd", long.class),
|
||||||
new ObjectStreamField("initialized", boolean.class)
|
new ObjectStreamField("initialized", boolean.class),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it).
|
* Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it).
|
||||||
|
* @param s the stream
|
||||||
|
* @throws java.io.IOException if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
private void writeObject(java.io.ObjectOutputStream out)
|
private void writeObject(java.io.ObjectOutputStream s)
|
||||||
throws java.io.IOException {
|
throws java.io.IOException {
|
||||||
|
|
||||||
java.io.ObjectOutputStream.PutField fields = out.putFields();
|
java.io.ObjectOutputStream.PutField fields = s.putFields();
|
||||||
fields.put("rnd", UNSAFE.getLong(Thread.currentThread(), SEED));
|
fields.put("rnd", UNSAFE.getLong(Thread.currentThread(), SEED));
|
||||||
fields.put("initialized", true);
|
fields.put("initialized", true);
|
||||||
out.writeFields();
|
s.writeFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link #current() current} thread's {@code ThreadLocalRandom}.
|
* Returns the {@link #current() current} thread's {@code ThreadLocalRandom}.
|
||||||
|
* @return the {@link #current() current} thread's {@code ThreadLocalRandom}
|
||||||
*/
|
*/
|
||||||
private Object readResolve() {
|
private Object readResolve() {
|
||||||
return current();
|
return current();
|
||||||
|
@ -226,7 +226,11 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
* incoming reader arrives while read lock is held but there is a
|
* incoming reader arrives while read lock is held but there is a
|
||||||
* queued writer, this incoming reader is queued. (This rule is
|
* queued writer, this incoming reader is queued. (This rule is
|
||||||
* responsible for some of the complexity of method acquireRead,
|
* responsible for some of the complexity of method acquireRead,
|
||||||
* but without it, the lock becomes highly unfair.)
|
* but without it, the lock becomes highly unfair.) Method release
|
||||||
|
* does not (and sometimes cannot) itself wake up cowaiters. This
|
||||||
|
* is done by the primary thread, but helped by any other threads
|
||||||
|
* with nothing better to do in methods acquireRead and
|
||||||
|
* acquireWrite.
|
||||||
*
|
*
|
||||||
* These rules apply to threads actually queued. All tryLock forms
|
* These rules apply to threads actually queued. All tryLock forms
|
||||||
* opportunistically try to acquire locks regardless of preference
|
* opportunistically try to acquire locks regardless of preference
|
||||||
@ -267,11 +271,14 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
/** Number of processors, for spin control */
|
/** Number of processors, for spin control */
|
||||||
private static final int NCPU = Runtime.getRuntime().availableProcessors();
|
private static final int NCPU = Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
/** Maximum number of retries before blocking on acquisition */
|
/** Maximum number of retries before enqueuing on acquisition */
|
||||||
private static final int SPINS = (NCPU > 1) ? 1 << 6 : 0;
|
private static final int SPINS = (NCPU > 1) ? 1 << 6 : 0;
|
||||||
|
|
||||||
|
/** Maximum number of retries before blocking at head on acquisition */
|
||||||
|
private static final int HEAD_SPINS = (NCPU > 1) ? 1 << 10 : 0;
|
||||||
|
|
||||||
/** Maximum number of retries before re-blocking */
|
/** Maximum number of retries before re-blocking */
|
||||||
private static final int MAX_HEAD_SPINS = (NCPU > 1) ? 1 << 12 : 0;
|
private static final int MAX_HEAD_SPINS = (NCPU > 1) ? 1 << 16 : 0;
|
||||||
|
|
||||||
/** The period for yielding when waiting for overflow spinlock */
|
/** The period for yielding when waiting for overflow spinlock */
|
||||||
private static final int OVERFLOW_YIELD_RATE = 7; // must be power 2 - 1
|
private static final int OVERFLOW_YIELD_RATE = 7; // must be power 2 - 1
|
||||||
@ -415,8 +422,8 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
* @return a stamp that can be used to unlock or convert mode
|
* @return a stamp that can be used to unlock or convert mode
|
||||||
*/
|
*/
|
||||||
public long readLock() {
|
public long readLock() {
|
||||||
long s, next; // bypass acquireRead on fully unlocked case only
|
long s = state, next; // bypass acquireRead on common uncontended case
|
||||||
return ((((s = state) & ABITS) == 0L &&
|
return ((whead == wtail && (s & ABITS) < RFULL &&
|
||||||
U.compareAndSwapLong(this, STATE, s, next = s + RUNIT)) ?
|
U.compareAndSwapLong(this, STATE, s, next = s + RUNIT)) ?
|
||||||
next : acquireRead(false, 0L));
|
next : acquireRead(false, 0L));
|
||||||
}
|
}
|
||||||
@ -1012,18 +1019,9 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
if (t.status <= 0)
|
if (t.status <= 0)
|
||||||
q = t;
|
q = t;
|
||||||
}
|
}
|
||||||
if (q != null) {
|
if (q != null && (w = q.thread) != null)
|
||||||
for (WNode r = q;;) { // release co-waiters too
|
|
||||||
if ((w = r.thread) != null) {
|
|
||||||
r.thread = null;
|
|
||||||
U.unpark(w);
|
U.unpark(w);
|
||||||
}
|
}
|
||||||
if ((r = q.cowait) == null)
|
|
||||||
break;
|
|
||||||
U.compareAndSwapObject(q, WCOWAIT, r, r.cowait);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1038,22 +1036,22 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
private long acquireWrite(boolean interruptible, long deadline) {
|
private long acquireWrite(boolean interruptible, long deadline) {
|
||||||
WNode node = null, p;
|
WNode node = null, p;
|
||||||
for (int spins = -1;;) { // spin while enqueuing
|
for (int spins = -1;;) { // spin while enqueuing
|
||||||
long s, ns;
|
long m, s, ns;
|
||||||
if (((s = state) & ABITS) == 0L) {
|
if ((m = (s = state) & ABITS) == 0L) {
|
||||||
if (U.compareAndSwapLong(this, STATE, s, ns = s + WBIT))
|
if (U.compareAndSwapLong(this, STATE, s, ns = s + WBIT))
|
||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
|
else if (spins < 0)
|
||||||
|
spins = (m == WBIT && wtail == whead) ? SPINS : 0;
|
||||||
else if (spins > 0) {
|
else if (spins > 0) {
|
||||||
if (LockSupport.nextSecondarySeed() >= 0)
|
if (LockSupport.nextSecondarySeed() >= 0)
|
||||||
--spins;
|
--spins;
|
||||||
}
|
}
|
||||||
else if ((p = wtail) == null) { // initialize queue
|
else if ((p = wtail) == null) { // initialize queue
|
||||||
WNode h = new WNode(WMODE, null);
|
WNode hd = new WNode(WMODE, null);
|
||||||
if (U.compareAndSwapObject(this, WHEAD, null, h))
|
if (U.compareAndSwapObject(this, WHEAD, null, hd))
|
||||||
wtail = h;
|
wtail = hd;
|
||||||
}
|
}
|
||||||
else if (spins < 0)
|
|
||||||
spins = (p == whead) ? SPINS : 0;
|
|
||||||
else if (node == null)
|
else if (node == null)
|
||||||
node = new WNode(WMODE, p);
|
node = new WNode(WMODE, p);
|
||||||
else if (node.prev != p)
|
else if (node.prev != p)
|
||||||
@ -1064,14 +1062,18 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int spins = SPINS;;) {
|
for (int spins = -1;;) {
|
||||||
WNode np, pp; int ps; long s, ns; Thread w;
|
WNode h, np, pp; int ps;
|
||||||
while ((np = node.prev) != p && np != null)
|
if ((h = whead) == p) {
|
||||||
(p = np).next = node; // stale
|
if (spins < 0)
|
||||||
if (whead == p) {
|
spins = HEAD_SPINS;
|
||||||
|
else if (spins < MAX_HEAD_SPINS)
|
||||||
|
spins <<= 1;
|
||||||
for (int k = spins;;) { // spin at head
|
for (int k = spins;;) { // spin at head
|
||||||
|
long s, ns;
|
||||||
if (((s = state) & ABITS) == 0L) {
|
if (((s = state) & ABITS) == 0L) {
|
||||||
if (U.compareAndSwapLong(this, STATE, s, ns = s+WBIT)) {
|
if (U.compareAndSwapLong(this, STATE, s,
|
||||||
|
ns = s + WBIT)) {
|
||||||
whead = node;
|
whead = node;
|
||||||
node.prev = null;
|
node.prev = null;
|
||||||
return ns;
|
return ns;
|
||||||
@ -1081,10 +1083,21 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
--k <= 0)
|
--k <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (spins < MAX_HEAD_SPINS)
|
|
||||||
spins <<= 1;
|
|
||||||
}
|
}
|
||||||
if ((ps = p.status) == 0)
|
else if (h != null) { // help release stale waiters
|
||||||
|
WNode c; Thread w;
|
||||||
|
while ((c = h.cowait) != null) {
|
||||||
|
if (U.compareAndSwapObject(h, WCOWAIT, c, c.cowait) &&
|
||||||
|
(w = c.thread) != null)
|
||||||
|
U.unpark(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (whead == h) {
|
||||||
|
if ((np = node.prev) != p) {
|
||||||
|
if (np != null)
|
||||||
|
(p = np).next = node; // stale
|
||||||
|
}
|
||||||
|
else if ((ps = p.status) == 0)
|
||||||
U.compareAndSwapInt(p, WSTATUS, 0, WAITING);
|
U.compareAndSwapInt(p, WSTATUS, 0, WAITING);
|
||||||
else if (ps == CANCELLED) {
|
else if (ps == CANCELLED) {
|
||||||
if ((pp = p.prev) != null) {
|
if ((pp = p.prev) != null) {
|
||||||
@ -1099,11 +1112,11 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
else if ((time = deadline - System.nanoTime()) <= 0L)
|
else if ((time = deadline - System.nanoTime()) <= 0L)
|
||||||
return cancelWaiter(node, node, false);
|
return cancelWaiter(node, node, false);
|
||||||
Thread wt = Thread.currentThread();
|
Thread wt = Thread.currentThread();
|
||||||
U.putObject(wt, PARKBLOCKER, this); // emulate LockSupport.park
|
U.putObject(wt, PARKBLOCKER, this);
|
||||||
node.thread = wt;
|
node.thread = wt;
|
||||||
if (node.prev == p && p.status == WAITING && // recheck
|
if (p.status < 0 && (p != h || (state & ABITS) != 0L) &&
|
||||||
(p != whead || (state & ABITS) != 0L))
|
whead == h && node.prev == p)
|
||||||
U.park(false, time);
|
U.park(false, time); // emulate LockSupport.park
|
||||||
node.thread = null;
|
node.thread = null;
|
||||||
U.putObject(wt, PARKBLOCKER, null);
|
U.putObject(wt, PARKBLOCKER, null);
|
||||||
if (interruptible && Thread.interrupted())
|
if (interruptible && Thread.interrupted())
|
||||||
@ -1111,6 +1124,7 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See above for explanation.
|
* See above for explanation.
|
||||||
@ -1122,115 +1136,134 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
* @return next state, or INTERRUPTED
|
* @return next state, or INTERRUPTED
|
||||||
*/
|
*/
|
||||||
private long acquireRead(boolean interruptible, long deadline) {
|
private long acquireRead(boolean interruptible, long deadline) {
|
||||||
WNode node = null, group = null, p;
|
WNode node = null, p;
|
||||||
for (int spins = -1;;) {
|
for (int spins = -1;;) {
|
||||||
for (;;) {
|
WNode h;
|
||||||
long s, m, ns; WNode h, q; Thread w; // anti-barging guard
|
if ((h = whead) == (p = wtail)) {
|
||||||
if (group == null && (h = whead) != null &&
|
for (long m, s, ns;;) {
|
||||||
(q = h.next) != null && q.mode != RMODE)
|
|
||||||
break;
|
|
||||||
if ((m = (s = state) & ABITS) < RFULL ?
|
if ((m = (s = state) & ABITS) < RFULL ?
|
||||||
U.compareAndSwapLong(this, STATE, s, ns = s + RUNIT) :
|
U.compareAndSwapLong(this, STATE, s, ns = s + RUNIT) :
|
||||||
(m < WBIT && (ns = tryIncReaderOverflow(s)) != 0L)) {
|
(m < WBIT && (ns = tryIncReaderOverflow(s)) != 0L))
|
||||||
if (group != null) { // help release others
|
|
||||||
for (WNode r = group;;) {
|
|
||||||
if ((w = r.thread) != null) {
|
|
||||||
r.thread = null;
|
|
||||||
U.unpark(w);
|
|
||||||
}
|
|
||||||
if ((r = group.cowait) == null)
|
|
||||||
break;
|
|
||||||
U.compareAndSwapObject(group, WCOWAIT, r, r.cowait);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ns;
|
return ns;
|
||||||
}
|
else if (m >= WBIT) {
|
||||||
if (m >= WBIT)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (spins > 0) {
|
if (spins > 0) {
|
||||||
if (LockSupport.nextSecondarySeed() >= 0)
|
if (LockSupport.nextSecondarySeed() >= 0)
|
||||||
--spins;
|
--spins;
|
||||||
}
|
}
|
||||||
else if ((p = wtail) == null) {
|
else {
|
||||||
WNode h = new WNode(WMODE, null);
|
if (spins == 0) {
|
||||||
if (U.compareAndSwapObject(this, WHEAD, null, h))
|
WNode nh = whead, np = wtail;
|
||||||
wtail = h;
|
if ((nh == h && np == p) || (h = nh) != (p = np))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
spins = SPINS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p == null) { // initialize queue
|
||||||
|
WNode hd = new WNode(WMODE, null);
|
||||||
|
if (U.compareAndSwapObject(this, WHEAD, null, hd))
|
||||||
|
wtail = hd;
|
||||||
}
|
}
|
||||||
else if (spins < 0)
|
|
||||||
spins = (p == whead) ? SPINS : 0;
|
|
||||||
else if (node == null)
|
else if (node == null)
|
||||||
node = new WNode(WMODE, p);
|
node = new WNode(RMODE, p);
|
||||||
else if (node.prev != p)
|
else if (h == p || p.mode != RMODE) {
|
||||||
|
if (node.prev != p)
|
||||||
node.prev = p;
|
node.prev = p;
|
||||||
else if (p.mode == RMODE && p != whead) {
|
|
||||||
WNode pp = p.prev; // become co-waiter with group p
|
|
||||||
if (pp != null && p == wtail &&
|
|
||||||
U.compareAndSwapObject(p, WCOWAIT,
|
|
||||||
node.cowait = p.cowait, node)) {
|
|
||||||
node.thread = Thread.currentThread();
|
|
||||||
for (long time;;) {
|
|
||||||
if (deadline == 0L)
|
|
||||||
time = 0L;
|
|
||||||
else if ((time = deadline - System.nanoTime()) <= 0L)
|
|
||||||
return cancelWaiter(node, p, false);
|
|
||||||
if (node.thread == null)
|
|
||||||
break;
|
|
||||||
if (p.prev != pp || p.status == CANCELLED ||
|
|
||||||
p == whead || p.prev != pp) {
|
|
||||||
node.thread = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Thread wt = Thread.currentThread();
|
|
||||||
U.putObject(wt, PARKBLOCKER, this);
|
|
||||||
if (node.thread == null) // must recheck
|
|
||||||
break;
|
|
||||||
U.park(false, time);
|
|
||||||
U.putObject(wt, PARKBLOCKER, null);
|
|
||||||
if (interruptible && Thread.interrupted())
|
|
||||||
return cancelWaiter(node, p, true);
|
|
||||||
}
|
|
||||||
group = p;
|
|
||||||
}
|
|
||||||
node = null; // throw away
|
|
||||||
}
|
|
||||||
else if (U.compareAndSwapObject(this, WTAIL, p, node)) {
|
else if (U.compareAndSwapObject(this, WTAIL, p, node)) {
|
||||||
p.next = node;
|
p.next = node;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!U.compareAndSwapObject(p, WCOWAIT,
|
||||||
|
node.cowait = p.cowait, node))
|
||||||
|
node.cowait = null;
|
||||||
|
else {
|
||||||
|
for (;;) {
|
||||||
|
WNode pp, c; Thread w;
|
||||||
|
if ((h = whead) != null && (c = h.cowait) != null &&
|
||||||
|
U.compareAndSwapObject(h, WCOWAIT, c, c.cowait) &&
|
||||||
|
(w = c.thread) != null) // help release
|
||||||
|
U.unpark(w);
|
||||||
|
if (h == (pp = p.prev) || h == p || pp == null) {
|
||||||
|
long m, s, ns;
|
||||||
|
do {
|
||||||
|
if ((m = (s = state) & ABITS) < RFULL ?
|
||||||
|
U.compareAndSwapLong(this, STATE, s,
|
||||||
|
ns = s + RUNIT) :
|
||||||
|
(m < WBIT &&
|
||||||
|
(ns = tryIncReaderOverflow(s)) != 0L))
|
||||||
|
return ns;
|
||||||
|
} while (m < WBIT);
|
||||||
|
}
|
||||||
|
if (whead == h && p.prev == pp) {
|
||||||
|
long time;
|
||||||
|
if (pp == null || h == p || p.status > 0) {
|
||||||
|
node = null; // throw away
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (deadline == 0L)
|
||||||
|
time = 0L;
|
||||||
|
else if ((time = deadline - System.nanoTime()) <= 0L)
|
||||||
|
return cancelWaiter(node, p, false);
|
||||||
|
Thread wt = Thread.currentThread();
|
||||||
|
U.putObject(wt, PARKBLOCKER, this);
|
||||||
|
node.thread = wt;
|
||||||
|
if ((h != pp || (state & ABITS) == WBIT) &&
|
||||||
|
whead == h && p.prev == pp)
|
||||||
|
U.park(false, time);
|
||||||
|
node.thread = null;
|
||||||
|
U.putObject(wt, PARKBLOCKER, null);
|
||||||
|
if (interruptible && Thread.interrupted())
|
||||||
|
return cancelWaiter(node, p, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int spins = SPINS;;) {
|
for (int spins = -1;;) {
|
||||||
WNode np, pp, r; int ps; long m, s, ns; Thread w;
|
WNode h, np, pp; int ps;
|
||||||
while ((np = node.prev) != p && np != null)
|
if ((h = whead) == p) {
|
||||||
(p = np).next = node;
|
if (spins < 0)
|
||||||
if (whead == p) {
|
spins = HEAD_SPINS;
|
||||||
for (int k = spins;;) {
|
else if (spins < MAX_HEAD_SPINS)
|
||||||
if ((m = (s = state) & ABITS) != WBIT) {
|
spins <<= 1;
|
||||||
if (m < RFULL ?
|
for (int k = spins;;) { // spin at head
|
||||||
U.compareAndSwapLong(this, STATE, s, ns = s + RUNIT):
|
long m, s, ns;
|
||||||
(ns = tryIncReaderOverflow(s)) != 0L) {
|
if ((m = (s = state) & ABITS) < RFULL ?
|
||||||
|
U.compareAndSwapLong(this, STATE, s, ns = s + RUNIT) :
|
||||||
|
(m < WBIT && (ns = tryIncReaderOverflow(s)) != 0L)) {
|
||||||
|
WNode c; Thread w;
|
||||||
whead = node;
|
whead = node;
|
||||||
node.prev = null;
|
node.prev = null;
|
||||||
while ((r = node.cowait) != null) {
|
while ((c = node.cowait) != null) {
|
||||||
if (U.compareAndSwapObject(node, WCOWAIT,
|
if (U.compareAndSwapObject(node, WCOWAIT,
|
||||||
r, r.cowait) &&
|
c, c.cowait) &&
|
||||||
(w = r.thread) != null) {
|
(w = c.thread) != null)
|
||||||
r.thread = null;
|
U.unpark(w);
|
||||||
U.unpark(w); // release co-waiter
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
}
|
else if (m >= WBIT &&
|
||||||
else if (LockSupport.nextSecondarySeed() >= 0 &&
|
LockSupport.nextSecondarySeed() >= 0 && --k <= 0)
|
||||||
--k <= 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (spins < MAX_HEAD_SPINS)
|
|
||||||
spins <<= 1;
|
|
||||||
}
|
}
|
||||||
if ((ps = p.status) == 0)
|
else if (h != null) {
|
||||||
|
WNode c; Thread w;
|
||||||
|
while ((c = h.cowait) != null) {
|
||||||
|
if (U.compareAndSwapObject(h, WCOWAIT, c, c.cowait) &&
|
||||||
|
(w = c.thread) != null)
|
||||||
|
U.unpark(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (whead == h) {
|
||||||
|
if ((np = node.prev) != p) {
|
||||||
|
if (np != null)
|
||||||
|
(p = np).next = node; // stale
|
||||||
|
}
|
||||||
|
else if ((ps = p.status) == 0)
|
||||||
U.compareAndSwapInt(p, WSTATUS, 0, WAITING);
|
U.compareAndSwapInt(p, WSTATUS, 0, WAITING);
|
||||||
else if (ps == CANCELLED) {
|
else if (ps == CANCELLED) {
|
||||||
if ((pp = p.prev) != null) {
|
if ((pp = p.prev) != null) {
|
||||||
@ -1247,8 +1280,9 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
Thread wt = Thread.currentThread();
|
Thread wt = Thread.currentThread();
|
||||||
U.putObject(wt, PARKBLOCKER, this);
|
U.putObject(wt, PARKBLOCKER, this);
|
||||||
node.thread = wt;
|
node.thread = wt;
|
||||||
if (node.prev == p && p.status == WAITING &&
|
if (p.status < 0 &&
|
||||||
(p != whead || (state & ABITS) != WBIT))
|
(p != h || (state & ABITS) == WBIT) &&
|
||||||
|
whead == h && node.prev == p)
|
||||||
U.park(false, time);
|
U.park(false, time);
|
||||||
node.thread = null;
|
node.thread = null;
|
||||||
U.putObject(wt, PARKBLOCKER, null);
|
U.putObject(wt, PARKBLOCKER, null);
|
||||||
@ -1257,6 +1291,7 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If node non-null, forces cancel status and unsplices it from
|
* If node non-null, forces cancel status and unsplices it from
|
||||||
@ -1278,22 +1313,19 @@ public class StampedLock implements java.io.Serializable {
|
|||||||
if (node != null && group != null) {
|
if (node != null && group != null) {
|
||||||
Thread w;
|
Thread w;
|
||||||
node.status = CANCELLED;
|
node.status = CANCELLED;
|
||||||
node.thread = null;
|
|
||||||
// unsplice cancelled nodes from group
|
// unsplice cancelled nodes from group
|
||||||
for (WNode p = group, q; (q = p.cowait) != null;) {
|
for (WNode p = group, q; (q = p.cowait) != null;) {
|
||||||
if (q.status == CANCELLED)
|
if (q.status == CANCELLED) {
|
||||||
U.compareAndSwapObject(p, WNEXT, q, q.next);
|
U.compareAndSwapObject(p, WCOWAIT, q, q.cowait);
|
||||||
|
p = group; // restart
|
||||||
|
}
|
||||||
else
|
else
|
||||||
p = q;
|
p = q;
|
||||||
}
|
}
|
||||||
if (group == node) {
|
if (group == node) {
|
||||||
WNode r; // detach and wake up uncancelled co-waiters
|
for (WNode r = group.cowait; r != null; r = r.cowait) {
|
||||||
while ((r = node.cowait) != null) {
|
if ((w = r.thread) != null)
|
||||||
if (U.compareAndSwapObject(node, WCOWAIT, r, r.cowait) &&
|
U.unpark(w); // wake up uncancelled co-waiters
|
||||||
(w = r.thread) != null) {
|
|
||||||
r.thread = null;
|
|
||||||
U.unpark(w);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (WNode pred = node.prev; pred != null; ) { // unsplice
|
for (WNode pred = node.prev; pred != null; ) { // unsplice
|
||||||
WNode succ, pp; // find valid successor
|
WNode succ, pp; // find valid successor
|
||||||
|
@ -32,6 +32,7 @@ import java.security.*;
|
|||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
|
import sun.misc.JarIndex;
|
||||||
import sun.security.util.ManifestDigester;
|
import sun.security.util.ManifestDigester;
|
||||||
import sun.security.util.ManifestEntryVerifier;
|
import sun.security.util.ManifestEntryVerifier;
|
||||||
import sun.security.util.SignatureFileVerifier;
|
import sun.security.util.SignatureFileVerifier;
|
||||||
@ -139,7 +140,8 @@ class JarVerifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uname.equals(JarFile.MANIFEST_NAME)) {
|
if (uname.equals(JarFile.MANIFEST_NAME) ||
|
||||||
|
uname.equals(JarIndex.INDEX_NAME)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,13 +457,15 @@ public class Logger {
|
|||||||
* of the subsystem, such as java.net
|
* of the subsystem, such as java.net
|
||||||
* or javax.swing
|
* or javax.swing
|
||||||
* @param resourceBundleName name of ResourceBundle to be used for localizing
|
* @param resourceBundleName name of ResourceBundle to be used for localizing
|
||||||
* messages for this logger. May be <CODE>null</CODE> if none of
|
* messages for this logger. May be {@code null}
|
||||||
* the messages require localization.
|
* if none of the messages require localization.
|
||||||
* @return a suitable Logger
|
* @return a suitable Logger
|
||||||
* @throws MissingResourceException if the resourceBundleName is non-null and
|
* @throws MissingResourceException if the resourceBundleName is non-null and
|
||||||
* no corresponding resource can be found.
|
* no corresponding resource can be found.
|
||||||
* @throws IllegalArgumentException if the Logger already exists and uses
|
* @throws IllegalArgumentException if the Logger already exists and uses
|
||||||
* a different resource bundle name.
|
* a different resource bundle name; or if
|
||||||
|
* {@code resourceBundleName} is {@code null} but the named
|
||||||
|
* logger has a resource bundle set.
|
||||||
* @throws NullPointerException if the name is null.
|
* @throws NullPointerException if the name is null.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1731,10 +1733,6 @@ public class Logger {
|
|||||||
// Synchronized to prevent races in setting the fields.
|
// Synchronized to prevent races in setting the fields.
|
||||||
private synchronized void setupResourceInfo(String name,
|
private synchronized void setupResourceInfo(String name,
|
||||||
Class<?> callersClass) {
|
Class<?> callersClass) {
|
||||||
if (name == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resourceBundleName != null) {
|
if (resourceBundleName != null) {
|
||||||
// this Logger already has a ResourceBundle
|
// this Logger already has a ResourceBundle
|
||||||
|
|
||||||
@ -1748,6 +1746,10 @@ public class Logger {
|
|||||||
resourceBundleName + " != " + name);
|
resourceBundleName + " != " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setCallersClassLoaderRef(callersClass);
|
setCallersClassLoaderRef(callersClass);
|
||||||
if (findResourceBundle(name, true) == null) {
|
if (findResourceBundle(name, true) == null) {
|
||||||
// We've failed to find an expected ResourceBundle.
|
// We've failed to find an expected ResourceBundle.
|
||||||
|
@ -219,7 +219,7 @@ import java.util.stream.StreamSupport;
|
|||||||
*
|
*
|
||||||
* <tr><th> </th></tr>
|
* <tr><th> </th></tr>
|
||||||
* <tr align="left"><th colspan="2" id="unicode">Classes for Unicode scripts, blocks, categories and binary properties</th></tr>
|
* <tr align="left"><th colspan="2" id="unicode">Classes for Unicode scripts, blocks, categories and binary properties</th></tr>
|
||||||
* * <tr><td valign="top" headers="construct unicode">{@code \p{IsLatin}}</td>
|
* <tr><td valign="top" headers="construct unicode">{@code \p{IsLatin}}</td>
|
||||||
* <td headers="matches">A Latin script character (<a href="#usc">script</a>)</td></tr>
|
* <td headers="matches">A Latin script character (<a href="#usc">script</a>)</td></tr>
|
||||||
* <tr><td valign="top" headers="construct unicode">{@code \p{InGreek}}</td>
|
* <tr><td valign="top" headers="construct unicode">{@code \p{InGreek}}</td>
|
||||||
* <td headers="matches">A character in the Greek block (<a href="#ubc">block</a>)</td></tr>
|
* <td headers="matches">A character in the Greek block (<a href="#ubc">block</a>)</td></tr>
|
||||||
@ -4456,16 +4456,16 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||||||
groups[groupIndex+1] = i;
|
groups[groupIndex+1] = i;
|
||||||
groups[groupIndex] = i - k;
|
groups[groupIndex] = i - k;
|
||||||
}
|
}
|
||||||
i = i - k;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// backing off
|
// backing off
|
||||||
|
i = i - k;
|
||||||
if (capture) {
|
if (capture) {
|
||||||
groups[groupIndex+1] = i;
|
groups[groupIndex+1] = i;
|
||||||
groups[groupIndex] = i - k;
|
groups[groupIndex] = i - k;
|
||||||
}
|
}
|
||||||
i = i - k;
|
|
||||||
j--;
|
j--;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4883,7 +4883,6 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||||||
int k = matcher.groups[groupIndex+1];
|
int k = matcher.groups[groupIndex+1];
|
||||||
|
|
||||||
int groupSize = k - j;
|
int groupSize = k - j;
|
||||||
|
|
||||||
// If the referenced group didn't match, neither can this
|
// If the referenced group didn't match, neither can this
|
||||||
if (j < 0)
|
if (j < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -4893,7 +4892,6 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||||||
matcher.hitEnd = true;
|
matcher.hitEnd = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check each new char to make sure it matches what the group
|
// Check each new char to make sure it matches what the group
|
||||||
// referenced matched last time around
|
// referenced matched last time around
|
||||||
for (int index=0; index<groupSize; index++)
|
for (int index=0; index<groupSize; index++)
|
||||||
|
@ -137,6 +137,11 @@ public final class Collectors {
|
|||||||
return (u,v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); };
|
return (u,v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static <I, R> Function<I, R> castingIdentity() {
|
||||||
|
return i -> (R) i;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation class for {@code Collector}.
|
* Simple implementation class for {@code Collector}.
|
||||||
*
|
*
|
||||||
@ -166,7 +171,7 @@ public final class Collectors {
|
|||||||
BiConsumer<A, T> accumulator,
|
BiConsumer<A, T> accumulator,
|
||||||
BinaryOperator<A> combiner,
|
BinaryOperator<A> combiner,
|
||||||
Set<Characteristics> characteristics) {
|
Set<Characteristics> characteristics) {
|
||||||
this(supplier, accumulator, combiner, i -> (R) i, characteristics);
|
this(supplier, accumulator, combiner, castingIdentity(), characteristics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -209,7 +214,7 @@ public final class Collectors {
|
|||||||
*/
|
*/
|
||||||
public static <T, C extends Collection<T>>
|
public static <T, C extends Collection<T>>
|
||||||
Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) {
|
Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) {
|
||||||
return new CollectorImpl<>(collectionFactory, Collection::add,
|
return new CollectorImpl<>(collectionFactory, Collection<T>::add,
|
||||||
(r1, r2) -> { r1.addAll(r2); return r1; },
|
(r1, r2) -> { r1.addAll(r2); return r1; },
|
||||||
CH_ID);
|
CH_ID);
|
||||||
}
|
}
|
||||||
@ -1046,30 +1051,23 @@ public final class Collectors {
|
|||||||
public static <T, D, A>
|
public static <T, D, A>
|
||||||
Collector<T, ?, Map<Boolean, D>> partitioningBy(Predicate<? super T> predicate,
|
Collector<T, ?, Map<Boolean, D>> partitioningBy(Predicate<? super T> predicate,
|
||||||
Collector<? super T, A, D> downstream) {
|
Collector<? super T, A, D> downstream) {
|
||||||
@SuppressWarnings("unchecked")
|
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
|
||||||
BiConsumer<D, ? super T> downstreamAccumulator = (BiConsumer<D, ? super T>) downstream.accumulator();
|
BiConsumer<Partition<A>, T> accumulator = (result, t) ->
|
||||||
BiConsumer<Map<Boolean, A>, T> accumulator = (result, t) -> {
|
downstreamAccumulator.accept(predicate.test(t) ? result.forTrue : result.forFalse, t);
|
||||||
Partition<D> asPartition = ((Partition<D>) result);
|
|
||||||
downstreamAccumulator.accept(predicate.test(t) ? asPartition.forTrue : asPartition.forFalse, t);
|
|
||||||
};
|
|
||||||
BinaryOperator<A> op = downstream.combiner();
|
BinaryOperator<A> op = downstream.combiner();
|
||||||
BinaryOperator<Map<Boolean, A>> merger = (m1, m2) -> {
|
BinaryOperator<Partition<A>> merger = (left, right) ->
|
||||||
Partition<A> left = (Partition<A>) m1;
|
new Partition<>(op.apply(left.forTrue, right.forTrue),
|
||||||
Partition<A> right = (Partition<A>) m2;
|
|
||||||
return new Partition<>(op.apply(left.forTrue, right.forTrue),
|
|
||||||
op.apply(left.forFalse, right.forFalse));
|
op.apply(left.forFalse, right.forFalse));
|
||||||
};
|
Supplier<Partition<A>> supplier = () ->
|
||||||
Supplier<Map<Boolean, A>> supplier = () -> new Partition<>(downstream.supplier().get(),
|
new Partition<>(downstream.supplier().get(),
|
||||||
downstream.supplier().get());
|
downstream.supplier().get());
|
||||||
if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
||||||
return new CollectorImpl<>(supplier, accumulator, merger, CH_ID);
|
return new CollectorImpl<>(supplier, accumulator, merger, CH_ID);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Function<Map<Boolean, A>, Map<Boolean, D>> finisher = (Map<Boolean, A> par) -> {
|
Function<Partition<A>, Map<Boolean, D>> finisher = par ->
|
||||||
Partition<A> asAPartition = (Partition<A>) par;
|
new Partition<>(downstream.finisher().apply(par.forTrue),
|
||||||
return new Partition<>(downstream.finisher().apply(asAPartition.forTrue),
|
downstream.finisher().apply(par.forFalse));
|
||||||
downstream.finisher().apply(asAPartition.forFalse));
|
|
||||||
};
|
|
||||||
return new CollectorImpl<>(supplier, accumulator, merger, finisher, CH_NOID);
|
return new CollectorImpl<>(supplier, accumulator, merger, finisher, CH_NOID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ final class DistinctOps {
|
|||||||
if (StreamOpFlag.DISTINCT.isKnown(flags)) {
|
if (StreamOpFlag.DISTINCT.isKnown(flags)) {
|
||||||
return sink;
|
return sink;
|
||||||
} else if (StreamOpFlag.SORTED.isKnown(flags)) {
|
} else if (StreamOpFlag.SORTED.isKnown(flags)) {
|
||||||
return new Sink.ChainedReference<T>(sink) {
|
return new Sink.ChainedReference<T, T>(sink) {
|
||||||
boolean seenNull;
|
boolean seenNull;
|
||||||
T lastSeen;
|
T lastSeen;
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ final class DistinctOps {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return new Sink.ChainedReference<T>(sink) {
|
return new Sink.ChainedReference<T, T>(sink) {
|
||||||
Set<T> seen;
|
Set<T> seen;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -191,7 +191,7 @@ abstract class DoublePipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(double t) {
|
public void accept(double t) {
|
||||||
downstream.accept(mapper.applyAsDouble(t));
|
downstream.accept(mapper.applyAsDouble(t));
|
||||||
@ -208,9 +208,8 @@ abstract class DoublePipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<U> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<U> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<U>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(double t) {
|
public void accept(double t) {
|
||||||
downstream.accept(mapper.apply(t));
|
downstream.accept(mapper.apply(t));
|
||||||
}
|
}
|
||||||
@ -226,7 +225,7 @@ abstract class DoublePipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(double t) {
|
public void accept(double t) {
|
||||||
downstream.accept(mapper.applyAsInt(t));
|
downstream.accept(mapper.applyAsInt(t));
|
||||||
@ -243,7 +242,7 @@ abstract class DoublePipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(double t) {
|
public void accept(double t) {
|
||||||
downstream.accept(mapper.applyAsLong(t));
|
downstream.accept(mapper.applyAsLong(t));
|
||||||
@ -259,7 +258,7 @@ abstract class DoublePipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
@ -296,7 +295,7 @@ abstract class DoublePipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
@ -319,7 +318,7 @@ abstract class DoublePipeline<E_IN>
|
|||||||
0) {
|
0) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(double t) {
|
public void accept(double t) {
|
||||||
consumer.accept(t);
|
consumer.accept(t);
|
||||||
|
@ -189,9 +189,8 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
downstream.accept((long) t);
|
downstream.accept((long) t);
|
||||||
}
|
}
|
||||||
@ -206,9 +205,8 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
downstream.accept((double) t);
|
downstream.accept((double) t);
|
||||||
}
|
}
|
||||||
@ -229,7 +227,7 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
downstream.accept(mapper.applyAsInt(t));
|
downstream.accept(mapper.applyAsInt(t));
|
||||||
@ -246,9 +244,8 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<U> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<U> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<U>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
downstream.accept(mapper.apply(t));
|
downstream.accept(mapper.apply(t));
|
||||||
}
|
}
|
||||||
@ -264,7 +261,7 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
downstream.accept(mapper.applyAsLong(t));
|
downstream.accept(mapper.applyAsLong(t));
|
||||||
@ -281,7 +278,7 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
downstream.accept(mapper.applyAsDouble(t));
|
downstream.accept(mapper.applyAsDouble(t));
|
||||||
@ -297,7 +294,7 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
@ -334,7 +331,7 @@ abstract class IntPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
@ -357,7 +354,7 @@ abstract class IntPipeline<E_IN>
|
|||||||
0) {
|
0) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(int t) {
|
public void accept(int t) {
|
||||||
consumer.accept(t);
|
consumer.accept(t);
|
||||||
|
@ -186,7 +186,7 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(long t) {
|
public void accept(long t) {
|
||||||
downstream.accept((double) t);
|
downstream.accept((double) t);
|
||||||
@ -208,9 +208,8 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(long t) {
|
public void accept(long t) {
|
||||||
downstream.accept(mapper.applyAsLong(t));
|
downstream.accept(mapper.applyAsLong(t));
|
||||||
}
|
}
|
||||||
@ -226,9 +225,8 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<U> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<U> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<U>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(long t) {
|
public void accept(long t) {
|
||||||
downstream.accept(mapper.apply(t));
|
downstream.accept(mapper.apply(t));
|
||||||
}
|
}
|
||||||
@ -244,9 +242,8 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(long t) {
|
public void accept(long t) {
|
||||||
downstream.accept(mapper.applyAsInt(t));
|
downstream.accept(mapper.applyAsInt(t));
|
||||||
}
|
}
|
||||||
@ -262,7 +259,7 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(long t) {
|
public void accept(long t) {
|
||||||
downstream.accept(mapper.applyAsDouble(t));
|
downstream.accept(mapper.applyAsDouble(t));
|
||||||
@ -278,7 +275,7 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
@ -315,7 +312,7 @@ abstract class LongPipeline<E_IN>
|
|||||||
StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
@ -338,7 +335,7 @@ abstract class LongPipeline<E_IN>
|
|||||||
0) {
|
0) {
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(long t) {
|
public void accept(long t) {
|
||||||
consumer.accept(t);
|
consumer.accept(t);
|
||||||
|
@ -163,17 +163,16 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, P_OUT>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
if (predicate.test(u))
|
if (predicate.test(u))
|
||||||
downstream.accept((Object) u);
|
downstream.accept(u);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -188,7 +187,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, R>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
downstream.accept(mapper.apply(u));
|
downstream.accept(mapper.apply(u));
|
||||||
@ -205,7 +204,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, Integer>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
downstream.accept(mapper.applyAsInt(u));
|
downstream.accept(mapper.applyAsInt(u));
|
||||||
@ -222,7 +221,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, Long>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
downstream.accept(mapper.applyAsLong(u));
|
downstream.accept(mapper.applyAsLong(u));
|
||||||
@ -239,7 +238,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, Double>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
downstream.accept(mapper.applyAsDouble(u));
|
downstream.accept(mapper.applyAsDouble(u));
|
||||||
@ -257,14 +256,13 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, R>(sink) {
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
downstream.begin(-1);
|
downstream.begin(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
|
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
|
||||||
Stream<? extends R> result = mapper.apply(u);
|
Stream<? extends R> result = mapper.apply(u);
|
||||||
@ -284,7 +282,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, Integer>(sink) {
|
||||||
IntConsumer downstreamAsInt = downstream::accept;
|
IntConsumer downstreamAsInt = downstream::accept;
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
@ -311,7 +309,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, Double>(sink) {
|
||||||
DoubleConsumer downstreamAsDouble = downstream::accept;
|
DoubleConsumer downstreamAsDouble = downstream::accept;
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
@ -338,7 +336,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, Long>(sink) {
|
||||||
LongConsumer downstreamAsLong = downstream::accept;
|
LongConsumer downstreamAsLong = downstream::accept;
|
||||||
@Override
|
@Override
|
||||||
public void begin(long size) {
|
public void begin(long size) {
|
||||||
@ -364,9 +362,8 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
0) {
|
0) {
|
||||||
@Override
|
@Override
|
||||||
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
|
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
|
||||||
return new Sink.ChainedReference<P_OUT>(sink) {
|
return new Sink.ChainedReference<P_OUT, P_OUT>(sink) {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void accept(P_OUT u) {
|
public void accept(P_OUT u) {
|
||||||
tee.accept(u);
|
tee.accept(u);
|
||||||
downstream.accept(u);
|
downstream.accept(u);
|
||||||
@ -495,6 +492,7 @@ abstract class ReferencePipeline<P_IN, P_OUT>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final <R, A> R collect(Collector<? super P_OUT, A, ? extends R> collector) {
|
public final <R, A> R collect(Collector<? super P_OUT, A, ? extends R> collector) {
|
||||||
A container;
|
A container;
|
||||||
if (isParallel()
|
if (isParallel()
|
||||||
|
@ -241,11 +241,10 @@ interface Sink<T> extends Consumer<T> {
|
|||||||
* implementation of the {@code accept()} method must call the correct
|
* implementation of the {@code accept()} method must call the correct
|
||||||
* {@code accept()} method on the downstream {@code Sink}.
|
* {@code accept()} method on the downstream {@code Sink}.
|
||||||
*/
|
*/
|
||||||
static abstract class ChainedReference<T> implements Sink<T> {
|
static abstract class ChainedReference<T, E_OUT> implements Sink<T> {
|
||||||
@SuppressWarnings("rawtypes")
|
protected final Sink<? super E_OUT> downstream;
|
||||||
protected final Sink downstream;
|
|
||||||
|
|
||||||
public ChainedReference(Sink downstream) {
|
public ChainedReference(Sink<? super E_OUT> downstream) {
|
||||||
this.downstream = Objects.requireNonNull(downstream);
|
this.downstream = Objects.requireNonNull(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,11 +273,10 @@ interface Sink<T> extends Consumer<T> {
|
|||||||
* The implementation of the {@code accept()} method must call the correct
|
* The implementation of the {@code accept()} method must call the correct
|
||||||
* {@code accept()} method on the downstream {@code Sink}.
|
* {@code accept()} method on the downstream {@code Sink}.
|
||||||
*/
|
*/
|
||||||
static abstract class ChainedInt implements Sink.OfInt {
|
static abstract class ChainedInt<E_OUT> implements Sink.OfInt {
|
||||||
@SuppressWarnings("rawtypes")
|
protected final Sink<? super E_OUT> downstream;
|
||||||
protected final Sink downstream;
|
|
||||||
|
|
||||||
public ChainedInt(Sink downstream) {
|
public ChainedInt(Sink<? super E_OUT> downstream) {
|
||||||
this.downstream = Objects.requireNonNull(downstream);
|
this.downstream = Objects.requireNonNull(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,11 +305,10 @@ interface Sink<T> extends Consumer<T> {
|
|||||||
* The implementation of the {@code accept()} method must call the correct
|
* The implementation of the {@code accept()} method must call the correct
|
||||||
* {@code accept()} method on the downstream {@code Sink}.
|
* {@code accept()} method on the downstream {@code Sink}.
|
||||||
*/
|
*/
|
||||||
static abstract class ChainedLong implements Sink.OfLong {
|
static abstract class ChainedLong<E_OUT> implements Sink.OfLong {
|
||||||
@SuppressWarnings("rawtypes")
|
protected final Sink<? super E_OUT> downstream;
|
||||||
protected final Sink downstream;
|
|
||||||
|
|
||||||
public ChainedLong(Sink downstream) {
|
public ChainedLong(Sink<? super E_OUT> downstream) {
|
||||||
this.downstream = Objects.requireNonNull(downstream);
|
this.downstream = Objects.requireNonNull(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,11 +337,10 @@ interface Sink<T> extends Consumer<T> {
|
|||||||
* The implementation of the {@code accept()} method must call the correct
|
* The implementation of the {@code accept()} method must call the correct
|
||||||
* {@code accept()} method on the downstream {@code Sink}.
|
* {@code accept()} method on the downstream {@code Sink}.
|
||||||
*/
|
*/
|
||||||
static abstract class ChainedDouble implements Sink.OfDouble {
|
static abstract class ChainedDouble<E_OUT> implements Sink.OfDouble {
|
||||||
@SuppressWarnings("rawtypes")
|
protected final Sink<? super E_OUT> downstream;
|
||||||
protected final Sink downstream;
|
|
||||||
|
|
||||||
public ChainedDouble(Sink downstream) {
|
public ChainedDouble(Sink<? super E_OUT> downstream) {
|
||||||
this.downstream = Objects.requireNonNull(downstream);
|
this.downstream = Objects.requireNonNull(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,11 @@ final class SliceOps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static <T> IntFunction<T[]> castingArray() {
|
||||||
|
return size -> (T[]) new Object[size];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends a "slice" operation to the provided stream. The slice operation
|
* Appends a "slice" operation to the provided stream. The slice operation
|
||||||
* may be may be skip-only, limit-only, or skip-and-limit.
|
* may be may be skip-only, limit-only, or skip-and-limit.
|
||||||
@ -111,7 +116,7 @@ final class SliceOps {
|
|||||||
if (skip < 0)
|
if (skip < 0)
|
||||||
throw new IllegalArgumentException("Skip must be non-negative: " + skip);
|
throw new IllegalArgumentException("Skip must be non-negative: " + skip);
|
||||||
|
|
||||||
return new ReferencePipeline.StatefulOp<T,T>(upstream, StreamShape.REFERENCE,
|
return new ReferencePipeline.StatefulOp<T, T>(upstream, StreamShape.REFERENCE,
|
||||||
flags(limit)) {
|
flags(limit)) {
|
||||||
Spliterator<T> unorderedSkipLimitSpliterator(Spliterator<T> s,
|
Spliterator<T> unorderedSkipLimitSpliterator(Spliterator<T> s,
|
||||||
long skip, long limit, long sizeIfKnown) {
|
long skip, long limit, long sizeIfKnown) {
|
||||||
@ -146,7 +151,7 @@ final class SliceOps {
|
|||||||
// cancellation will be more aggressive cancelling later tasks
|
// cancellation will be more aggressive cancelling later tasks
|
||||||
// if the target slice size has been reached from a given task,
|
// if the target slice size has been reached from a given task,
|
||||||
// cancellation should also clear local results if any
|
// cancellation should also clear local results if any
|
||||||
return new SliceTask<>(this, helper, spliterator, i -> (T[]) new Object[i], skip, limit).
|
return new SliceTask<>(this, helper, spliterator, castingArray(), skip, limit).
|
||||||
invoke().spliterator();
|
invoke().spliterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,7 +187,7 @@ final class SliceOps {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Sink<T> opWrapSink(int flags, Sink<T> sink) {
|
Sink<T> opWrapSink(int flags, Sink<T> sink) {
|
||||||
return new Sink.ChainedReference<T>(sink) {
|
return new Sink.ChainedReference<T, T>(sink) {
|
||||||
long n = skip;
|
long n = skip;
|
||||||
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
||||||
|
|
||||||
@ -291,7 +296,7 @@ final class SliceOps {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
|
||||||
return new Sink.ChainedInt(sink) {
|
return new Sink.ChainedInt<Integer>(sink) {
|
||||||
long n = skip;
|
long n = skip;
|
||||||
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
||||||
|
|
||||||
@ -400,7 +405,7 @@ final class SliceOps {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
|
||||||
return new Sink.ChainedLong(sink) {
|
return new Sink.ChainedLong<Long>(sink) {
|
||||||
long n = skip;
|
long n = skip;
|
||||||
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
||||||
|
|
||||||
@ -509,7 +514,7 @@ final class SliceOps {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
|
||||||
return new Sink.ChainedDouble(sink) {
|
return new Sink.ChainedDouble<Double>(sink) {
|
||||||
long n = skip;
|
long n = skip;
|
||||||
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
long m = limit >= 0 ? limit : Long.MAX_VALUE;
|
||||||
|
|
||||||
@ -560,13 +565,13 @@ final class SliceOps {
|
|||||||
|
|
||||||
private volatile boolean completed;
|
private volatile boolean completed;
|
||||||
|
|
||||||
SliceTask(AbstractPipeline<?, P_OUT, ?> op,
|
SliceTask(AbstractPipeline<P_OUT, P_OUT, ?> op,
|
||||||
PipelineHelper<P_OUT> helper,
|
PipelineHelper<P_OUT> helper,
|
||||||
Spliterator<P_IN> spliterator,
|
Spliterator<P_IN> spliterator,
|
||||||
IntFunction<P_OUT[]> generator,
|
IntFunction<P_OUT[]> generator,
|
||||||
long offset, long size) {
|
long offset, long size) {
|
||||||
super(helper, spliterator);
|
super(helper, spliterator);
|
||||||
this.op = (AbstractPipeline<P_OUT, P_OUT, ?>) op;
|
this.op = op;
|
||||||
this.generator = generator;
|
this.generator = generator;
|
||||||
this.targetOffset = offset;
|
this.targetOffset = offset;
|
||||||
this.targetSize = size;
|
this.targetSize = size;
|
||||||
|
@ -129,7 +129,7 @@ final class SortedOps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sink<T> opWrapSink(int flags, Sink sink) {
|
public Sink<T> opWrapSink(int flags, Sink<T> sink) {
|
||||||
Objects.requireNonNull(sink);
|
Objects.requireNonNull(sink);
|
||||||
|
|
||||||
// If the input is already naturally sorted and this operation
|
// If the input is already naturally sorted and this operation
|
||||||
@ -280,12 +280,12 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link ForkJoinTask} for implementing sort on SIZED reference streams.
|
* {@link ForkJoinTask} for implementing sort on SIZED reference streams.
|
||||||
*/
|
*/
|
||||||
private static final class SizedRefSortingSink<T> extends Sink.ChainedReference<T> {
|
private static final class SizedRefSortingSink<T> extends Sink.ChainedReference<T, T> {
|
||||||
private final Comparator<? super T> comparator;
|
private final Comparator<? super T> comparator;
|
||||||
private T[] array;
|
private T[] array;
|
||||||
private int offset;
|
private int offset;
|
||||||
|
|
||||||
SizedRefSortingSink(Sink<T> sink, Comparator<? super T> comparator) {
|
SizedRefSortingSink(Sink<? super T> sink, Comparator<? super T> comparator) {
|
||||||
super(sink);
|
super(sink);
|
||||||
this.comparator = comparator;
|
this.comparator = comparator;
|
||||||
}
|
}
|
||||||
@ -320,11 +320,11 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on reference streams.
|
* {@link Sink} for implementing sort on reference streams.
|
||||||
*/
|
*/
|
||||||
private static final class RefSortingSink<T> extends Sink.ChainedReference<T> {
|
private static final class RefSortingSink<T> extends Sink.ChainedReference<T, T> {
|
||||||
private final Comparator<? super T> comparator;
|
private final Comparator<? super T> comparator;
|
||||||
private ArrayList<T> list;
|
private ArrayList<T> list;
|
||||||
|
|
||||||
RefSortingSink(Sink<T> sink, Comparator<? super T> comparator) {
|
RefSortingSink(Sink<? super T> sink, Comparator<? super T> comparator) {
|
||||||
super(sink);
|
super(sink);
|
||||||
this.comparator = comparator;
|
this.comparator = comparator;
|
||||||
}
|
}
|
||||||
@ -352,11 +352,11 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on SIZED int streams.
|
* {@link Sink} for implementing sort on SIZED int streams.
|
||||||
*/
|
*/
|
||||||
private static final class SizedIntSortingSink extends Sink.ChainedInt {
|
private static final class SizedIntSortingSink extends Sink.ChainedInt<Integer> {
|
||||||
private int[] array;
|
private int[] array;
|
||||||
private int offset;
|
private int offset;
|
||||||
|
|
||||||
SizedIntSortingSink(Sink downstream) {
|
SizedIntSortingSink(Sink<? super Integer> downstream) {
|
||||||
super(downstream);
|
super(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,10 +386,10 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on int streams.
|
* {@link Sink} for implementing sort on int streams.
|
||||||
*/
|
*/
|
||||||
private static final class IntSortingSink extends Sink.ChainedInt {
|
private static final class IntSortingSink extends Sink.ChainedInt<Integer> {
|
||||||
private SpinedBuffer.OfInt b;
|
private SpinedBuffer.OfInt b;
|
||||||
|
|
||||||
IntSortingSink(Sink sink) {
|
IntSortingSink(Sink<? super Integer> sink) {
|
||||||
super(sink);
|
super(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,11 +417,11 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on SIZED long streams.
|
* {@link Sink} for implementing sort on SIZED long streams.
|
||||||
*/
|
*/
|
||||||
private static final class SizedLongSortingSink extends Sink.ChainedLong {
|
private static final class SizedLongSortingSink extends Sink.ChainedLong<Long> {
|
||||||
private long[] array;
|
private long[] array;
|
||||||
private int offset;
|
private int offset;
|
||||||
|
|
||||||
SizedLongSortingSink(Sink downstream) {
|
SizedLongSortingSink(Sink<? super Long> downstream) {
|
||||||
super(downstream);
|
super(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,10 +451,10 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on long streams.
|
* {@link Sink} for implementing sort on long streams.
|
||||||
*/
|
*/
|
||||||
private static final class LongSortingSink extends Sink.ChainedLong {
|
private static final class LongSortingSink extends Sink.ChainedLong<Long> {
|
||||||
private SpinedBuffer.OfLong b;
|
private SpinedBuffer.OfLong b;
|
||||||
|
|
||||||
LongSortingSink(Sink sink) {
|
LongSortingSink(Sink<? super Long> sink) {
|
||||||
super(sink);
|
super(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,11 +482,11 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on SIZED double streams.
|
* {@link Sink} for implementing sort on SIZED double streams.
|
||||||
*/
|
*/
|
||||||
private static final class SizedDoubleSortingSink extends Sink.ChainedDouble {
|
private static final class SizedDoubleSortingSink extends Sink.ChainedDouble<Double> {
|
||||||
private double[] array;
|
private double[] array;
|
||||||
private int offset;
|
private int offset;
|
||||||
|
|
||||||
SizedDoubleSortingSink(Sink downstream) {
|
SizedDoubleSortingSink(Sink<? super Double> downstream) {
|
||||||
super(downstream);
|
super(downstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,10 +516,10 @@ final class SortedOps {
|
|||||||
/**
|
/**
|
||||||
* {@link Sink} for implementing sort on double streams.
|
* {@link Sink} for implementing sort on double streams.
|
||||||
*/
|
*/
|
||||||
private static final class DoubleSortingSink extends Sink.ChainedDouble {
|
private static final class DoubleSortingSink extends Sink.ChainedDouble<Double> {
|
||||||
private SpinedBuffer.OfDouble b;
|
private SpinedBuffer.OfDouble b;
|
||||||
|
|
||||||
DoubleSortingSink(Sink sink) {
|
DoubleSortingSink(Sink<? super Double> sink) {
|
||||||
super(sink);
|
super(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,6 +663,9 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
|
|||||||
while (off + 4 <= len) {
|
while (off + 4 <= len) {
|
||||||
int tag = get16(extra, off);
|
int tag = get16(extra, off);
|
||||||
int sz = get16(extra, off + 2);
|
int sz = get16(extra, off + 2);
|
||||||
|
if (sz < 0 || (off + 4 + sz) > len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (tag == EXTID_EXTT || tag == EXTID_ZIP64) {
|
if (tag == EXTID_EXTT || tag == EXTID_ZIP64) {
|
||||||
skipped += (sz + 4);
|
skipped += (sz + 4);
|
||||||
}
|
}
|
||||||
@ -684,11 +687,18 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
|
|||||||
while (off + 4 <= len) {
|
while (off + 4 <= len) {
|
||||||
int tag = get16(extra, off);
|
int tag = get16(extra, off);
|
||||||
int sz = get16(extra, off + 2);
|
int sz = get16(extra, off + 2);
|
||||||
|
if (sz < 0 || (off + 4 + sz) > len) {
|
||||||
|
writeBytes(extra, off, len - off);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (tag != EXTID_EXTT && tag != EXTID_ZIP64) {
|
if (tag != EXTID_EXTT && tag != EXTID_ZIP64) {
|
||||||
writeBytes(extra, off, sz + 4);
|
writeBytes(extra, off, sz + 4);
|
||||||
}
|
}
|
||||||
off += (sz + 4);
|
off += (sz + 4);
|
||||||
}
|
}
|
||||||
|
if (off < len) {
|
||||||
|
writeBytes(extra, off, len - off);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -293,6 +293,7 @@ public final class SNIHostName extends SNIServerName {
|
|||||||
* the <a href="{@docRoot}/java/util/regex/Pattern.html#sum">
|
* the <a href="{@docRoot}/java/util/regex/Pattern.html#sum">
|
||||||
* regular expression pattern</a>
|
* regular expression pattern</a>
|
||||||
* representing the hostname(s) to match
|
* representing the hostname(s) to match
|
||||||
|
* @return a {@code SNIMatcher} object for {@code SNIHostName}s
|
||||||
* @throws NullPointerException if {@code regex} is
|
* @throws NullPointerException if {@code regex} is
|
||||||
* {@code null}
|
* {@code null}
|
||||||
* @throws java.util.regex.PatternSyntaxException if the regular expression's
|
* @throws java.util.regex.PatternSyntaxException if the regular expression's
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -40,7 +40,7 @@ import java.net.Socket;
|
|||||||
* <UL>
|
* <UL>
|
||||||
* <LI> determine the set of aliases that are available for negotiations
|
* <LI> determine the set of aliases that are available for negotiations
|
||||||
* based on the criteria presented,
|
* based on the criteria presented,
|
||||||
* <LI> select the <ITALIC> best alias </ITALIC> based on
|
* <LI> select the <i> best alias</i> based on
|
||||||
* the criteria presented, and
|
* the criteria presented, and
|
||||||
* <LI> obtain the corresponding key material for given aliases.
|
* <LI> obtain the corresponding key material for given aliases.
|
||||||
* </UL>
|
* </UL>
|
||||||
|
@ -197,8 +197,7 @@ public final class KerberosPrincipal
|
|||||||
* {@code KerberosPrincipal} and the two
|
* {@code KerberosPrincipal} and the two
|
||||||
* {@code KerberosPrincipal} instances are equivalent.
|
* {@code KerberosPrincipal} instances are equivalent.
|
||||||
* More formally two {@code KerberosPrincipal} instances are equal
|
* More formally two {@code KerberosPrincipal} instances are equal
|
||||||
* if the values returned by {@code getName()} are equal and the
|
* if the values returned by {@code getName()} are equal.
|
||||||
* values returned by {@code getNameType()} are equal.
|
|
||||||
*
|
*
|
||||||
* @param other the Object to compare to
|
* @param other the Object to compare to
|
||||||
* @return true if the Object passed in represents the same principal
|
* @return true if the Object passed in represents the same principal
|
||||||
@ -211,15 +210,10 @@ public final class KerberosPrincipal
|
|||||||
|
|
||||||
if (! (other instanceof KerberosPrincipal)) {
|
if (! (other instanceof KerberosPrincipal)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
String myFullName = getName();
|
String myFullName = getName();
|
||||||
String otherFullName = ((KerberosPrincipal) other).getName();
|
String otherFullName = ((KerberosPrincipal) other).getName();
|
||||||
if (nameType == ((KerberosPrincipal)other).nameType &&
|
return myFullName.equals(otherFullName);
|
||||||
myFullName.equals(otherFullName)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1996, 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. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort: a class that uses the quicksort algorithm to sort an
|
|
||||||
* array of objects.
|
|
||||||
*
|
|
||||||
* @author Sunita Mani
|
|
||||||
*/
|
|
||||||
|
|
||||||
package sun.misc;
|
|
||||||
|
|
||||||
public class Sort {
|
|
||||||
|
|
||||||
private static void swap(Object arr[], int i, int j) {
|
|
||||||
Object tmp;
|
|
||||||
|
|
||||||
tmp = arr[i];
|
|
||||||
arr[i] = arr[j];
|
|
||||||
arr[j] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* quicksort the array of objects.
|
|
||||||
*
|
|
||||||
* @param arr[] - an array of objects
|
|
||||||
* @param left - the start index - from where to begin sorting
|
|
||||||
* @param right - the last index.
|
|
||||||
* @param comp - an object that implemnts the Compare interface to resolve thecomparison.
|
|
||||||
*/
|
|
||||||
public static void quicksort(Object arr[], int left, int right, Compare comp) {
|
|
||||||
int i, last;
|
|
||||||
|
|
||||||
if (left >= right) { /* do nothing if array contains fewer than two */
|
|
||||||
return; /* two elements */
|
|
||||||
}
|
|
||||||
swap(arr, left, (left+right) / 2);
|
|
||||||
last = left;
|
|
||||||
for (i = left+1; i <= right; i++) {
|
|
||||||
if (comp.doCompare(arr[i], arr[left]) < 0) {
|
|
||||||
swap(arr, ++last, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
swap(arr, left, last);
|
|
||||||
quicksort(arr, left, last-1, comp);
|
|
||||||
quicksort(arr, last+1, right, comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void quicksort(Object arr[], Compare comp) {
|
|
||||||
quicksort(arr, 0, arr.length-1, comp);
|
|
||||||
}
|
|
||||||
}
|
|
@ -193,9 +193,4 @@ abstract class AbstractPollSelectorImpl
|
|||||||
if (!selch.isOpen() && !selch.isRegistered())
|
if (!selch.isOpen() && !selch.isRegistered())
|
||||||
((SelChImpl)selch).kill();
|
((SelChImpl)selch).kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
Util.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1138,7 +1138,7 @@ class DatagramChannelImpl
|
|||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1162,7 +1162,7 @@ public class FileChannelImpl
|
|||||||
private static native long initIDs();
|
private static native long initIDs();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
allocationGranularity = initIDs();
|
allocationGranularity = initIDs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,9 +347,23 @@ public class IOUtil {
|
|||||||
|
|
||||||
static native void initIDs();
|
static native void initIDs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to trigger loading of native libraries
|
||||||
|
*/
|
||||||
|
public static void load() { }
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Note that IOUtil.initIDs is called from within Util.load.
|
java.security.AccessController.doPrivileged(
|
||||||
Util.load();
|
new java.security.PrivilegedAction<Void>() {
|
||||||
|
public Void run() {
|
||||||
|
System.loadLibrary("net");
|
||||||
|
System.loadLibrary("nio");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
initIDs();
|
||||||
|
|
||||||
IOV_MAX = iovMax();
|
IOV_MAX = iovMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ public class Net {
|
|||||||
private static native void initIDs();
|
private static native void initIDs();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ class ServerSocketChannelImpl
|
|||||||
private static native void initIDs();
|
private static native void initIDs();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
nd = new SocketDispatcher();
|
nd = new SocketDispatcher();
|
||||||
}
|
}
|
||||||
|
@ -1024,7 +1024,7 @@ class SocketChannelImpl
|
|||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
nd = new SocketDispatcher();
|
nd = new SocketDispatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,30 +401,4 @@ public class Util {
|
|||||||
return bugLevel.equals(bl);
|
return bugLevel.equals(bl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -- Initialization --
|
|
||||||
|
|
||||||
private static boolean loaded = false;
|
|
||||||
|
|
||||||
public static void load() {
|
|
||||||
synchronized (Util.class) {
|
|
||||||
if (loaded)
|
|
||||||
return;
|
|
||||||
loaded = true;
|
|
||||||
java.security.AccessController.doPrivileged(
|
|
||||||
new java.security.PrivilegedAction<Void>() {
|
|
||||||
public Void run() {
|
|
||||||
System.loadLibrary("net");
|
|
||||||
System.loadLibrary("nio");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// IOUtil must be initialized; Its native methods are called from
|
|
||||||
// other places in native nio code so they must be set up.
|
|
||||||
IOUtil.initIDs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -268,8 +268,13 @@ public class ConnectDialog extends InternalDialog
|
|||||||
|
|
||||||
public void revalidate() {
|
public void revalidate() {
|
||||||
// Adjust some colors
|
// Adjust some colors
|
||||||
|
Color disabledForeground = UIManager.getColor("Label.disabledForeground");
|
||||||
|
if (disabledForeground == null) {
|
||||||
|
// fall back for Nimbus that doesn't support 'Label.disabledForeground'
|
||||||
|
disabledForeground = UIManager.getColor("Label.disabledText");
|
||||||
|
}
|
||||||
hintTextColor =
|
hintTextColor =
|
||||||
ensureContrast(UIManager.getColor("Label.disabledForeground"),
|
ensureContrast(disabledForeground,
|
||||||
UIManager.getColor("Panel.background"));
|
UIManager.getColor("Panel.background"));
|
||||||
disabledTableCellColor =
|
disabledTableCellColor =
|
||||||
ensureContrast(new Color(0x808080),
|
ensureContrast(new Color(0x808080),
|
||||||
|
@ -858,6 +858,10 @@ public class JConsole extends JFrame
|
|||||||
try {
|
try {
|
||||||
updateInterval = Integer.parseInt(arg.substring(10)) *
|
updateInterval = Integer.parseInt(arg.substring(10)) *
|
||||||
1000;
|
1000;
|
||||||
|
if (updateInterval <= 0) {
|
||||||
|
usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
usage();
|
usage();
|
||||||
return;
|
return;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -146,7 +146,6 @@ final public class Messages {
|
|||||||
public static String HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME;
|
public static String HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME;
|
||||||
public static String HELP_ABOUT_DIALOG_MASTHEAD_TITLE;
|
public static String HELP_ABOUT_DIALOG_MASTHEAD_TITLE;
|
||||||
public static String HELP_ABOUT_DIALOG_TITLE;
|
public static String HELP_ABOUT_DIALOG_TITLE;
|
||||||
public static String HELP_ABOUT_DIALOG_USER_GUIDE_LINK;
|
|
||||||
public static String HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL;
|
public static String HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL;
|
||||||
public static String HELP_MENU_ABOUT_TITLE;
|
public static String HELP_MENU_ABOUT_TITLE;
|
||||||
public static String HELP_MENU_USER_GUIDE_TITLE;
|
public static String HELP_MENU_USER_GUIDE_TITLE;
|
||||||
@ -272,6 +271,7 @@ final public class Messages {
|
|||||||
public static String THREADS;
|
public static String THREADS;
|
||||||
public static String THREAD_TAB_THREAD_INFO_ACCESSIBLE_NAME;
|
public static String THREAD_TAB_THREAD_INFO_ACCESSIBLE_NAME;
|
||||||
public static String THREAD_TAB_THREAD_PLOTTER_ACCESSIBLE_NAME;
|
public static String THREAD_TAB_THREAD_PLOTTER_ACCESSIBLE_NAME;
|
||||||
|
public static String THREAD_TAB_INITIAL_STACK_TRACE_MESSAGE;
|
||||||
public static String THRESHOLD;
|
public static String THRESHOLD;
|
||||||
public static String TILE;
|
public static String TILE;
|
||||||
public static String TIME_RANGE_COLON;
|
public static String TIME_RANGE_COLON;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -337,6 +337,13 @@ public class Plotter extends JComponent
|
|||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
|
int width = getWidth()-rightMargin-leftMargin-10;
|
||||||
|
int height = getHeight()-topMargin-bottomMargin;
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
// not enough room to paint anything
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Color oldColor = g.getColor();
|
Color oldColor = g.getColor();
|
||||||
Font oldFont = g.getFont();
|
Font oldFont = g.getFont();
|
||||||
Color fg = getForeground();
|
Color fg = getForeground();
|
||||||
|
@ -595,6 +595,8 @@ class ThreadTab extends Tab implements ActionListener, DocumentListener, ListSel
|
|||||||
|
|
||||||
setBorder(thinEmptyBorder);
|
setBorder(thinEmptyBorder);
|
||||||
|
|
||||||
|
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
textArea.setText(Messages.THREAD_TAB_INITIAL_STACK_TRACE_MESSAGE);
|
||||||
addListSelectionListener(ThreadTab.this);
|
addListSelectionListener(ThreadTab.this);
|
||||||
setCellRenderer(new DefaultListCellRenderer() {
|
setCellRenderer(new DefaultListCellRenderer() {
|
||||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
|
||||||
|
@ -153,9 +153,11 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
|
|||||||
// in order to reserve space for the connect toggle.
|
// in order to reserve space for the connect toggle.
|
||||||
public void setUI(TabbedPaneUI ui) {
|
public void setUI(TabbedPaneUI ui) {
|
||||||
Insets insets = (Insets) UIManager.getLookAndFeelDefaults().get("TabbedPane.tabAreaInsets");
|
Insets insets = (Insets) UIManager.getLookAndFeelDefaults().get("TabbedPane.tabAreaInsets");
|
||||||
|
if (insets != null) {
|
||||||
insets = (Insets) insets.clone();
|
insets = (Insets) insets.clone();
|
||||||
insets.right += connectedIcon24.getIconWidth() + 8;
|
insets.right += connectedIcon24.getIconWidth() + 8;
|
||||||
UIManager.put("TabbedPane.tabAreaInsets", insets);
|
UIManager.put("TabbedPane.tabAreaInsets", insets);
|
||||||
|
}
|
||||||
super.setUI(ui);
|
super.setUI(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,6 @@ HELP_ABOUT_DIALOG_JAVA_VERSION=Java VM version:<br>{0}
|
|||||||
HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME=Masthead Graphic
|
HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME=Masthead Graphic
|
||||||
HELP_ABOUT_DIALOG_MASTHEAD_TITLE=About JConsole
|
HELP_ABOUT_DIALOG_MASTHEAD_TITLE=About JConsole
|
||||||
HELP_ABOUT_DIALOG_TITLE=JConsole: About
|
HELP_ABOUT_DIALOG_TITLE=JConsole: About
|
||||||
HELP_ABOUT_DIALOG_USER_GUIDE_LINK=JConsole &User Guide:<br>{0}
|
|
||||||
HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL=http://docs.oracle.com/javase/{0}/docs/technotes/guides/management/jconsole.html
|
HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL=http://docs.oracle.com/javase/{0}/docs/technotes/guides/management/jconsole.html
|
||||||
HELP_MENU_ABOUT_TITLE=&About JConsole
|
HELP_MENU_ABOUT_TITLE=&About JConsole
|
||||||
HELP_MENU_USER_GUIDE_TITLE=Online &User Guide
|
HELP_MENU_USER_GUIDE_TITLE=Online &User Guide
|
||||||
@ -230,6 +229,7 @@ SUMMARY_TAB_VM_VERSION={0} version {1}
|
|||||||
THREADS=Threads
|
THREADS=Threads
|
||||||
THREAD_TAB_THREAD_INFO_ACCESSIBLE_NAME=Thread Information
|
THREAD_TAB_THREAD_INFO_ACCESSIBLE_NAME=Thread Information
|
||||||
THREAD_TAB_THREAD_PLOTTER_ACCESSIBLE_NAME=Chart for number of threads.
|
THREAD_TAB_THREAD_PLOTTER_ACCESSIBLE_NAME=Chart for number of threads.
|
||||||
|
THREAD_TAB_INITIAL_STACK_TRACE_MESSAGE=[No thread selected]
|
||||||
THRESHOLD=Threshold
|
THRESHOLD=Threshold
|
||||||
TILE=&Tile
|
TILE=&Tile
|
||||||
TIME_RANGE_COLON=&Time Range:
|
TIME_RANGE_COLON=&Time Range:
|
||||||
|
@ -104,7 +104,6 @@ HELP_ABOUT_DIALOG_JAVA_VERSION=Java VM\u30D0\u30FC\u30B8\u30E7\u30F3:<br>{0}
|
|||||||
HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME=\u30DE\u30B9\u30C8\u30D8\u30C3\u30C9\u56F3\u5F62
|
HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME=\u30DE\u30B9\u30C8\u30D8\u30C3\u30C9\u56F3\u5F62
|
||||||
HELP_ABOUT_DIALOG_MASTHEAD_TITLE=JConsole\u306B\u3064\u3044\u3066
|
HELP_ABOUT_DIALOG_MASTHEAD_TITLE=JConsole\u306B\u3064\u3044\u3066
|
||||||
HELP_ABOUT_DIALOG_TITLE=JConsole: \u8A73\u7D30
|
HELP_ABOUT_DIALOG_TITLE=JConsole: \u8A73\u7D30
|
||||||
HELP_ABOUT_DIALOG_USER_GUIDE_LINK=JConsole\u30E6\u30FC\u30B6\u30FC\u30FB\u30AC\u30A4\u30C9(&U):<br>{0}
|
|
||||||
HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL=http://docs.oracle.com/javase/{0}/docs/technotes/guides/management/jconsole.html
|
HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL=http://docs.oracle.com/javase/{0}/docs/technotes/guides/management/jconsole.html
|
||||||
HELP_MENU_ABOUT_TITLE=JConsole\u306B\u3064\u3044\u3066(&A)
|
HELP_MENU_ABOUT_TITLE=JConsole\u306B\u3064\u3044\u3066(&A)
|
||||||
HELP_MENU_USER_GUIDE_TITLE=\u30AA\u30F3\u30E9\u30A4\u30F3\u30FB\u30E6\u30FC\u30B6\u30FC\u30FB\u30AC\u30A4\u30C9(&U)
|
HELP_MENU_USER_GUIDE_TITLE=\u30AA\u30F3\u30E9\u30A4\u30F3\u30FB\u30E6\u30FC\u30B6\u30FC\u30FB\u30AC\u30A4\u30C9(&U)
|
||||||
|
@ -104,7 +104,6 @@ HELP_ABOUT_DIALOG_JAVA_VERSION=Java VM \u7248\u672C:<br>{0}
|
|||||||
HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME=\u62A5\u5934\u56FE
|
HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME=\u62A5\u5934\u56FE
|
||||||
HELP_ABOUT_DIALOG_MASTHEAD_TITLE=\u5173\u4E8E JConsole
|
HELP_ABOUT_DIALOG_MASTHEAD_TITLE=\u5173\u4E8E JConsole
|
||||||
HELP_ABOUT_DIALOG_TITLE=JConsole: \u5173\u4E8E
|
HELP_ABOUT_DIALOG_TITLE=JConsole: \u5173\u4E8E
|
||||||
HELP_ABOUT_DIALOG_USER_GUIDE_LINK=JConsole \u7528\u6237\u6307\u5357(&U):<br>{0}
|
|
||||||
HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL=http://docs.oracle.com/javase/{0}/docs/technotes/guides/management/jconsole.html
|
HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL=http://docs.oracle.com/javase/{0}/docs/technotes/guides/management/jconsole.html
|
||||||
HELP_MENU_ABOUT_TITLE=\u5173\u4E8E JConsole(&A)
|
HELP_MENU_ABOUT_TITLE=\u5173\u4E8E JConsole(&A)
|
||||||
HELP_MENU_USER_GUIDE_TITLE=\u8054\u673A\u7528\u6237\u6307\u5357(&U)
|
HELP_MENU_USER_GUIDE_TITLE=\u8054\u673A\u7528\u6237\u6307\u5357(&U)
|
||||||
|
@ -181,6 +181,7 @@ package.access=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
@ -225,6 +226,7 @@ package.definition=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
|
@ -182,6 +182,7 @@ package.access=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
@ -226,6 +227,7 @@ package.definition=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
|
@ -183,6 +183,7 @@ package.access=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
@ -226,6 +227,7 @@ package.definition=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
|
@ -182,6 +182,7 @@ package.access=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
@ -226,6 +227,7 @@ package.definition=sun.,\
|
|||||||
com.sun.imageio.,\
|
com.sun.imageio.,\
|
||||||
com.sun.istack.internal.,\
|
com.sun.istack.internal.,\
|
||||||
com.sun.jmx.,\
|
com.sun.jmx.,\
|
||||||
|
com.sun.media.sound.,\
|
||||||
com.sun.proxy.,\
|
com.sun.proxy.,\
|
||||||
com.sun.org.apache.bcel.internal.,\
|
com.sun.org.apache.bcel.internal.,\
|
||||||
com.sun.org.apache.regexp.internal.,\
|
com.sun.org.apache.regexp.internal.,\
|
||||||
|
@ -90,6 +90,12 @@
|
|||||||
#include "classfile_constants.h"
|
#include "classfile_constants.h"
|
||||||
#include "opcodes.in_out"
|
#include "opcodes.in_out"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
/* use setjmp/longjmp versions that do not save/restore the signal mask */
|
||||||
|
#define setjmp _setjmp
|
||||||
|
#define longjmp _longjmp
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_ARRAY_DIMENSIONS 255
|
#define MAX_ARRAY_DIMENSIONS 255
|
||||||
/* align byte code */
|
/* align byte code */
|
||||||
#ifndef ALIGN_UP
|
#ifndef ALIGN_UP
|
||||||
|
@ -36,7 +36,7 @@ import java.net.*;
|
|||||||
class DatagramDispatcher extends NativeDispatcher
|
class DatagramDispatcher extends NativeDispatcher
|
||||||
{
|
{
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int read(FileDescriptor fd, long address, int len) throws IOException {
|
int read(FileDescriptor fd, long address, int len) throws IOException {
|
||||||
|
@ -316,4 +316,8 @@ class DevPollArrayWrapper {
|
|||||||
private native int poll0(long pollAddress, int numfds, long timeout,
|
private native int poll0(long pollAddress, int numfds, long timeout,
|
||||||
int wfd);
|
int wfd);
|
||||||
private static native void interrupt(int fd);
|
private static native void interrupt(int fd);
|
||||||
|
|
||||||
|
static {
|
||||||
|
IOUtil.load();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,9 +196,4 @@ class DevPollSelectorImpl
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
Util.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,6 @@ class EPoll {
|
|||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,6 +318,7 @@ class EPollArrayWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
IOUtil.load();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +318,6 @@ final class EPollPort
|
|||||||
private static native void close0(int fd);
|
private static native void close0(int fd);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,8 +196,4 @@ class EPollSelectorImpl
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
Util.load();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class FileDispatcherImpl extends FileDispatcher
|
|||||||
{
|
{
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,6 @@ class InheritedChannel {
|
|||||||
private static native int peerPort0(int fd);
|
private static native int peerPort0(int fd);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,6 @@ class KQueue {
|
|||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,6 +326,6 @@ final class KQueuePort
|
|||||||
private static native void close0(int fd);
|
private static native void close0(int fd);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class NativeThread {
|
|||||||
private static native void init();
|
private static native void init();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,4 +126,7 @@ public class PollArrayWrapper extends AbstractPollArrayWrapper {
|
|||||||
|
|
||||||
private static native void interrupt(int fd);
|
private static native void interrupt(int fd);
|
||||||
|
|
||||||
|
static {
|
||||||
|
IOUtil.load();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class SinkChannelImpl
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Used to make native read and write calls
|
// Used to make native read and write calls
|
||||||
private static NativeDispatcher nd;
|
private static final NativeDispatcher nd = new FileDispatcherImpl();
|
||||||
|
|
||||||
// The file descriptor associated with this channel
|
// The file descriptor associated with this channel
|
||||||
FileDescriptor fd;
|
FileDescriptor fd;
|
||||||
@ -206,10 +206,4 @@ class SinkChannelImpl
|
|||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
return write(Util.subsequence(srcs, offset, length));
|
return write(Util.subsequence(srcs, offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
Util.load();
|
|
||||||
nd = new FileDispatcherImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -260,6 +260,6 @@ class SolarisEventPort
|
|||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class SourceChannelImpl
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Used to make native read and write calls
|
// Used to make native read and write calls
|
||||||
private static NativeDispatcher nd;
|
private static final NativeDispatcher nd = new FileDispatcherImpl();
|
||||||
|
|
||||||
// The file descriptor associated with this channel
|
// The file descriptor associated with this channel
|
||||||
FileDescriptor fd;
|
FileDescriptor fd;
|
||||||
@ -206,10 +206,4 @@ class SourceChannelImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
Util.load();
|
|
||||||
nd = new FileDispatcherImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ class UnixAsynchronousServerSocketChannelImpl
|
|||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -748,6 +748,6 @@ class UnixAsynchronousSocketChannelImpl
|
|||||||
private static native void checkConnect(int fdVal) throws IOException;
|
private static native void checkConnect(int fdVal) throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1106,7 +1106,7 @@ public class SctpChannelImpl extends SctpChannel
|
|||||||
boolean ready) throws IOException;
|
boolean ready) throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load(); /* loads nio & net native libraries */
|
IOUtil.load(); /* loads nio & net native libraries */
|
||||||
java.security.AccessController.doPrivileged(
|
java.security.AccessController.doPrivileged(
|
||||||
new java.security.PrivilegedAction<Void>() {
|
new java.security.PrivilegedAction<Void>() {
|
||||||
public Void run() {
|
public Void run() {
|
||||||
|
@ -995,7 +995,7 @@ public class SctpMultiChannelImpl extends SctpMultiChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load(); /* loads nio & net native libraries */
|
IOUtil.load(); /* loads nio & net native libraries */
|
||||||
java.security.AccessController.doPrivileged(
|
java.security.AccessController.doPrivileged(
|
||||||
new java.security.PrivilegedAction<Void>() {
|
new java.security.PrivilegedAction<Void>() {
|
||||||
public Void run() {
|
public Void run() {
|
||||||
|
@ -426,7 +426,7 @@ public class SctpServerChannelImpl extends SctpServerChannel
|
|||||||
FileDescriptor newfd, InetSocketAddress[] isaa) throws IOException;
|
FileDescriptor newfd, InetSocketAddress[] isaa) throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load(); // loads nio & net native libraries
|
IOUtil.load(); // loads nio & net native libraries
|
||||||
java.security.AccessController.doPrivileged(
|
java.security.AccessController.doPrivileged(
|
||||||
new java.security.PrivilegedAction<Void>() {
|
new java.security.PrivilegedAction<Void>() {
|
||||||
public Void run() {
|
public Void run() {
|
||||||
|
@ -36,7 +36,7 @@ import java.net.*;
|
|||||||
class DatagramDispatcher extends NativeDispatcher
|
class DatagramDispatcher extends NativeDispatcher
|
||||||
{
|
{
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int read(FileDescriptor fd, long address, int len) throws IOException {
|
int read(FileDescriptor fd, long address, int len) throws IOException {
|
||||||
|
@ -32,7 +32,7 @@ import sun.misc.JavaIOFileDescriptorAccess;
|
|||||||
class FileDispatcherImpl extends FileDispatcher
|
class FileDispatcherImpl extends FileDispatcher
|
||||||
{
|
{
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +73,7 @@ public class FileKey {
|
|||||||
private static native void initIDs();
|
private static native void initIDs();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ class Iocp extends AsynchronousChannelGroupImpl {
|
|||||||
private static native String getErrorMessage(int error);
|
private static native String getErrorMessage(int error);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
|
|
||||||
// thread agnostic I/O on Vista/2008 or newer
|
// thread agnostic I/O on Vista/2008 or newer
|
||||||
|
@ -56,7 +56,6 @@ class PipeImpl
|
|||||||
private static final Random rnd;
|
private static final Random rnd;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
|
||||||
byte[] someBytes = new byte[8];
|
byte[] someBytes = new byte[8];
|
||||||
boolean resultOK = IOUtil.randomBytes(someBytes);
|
boolean resultOK = IOUtil.randomBytes(someBytes);
|
||||||
if (resultOK) {
|
if (resultOK) {
|
||||||
|
@ -36,7 +36,7 @@ class SocketDispatcher extends NativeDispatcher
|
|||||||
{
|
{
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int read(FileDescriptor fd, long address, int len) throws IOException {
|
int read(FileDescriptor fd, long address, int len) throws IOException {
|
||||||
|
@ -750,6 +750,6 @@ public class WindowsAsynchronousFileChannelImpl
|
|||||||
private static native void close0(long handle);
|
private static native void close0(long handle);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ class WindowsAsynchronousServerSocketChannelImpl
|
|||||||
private static native void closesocket0(long socket) throws IOException;
|
private static native void closesocket0(long socket) throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -919,7 +919,7 @@ class WindowsAsynchronousSocketChannelImpl
|
|||||||
private static native void closesocket0(long socket) throws IOException;
|
private static native void closesocket0(long socket) throws IOException;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
initIDs();
|
initIDs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -611,6 +611,6 @@ final class WindowsSelectorImpl extends SelectorImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Util.load();
|
IOUtil.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ sun/net/www/http/HttpClient/ProxyTest.java generic-all
|
|||||||
# jdk_io
|
# jdk_io
|
||||||
|
|
||||||
# 7160013
|
# 7160013
|
||||||
java/io/File/MaxPathLength.java windows-all
|
#java/io/File/MaxPathLength.java windows-all
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
@ -336,12 +336,6 @@ com/sun/jdi/SuspendThreadTest.java generic-all
|
|||||||
# Filed 6653793
|
# Filed 6653793
|
||||||
com/sun/jdi/RedefineCrossEvent.java generic-all
|
com/sun/jdi/RedefineCrossEvent.java generic-all
|
||||||
|
|
||||||
# Filed 6987312
|
|
||||||
com/sun/jdi/DoubleAgentTest.java generic-all
|
|
||||||
|
|
||||||
# Filed 7020857
|
|
||||||
com/sun/jdi/FieldWatchpoints.java generic-all
|
|
||||||
|
|
||||||
# Filed 6402201
|
# Filed 6402201
|
||||||
com/sun/jdi/ProcessAttachTest.sh generic-all
|
com/sun/jdi/ProcessAttachTest.sh generic-all
|
||||||
|
|
||||||
|
@ -9,3 +9,6 @@ othervm.dirs=java/awt java/beans java/rmi javax/accessibility javax/imageio java
|
|||||||
|
|
||||||
# Tests that cannot run concurrently
|
# Tests that cannot run concurrently
|
||||||
exclusiveAccess.dirs=java/rmi/Naming java/util/Currency java/util/prefs sun/management/jmxremote sun/tools/jstatd sun/security/mscapi
|
exclusiveAccess.dirs=java/rmi/Naming java/util/Currency java/util/prefs sun/management/jmxremote sun/tools/jstatd sun/security/mscapi
|
||||||
|
|
||||||
|
# Group definitions
|
||||||
|
groups=TEST.groups [closed/TEST.groups]
|
||||||
|
214
jdk/test/TEST.groups
Normal file
214
jdk/test/TEST.groups
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
# Copyright (c) 2013, 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
jdk_lang = \
|
||||||
|
java/lang \
|
||||||
|
-java/lang/management \
|
||||||
|
-java/lang/instrument \
|
||||||
|
sun/invoke \
|
||||||
|
sun/misc \
|
||||||
|
sun/reflect \
|
||||||
|
vm
|
||||||
|
|
||||||
|
jdk_util = \
|
||||||
|
java/util \
|
||||||
|
sun/util
|
||||||
|
|
||||||
|
jdk_math = \
|
||||||
|
java/math
|
||||||
|
|
||||||
|
jdk_io = \
|
||||||
|
java/io
|
||||||
|
|
||||||
|
jdk_nio = \
|
||||||
|
java/nio \
|
||||||
|
sun/nio
|
||||||
|
|
||||||
|
jdk_net = \
|
||||||
|
java/net \
|
||||||
|
com/sun/net \
|
||||||
|
com/oracle/net \
|
||||||
|
sun/net
|
||||||
|
|
||||||
|
jdk_time = \
|
||||||
|
java/time
|
||||||
|
|
||||||
|
jdk_rmi = \
|
||||||
|
java/rmi \
|
||||||
|
javax/rmi/ssl \
|
||||||
|
sun/rmi
|
||||||
|
|
||||||
|
jdk_security1 = \
|
||||||
|
java/security
|
||||||
|
|
||||||
|
jdk_security2 = \
|
||||||
|
javax/crypto \
|
||||||
|
javax/xml/crypto \
|
||||||
|
com/sun/crypto
|
||||||
|
|
||||||
|
jdk_security3 = \
|
||||||
|
javax/security \
|
||||||
|
com/sun/security \
|
||||||
|
com/sun/org/apache/xml/internal/security \
|
||||||
|
com/oracle/security \
|
||||||
|
sun/security \
|
||||||
|
lib/security
|
||||||
|
|
||||||
|
jdk_security = \
|
||||||
|
:jdk_security1 \
|
||||||
|
:jdk_security2 \
|
||||||
|
:jdk_security3
|
||||||
|
|
||||||
|
jdk_text = \
|
||||||
|
java/text \
|
||||||
|
sun/text
|
||||||
|
|
||||||
|
jdk_management = \
|
||||||
|
java/lang/management \
|
||||||
|
com/sun/management \
|
||||||
|
sun/management
|
||||||
|
|
||||||
|
jdk_instrument = \
|
||||||
|
java/lang/instrument
|
||||||
|
|
||||||
|
jdk_jmx = \
|
||||||
|
javax/management \
|
||||||
|
com/sun/jmx
|
||||||
|
|
||||||
|
jdk_jdi = \
|
||||||
|
com/sun/jdi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tool (and tool API) tests are split into core and svc groups
|
||||||
|
#
|
||||||
|
core_tools = \
|
||||||
|
tools \
|
||||||
|
com/sun/tools/extcheck \
|
||||||
|
sun/tools/java \
|
||||||
|
sun/tools/native2ascii \
|
||||||
|
sun/tools/jrunscript
|
||||||
|
|
||||||
|
svc_tools = \
|
||||||
|
com/sun/tools/attach \
|
||||||
|
com/sun/tracing \
|
||||||
|
sun/tools \
|
||||||
|
-sun/tools/java \
|
||||||
|
-sun/tools/native2ascii \
|
||||||
|
-sun/tools/jrunscript \
|
||||||
|
sun/jvmstat \
|
||||||
|
demo/jvmti
|
||||||
|
|
||||||
|
jdk_tools = \
|
||||||
|
:core_tools \
|
||||||
|
:svc_tools
|
||||||
|
|
||||||
|
#
|
||||||
|
# Catch-all for other areas with a small number of tests
|
||||||
|
#
|
||||||
|
jdk_other = \
|
||||||
|
java/sql \
|
||||||
|
javax/sql \
|
||||||
|
javax/naming \
|
||||||
|
javax/script \
|
||||||
|
javax/smartcardio \
|
||||||
|
javax/xml \
|
||||||
|
-javax/xml/crypto \
|
||||||
|
jdk/asm \
|
||||||
|
jdk/lambda \
|
||||||
|
com/sun/jndi \
|
||||||
|
com/sun/corba \
|
||||||
|
lib/testlibrary \
|
||||||
|
demo/zipfs \
|
||||||
|
sample
|
||||||
|
|
||||||
|
#
|
||||||
|
# SCTP is its own group as it is highly sensitive to kernel/network config
|
||||||
|
#
|
||||||
|
jdk_sctp = \
|
||||||
|
com/sun/nio/sctp
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# core group to run all core area tests
|
||||||
|
#
|
||||||
|
jdk_core = \
|
||||||
|
:jdk_lang \
|
||||||
|
:jdk_util \
|
||||||
|
:jdk_math \
|
||||||
|
:jdk_io \
|
||||||
|
:jdk_nio \
|
||||||
|
:jdk_net \
|
||||||
|
:jdk_rmi \
|
||||||
|
:jdk_time \
|
||||||
|
:jdk_security \
|
||||||
|
:jdk_text \
|
||||||
|
:core_tools \
|
||||||
|
:jdk_other
|
||||||
|
|
||||||
|
#
|
||||||
|
# svc group to run all serviceability area tests
|
||||||
|
#
|
||||||
|
jdk_svc = \
|
||||||
|
:jdk_management \
|
||||||
|
:jdk_instrument \
|
||||||
|
:jdk_jmx \
|
||||||
|
:jdk_jdi \
|
||||||
|
:svc_tools
|
||||||
|
|
||||||
|
#############################
|
||||||
|
|
||||||
|
#
|
||||||
|
# Client area groups
|
||||||
|
#
|
||||||
|
|
||||||
|
jdk_awt = \
|
||||||
|
java/awt \
|
||||||
|
com/sun/awt \
|
||||||
|
com/apple/eawt \
|
||||||
|
sun/awt
|
||||||
|
|
||||||
|
jdk_2d = \
|
||||||
|
javax/print \
|
||||||
|
sun/pisces \
|
||||||
|
sun/java2d
|
||||||
|
|
||||||
|
jdk_beans = \
|
||||||
|
java/beans
|
||||||
|
|
||||||
|
jdk_swing = \
|
||||||
|
javax/accessibility \
|
||||||
|
javax/swing \
|
||||||
|
com/sun/java/swing
|
||||||
|
|
||||||
|
jdk_sound = \
|
||||||
|
javax/sound
|
||||||
|
|
||||||
|
jdk_imageio = \
|
||||||
|
javax/imageio
|
||||||
|
|
||||||
|
jdk_desktop = \
|
||||||
|
:jdk_awt \
|
||||||
|
:jdk_2d \
|
||||||
|
:jdk_beans \
|
||||||
|
:jdk_swing \
|
||||||
|
:jdk_sound \
|
||||||
|
:jdk_imageio
|
117
jdk/test/java/io/BufferedInputStream/LargeCopyWithMark.java
Normal file
117
jdk/test/java/io/BufferedInputStream/LargeCopyWithMark.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013, 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
|
||||||
|
* @bug 7129312
|
||||||
|
* @summary BufferedInputStream calculates negative array size with large
|
||||||
|
* streams and mark
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @run main/othervm LargeCopyWithMark
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import static jdk.testlibrary.ProcessTools.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class LargeCopyWithMark {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
if (! System.getProperty("os.arch").contains("64")) {
|
||||||
|
System.out.println("Test runs on 64 bit platforms");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProcessBuilder pb = createJavaProcessBuilder("-Xmx4G",
|
||||||
|
"-ea:LargeCopyWithMark$Child",
|
||||||
|
"LargeCopyWithMark$Child");
|
||||||
|
int res = pb.inheritIO().start().waitFor();
|
||||||
|
if (res != 0) {
|
||||||
|
throw new AssertionError("Test failed: exit code = " + res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Child {
|
||||||
|
static final int BUFF_SIZE = 8192;
|
||||||
|
static final int BIS_BUFF_SIZE = Integer.MAX_VALUE / 2 + 100;
|
||||||
|
static final long BYTES_TO_COPY = 2L * Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
static {
|
||||||
|
assert BIS_BUFF_SIZE * 2 < 0 : "doubling must overflow";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
byte[] buff = new byte[BUFF_SIZE];
|
||||||
|
|
||||||
|
try (InputStream myis = new MyInputStream(BYTES_TO_COPY);
|
||||||
|
InputStream bis = new BufferedInputStream(myis, BIS_BUFF_SIZE);
|
||||||
|
OutputStream myos = new MyOutputStream()) {
|
||||||
|
|
||||||
|
// will require a buffer bigger than BIS_BUFF_SIZE
|
||||||
|
bis.mark(BIS_BUFF_SIZE + 100);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
int count = bis.read(buff, 0, BUFF_SIZE);
|
||||||
|
if (count == -1)
|
||||||
|
break;
|
||||||
|
myos.write(buff, 0, count);
|
||||||
|
}
|
||||||
|
} catch (java.lang.NegativeArraySizeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(11);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyInputStream extends InputStream {
|
||||||
|
private long bytesLeft;
|
||||||
|
public MyInputStream(long bytesLeft) {
|
||||||
|
this.bytesLeft = bytesLeft;
|
||||||
|
}
|
||||||
|
@Override public int read() throws IOException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override public int read(byte[] b) throws IOException {
|
||||||
|
return read(b, 0, b.length);
|
||||||
|
}
|
||||||
|
@Override public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
if (bytesLeft <= 0)
|
||||||
|
return -1;
|
||||||
|
long result = Math.min(bytesLeft, (long)len);
|
||||||
|
bytesLeft -= result;
|
||||||
|
return (int)result;
|
||||||
|
}
|
||||||
|
@Override public int available() throws IOException {
|
||||||
|
return (bytesLeft > 0) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyOutputStream extends OutputStream {
|
||||||
|
@Override public void write(int b) throws IOException {}
|
||||||
|
@Override public void write(byte[] b) throws IOException {}
|
||||||
|
@Override public void write(byte[] b, int off, int len) throws IOException {}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class MaxPathLength {
|
public class MaxPathLength {
|
||||||
private static String sep = File.separator;
|
private static String sep = File.separator;
|
||||||
@ -87,10 +88,8 @@ public class MaxPathLength {
|
|||||||
System.err.println("Warning: Test directory structure exists already!");
|
System.err.println("Warning: Test directory structure exists already!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean couldMakeTestDirectory = dirFile.mkdirs();
|
Files.createDirectories(dirFile.toPath());
|
||||||
if (!couldMakeTestDirectory) {
|
|
||||||
throw new RuntimeException ("Could not create test directory structure");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (tryAbsolute)
|
if (tryAbsolute)
|
||||||
dirFile = new File(dirFile.getCanonicalPath());
|
dirFile = new File(dirFile.getCanonicalPath());
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.nio.file.*;
|
||||||
|
|
||||||
|
|
||||||
public class General {
|
public class General {
|
||||||
@ -57,7 +58,7 @@ public class General {
|
|||||||
for (int i = 0; i < dl.length; i++) {
|
for (int i = 0; i < dl.length; i++) {
|
||||||
File f = new File(subdir, dl[i]);
|
File f = new File(subdir, dl[i]);
|
||||||
File df = new File(dir, f.getPath());
|
File df = new File(dir, f.getPath());
|
||||||
if (df.exists() && df.isFile()) {
|
if (Files.isRegularFile(df.toPath(), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
return f.getPath();
|
return f.getPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +66,7 @@ public class General {
|
|||||||
File f = (subdir.length() == 0) ? new File(dl[i])
|
File f = (subdir.length() == 0) ? new File(dl[i])
|
||||||
: new File(subdir, dl[i]);
|
: new File(subdir, dl[i]);
|
||||||
File df = new File(dir, f.getPath());
|
File df = new File(dir, f.getPath());
|
||||||
if (df.exists() && df.isDirectory()) {
|
if (Files.isDirectory(df.toPath(), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
String[] dl2 = df.list();
|
String[] dl2 = df.list();
|
||||||
if (dl2 != null) {
|
if (dl2 != null) {
|
||||||
String ff = findSomeFile(dir, f.getPath(), dl2);
|
String ff = findSomeFile(dir, f.getPath(), dl2);
|
||||||
@ -90,7 +91,7 @@ public class General {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < dl.length; i++) {
|
for (int i = 0; i < dl.length; i++) {
|
||||||
File f = new File(dir, dl[i]);
|
File f = new File(dir, dl[i]);
|
||||||
if (f.isFile()) {
|
if (Files.isRegularFile(f.toPath(), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
return dl[i];
|
return dl[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ public class General {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < dl.length; i++) {
|
for (int i = 0; i < dl.length; i++) {
|
||||||
File f = new File(d, dl[i]);
|
File f = new File(d, dl[i]);
|
||||||
if (f.isDirectory()) {
|
if (Files.isDirectory(f.toPath(), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
String[] dl2 = f.list();
|
String[] dl2 = f.list();
|
||||||
if (dl2 == null || dl2.length >= 250) {
|
if (dl2 == null || dl2.length >= 250) {
|
||||||
/* Heuristic to avoid scanning huge directories */
|
/* Heuristic to avoid scanning huge directories */
|
||||||
@ -314,7 +315,7 @@ public class General {
|
|||||||
|
|
||||||
/* Normal name */
|
/* Normal name */
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
if (f.isDirectory() && f.list() != null) {
|
if (Files.isDirectory(f.toPath(), LinkOption.NOFOLLOW_LINKS) && f.list() != null) {
|
||||||
if ((n = findSomeFile(ans, create)) != null)
|
if ((n = findSomeFile(ans, create)) != null)
|
||||||
checkSlashes(d, create, ans + n, ask + n);
|
checkSlashes(d, create, ans + n, ask + n);
|
||||||
if ((n = findSomeDir(ans, create)) != null)
|
if ((n = findSomeDir(ans, create)) != null)
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user