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