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