JavaNativeMethod.st
author vranyj1
Fri, 19 Aug 2011 08:58:19 +0000
changeset 749 e898eaeff091
parent 748 da0840b7798c
child 2097 f0310d8634d3
permissions -rw-r--r--
Synchronized with CVS repository at: :ext:vrany@dialin.exept.de:/cvs/stx
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     1
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     3
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     4
                            SWING Research Group, Czech Technical University in Prague
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     5
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     6
 Parts of the code written by Claus Gittinger are under following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     7
 license:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     8
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
     9
 This software is furnished under a license and may be used
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    10
 only in accordance with the terms of that license and with the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    12
 be provided or otherwise made available to, or used by, any
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    13
 other person.  No title to or ownership of the software is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    14
 hereby transferred.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    15
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    16
 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    17
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    18
 Permission is hereby granted, free of charge, to any person
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    19
 obtaining a copy of this software and associated documentation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    20
 files (the 'Software'), to deal in the Software without
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    21
 restriction, including without limitation the rights to use,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    22
 copy, modify, merge, publish, distribute, sublicense, and/or sell
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    23
 copies of the Software, and to permit persons to whom the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    24
 Software is furnished to do so, subject to the following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    25
 conditions:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    26
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    27
 The above copyright notice and this permission notice shall be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    28
 included in all copies or substantial portions of the Software.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    29
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    30
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    31
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    32
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    33
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    34
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    35
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    36
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    37
 OTHER DEALINGS IN THE SOFTWARE.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    38
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    39
 [1] Code written at SWING Research Group contain a signature
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    40
     of one of the above copright owners.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    41
"
703
37d2ddc947ed *** empty log message ***
cg
parents: 663
diff changeset
    42
"{ Package: 'stx:libjava' }"
37d2ddc947ed *** empty log message ***
cg
parents: 663
diff changeset
    43
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
    44
JavaMethodWithHandler variableSubclass:#JavaNativeMethod
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
    45
	instanceVariableNames:'nativeImplementation'
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    46
	classVariableNames:'CacheNativeImplementation'
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
    47
	poolDictionaries:''
713
75e92ac63bf1 category change
cg
parents: 703
diff changeset
    48
	category:'Languages-Java-Classes'
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
    49
!
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
    50
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    51
!JavaNativeMethod class methodsFor:'documentation'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    52
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    53
copyright
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    54
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    55
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    56
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    57
                            SWING Research Group, Czech Technical University in Prague
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    58
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    59
 Parts of the code written by Claus Gittinger are under following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    60
 license:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    61
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    62
 This software is furnished under a license and may be used
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    63
 only in accordance with the terms of that license and with the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    64
 inclusion of the above copyright notice.   This software may not
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    65
 be provided or otherwise made available to, or used by, any
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    66
 other person.  No title to or ownership of the software is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    67
 hereby transferred.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    68
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    69
 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    70
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    71
 Permission is hereby granted, free of charge, to any person
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    72
 obtaining a copy of this software and associated documentation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    73
 files (the 'Software'), to deal in the Software without
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    74
 restriction, including without limitation the rights to use,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    75
 copy, modify, merge, publish, distribute, sublicense, and/or sell
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    76
 copies of the Software, and to permit persons to whom the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    77
 Software is furnished to do so, subject to the following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    78
 conditions:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    79
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    80
 The above copyright notice and this permission notice shall be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    81
 included in all copies or substantial portions of the Software.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    82
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    83
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    84
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    85
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    86
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    87
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    88
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    89
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    90
 OTHER DEALINGS IN THE SOFTWARE.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    91
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    92
 [1] Code written at SWING Research Group contain a signature
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    93
     of one of the above copright owners.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    94
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    95
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
    96
! !
642
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
    97
616
53bf2ec50346 *** empty log message ***
cg
parents: 611
diff changeset
    98
!JavaNativeMethod class methodsFor:'initialization'!
53bf2ec50346 *** empty log message ***
cg
parents: 611
diff changeset
    99
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   100
cacheNativeImplementation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   101
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   102
    "For details, see #cacheNativeImplementation:"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   103
    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   104
    ^CacheNativeImplementation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   105
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   106
    "Created: / 30-04-2011 / 23:38:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   107
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   108
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   109
cacheNativeImplementation: aBoolean
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   110
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   111
    "If set, native implementations are cached, resulting
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   112
     in better performance when calling native methods.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   113
     Hower, no change in native method implemenetaion will
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   114
     not be visible then, unless #flushAllCachedNativeMethods
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   115
     is explictely called"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   116
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   117
    CacheNativeImplementation := aBoolean
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   118
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   119
    "Created: / 30-04-2011 / 23:38:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   120
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   121
616
53bf2ec50346 *** empty log message ***
cg
parents: 611
diff changeset
   122
