8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
Reviewed-by: martin, psandoz
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Mon Apr 10 13:46:19 2017 -0700
@@ -48,7 +48,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.NoSuchElementException;
import java.util.Set;
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java Mon Apr 10 13:46:19 2017 -0700
@@ -43,7 +43,6 @@
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;
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java Mon Apr 10 13:46:19 2017 -0700
@@ -2354,7 +2354,7 @@
checkPermission();
}
- private Object newInstanceFromSystemProperty(String property)
+ private static Object newInstanceFromSystemProperty(String property)
throws ReflectiveOperationException {
String className = System.getProperty(property);
return (className == null)
@@ -2524,15 +2524,13 @@
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
*/
+ @SuppressWarnings("unchecked")
public ForkJoinTask<?> submit(Runnable task) {
if (task == null)
throw new NullPointerException();
- ForkJoinTask<?> job;
- if (task instanceof ForkJoinTask<?>) // avoid re-wrap
- job = (ForkJoinTask<?>) task;
- else
- job = new ForkJoinTask.AdaptedRunnableAction(task);
- return externalSubmit(job);
+ return externalSubmit((task instanceof ForkJoinTask<?>)
+ ? (ForkJoinTask<Void>) task // avoid re-wrap
+ : new ForkJoinTask.AdaptedRunnableAction(task));
}
/**
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java Mon Apr 10 13:46:19 2017 -0700
@@ -203,21 +203,19 @@
static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
/** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
private static final ThreadGroup innocuousThreadGroup =
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction<>() {
- public ThreadGroup run() {
- ThreadGroup group = Thread.currentThread().getThreadGroup();
- for (ThreadGroup p; (p = group.getParent()) != null; )
- group = p;
- return new ThreadGroup(group, "InnocuousForkJoinWorkerThreadGroup");
- }});
+ AccessController.doPrivileged(new PrivilegedAction<>() {
+ public ThreadGroup run() {
+ ThreadGroup group = Thread.currentThread().getThreadGroup();
+ for (ThreadGroup p; (p = group.getParent()) != null; )
+ group = p;
+ return new ThreadGroup(
+ group, "InnocuousForkJoinWorkerThreadGroup");
+ }});
/** An AccessControlContext supporting no privileges */
private static final AccessControlContext INNOCUOUS_ACC =
new AccessControlContext(
- new ProtectionDomain[] {
- new ProtectionDomain(null, null)
- });
+ new ProtectionDomain[] { new ProtectionDomain(null, null) });
InnocuousForkJoinWorkerThread(ForkJoinPool pool) {
super(pool,
--- a/jdk/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java Mon Apr 10 13:46:19 2017 -0700
@@ -444,7 +444,7 @@
}
}
- private IllegalMonitorStateException unmatchedUnlockException() {
+ private static IllegalMonitorStateException unmatchedUnlockException() {
return new IllegalMonitorStateException(
"attempt to unlock read lock, not locked by current thread");
}
--- a/jdk/test/java/util/concurrent/tck/ArrayDeque8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ArrayDeque8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -37,7 +37,6 @@
import java.util.Spliterator;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ArrayDeque8Test extends JSR166TestCase {
public static void main(String[] args) {
--- a/jdk/test/java/util/concurrent/tck/ArrayDequeTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ArrayDequeTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -35,7 +35,6 @@
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -44,7 +43,6 @@
import java.util.concurrent.ThreadLocalRandom;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ArrayDequeTest extends JSR166TestCase {
public static void main(String[] args) {
--- a/jdk/test/java/util/concurrent/tck/ArrayListTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ArrayListTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -33,11 +33,9 @@
*/
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ArrayListTest extends JSR166TestCase {
public static void main(String[] args) {
--- a/jdk/test/java/util/concurrent/tck/AtomicReferenceFieldUpdaterTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/AtomicReferenceFieldUpdaterTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -75,7 +75,7 @@
assertTrue(a.compareAndSet(this, two, m4));
assertSame(m4, a.get(this));
assertFalse(a.compareAndSet(this, m5, seven));
- assertFalse(seven == a.get(this));
+ assertNotSame(seven, a.get(this));
assertTrue(a.compareAndSet(this, m4, seven));
assertSame(seven, a.get(this));
}
@@ -208,7 +208,7 @@
assertTrue(a.compareAndSet(this, two, m4));
assertSame(m4, a.get(this));
assertFalse(a.compareAndSet(this, m5, seven));
- assertFalse(seven == a.get(this));
+ assertNotSame(seven, a.get(this));
assertTrue(a.compareAndSet(this, m4, seven));
assertSame(seven, a.get(this));
}
--- a/jdk/test/java/util/concurrent/tck/AtomicReferenceTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/AtomicReferenceTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -153,7 +153,7 @@
AtomicReference z = serialClone(x);
assertNotSame(y, z);
assertEquals(one, x.get());
- assertEquals(null, y.get());
+ assertNull(y.get());
assertEquals(one, z.get());
}
--- a/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -2589,28 +2589,28 @@
// unspecified behavior - both source completions available
try {
- assertEquals(null, h0.join());
+ assertNull(h0.join());
rs[0].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h0, ex);
rs[0].assertNotInvoked();
}
try {
- assertEquals(null, h1.join());
+ assertNull(h1.join());
rs[1].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h1, ex);
rs[1].assertNotInvoked();
}
try {
- assertEquals(null, h2.join());
+ assertNull(h2.join());
rs[2].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h2, ex);
rs[2].assertNotInvoked();
}
try {
- assertEquals(null, h3.join());
+ assertNull(h3.join());
rs[3].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h3, ex);
@@ -2849,28 +2849,28 @@
// unspecified behavior - both source completions available
try {
- assertEquals(null, h0.join());
+ assertNull(h0.join());
rs[0].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h0, ex);
rs[0].assertNotInvoked();
}
try {
- assertEquals(null, h1.join());
+ assertNull(h1.join());
rs[1].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h1, ex);
rs[1].assertNotInvoked();
}
try {
- assertEquals(null, h2.join());
+ assertNull(h2.join());
rs[2].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h2, ex);
rs[2].assertNotInvoked();
}
try {
- assertEquals(null, h3.join());
+ assertNull(h3.join());
rs[3].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h3, ex);
--- a/jdk/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -237,8 +237,8 @@
Set set1 = map.keySet();
Set set2 = map.keySet(true);
set2.add(six);
- assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map);
- assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map);
+ assertSame(map, ((ConcurrentHashMap.KeySetView)set2).getMap());
+ assertSame(map, ((ConcurrentHashMap.KeySetView)set1).getMap());
assertEquals(set2.size(), map.size());
assertEquals(set1.size(), map.size());
assertTrue((Boolean)map.get(six));
@@ -332,10 +332,10 @@
assertFalse(set.add(one));
assertTrue(set.add(six));
assertTrue(set.add(seven));
- assertTrue(set.getMappedValue() == one);
- assertTrue(map.get(one) != one);
- assertTrue(map.get(six) == one);
- assertTrue(map.get(seven) == one);
+ assertSame(one, set.getMappedValue());
+ assertNotSame(one, map.get(one));
+ assertSame(one, map.get(six));
+ assertSame(one, map.get(seven));
}
void checkSpliteratorCharacteristics(Spliterator<?> sp,
--- a/jdk/test/java/util/concurrent/tck/ConcurrentHashMapTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentHashMapTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -43,8 +43,6 @@
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -148,7 +146,7 @@
ConcurrentHashMap<BI, Boolean> m =
new ConcurrentHashMap<BI, Boolean>();
for (int i = 0; i < size; i++) {
- assertTrue(m.put(new CI(i), true) == null);
+ assertNull(m.put(new CI(i), true));
}
for (int i = 0; i < size; i++) {
assertTrue(m.containsKey(new CI(i)));
@@ -169,7 +167,7 @@
BS bs = new BS(String.valueOf(i));
LexicographicList<BI> bis = new LexicographicList<BI>(bi);
LexicographicList<BS> bss = new LexicographicList<BS>(bs);
- assertTrue(m.putIfAbsent(bis, true) == null);
+ assertNull(m.putIfAbsent(bis, true));
assertTrue(m.containsKey(bis));
if (m.putIfAbsent(bss, true) == null)
assertTrue(m.containsKey(bss));
--- a/jdk/test/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -43,7 +43,6 @@
import java.util.concurrent.ConcurrentLinkedDeque;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ConcurrentLinkedDequeTest extends JSR166TestCase {
@@ -67,7 +66,7 @@
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private ConcurrentLinkedDeque<Integer> populatedDeque(int n) {
+ private static ConcurrentLinkedDeque<Integer> populatedDeque(int n) {
ConcurrentLinkedDeque<Integer> q = new ConcurrentLinkedDeque<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
--- a/jdk/test/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -41,7 +41,6 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ConcurrentLinkedQueueTest extends JSR166TestCase {
@@ -65,7 +64,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
+ private static ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
--- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -64,7 +64,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private ConcurrentSkipListSet<Integer> populatedSet(int n) {
+ private static ConcurrentSkipListSet<Integer> populatedSet(int n) {
ConcurrentSkipListSet<Integer> q =
new ConcurrentSkipListSet<Integer>();
assertTrue(q.isEmpty());
@@ -80,7 +80,7 @@
/**
* Returns a new set of first 5 ints.
*/
- private ConcurrentSkipListSet set5() {
+ private static ConcurrentSkipListSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
@@ -229,7 +229,7 @@
} catch (ClassCastException success) {
assertTrue(q.size() < 2);
for (int i = 0, size = q.size(); i < size; i++)
- assertTrue(q.pollFirst().getClass() == Object.class);
+ assertSame(Object.class, q.pollFirst().getClass());
assertNull(q.pollFirst());
assertTrue(q.isEmpty());
assertEquals(0, q.size());
--- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -59,7 +59,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private NavigableSet<Integer> populatedSet(int n) {
+ private static NavigableSet<Integer> populatedSet(int n) {
ConcurrentSkipListSet<Integer> q =
new ConcurrentSkipListSet<Integer>();
assertTrue(q.isEmpty());
@@ -79,7 +79,7 @@
/**
* Returns a new set of first 5 ints.
*/
- private NavigableSet set5() {
+ private static NavigableSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
@@ -97,7 +97,7 @@
/**
* Returns a new set of first 5 negative ints.
*/
- private NavigableSet dset5() {
+ private static NavigableSet dset5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(m1);
--- a/jdk/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -44,7 +44,6 @@
import java.util.concurrent.CopyOnWriteArrayList;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class CopyOnWriteArrayListTest extends JSR166TestCase {
--- a/jdk/test/java/util/concurrent/tck/CountedCompleter8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/CountedCompleter8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -32,9 +32,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
import java.util.concurrent.CountedCompleter;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
--- a/jdk/test/java/util/concurrent/tck/CountedCompleterTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/CountedCompleterTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -40,7 +40,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
-import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
--- a/jdk/test/java/util/concurrent/tck/ExchangerTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ExchangerTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -160,12 +160,12 @@
public void realRun() throws InterruptedException {
assertSame(one, e.exchange(two));
exchanged.countDown();
- interrupted.await();
+ await(interrupted);
assertSame(three, e.exchange(one));
}});
Thread t3 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
- interrupted.await();
+ await(interrupted);
assertSame(one, e.exchange(three));
}});
--- a/jdk/test/java/util/concurrent/tck/ExecutorCompletionService9Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ExecutorCompletionService9Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -37,7 +37,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
--- a/jdk/test/java/util/concurrent/tck/ExecutorCompletionServiceTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ExecutorCompletionServiceTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -172,7 +172,7 @@
CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
final CountDownLatch proceed = new CountDownLatch(1);
cs.submit(new Callable() { public String call() throws Exception {
- proceed.await();
+ await(proceed);
return TEST_STRING;
}});
assertNull(cs.poll());
--- a/jdk/test/java/util/concurrent/tck/ExecutorsTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ExecutorsTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -333,16 +333,12 @@
public void realRun() {
try {
Thread current = Thread.currentThread();
- assertTrue(!current.isDaemon());
+ assertFalse(current.isDaemon());
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
- ThreadGroup g = current.getThreadGroup();
SecurityManager s = System.getSecurityManager();
- if (s != null)
- assertTrue(g == s.getThreadGroup());
- else
- assertTrue(g == egroup);
- String name = current.getName();
- assertTrue(name.endsWith("thread-1"));
+ assertSame(current.getThreadGroup(),
+ (s == null) ? egroup : s.getThreadGroup());
+ assertTrue(current.getName().endsWith("thread-1"));
} catch (SecurityException ok) {
// Also pass if not allowed to change setting
}
@@ -370,16 +366,12 @@
Runnable r = new CheckedRunnable() {
public void realRun() {
Thread current = Thread.currentThread();
- assertTrue(!current.isDaemon());
+ assertFalse(current.isDaemon());
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
- ThreadGroup g = current.getThreadGroup();
SecurityManager s = System.getSecurityManager();
- if (s != null)
- assertTrue(g == s.getThreadGroup());
- else
- assertTrue(g == egroup);
- String name = current.getName();
- assertTrue(name.endsWith("thread-1"));
+ assertSame(current.getThreadGroup(),
+ (s == null) ? egroup : s.getThreadGroup());
+ assertTrue(current.getName().endsWith("thread-1"));
assertSame(thisccl, current.getContextClassLoader());
assertEquals(thisacc, AccessController.getContext());
done.countDown();
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPool8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPool8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -206,7 +206,7 @@
public FJException(Throwable cause) { super(cause); }
}
- // A simple recursive action for testing
+ /** A simple recursive action for testing. */
final class FibAction extends CheckedRecursiveAction {
final int number;
int result;
@@ -224,7 +224,7 @@
}
}
- // A recursive action failing in base case
+ /** A recursive action failing in base case. */
static final class FailingFibAction extends RecursiveAction {
final int number;
int result;
@@ -932,7 +932,7 @@
}
}
- // Version of CCF with forced failure in left completions
+ /** Version of CCF with forced failure in left completions. */
abstract static class FailingCCF extends CountedCompleter {
int number;
int rnumber;
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPool9Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPool9Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -32,8 +32,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.CountDownLatch;
@@ -93,7 +91,7 @@
Future<?> f = ForkJoinPool.commonPool().submit(runInCommonPool);
// Ensure runInCommonPool is truly running in the common pool,
// by giving this thread no opportunity to "help" on get().
- assertTrue(taskStarted.await(LONG_DELAY_MS, MILLISECONDS));
+ await(taskStarted);
assertNull(f.get());
}
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -244,7 +244,7 @@
taskStarted.countDown();
assertEquals(1, p.getPoolSize());
assertEquals(1, p.getActiveThreadCount());
- done.await();
+ await(done);
}};
Future<?> future = p.submit(task);
await(taskStarted);
--- a/jdk/test/java/util/concurrent/tck/ForkJoinTask8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinTask8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -127,7 +127,8 @@
assertNull(a.getException());
assertNull(a.getRawResult());
if (a instanceof BinaryAsyncAction)
- assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == INITIAL_STATE);
+ assertEquals(INITIAL_STATE,
+ ((BinaryAsyncAction)a).getForkJoinTaskTag());
try {
a.get(0L, SECONDS);
@@ -148,7 +149,8 @@
assertNull(a.getException());
assertSame(expected, a.getRawResult());
if (a instanceof BinaryAsyncAction)
- assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == COMPLETE_STATE);
+ assertEquals(COMPLETE_STATE,
+ ((BinaryAsyncAction)a).getForkJoinTaskTag());
{
Thread.currentThread().interrupt();
--- a/jdk/test/java/util/concurrent/tck/JSR166TestCase.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/JSR166TestCase.java Mon Apr 10 13:46:19 2017 -0700
@@ -26,8 +26,9 @@
* However, the following notice accompanied the original version of this
* file:
*
- * Written by Doug Lea with assistance from members of JCP JSR-166
- * Expert Group and released to the public domain, as explained at
+ * Written by Doug Lea and Martin Buchholz with assistance from
+ * members of JCP JSR-166 Expert Group and released to the public
+ * domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
* Other contributors include Andrew Wright, Jeffrey Hayes,
* Pat Fisher, Mike Judd.
@@ -35,32 +36,33 @@
/*
* @test
- * @summary JSR-166 tck tests (conformance testing mode)
+ * @summary JSR-166 tck tests, in a number of variations.
+ * The first is the conformance testing variant,
+ * while others also test implementation details.
* @build *
* @modules java.management
* @run junit/othervm/timeout=1000 JSR166TestCase
- */
-
-/*
- * @test
- * @summary JSR-166 tck tests (whitebox tests allowed)
- * @build *
- * @modules java.base/java.util.concurrent:open
- * java.base/java.lang:open
- * java.management
* @run junit/othervm/timeout=1000
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* JSR166TestCase
* @run junit/othervm/timeout=1000
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0
* JSR166TestCase
* @run junit/othervm/timeout=1000
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1
* -Djava.util.secureRandomSeed=true
* JSR166TestCase
* @run junit/othervm/timeout=1000/policy=tck.policy
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* JSR166TestCase
*/
@@ -79,8 +81,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
@@ -118,7 +118,6 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.AssertionFailedError;
@@ -328,9 +327,11 @@
// public static String cpuModel() {
// try {
-// Matcher matcher = Pattern.compile("model name\\s*: (.*)")
+// java.util.regex.Matcher matcher
+// = Pattern.compile("model name\\s*: (.*)")
// .matcher(new String(
-// Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
+// java.nio.file.Files.readAllBytes(
+// java.nio.file.Paths.get("/proc/cpuinfo")), "UTF-8"));
// matcher.find();
// return matcher.group(1);
// } catch (Exception ex) { return null; }
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingDeque8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingDeque8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -36,7 +36,6 @@
import java.util.Spliterator;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class LinkedBlockingDeque8Test extends JSR166TestCase {
public static void main(String[] args) {
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -85,7 +85,7 @@
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private LinkedBlockingDeque<Integer> populatedDeque(int n) {
+ private static LinkedBlockingDeque<Integer> populatedDeque(int n) {
LinkedBlockingDeque<Integer> q =
new LinkedBlockingDeque<Integer>(n);
assertTrue(q.isEmpty());
@@ -801,7 +801,7 @@
}
}});
- aboutToWait.await();
+ await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingQueue8Test.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingQueue8Test.java Mon Apr 10 13:46:19 2017 -0700
@@ -36,7 +36,6 @@
import java.util.Spliterator;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class LinkedBlockingQueue8Test extends JSR166TestCase {
public static void main(String[] args) {
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -85,7 +85,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private LinkedBlockingQueue<Integer> populatedQueue(int n) {
+ private static LinkedBlockingQueue<Integer> populatedQueue(int n) {
LinkedBlockingQueue<Integer> q =
new LinkedBlockingQueue<Integer>(n);
assertTrue(q.isEmpty());
--- a/jdk/test/java/util/concurrent/tck/LinkedListTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/LinkedListTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -40,7 +40,6 @@
import java.util.NoSuchElementException;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class LinkedListTest extends JSR166TestCase {
public static void main(String[] args) {
@@ -70,7 +69,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private LinkedList<Integer> populatedQueue(int n) {
+ private static LinkedList<Integer> populatedQueue(int n) {
LinkedList<Integer> q = new LinkedList<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
--- a/jdk/test/java/util/concurrent/tck/LinkedTransferQueueTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/LinkedTransferQueueTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -321,7 +321,7 @@
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}});
- aboutToWait.await();
+ await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
@@ -826,7 +826,7 @@
Thread first = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.transfer(four);
- assertTrue(!q.contains(four));
+ assertFalse(q.contains(four));
assertEquals(1, q.size());
}});
--- a/jdk/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -93,7 +93,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private PriorityBlockingQueue<Integer> populatedQueue(int n) {
+ private static PriorityBlockingQueue<Integer> populatedQueue(int n) {
PriorityBlockingQueue<Integer> q =
new PriorityBlockingQueue<Integer>(n);
assertTrue(q.isEmpty());
@@ -445,7 +445,7 @@
}
}});
- aboutToWait.await();
+ await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
--- a/jdk/test/java/util/concurrent/tck/PriorityQueueTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/PriorityQueueTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -42,7 +42,6 @@
import java.util.Queue;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class PriorityQueueTest extends JSR166TestCase {
public static void main(String[] args) {
@@ -70,7 +69,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private PriorityQueue<Integer> populatedQueue(int n) {
+ private static PriorityQueue<Integer> populatedQueue(int n) {
PriorityQueue<Integer> q = new PriorityQueue<>(n);
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
--- a/jdk/test/java/util/concurrent/tck/RecursiveActionTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/RecursiveActionTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -195,7 +195,7 @@
public FJException(Throwable cause) { super(cause); }
}
- // A simple recursive action for testing
+ /** A simple recursive action for testing. */
final class FibAction extends CheckedRecursiveAction {
final int number;
int result;
@@ -213,7 +213,7 @@
}
}
- // A recursive action failing in base case
+ /** A recursive action failing in base case. */
static final class FailingFibAction extends RecursiveAction {
final int number;
int result;
--- a/jdk/test/java/util/concurrent/tck/RecursiveTaskTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/RecursiveTaskTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -210,10 +210,10 @@
public FJException() { super(); }
}
- // An invalid return value for Fib
+ /** An invalid return value for Fib. */
static final Integer NoResult = Integer.valueOf(-17);
- // A simple recursive task for testing
+ /** A simple recursive task for testing. */
final class FibTask extends CheckedRecursiveTask<Integer> {
final int number;
FibTask(int n) { number = n; }
@@ -231,7 +231,7 @@
}
}
- // A recursive action failing in base case
+ /** A recursive action failing in base case. */
final class FailingFibTask extends RecursiveTask<Integer> {
final int number;
int result;
--- a/jdk/test/java/util/concurrent/tck/StampedLockTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/StampedLockTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -518,7 +518,7 @@
lock.unlockWrite(s);
}});
- aboutToLock.await();
+ await(aboutToLock);
waitForThreadToEnterWaitState(t);
assertFalse(lock.isWriteLocked());
assertTrue(lock.isReadLocked());
@@ -777,7 +777,7 @@
lock.writeLockInterruptibly();
}});
- locked.await();
+ await(locked);
assertFalse(lock.validate(p));
assertEquals(0L, lock.tryOptimisticRead());
waitForThreadToEnterWaitState(t);
--- a/jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -519,7 +519,7 @@
s1.request = false;
p.subscribe(s1);
s1.awaitSubscribe();
- assertTrue(p.estimateMinimumDemand() == 0);
+ assertEquals(0, p.estimateMinimumDemand());
TestSubscriber s2 = new TestSubscriber();
p.subscribe(s2);
p.submit(1);
--- a/jdk/test/java/util/concurrent/tck/SynchronousQueueTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/SynchronousQueueTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -596,7 +596,7 @@
fail("timed out");
Thread.yield();
}
- assertTrue(l.size() == 1);
+ assertEquals(1, l.size());
assertSame(one, l.get(0));
awaitTermination(t);
}
--- a/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -265,7 +265,7 @@
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
p.execute(task);
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
@@ -359,13 +359,13 @@
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(0, p.getCompletedTaskCount());
- threadProceed.await();
+ await(threadProceed);
threadDone.countDown();
}});
await(threadStarted);
assertEquals(0, p.getCompletedTaskCount());
threadProceed.countDown();
- threadDone.await();
+ await(threadDone);
long startTime = System.nanoTime();
while (p.getCompletedTaskCount() != 1) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
@@ -1953,7 +1953,7 @@
public void realRun() {
done.countDown();
}});
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
--- a/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -45,7 +45,6 @@
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
@@ -118,7 +117,7 @@
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
p.execute(task);
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
@@ -212,13 +211,13 @@
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(0, p.getCompletedTaskCount());
- threadProceed.await();
+ await(threadProceed);
threadDone.countDown();
}});
await(threadStarted);
assertEquals(0, p.getCompletedTaskCount());
threadProceed.countDown();
- threadDone.await();
+ await(threadDone);
long startTime = System.nanoTime();
while (p.getCompletedTaskCount() != 1) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
@@ -302,6 +301,20 @@
}
/**
+ * The default rejected execution handler is AbortPolicy.
+ */
+ public void testDefaultRejectedExecutionHandler() {
+ final ThreadPoolExecutor p =
+ new ThreadPoolExecutor(1, 2,
+ LONG_DELAY_MS, MILLISECONDS,
+ new ArrayBlockingQueue<Runnable>(10));
+ try (PoolCleaner cleaner = cleaner(p)) {
+ assertTrue(p.getRejectedExecutionHandler()
+ instanceof ThreadPoolExecutor.AbortPolicy);
+ }
+ }
+
+ /**
* getRejectedExecutionHandler returns handler in constructor if not set
*/
public void testGetRejectedExecutionHandler() {
@@ -1139,7 +1152,7 @@
await(done);
}};
for (int i = 0; i < 2; ++i)
- p.submit(Executors.callable(task));
+ p.execute(task);
for (int i = 0; i < 2; ++i) {
try {
p.execute(task);
@@ -1955,7 +1968,7 @@
public void realRun() {
done.countDown();
}});
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
@@ -2048,7 +2061,7 @@
}
}
// enough time to run all tasks
- assertTrue(done.await(nTasks * SHORT_DELAY_MS, MILLISECONDS));
+ await(done, nTasks * SHORT_DELAY_MS);
}
}
--- a/jdk/test/java/util/concurrent/tck/ThreadTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/ThreadTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -76,7 +76,7 @@
* setDefaultUncaughtExceptionHandler.
*/
public void testGetAndSetDefaultUncaughtExceptionHandler() {
- assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
+ assertNull(Thread.getDefaultUncaughtExceptionHandler());
// failure due to SecurityException is OK.
// Would be nice to explicitly test both ways, but cannot yet.
Thread.UncaughtExceptionHandler defaultHandler
--- a/jdk/test/java/util/concurrent/tck/TreeSetTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/TreeSetTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -69,7 +69,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private TreeSet<Integer> populatedSet(int n) {
+ private static TreeSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
@@ -84,7 +84,7 @@
/**
* Returns a new set of first 5 ints.
*/
- private TreeSet set5() {
+ private static TreeSet set5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(one);
--- a/jdk/test/java/util/concurrent/tck/TreeSubSetTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/TreeSubSetTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -60,7 +60,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private NavigableSet<Integer> populatedSet(int n) {
+ private static NavigableSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
@@ -79,7 +79,7 @@
/**
* Returns a new set of first 5 ints.
*/
- private NavigableSet set5() {
+ private static NavigableSet set5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(one);
@@ -94,7 +94,7 @@
return s;
}
- private NavigableSet dset5() {
+ private static NavigableSet dset5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(m1);
--- a/jdk/test/java/util/concurrent/tck/VectorTest.java Mon Apr 10 13:46:16 2017 -0700
+++ b/jdk/test/java/util/concurrent/tck/VectorTest.java Mon Apr 10 13:46:19 2017 -0700
@@ -33,11 +33,9 @@
*/
import java.util.Vector;
-import java.util.Collection;
import java.util.List;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class VectorTest extends JSR166TestCase {
public static void main(String[] args) {