Fix in mixed exception handling. development
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 10 Oct 2013 10:42:05 +0100
branchdevelopment
changeset 2843 36f000314bcd
parent 2841 6fa1bcf9c997
child 2845 16c497edc69d
Fix in mixed exception handling. Care for chained finally handlers. Also, leave monitors on proper context (i.e., on java context being left by ATHROW)
JavaContext.st
JavaVM.st
--- a/JavaContext.st	Thu Oct 10 00:08:11 2013 +0100
+++ b/JavaContext.st	Thu Oct 10 10:42:05 2013 +0100
@@ -666,9 +666,6 @@
 
 pass
 
-    "First, release all leftover acquired monitors"
-    JavaVM releaseMonitorsOfUnwindingContext: context.
-
     selector == #return ifTrue:[
         thisContext evaluateUnwindActionsUpTo:context.    
         context return
@@ -681,7 +678,7 @@
     self error:'Should never be reached'.
 
     "Created: / 04-04-2012 / 20:24:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 09-10-2013 / 01:40:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 10-10-2013 / 10:13:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaContext class methodsFor:'documentation'!
--- a/JavaVM.st	Thu Oct 10 00:08:11 2013 +0100
+++ b/JavaVM.st	Thu Oct 10 10:42:05 2013 +0100
@@ -3579,28 +3579,31 @@
 
     method := context method.
     pc := context pc.
-
-    token := JavaContext::FinallyToken new.
     returnContext := thisContext sender sender sender.
-    returnContext selector == #return: ifTrue:[
-        token
-            context: (returnContext at: 2); "/ context which should return, see GenericException>>return:
-            selector: #return:;
-            exception: returnContext receiver;
-            value: (returnContext argAt:1).
+
+    (returnContext receiver class == JavaContext finallyTokenClass and:[returnContext selector == #pass ]) ifTrue:[
+        token := returnContext receiver
     ] ifFalse:[
-        returnContext selector == #return ifTrue:[
+    token := JavaContext finallyTokenClass new.
+        returnContext selector == #return: ifTrue:[
             token
-                context: (returnContext at: 1); "/ context which should return, see GenericException>>return
-                selector: #return;
+                context: (returnContext at: 2); "/ context which should return, see GenericException>>return:
+                selector: #return:;
                 exception: returnContext receiver;
-                value: (returnContext at: 2).  "/ value which should be returned, see GenericException>>return
+                value: (returnContext argAt:1).
         ] ifFalse:[
-            self error:'Unhandled case, inform libjava developers (JV in particular)' .
+            returnContext selector == #return ifTrue:[
+                token
+                    context: (returnContext at: 1); "/ context which should return, see GenericException>>return
+                    selector: #return;
+                    exception: returnContext receiver;
+                    value: (returnContext at: 2).  "/ value which should be returned, see GenericException>>return
+            ] ifFalse:[
+                self error:'Unhandled case, inform libjava developers (JV in particular)' .
+            ].
         ].
     ].
 
-
     handlerPC := method handlerFor: nil at: pc.
     handlerPC isNil ifTrue:[ ^ self ].
 
@@ -3612,7 +3615,7 @@
     self halt: 'should not be reached'.
 
     "Created: / 03-04-2012 / 16:56:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 09-10-2013 / 01:24:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 10-10-2013 / 10:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 throwExceptionInInitializerError:className
@@ -4921,6 +4924,14 @@
      We don't want to do so, in case we're manually invoking finally blocks.
      Hence following hack: we teleport back to handler caller"
     aJavaException class == JavaContext finallyTokenClass ifTrue:[
+        | sender |
+
+        "/ First, if the method is synchronized, leave its monitor
+        sender := thisContext sender.
+        sender method isSynchronized ifTrue:[
+            self releaseMonitorsOfUnwindingContext: thisContext sender.
+        ].
+        "/ Proceed to unwind or exception handler.
         aJavaException pass.
         self halt:'Should never be reached'.
     ].
@@ -4943,8 +4954,7 @@
 
     "Created: / 08-01-1999 / 14:15:36 / cg"
     "Modified: / 08-11-2011 / 16:32:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-    "Modified: / 08-10-2013 / 22:48:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (comment): / 09-10-2013 / 00:26:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 10-10-2013 / 10:36:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _CHECKCAST: object _: class