-
Bug
-
Resolution: Fixed
-
P2
-
5.0
-
b30
-
x86
-
linux
Name: vsR10238 Date: 10/24/2003
Filed By : J2SE-SQA [###@###.###
JDK : JDK1.5.0
Testbase : Regression-test
Platform[s] : Suse Linux 8.2
Falling test[s]:
java/util/concurrent/FutureTask/CancelledFutureLoops.java
Regression test java/util/concurrent/FutureTask/CancelledFutureLoops.java fails with JDK1.5.0
(tested with b24, b25) with BrokenBarrierException. The test fails intermittently and I cannot reproduce
the failure on other platforms. The test cannot be run on JDK1.4.2 since it tests features new for Tiger.
I inserted some tracing into the the test and found that some threads in FutureLoops.call() are still in
barrier.await() even when futures[0].get() is called in the main thread.
The probable cause of the failure is that a thread waiting in ReentrantLockCondition.await can be interrupted
after LockSupport.park() and before the call to Thread.interrupted():
public final void await() throws InterruptedException {
Thread current = Thread.currentThread();
lock.checkOwner(current);
ConditionNode w = addConditionWaiter(current);
int recs = lock.unlockForWait();
for (;;) {
if (Thread.interrupted()) {
cancelAndRelock(current, w, recs);
throw new InterruptedException();
}
if (lock.isOnLockQueue(w)) {
lock.relockAfterWait(current, w, recs);
checkInterruptAfterRelock();
return;
}
LockSupport.park();
}
}
The following situation seems to be possible that may explain the failure:
1) The last thread in the pool calls CyclicBarrier.await and then calls trip.signalAll() in CyclicBarrier.nextGeneration()
2) The main thread is awakened and interrupts other threads
3) Only then some thread in the pool but the first one reaches "if (Thread.interrupted())" in ReentrantLockCondition.await
and InterruptedException is thrown which is a bit unexpected since users of CyclicBarrier expect that all threads exit
its await method simultaneously.
When I had modified CyclicBarrier to use Object's synchronization methods instead of Lock and Condition (by removing
all references to ReentrantLock and Condition and changing the calls to their methods to corresponding synchronization statements
and wait/notifyAll calls), the test began to pass even when I increased maxThreads to 200:
Threads: 2 0.838254s run time
Threads: 3 0.878974s run time
Threads: 5 0.825411s run time
Threads: 8 0.828341s run time
Threads: 12 0.869557s run time
Threads: 18 0.946561s run time
Threads: 27 1.241634s run time
Threads: 41 2.454431s run time
Threads: 62 3.197021s run time
Threads: 93(cancelled too late) 42.532174s run time
Threads: 140 7.035452s run time
Even when I removed Thread.sleep(TIMEOUT) after barrier.await() in FutureLoop.test():
final void test() throws Exception {
Future[] futures = new Future[nthreads];
for (int i = 0; i < nthreads; ++i)
futures[i] = Executors.execute(pool, this);
barrier.await();
// Thread.sleep(TIMEOUT);
the test passed with 200 threads using the modified CyclicBarrier.
Also, when I had increased sleeping time after barrier.await() in FutureLoop.test():
final void test() throws Exception {
Future[] futures = new Future[nthreads];
for (int i = 0; i < nthreads; ++i)
futures[i] = Executors.execute(pool, this);
barrier.await();
Thread.sleep(TIMEOUT*10);
the test passed using the original CyclicBarrier 10 times of 10 (with maxThreads=5).
Test source location:
=====================
/java/re/jdk/1.5.0/promoted/all/b24/ws/j2se/test/java/util/concurrent/FutureTask/CancelledFutureLoops.java
jtr file location:
==================
/net/jtgb4u4c.sfbay/export/sail15/results.2/tiger/b24/regtest/linux/suse8.2_gnome_linux-2/workDir/test/java/util/concurrent/FutureTask/CancelledFutureLoops.jtr
How to reproduce:
=================
Run the following script (you may need to change its variables)
--- script start ---
#!/bin/sh
RESULT_DIR=`pwd`
WORK_DIR=$RESULT_DIR/workDir/test
REPORT_DIR=$RESULT_DIR/reportDir
#Paths in Java Software:
JT_HOME="/java/re/jct-tools/3.1.2/archive/fcs/binaries"
JEMMY_JAR="/net/jdk/export/jpse04/Jemmy/jemmy.jar"
JAVA_HOME="/java/re/jdk/1.5.0/promoted/all/b24/binaries/linux-i586"
TEST_BASE_PATH="/java/re/jdk/1.5.0/promoted/all/b24/ws/j2se/test"
#Alternative paths for the NSK site:
#JT_HOME="/net/linux-15/export/home/java/jct"
#JEMMY_JAR="$JT_HOME/jemmy/jemmy.jar"
#JAVA_HOME="/net/linux-15/export/home/java/jdk1.5.0/linux"
#TEST_BASE_PATH="/net/linux-15/export/home/java/regtest.tiger/test"
TESTVMOPTS="-client"
CLASSPATH="$JT_HOME/classes:$JT_HOME/lib/javatest.jar:$JT_HOME/lib/jtreg.jar"
TEST="java/util/concurrent/FutureTask/CancelledFutureLoops.java"
mkdir -p $WORK_DIR/scratch 2>&1
mkdir -p $WORK_DIR/jtData 2>&1
mkdir -p $REPORT_DIR 2>&1
#rm $WORK_DIR/jtData/ResultCache.jtw 2>&1
cd $WORK_DIR/scratch
$JAVA_HOME/bin/java -server -cp $CLASSPATH -DenvVars=TESTJAVAHOME=$JAVA_HOME,TESTVMOPTS=$TESTVMOPTS,DISPLAY=:0,HOME=$HOME/.regtest,PATH=/bin:/usr/bin,CPAPPEND=$JEMMY_JAR,TZ=,LC_ALL=en_US,LC_CTYPE=en_US,LANG=en_US,LPDEST= -DDISPLAY=:0 -DlocalHost="linux-2" -Dprogram=jtreg com.sun.javatest.regtest.Main -a -v default -batch -params -w "$WORK_DIR" -r "$REPORT_DIR" -t "$TEST_BASE_PATH" "$TEST_BASE_PATH/$TEST"
--- script end ---
Test output (jtr part):
=======================
----------System.out:(0/0)----------
----------System.err:(2/202)----------
Note: /net/linux-15/export/home/java/regtest.tiger/test/java/util/concurrent/FutureTask/CancelledFutureLoops.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
result: Passed. Compilation successful
#section:build
----------messages:(3/107)----------
command: build CancelledFutureLoops
reason: Named class compiled on demand
elapsed time (seconds): 0.0020
result: Passed. No need to compile: CancelledFutureLoops.java
#section:main
----------messages:(3/140)----------
command: main CancelledFutureLoops
reason: User specified action: run main/timeout=2000 CancelledFutureLoops
elapsed time (seconds): 2.476
----------System.out:(3/73)----------
Threads: 2 0.908261s run time
Threads: 3 0.851531s run time
Threads: 5
----------System.err:(25/1679)----------
java.util.concurrent.ExecutionException: java.util.concurrent.BrokenBarrierException
at java.util.concurrent.CancellableTask$InnerCancellableFuture.get(CancellableTask.java:257)
at java.util.concurrent.FutureTask.get(FutureTask.java:76)
at CancelledFutureLoops$FutureLoop.test(CancelledFutureLoops.java:70)
at CancelledFutureLoops.main(CancelledFutureLoops.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:82)
at java.lang.Thread.run(Thread.java:549)
Caused by: java.util.concurrent.BrokenBarrierException
at java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:186)
at java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:298)
at CancelledFutureLoops$FutureLoop.call(CancelledFutureLoops.java:90)
at java.util.concurrent.CancellableTask$InnerCancellableFuture.run(CancellableTask.java:232)
at java.util.concurrent.CancellableTask.run(CancellableTask.java:149)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:598)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
... 1 more
JavaTest Message: Test threw exception: java.util.concurrent.ExecutionException: java.util.concurrent.BrokenBarrierException
JavaTest Message: shutting down test
STATUS:Failed.`main' threw exception: java.util.concurrent.ExecutionException: java.util.concurrent.BrokenBarrierException
result: Failed. Execution failed: `main' threw exception: java.util.concurrent.ExecutionException: java.util.concurrent.BrokenBarrierException
test result: Failed. Execution failed: `main' threw exception: java.util.concurrent.ExecutionException: java.util.concurrent.BrokenBarrierException
Specific machine info:
======================
Hostname: linux-2
OS: Suse Linux 8.2 (GNOME2)
======================================================================
- relates to
-
JDK-4939930 Bring JSR-166 up to date with Public Review Nov 2003
-
- Resolved
-