United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7058828 test/java/util/concurrent/Phaser/Arrive.java fails intermittently
7058828 : test/java/util/concurrent/Phaser/Arrive.java fails intermittently

Details
Type:
Bug
Submit Date:
2011-06-24
Status:
Closed
Updated Date:
2013-01-03
Project Name:
JDK
Resolved Date:
2012-05-13
Component:
core-libs
OS:
generic
Sub-Component:
java.util.concurrent
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7,8
Fixed Versions:
8

Related Reports
Backport:
Duplicate:
Relates:

Sub Tasks

Description
This test failed once for me in JPRT on linux-x64. This is jdk8 b01 (which is essentially the same as jdk7-b146).



TEST: java/util/concurrent/Phaser/Arrive.java
JDK under test: (/tmp/jprt/P2/T/093317.ab23780/testproduct/linux_x64_2.6-product)
java version "1.8.0-internal"
Java(TM) SE Runtime Environment (build 1.8.0-internal-201106240933.ab23780.jdk-b00)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b16, mixed mode)

ACTION: build -- Passed. Build successful
REASON: Named class compiled on demand
TIME:   0.036 seconds
messages:
command: build Arrive
reason: Named class compiled on demand
elapsed time (seconds): 0.036

ACTION: compile -- Passed. Compilation successful
REASON: .class file out of date or does not exist
TIME:   0.035 seconds
messages:
command: compile /tmp/jprt/P2/T/093317.ab23780/source/test/java/util/concurrent/Phaser/Arrive.java
reason: .class file out of date or does not exist
elapsed time (seconds): 0.035

ACTION: main -- Failed. Execution failed: `main' threw exception: java.lang.AssertionError: Some tests failed
REASON: Assumed action based on file name: run main Arrive 
TIME:   120.01 seconds
messages:
command: main Arrive
reason: Assumed action based on file name: run main Arrive 
elapsed time (seconds): 120.01
STDOUT:

Passed = 20, failed = 1

STDERR:
java.lang.InterruptedException
	at java.lang.Object.wait(Native Method)
	at java.lang.Thread.join(Thread.java:1258)
	at java.lang.Thread.join(Thread.java:1332)
	at Arrive.test(Arrive.java:72)
	at Arrive.instanceMain(Arrive.java:91)
	at Arrive.main(Arrive.java:89)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:722)
java.lang.AssertionError: Some tests failed
	at Arrive.instanceMain(Arrive.java:93)
	at Arrive.main(Arrive.java:89)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:722)

JavaTest Message: Test threw exception: java.lang.AssertionError
JavaTest Message: shutting down test


TEST RESULT: Failed. Execution failed: `main' threw exception: java.lang.AssertionError: Some tests failed

                                    

Comments
EVALUATION

Equate number of threads and registered parties.

JDK8 changeset:

Changeset: 549b7c3f0bdc
Author:    dl
Date:      2011-07-12 15:23 +0100
URL:       http://hg.openjdk.java.net/jdk8/tl/jdk/rev/549b7c3f0bdc

7058828: test/java/util/concurrent/Phaser/Arrive.java fails intermittently
Reviewed-by: chegar

! test/java/util/concurrent/Phaser/Arrive.java
                                     
2011-07-12
EVALUATION

This test just started to fail with jdk8 ( failure NOT seen in jdk7 b146 ).

Previously the test only ever ran with 1 thread! The reason is that ThreadLocalRandom.current().nextInt(1, 10) always returned 1. Since the fix for 	7051516: "ThreadLocalRandom seed is never initialized so all instances generate the same sequence", the test now actually is running with a number of threads between 1-10.

I believe the test is misguided. It has more threads simultaneously arriving than registered parties. There is a race; In thread A the final party arrives, it does some internal state processing for the phaser, onAdvance, increment phase number, etc. Another thread may invoke arrive() while thread A is doing this, it will find that the unarrived count is -1 (  unarrived = (counts & UNARRIVED_MASK) - 1; ) and throw IllegalStateException.

I believe this to be a test problem/usage error because of the arrive() specification:

 "It is a usage error for an unregistered party to invoke this method. However, this error may result in an IllegalStateException only upon some subsequent operation on this phaser, if ever."
                                     
2011-06-24



Hardware and Software, Engineered to Work Together