JavaLookup.st
changeset 3551 f8304e321df7
parent 3550 81ee3d2cc629
child 3552 9c3f3089d912
--- a/JavaLookup.st	Tue Mar 22 23:42:40 2016 +0000
+++ b/JavaLookup.st	Wed Mar 23 10:07:43 2016 +0000
@@ -37,7 +37,7 @@
 
 Lookup subclass:#J2J
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'NoSuchMethodErrorSelector AbstractMethodErrorSelectors'
 	poolDictionaries:''
 	privateIn:JavaLookup
 !
@@ -256,6 +256,54 @@
     "Modified: / 22-03-2016 / 22:44:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!JavaLookup::J2J class methodsFor:'initialization'!
+
+initialize
+    "Invoked at system start or when the class is dynamically loaded."
+
+    "/ please change as required (and remove this comment)
+
+    NoSuchMethodErrorSelector := #(
+            " 0" #'throwNoSuchMethodError'
+            " 1" #'throwNoSuchMethodError_:'
+            " 2" #'throwNoSuchMethodError_:_:'
+            " 3" #'throwNoSuchMethodError_:_:_:'
+            " 4" #'throwNoSuchMethodError_:_:_:_:'
+            " 5" #'throwNoSuchMethodError_:_:_:_:_:'
+            " 6" #'throwNoSuchMethodError_:_:_:_:_:_:'
+            " 7" #'throwNoSuchMethodError_:_:_:_:_:_:_:'
+            " 8" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:'
+            " 9" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:'
+            "10" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:_:'
+            "11" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:_:_:'
+            "12" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:_:_:_:'
+            "13" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:_:_:_:_:'
+            "14" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:_:_:_:_:_:'
+            "15" #'throwNoSuchMethodError_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:'
+    ).
+
+    AbstractMethodErrorSelectors := #(
+            " 0" #'throwAbstractMethodError'
+            " 1" #'throwAbstractMethodError_:'
+            " 2" #'throwAbstractMethodError_:_:'
+            " 3" #'throwAbstractMethodError_:_:_:'
+            " 4" #'throwAbstractMethodError_:_:_:_:'
+            " 5" #'throwAbstractMethodError_:_:_:_:_:'
+            " 6" #'throwAbstractMethodError_:_:_:_:_:_:'
+            " 7" #'throwAbstractMethodError_:_:_:_:_:_:_:'
+            " 8" #'throwAbstractMethodError_:_:_:_:_:_:_:_:'
+            " 9" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:'
+            "10" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:_:'
+            "11" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:_:_:'
+            "12" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:_:_:_:'
+            "13" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:_:_:_:_:'
+            "14" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:_:_:_:_:_:'
+            "15" #'throwAbstractMethodError_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:'
+    ).
+
+    "Modified: / 23-03-2016 / 09:41:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaLookup::J2J methodsFor:'lookup'!
 
 lookupMethodForSelector: selector directedTo: initialSearchClass
@@ -268,30 +316,41 @@
     | method superMethod |
 
     method := super lookupMethodForSelector: selector directedTo: initialSearchClass.
-    method isNil ifTrue:[ ^ nil ].
-
-    superMethod := super lookupMethodForSelector: selector directedTo: method mclass superclass.
-    [ superMethod notNil ] whileTrue:[
-        (method overrides: superMethod) ifFalse:[
-            method := superMethod
+    method notNil ifTrue:[
+        superMethod := super lookupMethodForSelector: selector directedTo: method mclass superclass.
+        [ superMethod notNil ] whileTrue:[
+            (method overrides: superMethod) ifFalse:[
+                method := superMethod
+            ].
+            superMethod := super lookupMethodForSelector: selector directedTo: superMethod mclass superclass.
         ].
-        superMethod := super lookupMethodForSelector: selector directedTo: superMethod mclass superclass.
     ].
-
-    ^method
+    ^ method
 
     "Created: / 05-07-2012 / 11:06:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 23-03-2016 / 09:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache
     | method |
     method := self lookupMethodForSelector: selector directedTo: initialSearchClass.
+    "/ No method found. Return a trampoline that will throw NoSuchMethodError or AbstractMethodError
+    "/ (for INVOKEINTERFACE)
+    method isNil ifTrue:[ 
+        "/ This is a hacky check whether the failing instruction is INVOKEINTERFACE or not
+        (sendingContext method byteCode at: sendingContext pc - 1) == 185 ifTrue:[ 
+            method := JavaVM class >> (AbstractMethodErrorSelectors at: argArrayOrNil size + 1)
+        ] ifFalse:[ 
+            method := JavaVM class >> (NoSuchMethodErrorSelector at: argArrayOrNil size + 1)
+        ].
+    ].
     ilcCache notNil ifTrue:[
         ilcCache bindTo: method forClass: initialSearchClass.
     ].
     ^ method.
 
     "Created: / 22-03-2016 / 22:43:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 23-03-2016 / 09:57:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaLookup::J2S methodsFor:'lookup'!
@@ -1131,3 +1190,4 @@
 
 
 JavaLookup initialize!
+JavaLookup::J2J initialize!