--- a/src/JavaVM.st Thu Nov 17 13:59:35 2011 +0000
+++ b/src/JavaVM.st Thu Nov 17 18:13:31 2011 +0000
@@ -55,15 +55,15 @@
FileOpenConfirmation SocketConnectConfirmation FileIOTrace
OpenFileTable CachedNativeMethodTable ExceptionDebug ExitDebug
JavaConsoleStream StandardThreadGroup EnteredMonitorsPerProcess
- JavaMethods DUMMY_LONG_HIGHWORD DUMMY_DOUBLE_HIGHWORD NoAudio
- FirstWindowCreationSemaphore PermittedDirectories
- PermittedHostConnects SimulatedOS O_WGgraphics_originX
- O_WGgraphics_originY O_WGgraphics_pData O_FramePeer_pNativeWidget
- O_FramePeer_pData ImageStretchCache LastGraphics LastGC
- EnteredMonitorObject EnteredMonitorObjectCount
- EnteredMonitorProcess LeftMonitorObject JavaEventThread
- JavaScreenUpdaterThread JavaEventQueueThread SystemProperties
- ExceptionDebugPatterns NullPointerExceptionDebug
+ AcquiredMonitorsPerProcess JavaMethods DUMMY_LONG_HIGHWORD
+ DUMMY_DOUBLE_HIGHWORD NoAudio FirstWindowCreationSemaphore
+ PermittedDirectories PermittedHostConnects SimulatedOS
+ O_WGgraphics_originX O_WGgraphics_originY O_WGgraphics_pData
+ O_FramePeer_pNativeWidget O_FramePeer_pData ImageStretchCache
+ LastGraphics LastGC EnteredMonitorObject
+ EnteredMonitorObjectCount EnteredMonitorProcess LeftMonitorObject
+ JavaEventThread JavaScreenUpdaterThread JavaEventQueueThread
+ SystemProperties ExceptionDebugPatterns NullPointerExceptionDebug
DivisionByZeroExceptionDebug IOExceptionDebug
StdinReplacementFileQuerySignal AssertionsEnabled
SimulatedNativeMemory Reflection ZipCache ZipEntryCache
@@ -1603,9 +1603,14 @@
WaitTableAccess name: 'JavaVM wait table access mutex'.
Logger
log: 'Initializing EnteredMonitorsPerProcess'
- severity: #info
+ severity: #debug
facility: #JVM.
EnteredMonitorsPerProcess := IdentityDictionary new.
+ Logger
+ log: 'Initializing AcquiredMonitorsPerProcess'
+ severity: #debug
+ facility: #JVM.
+ AcquiredMonitorsPerProcess := IdentityDictionary new.
self initializePrimitiveClasses.
self initializeOpenFileTable.
@@ -2013,9 +2018,14 @@
self releaseLeftOverMonitors.
Logger
log: 'Clearing EnteredMonitorsPerProcess'
- severity: #info
+ severity: #debug
facility: #JVM.
EnteredMonitorsPerProcess := IdentityDictionary new.
+ Logger
+ log: 'Clearing AcquiredMonitorsPerProcess'
+ severity: #debug
+ facility: #JVM.
+ EnteredMonitorsPerProcess := IdentityDictionary new.
"
JavaVM releaseAllMonitors"
@@ -2023,7 +2033,7 @@
"Created: / 02-01-1998 / 18:04:05 / cg"
"Modified: / 07-01-1998 / 22:58:10 / cg"
"Modified: / 25-10-2010 / 19:14:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 16-11-2011 / 20:28:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 17-11-2011 / 17:00:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
releaseAllStreams
@@ -6751,18 +6761,14 @@
"Modified: / 01-05-2011 / 13:24:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-_java_lang_Thread_holdsLock: aJavaContext
-
+_java_lang_Thread_holdsLock: aJavaContext
<javanative: 'java/lang/Thread' name: 'holdsLock'>
-
-
| obj |
obj := aJavaContext argAt: 1.
-
- ^(self enteredMonitorsOfProcess:Processor activeProcess)
- includes: obj.
+ ^ self has: (Processor activeProcess) enteredMonitorFor: obj.
"Created: / 30-04-2011 / 22:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-11-2011 / 16:29:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
_java_lang_Thread_interrupt0: nativeContext
@@ -11509,36 +11515,6 @@
"Modified: / 11.12.1998 / 13:09:36 / cg"
!
-_Runtime_exitInternal: nativeContext
- "exit - here, we only shut down java threads"
-
- | enteredMonitors |
- ExitDebug == true ifTrue: [ self halt: 'Java code called exit'. ].
- self syncMonitorCache.
- (enteredMonitors := self enteredMonitors) size > 0 ifTrue: [
- enteredMonitors do: [
- :handle |
- | mon |
- mon := LockTable at: handle ifAbsent: nil.
- mon isNil ifTrue: [ self halt: 'no monitor in exitInternal'. ] ifFalse: [
- mon exit.
- ('====> terminateThread - exit monitor for ' , handle displayString
- , ' in ' , Processor activeProcess name
- , ' ...') infoPrintCR.
- ].
- ].
- ].
-
- "/ TODO: shut down all threads created by this one ...
-
- AbortSignal raise.
- self halt.
-
- "Created: / 07-01-1998 / 22:48:51 / cg"
- "Modified: / 08-01-1999 / 14:09:36 / cg"
- "Modified: / 09-11-2011 / 14:14:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-!
-
_Runtime_freeMemory:nativeContext
"free memory - Returns the number of free bytes"
@@ -16003,6 +15979,260 @@
^ UnimplementedNativeMethodSignal raise
! !
+!JavaVM class methodsFor:'new monitors'!
+
+acquireMonitor: obj ofProcess: aProcess
+ "Acquire* (stay in the queue and get it) monitor.
+ *leave is the word used by jvm spec"
+
+ | mon |
+ mon := JavaVM monitorFor: obj.
+ self assert: mon notNil.
+ Logger
+ log: ('leaving monitor %1 owned by thread: %2' bindWith: obj printString
+ with: aProcess name)
+ severity: #debug
+ facility: #JVM.
+ mon enter.
+ self assert: mon owningProcess == aProcess.
+ self acquiredMonitorsOf: aProcess add: obj.
+ self assert: ((self enteredMonitorsOfProcessAt: aProcess) includes: obj).
+
+ "Created: / 17-11-2011 / 19:01:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+acquireMonitorsOfProcess: aProcess
+ "will try to acquire all entered monitors of process"
+ | enteredMonitors |
+ (self hasEnteredMonitorsOfProcess: aProcess) ifTrue: [
+ enteredMonitors := self enteredMonitorsOfProcessAt: aProcess.
+ self assert: enteredMonitors notNil.
+ enteredMonitors do: [
+ :each |
+ self acquireMonitor:each ofProcess:aProcess.
+ ].
+ ].
+
+ "Created: / 17-11-2011 / 17:16:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+acquiredMonitorsOf: aProcess add: anyObject
+ self assert: ((self acquiredMonitorsOfProcess: aProcess) includes:anyObject).
+ ^ (self acquiredMonitorsOfProcess: aProcess) add: anyObject.
+
+ "Modified: / 08-01-1999 / 14:02:15 / cg"
+ "Created: / 17-11-2011 / 18:29:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+acquiredMonitorsOf: aProcess remove: anyObject
+ self assert: ((self acquiredMonitorsOfProcess: aProcess) includes:anyObject).
+ (self acquiredMonitorsOfProcess: aProcess) remove: anyObject.
+
+ "Modified: / 08-01-1999 / 14:02:15 / cg"
+ "Created: / 17-11-2011 / 18:40:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+acquiredMonitorsOfProcess: aProcess
+
+ ^(AcquiredMonitorsPerProcess at: aProcess ifAbsent: [|monitors|
+ monitors := OrderedCollection new.
+ AcquiredMonitorsPerProcess at: aProcess put: monitors.
+ monitors
+ ]) copy.
+
+ "Created: / 17-11-2011 / 18:29:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+acquiredMonitorsOfProcessAt: aProcess
+ "does not create empty collection like enteredMonitorsOfProcess"
+
+ ^ (AcquiredMonitorsPerProcess at: aProcess ifAbsent: nil) copy.
+
+ "Created: / 08-01-1999 / 14:02:02 / cg"
+ "Created: / 17-11-2011 / 17:03:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+countAcquiredMonitorsOfProcess: aProcess
+ | acquiredMonitors |
+ acquiredMonitors := self enteredMonitorsOfProcessAt: aProcess.
+ ^ acquiredMonitors isNil ifTrue: [ 0 ] ifFalse: [ acquiredMonitors size ].
+
+ "Created: / 17-11-2011 / 18:23:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+countEnteredMonitorsOfProcess: aProcess
+ | enteredMonitors |
+ enteredMonitors := self enteredMonitorsOfProcessAt: aProcess.
+ ^ enteredMonitors isNil ifTrue: [ 0 ] ifFalse: [ enteredMonitors size ].
+
+ "Created: / 17-11-2011 / 17:14:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enterMonitor: obj ofProcess: aProcess
+ "registers itself as one of processes wanting monitor and then tries to acquire it.
+ "
+
+ self enteredMonitorsOf:aProcess add: obj.
+ self acquireMonitor:obj ofProcess:aProcess.
+
+ "Created: / 17-11-2011 / 19:03:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enteredMonitorsOf: aProcess add: anyObject
+ self assert: ((self enteredMonitorsOfProcess: aProcess) includes:anyObject) not.
+ ^ (self enteredMonitorsOfProcess: aProcess) add: anyObject.
+
+ "Modified: / 08-01-1999 / 14:02:15 / cg"
+ "Created: / 17-11-2011 / 16:25:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enteredMonitorsOf: aProcess remove: anyObject
+ self assert: ((self enteredMonitorsOfProcess: aProcess) includes:anyObject).
+ ^ (self enteredMonitorsOfProcess: aProcess) add: anyObject.
+
+ "Modified: / 08-01-1999 / 14:02:15 / cg"
+ "Created: / 17-11-2011 / 18:40:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enteredMonitorsOfProcess: aProcess
+
+ ^ (EnteredMonitorsPerProcess at: aProcess ifAbsent: [ |monitors|
+ monitors := OrderedCollection new.
+ EnteredMonitorsPerProcess at: aProcess put: monitors.
+ monitors
+ ]) copy.
+
+ "Created: / 08-01-1999 / 14:02:02 / cg"
+ "Modified: / 17-11-2011 / 18:36:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enteredMonitorsOfProcessAt: aProcess
+ "does not create empty collection like enteredMonitorsOfProcess"
+
+ ^ (EnteredMonitorsPerProcess at: aProcess ifAbsent: nil) copy.
+
+ "Created: / 08-01-1999 / 14:02:02 / cg"
+ "Created: / 16-11-2011 / 15:37:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+has: aProcess enteredMonitorFor: anyObject
+ ^ (self enteredMonitorsOfProcess: aProcess) includes: anyObject.
+
+ "Created: / 17-11-2011 / 16:28:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+hasAcquiredMonitorsOfProcess: aProcess
+ | acquiredMonitors |
+ acquiredMonitors := self acquiredMonitorsOfProcessAt: aProcess.
+ ^ acquiredMonitors isNil
+ ifTrue: [ false ]
+ ifFalse: [ acquiredMonitors size > 0 ].
+
+ "Created: / 17-11-2011 / 17:07:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+hasEnteredMonitorsOfProcess: aProcess
+ | enteredMonitors |
+ enteredMonitors := self enteredMonitorsOfProcessAt: aProcess.
+ ^ enteredMonitors isNil ifTrue: [ false ] ifFalse: [ enteredMonitors size > 0].
+
+ "Created: / 17-11-2011 / 17:09:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+leaveMonitor: obj ofProcess: aProcess
+ "Leave* (release and never come back, exit) monitor owned by given project.
+ *leave is the word used by jvm spec"
+
+ | mon |
+ self breakPoint: #mh.
+ mon := JavaVM monitorFor: obj.
+ self assert: mon notNil.
+ self assert: mon owningProcess == aProcess.
+ Logger
+ log: ('leaving monitor %1 owned by thread: %2' bindWith: obj printString
+ with: aProcess name)
+ severity: #debug
+ facility: #JVM.
+ mon exit.
+ self acquiredMonitorsOf: aProcess remove: obj.
+ self enteredMonitorsOf: aProcess remove: obj.
+
+ "Created: / 17-11-2011 / 18:46:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+leaveMonitorsOfProcess: aProcess
+ "Leave* (release and never come back, exit) all monitors owned by given project.
+ Called when cleaning up after process death or when handling smalltalk (non-java) exceptions
+ (such an exception in native method)
+ *leave is the word used by jvm spec"
+
+ | monitors |
+ self breakPoint: #mh.
+ monitors := EnteredMonitorsPerProcess at: aProcess ifAbsent: nil.
+ monitors notNil ifTrue: [
+ monitors do: [
+ :obj |
+ | mon |
+ mon := JavaVM monitorFor: obj.
+ mon notNil ifTrue: [
+ mon owningProcess == aProcess ifTrue: [
+ Logger
+ log: ('leaving monitor owned by dying thread: ' , aProcess name)
+ severity: #info
+ facility: #JVM.
+ self breakPoint: #jv.
+ mon exit
+ ].
+ ].
+ ].
+ EnteredMonitorsPerProcess removeKey: aProcess.
+ ].
+
+ "Created: / 17-11-2011 / 16:51:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+releaseMonitor: obj ofProcess: aProcess
+ "Release* (let go and wait for it again) monitor owned by given project.
+ *word used by jvm spec"
+
+ | mon |
+ self breakPoint: #mh.
+ mon := JavaVM monitorFor: obj.
+ self assert: mon notNil.
+ self assert: mon owningProcess == aProcess.
+ Logger
+ log: ('releasing monitor %1 owned by thread: %2' bindWith: obj printString
+ with: aProcess name)
+ severity: #debug
+ facility: #JVM.
+ mon exit.
+ self acquiredMonitorsOf: aProcess remove: obj.
+ self assert: ((self enteredMonitorsOfProcessAt:aProcess) includes: obj).
+
+ "Created: / 17-11-2011 / 18:51:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+releaseMonitorsOfProcess: aProcess
+ "Releases* all monitors owned by given project.
+ Monitoc can be acquired again, (aProcess going into WAIT)
+ *word used by jvm spec"
+
+ | monitors |
+ self breakPoint: #mh.
+ monitors := self acquiredMonitorsOfProcessAt: aProcess.
+ monitors notNil ifTrue: [
+ monitors do: [
+ :obj |
+
+ self releaseMonitor:obj ofProcess:aProcess.
+
+ ].
+ ].
+
+ "Created: / 04-11-2011 / 22:15:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-11-2011 / 19:06:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
!JavaVM class methodsFor:'queries'!
booted
@@ -16019,36 +16249,8 @@
!JavaVM class methodsFor:'semaphores & monitors'!
-enteredMonitors
- ^ self enteredMonitorsOfProcess:(Processor activeProcess)
-
- "Modified: / 8.1.1999 / 14:02:15 / cg"
-!
-
-enteredMonitorsOfProcess:aProcess
- |monitors|
-
- monitors := EnteredMonitorsPerProcess at:aProcess ifAbsent:nil.
- monitors isNil ifTrue:[
- monitors := OrderedCollection new.
- EnteredMonitorsPerProcess at:aProcess put:monitors.
- ].
- ^ monitors
-
- "Created: / 8.1.1999 / 14:02:02 / cg"
-!
-
-enteredMonitorsOfProcessAt: aProcess
- "does not create empty collection like enteredMonitorsOfProcess"
-
- ^ EnteredMonitorsPerProcess at: aProcess ifAbsent: nil.
-
- "Created: / 08-01-1999 / 14:02:02 / cg"
- "Created: / 16-11-2011 / 15:37:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-!
-
monitorEnter: someObject in: aJavaContext
- | mon thisProcess objString |
+ | thisProcess objString |
self assert: (aJavaContext isJavaContext).
someObject isNil ifTrue: [
self throwNullPointerException.
@@ -16056,64 +16258,49 @@
^ self
].
thisProcess := Processor activeProcess.
- mon := self monitorFor: someObject.
- MonitorTrace ifTrue: [
- someObject isJavaClass ifTrue: [ objString := someObject name ] ifFalse: [
- objString := someObject class name , '@'
- , someObject identityHash printString.
- ].
- Logger log: 'entering monitor for ' , objString , ' in ' , thisProcess name
- severity:#info facility:#JVM.
- ].
- mon enter.
+ someObject isJavaClass ifTrue: [ objString := someObject name ] ifFalse: [
+ objString := someObject class name , '@'
+ , someObject identityHash printString.
+ ].
+ Logger
+ log: 'MONENTER: entering monitor for ' , objString , ' in '
+ , thisProcess name
+ severity: #debug
+ facility: #JVM.
+ self enterMonitor: someObject ofProcess: thisProcess.
aJavaContext addMonitor: someObject.
- MonitorTrace ifTrue: [
- Logger log: 'monitor entered in ' , thisProcess name
- severity:#info facility:#JVM.
- ].
- (self enteredMonitorsOfProcess: thisProcess) add: someObject.
+ Logger
+ log: 'MONENTER: monitor entered in ' , thisProcess name
+ severity: #debug
+ facility: #JVM.
"Created: / 08-11-2011 / 15:15:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
monitorExit: someObject in: aJavaContext
- | mon thisProcess wasBlocked lastMon objString enteredMonitors |
+ | thisProcess objString |
self assert: (aJavaContext isJavaContext).
someObject isNil ifTrue: [
self throwNullPointerException.
self breakPoint: #mh.
^ self
].
- self syncMonitorCache.
thisProcess := Processor activeProcess.
- mon := self monitorFor: someObject.
- MonitorTrace ifTrue: [
- someObject isJavaClass ifTrue: [ objString := someObject name ] ifFalse: [
- objString := someObject class name , '@'
- , someObject identityHash printString.
- ].
- Logger
- log: 'leaving monitor for ' , objString , ' in ' , thisProcess name
- severity: #info
- facility: #JVM.
- ].
- mon exit.
+ someObject isJavaClass ifTrue: [ objString := someObject name ] ifFalse: [
+ objString := someObject class name , '@'
+ , someObject identityHash printString.
+ ].
+ Logger
+ log: 'MONEXIT: leaving monitor for ' , objString , ' in '
+ , thisProcess name
+ severity: #info
+ facility: #JVM.
+ self leaveMonitor: someObject ofProcess: thisProcess.
aJavaContext removeMonitor: someObject.
- MonitorTrace ifTrue: [
- Logger
- log: 'monitor left in ' , thisProcess name
- severity: #info
- facility: #JVM.
- ].
- enteredMonitors := self enteredMonitorsOfProcessAt: thisProcess.
- enteredMonitors notNil ifTrue: [
- lastMon := enteredMonitors removeLast.
- lastMon ~~ someObject ifTrue: [
- self halt: 'oops - monitor enter/exit nesting wrong'
- ]] ifFalse: [Logger log: ('Seems that monitors of %1 were already released' bindWith: thisProcess) severity:#info facility:#JVM].
- wasBlocked := OperatingSystem blockInterrupts.
- "mon count == 0 ifTrue: [ LeftMonitorObject := someObject ]."
- wasBlocked ifFalse: [ OperatingSystem unblockInterrupts ]
+ Logger
+ log: 'MONEXIT: monitor left in ' , thisProcess name
+ severity: #info
+ facility: #JVM.
"Created: / 08-11-2011 / 15:17:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
@@ -16175,38 +16362,6 @@
"Created: / 04-11-2011 / 22:15:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-releaseMonitorsOfProcess: aProcess
- "Releases all monitors owned by given project.
- Called when cleaning up after process death or
- when handling smalltalk (non-java) exceptions
- (such an exception in native method)"
-
- | monitors |
- self breakPoint:#mh.
- monitors := EnteredMonitorsPerProcess at: aProcess ifAbsent: nil.
- monitors notNil ifTrue: [
- monitors do: [
- :obj |
- | mon |
- mon := JavaVM monitorFor: obj.
- mon notNil ifTrue: [
- mon owningProcess == aProcess ifTrue: [
- Logger
- log: ('release monitor owned by dying thread: ' , aProcess name)
- severity: #info
- facility: #JVM.
- self breakPoint: #jv.
- mon exit
- ].
- ].
- ].
- EnteredMonitorsPerProcess removeKey: aProcess.
- ].
-
- "Created: / 04-11-2011 / 22:15:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 16-11-2011 / 15:09:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-!
-
releaseSemaphoreFor:someObject
WaitTableAccess critical:[
WaitTable removeKey:someObject ifAbsent:nil
@@ -16232,22 +16387,24 @@
!
syncMonitorCache
- | mO mC mP mon wasBlocked enteredMonitors |
+ | mO mC mP mon wasBlocked |
wasBlocked := OperatingSystem blockInterrupts.
(mO := EnteredMonitorObject) notNil ifTrue: [
+ Logger log:'Syncing monitor cache'
+ severity:#debug
+ facility:#JVM.
mC := EnteredMonitorObjectCount.
mP := EnteredMonitorProcess.
mon := self monitorFor: mO.
mon fakeEnter: mP count: mC.
- enteredMonitors := self enteredMonitorsOfProcess: mP.
- mC timesRepeat: [ enteredMonitors addLast: mO ].
+ mC timesRepeat: [ self enteredMonitorsOf: mP add: mO ].
EnteredMonitorObject := EnteredMonitorProcess := LeftMonitorObject := nil.
].
wasBlocked ifFalse: [ OperatingSystem unblockInterrupts ].
"Created: / 08-01-1999 / 13:59:17 / cg"
"Modified: / 09-01-1999 / 00:39:55 / cg"
- "Modified: / 16-11-2011 / 09:37:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 17-11-2011 / 19:10:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
unwindHandlerForJavaContext: aJavaContext
@@ -16276,35 +16433,19 @@
waitFor: sema state: pState timeOut: tmo
"wait"
- | wasBlocked thisProcess enteredMonitors |
- "/ self syncMonitorCache.
+ | wasBlocked thisProcess releasedCount acquiredCount |
thisProcess := Processor activeProcess.
-
- "/ temporarily leave all entered monitors.
-
wasBlocked := OperatingSystem blockInterrupts.
self syncMonitorCache.
- enteredMonitors := self enteredMonitorsOfProcess: thisProcess.
- enteredMonitors size > 0 ifTrue: [
- MonitorTrace ifTrue: [
- ('====> wait - exit ' , enteredMonitors size printString , ' monitors in '
- , Processor activeProcess name , ' ...')
- infoPrintCR.
- ].
- enteredMonitors do: [
- :handle |
- | mon |
- mon := LockTable at: handle ifAbsent: nil.
- mon isNil ifTrue: [ self halt: 'no monitor in wait'. ] ifFalse: [
- MonitorTrace ifTrue: [
- ('====> wait - exit monitor for ' , handle displayString , ' in '
- , Processor activeProcess name , ' ...')
- infoPrintCR.
- ].
- mon exit.
- ].
- ].
- EnteredMonitorsPerProcess removeKey: thisProcess.
+ releasedCount := self countAcquiredMonitorsOfProcess: thisProcess.
+ (self hasAcquiredMonitorsOfProcess: thisProcess) ifTrue: [
+ Logger
+ log: thisProcess name , ' going into WAIT - releasing '
+ , (self countAcquiredMonitorsOfProcess: thisProcess) printString
+ , ' monitors'
+ severity: #debug
+ facility: #JVM.
+ self releaseMonitorsOfProcess: thisProcess.
].
wasBlocked ifFalse: [ OperatingSystem unblockInterrupts ].
pState notNil ifTrue: [ thisProcess state: pState ].
@@ -16316,36 +16457,24 @@
"/ re-enter monitors.
- enteredMonitors size > 0 ifTrue: [
+ (self hasEnteredMonitorsOfProcess: thisProcess) ifTrue: [
wasBlocked := OperatingSystem blockInterrupts.
self syncMonitorCache.
- MonitorTrace ifTrue: [
- ('====> wait - reenter ' , enteredMonitors size printString
- , ' monitors in ' , Processor activeProcess name
- , ' ...') infoPrintCR.
- ].
- enteredMonitors do: [
- :handle |
- | mon |
- LockTableAccess
- critical: [
- mon := LockTable at: handle ifAbsent: nil.
- mon isNil ifTrue: [ LockTable at: handle put: (mon := Monitor new) ]
- ].
- MonitorTrace ifTrue: [
- ('====> wait - reenter monitor for ' , handle displayString , ' in '
- , Processor activeProcess name , ' ...')
- infoPrintCR.
- ].
- mon enter.
- ].
- EnteredMonitorsPerProcess at: thisProcess put: enteredMonitors.
+ Logger
+ log: thisProcess name , ' has been notified - trying to acquire '
+ , (self countEnteredMonitorsOfProcess: thisProcess) printString
+ , ' monitors'
+ severity: #debug
+ facility: #JVM.
+ self acquireMonitorsOfProcess: thisProcess.
+ acquiredCount := self countAcquiredMonitorsOfProcess: thisProcess.
+ self assert: acquiredCount = releasedCount.
wasBlocked ifFalse: [ OperatingSystem unblockInterrupts ].
].
"Created: / 30-12-1998 / 19:19:35 / cg"
"Modified: / 08-01-1999 / 17:29:24 / cg"
- "Modified: / 09-11-2011 / 14:36:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 17-11-2011 / 18:56:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaVM class methodsFor:'vm support'!