This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 156368

Summary: Improve threading model
Product: debugger Reporter: Martin Entlicher <mentlicher>
Component: JavaAssignee: Martin Entlicher <mentlicher>
Status: CLOSED FIXED    
Severity: blocker Keywords: API, API_REVIEW_FAST
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: The proposed API change.

Description Martin Entlicher 2009-01-06 16:58:46 UTC
Current threading model in JPDA debugger is not really clear. JPDADebuggerImpl.LOCK is mostly used to synchronize access
to JDI and resume/suspend actions. However, threads have their own synchronization (directly on the JPDAThreadImpl
object). Combining of these locks does not scale much and is not implemented everywhere to handle collisions of
VirtualMachine.resume() with actions on individual threads.

The access to the debuggee through JDI layer can be classified into different categories. Each category have read or
write access and concerns a specific thread or the whole debuggee VM. Therefore we can have a "read" or "write" access
with global impact (on whole VirtualMachine and all it's threads) and "read" or "write" access to a specific thread.

Read or write operations on specific thread should run concurrently with read or write operations on other threads.
But global write operation needs to be exclusive.

In order to accomplish this, ReadWriteLock can be introduced instead of the plain synchronize.
Comment 1 Martin Entlicher 2009-01-06 17:23:33 UTC
The solution is to introduce:
ReadWriteLock JPDADebuggerImpl.accessLock field
and
ReadWriteLock JPDAThreadImpl.accessLock field.

Acquisition of JPDAThreadImpl.accessLock.readLock() or JPDAThreadImpl.accessLock.writeLock() will also acquire
JPDADebuggerImpl.accessLock.readLock(). That assures that the VM global state can not be changed while invoking
operations on a thread.

Retrieval of thread state (like call stack, monitors, local variables, etc.) is performed under
JPDAThreadImpl.accessLock.readLock().
Modification of thread state (like suspend/resume, method invocation) is performed under
JPDAThreadImpl.accessLock.writeLock().
Retrieval of VM global state is performed under JPDADebuggerImpl.accessLock.readLock().
Modification of VM global state is performed under JPDADebuggerImpl.accessLock.writeLock().

Since we need to retrieve the thread state information from the debugger.jpda.ui module as well, we need to put the
JPDAThreadImpl.accessLock.readLock() into the APIs in order to be able to synchronize the access on it.
Comment 2 Martin Entlicher 2009-01-06 18:27:07 UTC
Created attachment 75509 [details]
The proposed API change.
Comment 3 Martin Entlicher 2009-01-06 18:37:19 UTC
Please review this simple API change that helps with synchronization.
Instead of synchronize(JPDAThread instance) client code will use JPDAThread.getReadAccessLock().lock().
Comment 4 Martin Entlicher 2009-01-12 16:23:30 UTC
Thanks, I'm going to commit this simple change tomorrow COB.
Comment 5 Martin Entlicher 2009-01-13 20:55:36 UTC
The synchronized constructs are replaced with ReadWriteLock in changeset:   113877:7571a0a187b9
http://hg.netbeans.org/main/rev/7571a0a187b9

Also, in order to improve the threads management and prevent from threads proliferation, JavaEngineProvider creates an
RP of throughoutput 5, which is used for JDI communication. Changeset:   113878:18aae736efdb
http://hg.netbeans.org/main/rev/18aae736efdb

To assure that we do not acquire the communication lock in AWT thread, assertion was added in changeset:  
113880:b286f96180aa
http://hg.netbeans.org/main/rev/b286f96180aa
Comment 6 Quality Engineering 2009-01-16 07:30:47 UTC
Integrated into 'main-golden', will be available in build *200901160201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/7571a0a187b9
User: mentlicher@netbeans.org
Log: #156368 - Improve the threading model.
ReadWriteLock is introduced to synchronize the communication with the debuggee instead of the "synchronize" keyword.
Comment 7 Quality Engineering 2010-04-29 09:46:20 UTC
Verified ... and Closing all issues resolved into NetBeans 6.7 and earlier.