提交 fc9949fb 编写于 作者: V vinnie

Merge

...@@ -1675,10 +1675,18 @@ class SecurityManager { ...@@ -1675,10 +1675,18 @@ class SecurityManager {
* permission to access members. * permission to access members.
* @exception NullPointerException if the <code>clazz</code> argument is * @exception NullPointerException if the <code>clazz</code> argument is
* <code>null</code>. * <code>null</code>.
*
* @deprecated This method relies on the caller being at a stack depth
* of 4 which is error-prone and cannot be enforced by the runtime.
* Users of this method should instead invoke {@link #checkPermission}
* directly. This method will be changed in a future release
* to check the permission {@code java.security.AllPermission}.
*
* @see java.lang.reflect.Member * @see java.lang.reflect.Member
* @since JDK1.1 * @since JDK1.1
* @see #checkPermission(java.security.Permission) checkPermission * @see #checkPermission(java.security.Permission) checkPermission
*/ */
@Deprecated
@CallerSensitive @CallerSensitive
public void checkMemberAccess(Class<?> clazz, int which) { public void checkMemberAccess(Class<?> clazz, int which) {
if (clazz == null) { if (clazz == null) {
......
/* /*
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -363,6 +363,8 @@ public interface Instrumentation { ...@@ -363,6 +363,8 @@ public interface Instrumentation {
* Primitive classes (for example, <code>java.lang.Integer.TYPE</code>) * Primitive classes (for example, <code>java.lang.Integer.TYPE</code>)
* and array classes are never modifiable. * and array classes are never modifiable.
* *
* @param theClass the class to check for being modifiable
* @return whether or not the argument class is modifiable
* @throws java.lang.NullPointerException if the specified class is <code>null</code>. * @throws java.lang.NullPointerException if the specified class is <code>null</code>.
* *
* @see #retransformClasses * @see #retransformClasses
...@@ -549,14 +551,14 @@ public interface Instrumentation { ...@@ -549,14 +551,14 @@ public interface Instrumentation {
* {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer}, * {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer},
* it enables native methods to be * it enables native methods to be
* instrumented. * instrumented.
* <p/> * <p>
* Since native methods cannot be directly instrumented * Since native methods cannot be directly instrumented
* (they have no bytecodes), they must be wrapped with * (they have no bytecodes), they must be wrapped with
* a non-native method which can be instrumented. * a non-native method which can be instrumented.
* For example, if we had: * For example, if we had:
* <pre> * <pre>
* native boolean foo(int x);</pre> * native boolean foo(int x);</pre>
* <p/> * <p>
* We could transform the class file (with the * We could transform the class file (with the
* ClassFileTransformer during the initial definition * ClassFileTransformer during the initial definition
* of the class) so that this becomes: * of the class) so that this becomes:
...@@ -567,14 +569,14 @@ public interface Instrumentation { ...@@ -567,14 +569,14 @@ public interface Instrumentation {
* } * }
* *
* native boolean wrapped_foo(int x);</pre> * native boolean wrapped_foo(int x);</pre>
* <p/> * <p>
* Where <code>foo</code> becomes a wrapper for the actual native * Where <code>foo</code> becomes a wrapper for the actual native
* method with the appended prefix "wrapped_". Note that * method with the appended prefix "wrapped_". Note that
* "wrapped_" would be a poor choice of prefix since it * "wrapped_" would be a poor choice of prefix since it
* might conceivably form the name of an existing method * might conceivably form the name of an existing method
* thus something like "$$$MyAgentWrapped$$$_" would be * thus something like "$$$MyAgentWrapped$$$_" would be
* better but would make these examples less readable. * better but would make these examples less readable.
* <p/> * <p>
* The wrapper will allow data to be collected on the native * The wrapper will allow data to be collected on the native
* method call, but now the problem becomes linking up the * method call, but now the problem becomes linking up the
* wrapped method with the native implementation. * wrapped method with the native implementation.
...@@ -583,7 +585,7 @@ public interface Instrumentation { ...@@ -583,7 +585,7 @@ public interface Instrumentation {
* which might be: * which might be:
* <pre> * <pre>
* Java_somePackage_someClass_foo(JNIEnv* env, jint x)</pre> * Java_somePackage_someClass_foo(JNIEnv* env, jint x)</pre>
* <p/> * <p>
* This function allows the prefix to be specified and the * This function allows the prefix to be specified and the
* proper resolution to occur. * proper resolution to occur.
* Specifically, when the standard resolution fails, the * Specifically, when the standard resolution fails, the
...@@ -596,29 +598,29 @@ public interface Instrumentation { ...@@ -596,29 +598,29 @@ public interface Instrumentation {
* <pre>{@code * <pre>{@code
* method(foo) -> nativeImplementation(foo) * method(foo) -> nativeImplementation(foo)
* }</pre> * }</pre>
* <p/> * <p>
* When this fails, the resolution will be retried with * When this fails, the resolution will be retried with
* the specified prefix prepended to the method name, * the specified prefix prepended to the method name,
* yielding the correct resolution: * yielding the correct resolution:
* <pre>{@code * <pre>{@code
* method(wrapped_foo) -> nativeImplementation(foo) * method(wrapped_foo) -> nativeImplementation(foo)
* }</pre> * }</pre>
* <p/> * <p>
* For automatic resolution, the JVM will attempt: * For automatic resolution, the JVM will attempt:
* <pre>{@code * <pre>{@code
* method(wrapped_foo) -> nativeImplementation(wrapped_foo) * method(wrapped_foo) -> nativeImplementation(wrapped_foo)
* }</pre> * }</pre>
* <p/> * <p>
* When this fails, the resolution will be retried with * When this fails, the resolution will be retried with
* the specified prefix deleted from the implementation name, * the specified prefix deleted from the implementation name,
* yielding the correct resolution: * yielding the correct resolution:
* <pre>{@code * <pre>{@code
* method(wrapped_foo) -> nativeImplementation(foo) * method(wrapped_foo) -> nativeImplementation(foo)
* }</pre> * }</pre>
* <p/> * <p>
* Note that since the prefix is only used when standard * Note that since the prefix is only used when standard
* resolution fails, native methods can be wrapped selectively. * resolution fails, native methods can be wrapped selectively.
* <p/> * <p>
* Since each <code>ClassFileTransformer</code> * Since each <code>ClassFileTransformer</code>
* can do its own transformation of the bytecodes, more * can do its own transformation of the bytecodes, more
* than one layer of wrappers may be applied. Thus each * than one layer of wrappers may be applied. Thus each
......
...@@ -747,7 +747,8 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; ...@@ -747,7 +747,8 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
GuardWithCatch gguard = new GuardWithCatch(gtarget, exType, gcatcher); GuardWithCatch gguard = new GuardWithCatch(gtarget, exType, gcatcher);
if (gtarget == null || gcatcher == null) throw new InternalError(); if (gtarget == null || gcatcher == null) throw new InternalError();
MethodHandle ginvoker = GuardWithCatch.VARARGS_INVOKE.bindReceiver(gguard); MethodHandle ginvoker = GuardWithCatch.VARARGS_INVOKE.bindReceiver(gguard);
return makeCollectArguments(ginvoker, ValueConversions.varargsArray(nargs), 0, false); MethodHandle gcollect = makeCollectArguments(ginvoker, ValueConversions.varargsArray(nargs), 0, false);
return makePairwiseConvert(gcollect, type, 2);
} }
} }
......
...@@ -41,6 +41,7 @@ import sun.reflect.misc.ReflectUtil; ...@@ -41,6 +41,7 @@ import sun.reflect.misc.ReflectUtil;
import sun.security.util.SecurityConstants; import sun.security.util.SecurityConstants;
import static java.lang.invoke.MethodHandleStatics.*; import static java.lang.invoke.MethodHandleStatics.*;
import static java.lang.invoke.MethodHandleNatives.Constants.*; import static java.lang.invoke.MethodHandleNatives.Constants.*;
import sun.security.util.SecurityConstants;
/** /**
* This class consists exclusively of static methods that operate on or return * This class consists exclusively of static methods that operate on or return
...@@ -305,36 +306,30 @@ public class MethodHandles { ...@@ -305,36 +306,30 @@ public class MethodHandles {
* <a name="secmgr"></a> * <a name="secmgr"></a>
* If a security manager is present, member lookups are subject to * If a security manager is present, member lookups are subject to
* additional checks. * additional checks.
* From one to four calls are made to the security manager. * From one to three calls are made to the security manager.
* Any of these calls can refuse access by throwing a * Any of these calls can refuse access by throwing a
* {@link java.lang.SecurityException SecurityException}. * {@link java.lang.SecurityException SecurityException}.
* Define {@code smgr} as the security manager, * Define {@code smgr} as the security manager,
* {@code lookc} as the lookup class of the current lookup object,
* {@code refc} as the containing class in which the member * {@code refc} as the containing class in which the member
* is being sought, and {@code defc} as the class in which the * is being sought, and {@code defc} as the class in which the
* member is actually defined. * member is actually defined.
* The value {@code lookc} is defined as <em>not present</em>
* if the current lookup object does not have
* {@linkplain java.lang.invoke.MethodHandles.Lookup#PRIVATE private access}.
* The calls are made according to the following rules: * The calls are made according to the following rules:
* <ul> * <ul>
* <li>In all cases, {@link SecurityManager#checkMemberAccess * <li>If {@code lookc} is not present, or if its class loader is not
* smgr.checkMemberAccess(refc, Member.PUBLIC)} is called.
* <li>If the class loader of the lookup class is not
* the same as or an ancestor of the class loader of {@code refc}, * the same as or an ancestor of the class loader of {@code refc},
* then {@link SecurityManager#checkPackageAccess * then {@link SecurityManager#checkPackageAccess
* smgr.checkPackageAccess(refcPkg)} is called, * smgr.checkPackageAccess(refcPkg)} is called,
* where {@code refcPkg} is the package of {@code refc}. * where {@code refcPkg} is the package of {@code refc}.
* <li>If the retrieved member is not public and
* {@code lookc} is not present, then
* {@link SecurityManager#checkPermission smgr.checkPermission}
* with {@code RuntimePermission("accessDeclaredMembers")} is called.
* <li>If the retrieved member is not public, * <li>If the retrieved member is not public,
* {@link SecurityManager#checkMemberAccess * and if {@code defc} and {@code refc} are different,
* smgr.checkMemberAccess(defc, Member.DECLARED)} is called.
* (Note that {@code defc} might be the same as {@code refc}.)
* The default implementation of this security manager method
* inspects the stack to determine the original caller of
* the reflective request (such as {@code findStatic}),
* and performs additional permission checks if the
* class loader of {@code defc} differs from the class
* loader of the class from which the reflective request came.
* <li>If the retrieved member is not public,
* and if {@code defc} and {@code refc} are in different class loaders,
* and if the class loader of the lookup class is not
* the same as or an ancestor of the class loader of {@code defc},
* then {@link SecurityManager#checkPackageAccess * then {@link SecurityManager#checkPackageAccess
* smgr.checkPackageAccess(defcPkg)} is called, * smgr.checkPackageAccess(defcPkg)} is called,
* where {@code defcPkg} is the package of {@code defc}. * where {@code defcPkg} is the package of {@code defc}.
...@@ -1053,22 +1048,6 @@ return mh1; ...@@ -1053,22 +1048,6 @@ return mh1;
return (allowedModes & PRIVATE) != 0; return (allowedModes & PRIVATE) != 0;
} }
/**
* Determine whether a security manager has an overridden
* SecurityManager.checkMemberAccess method.
*/
private boolean isCheckMemberAccessOverridden(SecurityManager sm) {
final Class<? extends SecurityManager> cls = sm.getClass();
if (cls == SecurityManager.class) return false;
try {
return cls.getMethod("checkMemberAccess", Class.class, int.class).
getDeclaringClass() != SecurityManager.class;
} catch (NoSuchMethodException e) {
throw new InternalError("should not reach here");
}
}
/** /**
* Perform necessary <a href="MethodHandles.Lookup.html#secmgr">access checks</a>. * Perform necessary <a href="MethodHandles.Lookup.html#secmgr">access checks</a>.
* Determines a trustable caller class to compare with refc, the symbolic reference class. * Determines a trustable caller class to compare with refc, the symbolic reference class.
...@@ -1079,45 +1058,22 @@ return mh1; ...@@ -1079,45 +1058,22 @@ return mh1;
if (smgr == null) return; if (smgr == null) return;
if (allowedModes == TRUSTED) return; if (allowedModes == TRUSTED) return;
final boolean overridden = isCheckMemberAccessOverridden(smgr);
// Step 1: // Step 1:
{
// Default policy is to allow Member.PUBLIC; no need to check
// permission if SecurityManager is the default implementation
final int which = Member.PUBLIC;
final Class<?> clazz = refc;
if (overridden) {
// Don't refactor; otherwise break the stack depth for
// checkMemberAccess of subclasses of SecurityManager as specified.
smgr.checkMemberAccess(clazz, which);
}
}
// Step 2:
if (!isFullPowerLookup() || if (!isFullPowerLookup() ||
!VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) { !VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) {
ReflectUtil.checkPackageAccess(refc); ReflectUtil.checkPackageAccess(refc);
} }
// Step 3: // Step 2:
if (m.isPublic()) return; if (m.isPublic()) return;
Class<?> defc = m.getDeclaringClass(); Class<?> defc = m.getDeclaringClass();
{ {
// Inline SecurityManager.checkMemberAccess if (!isFullPowerLookup()) {
final int which = Member.DECLARED; smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
final Class<?> clazz = defc;
if (!overridden) {
if (!isFullPowerLookup()) {
smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
} else {
// Don't refactor; otherwise break the stack depth for
// checkMemberAccess of subclasses of SecurityManager as specified.
smgr.checkMemberAccess(clazz, which);
} }
} }
// Step 4: // Step 3:
if (defc != refc) { if (defc != refc) {
ReflectUtil.checkPackageAccess(defc); ReflectUtil.checkPackageAccess(defc);
} }
......
...@@ -42,14 +42,12 @@ interface Member { ...@@ -42,14 +42,12 @@ interface Member {
/** /**
* Identifies the set of all public members of a class or interface, * Identifies the set of all public members of a class or interface,
* including inherited members. * including inherited members.
* @see java.lang.SecurityManager#checkMemberAccess
*/ */
public static final int PUBLIC = 0; public static final int PUBLIC = 0;
/** /**
* Identifies the set of declared members of a class or interface. * Identifies the set of declared members of a class or interface.
* Inherited members are not included. * Inherited members are not included.
* @see java.lang.SecurityManager#checkMemberAccess
*/ */
public static final int DECLARED = 1; public static final int DECLARED = 1;
......
...@@ -1042,7 +1042,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> { ...@@ -1042,7 +1042,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* recalculate powers of radix^(2^n) more than once. This speeds * recalculate powers of radix^(2^n) more than once. This speeds
* Schoenhage recursive base conversion significantly. * Schoenhage recursive base conversion significantly.
*/ */
private static ArrayList<BigInteger>[] powerCache; private static volatile BigInteger[][] powerCache;
/** The cache of logarithms of radices for base conversion. */ /** The cache of logarithms of radices for base conversion. */
private static final double[] logCache; private static final double[] logCache;
...@@ -1063,14 +1063,12 @@ public class BigInteger extends Number implements Comparable<BigInteger> { ...@@ -1063,14 +1063,12 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* with just the very first value. Additional values will be created * with just the very first value. Additional values will be created
* on demand. * on demand.
*/ */
powerCache = (ArrayList<BigInteger>[]) powerCache = new BigInteger[Character.MAX_RADIX+1][];
new ArrayList[Character.MAX_RADIX+1];
logCache = new double[Character.MAX_RADIX+1]; logCache = new double[Character.MAX_RADIX+1];
for (int i=Character.MIN_RADIX; i<=Character.MAX_RADIX; i++) for (int i=Character.MIN_RADIX; i<=Character.MAX_RADIX; i++)
{ {
powerCache[i] = new ArrayList<BigInteger>(1); powerCache[i] = new BigInteger[] { BigInteger.valueOf(i) };
powerCache[i].add(BigInteger.valueOf(i));
logCache[i] = Math.log(i); logCache[i] = Math.log(i);
} }
} }
...@@ -3454,22 +3452,25 @@ public class BigInteger extends Number implements Comparable<BigInteger> { ...@@ -3454,22 +3452,25 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* This could be changed to a more complicated caching method using * This could be changed to a more complicated caching method using
* <code>Future</code>. * <code>Future</code>.
*/ */
private static synchronized BigInteger getRadixConversionCache(int radix, private static BigInteger getRadixConversionCache(int radix, int exponent) {
int exponent) { BigInteger[] cacheLine = powerCache[radix]; // volatile read
BigInteger retVal = null; if (exponent < cacheLine.length) {
ArrayList<BigInteger> cacheLine = powerCache[radix]; return cacheLine[exponent];
int oldSize = cacheLine.size();
if (exponent >= oldSize) {
cacheLine.ensureCapacity(exponent+1);
for (int i=oldSize; i<=exponent; i++) {
retVal = cacheLine.get(i-1).square();
cacheLine.add(i, retVal);
}
} }
else
retVal = cacheLine.get(exponent);
return retVal; int oldLength = cacheLine.length;
cacheLine = Arrays.copyOf(cacheLine, exponent + 1);
for (int i = oldLength; i <= exponent; i++) {
cacheLine[i] = cacheLine[i - 1].pow(2);
}
BigInteger[][] pc = powerCache; // volatile read again
if (exponent >= pc[radix].length) {
pc = pc.clone();
pc[radix] = cacheLine;
powerCache = pc; // volatile write, publish
}
return cacheLine[exponent];
} }
/* zero[i] is a string of i consecutive zeros. */ /* zero[i] is a string of i consecutive zeros. */
......
...@@ -227,15 +227,13 @@ public class KeyStore { ...@@ -227,15 +227,13 @@ public class KeyStore {
* {@link #store(KeyStore.LoadStoreParameter) store} operations. * {@link #store(KeyStore.LoadStoreParameter) store} operations.
* <p> * <p>
* The following syntax is supported for configuration data: * The following syntax is supported for configuration data:
* <pre> * <pre>{@code
*
* domain <domainName> [<property> ...] { * domain <domainName> [<property> ...] {
* keystore <keystoreName> [<property> ...] ; * keystore <keystoreName> [<property> ...] ;
* ... * ...
* }; * };
* ... * ...
* * }</pre>
* </pre>
* where {@code domainName} and {@code keystoreName} are identifiers * where {@code domainName} and {@code keystoreName} are identifiers
* and {@code property} is a key/value pairing. The key and value are * and {@code property} is a key/value pairing. The key and value are
* separated by an 'equals' symbol and the value is enclosed in double * separated by an 'equals' symbol and the value is enclosed in double
......
...@@ -67,6 +67,7 @@ import java.lang.reflect.*; ...@@ -67,6 +67,7 @@ import java.lang.reflect.*;
* or modified by applications. * or modified by applications.
* The following attributes are automatically placed in each Provider object: * The following attributes are automatically placed in each Provider object:
* <table cellspacing=4> * <table cellspacing=4>
* <caption><b>Attributes Automatically Placed in a Provider Object</b></caption>
* <tr><th>Name</th><th>Value</th> * <tr><th>Name</th><th>Value</th>
* <tr><td>{@code Provider.id name}</td> * <tr><td>{@code Provider.id name}</td>
* <td>{@code String.valueOf(provider.getName())}</td> * <td>{@code String.valueOf(provider.getName())}</td>
......
...@@ -480,8 +480,8 @@ public final class Security { ...@@ -480,8 +480,8 @@ public final class Security {
* Returns an array containing all installed providers that satisfy the * Returns an array containing all installed providers that satisfy the
* specified selection criterion, or null if no such providers have been * specified selection criterion, or null if no such providers have been
* installed. The returned providers are ordered * installed. The returned providers are ordered
* according to their <a href= * according to their
* "#insertProviderAt(java.security.Provider, int)">preference order</a>. * {@linkplain #insertProviderAt(java.security.Provider, int) preference order}.
* *
* <p> A cryptographic service is always associated with a particular * <p> A cryptographic service is always associated with a particular
* algorithm or type. For example, a digital signature service is * algorithm or type. For example, a digital signature service is
...@@ -492,8 +492,8 @@ public final class Security { ...@@ -492,8 +492,8 @@ public final class Security {
* <p>The selection criterion must be specified in one of the following two * <p>The selection criterion must be specified in one of the following two
* formats: * formats:
* <ul> * <ul>
* <li> <i>&lt;crypto_service>.&lt;algorithm_or_type></i> <p> The * <li> <i>{@literal <crypto_service>.<algorithm_or_type>}</i>
* cryptographic service name must not contain any dots. * <p> The cryptographic service name must not contain any dots.
* <p> A * <p> A
* provider satisfies the specified selection criterion iff the provider * provider satisfies the specified selection criterion iff the provider
* implements the * implements the
...@@ -501,11 +501,12 @@ public final class Security { ...@@ -501,11 +501,12 @@ public final class Security {
* <p> For example, "CertificateFactory.X.509" * <p> For example, "CertificateFactory.X.509"
* would be satisfied by any provider that supplied * would be satisfied by any provider that supplied
* a CertificateFactory implementation for X.509 certificates. * a CertificateFactory implementation for X.509 certificates.
* <li> <i>&lt;crypto_service>.&lt;algorithm_or_type> * <li> <i>{@literal <crypto_service>.<algorithm_or_type>
* &lt;attribute_name>:&lt attribute_value></i> * <attribute_name>:<attribute_value>}</i>
* <p> The cryptographic service name must not contain any dots. There * <p> The cryptographic service name must not contain any dots. There
* must be one or more space charaters between the * must be one or more space charaters between the
* <i>&lt;algorithm_or_type></i> and the <i>&lt;attribute_name></i>. * <i>{@literal <algorithm_or_type>}</i> and the
* <i>{@literal <attribute_name>}</i>.
* <p> A provider satisfies this selection criterion iff the * <p> A provider satisfies this selection criterion iff the
* provider implements the specified algorithm or type for the specified * provider implements the specified algorithm or type for the specified
* cryptographic service and its implementation meets the * cryptographic service and its implementation meets the
...@@ -558,8 +559,9 @@ public final class Security { ...@@ -558,8 +559,9 @@ public final class Security {
* Returns an array containing all installed providers that satisfy the * Returns an array containing all installed providers that satisfy the
* specified* selection criteria, or null if no such providers have been * specified* selection criteria, or null if no such providers have been
* installed. The returned providers are ordered * installed. The returned providers are ordered
* according to their <a href= * according to their
* "#insertProviderAt(java.security.Provider, int)">preference order</a>. * {@linkplain #insertProviderAt(java.security.Provider, int)
* preference order}.
* *
* <p>The selection criteria are represented by a map. * <p>The selection criteria are represented by a map.
* Each map entry represents a selection criterion. * Each map entry represents a selection criterion.
...@@ -567,16 +569,18 @@ public final class Security { ...@@ -567,16 +569,18 @@ public final class Security {
* criteria. The key for any entry in such a map must be in one of the * criteria. The key for any entry in such a map must be in one of the
* following two formats: * following two formats:
* <ul> * <ul>
* <li> <i>&lt;crypto_service>.&lt;algorithm_or_type></i> * <li> <i>{@literal <crypto_service>.<algorithm_or_type>}</i>
* <p> The cryptographic service name must not contain any dots. * <p> The cryptographic service name must not contain any dots.
* <p> The value associated with the key must be an empty string. * <p> The value associated with the key must be an empty string.
* <p> A provider * <p> A provider
* satisfies this selection criterion iff the provider implements the * satisfies this selection criterion iff the provider implements the
* specified algorithm or type for the specified cryptographic service. * specified algorithm or type for the specified cryptographic service.
* <li> <i>&lt;crypto_service>.&lt;algorithm_or_type> &lt;attribute_name></i> * <li> <i>{@literal <crypto_service>}.
* {@literal <algorithm_or_type> <attribute_name>}</i>
* <p> The cryptographic service name must not contain any dots. There * <p> The cryptographic service name must not contain any dots. There
* must be one or more space charaters between the <i>&lt;algorithm_or_type></i> * must be one or more space charaters between the
* and the <i>&lt;attribute_name></i>. * <i>{@literal <algorithm_or_type>}</i>
* and the <i>{@literal <attribute_name>}</i>.
* <p> The value associated with the key must be a non-empty string. * <p> The value associated with the key must be a non-empty string.
* A provider satisfies this selection criterion iff the * A provider satisfies this selection criterion iff the
* provider implements the specified algorithm or type for the specified * provider implements the specified algorithm or type for the specified
......
...@@ -249,7 +249,8 @@ public abstract class X509CRL extends CRL implements X509Extension { ...@@ -249,7 +249,8 @@ public abstract class X509CRL extends CRL implements X509Extension {
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* version Version OPTIONAL, * version Version OPTIONAL,
* -- if present, must be v2<p> * -- if present, must be v2
*
* Version ::= INTEGER { v1(0), v2(1), v3(2) } * Version ::= INTEGER { v1(0), v2(1), v3(2) }
* -- v3 does not apply to CRLs but appears for consistency * -- v3 does not apply to CRLs but appears for consistency
* -- with definition of Version for certs * -- with definition of Version for certs
...@@ -413,7 +414,8 @@ public abstract class X509CRL extends CRL implements X509Extension { ...@@ -413,7 +414,8 @@ public abstract class X509CRL extends CRL implements X509Extension {
* signature algorithm. An example is the string "SHA256withRSA". * signature algorithm. An example is the string "SHA256withRSA".
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* signatureAlgorithm AlgorithmIdentifier<p> * signatureAlgorithm AlgorithmIdentifier
*
* AlgorithmIdentifier ::= SEQUENCE { * AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER, * algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL } * parameters ANY DEFINED BY algorithm OPTIONAL }
......
...@@ -43,11 +43,11 @@ import sun.security.x509.X509CRLEntryImpl; ...@@ -43,11 +43,11 @@ import sun.security.x509.X509CRLEntryImpl;
* crlEntryExtensions Extensions OPTIONAL * crlEntryExtensions Extensions OPTIONAL
* -- if present, must be v2 * -- if present, must be v2
* } OPTIONAL * } OPTIONAL
*<p> *
* CertificateSerialNumber ::= INTEGER * CertificateSerialNumber ::= INTEGER
*<p> *
* Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
*<p> *
* Extension ::= SEQUENCE { * Extension ::= SEQUENCE {
* extnId OBJECT IDENTIFIER, * extnId OBJECT IDENTIFIER,
* critical BOOLEAN DEFAULT FALSE, * critical BOOLEAN DEFAULT FALSE,
......
...@@ -126,10 +126,12 @@ implements X509Extension { ...@@ -126,10 +126,12 @@ implements X509Extension {
* is valid. It is defined in * is valid. It is defined in
* ASN.1 as: * ASN.1 as:
* <pre> * <pre>
* validity Validity<p> * validity Validity
*
* Validity ::= SEQUENCE { * Validity ::= SEQUENCE {
* notBefore CertificateValidityDate, * notBefore CertificateValidityDate,
* notAfter CertificateValidityDate }<p> * notAfter CertificateValidityDate }
*
* CertificateValidityDate ::= CHOICE { * CertificateValidityDate ::= CHOICE {
* utcTime UTCTime, * utcTime UTCTime,
* generalTime GeneralizedTime } * generalTime GeneralizedTime }
...@@ -165,7 +167,8 @@ implements X509Extension { ...@@ -165,7 +167,8 @@ implements X509Extension {
* certificate. * certificate.
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* version [0] EXPLICIT Version DEFAULT v1<p> * version [0] EXPLICIT Version DEFAULT v1
*
* Version ::= INTEGER { v1(0), v2(1), v3(2) } * Version ::= INTEGER { v1(0), v2(1), v3(2) }
* </pre> * </pre>
* @return the version number, i.e. 1, 2 or 3. * @return the version number, i.e. 1, 2 or 3.
...@@ -180,7 +183,7 @@ implements X509Extension { ...@@ -180,7 +183,7 @@ implements X509Extension {
* serial number identify a unique certificate). * serial number identify a unique certificate).
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* serialNumber CertificateSerialNumber<p> * serialNumber CertificateSerialNumber
* *
* CertificateSerialNumber ::= INTEGER * CertificateSerialNumber ::= INTEGER
* </pre> * </pre>
...@@ -204,7 +207,7 @@ implements X509Extension { ...@@ -204,7 +207,7 @@ implements X509Extension {
* X.500 distinguished name (DN). * X.500 distinguished name (DN).
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* issuer Name<p> * issuer Name
* *
* Name ::= CHOICE { RDNSequence } * Name ::= CHOICE { RDNSequence }
* RDNSequence ::= SEQUENCE OF RelativeDistinguishedName * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
...@@ -295,11 +298,12 @@ implements X509Extension { ...@@ -295,11 +298,12 @@ implements X509Extension {
* the certificate. * the certificate.
* The relevant ASN.1 definitions are: * The relevant ASN.1 definitions are:
* <pre> * <pre>
* validity Validity<p> * validity Validity
* *
* Validity ::= SEQUENCE { * Validity ::= SEQUENCE {
* notBefore CertificateValidityDate, * notBefore CertificateValidityDate,
* notAfter CertificateValidityDate }<p> * notAfter CertificateValidityDate }
*
* CertificateValidityDate ::= CHOICE { * CertificateValidityDate ::= CHOICE {
* utcTime UTCTime, * utcTime UTCTime,
* generalTime GeneralizedTime } * generalTime GeneralizedTime }
...@@ -348,7 +352,8 @@ implements X509Extension { ...@@ -348,7 +352,8 @@ implements X509Extension {
* signature algorithm. An example is the string "SHA256withRSA". * signature algorithm. An example is the string "SHA256withRSA".
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* signatureAlgorithm AlgorithmIdentifier<p> * signatureAlgorithm AlgorithmIdentifier
*
* AlgorithmIdentifier ::= SEQUENCE { * AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER, * algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL } * parameters ANY DEFINED BY algorithm OPTIONAL }
...@@ -410,7 +415,8 @@ implements X509Extension { ...@@ -410,7 +415,8 @@ implements X509Extension {
* *
* <p>The ASN.1 definition for this is: * <p>The ASN.1 definition for this is:
* <pre> * <pre>
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL<p> * issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL
*
* UniqueIdentifier ::= BIT STRING * UniqueIdentifier ::= BIT STRING
* </pre> * </pre>
* *
...@@ -424,7 +430,8 @@ implements X509Extension { ...@@ -424,7 +430,8 @@ implements X509Extension {
* *
* <p>The ASN.1 definition for this is: * <p>The ASN.1 definition for this is:
* <pre> * <pre>
* subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL<p> * subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL
*
* UniqueIdentifier ::= BIT STRING * UniqueIdentifier ::= BIT STRING
* </pre> * </pre>
* *
...@@ -474,9 +481,9 @@ implements X509Extension { ...@@ -474,9 +481,9 @@ implements X509Extension {
* indicated in the key usage extension field. The ASN.1 * indicated in the key usage extension field. The ASN.1
* definition for this is: * definition for this is:
* <pre> * <pre>
* ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId<p> * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
* *
* KeyPurposeId ::= OBJECT IDENTIFIER<p> * KeyPurposeId ::= OBJECT IDENTIFIER
* </pre> * </pre>
* *
* Key purposes may be defined by any organization with a * Key purposes may be defined by any organization with a
......
...@@ -1304,6 +1304,7 @@ public final class DateTimeFormatter { ...@@ -1304,6 +1304,7 @@ public final class DateTimeFormatter {
* LocalTime time = parsed.query(LocalTime::from); * LocalTime time = parsed.query(LocalTime::from);
* Period extraDays = parsed.query(DateTimeFormatter.parsedExcessDays()); * Period extraDays = parsed.query(DateTimeFormatter.parsedExcessDays());
* </pre> * </pre>
* @return a query that provides access to the excess days that were parsed
*/ */
public static final TemporalQuery<Period> parsedExcessDays() { public static final TemporalQuery<Period> parsedExcessDays() {
return PARSED_EXCESS_DAYS; return PARSED_EXCESS_DAYS;
...@@ -1344,6 +1345,7 @@ public final class DateTimeFormatter { ...@@ -1344,6 +1345,7 @@ public final class DateTimeFormatter {
* // validate leap-second is correct and apply correct smoothing * // validate leap-second is correct and apply correct smoothing
* } * }
* </pre> * </pre>
* @return a query that provides access to whether a leap-second was parsed
*/ */
public static final TemporalQuery<Boolean> parsedLeapSecond() { public static final TemporalQuery<Boolean> parsedLeapSecond() {
return PARSED_LEAP_SECOND; return PARSED_LEAP_SECOND;
......
...@@ -41,17 +41,18 @@ import java.util.*; ...@@ -41,17 +41,18 @@ import java.util.*;
* for the deque to become non-empty when retrieving an element, and wait for * for the deque to become non-empty when retrieving an element, and wait for
* space to become available in the deque when storing an element. * space to become available in the deque when storing an element.
* *
* <p><tt>BlockingDeque</tt> methods come in four forms, with different ways * <p>{@code BlockingDeque} methods come in four forms, with different ways
* of handling operations that cannot be satisfied immediately, but may be * of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future: * satisfied at some point in the future:
* one throws an exception, the second returns a special value (either * one throws an exception, the second returns a special value (either
* <tt>null</tt> or <tt>false</tt>, depending on the operation), the third * {@code null} or {@code false}, depending on the operation), the third
* blocks the current thread indefinitely until the operation can succeed, * blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving * and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table: * up. These methods are summarized in the following table:
* *
* <p> * <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1> * <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of BlockingDeque methods</caption>
* <tr> * <tr>
* <td ALIGN=CENTER COLSPAN = 5> <b>First Element (Head)</b></td> * <td ALIGN=CENTER COLSPAN = 5> <b>First Element (Head)</b></td>
* </tr> * </tr>
...@@ -116,20 +117,21 @@ import java.util.*; ...@@ -116,20 +117,21 @@ import java.util.*;
* </tr> * </tr>
* </table> * </table>
* *
* <p>Like any {@link BlockingQueue}, a <tt>BlockingDeque</tt> is thread safe, * <p>Like any {@link BlockingQueue}, a {@code BlockingDeque} is thread safe,
* does not permit null elements, and may (or may not) be * does not permit null elements, and may (or may not) be
* capacity-constrained. * capacity-constrained.
* *
* <p>A <tt>BlockingDeque</tt> implementation may be used directly as a FIFO * <p>A {@code BlockingDeque} implementation may be used directly as a FIFO
* <tt>BlockingQueue</tt>. The methods inherited from the * {@code BlockingQueue}. The methods inherited from the
* <tt>BlockingQueue</tt> interface are precisely equivalent to * {@code BlockingQueue} interface are precisely equivalent to
* <tt>BlockingDeque</tt> methods as indicated in the following table: * {@code BlockingDeque} methods as indicated in the following table:
* *
* <p> * <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1> * <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Comparison of BlockingQueue and BlockingDeque methods</caption>
* <tr> * <tr>
* <td ALIGN=CENTER> <b><tt>BlockingQueue</tt> Method</b></td> * <td ALIGN=CENTER> <b>{@code BlockingQueue} Method</b></td>
* <td ALIGN=CENTER> <b>Equivalent <tt>BlockingDeque</tt> Method</b></td> * <td ALIGN=CENTER> <b>Equivalent {@code BlockingDeque} Method</b></td>
* </tr> * </tr>
* <tr> * <tr>
* <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td> * <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td>
...@@ -208,7 +210,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -208,7 +210,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the front of this deque if it is * Inserts the specified element at the front of this deque if it is
* possible to do so immediately without violating capacity restrictions, * possible to do so immediately without violating capacity restrictions,
* throwing an <tt>IllegalStateException</tt> if no space is currently * throwing an {@code IllegalStateException} if no space is currently
* available. When using a capacity-restricted deque, it is generally * available. When using a capacity-restricted deque, it is generally
* preferable to use {@link #offerFirst(Object) offerFirst}. * preferable to use {@link #offerFirst(Object) offerFirst}.
* *
...@@ -223,7 +225,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -223,7 +225,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the end of this deque if it is * Inserts the specified element at the end of this deque if it is
* possible to do so immediately without violating capacity restrictions, * possible to do so immediately without violating capacity restrictions,
* throwing an <tt>IllegalStateException</tt> if no space is currently * throwing an {@code IllegalStateException} if no space is currently
* available. When using a capacity-restricted deque, it is generally * available. When using a capacity-restricted deque, it is generally
* preferable to use {@link #offerLast(Object) offerLast}. * preferable to use {@link #offerLast(Object) offerLast}.
* *
...@@ -238,7 +240,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -238,7 +240,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the front of this deque if it is * Inserts the specified element at the front of this deque if it is
* possible to do so immediately without violating capacity restrictions, * possible to do so immediately without violating capacity restrictions,
* returning <tt>true</tt> upon success and <tt>false</tt> if no space is * returning {@code true} upon success and {@code false} if no space is
* currently available. * currently available.
* When using a capacity-restricted deque, this method is generally * When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addFirst(Object) addFirst} method, which can * preferable to the {@link #addFirst(Object) addFirst} method, which can
...@@ -254,7 +256,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -254,7 +256,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the end of this deque if it is * Inserts the specified element at the end of this deque if it is
* possible to do so immediately without violating capacity restrictions, * possible to do so immediately without violating capacity restrictions,
* returning <tt>true</tt> upon success and <tt>false</tt> if no space is * returning {@code true} upon success and {@code false} if no space is
* currently available. * currently available.
* When using a capacity-restricted deque, this method is generally * When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addLast(Object) addLast} method, which can * preferable to the {@link #addLast(Object) addLast} method, which can
...@@ -302,10 +304,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -302,10 +304,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* *
* @param e the element to add * @param e the element to add
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return <tt>true</tt> if successful, or <tt>false</tt> if * @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available * the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -324,10 +326,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -324,10 +326,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* *
* @param e the element to add * @param e the element to add
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return <tt>true</tt> if successful, or <tt>false</tt> if * @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available * the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -363,10 +365,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -363,10 +365,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available. * become available.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the head of this deque, or <tt>null</tt> if the specified * @return the head of this deque, or {@code null} if the specified
* waiting time elapses before an element is available * waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -379,10 +381,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -379,10 +381,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available. * become available.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the tail of this deque, or <tt>null</tt> if the specified * @return the tail of this deque, or {@code null} if the specified
* waiting time elapses before an element is available * waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -392,13 +394,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -392,13 +394,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Removes the first occurrence of the specified element from this deque. * Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged. * If the deque does not contain the element, it is unchanged.
* More formally, removes the first element <tt>e</tt> such that * More formally, removes the first element {@code e} such that
* <tt>o.equals(e)</tt> (if such an element exists). * {@code o.equals(e)} (if such an element exists).
* Returns <tt>true</tt> if this deque contained the specified element * Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call). * (or equivalently, if this deque changed as a result of the call).
* *
* @param o element to be removed from this deque, if present * @param o element to be removed from this deque, if present
* @return <tt>true</tt> if an element was removed as a result of this call * @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -410,13 +412,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -410,13 +412,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Removes the last occurrence of the specified element from this deque. * Removes the last occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged. * If the deque does not contain the element, it is unchanged.
* More formally, removes the last element <tt>e</tt> such that * More formally, removes the last element {@code e} such that
* <tt>o.equals(e)</tt> (if such an element exists). * {@code o.equals(e)} (if such an element exists).
* Returns <tt>true</tt> if this deque contained the specified element * Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call). * (or equivalently, if this deque changed as a result of the call).
* *
* @param o element to be removed from this deque, if present * @param o element to be removed from this deque, if present
* @return <tt>true</tt> if an element was removed as a result of this call * @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -431,8 +433,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -431,8 +433,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* Inserts the specified element into the queue represented by this deque * Inserts the specified element into the queue represented by this deque
* (in other words, at the tail of this deque) if it is possible to do so * (in other words, at the tail of this deque) if it is possible to do so
* immediately without violating capacity restrictions, returning * immediately without violating capacity restrictions, returning
* <tt>true</tt> upon success and throwing an * {@code true} upon success and throwing an
* <tt>IllegalStateException</tt> if no space is currently available. * {@code IllegalStateException} if no space is currently available.
* When using a capacity-restricted deque, it is generally preferable to * When using a capacity-restricted deque, it is generally preferable to
* use {@link #offer(Object) offer}. * use {@link #offer(Object) offer}.
* *
...@@ -452,7 +454,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -452,7 +454,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* Inserts the specified element into the queue represented by this deque * Inserts the specified element into the queue represented by this deque
* (in other words, at the tail of this deque) if it is possible to do so * (in other words, at the tail of this deque) if it is possible to do so
* immediately without violating capacity restrictions, returning * immediately without violating capacity restrictions, returning
* <tt>true</tt> upon success and <tt>false</tt> if no space is currently * {@code true} upon success and {@code false} if no space is currently
* available. When using a capacity-restricted deque, this method is * available. When using a capacity-restricted deque, this method is
* generally preferable to the {@link #add} method, which can fail to * generally preferable to the {@link #add} method, which can fail to
* insert an element only by throwing an exception. * insert an element only by throwing an exception.
...@@ -494,8 +496,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -494,8 +496,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* {@link #offerLast(Object,long,TimeUnit) offerLast}. * {@link #offerLast(Object,long,TimeUnit) offerLast}.
* *
* @param e the element to add * @param e the element to add
* @return <tt>true</tt> if the element was added to this deque, else * @return {@code true} if the element was added to this deque, else
* <tt>false</tt> * {@code false}
* @throws InterruptedException {@inheritDoc} * @throws InterruptedException {@inheritDoc}
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* prevents it from being added to this deque * prevents it from being added to this deque
...@@ -522,11 +524,11 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -522,11 +524,11 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Retrieves and removes the head of the queue represented by this deque * Retrieves and removes the head of the queue represented by this deque
* (in other words, the first element of this deque), or returns * (in other words, the first element of this deque), or returns
* <tt>null</tt> if this deque is empty. * {@code null} if this deque is empty.
* *
* <p>This method is equivalent to {@link #pollFirst()}. * <p>This method is equivalent to {@link #pollFirst()}.
* *
* @return the head of this deque, or <tt>null</tt> if this deque is empty * @return the head of this deque, or {@code null} if this deque is empty
*/ */
E poll(); E poll();
...@@ -550,7 +552,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -550,7 +552,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* <p>This method is equivalent to * <p>This method is equivalent to
* {@link #pollFirst(long,TimeUnit) pollFirst}. * {@link #pollFirst(long,TimeUnit) pollFirst}.
* *
* @return the head of this deque, or <tt>null</tt> if the * @return the head of this deque, or {@code null} if the
* specified waiting time elapses before an element is available * specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -573,27 +575,27 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -573,27 +575,27 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Retrieves, but does not remove, the head of the queue represented by * Retrieves, but does not remove, the head of the queue represented by
* this deque (in other words, the first element of this deque), or * this deque (in other words, the first element of this deque), or
* returns <tt>null</tt> if this deque is empty. * returns {@code null} if this deque is empty.
* *
* <p>This method is equivalent to {@link #peekFirst() peekFirst}. * <p>This method is equivalent to {@link #peekFirst() peekFirst}.
* *
* @return the head of this deque, or <tt>null</tt> if this deque is empty * @return the head of this deque, or {@code null} if this deque is empty
*/ */
E peek(); E peek();
/** /**
* Removes the first occurrence of the specified element from this deque. * Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged. * If the deque does not contain the element, it is unchanged.
* More formally, removes the first element <tt>e</tt> such that * More formally, removes the first element {@code e} such that
* <tt>o.equals(e)</tt> (if such an element exists). * {@code o.equals(e)} (if such an element exists).
* Returns <tt>true</tt> if this deque contained the specified element * Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call). * (or equivalently, if this deque changed as a result of the call).
* *
* <p>This method is equivalent to * <p>This method is equivalent to
* {@link #removeFirstOccurrence(Object) removeFirstOccurrence}. * {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
* *
* @param o element to be removed from this deque, if present * @param o element to be removed from this deque, if present
* @return <tt>true</tt> if this deque changed as a result of the call * @return {@code true} if this deque changed as a result of the call
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -603,12 +605,12 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -603,12 +605,12 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
boolean remove(Object o); boolean remove(Object o);
/** /**
* Returns <tt>true</tt> if this deque contains the specified element. * Returns {@code true} if this deque contains the specified element.
* More formally, returns <tt>true</tt> if and only if this deque contains * More formally, returns {@code true} if and only if this deque contains
* at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * at least one element {@code e} such that {@code o.equals(e)}.
* *
* @param o object to be checked for containment in this deque * @param o object to be checked for containment in this deque
* @return <tt>true</tt> if this deque contains the specified element * @return {@code true} if this deque contains the specified element
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -635,9 +637,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -635,9 +637,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
// *** Stack methods *** // *** Stack methods ***
/** /**
* Pushes an element onto the stack represented by this deque. In other * Pushes an element onto the stack represented by this deque (in other
* words, inserts the element at the front of this deque unless it would * words, at the head of this deque) if it is possible to do so
* violate capacity restrictions. * immediately without violating capacity restrictions, throwing an
* {@code IllegalStateException} if no space is currently available.
* *
* <p>This method is equivalent to {@link #addFirst(Object) addFirst}. * <p>This method is equivalent to {@link #addFirst(Object) addFirst}.
* *
......
...@@ -44,17 +44,18 @@ import java.util.Queue; ...@@ -44,17 +44,18 @@ import java.util.Queue;
* element, and wait for space to become available in the queue when * element, and wait for space to become available in the queue when
* storing an element. * storing an element.
* *
* <p><tt>BlockingQueue</tt> methods come in four forms, with different ways * <p>{@code BlockingQueue} methods come in four forms, with different ways
* of handling operations that cannot be satisfied immediately, but may be * of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future: * satisfied at some point in the future:
* one throws an exception, the second returns a special value (either * one throws an exception, the second returns a special value (either
* <tt>null</tt> or <tt>false</tt>, depending on the operation), the third * {@code null} or {@code false}, depending on the operation), the third
* blocks the current thread indefinitely until the operation can succeed, * blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving * and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table: * up. These methods are summarized in the following table:
* *
* <p> * <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1> * <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of BlockingQueue methods</caption>
* <tr> * <tr>
* <td></td> * <td></td>
* <td ALIGN=CENTER><em>Throws exception</em></td> * <td ALIGN=CENTER><em>Throws exception</em></td>
...@@ -85,37 +86,37 @@ import java.util.Queue; ...@@ -85,37 +86,37 @@ import java.util.Queue;
* </tr> * </tr>
* </table> * </table>
* *
* <p>A <tt>BlockingQueue</tt> does not accept <tt>null</tt> elements. * <p>A {@code BlockingQueue} does not accept {@code null} elements.
* Implementations throw <tt>NullPointerException</tt> on attempts * Implementations throw {@code NullPointerException} on attempts
* to <tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>. A * to {@code add}, {@code put} or {@code offer} a {@code null}. A
* <tt>null</tt> is used as a sentinel value to indicate failure of * {@code null} is used as a sentinel value to indicate failure of
* <tt>poll</tt> operations. * {@code poll} operations.
* *
* <p>A <tt>BlockingQueue</tt> may be capacity bounded. At any given * <p>A {@code BlockingQueue} may be capacity bounded. At any given
* time it may have a <tt>remainingCapacity</tt> beyond which no * time it may have a {@code remainingCapacity} beyond which no
* additional elements can be <tt>put</tt> without blocking. * additional elements can be {@code put} without blocking.
* A <tt>BlockingQueue</tt> without any intrinsic capacity constraints always * A {@code BlockingQueue} without any intrinsic capacity constraints always
* reports a remaining capacity of <tt>Integer.MAX_VALUE</tt>. * reports a remaining capacity of {@code Integer.MAX_VALUE}.
* *
* <p> <tt>BlockingQueue</tt> implementations are designed to be used * <p>{@code BlockingQueue} implementations are designed to be used
* primarily for producer-consumer queues, but additionally support * primarily for producer-consumer queues, but additionally support
* the {@link java.util.Collection} interface. So, for example, it is * the {@link java.util.Collection} interface. So, for example, it is
* possible to remove an arbitrary element from a queue using * possible to remove an arbitrary element from a queue using
* <tt>remove(x)</tt>. However, such operations are in general * {@code remove(x)}. However, such operations are in general
* <em>not</em> performed very efficiently, and are intended for only * <em>not</em> performed very efficiently, and are intended for only
* occasional use, such as when a queued message is cancelled. * occasional use, such as when a queued message is cancelled.
* *
* <p> <tt>BlockingQueue</tt> implementations are thread-safe. All * <p>{@code BlockingQueue} implementations are thread-safe. All
* queuing methods achieve their effects atomically using internal * queuing methods achieve their effects atomically using internal
* locks or other forms of concurrency control. However, the * locks or other forms of concurrency control. However, the
* <em>bulk</em> Collection operations <tt>addAll</tt>, * <em>bulk</em> Collection operations {@code addAll},
* <tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt> are * {@code containsAll}, {@code retainAll} and {@code removeAll} are
* <em>not</em> necessarily performed atomically unless specified * <em>not</em> necessarily performed atomically unless specified
* otherwise in an implementation. So it is possible, for example, for * otherwise in an implementation. So it is possible, for example, for
* <tt>addAll(c)</tt> to fail (throwing an exception) after adding * {@code addAll(c)} to fail (throwing an exception) after adding
* only some of the elements in <tt>c</tt>. * only some of the elements in {@code c}.
* *
* <p>A <tt>BlockingQueue</tt> does <em>not</em> intrinsically support * <p>A {@code BlockingQueue} does <em>not</em> intrinsically support
* any kind of &quot;close&quot; or &quot;shutdown&quot; operation to * any kind of &quot;close&quot; or &quot;shutdown&quot; operation to
* indicate that no more items will be added. The needs and usage of * indicate that no more items will be added. The needs and usage of
* such features tend to be implementation-dependent. For example, a * such features tend to be implementation-dependent. For example, a
...@@ -125,7 +126,7 @@ import java.util.Queue; ...@@ -125,7 +126,7 @@ import java.util.Queue;
* *
* <p> * <p>
* Usage example, based on a typical producer-consumer scenario. * Usage example, based on a typical producer-consumer scenario.
* Note that a <tt>BlockingQueue</tt> can safely be used with multiple * Note that a {@code BlockingQueue} can safely be used with multiple
* producers and multiple consumers. * producers and multiple consumers.
* <pre> {@code * <pre> {@code
* class Producer implements Runnable { * class Producer implements Runnable {
...@@ -181,13 +182,13 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -181,13 +182,13 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Inserts the specified element into this queue if it is possible to do * Inserts the specified element into this queue if it is possible to do
* so immediately without violating capacity restrictions, returning * so immediately without violating capacity restrictions, returning
* <tt>true</tt> upon success and throwing an * {@code true} upon success and throwing an
* <tt>IllegalStateException</tt> if no space is currently available. * {@code IllegalStateException} if no space is currently available.
* When using a capacity-restricted queue, it is generally preferable to * When using a capacity-restricted queue, it is generally preferable to
* use {@link #offer(Object) offer}. * use {@link #offer(Object) offer}.
* *
* @param e the element to add * @param e the element to add
* @return <tt>true</tt> (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 * @throws IllegalStateException if the element cannot be added at this
* time due to capacity restrictions * time due to capacity restrictions
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -201,14 +202,14 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -201,14 +202,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Inserts the specified element into this queue if it is possible to do * Inserts the specified element into this queue if it is possible to do
* so immediately without violating capacity restrictions, returning * so immediately without violating capacity restrictions, returning
* <tt>true</tt> upon success and <tt>false</tt> if no space is currently * {@code true} upon success and {@code false} if no space is currently
* available. When using a capacity-restricted queue, this method is * available. When using a capacity-restricted queue, this method is
* generally preferable to {@link #add}, which can fail to insert an * generally preferable to {@link #add}, which can fail to insert an
* element only by throwing an exception. * element only by throwing an exception.
* *
* @param e the element to add * @param e the element to add
* @return <tt>true</tt> if the element was added to this queue, else * @return {@code true} if the element was added to this queue, else
* <tt>false</tt> * {@code false}
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* prevents it from being added to this queue * prevents it from being added to this queue
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
...@@ -237,10 +238,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -237,10 +238,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* *
* @param e the element to add * @param e the element to add
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return <tt>true</tt> if successful, or <tt>false</tt> if * @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available * the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -266,10 +267,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -266,10 +267,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* specified wait time if necessary for an element to become available. * specified wait time if necessary for an element to become available.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the head of this queue, or <tt>null</tt> if the * @return the head of this queue, or {@code null} if the
* specified waiting time elapses before an element is available * specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -279,11 +280,11 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -279,11 +280,11 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Returns the number of additional elements that this queue can ideally * Returns the number of additional elements that this queue can ideally
* (in the absence of memory or resource constraints) accept without * (in the absence of memory or resource constraints) accept without
* blocking, or <tt>Integer.MAX_VALUE</tt> if there is no intrinsic * blocking, or {@code Integer.MAX_VALUE} if there is no intrinsic
* limit. * limit.
* *
* <p>Note that you <em>cannot</em> always tell if an attempt to insert * <p>Note that you <em>cannot</em> always tell if an attempt to insert
* an element will succeed by inspecting <tt>remainingCapacity</tt> * an element will succeed by inspecting {@code remainingCapacity}
* because it may be the case that another thread is about to * because it may be the case that another thread is about to
* insert or remove an element. * insert or remove an element.
* *
...@@ -293,14 +294,14 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -293,14 +294,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Removes a single instance of the specified element from this queue, * Removes a single instance of the specified element from this queue,
* if it is present. More formally, removes an element <tt>e</tt> such * if it is present. More formally, removes an element {@code e} such
* that <tt>o.equals(e)</tt>, if this queue contains one or more such * that {@code o.equals(e)}, if this queue contains one or more such
* elements. * elements.
* Returns <tt>true</tt> if this queue contained the specified element * Returns {@code true} if this queue contained the specified element
* (or equivalently, if this queue changed as a result of the call). * (or equivalently, if this queue changed as a result of the call).
* *
* @param o element to be removed from this queue, if present * @param o element to be removed from this queue, if present
* @return <tt>true</tt> 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 the specified element * @throws ClassCastException if the class of the specified element
* is incompatible with this queue * is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -310,12 +311,12 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -310,12 +311,12 @@ public interface BlockingQueue<E> extends Queue<E> {
boolean remove(Object o); boolean remove(Object o);
/** /**
* Returns <tt>true</tt> if this queue contains the specified element. * Returns {@code true} if this queue contains the specified element.
* More formally, returns <tt>true</tt> if and only if this queue contains * More formally, returns {@code true} if and only if this queue contains
* at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * at least one element {@code e} such that {@code o.equals(e)}.
* *
* @param o object to be checked for containment in this queue * @param o object to be checked for containment in this queue
* @return <tt>true</tt> if this queue contains the specified element * @return {@code true} if this queue contains the specified element
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* is incompatible with this queue * is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -329,10 +330,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -329,10 +330,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* to the given collection. This operation may be more * to the given collection. This operation may be more
* efficient than repeatedly polling this queue. A failure * efficient than repeatedly polling this queue. A failure
* encountered while attempting to add elements to * encountered while attempting to add elements to
* collection <tt>c</tt> may result in elements being in neither, * collection {@code c} may result in elements being in neither,
* either or both collections when the associated exception is * either or both collections when the associated exception is
* thrown. Attempts to drain a queue to itself result in * thrown. Attempts to drain a queue to itself result in
* <tt>IllegalArgumentException</tt>. Further, the behavior of * {@code IllegalArgumentException}. Further, the behavior of
* this operation is undefined if the specified collection is * this operation is undefined if the specified collection is
* modified while the operation is in progress. * modified while the operation is in progress.
* *
...@@ -353,10 +354,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -353,10 +354,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* Removes at most the given number of available elements from * Removes at most the given number of available elements from
* this queue and adds them to the given collection. A failure * this queue and adds them to the given collection. A failure
* encountered while attempting to add elements to * encountered while attempting to add elements to
* collection <tt>c</tt> may result in elements being in neither, * collection {@code c} may result in elements being in neither,
* either or both collections when the associated exception is * either or both collections when the associated exception is
* thrown. Attempts to drain a queue to itself result in * thrown. Attempts to drain a queue to itself result in
* <tt>IllegalArgumentException</tt>. Further, the behavior of * {@code IllegalArgumentException}. Further, the behavior of
* this operation is undefined if the specified collection is * this operation is undefined if the specified collection is
* modified while the operation is in progress. * modified while the operation is in progress.
* *
......
...@@ -49,13 +49,13 @@ public class BrokenBarrierException extends Exception { ...@@ -49,13 +49,13 @@ public class BrokenBarrierException extends Exception {
private static final long serialVersionUID = 7117394618823254244L; private static final long serialVersionUID = 7117394618823254244L;
/** /**
* Constructs a <tt>BrokenBarrierException</tt> with no specified detail * Constructs a {@code BrokenBarrierException} with no specified detail
* message. * message.
*/ */
public BrokenBarrierException() {} public BrokenBarrierException() {}
/** /**
* Constructs a <tt>BrokenBarrierException</tt> with the specified * Constructs a {@code BrokenBarrierException} with the specified
* detail message. * detail message.
* *
* @param message the detail message * @param message the detail message
......
...@@ -42,6 +42,9 @@ import java.util.Deque; ...@@ -42,6 +42,9 @@ import java.util.Deque;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Queue; import java.util.Queue;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
/** /**
* An unbounded concurrent {@linkplain Deque deque} based on linked nodes. * An unbounded concurrent {@linkplain Deque deque} based on linked nodes.
...@@ -816,7 +819,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -816,7 +819,7 @@ public class ConcurrentLinkedDeque<E>
* Creates an array list and fills it with elements of this list. * Creates an array list and fills it with elements of this list.
* Used by toArray. * Used by toArray.
* *
* @return the arrayList * @return the array list
*/ */
private ArrayList<E> toArrayList() { private ArrayList<E> toArrayList() {
ArrayList<E> list = new ArrayList<E>(); ArrayList<E> list = new ArrayList<E>();
...@@ -1024,11 +1027,27 @@ public class ConcurrentLinkedDeque<E> ...@@ -1024,11 +1027,27 @@ public class ConcurrentLinkedDeque<E>
} }
public E poll() { return pollFirst(); } public E poll() { return pollFirst(); }
public E remove() { return removeFirst(); }
public E peek() { return peekFirst(); } public E peek() { return peekFirst(); }
/**
* @throws NoSuchElementException {@inheritDoc}
*/
public E remove() { return removeFirst(); }
/**
* @throws NoSuchElementException {@inheritDoc}
*/
public E pop() { return removeFirst(); }
/**
* @throws NoSuchElementException {@inheritDoc}
*/
public E element() { return getFirst(); } public E element() { return getFirst(); }
/**
* @throws NullPointerException {@inheritDoc}
*/
public void push(E e) { addFirst(e); } public void push(E e) { addFirst(e); }
public E pop() { return removeFirst(); }
/** /**
* Removes the first element {@code e} such that * Removes the first element {@code e} such that
...@@ -1385,6 +1404,99 @@ public class ConcurrentLinkedDeque<E> ...@@ -1385,6 +1404,99 @@ public class ConcurrentLinkedDeque<E>
Node<E> nextNode(Node<E> p) { return pred(p); } Node<E> nextNode(Node<E> p) { return pred(p); }
} }
/** A customized variant of Spliterators.IteratorSpliterator */
static final class CLDSpliterator<E> implements Spliterator<E> {
static final int MAX_BATCH = 1 << 25; // max batch array size;
final ConcurrentLinkedDeque<E> queue;
Node<E> current; // current node; null until initialized
int batch; // batch size for splits
boolean exhausted; // true when no more nodes
CLDSpliterator(ConcurrentLinkedDeque<E> queue) {
this.queue = queue;
}
public Spliterator<E> trySplit() {
Node<E> p;
final ConcurrentLinkedDeque<E> q = this.queue;
int b = batch;
int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null)) {
if (p.item == null && p == (p = p.next))
current = p = q.first();
if (p != null && p.next != null) {
Object[] a = new Object[n];
int i = 0;
do {
if ((a[i] = p.item) != null)
++i;
if (p == (p = p.next))
p = q.first();
} while (p != null && i < n);
if ((current = p) == null)
exhausted = true;
if (i > 0) {
batch = i;
return Spliterators.spliterator
(a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
Spliterator.CONCURRENT);
}
}
}
return null;
}
public void forEachRemaining(Consumer<? super E> action) {
Node<E> p;
if (action == null) throw new NullPointerException();
final ConcurrentLinkedDeque<E> q = this.queue;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null)) {
exhausted = true;
do {
E e = p.item;
if (p == (p = p.next))
p = q.first();
if (e != null)
action.accept(e);
} while (p != null);
}
}
public boolean tryAdvance(Consumer<? super E> action) {
Node<E> p;
if (action == null) throw new NullPointerException();
final ConcurrentLinkedDeque<E> q = this.queue;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null)) {
E e;
do {
e = p.item;
if (p == (p = p.next))
p = q.first();
} while (e == null && p != null);
if ((current = p) == null)
exhausted = true;
if (e != null) {
action.accept(e);
return true;
}
}
return false;
}
public long estimateSize() { return Long.MAX_VALUE; }
public int characteristics() {
return Spliterator.ORDERED | Spliterator.NONNULL |
Spliterator.CONCURRENT;
}
}
public Spliterator<E> spliterator() {
return new CLDSpliterator<E>(this);
}
/** /**
* Saves this deque to a stream (that is, serializes it). * Saves this deque to a stream (that is, serializes it).
* *
......
...@@ -41,6 +41,9 @@ import java.util.Collection; ...@@ -41,6 +41,9 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Queue; import java.util.Queue;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
/** /**
* An unbounded thread-safe {@linkplain Queue queue} based on linked nodes. * An unbounded thread-safe {@linkplain Queue queue} based on linked nodes.
...@@ -56,7 +59,7 @@ import java.util.Queue; ...@@ -56,7 +59,7 @@ import java.util.Queue;
* Like most other concurrent collection implementations, this class * Like most other concurrent collection implementations, this class
* does not permit the use of {@code null} elements. * does not permit the use of {@code null} elements.
* *
* <p>This implementation employs an efficient &quot;wait-free&quot; * <p>This implementation employs an efficient <em>non-blocking</em>
* algorithm based on one described in <a * algorithm based on one described in <a
* href="http://www.cs.rochester.edu/u/michael/PODC96.html"> Simple, * href="http://www.cs.rochester.edu/u/michael/PODC96.html"> Simple,
* Fast, and Practical Non-Blocking and Blocking Concurrent Queue * Fast, and Practical Non-Blocking and Blocking Concurrent Queue
...@@ -295,7 +298,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -295,7 +298,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
} }
/** /**
* Try to CAS head to p. If successful, repoint old head to itself * Tries to CAS head to p. If successful, repoint old head to itself
* as sentinel for succ(), below. * as sentinel for succ(), below.
*/ */
final void updateHead(Node<E> h, Node<E> p) { final void updateHead(Node<E> h, Node<E> p) {
...@@ -792,6 +795,96 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -792,6 +795,96 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
tail = t; tail = t;
} }
/** A customized variant of Spliterators.IteratorSpliterator */
static final class CLQSpliterator<E> implements Spliterator<E> {
static final int MAX_BATCH = 1 << 25; // max batch array size;
final ConcurrentLinkedQueue<E> queue;
Node<E> current; // current node; null until initialized
int batch; // batch size for splits
boolean exhausted; // true when no more nodes
CLQSpliterator(ConcurrentLinkedQueue<E> queue) {
this.queue = queue;
}
public Spliterator<E> trySplit() {
Node<E> p;
final ConcurrentLinkedQueue<E> q = this.queue;
int b = batch;
int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null) &&
p.next != null) {
Object[] a = new Object[n];
int i = 0;
do {
if ((a[i] = p.item) != null)
++i;
if (p == (p = p.next))
p = q.first();
} while (p != null && i < n);
if ((current = p) == null)
exhausted = true;
if (i > 0) {
batch = i;
return Spliterators.spliterator
(a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
Spliterator.CONCURRENT);
}
}
return null;
}
public void forEachRemaining(Consumer<? super E> action) {
Node<E> p;
if (action == null) throw new NullPointerException();
final ConcurrentLinkedQueue<E> q = this.queue;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null)) {
exhausted = true;
do {
E e = p.item;
if (p == (p = p.next))
p = q.first();
if (e != null)
action.accept(e);
} while (p != null);
}
}
public boolean tryAdvance(Consumer<? super E> action) {
Node<E> p;
if (action == null) throw new NullPointerException();
final ConcurrentLinkedQueue<E> q = this.queue;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null)) {
E e;
do {
e = p.item;
if (p == (p = p.next))
p = q.first();
} while (e == null && p != null);
if ((current = p) == null)
exhausted = true;
if (e != null) {
action.accept(e);
return true;
}
}
return false;
}
public long estimateSize() { return Long.MAX_VALUE; }
public int characteristics() {
return Spliterator.ORDERED | Spliterator.NONNULL |
Spliterator.CONCURRENT;
}
}
public Spliterator<E> spliterator() {
return new CLQSpliterator<E>(this);
}
/** /**
* Throws NullPointerException if argument is null. * Throws NullPointerException if argument is null.
* *
......
...@@ -34,7 +34,17 @@ ...@@ -34,7 +34,17 @@
*/ */
package java.util.concurrent; package java.util.concurrent;
import java.util.*; import java.util.AbstractSet;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.Spliterator;
/** /**
* A scalable concurrent {@link NavigableSet} implementation based on * A scalable concurrent {@link NavigableSet} implementation based on
...@@ -44,33 +54,33 @@ import java.util.*; ...@@ -44,33 +54,33 @@ import java.util.*;
* on which constructor is used. * on which constructor is used.
* *
* <p>This implementation provides expected average <i>log(n)</i> time * <p>This implementation provides expected average <i>log(n)</i> time
* cost for the <tt>contains</tt>, <tt>add</tt>, and <tt>remove</tt> * cost for the {@code contains}, {@code add}, and {@code remove}
* operations and their variants. Insertion, removal, and access * operations and their variants. Insertion, removal, and access
* operations safely execute concurrently by multiple threads. * operations safely execute concurrently by multiple threads.
* Iterators are <i>weakly consistent</i>, returning elements * Iterators are <i>weakly consistent</i>, returning elements
* reflecting the state of the set at some point at or since the * reflecting the state of the set at some point at or since the
* creation of the iterator. They do <em>not</em> throw {@link * creation of the iterator. They do <em>not</em> throw {@link
* ConcurrentModificationException}, and may proceed concurrently with * java.util.ConcurrentModificationException}, and may proceed
* other operations. Ascending ordered views and their iterators are * concurrently with other operations. Ascending ordered views and
* faster than descending ones. * their iterators are faster than descending ones.
* *
* <p>Beware that, unlike in most collections, the <tt>size</tt> * <p>Beware that, unlike in most collections, the {@code size}
* method is <em>not</em> a constant-time operation. Because of the * method is <em>not</em> a constant-time operation. Because of the
* asynchronous nature of these sets, determining the current number * asynchronous nature of these sets, determining the current number
* of elements requires a traversal of the elements, and so may report * of elements requires a traversal of the elements, and so may report
* inaccurate results if this collection is modified during traversal. * inaccurate results if this collection is modified during traversal.
* Additionally, the bulk operations <tt>addAll</tt>, * Additionally, the bulk operations {@code addAll},
* <tt>removeAll</tt>, <tt>retainAll</tt>, <tt>containsAll</tt>, * {@code removeAll}, {@code retainAll}, {@code containsAll},
* <tt>equals</tt>, and <tt>toArray</tt> are <em>not</em> guaranteed * {@code equals}, and {@code toArray} are <em>not</em> guaranteed
* to be performed atomically. For example, an iterator operating * to be performed atomically. For example, an iterator operating
* concurrently with an <tt>addAll</tt> operation might view only some * concurrently with an {@code addAll} operation might view only some
* of the added elements. * of the added elements.
* *
* <p>This class and its iterators implement all of the * <p>This class and its iterators implement all of the
* <em>optional</em> methods of the {@link Set} and {@link Iterator} * <em>optional</em> methods of the {@link Set} and {@link Iterator}
* interfaces. Like most other concurrent collection implementations, * interfaces. Like most other concurrent collection implementations,
* this class does not permit the use of <tt>null</tt> elements, * this class does not permit the use of {@code null} elements,
* because <tt>null</tt> arguments and return values cannot be reliably * because {@code null} arguments and return values cannot be reliably
* distinguished from the absence of elements. * distinguished from the absence of elements.
* *
* <p>This class is a member of the * <p>This class is a member of the
...@@ -90,7 +100,7 @@ public class ConcurrentSkipListSet<E> ...@@ -90,7 +100,7 @@ public class ConcurrentSkipListSet<E>
/** /**
* The underlying map. Uses Boolean.TRUE as value for each * The underlying map. Uses Boolean.TRUE as value for each
* element. This field is declared final for the sake of thread * element. This field is declared final for the sake of thread
* safety, which entails some ugliness in clone() * safety, which entails some ugliness in clone().
*/ */
private final ConcurrentNavigableMap<E,Object> m; private final ConcurrentNavigableMap<E,Object> m;
...@@ -107,7 +117,7 @@ public class ConcurrentSkipListSet<E> ...@@ -107,7 +117,7 @@ public class ConcurrentSkipListSet<E>
* the specified comparator. * the specified comparator.
* *
* @param comparator the comparator that will be used to order this set. * @param comparator the comparator that will be used to order this set.
* If <tt>null</tt>, the {@linkplain Comparable natural * If {@code null}, the {@linkplain Comparable natural
* ordering} of the elements will be used. * ordering} of the elements will be used.
*/ */
public ConcurrentSkipListSet(Comparator<? super E> comparator) { public ConcurrentSkipListSet(Comparator<? super E> comparator) {
...@@ -120,7 +130,7 @@ public class ConcurrentSkipListSet<E> ...@@ -120,7 +130,7 @@ public class ConcurrentSkipListSet<E>
* {@linkplain Comparable natural ordering}. * {@linkplain Comparable natural ordering}.
* *
* @param c The elements that will comprise the new set * @param c The elements that will comprise the new set
* @throws ClassCastException if the elements in <tt>c</tt> are * @throws ClassCastException if the elements in {@code c} are
* not {@link Comparable}, or are not mutually comparable * not {@link Comparable}, or are not mutually comparable
* @throws NullPointerException if the specified collection or any * @throws NullPointerException if the specified collection or any
* of its elements are null * of its elements are null
...@@ -151,7 +161,7 @@ public class ConcurrentSkipListSet<E> ...@@ -151,7 +161,7 @@ public class ConcurrentSkipListSet<E>
} }
/** /**
* Returns a shallow copy of this <tt>ConcurrentSkipListSet</tt> * Returns a shallow copy of this {@code ConcurrentSkipListSet}
* instance. (The elements themselves are not cloned.) * instance. (The elements themselves are not cloned.)
* *
* @return a shallow copy of this set * @return a shallow copy of this set
...@@ -172,8 +182,8 @@ public class ConcurrentSkipListSet<E> ...@@ -172,8 +182,8 @@ public class ConcurrentSkipListSet<E>
/** /**
* Returns the number of elements in this set. If this set * Returns the number of elements in this set. If this set
* contains more than <tt>Integer.MAX_VALUE</tt> elements, it * contains more than {@code Integer.MAX_VALUE} elements, it
* returns <tt>Integer.MAX_VALUE</tt>. * returns {@code Integer.MAX_VALUE}.
* *
* <p>Beware that, unlike in most collections, this method is * <p>Beware that, unlike in most collections, this method is
* <em>NOT</em> a constant-time operation. Because of the * <em>NOT</em> a constant-time operation. Because of the
...@@ -191,20 +201,20 @@ public class ConcurrentSkipListSet<E> ...@@ -191,20 +201,20 @@ public class ConcurrentSkipListSet<E>
} }
/** /**
* Returns <tt>true</tt> if this set contains no elements. * Returns {@code true} if this set contains no elements.
* @return <tt>true</tt> if this set contains no elements * @return {@code true} if this set contains no elements
*/ */
public boolean isEmpty() { public boolean isEmpty() {
return m.isEmpty(); return m.isEmpty();
} }
/** /**
* Returns <tt>true</tt> if this set contains the specified element. * Returns {@code true} if this set contains the specified element.
* More formally, returns <tt>true</tt> if and only if this set * More formally, returns {@code true} if and only if this set
* contains an element <tt>e</tt> such that <tt>o.equals(e)</tt>. * contains an element {@code e} such that {@code o.equals(e)}.
* *
* @param o object to be checked for containment in this set * @param o object to be checked for containment in this set
* @return <tt>true</tt> if this set contains the specified element * @return {@code true} if this set contains the specified element
* @throws ClassCastException if the specified element cannot be * @throws ClassCastException if the specified element cannot be
* compared with the elements currently in this set * compared with the elements currently in this set
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
...@@ -215,15 +225,15 @@ public class ConcurrentSkipListSet<E> ...@@ -215,15 +225,15 @@ public class ConcurrentSkipListSet<E>
/** /**
* Adds the specified element to this set if it is not already present. * Adds the specified element to this set if it is not already present.
* More formally, adds the specified element <tt>e</tt> to this set if * More formally, adds the specified element {@code e} to this set if
* the set contains no element <tt>e2</tt> such that <tt>e.equals(e2)</tt>. * the set contains no element {@code e2} such that {@code e.equals(e2)}.
* If this set already contains the element, the call leaves the set * If this set already contains the element, the call leaves the set
* unchanged and returns <tt>false</tt>. * unchanged and returns {@code false}.
* *
* @param e element to be added to this set * @param e element to be added to this set
* @return <tt>true</tt> if this set did not already contain the * @return {@code true} if this set did not already contain the
* specified element * specified element
* @throws ClassCastException if <tt>e</tt> cannot be compared * @throws ClassCastException if {@code e} cannot be compared
* with the elements currently in this set * with the elements currently in this set
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
*/ */
...@@ -233,15 +243,15 @@ public class ConcurrentSkipListSet<E> ...@@ -233,15 +243,15 @@ public class ConcurrentSkipListSet<E>
/** /**
* Removes the specified element from this set if it is present. * Removes the specified element from this set if it is present.
* More formally, removes an element <tt>e</tt> such that * More formally, removes an element {@code e} such that
* <tt>o.equals(e)</tt>, if this set contains such an element. * {@code o.equals(e)}, if this set contains such an element.
* Returns <tt>true</tt> if this set contained the element (or * Returns {@code true} if this set contained the element (or
* equivalently, if this set changed as a result of the call). * equivalently, if this set changed as a result of the call).
* (This set will not contain the element once the call returns.) * (This set will not contain the element once the call returns.)
* *
* @param o object to be removed from this set, if present * @param o object to be removed from this set, if present
* @return <tt>true</tt> if this set contained the specified element * @return {@code true} if this set contained the specified element
* @throws ClassCastException if <tt>o</tt> cannot be compared * @throws ClassCastException if {@code o} cannot be compared
* with the elements currently in this set * with the elements currently in this set
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
*/ */
...@@ -279,7 +289,7 @@ public class ConcurrentSkipListSet<E> ...@@ -279,7 +289,7 @@ public class ConcurrentSkipListSet<E>
/** /**
* Compares the specified object with this set for equality. Returns * Compares the specified object with this set for equality. Returns
* <tt>true</tt> if the specified object is also a set, the two sets * {@code true} if the specified object is also a set, the two sets
* have the same size, and every member of the specified set is * have the same size, and every member of the specified set is
* contained in this set (or equivalently, every member of this set is * contained in this set (or equivalently, every member of this set is
* contained in the specified set). This definition ensures that the * contained in the specified set). This definition ensures that the
...@@ -287,7 +297,7 @@ public class ConcurrentSkipListSet<E> ...@@ -287,7 +297,7 @@ public class ConcurrentSkipListSet<E>
* set interface. * set interface.
* *
* @param o the object to be compared for equality with this set * @param o the object to be compared for equality with this set
* @return <tt>true</tt> if the specified object is equal to this set * @return {@code true} if the specified object is equal to this set
*/ */
public boolean equals(Object o) { public boolean equals(Object o) {
// Override AbstractSet version to avoid calling size() // Override AbstractSet version to avoid calling size()
...@@ -312,7 +322,7 @@ public class ConcurrentSkipListSet<E> ...@@ -312,7 +322,7 @@ public class ConcurrentSkipListSet<E>
* value is the <i>asymmetric set difference</i> of the two sets. * value is the <i>asymmetric set difference</i> of the two sets.
* *
* @param c collection containing elements to be removed from this set * @param c collection containing elements to be removed from this set
* @return <tt>true</tt> if this set changed as a result of the call * @return {@code true} if this set changed as a result of the call
* @throws ClassCastException if the types of one or more elements in this * @throws ClassCastException if the types of one or more elements in this
* set are incompatible with the specified collection * set are incompatible with the specified collection
* @throws NullPointerException if the specified collection or any * @throws NullPointerException if the specified collection or any
...@@ -380,14 +390,14 @@ public class ConcurrentSkipListSet<E> ...@@ -380,14 +390,14 @@ public class ConcurrentSkipListSet<E>
} }
/** /**
* @throws NoSuchElementException {@inheritDoc} * @throws java.util.NoSuchElementException {@inheritDoc}
*/ */
public E first() { public E first() {
return m.firstKey(); return m.firstKey();
} }
/** /**
* @throws NoSuchElementException {@inheritDoc} * @throws java.util.NoSuchElementException {@inheritDoc}
*/ */
public E last() { public E last() {
return m.lastKey(); return m.lastKey();
...@@ -460,7 +470,7 @@ public class ConcurrentSkipListSet<E> ...@@ -460,7 +470,7 @@ public class ConcurrentSkipListSet<E>
* reflected in the descending set, and vice-versa. * reflected in the descending set, and vice-versa.
* *
* <p>The returned set has an ordering equivalent to * <p>The returned set has an ordering equivalent to
* <tt>{@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator())</tt>. * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}{@code (comparator())}.
* The expression {@code s.descendingSet().descendingSet()} returns a * The expression {@code s.descendingSet().descendingSet()} returns a
* view of {@code s} essentially equivalent to {@code s}. * view of {@code s} essentially equivalent to {@code s}.
* *
...@@ -470,6 +480,14 @@ public class ConcurrentSkipListSet<E> ...@@ -470,6 +480,14 @@ public class ConcurrentSkipListSet<E>
return new ConcurrentSkipListSet<E>(m.descendingMap()); return new ConcurrentSkipListSet<E>(m.descendingMap());
} }
@SuppressWarnings("unchecked")
public Spliterator<E> spliterator() {
if (m instanceof ConcurrentSkipListMap)
return ((ConcurrentSkipListMap<E,?>)m).keySpliterator();
else
return (Spliterator<E>)((ConcurrentSkipListMap.SubMap<E,?>)m).keyIterator();
}
// Support for resetting map in clone // Support for resetting map in clone
private void setMap(ConcurrentNavigableMap<E,Object> map) { private void setMap(ConcurrentNavigableMap<E,Object> map) {
UNSAFE.putObjectVolatile(this, mapOffset, map); UNSAFE.putObjectVolatile(this, mapOffset, map);
......
...@@ -34,7 +34,14 @@ ...@@ -34,7 +34,14 @@
*/ */
package java.util.concurrent; package java.util.concurrent;
import java.util.*; import java.util.Collection;
import java.util.Set;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Predicate;
import java.util.function.Consumer;
/** /**
* A {@link java.util.Set} that uses an internal {@link CopyOnWriteArrayList} * A {@link java.util.Set} that uses an internal {@link CopyOnWriteArrayList}
...@@ -45,17 +52,17 @@ import java.util.*; ...@@ -45,17 +52,17 @@ import java.util.*;
* vastly outnumber mutative operations, and you need * vastly outnumber mutative operations, and you need
* to prevent interference among threads during traversal. * to prevent interference among threads during traversal.
* <li>It is thread-safe. * <li>It is thread-safe.
* <li>Mutative operations (<tt>add</tt>, <tt>set</tt>, <tt>remove</tt>, etc.) * <li>Mutative operations ({@code add}, {@code set}, {@code remove}, etc.)
* are expensive since they usually entail copying the entire underlying * are expensive since they usually entail copying the entire underlying
* array. * array.
* <li>Iterators do not support the mutative <tt>remove</tt> operation. * <li>Iterators do not support the mutative {@code remove} operation.
* <li>Traversal via iterators is fast and cannot encounter * <li>Traversal via iterators is fast and cannot encounter
* interference from other threads. Iterators rely on * interference from other threads. Iterators rely on
* unchanging snapshots of the array at the time the iterators were * unchanging snapshots of the array at the time the iterators were
* constructed. * constructed.
* </ul> * </ul>
* *
* <p> <b>Sample Usage.</b> The following code sketch uses a * <p><b>Sample Usage.</b> The following code sketch uses a
* copy-on-write set to maintain a set of Handler objects that * copy-on-write set to maintain a set of Handler objects that
* perform some action upon state updates. * perform some action upon state updates.
* *
...@@ -73,7 +80,7 @@ import java.util.*; ...@@ -73,7 +80,7 @@ import java.util.*;
* public void update() { * public void update() {
* changeState(); * changeState();
* for (Handler handler : handlers) * for (Handler handler : handlers)
* handler.handle(); * handler.handle();
* } * }
* }}</pre> * }}</pre>
* *
...@@ -107,8 +114,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -107,8 +114,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* @throws NullPointerException if the specified collection is null * @throws NullPointerException if the specified collection is null
*/ */
public CopyOnWriteArraySet(Collection<? extends E> c) { public CopyOnWriteArraySet(Collection<? extends E> c) {
al = new CopyOnWriteArrayList<E>(); if (c.getClass() == CopyOnWriteArraySet.class) {
al.addAllAbsent(c); @SuppressWarnings("unchecked") CopyOnWriteArraySet<E> cc =
(CopyOnWriteArraySet<E>)c;
al = new CopyOnWriteArrayList<E>(cc.al);
}
else {
al = new CopyOnWriteArrayList<E>();
al.addAllAbsent(c);
}
} }
/** /**
...@@ -121,22 +135,22 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -121,22 +135,22 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
} }
/** /**
* Returns <tt>true</tt> if this set contains no elements. * Returns {@code true} if this set contains no elements.
* *
* @return <tt>true</tt> if this set contains no elements * @return {@code true} if this set contains no elements
*/ */
public boolean isEmpty() { public boolean isEmpty() {
return al.isEmpty(); return al.isEmpty();
} }
/** /**
* Returns <tt>true</tt> if this set contains the specified element. * Returns {@code true} if this set contains the specified element.
* More formally, returns <tt>true</tt> if and only if this set * More formally, returns {@code true} if and only if this set
* contains an element <tt>e</tt> such that * contains an element {@code e} such that
* <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>. * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
* *
* @param o element whose presence in this set is to be tested * @param o element whose presence in this set is to be tested
* @return <tt>true</tt> if this set contains the specified element * @return {@code true} if this set contains the specified element
*/ */
public boolean contains(Object o) { public boolean contains(Object o) {
return al.contains(o); return al.contains(o);
...@@ -172,7 +186,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -172,7 +186,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>If this set fits in the specified array with room to spare * <p>If this set fits in the specified array with room to spare
* (i.e., the array has more elements than this set), the element in * (i.e., the array has more elements than this set), the element in
* the array immediately following the end of the set is set to * the array immediately following the end of the set is set to
* <tt>null</tt>. (This is useful in determining the length of this * {@code null}. (This is useful in determining the length of this
* set <i>only</i> if the caller knows that this set does not contain * set <i>only</i> if the caller knows that this set does not contain
* any null elements.) * any null elements.)
* *
...@@ -185,14 +199,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -185,14 +199,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* precise control over the runtime type of the output array, and may, * precise control over the runtime type of the output array, and may,
* under certain circumstances, be used to save allocation costs. * under certain circumstances, be used to save allocation costs.
* *
* <p>Suppose <tt>x</tt> is a set known to contain only strings. * <p>Suppose {@code x} is a set known to contain only strings.
* The following code can be used to dump the set into a newly allocated * The following code can be used to dump the set into a newly allocated
* array of <tt>String</tt>: * array of {@code String}:
* *
* <pre> {@code String[] y = x.toArray(new String[0]);}</pre> * <pre> {@code String[] y = x.toArray(new String[0]);}</pre>
* *
* Note that <tt>toArray(new Object[0])</tt> is identical in function to * Note that {@code toArray(new Object[0])} is identical in function to
* <tt>toArray()</tt>. * {@code toArray()}.
* *
* @param a the array into which the elements of this set are to be * @param a the array into which the elements of this set are to be
* stored, if it is big enough; otherwise, a new array of the same * stored, if it is big enough; otherwise, a new array of the same
...@@ -217,15 +231,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -217,15 +231,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/** /**
* Removes the specified element from this set if it is present. * Removes the specified element from this set if it is present.
* More formally, removes an element <tt>e</tt> such that * More formally, removes an element {@code e} such that
* <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
* if this set contains such an element. Returns <tt>true</tt> if * if this set contains such an element. Returns {@code true} if
* this set contained the element (or equivalently, if this set * this set contained the element (or equivalently, if this set
* changed as a result of the call). (This set will not contain the * changed as a result of the call). (This set will not contain the
* element once the call returns.) * element once the call returns.)
* *
* @param o object to be removed from this set, if present * @param o object to be removed from this set, if present
* @return <tt>true</tt> if this set contained the specified element * @return {@code true} if this set contained the specified element
*/ */
public boolean remove(Object o) { public boolean remove(Object o) {
return al.remove(o); return al.remove(o);
...@@ -233,14 +247,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -233,14 +247,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/** /**
* Adds the specified element to this set if it is not already present. * Adds the specified element to this set if it is not already present.
* More formally, adds the specified element <tt>e</tt> to this set if * More formally, adds the specified element {@code e} to this set if
* the set contains no element <tt>e2</tt> such that * the set contains no element {@code e2} such that
* <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>. * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
* If this set already contains the element, the call leaves the set * If this set already contains the element, the call leaves the set
* unchanged and returns <tt>false</tt>. * unchanged and returns {@code false}.
* *
* @param e element to be added to this set * @param e element to be added to this set
* @return <tt>true</tt> if this set did not already contain the specified * @return {@code true} if this set did not already contain the specified
* element * element
*/ */
public boolean add(E e) { public boolean add(E e) {
...@@ -248,12 +262,12 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -248,12 +262,12 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
} }
/** /**
* Returns <tt>true</tt> if this set contains all of the elements of the * Returns {@code true} if this set contains all of the elements of the
* specified collection. If the specified collection is also a set, this * specified collection. If the specified collection is also a set, this
* method returns <tt>true</tt> if it is a <i>subset</i> of this set. * method returns {@code true} if it is a <i>subset</i> of this set.
* *
* @param c collection to be checked for containment in this set * @param c collection to be checked for containment in this set
* @return <tt>true</tt> if this set contains all of the elements of the * @return {@code true} if this set contains all of the elements of the
* specified collection * specified collection
* @throws NullPointerException if the specified collection is null * @throws NullPointerException if the specified collection is null
* @see #contains(Object) * @see #contains(Object)
...@@ -265,13 +279,13 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -265,13 +279,13 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/** /**
* Adds all of the elements in the specified collection to this set if * Adds all of the elements in the specified collection to this set if
* they're not already present. If the specified collection is also a * they're not already present. If the specified collection is also a
* set, the <tt>addAll</tt> operation effectively modifies this set so * set, the {@code addAll} operation effectively modifies this set so
* that its value is the <i>union</i> of the two sets. The behavior of * that its value is the <i>union</i> of the two sets. The behavior of
* this operation is undefined if the specified collection is modified * this operation is undefined if the specified collection is modified
* while the operation is in progress. * while the operation is in progress.
* *
* @param c collection containing elements to be added to this set * @param c collection containing elements to be added to this set
* @return <tt>true</tt> if this set changed as a result of the call * @return {@code true} if this set changed as a result of the call
* @throws NullPointerException if the specified collection is null * @throws NullPointerException if the specified collection is null
* @see #add(Object) * @see #add(Object)
*/ */
...@@ -286,7 +300,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -286,7 +300,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <i>asymmetric set difference</i> of the two sets. * <i>asymmetric set difference</i> of the two sets.
* *
* @param c collection containing elements to be removed from this set * @param c collection containing elements to be removed from this set
* @return <tt>true</tt> if this set changed as a result of the call * @return {@code true} if this set changed as a result of the call
* @throws ClassCastException if the class of an element of this set * @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection (optional) * is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the * @throws NullPointerException if this set contains a null element and the
...@@ -307,7 +321,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -307,7 +321,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* two sets. * two sets.
* *
* @param c collection containing elements to be retained in this set * @param c collection containing elements to be retained in this set
* @return <tt>true</tt> if this set changed as a result of the call * @return {@code true} if this set changed as a result of the call
* @throws ClassCastException if the class of an element of this set * @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection (optional) * is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the * @throws NullPointerException if this set contains a null element and the
...@@ -326,7 +340,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -326,7 +340,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>The returned iterator provides a snapshot of the state of the set * <p>The returned iterator provides a snapshot of the state of the set
* when the iterator was constructed. No synchronization is needed while * when the iterator was constructed. No synchronization is needed while
* traversing the iterator. The iterator does <em>NOT</em> support the * traversing the iterator. The iterator does <em>NOT</em> support the
* <tt>remove</tt> method. * {@code remove} method.
* *
* @return an iterator over the elements in this set * @return an iterator over the elements in this set
*/ */
...@@ -338,7 +352,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -338,7 +352,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* Compares the specified object with this set for equality. * Compares the specified object with this set for equality.
* Returns {@code true} if the specified object is the same object * Returns {@code true} if the specified object is the same object
* as this object, or if it is also a {@link Set} and the elements * as this object, or if it is also a {@link Set} and the elements
* returned by an {@linkplain List#iterator() iterator} over the * returned by an {@linkplain Set#iterator() iterator} over the
* specified set are the same as the elements returned by an * specified set are the same as the elements returned by an
* iterator over this set. More formally, the two iterators are * iterator over this set. More formally, the two iterators are
* considered to return the same elements if they return the same * considered to return the same elements if they return the same
...@@ -382,6 +396,19 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -382,6 +396,19 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
return k == len; return k == len;
} }
public boolean removeIf(Predicate<? super E> filter) {
return al.removeIf(filter);
}
public void forEach(Consumer<? super E> action) {
al.forEach(action);
}
public Spliterator<E> spliterator() {
return Spliterators.spliterator
(al.getArray(), Spliterator.IMMUTABLE | Spliterator.DISTINCT);
}
/** /**
* Tests for equality, coping with nulls. * Tests for equality, coping with nulls.
*/ */
......
...@@ -92,15 +92,15 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer; ...@@ -92,15 +92,15 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer;
* private final CountDownLatch startSignal; * private final CountDownLatch startSignal;
* private final CountDownLatch doneSignal; * private final CountDownLatch doneSignal;
* Worker(CountDownLatch startSignal, CountDownLatch doneSignal) { * Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
* this.startSignal = startSignal; * this.startSignal = startSignal;
* this.doneSignal = doneSignal; * this.doneSignal = doneSignal;
* } * }
* public void run() { * public void run() {
* try { * try {
* startSignal.await(); * startSignal.await();
* doWork(); * doWork();
* doneSignal.countDown(); * doneSignal.countDown();
* } catch (InterruptedException ex) {} // return; * } catch (InterruptedException ex) {} // return;
* } * }
* *
* void doWork() { ... } * void doWork() { ... }
...@@ -130,14 +130,14 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer; ...@@ -130,14 +130,14 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer;
* private final CountDownLatch doneSignal; * private final CountDownLatch doneSignal;
* private final int i; * private final int i;
* WorkerRunnable(CountDownLatch doneSignal, int i) { * WorkerRunnable(CountDownLatch doneSignal, int i) {
* this.doneSignal = doneSignal; * this.doneSignal = doneSignal;
* this.i = i; * this.i = i;
* } * }
* public void run() { * public void run() {
* try { * try {
* doWork(i); * doWork(i);
* doneSignal.countDown(); * doneSignal.countDown();
* } catch (InterruptedException ex) {} // return; * } catch (InterruptedException ex) {} // return;
* } * }
* *
* void doWork() { ... } * void doWork() { ... }
......
...@@ -45,14 +45,14 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -45,14 +45,14 @@ import java.util.concurrent.locks.ReentrantLock;
* <em>cyclic</em> because it can be re-used after the waiting threads * <em>cyclic</em> because it can be re-used after the waiting threads
* are released. * are released.
* *
* <p>A <tt>CyclicBarrier</tt> supports an optional {@link Runnable} command * <p>A {@code CyclicBarrier} supports an optional {@link Runnable} command
* that is run once per barrier point, after the last thread in the party * that is run once per barrier point, after the last thread in the party
* arrives, but before any threads are released. * arrives, but before any threads are released.
* This <em>barrier action</em> is useful * This <em>barrier action</em> is useful
* for updating shared-state before any of the parties continue. * for updating shared-state before any of the parties continue.
* *
* <p><b>Sample usage:</b> Here is an example of * <p><b>Sample usage:</b> Here is an example of using a barrier in a
* using a barrier in a parallel decomposition design: * parallel decomposition design:
* *
* <pre> {@code * <pre> {@code
* class Solver { * class Solver {
...@@ -81,16 +81,20 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -81,16 +81,20 @@ import java.util.concurrent.locks.ReentrantLock;
* public Solver(float[][] matrix) { * public Solver(float[][] matrix) {
* data = matrix; * data = matrix;
* N = matrix.length; * N = matrix.length;
* barrier = new CyclicBarrier(N, * Runnable barrierAction =
* new Runnable() { * new Runnable() { public void run() { mergeRows(...); }};
* public void run() { * barrier = new CyclicBarrier(N, barrierAction);
* mergeRows(...);
* }
* });
* for (int i = 0; i < N; ++i)
* new Thread(new Worker(i)).start();
* *
* waitUntilDone(); * List<Thread> threads = new ArrayList<Thread>(N);
* for (int i = 0; i < N; i++) {
* Thread thread = new Thread(new Worker(i));
* threads.add(thread);
* thread.start();
* }
*
* // wait until done
* for (Thread thread : threads)
* thread.join();
* } * }
* }}</pre> * }}</pre>
* *
...@@ -98,8 +102,8 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -98,8 +102,8 @@ import java.util.concurrent.locks.ReentrantLock;
* barrier until all rows have been processed. When all rows are processed * barrier until all rows have been processed. When all rows are processed
* the supplied {@link Runnable} barrier action is executed and merges the * the supplied {@link Runnable} barrier action is executed and merges the
* rows. If the merger * rows. If the merger
* determines that a solution has been found then <tt>done()</tt> will return * determines that a solution has been found then {@code done()} will return
* <tt>true</tt> and each worker will terminate. * {@code true} and each worker will terminate.
* *
* <p>If the barrier action does not rely on the parties being suspended when * <p>If the barrier action does not rely on the parties being suspended when
* it is executed, then any of the threads in the party could execute that * it is executed, then any of the threads in the party could execute that
...@@ -112,7 +116,7 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -112,7 +116,7 @@ import java.util.concurrent.locks.ReentrantLock;
* // log the completion of this iteration * // log the completion of this iteration
* }}</pre> * }}</pre>
* *
* <p>The <tt>CyclicBarrier</tt> uses an all-or-none breakage model * <p>The {@code CyclicBarrier} uses an all-or-none breakage model
* for failed synchronization attempts: If a thread leaves a barrier * for failed synchronization attempts: If a thread leaves a barrier
* point prematurely because of interruption, failure, or timeout, all * point prematurely because of interruption, failure, or timeout, all
* other threads waiting at that barrier point will also leave * other threads waiting at that barrier point will also leave
...@@ -139,7 +143,7 @@ public class CyclicBarrier { ...@@ -139,7 +143,7 @@ public class CyclicBarrier {
* is reset. There can be many generations associated with threads * is reset. There can be many generations associated with threads
* using the barrier - due to the non-deterministic way the lock * using the barrier - due to the non-deterministic way the lock
* may be allocated to waiting threads - but only one of these * may be allocated to waiting threads - but only one of these
* can be active at a time (the one to which <tt>count</tt> applies) * can be active at a time (the one to which {@code count} applies)
* and all the rest are either broken or tripped. * and all the rest are either broken or tripped.
* There need not be an active generation if there has been a break * There need not be an active generation if there has been a break
* but no subsequent reset. * but no subsequent reset.
...@@ -259,7 +263,7 @@ public class CyclicBarrier { ...@@ -259,7 +263,7 @@ public class CyclicBarrier {
} }
/** /**
* Creates a new <tt>CyclicBarrier</tt> that will trip when the * Creates a new {@code CyclicBarrier} that will trip when the
* given number of parties (threads) are waiting upon it, and which * given number of parties (threads) are waiting upon it, and which
* will execute the given barrier action when the barrier is tripped, * will execute the given barrier action when the barrier is tripped,
* performed by the last thread entering the barrier. * performed by the last thread entering the barrier.
...@@ -278,7 +282,7 @@ public class CyclicBarrier { ...@@ -278,7 +282,7 @@ public class CyclicBarrier {
} }
/** /**
* Creates a new <tt>CyclicBarrier</tt> that will trip when the * Creates a new {@code CyclicBarrier} that will trip when the
* given number of parties (threads) are waiting upon it, and * given number of parties (threads) are waiting upon it, and
* does not perform a predefined action when the barrier is tripped. * does not perform a predefined action when the barrier is tripped.
* *
...@@ -301,7 +305,7 @@ public class CyclicBarrier { ...@@ -301,7 +305,7 @@ public class CyclicBarrier {
/** /**
* Waits until all {@linkplain #getParties parties} have invoked * Waits until all {@linkplain #getParties parties} have invoked
* <tt>await</tt> on this barrier. * {@code await} on this barrier.
* *
* <p>If the current thread is not the last to arrive then it is * <p>If the current thread is not the last to arrive then it is
* disabled for thread scheduling purposes and lies dormant until * disabled for thread scheduling purposes and lies dormant until
...@@ -326,7 +330,7 @@ public class CyclicBarrier { ...@@ -326,7 +330,7 @@ public class CyclicBarrier {
* *
* <p>If the barrier is {@link #reset} while any thread is waiting, * <p>If the barrier is {@link #reset} while any thread is waiting,
* or if the barrier {@linkplain #isBroken is broken} when * or if the barrier {@linkplain #isBroken is broken} when
* <tt>await</tt> is invoked, or while any thread is waiting, then * {@code await} is invoked, or while any thread is waiting, then
* {@link BrokenBarrierException} is thrown. * {@link BrokenBarrierException} is thrown.
* *
* <p>If any thread is {@linkplain Thread#interrupt interrupted} while waiting, * <p>If any thread is {@linkplain Thread#interrupt interrupted} while waiting,
...@@ -343,7 +347,7 @@ public class CyclicBarrier { ...@@ -343,7 +347,7 @@ public class CyclicBarrier {
* the broken state. * the broken state.
* *
* @return the arrival index of the current thread, where index * @return the arrival index of the current thread, where index
* <tt>{@link #getParties()} - 1</tt> indicates the first * {@code getParties() - 1} indicates the first
* to arrive and zero indicates the last to arrive * to arrive and zero indicates the last to arrive
* @throws InterruptedException if the current thread was interrupted * @throws InterruptedException if the current thread was interrupted
* while waiting * while waiting
...@@ -351,7 +355,7 @@ public class CyclicBarrier { ...@@ -351,7 +355,7 @@ public class CyclicBarrier {
* interrupted or timed out while the current thread was * interrupted or timed out while the current thread was
* waiting, or the barrier was reset, or the barrier was * waiting, or the barrier was reset, or the barrier was
* broken when {@code await} was called, or the barrier * broken when {@code await} was called, or the barrier
* action (if present) failed due an exception. * action (if present) failed due to an exception
*/ */
public int await() throws InterruptedException, BrokenBarrierException { public int await() throws InterruptedException, BrokenBarrierException {
try { try {
...@@ -363,7 +367,7 @@ public class CyclicBarrier { ...@@ -363,7 +367,7 @@ public class CyclicBarrier {
/** /**
* Waits until all {@linkplain #getParties parties} have invoked * Waits until all {@linkplain #getParties parties} have invoked
* <tt>await</tt> on this barrier, or the specified waiting time elapses. * {@code await} on this barrier, or the specified waiting time elapses.
* *
* <p>If the current thread is not the last to arrive then it is * <p>If the current thread is not the last to arrive then it is
* disabled for thread scheduling purposes and lies dormant until * disabled for thread scheduling purposes and lies dormant until
...@@ -393,7 +397,7 @@ public class CyclicBarrier { ...@@ -393,7 +397,7 @@ public class CyclicBarrier {
* *
* <p>If the barrier is {@link #reset} while any thread is waiting, * <p>If the barrier is {@link #reset} while any thread is waiting,
* or if the barrier {@linkplain #isBroken is broken} when * or if the barrier {@linkplain #isBroken is broken} when
* <tt>await</tt> is invoked, or while any thread is waiting, then * {@code await} is invoked, or while any thread is waiting, then
* {@link BrokenBarrierException} is thrown. * {@link BrokenBarrierException} is thrown.
* *
* <p>If any thread is {@linkplain Thread#interrupt interrupted} while * <p>If any thread is {@linkplain Thread#interrupt interrupted} while
...@@ -412,16 +416,17 @@ public class CyclicBarrier { ...@@ -412,16 +416,17 @@ public class CyclicBarrier {
* @param timeout the time to wait for the barrier * @param timeout the time to wait for the barrier
* @param unit the time unit of the timeout parameter * @param unit the time unit of the timeout parameter
* @return the arrival index of the current thread, where index * @return the arrival index of the current thread, where index
* <tt>{@link #getParties()} - 1</tt> indicates the first * {@code getParties() - 1} indicates the first
* to arrive and zero indicates the last to arrive * to arrive and zero indicates the last to arrive
* @throws InterruptedException if the current thread was interrupted * @throws InterruptedException if the current thread was interrupted
* while waiting * while waiting
* @throws TimeoutException if the specified timeout elapses * @throws TimeoutException if the specified timeout elapses.
* In this case the barrier will be broken.
* @throws BrokenBarrierException if <em>another</em> thread was * @throws BrokenBarrierException if <em>another</em> thread was
* interrupted or timed out while the current thread was * interrupted or timed out while the current thread was
* waiting, or the barrier was reset, or the barrier was broken * waiting, or the barrier was reset, or the barrier was broken
* when {@code await} was called, or the barrier action (if * when {@code await} was called, or the barrier action (if
* present) failed due an exception * present) failed due to an exception
*/ */
public int await(long timeout, TimeUnit unit) public int await(long timeout, TimeUnit unit)
throws InterruptedException, throws InterruptedException,
......
...@@ -40,8 +40,8 @@ package java.util.concurrent; ...@@ -40,8 +40,8 @@ package java.util.concurrent;
* acted upon after a given delay. * acted upon after a given delay.
* *
* <p>An implementation of this interface must define a * <p>An implementation of this interface must define a
* <tt>compareTo</tt> method that provides an ordering consistent with * {@code compareTo} method that provides an ordering consistent with
* its <tt>getDelay</tt> method. * its {@code getDelay} method.
* *
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
......
...@@ -37,7 +37,17 @@ package java.util.concurrent; ...@@ -37,7 +37,17 @@ package java.util.concurrent;
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.*; import java.util.AbstractQueue;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.SortedSet;
import java.util.Spliterator;
import java.util.function.Consumer;
/** /**
* An unbounded {@linkplain BlockingQueue blocking queue} that uses * An unbounded {@linkplain BlockingQueue blocking queue} that uses
...@@ -342,7 +352,6 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E> ...@@ -342,7 +352,6 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* @param k the position to fill * @param k the position to fill
* @param x the item to insert * @param x the item to insert
* @param array the heap array * @param array the heap array
* @param n heap size
*/ */
private static <T> void siftUpComparable(int k, T x, Object[] array) { private static <T> void siftUpComparable(int k, T x, Object[] array) {
Comparable<? super T> key = (Comparable<? super T>) x; Comparable<? super T> key = (Comparable<? super T>) x;
...@@ -936,6 +945,70 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E> ...@@ -936,6 +945,70 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
} }
} }
// Similar to Collections.ArraySnapshotSpliterator but avoids
// commitment to toArray until needed
static final class PBQSpliterator<E> implements Spliterator<E> {
final PriorityBlockingQueue<E> queue;
Object[] array;
int index;
int fence;
PBQSpliterator(PriorityBlockingQueue<E> queue, Object[] array,
int index, int fence) {
this.queue = queue;
this.array = array;
this.index = index;
this.fence = fence;
}
final int getFence() {
int hi;
if ((hi = fence) < 0)
hi = fence = (array = queue.toArray()).length;
return hi;
}
public Spliterator<E> trySplit() {
int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
return (lo >= mid) ? null :
new PBQSpliterator<E>(queue, array, lo, index = mid);
}
@SuppressWarnings("unchecked")
public void forEachRemaining(Consumer<? super E> action) {
Object[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if ((a = array) == null)
fence = (a = queue.toArray()).length;
if ((hi = fence) <= a.length &&
(i = index) >= 0 && i < (index = hi)) {
do { action.accept((E)a[i]); } while (++i < hi);
}
}
public boolean tryAdvance(Consumer<? super E> action) {
if (action == null)
throw new NullPointerException();
if (getFence() > index && index >= 0) {
@SuppressWarnings("unchecked") E e = (E) array[index++];
action.accept(e);
return true;
}
return false;
}
public long estimateSize() { return (long)(getFence() - index); }
public int characteristics() {
return Spliterator.NONNULL | Spliterator.SIZED | Spliterator.SUBSIZED;
}
}
public Spliterator<E> spliterator() {
return new PBQSpliterator<E>(this, null, 0, -1);
}
// Unsafe mechanics // Unsafe mechanics
private static final sun.misc.Unsafe UNSAFE; private static final sun.misc.Unsafe UNSAFE;
private static final long allocationSpinLockOffset; private static final long allocationSpinLockOffset;
......
...@@ -40,7 +40,7 @@ package java.util.concurrent; ...@@ -40,7 +40,7 @@ package java.util.concurrent;
* operations for which a timeout is specified need a means to * operations for which a timeout is specified need a means to
* indicate that the timeout has occurred. For many such operations it * indicate that the timeout has occurred. For many such operations it
* is possible to return a value that indicates timeout; when that is * is possible to return a value that indicates timeout; when that is
* not possible or desirable then <tt>TimeoutException</tt> should be * not possible or desirable then {@code TimeoutException} should be
* declared and thrown. * declared and thrown.
* *
* @since 1.5 * @since 1.5
...@@ -50,13 +50,13 @@ public class TimeoutException extends Exception { ...@@ -50,13 +50,13 @@ public class TimeoutException extends Exception {
private static final long serialVersionUID = 1900926677490660714L; private static final long serialVersionUID = 1900926677490660714L;
/** /**
* Constructs a <tt>TimeoutException</tt> with no specified detail * Constructs a {@code TimeoutException} with no specified detail
* message. * message.
*/ */
public TimeoutException() {} public TimeoutException() {}
/** /**
* Constructs a <tt>TimeoutException</tt> with the specified detail * Constructs a {@code TimeoutException} with the specified detail
* message. * message.
* *
* @param message the detail message * @param message the detail message
......
此差异已折叠。
.level=INFO
handlers=testgetglobal.HandlerImpl
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册