src/JavaContext.st
branchjk_new_structure
changeset 1098 dd1e76f6f964
parent 1097 41def5679e28
child 1100 1405b1485a66
--- a/src/JavaContext.st	Tue Nov 08 15:48:44 2011 +0000
+++ b/src/JavaContext.st	Tue Nov 08 21:25:05 2011 +0000
@@ -364,21 +364,20 @@
 !
 
 acquiredMonitorsDo: aBlock 
-    acqrMonitors isNil ifTrue: [ acqrMonitors := OrderedCollection new ].
+    acqrMonitors isNil ifTrue: [ ^self ].
     acqrMonitors copy reverseDo: aBlock.
 
     "Created: / 08-11-2011 / 15:03:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 08-11-2011 / 21:46:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 addMonitor: mon 
-    Logger 
-        log: 'adding monitor'
-        severity: #info
-        facility: #JVM.
+
     acqrMonitors ifNil: [ acqrMonitors := OrderedCollection new ].
     acqrMonitors add: mon.
 
     "Created: / 08-11-2011 / 14:19:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 08-11-2011 / 21:40:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 programmingLanguage
@@ -389,18 +388,20 @@
 !
 
 removeMonitor: mon 
-    Logger 
-        log: 'removing monitor'
-        severity: #info
-        facility: #JVM.
+
     acqrMonitors isNil ifTrue: [
-        'accessing nil acqrmonitors in monexit' infoPrintCR
-    ] ifFalse: [
-        acqrMonitors remove: mon
-            ifAbsent: [ 'removing non existing monitor' infoPrintCR ]
+        Logger log: ('removeMonitor: called but no monitors in acqrMonitors (%1)' bindWith: self) severity: #warn facility: #JVM.
+        self breakPoint: #jv.
+        ^self.
     ].
+    acqrMonitors remove: mon ifAbsent: [ 
+        Logger log: ('removeMonitor: called but such monitor in acqrMonitors (%1)' bindWith: self) severity: #warn facility: #JVM.
+        self breakPoint: #jv.
+        ^self.        
+    ]
 
     "Created: / 08-11-2011 / 14:19:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 08-11-2011 / 21:39:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaContext methodsFor:'exception handler support'!
@@ -418,6 +419,50 @@
     "Created: / 7.1.1998 / 21:36:56 / cg"
 ! !
 
+!JavaContext methodsFor:'non local control flow'!
+
+unwindAndRestartForJavaException
+
+    "Called by JavaVM>>throwException: unwinds the stack
+     up to this context and restarts it so an exception handler
+     executes"
+
+    | con wasMarked |
+
+    "Each context that has a monitor acquired has
+     and unwind action that release all monitors acquired.
+     However, we DONT want my monitors to be released,
+     so we temporarily unmark this context for unwind and
+     then mark it again, eventually"
+
+    wasMarked := self isUnwindContext.
+    wasMarked ifTrue:[self unmarkForUnwind].    
+    self senderIsNil ifFalse:[
+        con := thisContext evaluateUnwindActionsUpTo:self.
+    ].
+    wasMarked ifTrue:[self markForUnwind].
+
+    "oops, if nil, I am not on the calling chain;
+     (bad bad, unwind action have already been performed.
+      should we check for this situation first and NOT evaluate
+      the unwind actions in this case ?)
+    "
+    con isNil ifTrue:[
+        "
+         tried to return to a context which is already dead
+         (i.e. the method/block has already executed a return)
+        "
+        ^ self invalidReturnOrRestartError:#'unwindAndRestart:' with:nil
+    ].
+    "
+     now, that all unwind-actions are done, I can use the
+     low-level restart ...
+    "
+    ^ self restart
+
+    "Created: / 08-11-2011 / 22:00:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaContext methodsFor:'printing & storing'!
 
 receiverPrintString