initialize
53bf2ec50346 *** empty log message ***
cg
parents: 611
diff changeset
   123
    self flags:(self flags bitOr:Behavior flagJavaMethod).
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   124
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   125
    "By default, do not cache native impls while developing"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   126
    CacheNativeImplementation := Smalltalk isStandAloneApp.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   127
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   128
    "Modified: / 30-04-2011 / 23:35:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
616
53bf2ec50346 *** empty log message ***
cg
parents: 611
diff changeset
   129
! !
53bf2ec50346 *** empty log message ***
cg
parents: 611
diff changeset
   130
654
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   131
!JavaNativeMethod class methodsFor:'cleanup'!
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   132
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   133
flushAllCachedNativeMethods
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   134
    self allInstancesDo:[:aNativeMethod |
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   135
        aNativeMethod nativeImplementation:nil
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   136
    ].
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   137
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   138
    "
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   139
     self flushAllCachedNativeMethods
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   140
    "
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   141
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   142
    "Created: / 24.12.1999 / 03:10:38 / cg"
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   143
    "Modified: / 24.12.1999 / 03:10:51 / cg"
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   144
! !
da8d060a3150 checkin from browser
cg
parents: 642
diff changeset
   145
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   146
!JavaNativeMethod methodsFor:'accessing'!
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   147
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   148
nativeImplementation
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   149
    "return the value of the instance variable 'nativeImplementation' (automatically generated)"
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   150
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   151
    ^ nativeImplementation
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   152
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   153
    "Created: / 25.9.1999 / 23:08:00 / cg"
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   154
!
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   155
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   156
nativeImplementation:something
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   157
    "set the value of the instance variable 'nativeImplementation' (automatically generated)"
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   158
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   159
    nativeImplementation := something.
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   160
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   161
    "Created: / 25.9.1999 / 23:08:00 / cg"
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   162
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   163
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   164
sourceLineNumber
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   165
    ForceByteCodeDisplay == true ifTrue:[ ^ 1].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   166
    lineNumberTable notNil ifTrue:[ ^ lineNumberTable at:2].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   167
    ^1
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   168
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   169
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   170
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   171
    ^ (JavaSourceCodeCache new) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   172
        findLineForMethod:(self selector)
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   173
        inClass:javaClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   174
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   175
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   176
    "Modified: / 13-12-2010 / 13:55:55 / Jan Kurs <kurs.jan@post.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   177
    "Modified: / 13-12-2010 / 23:46:30 / Marcel Hlopko <hlopik@gmail.com>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   178
    "Created: / 17-12-2010 / 10:34:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   179
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   180
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   181
!JavaNativeMethod methodsFor:'private'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   182
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   183
compileNativeImplementation: sel dispatchingTo: oldSel
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   184
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   185
    | src arg converted |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   186
    src := (JavaVM class compiledMethodAt: oldSel) source.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   187
    src := src asStringCollection.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   188
    (src first includesString: 'aJavaContext') ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   189
        arg := 'aJavaContext'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   190
    ] ifFalse:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   191
        (src first includesString: 'nativeContext') ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   192
            arg := 'nativeContext'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   193
        ]
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   194
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   195
    arg ifNotNil:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   196
        src removeFirst asString.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   197
        converted := true.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   198
    ] ifNil:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   199
        arg := 'nativeContext'.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   200
        src := '    self breakPoint: #jv info: ''Convert it to new-style natives''.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   201
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   202
                ^ self ', oldSel, ' nativeContext'.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   203
        converted := false.            
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   204
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   205
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   206
    (JavaVM class 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   207
        compile:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   208
            (self nativeMethodTemplate bindWith:sel with: arg with: src asString)
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   209
        classified:         
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   210
            'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$. ))
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   211
        package: JavaVM package.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   212
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   213
    converted ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   214
        (JavaVM class compiledMethodAt: oldSel) category: 'native - old-style (converted)'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   215
    ] ifFalse:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   216
       (JavaVM class compiledMethodAt: oldSel) category:  'native - old-style (FAILED to convert)'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   217
    ]
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   218
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   219
    "Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   220
    "Modified: / 01-05-2011 / 13:15:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   221
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   222
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   223
compileNativeImplementationStub: sel
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   224
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   225
    (JavaVM class 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   226
        compile:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   227
            (self nativeMethodTemplate bindWith:sel with: 'nativeContext' with:('^ UnimplementedNativeMethodSignal raise'))
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   228
        classified:         
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   229
            'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$.))
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   230
        package: JavaVM package
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   231
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   232
    "Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   233
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   234
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   235
nativeMethodTemplate
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   236
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   237
    ^'%1 %2
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   238
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   239
    <javanative: ''', javaClass name , ''' name: ''', (selector copyWithoutLast:signature size), '''>
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   240
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   241
    %3'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   242
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   243
    "Created: / 01-05-2011 / 00:12:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   244
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   245
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   246
searchNativeImplementation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   247
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   248
    "Returns a SELECTOR of native method implementation.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   249
    For now, two naming schemes are used. The onld one uses
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   250
    just a class name and selector as a name for native method impl.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   251
    The new one uses fully qualified class name.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   252
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   253
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   254
    | nm newStyleSel oldStyleSel |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   255
    nm := selector upTo: $(.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   256
    newStyleSel := ('_' , ((javaClass name copyReplaceAll:$/ with:$_) replaceAll:$$ with:$_), '_' , nm , ':') asSymbol.    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   257
    (JavaVM class canUnderstand: newStyleSel) ifTrue:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   258
        ["Good, a JavaVM understands new style native selectors"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   259
        ^newStyleSel].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   260
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   261
    oldStyleSel := ('_' , (javaClass lastName copyReplaceAll:$$ with:$_) , '_' , nm , ':') asSymbol.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   262
    (JavaVM class canUnderstand: oldStyleSel) ifTrue:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   263
        [
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   264
        "Convert method on the fly only if Im Jan Vrany
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   265
         (to avoid confusion of other developers :-)"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   266
        OperatingSystem getLoginName = 'jv' ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   267
            "OK, old style method has not yet been converted to a newstyle one.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   268
            Converts old-style method to a new-style one"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   269
            self compileNativeImplementation: newStyleSel dispatchingTo: oldStyleSel.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   270
            ^newStyleSel
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   271
        ] ifFalse:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   272
            ^oldStyleSel
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   273
        ]].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   274
    self compileNativeImplementationStub: newStyleSel.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   275
    ^newStyleSel
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   276
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   277
    "Created: / 30-04-2011 / 23:50:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   278
    "Modified: / 13-08-2011 / 01:08:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   279
