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 - Improve threading model
Summary: Improve threading model
Alias: None
Product: debugger
Classification: Unclassified
Component: Java (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Martin Entlicher
Depends on:
Reported: 2009-01-06 16:58 UTC by Martin Entlicher
Modified: 2010-04-29 09:46 UTC (History)
0 users

See Also:
Exception Reporter:

The proposed API change. (2.91 KB, text/plain)
2009-01-06 18:27 UTC, Martin Entlicher

Note You need to log in before you can comment on or make changes to this bug.
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
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
Modification of thread state (like suspend/resume, method invocation) is performed under
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

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

To assure that we do not acquire the communication lock in AWT thread, assertion was added in changeset:  
Comment 6 Quality Engineering 2009-01-16 07:30:47 UTC
Integrated into 'main-golden', will be available in build *200901160201* on (upload may still be in progress)
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.