Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
fc9949fb
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fc9949fb
编写于
7月 03, 2013
作者:
V
vinnie
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
b1a59bac
4bf8cc29
变更
83
展开全部
隐藏空白更改
内联
并排
Showing
83 changed file
with
5916 addition
and
2530 deletion
+5916
-2530
src/share/classes/java/lang/Class.java
src/share/classes/java/lang/Class.java
+266
-356
src/share/classes/java/lang/SecurityManager.java
src/share/classes/java/lang/SecurityManager.java
+8
-0
src/share/classes/java/lang/instrument/Instrumentation.java
src/share/classes/java/lang/instrument/Instrumentation.java
+13
-11
src/share/classes/java/lang/invoke/MethodHandleImpl.java
src/share/classes/java/lang/invoke/MethodHandleImpl.java
+2
-1
src/share/classes/java/lang/invoke/MethodHandles.java
src/share/classes/java/lang/invoke/MethodHandles.java
+16
-60
src/share/classes/java/lang/reflect/Member.java
src/share/classes/java/lang/reflect/Member.java
+0
-2
src/share/classes/java/math/BigInteger.java
src/share/classes/java/math/BigInteger.java
+20
-19
src/share/classes/java/security/KeyStore.java
src/share/classes/java/security/KeyStore.java
+2
-4
src/share/classes/java/security/Provider.java
src/share/classes/java/security/Provider.java
+1
-0
src/share/classes/java/security/Security.java
src/share/classes/java/security/Security.java
+17
-13
src/share/classes/java/security/cert/X509CRL.java
src/share/classes/java/security/cert/X509CRL.java
+4
-2
src/share/classes/java/security/cert/X509CRLEntry.java
src/share/classes/java/security/cert/X509CRLEntry.java
+3
-3
src/share/classes/java/security/cert/X509Certificate.java
src/share/classes/java/security/cert/X509Certificate.java
+19
-12
src/share/classes/java/time/format/DateTimeFormatter.java
src/share/classes/java/time/format/DateTimeFormatter.java
+2
-0
src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
...hare/classes/java/util/concurrent/ArrayBlockingQueue.java
+752
-159
src/share/classes/java/util/concurrent/BlockingDeque.java
src/share/classes/java/util/concurrent/BlockingDeque.java
+61
-58
src/share/classes/java/util/concurrent/BlockingQueue.java
src/share/classes/java/util/concurrent/BlockingQueue.java
+50
-49
src/share/classes/java/util/concurrent/BrokenBarrierException.java
.../classes/java/util/concurrent/BrokenBarrierException.java
+2
-2
src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
...e/classes/java/util/concurrent/ConcurrentLinkedDeque.java
+115
-3
src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
...e/classes/java/util/concurrent/ConcurrentLinkedQueue.java
+95
-2
src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
...e/classes/java/util/concurrent/ConcurrentSkipListMap.java
+1059
-611
src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
...e/classes/java/util/concurrent/ConcurrentSkipListSet.java
+58
-40
src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
...re/classes/java/util/concurrent/CopyOnWriteArrayList.java
+388
-266
src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
...are/classes/java/util/concurrent/CopyOnWriteArraySet.java
+61
-34
src/share/classes/java/util/concurrent/CountDownLatch.java
src/share/classes/java/util/concurrent/CountDownLatch.java
+13
-13
src/share/classes/java/util/concurrent/CyclicBarrier.java
src/share/classes/java/util/concurrent/CyclicBarrier.java
+32
-27
src/share/classes/java/util/concurrent/DelayQueue.java
src/share/classes/java/util/concurrent/DelayQueue.java
+77
-62
src/share/classes/java/util/concurrent/Delayed.java
src/share/classes/java/util/concurrent/Delayed.java
+2
-2
src/share/classes/java/util/concurrent/Exchanger.java
src/share/classes/java/util/concurrent/Exchanger.java
+404
-431
src/share/classes/java/util/concurrent/LinkedBlockingDeque.java
...are/classes/java/util/concurrent/LinkedBlockingDeque.java
+132
-9
src/share/classes/java/util/concurrent/LinkedBlockingQueue.java
...are/classes/java/util/concurrent/LinkedBlockingQueue.java
+126
-4
src/share/classes/java/util/concurrent/LinkedTransferQueue.java
...are/classes/java/util/concurrent/LinkedTransferQueue.java
+113
-1
src/share/classes/java/util/concurrent/Phaser.java
src/share/classes/java/util/concurrent/Phaser.java
+76
-67
src/share/classes/java/util/concurrent/PriorityBlockingQueue.java
...e/classes/java/util/concurrent/PriorityBlockingQueue.java
+75
-2
src/share/classes/java/util/concurrent/SynchronousQueue.java
src/share/classes/java/util/concurrent/SynchronousQueue.java
+51
-47
src/share/classes/java/util/concurrent/TimeUnit.java
src/share/classes/java/util/concurrent/TimeUnit.java
+46
-47
src/share/classes/java/util/concurrent/TimeoutException.java
src/share/classes/java/util/concurrent/TimeoutException.java
+3
-3
src/share/classes/java/util/concurrent/package-info.java
src/share/classes/java/util/concurrent/package-info.java
+8
-6
src/share/classes/java/util/logging/LogManager.java
src/share/classes/java/util/logging/LogManager.java
+113
-13
src/share/classes/java/util/logging/Logger.java
src/share/classes/java/util/logging/Logger.java
+21
-0
src/share/classes/java/util/spi/LocaleServiceProvider.java
src/share/classes/java/util/spi/LocaleServiceProvider.java
+2
-2
src/share/classes/java/util/stream/SliceOps.java
src/share/classes/java/util/stream/SliceOps.java
+3
-3
src/share/classes/javax/crypto/Cipher.java
src/share/classes/javax/crypto/Cipher.java
+3
-3
src/share/classes/javax/crypto/CipherInputStream.java
src/share/classes/javax/crypto/CipherInputStream.java
+1
-1
src/share/classes/javax/crypto/ExemptionMechanism.java
src/share/classes/javax/crypto/ExemptionMechanism.java
+4
-4
src/share/classes/javax/crypto/KeyAgreement.java
src/share/classes/javax/crypto/KeyAgreement.java
+6
-6
src/share/classes/javax/crypto/KeyGenerator.java
src/share/classes/javax/crypto/KeyGenerator.java
+3
-3
src/share/classes/javax/crypto/NullCipher.java
src/share/classes/javax/crypto/NullCipher.java
+4
-1
src/share/classes/javax/security/auth/Subject.java
src/share/classes/javax/security/auth/Subject.java
+19
-1
src/share/classes/javax/security/cert/X509Certificate.java
src/share/classes/javax/security/cert/X509Certificate.java
+20
-15
src/share/classes/sun/security/provider/certpath/RevocationChecker.java
...ses/sun/security/provider/certpath/RevocationChecker.java
+6
-2
test/java/lang/invoke/InvokeDynamicPrintArgs.java
test/java/lang/invoke/InvokeDynamicPrintArgs.java
+24
-24
test/java/lang/invoke/TestCatchExceptionWithVarargs.java
test/java/lang/invoke/TestCatchExceptionWithVarargs.java
+97
-0
test/java/lang/invoke/TestPrivateMember.java
test/java/lang/invoke/TestPrivateMember.java
+57
-0
test/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java
...a/security/cert/CertPathValidator/OCSP/FailoverToCRL.java
+23
-3
test/java/util/logging/LogManagerInstanceTest.java
test/java/util/logging/LogManagerInstanceTest.java
+1
-1
test/java/util/logging/Logger/getGlobal/TestGetGlobal.java
test/java/util/logging/Logger/getGlobal/TestGetGlobal.java
+73
-0
test/java/util/logging/Logger/getGlobal/TestGetGlobalByName.java
...va/util/logging/Logger/getGlobal/TestGetGlobalByName.java
+73
-0
test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java
...til/logging/Logger/getGlobal/TestGetGlobalConcurrent.java
+184
-0
test/java/util/logging/Logger/getGlobal/logging.properties
test/java/util/logging/Logger/getGlobal/logging.properties
+2
-0
test/java/util/logging/Logger/getGlobal/policy
test/java/util/logging/Logger/getGlobal/policy
+7
-0
test/java/util/logging/Logger/getGlobal/testgetglobal/BadLogManagerImpl.java
...ing/Logger/getGlobal/testgetglobal/BadLogManagerImpl.java
+46
-0
test/java/util/logging/Logger/getGlobal/testgetglobal/DummyLogManagerImpl.java
...g/Logger/getGlobal/testgetglobal/DummyLogManagerImpl.java
+35
-0
test/java/util/logging/Logger/getGlobal/testgetglobal/HandlerImpl.java
...l/logging/Logger/getGlobal/testgetglobal/HandlerImpl.java
+46
-0
test/java/util/logging/Logger/getGlobal/testgetglobal/LogManagerImpl1.java
...gging/Logger/getGlobal/testgetglobal/LogManagerImpl1.java
+42
-0
test/java/util/logging/Logger/getGlobal/testgetglobal/LogManagerImpl2.java
...gging/Logger/getGlobal/testgetglobal/LogManagerImpl2.java
+42
-0
test/java/util/logging/Logger/getGlobal/testgetglobal/LogManagerImpl3.java
...gging/Logger/getGlobal/testgetglobal/LogManagerImpl3.java
+59
-0
test/java/util/logging/TestAppletLoggerContext.java
test/java/util/logging/TestAppletLoggerContext.java
+610
-0
test/java/util/stream/test/org/openjdk/tests/java/util/stream/SliceOpTest.java
.../test/org/openjdk/tests/java/util/stream/SliceOpTest.java
+50
-0
test/tools/pack200/AttributeTests.java
test/tools/pack200/AttributeTests.java
+1
-0
test/tools/pack200/BandIntegrity.java
test/tools/pack200/BandIntegrity.java
+3
-2
test/tools/pack200/CommandLineTests.java
test/tools/pack200/CommandLineTests.java
+7
-1
test/tools/pack200/InstructionTests.java
test/tools/pack200/InstructionTests.java
+1
-0
test/tools/pack200/Pack200Props.java
test/tools/pack200/Pack200Props.java
+4
-2
test/tools/pack200/Pack200Test.java
test/tools/pack200/Pack200Test.java
+3
-2
test/tools/pack200/PackageVersionTest.java
test/tools/pack200/PackageVersionTest.java
+3
-3
test/tools/pack200/RepackTest.java
test/tools/pack200/RepackTest.java
+2
-1
test/tools/pack200/T7007157.java
test/tools/pack200/T7007157.java
+2
-1
test/tools/pack200/TestExceptions.java
test/tools/pack200/TestExceptions.java
+3
-2
test/tools/pack200/TimeStamp.java
test/tools/pack200/TimeStamp.java
+2
-1
test/tools/pack200/UnpackerMemoryTest.java
test/tools/pack200/UnpackerMemoryTest.java
+2
-1
test/tools/pack200/Utils.java
test/tools/pack200/Utils.java
+34
-4
test/tools/pack200/typeannos/TestTypeAnnotations.java
test/tools/pack200/typeannos/TestTypeAnnotations.java
+1
-0
未找到文件。
src/share/classes/java/lang/Class.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/lang/SecurityManager.java
浏览文件 @
fc9949fb
...
...
@@ -1675,10 +1675,18 @@ class SecurityManager {
* permission to access members.
* @exception NullPointerException if the <code>clazz</code> argument is
* <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
* @since JDK1.1
* @see #checkPermission(java.security.Permission) checkPermission
*/
@Deprecated
@CallerSensitive
public
void
checkMemberAccess
(
Class
<?>
clazz
,
int
which
)
{
if
(
clazz
==
null
)
{
...
...
src/share/classes/java/lang/instrument/Instrumentation.java
浏览文件 @
fc9949fb
/*
* Copyright (c) 2003, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -363,6 +363,8 @@ public interface Instrumentation {
* Primitive classes (for example, <code>java.lang.Integer.TYPE</code>)
* 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>.
*
* @see #retransformClasses
...
...
@@ -549,14 +551,14 @@ public interface Instrumentation {
* {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer},
* it enables native methods to be
* instrumented.
* <p
/
>
* <p>
* Since native methods cannot be directly instrumented
* (they have no bytecodes), they must be wrapped with
* a non-native method which can be instrumented.
* For example, if we had:
* <pre>
* native boolean foo(int x);</pre>
* <p
/
>
* <p>
* We could transform the class file (with the
* ClassFileTransformer during the initial definition
* of the class) so that this becomes:
...
...
@@ -567,14 +569,14 @@ public interface Instrumentation {
* }
*
* native boolean wrapped_foo(int x);</pre>
* <p
/
>
* <p>
* Where <code>foo</code> becomes a wrapper for the actual native
* method with the appended prefix "wrapped_". Note that
* "wrapped_" would be a poor choice of prefix since it
* might conceivably form the name of an existing method
* thus something like "$$$MyAgentWrapped$$$_" would be
* better but would make these examples less readable.
* <p
/
>
* <p>
* The wrapper will allow data to be collected on the native
* method call, but now the problem becomes linking up the
* wrapped method with the native implementation.
...
...
@@ -583,7 +585,7 @@ public interface Instrumentation {
* which might be:
* <pre>
* Java_somePackage_someClass_foo(JNIEnv* env, jint x)</pre>
* <p
/
>
* <p>
* This function allows the prefix to be specified and the
* proper resolution to occur.
* Specifically, when the standard resolution fails, the
...
...
@@ -596,29 +598,29 @@ public interface Instrumentation {
* <pre>{@code
* method(foo) -> nativeImplementation(foo)
* }</pre>
* <p
/
>
* <p>
* When this fails, the resolution will be retried with
* the specified prefix prepended to the method name,
* yielding the correct resolution:
* <pre>{@code
* method(wrapped_foo) -> nativeImplementation(foo)
* }</pre>
* <p
/
>
* <p>
* For automatic resolution, the JVM will attempt:
* <pre>{@code
* method(wrapped_foo) -> nativeImplementation(wrapped_foo)
* }</pre>
* <p
/
>
* <p>
* When this fails, the resolution will be retried with
* the specified prefix deleted from the implementation name,
* yielding the correct resolution:
* <pre>{@code
* method(wrapped_foo) -> nativeImplementation(foo)
* }</pre>
* <p
/
>
* <p>
* Note that since the prefix is only used when standard
* resolution fails, native methods can be wrapped selectively.
* <p
/
>
* <p>
* Since each <code>ClassFileTransformer</code>
* can do its own transformation of the bytecodes, more
* than one layer of wrappers may be applied. Thus each
...
...
src/share/classes/java/lang/invoke/MethodHandleImpl.java
浏览文件 @
fc9949fb
...
...
@@ -747,7 +747,8 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
GuardWithCatch
gguard
=
new
GuardWithCatch
(
gtarget
,
exType
,
gcatcher
);
if
(
gtarget
==
null
||
gcatcher
==
null
)
throw
new
InternalError
();
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
);
}
}
...
...
src/share/classes/java/lang/invoke/MethodHandles.java
浏览文件 @
fc9949fb
...
...
@@ -41,6 +41,7 @@ import sun.reflect.misc.ReflectUtil;
import
sun.security.util.SecurityConstants
;
import
static
java
.
lang
.
invoke
.
MethodHandleStatics
.*;
import
static
java
.
lang
.
invoke
.
MethodHandleNatives
.
Constants
.*;
import
sun.security.util.SecurityConstants
;
/**
* This class consists exclusively of static methods that operate on or return
...
...
@@ -305,36 +306,30 @@ public class MethodHandles {
* <a name="secmgr"></a>
* If a security manager is present, member lookups are subject to
* 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
* {@link java.lang.SecurityException SecurityException}.
* 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
* is being sought, and {@code defc} as the class in which the
* 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:
* <ul>
* <li>In all cases, {@link SecurityManager#checkMemberAccess
* smgr.checkMemberAccess(refc, Member.PUBLIC)} is called.
* <li>If the class loader of the lookup class is not
* <li>If {@code lookc} is not present, or if its class loader is not
* the same as or an ancestor of the class loader of {@code refc},
* then {@link SecurityManager#checkPackageAccess
* smgr.checkPackageAccess(refcPkg)} is called,
* 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,
* {@link SecurityManager#checkMemberAccess
* 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},
* and if {@code defc} and {@code refc} are different,
* then {@link SecurityManager#checkPackageAccess
* smgr.checkPackageAccess(defcPkg)} is called,
* where {@code defcPkg} is the package of {@code defc}.
...
...
@@ -1053,22 +1048,6 @@ return mh1;
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>.
* Determines a trustable caller class to compare with refc, the symbolic reference class.
...
...
@@ -1079,45 +1058,22 @@ return mh1;
if
(
smgr
==
null
)
return
;
if
(
allowedModes
==
TRUSTED
)
return
;
final
boolean
overridden
=
isCheckMemberAccessOverridden
(
smgr
);
// 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
()
||
!
VerifyAccess
.
classLoaderIsAncestor
(
lookupClass
,
refc
))
{
ReflectUtil
.
checkPackageAccess
(
refc
);
}
// Step
3
:
// Step
2
:
if
(
m
.
isPublic
())
return
;
Class
<?>
defc
=
m
.
getDeclaringClass
();
{
// Inline SecurityManager.checkMemberAccess
final
int
which
=
Member
.
DECLARED
;
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
);
if
(!
isFullPowerLookup
())
{
smgr
.
checkPermission
(
SecurityConstants
.
CHECK_MEMBER_ACCESS_PERMISSION
);
}
}
// Step
4
:
// Step
3
:
if
(
defc
!=
refc
)
{
ReflectUtil
.
checkPackageAccess
(
defc
);
}
...
...
src/share/classes/java/lang/reflect/Member.java
浏览文件 @
fc9949fb
...
...
@@ -42,14 +42,12 @@ interface Member {
/**
* Identifies the set of all public members of a class or interface,
* including inherited members.
* @see java.lang.SecurityManager#checkMemberAccess
*/
public
static
final
int
PUBLIC
=
0
;
/**
* Identifies the set of declared members of a class or interface.
* Inherited members are not included.
* @see java.lang.SecurityManager#checkMemberAccess
*/
public
static
final
int
DECLARED
=
1
;
...
...
src/share/classes/java/math/BigInteger.java
浏览文件 @
fc9949fb
...
...
@@ -1042,7 +1042,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* recalculate powers of radix^(2^n) more than once. This speeds
* Schoenhage recursive base conversion significantly.
*/
private
static
ArrayList
<
BigInteger
>
[]
powerCache
;
private
static
volatile
BigInteger
[]
[]
powerCache
;
/** The cache of logarithms of radices for base conversion. */
private
static
final
double
[]
logCache
;
...
...
@@ -1063,14 +1063,12 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* with just the very first value. Additional values will be created
* on demand.
*/
powerCache
=
(
ArrayList
<
BigInteger
>[])
new
ArrayList
[
Character
.
MAX_RADIX
+
1
];
powerCache
=
new
BigInteger
[
Character
.
MAX_RADIX
+
1
][];
logCache
=
new
double
[
Character
.
MAX_RADIX
+
1
];
for
(
int
i
=
Character
.
MIN_RADIX
;
i
<=
Character
.
MAX_RADIX
;
i
++)
{
powerCache
[
i
]
=
new
ArrayList
<
BigInteger
>(
1
);
powerCache
[
i
].
add
(
BigInteger
.
valueOf
(
i
));
powerCache
[
i
]
=
new
BigInteger
[]
{
BigInteger
.
valueOf
(
i
)
};
logCache
[
i
]
=
Math
.
log
(
i
);
}
}
...
...
@@ -3454,22 +3452,25 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* This could be changed to a more complicated caching method using
* <code>Future</code>.
*/
private
static
synchronized
BigInteger
getRadixConversionCache
(
int
radix
,
int
exponent
)
{
BigInteger
retVal
=
null
;
ArrayList
<
BigInteger
>
cacheLine
=
powerCache
[
radix
];
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
);
}
private
static
BigInteger
getRadixConversionCache
(
int
radix
,
int
exponent
)
{
BigInteger
[]
cacheLine
=
powerCache
[
radix
];
// volatile read
if
(
exponent
<
cacheLine
.
length
)
{
return
cacheLine
[
exponent
];
}
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. */
...
...
src/share/classes/java/security/KeyStore.java
浏览文件 @
fc9949fb
...
...
@@ -227,15 +227,13 @@ public class KeyStore {
* {@link #store(KeyStore.LoadStoreParameter) store} operations.
* <p>
* The following syntax is supported for configuration data:
* <pre>
*
* <pre>{@code
* domain <domainName> [<property> ...] {
* keystore <keystoreName> [<property> ...] ;
* ...
* };
* ...
*
* </pre>
* }</pre>
* where {@code domainName} and {@code keystoreName} are identifiers
* 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
...
...
src/share/classes/java/security/Provider.java
浏览文件 @
fc9949fb
...
...
@@ -67,6 +67,7 @@ import java.lang.reflect.*;
* or modified by applications.
* The following attributes are automatically placed in each Provider object:
* <table cellspacing=4>
* <caption><b>Attributes Automatically Placed in a Provider Object</b></caption>
* <tr><th>Name</th><th>Value</th>
* <tr><td>{@code Provider.id name}</td>
* <td>{@code String.valueOf(provider.getName())}</td>
...
...
src/share/classes/java/security/Security.java
浏览文件 @
fc9949fb
...
...
@@ -480,8 +480,8 @@ public final class Security {
* Returns an array containing all installed providers that satisfy the
* specified selection criterion, or null if no such providers have been
* installed. The returned providers are ordered
* according to their
<a href=
*
"#insertProviderAt(java.security.Provider, int)">preference order</a>
.
* according to their
*
{@linkplain #insertProviderAt(java.security.Provider, int) preference order}
.
*
* <p> A cryptographic service is always associated with a particular
* algorithm or type. For example, a digital signature service is
...
...
@@ -492,8 +492,8 @@ public final class Security {
* <p>The selection criterion must be specified in one of the following two
* formats:
* <ul>
* <li> <i>
<crypto_service>.<algorithm_or_type></i> <p> The
* cryptographic service name must not contain any dots.
* <li> <i>
{@literal <crypto_service>.<algorithm_or_type>}</i>
*
<p> The
cryptographic service name must not contain any dots.
* <p> A
* provider satisfies the specified selection criterion iff the provider
* implements the
...
...
@@ -501,11 +501,12 @@ public final class Security {
* <p> For example, "CertificateFactory.X.509"
* would be satisfied by any provider that supplied
* a CertificateFactory implementation for X.509 certificates.
* <li> <i>
<crypto_service>.<
algorithm_or_type>
*
<attribute_name>:< attribute_value>
</i>
* <li> <i>
{@literal <crypto_service>.<
algorithm_or_type>
*
<attribute_name>:<attribute_value>}
</i>
* <p> The cryptographic service name must not contain any dots. There
* must be one or more space charaters between the
* <i><algorithm_or_type></i> and the <i><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
* provider implements the specified algorithm or type for the specified
* cryptographic service and its implementation meets the
...
...
@@ -558,8 +559,9 @@ public final class Security {
* Returns an array containing all installed providers that satisfy the
* specified* selection criteria, or null if no such providers have been
* installed. The returned providers are ordered
* according to their <a href=
* "#insertProviderAt(java.security.Provider, int)">preference order</a>.
* according to their
* {@linkplain #insertProviderAt(java.security.Provider, int)
* preference order}.
*
* <p>The selection criteria are represented by a map.
* Each map entry represents a selection criterion.
...
...
@@ -567,16 +569,18 @@ public final class Security {
* criteria. The key for any entry in such a map must be in one of the
* following two formats:
* <ul>
* <li> <i>
<crypto_service>.<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 value associated with the key must be an empty string.
* <p> A provider
* satisfies this selection criterion iff the provider implements the
* specified algorithm or type for the specified cryptographic service.
* <li> <i><crypto_service>.<algorithm_or_type> <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
* must be one or more space charaters between the <i><algorithm_or_type></i>
* and the <i><attribute_name></i>.
* must be one or more space charaters between the
* <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.
* A provider satisfies this selection criterion iff the
* provider implements the specified algorithm or type for the specified
...
...
src/share/classes/java/security/cert/X509CRL.java
浏览文件 @
fc9949fb
...
...
@@ -249,7 +249,8 @@ public abstract class X509CRL extends CRL implements X509Extension {
* The ASN.1 definition for this is:
* <pre>
* version Version OPTIONAL,
* -- if present, must be v2<p>
* -- if present, must be v2
*
* Version ::= INTEGER { v1(0), v2(1), v3(2) }
* -- v3 does not apply to CRLs but appears for consistency
* -- with definition of Version for certs
...
...
@@ -413,7 +414,8 @@ public abstract class X509CRL extends CRL implements X509Extension {
* signature algorithm. An example is the string "SHA256withRSA".
* The ASN.1 definition for this is:
* <pre>
* signatureAlgorithm AlgorithmIdentifier<p>
* signatureAlgorithm AlgorithmIdentifier
*
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL }
...
...
src/share/classes/java/security/cert/X509CRLEntry.java
浏览文件 @
fc9949fb
...
...
@@ -43,11 +43,11 @@ import sun.security.x509.X509CRLEntryImpl;
* crlEntryExtensions Extensions OPTIONAL
* -- if present, must be v2
* } OPTIONAL
*
<p>
*
* CertificateSerialNumber ::= INTEGER
*
<p>
*
* Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
*
<p>
*
* Extension ::= SEQUENCE {
* extnId OBJECT IDENTIFIER,
* critical BOOLEAN DEFAULT FALSE,
...
...
src/share/classes/java/security/cert/X509Certificate.java
浏览文件 @
fc9949fb
...
...
@@ -126,10 +126,12 @@ implements X509Extension {
* is valid. It is defined in
* ASN.1 as:
* <pre>
* validity Validity<p>
* validity Validity
*
* Validity ::= SEQUENCE {
* notBefore CertificateValidityDate,
* notAfter CertificateValidityDate }<p>
* notAfter CertificateValidityDate }
*
* CertificateValidityDate ::= CHOICE {
* utcTime UTCTime,
* generalTime GeneralizedTime }
...
...
@@ -165,7 +167,8 @@ implements X509Extension {
* certificate.
* The ASN.1 definition for this is:
* <pre>
* version [0] EXPLICIT Version DEFAULT v1<p>
* version [0] EXPLICIT Version DEFAULT v1
*
* Version ::= INTEGER { v1(0), v2(1), v3(2) }
* </pre>
* @return the version number, i.e. 1, 2 or 3.
...
...
@@ -180,7 +183,7 @@ implements X509Extension {
* serial number identify a unique certificate).
* The ASN.1 definition for this is:
* <pre>
* serialNumber CertificateSerialNumber
<p>
* serialNumber CertificateSerialNumber
*
* CertificateSerialNumber ::= INTEGER
* </pre>
...
...
@@ -204,7 +207,7 @@ implements X509Extension {
* X.500 distinguished name (DN).
* The ASN.1 definition for this is:
* <pre>
* issuer Name
<p>
* issuer Name
*
* Name ::= CHOICE { RDNSequence }
* RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
...
...
@@ -295,11 +298,12 @@ implements X509Extension {
* the certificate.
* The relevant ASN.1 definitions are:
* <pre>
* validity Validity
<p>
* validity Validity
*
* Validity ::= SEQUENCE {
* notBefore CertificateValidityDate,
* notAfter CertificateValidityDate }<p>
* notAfter CertificateValidityDate }
*
* CertificateValidityDate ::= CHOICE {
* utcTime UTCTime,
* generalTime GeneralizedTime }
...
...
@@ -348,7 +352,8 @@ implements X509Extension {
* signature algorithm. An example is the string "SHA256withRSA".
* The ASN.1 definition for this is:
* <pre>
* signatureAlgorithm AlgorithmIdentifier<p>
* signatureAlgorithm AlgorithmIdentifier
*
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL }
...
...
@@ -410,7 +415,8 @@ implements X509Extension {
*
* <p>The ASN.1 definition for this is:
* <pre>
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL<p>
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL
*
* UniqueIdentifier ::= BIT STRING
* </pre>
*
...
...
@@ -424,7 +430,8 @@ implements X509Extension {
*
* <p>The ASN.1 definition for this is:
* <pre>
* subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL<p>
* subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL
*
* UniqueIdentifier ::= BIT STRING
* </pre>
*
...
...
@@ -474,9 +481,9 @@ implements X509Extension {
* indicated in the key usage extension field. The ASN.1
* definition for this is:
* <pre>
* ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
<p>
* ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
*
* KeyPurposeId ::= OBJECT IDENTIFIER
<p>
* KeyPurposeId ::= OBJECT IDENTIFIER
* </pre>
*
* Key purposes may be defined by any organization with a
...
...
src/share/classes/java/time/format/DateTimeFormatter.java
浏览文件 @
fc9949fb
...
...
@@ -1304,6 +1304,7 @@ public final class DateTimeFormatter {
* LocalTime time = parsed.query(LocalTime::from);
* Period extraDays = parsed.query(DateTimeFormatter.parsedExcessDays());
* </pre>
* @return a query that provides access to the excess days that were parsed
*/
public
static
final
TemporalQuery
<
Period
>
parsedExcessDays
()
{
return
PARSED_EXCESS_DAYS
;
...
...
@@ -1344,6 +1345,7 @@ public final class DateTimeFormatter {
* // validate leap-second is correct and apply correct smoothing
* }
* </pre>
* @return a query that provides access to whether a leap-second was parsed
*/
public
static
final
TemporalQuery
<
Boolean
>
parsedLeapSecond
()
{
return
PARSED_LEAP_SECOND
;
...
...
src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/BlockingDeque.java
浏览文件 @
fc9949fb
...
...
@@ -41,17 +41,18 @@ import java.util.*;
* 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.
*
* <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
* satisfied at some point in the future:
* 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,
* and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table:
*
* <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of BlockingDeque methods</caption>
* <tr>
* <td ALIGN=CENTER COLSPAN = 5> <b>First Element (Head)</b></td>
* </tr>
...
...
@@ -116,20 +117,21 @@ import java.util.*;
* </tr>
* </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
* capacity-constrained.
*
* <p>A
<tt>BlockingDeque</tt>
implementation may be used directly as a FIFO
*
<tt>BlockingQueue</tt>
. The methods inherited from the
*
<tt>BlockingQueue</tt>
interface are precisely equivalent to
*
<tt>BlockingDeque</tt>
methods as indicated in the following table:
* <p>A
{@code BlockingDeque}
implementation may be used directly as a FIFO
*
{@code BlockingQueue}
. The methods inherited from the
*
{@code BlockingQueue}
interface are precisely equivalent to
*
{@code BlockingDeque}
methods as indicated in the following table:
*
* <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Comparison of BlockingQueue and BlockingDeque methods</caption>
* <tr>
* <td ALIGN=CENTER> <b>
<tt>BlockingQueue</tt>
Method</b></td>
* <td ALIGN=CENTER> <b>Equivalent
<tt>BlockingDeque</tt>
Method</b></td>
* <td ALIGN=CENTER> <b>
{@code BlockingQueue}
Method</b></td>
* <td ALIGN=CENTER> <b>Equivalent
{@code BlockingDeque}
Method</b></td>
* </tr>
* <tr>
* <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td>
...
...
@@ -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
* 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
* preferable to use {@link #offerFirst(Object) offerFirst}.
*
...
...
@@ -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
* 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
* preferable to use {@link #offerLast(Object) offerLast}.
*
...
...
@@ -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
* 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.
* When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addFirst(Object) addFirst} method, which can
...
...
@@ -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
* 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.
* When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addLast(Object) addLast} method, which can
...
...
@@ -302,10 +304,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return
<tt>true</tt> if successful, or <tt>false</tt>
if
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return
{@code true} if successful, or {@code false}
if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
...
...
@@ -324,10 +326,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return
<tt>true</tt> if successful, or <tt>false</tt>
if
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return
{@code true} if successful, or {@code false}
if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
...
...
@@ -363,10 +365,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available.
*
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return the head of this deque, or
<tt>null</tt>
if the specified
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return the head of this deque, or
{@code null}
if the specified
* waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -379,10 +381,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available.
*
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return the tail of this deque, or
<tt>null</tt>
if the specified
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return the tail of this deque, or
{@code null}
if the specified
* waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -392,13 +394,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the first element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
(if such an element exists).
* Returns
<tt>true</tt>
if this deque contained the specified element
* More formally, removes the first element
{@code e}
such that
*
{@code o.equals(e)}
(if such an element exists).
* Returns
{@code true}
if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
* @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
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -410,13 +412,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Removes the last occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the last element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
(if such an element exists).
* Returns
<tt>true</tt>
if this deque contained the specified element
* More formally, removes the last element
{@code e}
such that
*
{@code o.equals(e)}
(if such an element exists).
* Returns
{@code true}
if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
* @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
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -431,8 +433,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* 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
* immediately without violating capacity restrictions, returning
*
<tt>true</tt>
upon success and throwing an
*
<tt>IllegalStateException</tt>
if no space is currently available.
*
{@code true}
upon success and throwing an
*
{@code IllegalStateException}
if no space is currently available.
* When using a capacity-restricted deque, it is generally preferable to
* use {@link #offer(Object) offer}.
*
...
...
@@ -452,7 +454,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* 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
* 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
* generally preferable to the {@link #add} method, which can fail to
* insert an element only by throwing an exception.
...
...
@@ -494,8 +496,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* {@link #offerLast(Object,long,TimeUnit) offerLast}.
*
* @param e the element to add
* @return
<tt>true</tt>
if the element was added to this deque, else
*
<tt>false</tt>
* @return
{@code true}
if the element was added to this deque, else
*
{@code false}
* @throws InterruptedException {@inheritDoc}
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this deque
...
...
@@ -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
* (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()}.
*
* @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
();
...
...
@@ -550,7 +552,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* <p>This method is equivalent to
* {@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
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -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
* 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}.
*
* @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
();
/**
* Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the first element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
(if such an element exists).
* Returns
<tt>true</tt>
if this deque contained the specified element
* More formally, removes the first element
{@code e}
such that
*
{@code o.equals(e)}
(if such an element exists).
* Returns
{@code true}
if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
* <p>This method is equivalent to
* {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
*
* @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
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -603,12 +605,12 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
boolean
remove
(
Object
o
);
/**
* Returns
<tt>true</tt>
if this deque contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this deque contains
* at least one element
<tt>e</tt> such that <tt>o.equals(e)</tt>
.
* Returns
{@code true}
if this deque contains the specified element.
* More formally, returns
{@code true}
if and only if this deque contains
* at least one element
{@code e} such that {@code o.equals(e)}
.
*
* @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
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -635,9 +637,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
// *** Stack methods ***
/**
* 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
* violate capacity restrictions.
* Pushes an element onto the stack represented by this deque (in other
* words, at the head of this deque) if it is possible to do so
* 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}.
*
...
...
src/share/classes/java/util/concurrent/BlockingQueue.java
浏览文件 @
fc9949fb
...
...
@@ -44,17 +44,18 @@ import java.util.Queue;
* element, and wait for space to become available in the queue when
* 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
* satisfied at some point in the future:
* 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,
* and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table:
*
* <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of BlockingQueue methods</caption>
* <tr>
* <td></td>
* <td ALIGN=CENTER><em>Throws exception</em></td>
...
...
@@ -85,37 +86,37 @@ import java.util.Queue;
* </tr>
* </table>
*
* <p>A
<tt>BlockingQueue</tt> does not accept <tt>null</tt>
elements.
* Implementations throw
<tt>NullPointerException</tt>
on attempts
* to
<tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>
. A
*
<tt>null</tt>
is used as a sentinel value to indicate failure of
*
<tt>poll</tt>
operations.
* <p>A
{@code BlockingQueue} does not accept {@code null}
elements.
* Implementations throw
{@code NullPointerException}
on attempts
* to
{@code add}, {@code put} or {@code offer} a {@code null}
. A
*
{@code null}
is used as a sentinel value to indicate failure of
*
{@code poll}
operations.
*
* <p>A
<tt>BlockingQueue</tt>
may be capacity bounded. At any given
* time it may have a
<tt>remainingCapacity</tt>
beyond which no
* additional elements can be
<tt>put</tt>
without blocking.
* A
<tt>BlockingQueue</tt>
without any intrinsic capacity constraints always
* reports a remaining capacity of
<tt>Integer.MAX_VALUE</tt>
.
* <p>A
{@code BlockingQueue}
may be capacity bounded. At any given
* time it may have a
{@code remainingCapacity}
beyond which no
* additional elements can be
{@code put}
without blocking.
* A
{@code BlockingQueue}
without any intrinsic capacity constraints always
* 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
* the {@link java.util.Collection} interface. So, for example, it is
* 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
* 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
* locks or other forms of concurrency control. However, the
* <em>bulk</em> Collection operations
<tt>addAll</tt>
,
*
<tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt>
are
* <em>bulk</em> Collection operations
{@code addAll}
,
*
{@code containsAll}, {@code retainAll} and {@code removeAll}
are
* <em>not</em> necessarily performed atomically unless specified
* otherwise in an implementation. So it is possible, for example, for
*
<tt>addAll(c)</tt>
to fail (throwing an exception) after adding
* only some of the elements in
<tt>c</tt>
.
*
{@code addAll(c)}
to fail (throwing an exception) after adding
* 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 "close" or "shutdown" operation to
* indicate that no more items will be added. The needs and usage of
* such features tend to be implementation-dependent. For example, a
...
...
@@ -125,7 +126,7 @@ import java.util.Queue;
*
* <p>
* 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.
* <pre> {@code
* class Producer implements Runnable {
...
...
@@ -181,13 +182,13 @@ public interface BlockingQueue<E> extends Queue<E> {
/**
* Inserts the specified element into this queue if it is possible to do
* so immediately without violating capacity restrictions, returning
*
<tt>true</tt>
upon success and throwing an
*
<tt>IllegalStateException</tt>
if no space is currently available.
*
{@code true}
upon success and throwing an
*
{@code IllegalStateException}
if no space is currently available.
* When using a capacity-restricted queue, it is generally preferable to
* use {@link #offer(Object) offer}.
*
* @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
* time due to capacity restrictions
* @throws ClassCastException if the class of the specified element
...
...
@@ -201,14 +202,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/**
* Inserts the specified element into this queue if it is possible to do
* 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
* generally preferable to {@link #add}, which can fail to insert an
* element only by throwing an exception.
*
* @param e the element to add
* @return
<tt>true</tt>
if the element was added to this queue, else
*
<tt>false</tt>
* @return
{@code true}
if the element was added to this queue, else
*
{@code false}
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this queue
* @throws NullPointerException if the specified element is null
...
...
@@ -237,10 +238,10 @@ public interface BlockingQueue<E> extends Queue<E> {
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return
<tt>true</tt> if successful, or <tt>false</tt>
if
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return
{@code true} if successful, or {@code false}
if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
...
...
@@ -266,10 +267,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* specified wait time if necessary for an element to become available.
*
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return the head of this queue, or
<tt>null</tt>
if the
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return the head of this queue, or
{@code null}
if the
* specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -279,11 +280,11 @@ public interface BlockingQueue<E> extends Queue<E> {
/**
* Returns the number of additional elements that this queue can ideally
* (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.
*
* <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
* insert or remove an element.
*
...
...
@@ -293,14 +294,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/**
* Removes a single instance of the specified element from this queue,
* if it is present. More formally, removes an element
<tt>e</tt>
such
* that
<tt>o.equals(e)</tt>
, if this queue contains one or more such
* if it is present. More formally, removes an element
{@code e}
such
* that
{@code o.equals(e)}
, if this queue contains one or more such
* 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).
*
* @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
* is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -310,12 +311,12 @@ public interface BlockingQueue<E> extends Queue<E> {
boolean
remove
(
Object
o
);
/**
* Returns
<tt>true</tt>
if this queue contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this queue contains
* at least one element
<tt>e</tt> such that <tt>o.equals(e)</tt>
.
* Returns
{@code true}
if this queue contains the specified element.
* More formally, returns
{@code true}
if and only if this queue contains
* at least one element
{@code e} such that {@code o.equals(e)}
.
*
* @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
* is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -329,10 +330,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* to the given collection. This operation may be more
* efficient than repeatedly polling this queue. A failure
* 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
* 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
* modified while the operation is in progress.
*
...
...
@@ -353,10 +354,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* Removes at most the given number of available elements from
* this queue and adds them to the given collection. A failure
* 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
* 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
* modified while the operation is in progress.
*
...
...
src/share/classes/java/util/concurrent/BrokenBarrierException.java
浏览文件 @
fc9949fb
...
...
@@ -49,13 +49,13 @@ public class BrokenBarrierException extends Exception {
private
static
final
long
serialVersionUID
=
7117394618823254244L
;
/**
* Constructs a
<tt>BrokenBarrierException</tt>
with no specified detail
* Constructs a
{@code BrokenBarrierException}
with no specified detail
* message.
*/
public
BrokenBarrierException
()
{}
/**
* Constructs a
<tt>BrokenBarrierException</tt>
with the specified
* Constructs a
{@code BrokenBarrierException}
with the specified
* detail message.
*
* @param message the detail message
...
...
src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
浏览文件 @
fc9949fb
...
...
@@ -42,6 +42,9 @@ import java.util.Deque;
import
java.util.Iterator
;
import
java.util.NoSuchElementException
;
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.
...
...
@@ -816,7 +819,7 @@ public class ConcurrentLinkedDeque<E>
* Creates an array list and fills it with elements of this list.
* Used by toArray.
*
* @return the array
L
ist
* @return the array
l
ist
*/
private
ArrayList
<
E
>
toArrayList
()
{
ArrayList
<
E
>
list
=
new
ArrayList
<
E
>();
...
...
@@ -1024,11 +1027,27 @@ public class ConcurrentLinkedDeque<E>
}
public
E
poll
()
{
return
pollFirst
();
}
public
E
remove
()
{
return
removeFirst
();
}
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
();
}
/**
* @throws NullPointerException {@inheritDoc}
*/
public
void
push
(
E
e
)
{
addFirst
(
e
);
}
public
E
pop
()
{
return
removeFirst
();
}
/**
* Removes the first element {@code e} such that
...
...
@@ -1385,6 +1404,99 @@ public class ConcurrentLinkedDeque<E>
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).
*
...
...
src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
浏览文件 @
fc9949fb
...
...
@@ -41,6 +41,9 @@ import java.util.Collection;
import
java.util.Iterator
;
import
java.util.NoSuchElementException
;
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.
...
...
@@ -56,7 +59,7 @@ import java.util.Queue;
* Like most other concurrent collection implementations, this class
* does not permit the use of {@code null} elements.
*
* <p>This implementation employs an efficient
"wait-free"
* <p>This implementation employs an efficient
<em>non-blocking</em>
* algorithm based on one described in <a
* href="http://www.cs.rochester.edu/u/michael/PODC96.html"> Simple,
* Fast, and Practical Non-Blocking and Blocking Concurrent Queue
...
...
@@ -295,7 +298,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
}
/**
* Tr
y
to CAS head to p. If successful, repoint old head to itself
* Tr
ies
to CAS head to p. If successful, repoint old head to itself
* as sentinel for succ(), below.
*/
final
void
updateHead
(
Node
<
E
>
h
,
Node
<
E
>
p
)
{
...
...
@@ -792,6 +795,96 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
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.
*
...
...
src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
浏览文件 @
fc9949fb
...
...
@@ -34,7 +34,17 @@
*/
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
...
...
@@ -44,33 +54,33 @@ import java.util.*;
* on which constructor is used.
*
* <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 safely execute concurrently by multiple threads.
* Iterators are <i>weakly consistent</i>, returning elements
* reflecting the state of the set at some point at or since the
* creation of the iterator. They do <em>not</em> throw {@link
*
ConcurrentModificationException}, and may proceed concurrently with
*
other operations. Ascending ordered views and their iterators are
* faster than descending ones.
*
java.util.ConcurrentModificationException}, and may proceed
*
concurrently with other operations. Ascending ordered views and
*
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
* asynchronous nature of these sets, determining the current number
* of elements requires a traversal of the elements, and so may report
* inaccurate results if this collection is modified during traversal.
* Additionally, the bulk operations
<tt>addAll</tt>
,
*
<tt>removeAll</tt>, <tt>retainAll</tt>, <tt>containsAll</tt>
,
*
<tt>equals</tt>, and <tt>toArray</tt>
are <em>not</em> guaranteed
* Additionally, the bulk operations
{@code addAll}
,
*
{@code removeAll}, {@code retainAll}, {@code containsAll}
,
*
{@code equals}, and {@code toArray}
are <em>not</em> guaranteed
* 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.
*
* <p>This class and its iterators implement all of the
* <em>optional</em> methods of the {@link Set} and {@link Iterator}
* interfaces. Like most other concurrent collection implementations,
* this class does not permit the use of
<tt>null</tt>
elements,
* because
<tt>null</tt>
arguments and return values cannot be reliably
* this class does not permit the use of
{@code null}
elements,
* because
{@code null}
arguments and return values cannot be reliably
* distinguished from the absence of elements.
*
* <p>This class is a member of the
...
...
@@ -90,7 +100,7 @@ public class ConcurrentSkipListSet<E>
/**
* The underlying map. Uses Boolean.TRUE as value for each
* 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
;
...
...
@@ -107,7 +117,7 @@ public class ConcurrentSkipListSet<E>
* the specified comparator.
*
* @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.
*/
public
ConcurrentSkipListSet
(
Comparator
<?
super
E
>
comparator
)
{
...
...
@@ -120,7 +130,7 @@ public class ConcurrentSkipListSet<E>
* {@linkplain Comparable natural ordering}.
*
* @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
* @throws NullPointerException if the specified collection or any
* of its elements are null
...
...
@@ -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.)
*
* @return a shallow copy of this set
...
...
@@ -172,8 +182,8 @@ public class ConcurrentSkipListSet<E>
/**
* Returns the number of elements in this set. If this set
* contains more than
<tt>Integer.MAX_VALUE</tt>
elements, it
* returns
<tt>Integer.MAX_VALUE</tt>
.
* contains more than
{@code Integer.MAX_VALUE}
elements, it
* returns
{@code Integer.MAX_VALUE}
.
*
* <p>Beware that, unlike in most collections, this method is
* <em>NOT</em> a constant-time operation. Because of the
...
...
@@ -191,20 +201,20 @@ public class ConcurrentSkipListSet<E>
}
/**
* Returns
<tt>true</tt>
if this set contains no elements.
* @return
<tt>true</tt>
if this set contains no elements
* Returns
{@code true}
if this set contains no elements.
* @return
{@code true}
if this set contains no elements
*/
public
boolean
isEmpty
()
{
return
m
.
isEmpty
();
}
/**
* Returns
<tt>true</tt>
if this set contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this set
* contains an element
<tt>e</tt> such that <tt>o.equals(e)</tt>
.
* Returns
{@code true}
if this set contains the specified element.
* More formally, returns
{@code true}
if and only if this set
* contains an element
{@code e} such that {@code o.equals(e)}
.
*
* @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
* compared with the elements currently in this set
* @throws NullPointerException if the specified element is null
...
...
@@ -215,15 +225,15 @@ public class ConcurrentSkipListSet<E>
/**
* 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
* the set contains no element
<tt>e2</tt> such that <tt>e.equals(e2)</tt>
.
* More formally, adds the specified element
{@code e}
to this set if
* 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
* unchanged and returns
<tt>false</tt>
.
* unchanged and returns
{@code false}
.
*
* @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
* @throws ClassCastException if
<tt>e</tt>
cannot be compared
* @throws ClassCastException if
{@code e}
cannot be compared
* with the elements currently in this set
* @throws NullPointerException if the specified element is null
*/
...
...
@@ -233,15 +243,15 @@ public class ConcurrentSkipListSet<E>
/**
* Removes the specified element from this set if it is present.
* More formally, removes an element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
, if this set contains such an element.
* Returns
<tt>true</tt>
if this set contained the element (or
* More formally, removes an element
{@code e}
such that
*
{@code o.equals(e)}
, if this set contains such an element.
* Returns
{@code true}
if this set contained the element (or
* equivalently, if this set changed as a result of the call).
* (This set will not contain the element once the call returns.)
*
* @param o object to be removed from this set, if present
* @return
<tt>true</tt>
if this set contained the specified element
* @throws ClassCastException if
<tt>o</tt>
cannot be compared
* @return
{@code true}
if this set contained the specified element
* @throws ClassCastException if
{@code o}
cannot be compared
* with the elements currently in this set
* @throws NullPointerException if the specified element is null
*/
...
...
@@ -279,7 +289,7 @@ public class ConcurrentSkipListSet<E>
/**
* 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
* contained in this set (or equivalently, every member of this set is
* contained in the specified set). This definition ensures that the
...
...
@@ -287,7 +297,7 @@ public class ConcurrentSkipListSet<E>
* set interface.
*
* @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
)
{
// Override AbstractSet version to avoid calling size()
...
...
@@ -312,7 +322,7 @@ public class ConcurrentSkipListSet<E>
* value is the <i>asymmetric set difference</i> of the two sets.
*
* @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
* set are incompatible with the specified collection
* @throws NullPointerException if the specified collection or any
...
...
@@ -380,14 +390,14 @@ public class ConcurrentSkipListSet<E>
}
/**
* @throws NoSuchElementException {@inheritDoc}
* @throws
java.util.
NoSuchElementException {@inheritDoc}
*/
public
E
first
()
{
return
m
.
firstKey
();
}
/**
* @throws NoSuchElementException {@inheritDoc}
* @throws
java.util.
NoSuchElementException {@inheritDoc}
*/
public
E
last
()
{
return
m
.
lastKey
();
...
...
@@ -460,7 +470,7 @@ public class ConcurrentSkipListSet<E>
* reflected in the descending set, and vice-versa.
*
* <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
* view of {@code s} essentially equivalent to {@code s}.
*
...
...
@@ -470,6 +480,14 @@ public class ConcurrentSkipListSet<E>
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
private
void
setMap
(
ConcurrentNavigableMap
<
E
,
Object
>
map
)
{
UNSAFE
.
putObjectVolatile
(
this
,
mapOffset
,
map
);
...
...
src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
浏览文件 @
fc9949fb
...
...
@@ -34,7 +34,14 @@
*/
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}
...
...
@@ -45,17 +52,17 @@ import java.util.*;
* vastly outnumber mutative operations, and you need
* to prevent interference among threads during traversal.
* <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
* 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
* interference from other threads. Iterators rely on
* unchanging snapshots of the array at the time the iterators were
* constructed.
* </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
* perform some action upon state updates.
*
...
...
@@ -73,7 +80,7 @@ import java.util.*;
* public void update() {
* changeState();
* for (Handler handler : handlers)
*
handler.handle();
* handler.handle();
* }
* }}</pre>
*
...
...
@@ -107,8 +114,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* @throws NullPointerException if the specified collection is null
*/
public
CopyOnWriteArraySet
(
Collection
<?
extends
E
>
c
)
{
al
=
new
CopyOnWriteArrayList
<
E
>();
al
.
addAllAbsent
(
c
);
if
(
c
.
getClass
()
==
CopyOnWriteArraySet
.
class
)
{
@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>
}
/**
* 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
()
{
return
al
.
isEmpty
();
}
/**
* Returns
<tt>true</tt>
if this set contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this set
* contains an element
<tt>e</tt>
such that
* Returns
{@code true}
if this set contains the specified element.
* More formally, returns
{@code true}
if and only if this set
* contains an element
{@code e}
such that
* <tt>(o==null ? e==null : o.equals(e))</tt>.
*
* @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
)
{
return
al
.
contains
(
o
);
...
...
@@ -172,7 +186,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <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
* 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
* any null elements.)
*
...
...
@@ -185,14 +199,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* precise control over the runtime type of the output array, and may,
* 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
* array of
<tt>String</tt>
:
* array of
{@code String}
:
*
* <pre> {@code String[] y = x.toArray(new String[0]);}</pre>
*
* Note that
<tt>toArray(new Object[0])</tt>
is identical in function to
*
<tt>toArray()</tt>
.
* Note that
{@code toArray(new Object[0])}
is identical in function to
*
{@code toArray()}
.
*
* @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
...
...
@@ -217,15 +231,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/**
* 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 ? e==null : 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
* changed as a result of the call). (This set will not contain the
* element once the call returns.)
*
* @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
)
{
return
al
.
remove
(
o
);
...
...
@@ -233,14 +247,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/**
* 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
* the set contains no element
<tt>e2</tt>
such that
* More formally, adds the specified element
{@code e}
to this set if
* the set contains no element
{@code e2}
such that
* <tt>(e==null ? e2==null : e.equals(e2))</tt>.
* 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
* @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
*/
public
boolean
add
(
E
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
* 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
* @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
* @throws NullPointerException if the specified collection is null
* @see #contains(Object)
...
...
@@ -265,13 +279,13 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/**
* 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
* 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
* this operation is undefined if the specified collection is modified
* while the operation is in progress.
*
* @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
* @see #add(Object)
*/
...
...
@@ -286,7 +300,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <i>asymmetric set difference</i> of the two sets.
*
* @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
* is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the
...
...
@@ -307,7 +321,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* two sets.
*
* @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
* is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the
...
...
@@ -326,7 +340,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>The returned iterator provides a snapshot of the state of the set
* when the iterator was constructed. No synchronization is needed while
* 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
*/
...
...
@@ -338,7 +352,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* Compares the specified object with this set for equality.
* 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
* returned by an {@linkplain
Lis
t#iterator() iterator} over the
* returned by an {@linkplain
Se
t#iterator() iterator} over the
* specified set are the same as the elements returned by an
* iterator over this set. More formally, the two iterators are
* considered to return the same elements if they return the same
...
...
@@ -382,6 +396,19 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
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.
*/
...
...
src/share/classes/java/util/concurrent/CountDownLatch.java
浏览文件 @
fc9949fb
...
...
@@ -92,15 +92,15 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer;
* private final CountDownLatch startSignal;
* private final CountDownLatch doneSignal;
* Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
*
this.startSignal = startSignal;
*
this.doneSignal = doneSignal;
* this.startSignal = startSignal;
* this.doneSignal = doneSignal;
* }
* public void run() {
*
try {
*
startSignal.await();
*
doWork();
*
doneSignal.countDown();
*
} catch (InterruptedException ex) {} // return;
* try {
* startSignal.await();
* doWork();
* doneSignal.countDown();
* } catch (InterruptedException ex) {} // return;
* }
*
* void doWork() { ... }
...
...
@@ -130,14 +130,14 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer;
* private final CountDownLatch doneSignal;
* private final int i;
* WorkerRunnable(CountDownLatch doneSignal, int i) {
*
this.doneSignal = doneSignal;
*
this.i = i;
* this.doneSignal = doneSignal;
* this.i = i;
* }
* public void run() {
*
try {
*
doWork(i);
*
doneSignal.countDown();
*
} catch (InterruptedException ex) {} // return;
* try {
* doWork(i);
* doneSignal.countDown();
* } catch (InterruptedException ex) {} // return;
* }
*
* void doWork() { ... }
...
...
src/share/classes/java/util/concurrent/CyclicBarrier.java
浏览文件 @
fc9949fb
...
...
@@ -45,14 +45,14 @@ import java.util.concurrent.locks.ReentrantLock;
* <em>cyclic</em> because it can be re-used after the waiting threads
* 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
* arrives, but before any threads are released.
* This <em>barrier action</em> is useful
* for updating shared-state before any of the parties continue.
*
* <p><b>Sample usage:</b> Here is an example of
*
using a barrier in a
parallel decomposition design:
* <p><b>Sample usage:</b> Here is an example of
using a barrier in a
* parallel decomposition design:
*
* <pre> {@code
* class Solver {
...
...
@@ -81,16 +81,20 @@ import java.util.concurrent.locks.ReentrantLock;
* public Solver(float[][] matrix) {
* data = matrix;
* N = matrix.length;
* barrier = new CyclicBarrier(N,
* new Runnable() {
* public void run() {
* mergeRows(...);
* }
* });
* for (int i = 0; i < N; ++i)
* new Thread(new Worker(i)).start();
* Runnable barrierAction =
* new Runnable() { public void run() { mergeRows(...); }};
* barrier = new CyclicBarrier(N, barrierAction);
*
* 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>
*
...
...
@@ -98,8 +102,8 @@ import java.util.concurrent.locks.ReentrantLock;
* barrier until all rows have been processed. When all rows are processed
* the supplied {@link Runnable} barrier action is executed and merges the
* rows. If the merger
* determines that a solution has been found then
<tt>done()</tt>
will return
*
<tt>true</tt>
and each worker will terminate.
* determines that a solution has been found then
{@code done()}
will return
*
{@code true}
and each worker will terminate.
*
* <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
...
...
@@ -112,7 +116,7 @@ import java.util.concurrent.locks.ReentrantLock;
* // log the completion of this iteration
* }}</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
* point prematurely because of interruption, failure, or timeout, all
* other threads waiting at that barrier point will also leave
...
...
@@ -139,7 +143,7 @@ public class CyclicBarrier {
* is reset. There can be many generations associated with threads
* using the barrier - due to the non-deterministic way the lock
* 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.
* There need not be an active generation if there has been a break
* but no subsequent reset.
...
...
@@ -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
* will execute the given barrier action when the barrier is tripped,
* performed by the last thread entering the barrier.
...
...
@@ -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
* does not perform a predefined action when the barrier is tripped.
*
...
...
@@ -301,7 +305,7 @@ public class CyclicBarrier {
/**
* 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
* disabled for thread scheduling purposes and lies dormant until
...
...
@@ -326,7 +330,7 @@ public class CyclicBarrier {
*
* <p>If the barrier is {@link #reset} while any thread is waiting,
* 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.
*
* <p>If any thread is {@linkplain Thread#interrupt interrupted} while waiting,
...
...
@@ -343,7 +347,7 @@ public class CyclicBarrier {
* the broken state.
*
* @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
* @throws InterruptedException if the current thread was interrupted
* while waiting
...
...
@@ -351,7 +355,7 @@ public class CyclicBarrier {
* interrupted or timed out while the current thread was
* waiting, or the barrier was reset, or the barrier was
* 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
{
try
{
...
...
@@ -363,7 +367,7 @@ public class CyclicBarrier {
/**
* 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
* disabled for thread scheduling purposes and lies dormant until
...
...
@@ -393,7 +397,7 @@ public class CyclicBarrier {
*
* <p>If the barrier is {@link #reset} while any thread is waiting,
* 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.
*
* <p>If any thread is {@linkplain Thread#interrupt interrupted} while
...
...
@@ -412,16 +416,17 @@ public class CyclicBarrier {
* @param timeout the time to wait for the barrier
* @param unit the time unit of the timeout parameter
* @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
* @throws InterruptedException if the current thread was interrupted
* 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
* interrupted or timed out while the current thread was
* waiting, or the barrier was reset, or the barrier was broken
* 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
)
throws
InterruptedException
,
...
...
src/share/classes/java/util/concurrent/DelayQueue.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/Delayed.java
浏览文件 @
fc9949fb
...
...
@@ -40,8 +40,8 @@ package java.util.concurrent;
* acted upon after a given delay.
*
* <p>An implementation of this interface must define a
*
<tt>compareTo</tt>
method that provides an ordering consistent with
* its
<tt>getDelay</tt>
method.
*
{@code compareTo}
method that provides an ordering consistent with
* its
{@code getDelay}
method.
*
* @since 1.5
* @author Doug Lea
...
...
src/share/classes/java/util/concurrent/Exchanger.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/LinkedBlockingDeque.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/LinkedBlockingQueue.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/LinkedTransferQueue.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/Phaser.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/PriorityBlockingQueue.java
浏览文件 @
fc9949fb
...
...
@@ -37,7 +37,17 @@ package java.util.concurrent;
import
java.util.concurrent.locks.Condition
;
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
...
...
@@ -342,7 +352,6 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* @param k the position to fill
* @param x the item to insert
* @param array the heap array
* @param n heap size
*/
private
static
<
T
>
void
siftUpComparable
(
int
k
,
T
x
,
Object
[]
array
)
{
Comparable
<?
super
T
>
key
=
(
Comparable
<?
super
T
>)
x
;
...
...
@@ -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
private
static
final
sun
.
misc
.
Unsafe
UNSAFE
;
private
static
final
long
allocationSpinLockOffset
;
...
...
src/share/classes/java/util/concurrent/SynchronousQueue.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/TimeUnit.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/TimeoutException.java
浏览文件 @
fc9949fb
...
...
@@ -40,7 +40,7 @@ package java.util.concurrent;
* operations for which a timeout is specified need a means to
* indicate that the timeout has occurred. For many such operations it
* 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.
*
* @since 1.5
...
...
@@ -50,13 +50,13 @@ public class TimeoutException extends Exception {
private
static
final
long
serialVersionUID
=
1900926677490660714L
;
/**
* Constructs a
<tt>TimeoutException</tt>
with no specified detail
* Constructs a
{@code TimeoutException}
with no specified detail
* message.
*/
public
TimeoutException
()
{}
/**
* Constructs a
<tt>TimeoutException</tt>
with the specified detail
* Constructs a
{@code TimeoutException}
with the specified detail
* message.
*
* @param message the detail message
...
...
src/share/classes/java/util/concurrent/package-info.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/logging/LogManager.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/logging/Logger.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/spi/LocaleServiceProvider.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/java/util/stream/SliceOps.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/crypto/Cipher.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/crypto/CipherInputStream.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/crypto/ExemptionMechanism.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/crypto/KeyAgreement.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/crypto/KeyGenerator.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/crypto/NullCipher.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/security/auth/Subject.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/javax/security/cert/X509Certificate.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
src/share/classes/sun/security/provider/certpath/RevocationChecker.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/lang/invoke/InvokeDynamicPrintArgs.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/lang/invoke/TestCatchExceptionWithVarargs.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/lang/invoke/TestPrivateMember.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/LogManagerInstanceTest.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/TestGetGlobal.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/TestGetGlobalByName.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/logging.properties
0 → 100644
浏览文件 @
fc9949fb
.level
=
INFO
handlers
=
testgetglobal.HandlerImpl
test/java/util/logging/Logger/getGlobal/policy
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/testgetglobal/BadLogManagerImpl.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/testgetglobal/DummyLogManagerImpl.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/testgetglobal/HandlerImpl.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/testgetglobal/LogManagerImpl1.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/testgetglobal/LogManagerImpl2.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/Logger/getGlobal/testgetglobal/LogManagerImpl3.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/logging/TestAppletLoggerContext.java
0 → 100644
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/java/util/stream/test/org/openjdk/tests/java/util/stream/SliceOpTest.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/AttributeTests.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/BandIntegrity.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/CommandLineTests.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/InstructionTests.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/Pack200Props.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/Pack200Test.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/PackageVersionTest.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/RepackTest.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/T7007157.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/TestExceptions.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/TimeStamp.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/UnpackerMemoryTest.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/Utils.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
test/tools/pack200/typeannos/TestTypeAnnotations.java
浏览文件 @
fc9949fb
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录