! !
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   280
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   281
!JavaNativeMethod methodsFor:'vm support'!
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   282
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   283
nativeMethodInvokation
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   284
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   285
    "Called by the VM when a native method is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   286
     to be executed"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   287
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   288
    | sel mthd sender|
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   289
642
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   290
    (mthd := nativeImplementation) isNil ifTrue:[
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   291
        sel := self searchNativeImplementation.
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   292
642
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   293
        mthd := (JavaVM class compiledMethodAt:sel).
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   294
        (mthd isNil or:[mthd isLazyMethod]) ifTrue:[
660
9e916dc2ff18 breakpoint with lazy native method
cg
parents: 654
diff changeset
   295
            sender := thisContext sender.
9e916dc2ff18 breakpoint with lazy native method
cg
parents: 654
diff changeset
   296
            sender sender selector == #noByteCode ifTrue:[
9e916dc2ff18 breakpoint with lazy native method
cg
parents: 654
diff changeset
   297
                sender := sender sender.
663
c346b0d28deb checkin from browser
cg
parents: 660
diff changeset
   298
                sender := sender sender.
c346b0d28deb checkin from browser
cg
parents: 660
diff changeset
   299
                sender := sender sender.
660
9e916dc2ff18 breakpoint with lazy native method
cg
parents: 654
diff changeset
   300
            ].
642
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   301
            ^ JavaVM 
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   302
                perform:sel
660
9e916dc2ff18 breakpoint with lazy native method
cg
parents: 654
diff changeset
   303
                with:sender.
642
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   304
        ].
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   305
        CacheNativeImplementation ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   306
            nativeImplementation := mthd.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   307
        ]
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   308
    ].
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   309
642
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   310
    ^ mthd
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   311
        valueWithReceiver:JavaVM
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   312
        arguments:(Array with:thisContext sender)
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   313
        selector:selector
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   314
        search:JavaVM class
3f9842e199be checkin from browser
cg
parents: 616
diff changeset
   315
        sender:nil
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   316
703
37d2ddc947ed *** empty log message ***
cg
parents: 663
diff changeset
   317
"
37d2ddc947ed *** empty log message ***
cg
parents: 663
diff changeset
   318
JavaNativeMethod flushAllCachedNativeMethods
37d2ddc947ed *** empty log message ***
cg
parents: 663
diff changeset
   319
"
37d2ddc947ed *** empty log message ***
cg
parents: 663
diff changeset
   320
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   321
    "Modified: / 27-01-2000 / 13:34:53 / cg"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   322
    "Modified: / 30-04-2011 / 23:52:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   323
! !
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   324
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   325
!JavaNativeMethod class methodsFor:'documentation'!
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   326
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   327
version
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   328
    ^ '$Id: JavaNativeMethod.st,v 1.9 2011/08/18 18:42:48 vrany Exp $'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   329
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   330
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   331
version_SVN
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   332
    ^ '$Id: JavaNativeMethod.st,v 1.9 2011/08/18 18:42:48 vrany Exp $'
611
490fbaed2257 faster nativeMethod invocation
cg
parents:
diff changeset
   333
! !
713
75e92ac63bf1 category change
cg
parents: 703
diff changeset
   334
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents: 748
diff changeset
   335
JavaNativeMethod initialize!