src/JavaLookup.st
branchjk_new_structure
changeset 1508 ede3a3720ec6
parent 1483 3488eebbc835
child 1637 6a971ebbfb81
equal deleted inserted replaced
1507:87cb86c7b75c 1508:ede3a3720ec6
   120     "Modified: / 15-12-2011 / 23:06:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   120     "Modified: / 15-12-2011 / 23:06:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   121 ! !
   121 ! !
   122 
   122 
   123 !JavaLookup methodsFor:'lookup'!
   123 !JavaLookup methodsFor:'lookup'!
   124 
   124 
       
   125 lookupMethodForSelector: selector directedTo: initialSearchClass
       
   126     "This method performs standard Java lookup as required JVM spec. See 
       
   127         - JVM spec, 5.4.2.1 Method overriding
       
   128         - JVM spec, 6.4 invokevirtual
       
   129 
       
   130      This is hacky because of those stupid package-private methods. Sigh."
       
   131 
       
   132     | method superMethod |
       
   133 
       
   134     method := super lookupMethodForSelector: selector directedTo: initialSearchClass.
       
   135     method isNil ifTrue:[ ^ nil ].
       
   136 
       
   137     superMethod := super lookupMethodForSelector: selector directedTo: method mclass superclass.
       
   138     [ superMethod notNil ] whileTrue:[
       
   139         (method overrides: superMethod) ifFalse:[
       
   140             method := superMethod
       
   141         ].
       
   142         superMethod := super lookupMethodForSelector: selector directedTo: superMethod mclass superclass.
       
   143     ].
       
   144 
       
   145     ^method
       
   146 
       
   147     "Created: / 05-07-2012 / 11:06:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   148 !
       
   149 
   125 lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache
   150 lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache
   126 
   151 
   127     "Invoked by the VM to ask me for a method to call.
   152     "Invoked by the VM to ask me for a method to call.
   128      The arguments are: the selector, receiver and arguments,
   153      The arguments are: the selector, receiver and arguments,
   129      the class to start the search in (for here-, super and directed sends)
   154      the class to start the search in (for here-, super and directed sends)
   130      the sending context and the inline/poly cache (instance of
   155      the sending context and the inline/poly cache (instance of
   131      PolymorphicInlineCache). "
   156      PolymorphicInlineCache). "
   132 
   157 
   133     | m |
       
   134     m := super lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache.
       
   135     m notNil ifTrue: [ ^ m ].
       
   136 
       
   137     sendingContext programmingLanguage isSmalltalk ifTrue:[
   158     sendingContext programmingLanguage isSmalltalk ifTrue:[
   138         aReceiver class theNonMetaclass programmingLanguage isJavaLike ifTrue:[
   159         aReceiver class theNonMetaclass programmingLanguage isJavaLike ifTrue:[
   139             ^s2j lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache.
   160             ^s2j lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache.
   140         ]
   161         ].
   141     ].
   162     ].
   142 
   163 
   143     sendingContext programmingLanguage isJava ifTrue:[
   164     sendingContext programmingLanguage isJavaLike ifTrue:[
   144         aReceiver class programmingLanguage isSmalltalk ifTrue:[
   165         initialSearchClass programmingLanguage isSmalltalk ifTrue:[
       
   166             "Java to Smalltalk send"
   145             ^j2s lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache.
   167             ^j2s lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache.
   146         ]
   168         ].
   147     ].
   169         initialSearchClass programmingLanguage isJavaLike ifTrue:[
   148 
   170             "Java to Java send"
   149     ^nil
   171             | m |
       
   172 
       
   173             m := self lookupMethodForSelector: selector directedTo: initialSearchClass.
       
   174             m notNil ifTrue:[
       
   175                 ilcCache notNil ifTrue:[ ilcCache bindTo: m forClass: aReceiver class ].
       
   176                 ^m.
       
   177             ]
       
   178         ].
       
   179     ].
       
   180 
       
   181     ^super lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache.
   150 
   182 
   151     "Created: / 01-10-2011 / 13:18:40 / Jan Kurs <kursjan@fit.cvut.cz>"
   183     "Created: / 01-10-2011 / 13:18:40 / Jan Kurs <kursjan@fit.cvut.cz>"
   152     "Created: / 15-12-2011 / 23:11:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   184     "Created: / 15-12-2011 / 23:11:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   153 ! !
   185 ! !
   154 
   186