diff --git a/.hgtags-top-repo b/.hgtags-top-repo
index 5650b64d79b..07921d280f1 100644
--- a/.hgtags-top-repo
+++ b/.hgtags-top-repo
@@ -329,3 +329,4 @@ ce5c14d97d95084504c32b9320cb33cce4235588 jdk9-b83
1c8134475511ffe6726677e1418a89a7a45e92d6 jdk9-b84
1f345217c9bab05f192d00cf1665b3286c49ccdb jdk9-b85
2aa1daf98d3e2ee37f20f6858c53cc37020f6937 jdk9-b86
+fd4f4f7561074dc0dbc1772c8489c7b902b6b8a9 jdk9-b87
diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh
index b8b6177d86d..ac326867966 100644
--- a/common/autoconf/generated-configure.sh
+++ b/common/autoconf/generated-configure.sh
@@ -4587,7 +4587,7 @@ VS_SDK_PLATFORM_NAME_2013=
#CUSTOM_AUTOCONF_INCLUDE
# Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1444224363
+DATE_WHEN_GENERATED=1444643341
###############################################################################
#
@@ -46678,10 +46678,24 @@ $as_echo "$as_me: WARNING: X11 is not used, so --with-x is ignored" >&2;}
X_CFLAGS=
X_LIBS=
else
- # Check if the user has specified sysroot, but not --x-includes or --x-libraries.
- # Make a simple check for the libraries at the sysroot, and setup --x-includes and
- # --x-libraries for the sysroot, if that seems to be correct.
- if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
+
+ if test "x${with_x}" = xno; then
+ as_fn_error $? "It is not possible to disable the use of X11. Remove the --without-x option." "$LINENO" 5
+ fi
+
+ if test "x${with_x}" != x && test "x${with_x}" != xyes; then
+ # The user has specified a X11 base directory. Use it for includes and
+ # libraries, unless explicitely overridden.
+ if test "x$x_includes" = xNONE; then
+ x_includes="${with_x}/include"
+ fi
+ if test "x$x_libraries" = xNONE; then
+ x_libraries="${with_x}/lib"
+ fi
+ else
+ # Check if the user has specified sysroot, but not --with-x, --x-includes or --x-libraries.
+ # Make a simple check for the libraries at the sysroot, and setup --x-includes and
+ # --x-libraries for the sysroot, if that seems to be correct.
if test "x$SYSROOT" != "x"; then
if test "x$x_includes" = xNONE; then
if test -f "$SYSROOT/usr/X11R6/include/X11/Xlib.h"; then
diff --git a/common/autoconf/lib-x11.m4 b/common/autoconf/lib-x11.m4
index b5671af2ff4..1fbc583db9f 100644
--- a/common/autoconf/lib-x11.m4
+++ b/common/autoconf/lib-x11.m4
@@ -35,10 +35,24 @@ AC_DEFUN_ONCE([LIB_SETUP_X11],
X_CFLAGS=
X_LIBS=
else
- # Check if the user has specified sysroot, but not --x-includes or --x-libraries.
- # Make a simple check for the libraries at the sysroot, and setup --x-includes and
- # --x-libraries for the sysroot, if that seems to be correct.
- if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
+
+ if test "x${with_x}" = xno; then
+ AC_MSG_ERROR([It is not possible to disable the use of X11. Remove the --without-x option.])
+ fi
+
+ if test "x${with_x}" != x && test "x${with_x}" != xyes; then
+ # The user has specified a X11 base directory. Use it for includes and
+ # libraries, unless explicitely overridden.
+ if test "x$x_includes" = xNONE; then
+ x_includes="${with_x}/include"
+ fi
+ if test "x$x_libraries" = xNONE; then
+ x_libraries="${with_x}/lib"
+ fi
+ else
+ # Check if the user has specified sysroot, but not --with-x, --x-includes or --x-libraries.
+ # Make a simple check for the libraries at the sysroot, and setup --x-includes and
+ # --x-libraries for the sysroot, if that seems to be correct.
if test "x$SYSROOT" != "x"; then
if test "x$x_includes" = xNONE; then
if test -f "$SYSROOT/usr/X11R6/include/X11/Xlib.h"; then
diff --git a/corba/.hgtags b/corba/.hgtags
index 492bb735842..05ed676d17e 100644
--- a/corba/.hgtags
+++ b/corba/.hgtags
@@ -329,3 +329,4 @@ ca8a1719588424f6e04e943790c7fcb7cb0b8c8f jdk9-b83
df70bb200356fec686681f0295c50cc3ed43c3b3 jdk9-b84
3ec06af1368924469f7ce60a00324bac55eaeecc jdk9-b85
0a3f0d25c201b40575a7c3920fce4d6f4d3ae310 jdk9-b86
+a5c40ac9b916ff44d512ee764fa919ed2097e149 jdk9-b87
diff --git a/hotspot/.hgtags b/hotspot/.hgtags
index a19cb298ea3..e1a9f80ec13 100644
--- a/hotspot/.hgtags
+++ b/hotspot/.hgtags
@@ -489,3 +489,4 @@ e9e63d93bbfe2c6c23447e2c1f5cc71c98671cba jdk9-b79
184c4328444974edd6b3b490b9d0177ace7e331c jdk9-b84
03845376ea9dbf9690b6a9cfb4ed63f8cc0541c0 jdk9-b85
1ae4191359d811a51512f17dca80ffe79837a5ff jdk9-b86
+d7ffd16382fe7071181b967932b47cff6d1312e1 jdk9-b87
diff --git a/jaxp/.hgtags b/jaxp/.hgtags
index 4dcf642142e..481f558a62d 100644
--- a/jaxp/.hgtags
+++ b/jaxp/.hgtags
@@ -329,3 +329,4 @@ f464f9b2fb1178f6a957e5730b4b5252c6149ed9 jdk9-b80
91795d86744f3074d1e59b1e75d9c851c098688f jdk9-b84
1d9850c1b35c74e8b5c17970ed5d46dc0fc33f06 jdk9-b85
88d9b1f6b73e0c46fcb5ccabe1231a30ce758a22 jdk9-b86
+eb435c878c2cbbfb043d0b205f4d5bd6faffd44a jdk9-b87
diff --git a/jdk/.hgtags b/jdk/.hgtags
index 1b65224c2bb..4609832ca7f 100644
--- a/jdk/.hgtags
+++ b/jdk/.hgtags
@@ -329,3 +329,4 @@ d11f25ce3c545823f53bb978d454a4d2901abac3 jdk9-b83
757ef7f6d0042934edea3e0bf616fad2c1a22789 jdk9-b84
fe40b31c0e526d357cf5b62044fea006e43b53a5 jdk9-b85
e8a66c0b05d786a282a7ff1d7eb4989afa30c891 jdk9-b86
+110fc90bdfa0fe59606c047c2301ed75d2bad6cf jdk9-b87
diff --git a/jdk/make/mapfiles/libjava/mapfile-vers b/jdk/make/mapfiles/libjava/mapfile-vers
index afc317bb5cf..c2e022c4ae9 100644
--- a/jdk/make/mapfiles/libjava/mapfile-vers
+++ b/jdk/make/mapfiles/libjava/mapfile-vers
@@ -152,7 +152,6 @@ SUNWprivate_1.1 {
Java_java_lang_StrictMath_log10;
Java_java_lang_StrictMath_sin;
Java_java_lang_StrictMath_sqrt;
- Java_java_lang_StrictMath_cbrt;
Java_java_lang_StrictMath_tan;
Java_java_lang_StrictMath_cosh;
Java_java_lang_StrictMath_sinh;
diff --git a/jdk/src/java.base/share/classes/java/lang/FdLibm.java b/jdk/src/java.base/share/classes/java/lang/FdLibm.java
index 938683f567f..dfecf79bb18 100644
--- a/jdk/src/java.base/share/classes/java/lang/FdLibm.java
+++ b/jdk/src/java.base/share/classes/java/lang/FdLibm.java
@@ -99,6 +99,64 @@ class FdLibm {
return Double.longBitsToDouble((transX & 0x0000_0000_FFFF_FFFFL)|( ((long)high)) << 32 );
}
+ /**
+ * cbrt(x)
+ * Return cube root of x
+ */
+ public static class Cbrt {
+ // unsigned
+ private static final int B1 = 715094163; /* B1 = (682-0.03306235651)*2**20 */
+ private static final int B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
+
+ private static final double C = 0x1.15f15f15f15f1p-1; // 19/35 ~= 5.42857142857142815906e-01
+ private static final double D = -0x1.691de2532c834p-1; // -864/1225 ~= 7.05306122448979611050e-01
+ private static final double E = 0x1.6a0ea0ea0ea0fp0; // 99/70 ~= 1.41428571428571436819e+00
+ private static final double F = 0x1.9b6db6db6db6ep0; // 45/28 ~= 1.60714285714285720630e+00
+ private static final double G = 0x1.6db6db6db6db7p-2; // 5/14 ~= 3.57142857142857150787e-01
+
+ public static strictfp double compute(double x) {
+ double t = 0.0;
+ double sign;
+
+ if (x == 0.0 || !Double.isFinite(x))
+ return x; // Handles signed zeros properly
+
+ sign = (x < 0.0) ? -1.0: 1.0;
+
+ x = Math.abs(x); // x <- |x|
+
+ // Rough cbrt to 5 bits
+ if (x < 0x1.0p-1022) { // subnormal number
+ t = 0x1.0p54; // set t= 2**54
+ t *= x;
+ t = __HI(t, __HI(t)/3 + B2);
+ } else {
+ int hx = __HI(x); // high word of x
+ t = __HI(t, hx/3 + B1);
+ }
+
+ // New cbrt to 23 bits, may be implemented in single precision
+ double r, s, w;
+ r = t * t/x;
+ s = C + r*t;
+ t *= G + F/(s + E + D/s);
+
+ // Chopped to 20 bits and make it larger than cbrt(x)
+ t = __LO(t, 0);
+ t = __HI(t, __HI(t) + 0x00000001);
+
+ // One step newton iteration to 53 bits with error less than 0.667 ulps
+ s = t * t; // t*t is exact
+ r = x / s;
+ w = t + t;
+ r = (r - t)/(w + r); // r-s is exact
+ t = t + t*r;
+
+ // Restore the original sign bit
+ return sign * t;
+ }
+ }
+
/**
* hypot(x,y)
*
diff --git a/jdk/src/java.base/share/classes/java/lang/StrictMath.java b/jdk/src/java.base/share/classes/java/lang/StrictMath.java
index b06fda19537..68bba059786 100644
--- a/jdk/src/java.base/share/classes/java/lang/StrictMath.java
+++ b/jdk/src/java.base/share/classes/java/lang/StrictMath.java
@@ -307,7 +307,9 @@ public final class StrictMath {
* @return the cube root of {@code a}.
* @since 1.5
*/
- public static native double cbrt(double a);
+ public static double cbrt(double a) {
+ return FdLibm.Cbrt.compute(a);
+ }
/**
* Computes the remainder operation on two arguments as prescribed
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java b/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java
index 60b695571d7..659759b882d 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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
@@ -834,7 +834,7 @@ import jdk.internal.org.objectweb.asm.Type;
static MethodHandle makeCbmhCtor(Class extends BoundMethodHandle> cbmh, String types) {
try {
- return LOOKUP.findStatic(cbmh, "make", MethodType.fromMethodDescriptorString(makeSignature(types, false), null));
+ return LOOKUP.findStatic(cbmh, "make", MethodType.fromDescriptor(makeSignature(types, false), null));
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) {
throw newInternalError(e);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java b/jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java
index 0393345bac6..1f60038e121 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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
@@ -141,7 +141,7 @@ import java.util.Objects;
synchronized (this) {
if (type instanceof String) {
String sig = (String) type;
- MethodType res = MethodType.fromMethodDescriptorString(sig, getClassLoader());
+ MethodType res = MethodType.fromDescriptor(sig, getClassLoader());
type = res;
} else if (type instanceof Object[]) {
Object[] typeInfo = (Object[]) type;
@@ -206,7 +206,7 @@ import java.util.Objects;
synchronized (this) {
if (type instanceof String) {
String sig = (String) type;
- MethodType mtype = MethodType.fromMethodDescriptorString("()"+sig, getClassLoader());
+ MethodType mtype = MethodType.fromDescriptor("()"+sig, getClassLoader());
Class> res = mtype.returnType();
type = res;
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java
index 4b98a2cf1a1..29bd6dbf512 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java
@@ -383,7 +383,7 @@ class MethodHandleNatives {
if (type instanceof MethodType)
return (MethodType) type;
else
- return MethodType.fromMethodDescriptorString((String)type, callerClass.getClassLoader());
+ return MethodType.fromDescriptor((String)type, callerClass.getClassLoader());
}
// Tracing logic:
static MemberName linkMethodTracing(Class> callerClass, int refKind,
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java
index b43b0c35703..1a986a4bf64 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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
@@ -1057,6 +1057,23 @@ class MethodType implements java.io.Serializable {
*/
public static MethodType fromMethodDescriptorString(String descriptor, ClassLoader loader)
throws IllegalArgumentException, TypeNotPresentException
+ {
+ return fromDescriptor(descriptor,
+ (loader == null) ? ClassLoader.getSystemClassLoader() : loader);
+ }
+
+ /**
+ * Same as {@link #fromMethodDescriptorString(String, ClassLoader)}, but
+ * {@code null} ClassLoader means the bootstrap loader is used here.
+ *
+ * IMPORTANT: This method is preferable for JDK internal use as it more
+ * correctly interprets {@code null} ClassLoader than
+ * {@link #fromMethodDescriptorString(String, ClassLoader)}.
+ * Use of this method also avoids early initialization issues when system
+ * ClassLoader is not initialized yet.
+ */
+ static MethodType fromDescriptor(String descriptor, ClassLoader loader)
+ throws IllegalArgumentException, TypeNotPresentException
{
if (!descriptor.startsWith("(") || // also generates NPE if needed
descriptor.indexOf(')') < 0 ||
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/TypeConvertingMethodAdapter.java b/jdk/src/java.base/share/classes/java/lang/invoke/TypeConvertingMethodAdapter.java
index 6bfbf6b601a..c640d726ea2 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/TypeConvertingMethodAdapter.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/TypeConvertingMethodAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, 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
@@ -131,7 +131,7 @@ class TypeConvertingMethodAdapter extends MethodVisitor {
}
private static String boxingDescriptor(Wrapper w) {
- return String.format("(%s)L%s;", w.basicTypeChar(), wrapperName(w));
+ return "(" + w.basicTypeChar() + ")L" + wrapperName(w) + ";";
}
private static String unboxingDescriptor(Wrapper w) {
diff --git a/jdk/src/java.base/share/classes/java/net/URLStreamHandlerFactory.java b/jdk/src/java.base/share/classes/java/net/URLStreamHandlerFactory.java
index fd42613a1cf..d49a4a2fcc8 100644
--- a/jdk/src/java.base/share/classes/java/net/URLStreamHandlerFactory.java
+++ b/jdk/src/java.base/share/classes/java/net/URLStreamHandlerFactory.java
@@ -28,9 +28,9 @@ package java.net;
/**
* This interface defines a factory for {@code URL} stream
* protocol handlers.
- *
- * It is used by the {@code URL} class to create a
- * {@code URLStreamHandler} for a specific protocol.
+ *
+ *
A URL stream handler factory is used as specified in the
+ * {@linkplain java.net.URL#URL(String,String,int,String) URL constructor}.
*
* @author Arthur van Hoff
* @see java.net.URL
diff --git a/jdk/src/java.base/share/classes/java/net/spi/URLStreamHandlerProvider.java b/jdk/src/java.base/share/classes/java/net/spi/URLStreamHandlerProvider.java
index bfd0de937af..0d6b424205e 100644
--- a/jdk/src/java.base/share/classes/java/net/spi/URLStreamHandlerProvider.java
+++ b/jdk/src/java.base/share/classes/java/net/spi/URLStreamHandlerProvider.java
@@ -41,6 +41,9 @@ import java.net.URLStreamHandlerFactory;
* fully-qualified concrete URL stream handler provider class names, one per
* line.
*
+ *
URL stream handler providers are located at runtime, as specified in the
+ * {@linkplain java.net.URL#URL(String,String,int,String) URL constructor}.
+ *
* @since 1.9
*/
public abstract class URLStreamHandlerProvider
diff --git a/jdk/src/java.base/share/classes/java/util/AbstractQueue.java b/jdk/src/java.base/share/classes/java/util/AbstractQueue.java
index 182698dc5a2..6c1442b09f6 100644
--- a/jdk/src/java.base/share/classes/java/util/AbstractQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/AbstractQueue.java
@@ -38,16 +38,16 @@ package java.util;
/**
* This class provides skeletal implementations of some {@link Queue}
* operations. The implementations in this class are appropriate when
- * the base implementation does not allow null
+ * the base implementation does not allow {@code null}
* elements. Methods {@link #add add}, {@link #remove remove}, and
* {@link #element element} are based on {@link #offer offer}, {@link
* #poll poll}, and {@link #peek peek}, respectively, but throw
- * exceptions instead of indicating failure via false or
- * null returns.
+ * exceptions instead of indicating failure via {@code false} or
+ * {@code null} returns.
*
- *
A Queue implementation that extends this class must
+ *
A {@code Queue} implementation that extends this class must
* minimally define a method {@link Queue#offer} which does not permit
- * insertion of null elements, along with methods {@link
+ * insertion of {@code null} elements, along with methods {@link
* Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and
* {@link Collection#iterator}. Typically, additional methods will be
* overridden as well. If these requirements cannot be met, consider
@@ -59,7 +59,7 @@ package java.util;
*
* @since 1.5
* @author Doug Lea
- * @param the type of elements held in this collection
+ * @param the type of elements held in this queue
*/
public abstract class AbstractQueue
extends AbstractCollection
@@ -74,14 +74,14 @@ public abstract class AbstractQueue
/**
* Inserts the specified element into this queue if it is possible to do so
* immediately without violating capacity restrictions, returning
- * true upon success and throwing an IllegalStateException
+ * {@code true} upon success and throwing an {@code IllegalStateException}
* if no space is currently available.
*
- * This implementation returns true if offer succeeds,
- * else throws an IllegalStateException.
+ *
This implementation returns {@code true} if {@code offer} succeeds,
+ * else throws an {@code IllegalStateException}.
*
* @param e the element to add
- * @return true (as specified by {@link Collection#add})
+ * @return {@code true} (as specified by {@link Collection#add})
* @throws IllegalStateException if the element cannot be added at this
* time due to capacity restrictions
* @throws ClassCastException if the class of the specified element
@@ -103,7 +103,7 @@ public abstract class AbstractQueue
* from {@link #poll poll} only in that it throws an exception if this
* queue is empty.
*
- * This implementation returns the result of poll
+ *
This implementation returns the result of {@code poll}
* unless the queue is empty.
*
* @return the head of this queue
@@ -122,7 +122,7 @@ public abstract class AbstractQueue
* differs from {@link #peek peek} only in that it throws an exception if
* this queue is empty.
*
- * This implementation returns the result of peek
+ *
This implementation returns the result of {@code peek}
* unless the queue is empty.
*
* @return the head of this queue
@@ -141,7 +141,7 @@ public abstract class AbstractQueue
* The queue will be empty after this call returns.
*
* This implementation repeatedly invokes {@link #poll poll} until it
- * returns null.
+ * returns {@code null}.
*/
public void clear() {
while (poll() != null)
@@ -151,7 +151,7 @@ public abstract class AbstractQueue
/**
* Adds all of the elements in the specified collection to this
* queue. Attempts to addAll of a queue to itself result in
- * IllegalArgumentException. Further, the behavior of
+ * {@code IllegalArgumentException}. Further, the behavior of
* this operation is undefined if the specified collection is
* modified while the operation is in progress.
*
@@ -159,12 +159,12 @@ public abstract class AbstractQueue
* and adds each element returned by the iterator to this
* queue, in turn. A runtime exception encountered while
* trying to add an element (including, in particular, a
- * null element) may result in only some of the elements
+ * {@code null} element) may result in only some of the elements
* having been successfully added when the associated exception is
* thrown.
*
* @param c collection containing elements to be added to this queue
- * @return true if this queue changed as a result of the call
+ * @return {@code true} if this queue changed as a result of the call
* @throws ClassCastException if the class of an element of the specified
* collection prevents it from being added to this queue
* @throws NullPointerException if the specified collection contains a
diff --git a/jdk/src/java.base/share/classes/java/util/ArrayDeque.java b/jdk/src/java.base/share/classes/java/util/ArrayDeque.java
index 7d5e015abcd..ca3c66b6249 100644
--- a/jdk/src/java.base/share/classes/java/util/ArrayDeque.java
+++ b/jdk/src/java.base/share/classes/java/util/ArrayDeque.java
@@ -47,16 +47,18 @@ import java.util.function.Consumer;
* when used as a queue.
*
* Most {@code ArrayDeque} operations run in amortized constant time.
- * Exceptions include {@link #remove(Object) remove}, {@link
- * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
- * removeLastOccurrence}, {@link #contains contains}, {@link #iterator
- * iterator.remove()}, and the bulk operations, all of which run in linear
- * time.
+ * Exceptions include
+ * {@link #remove(Object) remove},
+ * {@link #removeFirstOccurrence removeFirstOccurrence},
+ * {@link #removeLastOccurrence removeLastOccurrence},
+ * {@link #contains contains},
+ * {@link #iterator iterator.remove()},
+ * and the bulk operations, all of which run in linear time.
*
- *
The iterators returned by this class's {@code iterator} method are
- * fail-fast: If the deque is modified at any time after the iterator
- * is created, in any way except through the iterator's own {@code remove}
- * method, the iterator will generally throw a {@link
+ *
The iterators returned by this class's {@link #iterator() iterator}
+ * method are fail-fast: If the deque is modified at any time after
+ * the iterator is created, in any way except through the iterator's own
+ * {@code remove} method, the iterator will generally throw a {@link
* ConcurrentModificationException}. Thus, in the face of concurrent
* modification, the iterator fails quickly and cleanly, rather than risking
* arbitrary, non-deterministic behavior at an undetermined time in the
@@ -80,7 +82,7 @@ import java.util.function.Consumer;
*
* @author Josh Bloch and Doug Lea
* @since 1.6
- * @param the type of elements held in this collection
+ * @param the type of elements held in this deque
*/
public class ArrayDeque extends AbstractCollection
implements Deque, Cloneable, Serializable
@@ -136,8 +138,8 @@ public class ArrayDeque extends AbstractCollection
initialCapacity |= (initialCapacity >>> 16);
initialCapacity++;
- if (initialCapacity < 0) // Too many elements, must back off
- initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
+ if (initialCapacity < 0) // Too many elements, must back off
+ initialCapacity >>>= 1; // Good luck allocating 2^30 elements
}
elements = new Object[initialCapacity];
}
@@ -162,24 +164,6 @@ public class ArrayDeque extends AbstractCollection
tail = n;
}
- /**
- * Copies the elements from our element array into the specified array,
- * in order (from first to last element in the deque). It is assumed
- * that the array is large enough to hold all elements in the deque.
- *
- * @return its argument
- */
- private T[] copyElements(T[] a) {
- if (head < tail) {
- System.arraycopy(elements, head, a, 0, size());
- } else if (head > tail) {
- int headPortionLen = elements.length - head;
- System.arraycopy(elements, head, a, 0, headPortionLen);
- System.arraycopy(elements, 0, a, headPortionLen, tail);
- }
- return a;
- }
-
/**
* Constructs an empty array deque with an initial capacity
* sufficient to hold 16 elements.
@@ -292,25 +276,27 @@ public class ArrayDeque extends AbstractCollection
}
public E pollFirst() {
- int h = head;
+ final Object[] elements = this.elements;
+ final int h = head;
@SuppressWarnings("unchecked")
E result = (E) elements[h];
// Element is null if deque empty
- if (result == null)
- return null;
- elements[h] = null; // Must null out slot
- head = (h + 1) & (elements.length - 1);
+ if (result != null) {
+ elements[h] = null; // Must null out slot
+ head = (h + 1) & (elements.length - 1);
+ }
return result;
}
public E pollLast() {
- int t = (tail - 1) & (elements.length - 1);
+ final Object[] elements = this.elements;
+ final int t = (tail - 1) & (elements.length - 1);
@SuppressWarnings("unchecked")
E result = (E) elements[t];
- if (result == null)
- return null;
- elements[t] = null;
- tail = t;
+ if (result != null) {
+ elements[t] = null;
+ tail = t;
+ }
return result;
}
@@ -360,17 +346,15 @@ public class ArrayDeque extends AbstractCollection
* @return {@code true} if the deque contained the specified element
*/
public boolean removeFirstOccurrence(Object o) {
- if (o == null)
- return false;
- int mask = elements.length - 1;
- int i = head;
- Object x;
- while ( (x = elements[i]) != null) {
- if (o.equals(x)) {
- delete(i);
- return true;
+ if (o != null) {
+ int mask = elements.length - 1;
+ int i = head;
+ for (Object x; (x = elements[i]) != null; i = (i + 1) & mask) {
+ if (o.equals(x)) {
+ delete(i);
+ return true;
+ }
}
- i = (i + 1) & mask;
}
return false;
}
@@ -388,17 +372,15 @@ public class ArrayDeque extends AbstractCollection
* @return {@code true} if the deque contained the specified element
*/
public boolean removeLastOccurrence(Object o) {
- if (o == null)
- return false;
- int mask = elements.length - 1;
- int i = (tail - 1) & mask;
- Object x;
- while ( (x = elements[i]) != null) {
- if (o.equals(x)) {
- delete(i);
- return true;
+ if (o != null) {
+ int mask = elements.length - 1;
+ int i = (tail - 1) & mask;
+ for (Object x; (x = elements[i]) != null; i = (i - 1) & mask) {
+ if (o.equals(x)) {
+ delete(i);
+ return true;
+ }
}
- i = (i - 1) & mask;
}
return false;
}
@@ -535,7 +517,7 @@ public class ArrayDeque extends AbstractCollection
*
* @return true if elements moved backwards
*/
- private boolean delete(int i) {
+ boolean delete(int i) {
checkInvariants();
final Object[] elements = this.elements;
final int mask = elements.length - 1;
@@ -671,12 +653,12 @@ public class ArrayDeque extends AbstractCollection
}
}
+ /**
+ * This class is nearly a mirror-image of DeqIterator, using tail
+ * instead of head for initial cursor, and head instead of tail
+ * for fence.
+ */
private class DescendingIterator implements Iterator {
- /*
- * This class is nearly a mirror-image of DeqIterator, using
- * tail instead of head for initial cursor, and head instead of
- * tail for fence.
- */
private int cursor = tail;
private int fence = head;
private int lastRet = -1;
@@ -717,15 +699,13 @@ public class ArrayDeque extends AbstractCollection
* @return {@code true} if this deque contains the specified element
*/
public boolean contains(Object o) {
- if (o == null)
- return false;
- int mask = elements.length - 1;
- int i = head;
- Object x;
- while ( (x = elements[i]) != null) {
- if (o.equals(x))
- return true;
- i = (i + 1) & mask;
+ if (o != null) {
+ int mask = elements.length - 1;
+ int i = head;
+ for (Object x; (x = elements[i]) != null; i = (i + 1) & mask) {
+ if (o.equals(x))
+ return true;
+ }
}
return false;
}
@@ -779,7 +759,14 @@ public class ArrayDeque extends AbstractCollection
* @return an array containing all of the elements in this deque
*/
public Object[] toArray() {
- return copyElements(new Object[size()]);
+ final int head = this.head;
+ final int tail = this.tail;
+ boolean wrap = (tail < head);
+ int end = wrap ? tail + elements.length : tail;
+ Object[] a = Arrays.copyOfRange(elements, head, end);
+ if (wrap)
+ System.arraycopy(elements, 0, a, elements.length - head, tail);
+ return a;
}
/**
@@ -804,7 +791,7 @@ public class ArrayDeque extends AbstractCollection
* The following code can be used to dump the deque into a newly
* allocated array of {@code String}:
*
- * {@code String[] y = x.toArray(new String[0]);}
+ * {@code String[] y = x.toArray(new String[0]);}
*
* Note that {@code toArray(new Object[0])} is identical in function to
* {@code toArray()}.
@@ -820,13 +807,22 @@ public class ArrayDeque extends AbstractCollection
*/
@SuppressWarnings("unchecked")
public T[] toArray(T[] a) {
- int size = size();
- if (a.length < size)
- a = (T[])java.lang.reflect.Array.newInstance(
- a.getClass().getComponentType(), size);
- copyElements(a);
- if (a.length > size)
- a[size] = null;
+ final int head = this.head;
+ final int tail = this.tail;
+ boolean wrap = (tail < head);
+ int size = (tail - head) + (wrap ? elements.length : 0);
+ int firstLeg = size - (wrap ? tail : 0);
+ int len = a.length;
+ if (size > len) {
+ a = (T[]) Arrays.copyOfRange(elements, head, head + size,
+ a.getClass());
+ } else {
+ System.arraycopy(elements, head, a, 0, firstLeg);
+ if (size < len)
+ a[size] = null;
+ }
+ if (wrap)
+ System.arraycopy(elements, 0, a, firstLeg, tail);
return a;
}
@@ -853,6 +849,8 @@ public class ArrayDeque extends AbstractCollection
/**
* Saves this deque to a stream (that is, serializes it).
*
+ * @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
* @serialData The current size ({@code int}) of the deque,
* followed by all of its elements (each an object reference) in
* first-to-last order.
@@ -872,6 +870,10 @@ public class ArrayDeque extends AbstractCollection
/**
* Reconstitutes this deque from a stream (that is, deserializes it).
+ * @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
@@ -910,7 +912,7 @@ public class ArrayDeque extends AbstractCollection
private int fence; // -1 until first use
private int index; // current index, modified on traverse/split
- /** Creates new spliterator covering the given array and range */
+ /** Creates new spliterator covering the given array and range. */
DeqSpliterator(ArrayDeque deq, int origin, int fence) {
this.deq = deq;
this.index = origin;
@@ -932,7 +934,7 @@ public class ArrayDeque extends AbstractCollection
if (h > t)
t += n;
int m = ((h + t) >>> 1) & (n - 1);
- return new DeqSpliterator<>(deq, h, index = m);
+ return new DeqSpliterator(deq, h, index = m);
}
return null;
}
@@ -957,7 +959,7 @@ public class ArrayDeque extends AbstractCollection
throw new NullPointerException();
Object[] a = deq.elements;
int m = a.length - 1, f = getFence(), i = index;
- if (i != fence) {
+ if (i != f) {
@SuppressWarnings("unchecked") E e = (E)a[i];
index = (i + 1) & m;
if (e == null)
diff --git a/jdk/src/java.base/share/classes/java/util/ArrayPrefixHelpers.java b/jdk/src/java.base/share/classes/java/util/ArrayPrefixHelpers.java
index abcdb2b35aa..87c04d17dd0 100644
--- a/jdk/src/java.base/share/classes/java/util/ArrayPrefixHelpers.java
+++ b/jdk/src/java.base/share/classes/java/util/ArrayPrefixHelpers.java
@@ -1,5 +1,4 @@
/*
- * Copyright (c) 2012, 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
@@ -22,20 +21,26 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-package java.util;
/*
+ * This file is available under and governed by the GNU General Public
+ * License version 2 only, as published by the Free Software Foundation.
+ * However, the following notice accompanied the original version of this
+ * file:
+ *
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
-import java.util.concurrent.ForkJoinPool;
+package java.util;
+
import java.util.concurrent.CountedCompleter;
+import java.util.concurrent.ForkJoinPool;
import java.util.function.BinaryOperator;
+import java.util.function.DoubleBinaryOperator;
import java.util.function.IntBinaryOperator;
import java.util.function.LongBinaryOperator;
-import java.util.function.DoubleBinaryOperator;
/**
* ForkJoin tasks to perform Arrays.parallelPrefix operations.
@@ -44,7 +49,7 @@ import java.util.function.DoubleBinaryOperator;
* @since 1.8
*/
class ArrayPrefixHelpers {
- private ArrayPrefixHelpers() {}; // non-instantiable
+ private ArrayPrefixHelpers() {} // non-instantiable
/*
* Parallel prefix (aka cumulate, scan) task classes
@@ -113,8 +118,8 @@ class ArrayPrefixHelpers {
this.lo = this.origin = lo; this.hi = this.fence = hi;
int p;
this.threshold =
- (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
- <= MIN_PARTITION ? MIN_PARTITION : p;
+ (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
+ <= MIN_PARTITION ? MIN_PARTITION : p;
}
/** Subtask constructor */
@@ -141,9 +146,9 @@ class ArrayPrefixHelpers {
if (lt == null) { // first pass
int mid = (l + h) >>> 1;
f = rt = t.right =
- new CumulateTask(t, fn, a, org, fnc, th, mid, h);
- t = lt = t.left =
- new CumulateTask(t, fn, a, org, fnc, th, l, mid);
+ new CumulateTask(t, fn, a, org, fnc, th, mid, h);
+ t = lt = t.left =
+ new CumulateTask(t, fn, a, org, fnc, th, l, mid);
}
else { // possibly refork
T pin = t.in;
@@ -183,7 +188,7 @@ class ArrayPrefixHelpers {
for (int b;;) {
if (((b = t.getPendingCount()) & FINISHED) != 0)
break outer; // already done
- state = ((b & CUMULATE) != 0? FINISHED :
+ state = ((b & CUMULATE) != 0 ? FINISHED :
(l > org) ? SUMMED : (SUMMED|FINISHED));
if (t.compareAndSetPendingCount(b, b|state))
break;
@@ -265,8 +270,8 @@ class ArrayPrefixHelpers {
this.lo = this.origin = lo; this.hi = this.fence = hi;
int p;
this.threshold =
- (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
- <= MIN_PARTITION ? MIN_PARTITION : p;
+ (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
+ <= MIN_PARTITION ? MIN_PARTITION : p;
}
/** Subtask constructor */
@@ -293,9 +298,9 @@ class ArrayPrefixHelpers {
if (lt == null) { // first pass
int mid = (l + h) >>> 1;
f = rt = t.right =
- new LongCumulateTask(t, fn, a, org, fnc, th, mid, h);
- t = lt = t.left =
- new LongCumulateTask(t, fn, a, org, fnc, th, l, mid);
+ new LongCumulateTask(t, fn, a, org, fnc, th, mid, h);
+ t = lt = t.left =
+ new LongCumulateTask(t, fn, a, org, fnc, th, l, mid);
}
else { // possibly refork
long pin = t.in;
@@ -335,7 +340,7 @@ class ArrayPrefixHelpers {
for (int b;;) {
if (((b = t.getPendingCount()) & FINISHED) != 0)
break outer; // already done
- state = ((b & CUMULATE) != 0? FINISHED :
+ state = ((b & CUMULATE) != 0 ? FINISHED :
(l > org) ? SUMMED : (SUMMED|FINISHED));
if (t.compareAndSetPendingCount(b, b|state))
break;
@@ -415,8 +420,8 @@ class ArrayPrefixHelpers {
this.lo = this.origin = lo; this.hi = this.fence = hi;
int p;
this.threshold =
- (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
- <= MIN_PARTITION ? MIN_PARTITION : p;
+ (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
+ <= MIN_PARTITION ? MIN_PARTITION : p;
}
/** Subtask constructor */
@@ -443,9 +448,9 @@ class ArrayPrefixHelpers {
if (lt == null) { // first pass
int mid = (l + h) >>> 1;
f = rt = t.right =
- new DoubleCumulateTask(t, fn, a, org, fnc, th, mid, h);
- t = lt = t.left =
- new DoubleCumulateTask(t, fn, a, org, fnc, th, l, mid);
+ new DoubleCumulateTask(t, fn, a, org, fnc, th, mid, h);
+ t = lt = t.left =
+ new DoubleCumulateTask(t, fn, a, org, fnc, th, l, mid);
}
else { // possibly refork
double pin = t.in;
@@ -485,7 +490,7 @@ class ArrayPrefixHelpers {
for (int b;;) {
if (((b = t.getPendingCount()) & FINISHED) != 0)
break outer; // already done
- state = ((b & CUMULATE) != 0? FINISHED :
+ state = ((b & CUMULATE) != 0 ? FINISHED :
(l > org) ? SUMMED : (SUMMED|FINISHED));
if (t.compareAndSetPendingCount(b, b|state))
break;
@@ -565,8 +570,8 @@ class ArrayPrefixHelpers {
this.lo = this.origin = lo; this.hi = this.fence = hi;
int p;
this.threshold =
- (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
- <= MIN_PARTITION ? MIN_PARTITION : p;
+ (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
+ <= MIN_PARTITION ? MIN_PARTITION : p;
}
/** Subtask constructor */
@@ -593,9 +598,9 @@ class ArrayPrefixHelpers {
if (lt == null) { // first pass
int mid = (l + h) >>> 1;
f = rt = t.right =
- new IntCumulateTask(t, fn, a, org, fnc, th, mid, h);
- t = lt = t.left =
- new IntCumulateTask(t, fn, a, org, fnc, th, l, mid);
+ new IntCumulateTask(t, fn, a, org, fnc, th, mid, h);
+ t = lt = t.left =
+ new IntCumulateTask(t, fn, a, org, fnc, th, l, mid);
}
else { // possibly refork
int pin = t.in;
@@ -635,7 +640,7 @@ class ArrayPrefixHelpers {
for (int b;;) {
if (((b = t.getPendingCount()) & FINISHED) != 0)
break outer; // already done
- state = ((b & CUMULATE) != 0? FINISHED :
+ state = ((b & CUMULATE) != 0 ? FINISHED :
(l > org) ? SUMMED : (SUMMED|FINISHED));
if (t.compareAndSetPendingCount(b, b|state))
break;
diff --git a/jdk/src/java.base/share/classes/java/util/Collections.java b/jdk/src/java.base/share/classes/java/util/Collections.java
index 7f9cb7c83f7..fec21c29079 100644
--- a/jdk/src/java.base/share/classes/java/util/Collections.java
+++ b/jdk/src/java.base/share/classes/java/util/Collections.java
@@ -537,8 +537,9 @@ public class Collections {
* Copies all of the elements from one list into another. After the
* operation, the index of each copied element in the destination list
* will be identical to its index in the source list. The destination
- * list must be at least as long as the source list. If it is longer, the
- * remaining elements in the destination list are unaffected.
+ * list's size must be greater than or equal to the source list's size.
+ * If it is greater, the remaining elements in the destination list are
+ * unaffected.
*
* This method runs in linear time.
*
diff --git a/jdk/src/java.base/share/classes/java/util/Deque.java b/jdk/src/java.base/share/classes/java/util/Deque.java
index 3ed3ab8f667..098be9b4bf9 100644
--- a/jdk/src/java.base/share/classes/java/util/Deque.java
+++ b/jdk/src/java.base/share/classes/java/util/Deque.java
@@ -188,7 +188,7 @@ package java.util;
* @author Doug Lea
* @author Josh Bloch
* @since 1.6
- * @param the type of elements held in this collection
+ * @param the type of elements held in this deque
*/
public interface Deque extends Queue {
/**
@@ -344,8 +344,7 @@ public interface Deque extends Queue {
* Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the first element {@code e} such that
- * (o==null ? e==null : o.equals(e))
- * (if such an element exists).
+ * {@code Objects.equals(o, e)} (if such an element exists).
* Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
@@ -353,10 +352,10 @@ public interface Deque extends Queue {
* @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null and this
* deque does not permit null elements
- * (optional)
+ * (optional)
*/
boolean removeFirstOccurrence(Object o);
@@ -364,8 +363,7 @@ public interface Deque extends Queue {
* Removes the last occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the last element {@code e} such that
- * (o==null ? e==null : o.equals(e))
- * (if such an element exists).
+ * {@code Objects.equals(o, e)} (if such an element exists).
* Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
@@ -373,10 +371,10 @@ public interface Deque extends Queue {
* @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null and this
* deque does not permit null elements
- * (optional)
+ * (optional)
*/
boolean removeLastOccurrence(Object o);
@@ -521,8 +519,7 @@ public interface Deque extends Queue {
* Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the first element {@code e} such that
- * (o==null ? e==null : o.equals(e))
- * (if such an element exists).
+ * {@code Objects.equals(o, e)} (if such an element exists).
* Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
@@ -532,27 +529,26 @@ public interface Deque extends Queue {
* @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null and this
* deque does not permit null elements
- * (optional)
+ * (optional)
*/
boolean remove(Object o);
/**
* Returns {@code true} if this deque contains the specified element.
* More formally, returns {@code true} if and only if this deque contains
- * at least one element {@code e} such that
- * (o==null ? e==null : o.equals(e)).
+ * at least one element {@code e} such that {@code Objects.equals(o, e)}.
*
* @param o element whose presence in this deque is to be tested
* @return {@code true} if this deque contains the specified element
- * @throws ClassCastException if the type of the specified element
+ * @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null and this
* deque does not permit null elements
- * (optional)
+ * (optional)
*/
boolean contains(Object o);
@@ -561,7 +557,7 @@ public interface Deque extends Queue {
*
* @return the number of elements in this deque
*/
- public int size();
+ int size();
/**
* Returns an iterator over the elements in this deque in proper sequence.
diff --git a/jdk/src/java.base/share/classes/java/util/NavigableMap.java b/jdk/src/java.base/share/classes/java/util/NavigableMap.java
index 2d18d4a7215..6045ee2b48f 100644
--- a/jdk/src/java.base/share/classes/java/util/NavigableMap.java
+++ b/jdk/src/java.base/share/classes/java/util/NavigableMap.java
@@ -38,30 +38,32 @@ package java.util;
/**
* A {@link SortedMap} extended with navigation methods returning the
* closest matches for given search targets. Methods
- * {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry},
- * and {@code higherEntry} return {@code Map.Entry} objects
+ * {@link #lowerEntry}, {@link #floorEntry}, {@link #ceilingEntry},
+ * and {@link #higherEntry} return {@code Map.Entry} objects
* associated with keys respectively less than, less than or equal,
* greater than or equal, and greater than a given key, returning
* {@code null} if there is no such key. Similarly, methods
- * {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and
- * {@code higherKey} return only the associated keys. All of these
+ * {@link #lowerKey}, {@link #floorKey}, {@link #ceilingKey}, and
+ * {@link #higherKey} return only the associated keys. All of these
* methods are designed for locating, not traversing entries.
*
* A {@code NavigableMap} may be accessed and traversed in either
- * ascending or descending key order. The {@code descendingMap}
+ * ascending or descending key order. The {@link #descendingMap}
* method returns a view of the map with the senses of all relational
* and directional methods inverted. The performance of ascending
* operations and views is likely to be faster than that of descending
- * ones. Methods {@code subMap}, {@code headMap},
- * and {@code tailMap} differ from the like-named {@code
- * SortedMap} methods in accepting additional arguments describing
- * whether lower and upper bounds are inclusive versus exclusive.
- * Submaps of any {@code NavigableMap} must implement the {@code
- * NavigableMap} interface.
+ * ones. Methods
+ * {@link #subMap(Object, boolean, Object, boolean) subMap(K, boolean, K, boolean)},
+ * {@link #headMap(Object, boolean) headMap(K, boolean)}, and
+ * {@link #tailMap(Object, boolean) tailMap(K, boolean)}
+ * differ from the like-named {@code SortedMap} methods in accepting
+ * additional arguments describing whether lower and upper bounds are
+ * inclusive versus exclusive. Submaps of any {@code NavigableMap}
+ * must implement the {@code NavigableMap} interface.
*
- *
This interface additionally defines methods {@code firstEntry},
- * {@code pollFirstEntry}, {@code lastEntry}, and
- * {@code pollLastEntry} that return and/or remove the least and
+ *
This interface additionally defines methods {@link #firstEntry},
+ * {@link #pollFirstEntry}, {@link #lastEntry}, and
+ * {@link #pollLastEntry} that return and/or remove the least and
* greatest mappings, if any exist, else returning {@code null}.
*
*
Implementations of entry-returning methods are expected to
@@ -80,7 +82,7 @@ package java.util;
* implement {@code NavigableMap}, but extensions and implementations
* of this interface are encouraged to override these methods to return
* {@code NavigableMap}. Similarly,
- * {@link #keySet()} can be overriden to return {@code NavigableSet}.
+ * {@link #keySet()} can be overridden to return {@link NavigableSet}.
*
*
This interface is a member of the
*
@@ -254,7 +256,7 @@ public interface NavigableMap extends SortedMap {
* operation), the results of the iteration are undefined.
*
* The returned map has an ordering equivalent to
- * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator()).
+ * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}{@code (comparator())}.
* The expression {@code m.descendingMap().descendingMap()} returns a
* view of {@code m} essentially equivalent to {@code m}.
*
diff --git a/jdk/src/java.base/share/classes/java/util/NavigableSet.java b/jdk/src/java.base/share/classes/java/util/NavigableSet.java
index 4dbb1c1cc45..40843905271 100644
--- a/jdk/src/java.base/share/classes/java/util/NavigableSet.java
+++ b/jdk/src/java.base/share/classes/java/util/NavigableSet.java
@@ -37,26 +37,30 @@ package java.util;
/**
* A {@link SortedSet} extended with navigation methods reporting
- * closest matches for given search targets. Methods {@code lower},
- * {@code floor}, {@code ceiling}, and {@code higher} return elements
+ * closest matches for given search targets. Methods {@link #lower},
+ * {@link #floor}, {@link #ceiling}, and {@link #higher} return elements
* respectively less than, less than or equal, greater than or equal,
* and greater than a given element, returning {@code null} if there
- * is no such element. A {@code NavigableSet} may be accessed and
- * traversed in either ascending or descending order. The {@code
- * descendingSet} method returns a view of the set with the senses of
- * all relational and directional methods inverted. The performance of
- * ascending operations and views is likely to be faster than that of
- * descending ones. This interface additionally defines methods
- * {@code pollFirst} and {@code pollLast} that return and remove the
- * lowest and highest element, if one exists, else returning {@code
- * null}. Methods {@code subSet}, {@code headSet},
- * and {@code tailSet} differ from the like-named {@code
- * SortedSet} methods in accepting additional arguments describing
- * whether lower and upper bounds are inclusive versus exclusive.
- * Subsets of any {@code NavigableSet} must implement the {@code
- * NavigableSet} interface.
+ * is no such element.
*
- *
The return values of navigation methods may be ambiguous in
+ *
A {@code NavigableSet} may be accessed and traversed in either
+ * ascending or descending order. The {@link #descendingSet} method
+ * returns a view of the set with the senses of all relational and
+ * directional methods inverted. The performance of ascending
+ * operations and views is likely to be faster than that of descending
+ * ones. This interface additionally defines methods {@link
+ * #pollFirst} and {@link #pollLast} that return and remove the lowest
+ * and highest element, if one exists, else returning {@code null}.
+ * Methods
+ * {@link #subSet(Object, boolean, Object, boolean) subSet(E, boolean, E, boolean)},
+ * {@link #headSet(Object, boolean) headSet(E, boolean)}, and
+ * {@link #tailSet(Object, boolean) tailSet(E, boolean)}
+ * differ from the like-named {@code SortedSet} methods in accepting
+ * additional arguments describing whether lower and upper bounds are
+ * inclusive versus exclusive. Subsets of any {@code NavigableSet}
+ * must implement the {@code NavigableSet} interface.
+ *
+ *
The return values of navigation methods may be ambiguous in
* implementations that permit {@code null} elements. However, even
* in this case the result can be disambiguated by checking
* {@code contains(null)}. To avoid such issues, implementations of
@@ -172,7 +176,7 @@ public interface NavigableSet extends SortedSet {
* the iteration are undefined.
*
* The returned set has an ordering equivalent to
- * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator()).
+ * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}{@code (comparator())}.
* The expression {@code s.descendingSet().descendingSet()} returns a
* view of {@code s} essentially equivalent to {@code s}.
*
diff --git a/jdk/src/java.base/share/classes/java/util/PriorityQueue.java b/jdk/src/java.base/share/classes/java/util/PriorityQueue.java
index cc1af05aa36..7c929bda6d1 100644
--- a/jdk/src/java.base/share/classes/java/util/PriorityQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/PriorityQueue.java
@@ -77,7 +77,7 @@ import java.util.function.Consumer;
*
* @since 1.5
* @author Josh Bloch, Doug Lea
- * @param the type of elements held in this collection
+ * @param the type of elements held in this queue
*/
public class PriorityQueue extends AbstractQueue
implements java.io.Serializable {
@@ -99,7 +99,7 @@ public class PriorityQueue extends AbstractQueue
/**
* The number of elements in the priority queue.
*/
- private int size = 0;
+ int size;
/**
* The comparator, or null if priority queue uses elements'
@@ -111,7 +111,7 @@ public class PriorityQueue extends AbstractQueue
* The number of times this priority queue has been
* structurally modified. See AbstractList for gory details.
*/
- transient int modCount = 0; // non-private to simplify nested class access
+ transient int modCount; // non-private to simplify nested class access
/**
* Creates a {@code PriorityQueue} with the default initial
@@ -448,7 +448,7 @@ public class PriorityQueue extends AbstractQueue
* The following code can be used to dump the queue into a newly
* allocated array of {@code String}:
*
- * {@code String[] y = x.toArray(new String[0]);}
+ * {@code String[] y = x.toArray(new String[0]);}
*
* Note that {@code toArray(new Object[0])} is identical in function to
* {@code toArray()}.
@@ -489,7 +489,7 @@ public class PriorityQueue extends AbstractQueue
* Index (into queue array) of element to be returned by
* subsequent call to next.
*/
- private int cursor = 0;
+ private int cursor;
/**
* Index of element returned by most recent call to next,
@@ -509,13 +509,13 @@ public class PriorityQueue extends AbstractQueue
* We expect that most iterations, even those involving removals,
* will not need to store elements in this field.
*/
- private ArrayDeque forgetMeNot = null;
+ private ArrayDeque forgetMeNot;
/**
* Element returned by the most recent call to next iff that
* element was drawn from the forgetMeNot list.
*/
- private E lastRetElt = null;
+ private E lastRetElt;
/**
* The modCount value that the iterator believes that the backing
@@ -609,7 +609,7 @@ public class PriorityQueue extends AbstractQueue
* avoid missing traversing elements.
*/
@SuppressWarnings("unchecked")
- private E removeAt(int i) {
+ E removeAt(int i) {
// assert i >= 0 && i < size;
modCount++;
int s = --size;
@@ -756,6 +756,7 @@ public class PriorityQueue extends AbstractQueue
* emitted (int), followed by all of its elements
* (each an {@code Object}) in the proper order.
* @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
*/
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
@@ -775,6 +776,9 @@ public class PriorityQueue extends AbstractQueue
* (that is, deserializes it).
*
* @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
@@ -822,9 +826,9 @@ public class PriorityQueue extends AbstractQueue
private int fence; // -1 until first use
private int expectedModCount; // initialized when fence set
- /** Creates new spliterator covering the given range */
+ /** Creates new spliterator covering the given range. */
PriorityQueueSpliterator(PriorityQueue pq, int origin, int fence,
- int expectedModCount) {
+ int expectedModCount) {
this.pq = pq;
this.index = origin;
this.fence = fence;
diff --git a/jdk/src/java.base/share/classes/java/util/Queue.java b/jdk/src/java.base/share/classes/java/util/Queue.java
index 975ea457142..b5456b99f2f 100644
--- a/jdk/src/java.base/share/classes/java/util/Queue.java
+++ b/jdk/src/java.base/share/classes/java/util/Queue.java
@@ -139,7 +139,7 @@ package java.util;
* @see java.util.concurrent.PriorityBlockingQueue
* @since 1.5
* @author Doug Lea
- * @param the type of elements held in this collection
+ * @param the type of elements held in this queue
*/
public interface Queue extends Collection {
/**
diff --git a/jdk/src/java.base/share/classes/java/util/SplittableRandom.java b/jdk/src/java.base/share/classes/java/util/SplittableRandom.java
index 285655d40c9..2e08a4ddb87 100644
--- a/jdk/src/java.base/share/classes/java/util/SplittableRandom.java
+++ b/jdk/src/java.base/share/classes/java/util/SplittableRandom.java
@@ -26,13 +26,13 @@
package java.util;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.DoubleConsumer;
import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
-import java.util.function.DoubleConsumer;
-import java.util.stream.StreamSupport;
+import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
-import java.util.stream.DoubleStream;
+import java.util.stream.StreamSupport;
/**
* A generator of uniform pseudorandom values applicable for use in
@@ -52,15 +52,15 @@ import java.util.stream.DoubleStream;
* types and ranges, but similar properties are expected to hold, at
* least approximately, for others as well. The period
* (length of any series of generated values before it repeats) is at
- * least 264.
+ * least 264.
*
- * Method {@link #split} constructs and returns a new
+ * Method {@link #split} constructs and returns a new
* SplittableRandom instance that shares no mutable state with the
* current instance. However, with very high probability, the
* values collectively generated by the two objects have the same
* statistical properties as if the same quantity of values were
* generated by a single thread using a single {@code
- * SplittableRandom} object.
+ * SplittableRandom} object.
*
* Instances of SplittableRandom are not thread-safe.
* They are designed to be split, not shared, across threads. For
@@ -71,7 +71,7 @@ import java.util.stream.DoubleStream;
*
* This class provides additional methods for generating random
* streams, that employ the above techniques when used in {@code
- * stream.parallel()} mode.
+ * stream.parallel()} mode.
*
*
*
@@ -240,9 +240,9 @@ public final class SplittableRandom {
}
// 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";
+ static final String BAD_BOUND = "bound must be positive";
+ static final String BAD_RANGE = "bound must be greater than origin";
+ static final String BAD_SIZE = "size must be non-negative";
/*
* Internal versions of nextX methods used by streams, as well as
@@ -416,7 +416,7 @@ public final class SplittableRandom {
*/
public int nextInt(int bound) {
if (bound <= 0)
- throw new IllegalArgumentException(BadBound);
+ throw new IllegalArgumentException(BAD_BOUND);
// Specialize internalNextInt for origin 0
int r = mix32(nextSeed());
int m = bound - 1;
@@ -444,7 +444,7 @@ public final class SplittableRandom {
*/
public int nextInt(int origin, int bound) {
if (origin >= bound)
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return internalNextInt(origin, bound);
}
@@ -468,7 +468,7 @@ public final class SplittableRandom {
*/
public long nextLong(long bound) {
if (bound <= 0)
- throw new IllegalArgumentException(BadBound);
+ throw new IllegalArgumentException(BAD_BOUND);
// Specialize internalNextLong for origin 0
long r = mix64(nextSeed());
long m = bound - 1;
@@ -496,7 +496,7 @@ public final class SplittableRandom {
*/
public long nextLong(long origin, long bound) {
if (origin >= bound)
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return internalNextLong(origin, bound);
}
@@ -522,7 +522,7 @@ public final class SplittableRandom {
*/
public double nextDouble(double bound) {
if (!(bound > 0.0))
- throw new IllegalArgumentException(BadBound);
+ throw new IllegalArgumentException(BAD_BOUND);
double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound;
return (result < bound) ? result : // correct for rounding
Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
@@ -541,7 +541,7 @@ public final class SplittableRandom {
*/
public double nextDouble(double origin, double bound) {
if (!(origin < bound))
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return internalNextDouble(origin, bound);
}
@@ -569,7 +569,7 @@ public final class SplittableRandom {
*/
public IntStream ints(long streamSize) {
if (streamSize < 0L)
- throw new IllegalArgumentException(BadSize);
+ throw new IllegalArgumentException(BAD_SIZE);
return StreamSupport.intStream
(new RandomIntsSpliterator
(this, 0L, streamSize, Integer.MAX_VALUE, 0),
@@ -610,9 +610,9 @@ public final class SplittableRandom {
public IntStream ints(long streamSize, int randomNumberOrigin,
int randomNumberBound) {
if (streamSize < 0L)
- throw new IllegalArgumentException(BadSize);
+ throw new IllegalArgumentException(BAD_SIZE);
if (randomNumberOrigin >= randomNumberBound)
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return StreamSupport.intStream
(new RandomIntsSpliterator
(this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
@@ -636,7 +636,7 @@ public final class SplittableRandom {
*/
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
if (randomNumberOrigin >= randomNumberBound)
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return StreamSupport.intStream
(new RandomIntsSpliterator
(this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
@@ -655,7 +655,7 @@ public final class SplittableRandom {
*/
public LongStream longs(long streamSize) {
if (streamSize < 0L)
- throw new IllegalArgumentException(BadSize);
+ throw new IllegalArgumentException(BAD_SIZE);
return StreamSupport.longStream
(new RandomLongsSpliterator
(this, 0L, streamSize, Long.MAX_VALUE, 0L),
@@ -696,9 +696,9 @@ public final class SplittableRandom {
public LongStream longs(long streamSize, long randomNumberOrigin,
long randomNumberBound) {
if (streamSize < 0L)
- throw new IllegalArgumentException(BadSize);
+ throw new IllegalArgumentException(BAD_SIZE);
if (randomNumberOrigin >= randomNumberBound)
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return StreamSupport.longStream
(new RandomLongsSpliterator
(this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
@@ -722,7 +722,7 @@ public final class SplittableRandom {
*/
public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
if (randomNumberOrigin >= randomNumberBound)
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return StreamSupport.longStream
(new RandomLongsSpliterator
(this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
@@ -741,7 +741,7 @@ public final class SplittableRandom {
*/
public DoubleStream doubles(long streamSize) {
if (streamSize < 0L)
- throw new IllegalArgumentException(BadSize);
+ throw new IllegalArgumentException(BAD_SIZE);
return StreamSupport.doubleStream
(new RandomDoublesSpliterator
(this, 0L, streamSize, Double.MAX_VALUE, 0.0),
@@ -784,9 +784,9 @@ public final class SplittableRandom {
public DoubleStream doubles(long streamSize, double randomNumberOrigin,
double randomNumberBound) {
if (streamSize < 0L)
- throw new IllegalArgumentException(BadSize);
+ throw new IllegalArgumentException(BAD_SIZE);
if (!(randomNumberOrigin < randomNumberBound))
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return StreamSupport.doubleStream
(new RandomDoublesSpliterator
(this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
@@ -810,7 +810,7 @@ public final class SplittableRandom {
*/
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
if (!(randomNumberOrigin < randomNumberBound))
- throw new IllegalArgumentException(BadRange);
+ throw new IllegalArgumentException(BAD_RANGE);
return StreamSupport.doubleStream
(new RandomDoublesSpliterator
(this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
@@ -825,7 +825,8 @@ public final class SplittableRandom {
* approach. The long and double versions of this class are
* identical except for types.
*/
- static final class RandomIntsSpliterator implements Spliterator.OfInt {
+ private static final class RandomIntsSpliterator
+ implements Spliterator.OfInt {
final SplittableRandom rng;
long index;
final long fence;
@@ -880,7 +881,8 @@ public final class SplittableRandom {
/**
* Spliterator for long streams.
*/
- static final class RandomLongsSpliterator implements Spliterator.OfLong {
+ private static final class RandomLongsSpliterator
+ implements Spliterator.OfLong {
final SplittableRandom rng;
long index;
final long fence;
@@ -936,7 +938,8 @@ public final class SplittableRandom {
/**
* Spliterator for double streams.
*/
- static final class RandomDoublesSpliterator implements Spliterator.OfDouble {
+ private static final class RandomDoublesSpliterator
+ implements Spliterator.OfDouble {
final SplittableRandom rng;
long index;
final long fence;
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java b/jdk/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
index 73aa047ca30..e4d22357190 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
@@ -34,7 +34,13 @@
*/
package java.util.concurrent;
-import java.util.*;
+
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
/**
* Provides default implementations of {@link ExecutorService}
@@ -51,7 +57,7 @@ import java.util.*;
* Extension example. Here is a sketch of a class
* that customizes {@link ThreadPoolExecutor} to use
* a {@code CustomTask} class instead of the default {@code FutureTask}:
- *
{@code
+ * {@code
* public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
*
* static class CustomTask implements RunnableFuture {...}
@@ -146,7 +152,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
int ntasks = tasks.size();
if (ntasks == 0)
throw new IllegalArgumentException();
- ArrayList> futures = new ArrayList>(ntasks);
+ ArrayList> futures = new ArrayList<>(ntasks);
ExecutorCompletionService ecs =
new ExecutorCompletionService(this);
@@ -179,7 +185,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
else if (active == 0)
break;
else if (timed) {
- f = ecs.poll(nanos, TimeUnit.NANOSECONDS);
+ f = ecs.poll(nanos, NANOSECONDS);
if (f == null)
throw new TimeoutException();
nanos = deadline - System.nanoTime();
@@ -204,8 +210,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
throw ee;
} finally {
- for (int i = 0, size = futures.size(); i < size; i++)
- futures.get(i).cancel(true);
+ cancelAll(futures);
}
}
@@ -229,8 +234,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
throws InterruptedException {
if (tasks == null)
throw new NullPointerException();
- ArrayList> futures = new ArrayList>(tasks.size());
- boolean done = false;
+ ArrayList> futures = new ArrayList<>(tasks.size());
try {
for (Callable t : tasks) {
RunnableFuture f = newTaskFor(t);
@@ -240,19 +244,15 @@ public abstract class AbstractExecutorService implements ExecutorService {
for (int i = 0, size = futures.size(); i < size; i++) {
Future f = futures.get(i);
if (!f.isDone()) {
- try {
- f.get();
- } catch (CancellationException ignore) {
- } catch (ExecutionException ignore) {
- }
+ try { f.get(); }
+ catch (CancellationException ignore) {}
+ catch (ExecutionException ignore) {}
}
}
- done = true;
return futures;
- } finally {
- if (!done)
- for (int i = 0, size = futures.size(); i < size; i++)
- futures.get(i).cancel(true);
+ } catch (Throwable t) {
+ cancelAll(futures);
+ throw t;
}
}
@@ -261,47 +261,52 @@ public abstract class AbstractExecutorService implements ExecutorService {
throws InterruptedException {
if (tasks == null)
throw new NullPointerException();
- long nanos = unit.toNanos(timeout);
- ArrayList> futures = new ArrayList>(tasks.size());
- boolean done = false;
- try {
+ final long nanos = unit.toNanos(timeout);
+ final long deadline = System.nanoTime() + nanos;
+ ArrayList> futures = new ArrayList<>(tasks.size());
+ int j = 0;
+ timedOut: try {
for (Callable t : tasks)
futures.add(newTaskFor(t));
- final long deadline = System.nanoTime() + nanos;
final int size = futures.size();
// Interleave time checks and calls to execute in case
// executor doesn't have any/much parallelism.
for (int i = 0; i < size; i++) {
+ if (((i == 0) ? nanos : deadline - System.nanoTime()) <= 0L)
+ break timedOut;
execute((Runnable)futures.get(i));
- nanos = deadline - System.nanoTime();
- if (nanos <= 0L)
- return futures;
}
- for (int i = 0; i < size; i++) {
- Future f = futures.get(i);
+ for (; j < size; j++) {
+ Future f = futures.get(j);
if (!f.isDone()) {
- if (nanos <= 0L)
- return futures;
- try {
- f.get(nanos, TimeUnit.NANOSECONDS);
- } catch (CancellationException ignore) {
- } catch (ExecutionException ignore) {
- } catch (TimeoutException toe) {
- return futures;
+ try { f.get(deadline - System.nanoTime(), NANOSECONDS); }
+ catch (CancellationException ignore) {}
+ catch (ExecutionException ignore) {}
+ catch (TimeoutException timedOut) {
+ break timedOut;
}
- nanos = deadline - System.nanoTime();
}
}
- done = true;
return futures;
- } finally {
- if (!done)
- for (int i = 0, size = futures.size(); i < size; i++)
- futures.get(i).cancel(true);
+ } catch (Throwable t) {
+ cancelAll(futures);
+ throw t;
}
+ // Timed out before all the tasks could be completed; cancel remaining
+ cancelAll(futures, j);
+ return futures;
}
+ private static void cancelAll(ArrayList> futures) {
+ cancelAll(futures, 0);
+ }
+
+ /** Cancels all futures with index at least j. */
+ private static void cancelAll(ArrayList> futures, int j) {
+ for (int size = futures.size(); j < size; j++)
+ futures.get(j).cancel(true);
+ }
}
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java
index a8f27ec8216..319a0bfc0e8 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java
@@ -34,15 +34,18 @@
*/
package java.util.concurrent;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+
+import java.lang.ref.WeakReference;
import java.util.AbstractQueue;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import java.lang.ref.WeakReference;
-import java.util.Spliterators;
+import java.util.Objects;
import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
/**
* A bounded {@linkplain BlockingQueue blocking queue} backed by an
@@ -77,7 +80,7 @@ import java.util.Spliterator;
*
* @since 1.5
* @author Doug Lea
- * @param the type of elements held in this collection
+ * @param the type of elements held in this queue
*/
public class ArrayBlockingQueue extends AbstractQueue
implements BlockingQueue, java.io.Serializable {
@@ -121,12 +124,12 @@ public class ArrayBlockingQueue extends AbstractQueue
* are known not to be any. Allows queue operations to update
* iterator state.
*/
- transient Itrs itrs = null;
+ transient Itrs itrs;
// Internal helper methods
/**
- * Circularly decrement i.
+ * Circularly decrements array index i.
*/
final int dec(int i) {
return ((i == 0) ? items.length : i) - 1;
@@ -140,16 +143,6 @@ public class ArrayBlockingQueue extends AbstractQueue
return (E) items[i];
}
- /**
- * Throws NullPointerException if argument is null.
- *
- * @param v the element
- */
- private static void checkNotNull(Object v) {
- if (v == null)
- throw new NullPointerException();
- }
-
/**
* Inserts element at current put position, advances, and signals.
* Call only when holding lock.
@@ -159,8 +152,7 @@ public class ArrayBlockingQueue extends AbstractQueue
// assert items[putIndex] == null;
final Object[] items = this.items;
items[putIndex] = x;
- if (++putIndex == items.length)
- putIndex = 0;
+ if (++putIndex == items.length) putIndex = 0;
count++;
notEmpty.signal();
}
@@ -176,8 +168,7 @@ public class ArrayBlockingQueue extends AbstractQueue
@SuppressWarnings("unchecked")
E x = (E) items[takeIndex];
items[takeIndex] = null;
- if (++takeIndex == items.length)
- takeIndex = 0;
+ if (++takeIndex == items.length) takeIndex = 0;
count--;
if (itrs != null)
itrs.elementDequeued();
@@ -198,8 +189,7 @@ public class ArrayBlockingQueue extends AbstractQueue
if (removeIndex == takeIndex) {
// removing front item; just advance
items[takeIndex] = null;
- if (++takeIndex == items.length)
- takeIndex = 0;
+ if (++takeIndex == items.length) takeIndex = 0;
count--;
if (itrs != null)
itrs.elementDequeued();
@@ -207,19 +197,15 @@ public class ArrayBlockingQueue extends AbstractQueue
// an "interior" remove
// slide over all others up through putIndex.
- final int putIndex = this.putIndex;
- for (int i = removeIndex;;) {
- int next = i + 1;
- if (next == items.length)
- next = 0;
- if (next != putIndex) {
- items[i] = items[next];
- i = next;
- } else {
- items[i] = null;
- this.putIndex = i;
+ for (int i = removeIndex, putIndex = this.putIndex;;) {
+ int pred = i;
+ if (++i == items.length) i = 0;
+ if (i == putIndex) {
+ items[pred] = null;
+ this.putIndex = pred;
break;
}
+ items[pred] = items[i];
}
count--;
if (itrs != null)
@@ -283,10 +269,8 @@ public class ArrayBlockingQueue extends AbstractQueue
try {
int i = 0;
try {
- for (E e : c) {
- checkNotNull(e);
- items[i++] = e;
- }
+ for (E e : c)
+ items[i++] = Objects.requireNonNull(e);
} catch (ArrayIndexOutOfBoundsException ex) {
throw new IllegalArgumentException();
}
@@ -322,7 +306,7 @@ public class ArrayBlockingQueue extends AbstractQueue
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
- checkNotNull(e);
+ Objects.requireNonNull(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
@@ -345,7 +329,7 @@ public class ArrayBlockingQueue extends AbstractQueue
* @throws NullPointerException {@inheritDoc}
*/
public void put(E e) throws InterruptedException {
- checkNotNull(e);
+ Objects.requireNonNull(e);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
@@ -368,13 +352,13 @@ public class ArrayBlockingQueue extends AbstractQueue
public boolean offer(E e, long timeout, TimeUnit unit)
throws InterruptedException {
- checkNotNull(e);
+ Objects.requireNonNull(e);
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
while (count == items.length) {
- if (nanos <= 0)
+ if (nanos <= 0L)
return false;
nanos = notFull.awaitNanos(nanos);
}
@@ -413,7 +397,7 @@ public class ArrayBlockingQueue extends AbstractQueue
lock.lockInterruptibly();
try {
while (count == 0) {
- if (nanos <= 0)
+ if (nanos <= 0L)
return null;
nanos = notEmpty.awaitNanos(nanos);
}
@@ -492,11 +476,11 @@ public class ArrayBlockingQueue extends AbstractQueue
*/
public boolean remove(Object o) {
if (o == null) return false;
- final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (count > 0) {
+ final Object[] items = this.items;
final int putIndex = this.putIndex;
int i = takeIndex;
do {
@@ -504,8 +488,7 @@ public class ArrayBlockingQueue extends AbstractQueue
removeAt(i);
return true;
}
- if (++i == items.length)
- i = 0;
+ if (++i == items.length) i = 0;
} while (i != putIndex);
}
return false;
@@ -524,18 +507,17 @@ public class ArrayBlockingQueue extends AbstractQueue
*/
public boolean contains(Object o) {
if (o == null) return false;
- final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (count > 0) {
+ final Object[] items = this.items;
final int putIndex = this.putIndex;
int i = takeIndex;
do {
if (o.equals(items[i]))
return true;
- if (++i == items.length)
- i = 0;
+ if (++i == items.length) i = 0;
} while (i != putIndex);
}
return false;
@@ -558,23 +540,18 @@ public class ArrayBlockingQueue extends AbstractQueue
* @return an array containing all of the elements in this queue
*/
public Object[] toArray() {
- Object[] a;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- final int count = this.count;
- a = new Object[count];
- int n = items.length - takeIndex;
- if (count <= n)
- System.arraycopy(items, takeIndex, a, 0, count);
- else {
- System.arraycopy(items, takeIndex, a, 0, n);
- System.arraycopy(items, 0, a, n, count - n);
- }
+ final Object[] items = this.items;
+ final int end = takeIndex + count;
+ final Object[] a = Arrays.copyOfRange(items, takeIndex, end);
+ if (end != putIndex)
+ System.arraycopy(items, 0, a, items.length - takeIndex, putIndex);
+ return a;
} finally {
lock.unlock();
}
- return a;
}
/**
@@ -598,7 +575,7 @@ public class ArrayBlockingQueue extends AbstractQueue
* The following code can be used to dump the queue into a newly
* allocated array of {@code String}:
*
- * {@code String[] y = x.toArray(new String[0]);}
+ * {@code String[] y = x.toArray(new String[0]);}
*
* Note that {@code toArray(new Object[0])} is identical in function to
* {@code toArray()}.
@@ -614,53 +591,30 @@ public class ArrayBlockingQueue extends AbstractQueue
*/
@SuppressWarnings("unchecked")
public T[] toArray(T[] a) {
- final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
+ final Object[] items = this.items;
final int count = this.count;
- final int len = a.length;
- if (len < count)
- a = (T[])java.lang.reflect.Array.newInstance(
- a.getClass().getComponentType(), count);
- int n = items.length - takeIndex;
- if (count <= n)
- System.arraycopy(items, takeIndex, a, 0, count);
- else {
- System.arraycopy(items, takeIndex, a, 0, n);
- System.arraycopy(items, 0, a, n, count - n);
+ final int firstLeg = Math.min(items.length - takeIndex, count);
+ if (a.length < count) {
+ a = (T[]) Arrays.copyOfRange(items, takeIndex, takeIndex + count,
+ a.getClass());
+ } else {
+ System.arraycopy(items, takeIndex, a, 0, firstLeg);
+ if (a.length > count)
+ a[count] = null;
}
- if (len > count)
- a[count] = null;
+ if (firstLeg < count)
+ System.arraycopy(items, 0, a, firstLeg, putIndex);
+ return a;
} finally {
lock.unlock();
}
- return a;
}
public String toString() {
- final ReentrantLock lock = this.lock;
- lock.lock();
- try {
- int k = count;
- if (k == 0)
- return "[]";
-
- final Object[] items = this.items;
- StringBuilder sb = new StringBuilder();
- sb.append('[');
- for (int i = takeIndex; ; ) {
- Object e = items[i];
- sb.append(e == this ? "(this Collection)" : e);
- if (--k == 0)
- return sb.append(']').toString();
- sb.append(',').append(' ');
- if (++i == items.length)
- i = 0;
- }
- } finally {
- lock.unlock();
- }
+ return Helpers.collectionToString(this);
}
/**
@@ -668,18 +622,17 @@ public class ArrayBlockingQueue extends AbstractQueue
* The queue will be empty after this call returns.
*/
public void clear() {
- final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
int k = count;
if (k > 0) {
+ final Object[] items = this.items;
final int putIndex = this.putIndex;
int i = takeIndex;
do {
items[i] = null;
- if (++i == items.length)
- i = 0;
+ if (++i == items.length) i = 0;
} while (i != putIndex);
takeIndex = putIndex;
count = 0;
@@ -710,7 +663,7 @@ public class ArrayBlockingQueue extends AbstractQueue
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection super E> c, int maxElements) {
- checkNotNull(c);
+ Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
if (maxElements <= 0)
@@ -728,8 +681,7 @@ public class ArrayBlockingQueue extends AbstractQueue
E x = (E) items[take];
c.add(x);
items[take] = null;
- if (++take == items.length)
- take = 0;
+ if (++take == items.length) take = 0;
i++;
}
return n;
@@ -832,13 +784,13 @@ public class ArrayBlockingQueue extends AbstractQueue
}
/** Incremented whenever takeIndex wraps around to 0 */
- int cycles = 0;
+ int cycles;
/** Linked list of weak iterator references */
private Node head;
/** Used to expunge stale iterators */
- private Node sweeper = null;
+ private Node sweeper;
private static final int SHORT_SWEEP_PROBES = 4;
private static final int LONG_SWEEP_PROBES = 16;
@@ -1095,10 +1047,8 @@ public class ArrayBlockingQueue extends AbstractQueue
private int incCursor(int index) {
// assert lock.getHoldCount() == 1;
- if (++index == items.length)
- index = 0;
- if (index == putIndex)
- index = NONE;
+ if (++index == items.length) index = 0;
+ if (index == putIndex) index = NONE;
return index;
}
@@ -1314,17 +1264,18 @@ public class ArrayBlockingQueue extends AbstractQueue
if (isDetached())
return true;
- final int cycles = itrs.cycles;
final int takeIndex = ArrayBlockingQueue.this.takeIndex;
- final int prevCycles = this.prevCycles;
final int prevTakeIndex = this.prevTakeIndex;
final int len = items.length;
- int cycleDiff = cycles - prevCycles;
- if (removedIndex < takeIndex)
- cycleDiff++;
+ // distance from prevTakeIndex to removedIndex
final int removedDistance =
- (cycleDiff * len) + (removedIndex - prevTakeIndex);
- // assert removedDistance >= 0;
+ len * (itrs.cycles - this.prevCycles
+ + ((removedIndex < takeIndex) ? 1 : 0))
+ + (removedIndex - prevTakeIndex);
+ // assert itrs.cycles - this.prevCycles >= 0;
+ // assert itrs.cycles - this.prevCycles <= 1;
+ // assert removedDistance > 0;
+ // assert removedIndex != takeIndex;
int cursor = this.cursor;
if (cursor >= 0) {
int x = distance(cursor, prevTakeIndex, len);
@@ -1353,7 +1304,7 @@ public class ArrayBlockingQueue extends AbstractQueue
else if (x > removedDistance)
this.nextIndex = nextIndex = dec(nextIndex);
}
- else if (cursor < 0 && nextIndex < 0 && lastRet < 0) {
+ if (cursor < 0 && nextIndex < 0 && lastRet < 0) {
this.prevTakeIndex = DETACHED;
return true;
}
@@ -1410,8 +1361,9 @@ public class ArrayBlockingQueue extends AbstractQueue
*/
public Spliterator spliterator() {
return Spliterators.spliterator
- (this, Spliterator.ORDERED | Spliterator.NONNULL |
- Spliterator.CONCURRENT);
+ (this, (Spliterator.ORDERED |
+ Spliterator.NONNULL |
+ Spliterator.CONCURRENT));
}
}
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java
index 0a26fa8dee9..27b05bf711b 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java
@@ -34,7 +34,10 @@
*/
package java.util.concurrent;
-import java.util.*;
+
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
/**
* A {@link Deque} that additionally supports blocking operations that wait
@@ -195,7 +198,7 @@ import java.util.*;
*
* @since 1.6
* @author Doug Lea
- * @param the type of elements held in this collection
+ * @param the type of elements held in this deque
*/
public interface BlockingDeque extends BlockingQueue, Deque {
/*
@@ -401,9 +404,9 @@ public interface BlockingDeque extends BlockingQueue, Deque {
* @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null
- * (optional)
+ * (optional)
*/
boolean removeFirstOccurrence(Object o);
@@ -419,9 +422,9 @@ public interface BlockingDeque extends BlockingQueue, Deque {
* @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null
- * (optional)
+ * (optional)
*/
boolean removeLastOccurrence(Object o);
@@ -596,9 +599,9 @@ public interface BlockingDeque extends BlockingQueue, Deque {
* @return {@code true} if this deque changed as a result of the call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null
- * (optional)
+ * (optional)
*/
boolean remove(Object o);
@@ -611,18 +614,18 @@ public interface BlockingDeque extends BlockingQueue, Deque {
* @return {@code true} if this deque contains the specified element
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null
- * (optional)
+ * (optional)
*/
- public boolean contains(Object o);
+ boolean contains(Object o);
/**
* Returns the number of elements in this deque.
*
* @return the number of elements in this deque
*/
- public int size();
+ int size();
/**
* Returns an iterator over the elements in this deque in proper sequence.
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java
index 3d097079f6b..03ca56d8791 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java
@@ -127,7 +127,7 @@ import java.util.Queue;
* Usage example, based on a typical producer-consumer scenario.
* Note that a {@code BlockingQueue} can safely be used with multiple
* producers and multiple consumers.
- * {@code
+ * {@code
* class Producer implements Runnable {
* private final BlockingQueue queue;
* Producer(BlockingQueue q) { queue = q; }
@@ -175,7 +175,7 @@ import java.util.Queue;
*
* @since 1.5
* @author Doug Lea
- * @param the type of elements held in this collection
+ * @param the type of elements held in this queue
*/
public interface BlockingQueue extends Queue {
/**
@@ -303,9 +303,9 @@ public interface BlockingQueue extends Queue {
* @return {@code true} if this queue changed as a result of the call
* @throws ClassCastException if the class of the specified element
* is incompatible with this queue
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null
- * (optional)
+ * (optional)
*/
boolean remove(Object o);
@@ -318,11 +318,11 @@ public interface BlockingQueue extends Queue {
* @return {@code true} if this queue contains the specified element
* @throws ClassCastException if the class of the specified element
* is incompatible with this queue
- * (optional)
+ * (optional)
* @throws NullPointerException if the specified element is null
- * (optional)
+ * (optional)
*/
- public boolean contains(Object o);
+ boolean contains(Object o);
/**
* Removes all available elements from this queue and adds them
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java b/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java
index 955daabedc0..ee553e8f261 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java
@@ -34,23 +34,13 @@
*/
package java.util.concurrent;
-import java.util.function.Supplier;
-import java.util.function.Consumer;
-import java.util.function.BiConsumer;
-import java.util.function.Function;
-import java.util.function.BiFunction;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.ForkJoinTask;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletionException;
-import java.util.concurrent.CompletionStage;
+
import java.util.concurrent.locks.LockSupport;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
/**
* A {@link Future} that may be explicitly completed (setting its
@@ -71,19 +61,32 @@ import java.util.concurrent.locks.LockSupport;
* Actions supplied for dependent completions of
* non-async methods may be performed by the thread that
* completes the current CompletableFuture, or by any other caller of
- * a completion method.
+ * a completion method.
*
* All async methods without an explicit Executor
* argument are performed using the {@link ForkJoinPool#commonPool()}
* (unless it does not support a parallelism level of at least two, in
- * which case, a new Thread is created to run each task). To simplify
- * monitoring, debugging, and tracking, all generated asynchronous
- * tasks are instances of the marker interface {@link
- * AsynchronousCompletionTask}.
+ * which case, a new Thread is created to run each task). This may be
+ * overridden for non-static methods in subclasses by defining method
+ * {@link #defaultExecutor()}. To simplify monitoring, debugging,
+ * and tracking, all generated asynchronous tasks are instances of the
+ * marker interface {@link AsynchronousCompletionTask}. Operations
+ * with time-delays can use adapter methods defined in this class, for
+ * example: {@code supplyAsync(supplier, delayedExecutor(timeout,
+ * timeUnit))}. To support methods with delays and timeouts, this
+ * class maintains at most one daemon thread for triggering and
+ * cancelling actions, not for running them.
*
* All CompletionStage methods are implemented independently of
* other public methods, so the behavior of one method is not impacted
- * by overrides of others in subclasses.
+ * by overrides of others in subclasses.
+ *
+ * All CompletionStage methods return CompletableFutures. To
+ * restrict usages to only those methods defined in interface
+ * CompletionStage, use method {@link #minimalCompletionStage}. Or to
+ * ensure only that clients do not themselves modify a future, use
+ * method {@link #copy}.
+ *
*
* CompletableFuture also implements {@link Future} with the following
* policies:
@@ -94,7 +97,7 @@ import java.util.concurrent.locks.LockSupport;
* completion. Method {@link #cancel cancel} has the same effect as
* {@code completeExceptionally(new CancellationException())}. Method
* {@link #isCompletedExceptionally} can be used to determine if a
- * CompletableFuture completed in any exceptional fashion.
+ * CompletableFuture completed in any exceptional fashion.
*
* In case of exceptional completion with a CompletionException,
* methods {@link #get()} and {@link #get(long, TimeUnit)} throw an
@@ -102,10 +105,38 @@ import java.util.concurrent.locks.LockSupport;
* corresponding CompletionException. To simplify usage in most
* contexts, this class also defines methods {@link #join()} and
* {@link #getNow} that instead throw the CompletionException directly
- * in these cases.
+ * in these cases.
+ *
+ *
+ * Arguments used to pass a completion result (that is, for
+ * parameters of type {@code T}) for methods accepting them may be
+ * null, but passing a null value for any other parameter will result
+ * in a {@link NullPointerException} being thrown.
+ *
+ *
Subclasses of this class should normally override the "virtual
+ * constructor" method {@link #newIncompleteFuture}, which establishes
+ * the concrete type returned by CompletionStage methods. For example,
+ * here is a class that substitutes a different default Executor and
+ * disables the {@code obtrude} methods:
+ *
+ *
{@code
+ * class MyCompletableFuture extends CompletableFuture {
+ * static final Executor myExecutor = ...;
+ * public MyCompletableFuture() { }
+ * public CompletableFuture newIncompleteFuture() {
+ * return new MyCompletableFuture(); }
+ * public Executor defaultExecutor() {
+ * return myExecutor; }
+ * public void obtrudeValue(T value) {
+ * throw new UnsupportedOperationException(); }
+ * public void obtrudeException(Throwable ex) {
+ * throw new UnsupportedOperationException(); }
+ * }}
*
* @author Doug Lea
* @since 1.8
+ * @param The result type returned by this future's {@code join}
+ * and {@code get} methods
*/
public class CompletableFuture implements Future, CompletionStage {
@@ -150,9 +181,7 @@ public class CompletableFuture implements Future, CompletionStage {
* fields for source(s), actions, and dependent. They are
* boringly similar, differing from others only with respect to
* underlying functional forms. We do this so that users don't
- * encounter layers of adaptors in common usages. We also
- * include "Relay" classes/methods that don't correspond to user
- * methods; they copy results from one stage to another.
+ * encounter layers of adapters in common usages.
*
* * Boolean CompletableFuture method x(...) (for example
* uniApply) takes all of the arguments needed to check that an
@@ -219,18 +248,18 @@ public class CompletableFuture implements Future, CompletionStage {
volatile Completion stack; // Top of Treiber stack of dependent actions
final boolean internalComplete(Object r) { // CAS from null to r
- return UNSAFE.compareAndSwapObject(this, RESULT, null, r);
+ return U.compareAndSwapObject(this, RESULT, null, r);
}
final boolean casStack(Completion cmp, Completion val) {
- return UNSAFE.compareAndSwapObject(this, STACK, cmp, val);
+ return U.compareAndSwapObject(this, STACK, cmp, val);
}
/** Returns true if successfully pushed c onto stack. */
final boolean tryPushStack(Completion c) {
Completion h = stack;
lazySetNext(c, h);
- return UNSAFE.compareAndSwapObject(this, STACK, h, c);
+ return U.compareAndSwapObject(this, STACK, h, c);
}
/** Unconditionally pushes c onto stack, retrying if necessary. */
@@ -250,8 +279,8 @@ public class CompletableFuture implements Future, CompletionStage {
/** Completes with the null value, unless already completed. */
final boolean completeNull() {
- return UNSAFE.compareAndSwapObject(this, RESULT, null,
- NIL);
+ return U.compareAndSwapObject(this, RESULT, null,
+ NIL);
}
/** Returns the encoding of the given non-exceptional value. */
@@ -261,8 +290,8 @@ public class CompletableFuture implements Future, CompletionStage {
/** Completes with a non-exceptional result, unless already completed. */
final boolean completeValue(T t) {
- return UNSAFE.compareAndSwapObject(this, RESULT, null,
- (t == null) ? NIL : t);
+ return U.compareAndSwapObject(this, RESULT, null,
+ (t == null) ? NIL : t);
}
/**
@@ -276,8 +305,8 @@ public class CompletableFuture implements Future, CompletionStage {
/** Completes with an exceptional result, unless already completed. */
final boolean completeThrowable(Throwable x) {
- return UNSAFE.compareAndSwapObject(this, RESULT, null,
- encodeThrowable(x));
+ return U.compareAndSwapObject(this, RESULT, null,
+ encodeThrowable(x));
}
/**
@@ -304,8 +333,8 @@ public class CompletableFuture implements Future, CompletionStage {
* existing CompletionException.
*/
final boolean completeThrowable(Throwable x, Object r) {
- return UNSAFE.compareAndSwapObject(this, RESULT, null,
- encodeThrowable(x, r));
+ return U.compareAndSwapObject(this, RESULT, null,
+ encodeThrowable(x, r));
}
/**
@@ -334,8 +363,8 @@ public class CompletableFuture implements Future, CompletionStage {
* If exceptional, r is first coerced to a CompletionException.
*/
final boolean completeRelay(Object r) {
- return UNSAFE.compareAndSwapObject(this, RESULT, null,
- encodeRelay(r));
+ return U.compareAndSwapObject(this, RESULT, null,
+ encodeRelay(r));
}
/**
@@ -390,14 +419,14 @@ public class CompletableFuture implements Future