United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6560119 incorrect synchonization in com/sun/jmx/remote/internal/ArrayNotificationBuffer.java
JDK-6560119 : incorrect synchonization in com/sun/jmx/remote/internal/ArrayNotificationBuffer.java

Details
Type:
Bug
Submit Date:
2007-05-21
Status:
Resolved
Updated Date:
2010-07-29
Project Name:
JDK
Resolved Date:
2007-06-10
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6u1
Fixed Versions:
6u4 (b01)

Related Reports
Backport:

Sub Tasks

Description
In the Java6 JDK, file:   src/share/classes/com/sun/jmx/remote/internal/ArrayNotificationBuffer.java

void removeSharer(xxx) {
  sync(this) {
    empty = ...; // set empty=true
  }              // UNLOCK 'this' - 1
  if( empty )    // test empty - 2
    dispose();   // call dispose
}

public void dispose() {
  synchronized(this) {  // RELOCK 'this' - 3
    ...
  }
}

So basically the order of events is:
- 1 : UNLOCK 'this'
- 2 : test empty
- 3 : RELOCK 'this'

If another thread invalidates the 'empty' flag while at step 2 ('this' is unlocked), e.g. by calling addSharer on the same ArrayNotificationBuffer then you end up calling 'dispose()' on a non-empty sharer.  Our stress-mode -Xcomp JCK test runs trigger this crash fairly routinely.

                                    

Comments
EVALUATION

The logic is indeed incorrect.  The reason the call to dispose() is outside the synchronized block is that we do not want to hold any locks while we are removing the listeners that the buffer has on user MBeans.  Removing those listeners involves calling user code so it would be risky to hold any locks.
                                     
2007-05-22
EVALUATION

I have reworked and simplified the synchronization logic in ArrayNotificationBuffer and added comments to document more clearly how it works.  This problem should no longer exist (subject to confirmation by the previously-failing JCK tests).
                                     
2007-05-25



Hardware and Software, Engineered to Work Together