src/JavaNativeMethod.st
branchjk_new_structure
changeset 1075 927aeb3649fc
parent 1073 e842ab17fe16
child 1152 040cba55a7d2
equal deleted inserted replaced
1074:9a9b2955bc3a 1075:927aeb3649fc
    41 "
    41 "
    42 "{ Package: 'stx:libjava' }"
    42 "{ Package: 'stx:libjava' }"
    43 
    43 
    44 JavaMethodWithHandler variableSubclass:#JavaNativeMethod
    44 JavaMethodWithHandler variableSubclass:#JavaNativeMethod
    45 	instanceVariableNames:'nativeImplementation'
    45 	instanceVariableNames:'nativeImplementation'
    46 	classVariableNames:'CacheNativeImplementation'
    46 	classVariableNames:'CacheNativeImplementation Verbose'
    47 	poolDictionaries:''
    47 	poolDictionaries:''
    48 	category:'Languages-Java-Classes'
    48 	category:'Languages-Java-Classes'
    49 !
    49 !
    50 
    50 
    51 !JavaNativeMethod class methodsFor:'documentation'!
    51 !JavaNativeMethod class methodsFor:'documentation'!
   118 
   118 
   119     "Created: / 30-04-2011 / 23:38:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   119     "Created: / 30-04-2011 / 23:38:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   120 !
   120 !
   121 
   121 
   122 initialize
   122 initialize
   123     self flags:(self flags bitOr:Behavior flagJavaMethod).
   123     self flags: (self flags bitOr: Behavior flagJavaMethod).
   124 
   124      "By default, do not cache native impls while developing"
   125     "By default, do not cache native impls while developing"
       
   126     CacheNativeImplementation := Smalltalk isStandAloneApp.
   125     CacheNativeImplementation := Smalltalk isStandAloneApp.
       
   126     Verbose := false.
       
   127     "
       
   128 Verbose := true.
       
   129 "
   127 
   130 
   128     "Modified: / 30-04-2011 / 23:35:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   131     "Modified: / 30-04-2011 / 23:35:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   132     "Modified (comment): / 03-11-2011 / 10:48:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
   129 ! !
   133 ! !
   130 
   134 
   131 !JavaNativeMethod class methodsFor:'cleanup'!
   135 !JavaNativeMethod class methodsFor:'cleanup'!
   132 
   136 
   133 flushAllCachedNativeMethods
   137 flushAllCachedNativeMethods
   284     "Called by the VM when a native method is
   288     "Called by the VM when a native method is
   285      to be executed"
   289      to be executed"
   286     
   290     
   287     | sel  mthd  sender |
   291     | sel  mthd  sender |
   288     (mthd := nativeImplementation) isNil ifTrue: [
   292     (mthd := nativeImplementation) isNil ifTrue: [
   289         sel := self searchNativeImplementation.        
   293         sel := self searchNativeImplementation.
   290         mthd := (JavaVM class compiledMethodAt: sel).
   294         mthd := (JavaVM class compiledMethodAt: sel).
   291         (mthd isNil or: [ mthd isLazyMethod ]) ifTrue: [
   295         (mthd isNil or: [ mthd isLazyMethod ]) ifTrue: [
   292             sender := thisContext sender.
   296             sender := thisContext sender.
   293             sender sender selector == #noByteCode ifTrue: [
   297             sender sender selector == #noByteCode ifTrue: [
   294                 sender := sender sender.
   298                 sender := sender sender.
   297             ].
   301             ].
   298             ^ JavaVM perform: sel with: sender.
   302             ^ JavaVM perform: sel with: sender.
   299         ].
   303         ].
   300         CacheNativeImplementation ifTrue: [ nativeImplementation := mthd. ]
   304         CacheNativeImplementation ifTrue: [ nativeImplementation := mthd. ]
   301     ].
   305     ].
       
   306     Verbose ifTrue: [Logger log: 'Native method invokation: ' , sel severity: #debug facility: #JVM].
   302     ^ mthd 
   307     ^ mthd 
   303         valueWithReceiver: JavaVM
   308         valueWithReceiver: JavaVM
   304         arguments: (Array with: thisContext sender)
   309         arguments: (Array with: thisContext sender)
   305         selector: selector
   310         selector: selector
   306         search: JavaVM class
   311         search: JavaVM class
   309     "
   314     "
   310      JavaNativeMethod flushAllCachedNativeMethods"
   315      JavaNativeMethod flushAllCachedNativeMethods"
   311 
   316 
   312     "Modified: / 27-01-2000 / 13:34:53 / cg"
   317     "Modified: / 27-01-2000 / 13:34:53 / cg"
   313     "Modified: / 30-04-2011 / 23:52:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   318     "Modified: / 30-04-2011 / 23:52:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   314     "Modified: / 02-11-2011 / 20:45:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
   319     "Modified: / 03-11-2011 / 10:47:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
   315 ! !
   320 ! !
   316 
   321 
   317 !JavaNativeMethod class methodsFor:'documentation'!
   322 !JavaNativeMethod class methodsFor:'documentation'!
   318 
   323 
   319 version
   324 version