author | vranyj1 |
Sat, 27 Oct 2012 15:25:16 +0000 | |
branch | jk_new_structure |
changeset 1748 | ff89096bf12f |
parent 1213 | fc90769151e8 |
child 1749 | 2a942f354a94 |
permissions | -rw-r--r-- |
877 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
877 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
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 |
||
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
877 | 20 |
" |
752 | 21 |
"{ Package: 'stx:libjava' }" |
22 |
||
23 |
JavaMethodWithHandler variableSubclass:#JavaNativeMethod |
|
24 |
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
|
25 |
classVariableNames:'CacheNativeImplementation Verbose' |
752 | 26 |
poolDictionaries:'' |
27 |
category:'Languages-Java-Classes' |
|
28 |
! |
|
29 |
||
877 | 30 |
!JavaNativeMethod class methodsFor:'documentation'! |
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 35 |
|
1155 | 36 |
New code and modifications done at SWING Research Group [1]: |
1152 | 37 |
|
877 | 38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
39 |
SWING Research Group, Czech Technical University in Prague |
|
40 |
||
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
||
1155 | 48 |
[1] Code written at SWING Research Group contains a signature |
49 |
of one of the above copright owners. For exact set of such code, |
|
50 |
see the differences between this version and version stx:libjava |
|
1152 | 51 |
as of 1.9.2010 |
877 | 52 |
|
53 |
" |
|
54 |
! ! |
|
752 | 55 |
|
56 |
!JavaNativeMethod class methodsFor:'initialization'! |
|
57 |
||
761 | 58 |
cacheNativeImplementation |
59 |
||
60 |
"For details, see #cacheNativeImplementation:" |
|
61 |
||
62 |
^CacheNativeImplementation |
|
63 |
||
64 |
"Created: / 30-04-2011 / 23:38:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
65 |
! |
|
66 |
||
67 |
cacheNativeImplementation: aBoolean |
|
68 |
||
69 |
"If set, native implementations are cached, resulting |
|
70 |
in better performance when calling native methods. |
|
71 |
Hower, no change in native method implemenetaion will |
|
72 |
not be visible then, unless #flushAllCachedNativeMethods |
|
73 |
is explictely called" |
|
74 |
||
75 |
CacheNativeImplementation := aBoolean |
|
76 |
||
77 |
"Created: / 30-04-2011 / 23:38:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
78 |
! |
|
79 |
||
752 | 80 |
initialize |
1075
927aeb3649fc
Fix in native method imp -> class loading java tests all pass.. I'm getting drunk tonight :)
hlopkmar
parents:
1073
diff
changeset
|
81 |
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
|
82 |
"By default, do not cache native impls while developing" |
761 | 83 |
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
|
84 |
Verbose := false. |
927aeb3649fc
Fix in native method imp -> class loading java tests all pass.. I'm getting drunk tonight :)
hlopkmar
parents:
1073
diff
changeset
|
85 |
" |
927aeb3649fc
Fix in native method imp -> class loading java tests all pass.. I'm getting drunk tonight :)
hlopkmar
parents:
1073
diff
changeset
|
86 |
Verbose := true. |
927aeb3649fc
Fix in native method imp -> class loading java tests all pass.. I'm getting drunk tonight :)
hlopkmar
parents:
1073
diff
changeset
|
87 |
" |
761 | 88 |
|
89 |
"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
|
90 |
"Modified (comment): / 03-11-2011 / 10:48:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 91 |
! ! |
92 |
||
93 |
!JavaNativeMethod class methodsFor:'cleanup'! |
|
94 |
||
95 |
flushAllCachedNativeMethods |
|
96 |
self allInstancesDo:[:aNativeMethod | |
|
97 |
aNativeMethod nativeImplementation:nil |
|
98 |
]. |
|
99 |
||
100 |
" |
|
101 |
self flushAllCachedNativeMethods |
|
102 |
" |
|
103 |
||
104 |
"Created: / 24.12.1999 / 03:10:38 / cg" |
|
105 |
"Modified: / 24.12.1999 / 03:10:51 / cg" |
|
106 |
! ! |
|
107 |
||
108 |
!JavaNativeMethod methodsFor:'accessing'! |
|
109 |
||
110 |
nativeImplementation |
|
111 |
"return the value of the instance variable 'nativeImplementation' (automatically generated)" |
|
112 |
||
113 |
^ nativeImplementation |
|
114 |
||
115 |
"Created: / 25.9.1999 / 23:08:00 / cg" |
|
116 |
! |
|
117 |
||
118 |
nativeImplementation:something |
|
119 |
"set the value of the instance variable 'nativeImplementation' (automatically generated)" |
|
120 |
||
121 |
nativeImplementation := something. |
|
122 |
||
123 |
"Created: / 25.9.1999 / 23:08:00 / cg" |
|
124 |
! |
|
125 |
||
126 |
sourceLineNumber |
|
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
127 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
128 |
^super sourceLineNumber |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
129 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
130 |
"/ ForceByteCodeDisplay == true ifTrue:[ ^ 1]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
131 |
"/ lineNumberTable notNil ifTrue:[ ^ lineNumberTable at:2]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
132 |
"/ ^1 |
752 | 133 |
|
134 |
||
135 |
" |
|
136 |
^ (JavaSourceCodeCache new) |
|
137 |
findLineForMethod:(self selector) |
|
138 |
inClass:javaClass. |
|
139 |
" |
|
140 |
||
141 |
"Modified: / 13-12-2010 / 13:55:55 / Jan Kurs <kurs.jan@post.cz>" |
|
142 |
"Modified: / 13-12-2010 / 23:46:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
143 |
"Created: / 17-12-2010 / 10:34:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
144 |
! ! |
|
145 |
||
761 | 146 |
!JavaNativeMethod methodsFor:'private'! |
147 |
||
148 |
compileNativeImplementation: sel dispatchingTo: oldSel |
|
149 |
||
150 |
| src arg converted | |
|
151 |
src := (JavaVM class compiledMethodAt: oldSel) source. |
|
152 |
src := src asStringCollection. |
|
153 |
(src first includesString: 'aJavaContext') ifTrue:[ |
|
154 |
arg := 'aJavaContext' |
|
155 |
] ifFalse:[ |
|
156 |
(src first includesString: 'nativeContext') ifTrue:[ |
|
157 |
arg := 'nativeContext' |
|
158 |
] |
|
159 |
]. |
|
160 |
arg ifNotNil:[ |
|
161 |
src removeFirst asString. |
|
162 |
converted := true. |
|
163 |
] ifNil:[ |
|
164 |
arg := 'nativeContext'. |
|
165 |
src := ' self breakPoint: #jv info: ''Convert it to new-style natives''. |
|
166 |
||
167 |
^ self ', oldSel, ' nativeContext'. |
|
168 |
converted := false. |
|
169 |
]. |
|
170 |
||
171 |
(JavaVM class |
|
172 |
compile: |
|
173 |
(self nativeMethodTemplate bindWith:sel with: arg with: src asString) |
|
174 |
classified: |
|
175 |
'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$. )) |
|
176 |
package: JavaVM package. |
|
177 |
||
178 |
converted ifTrue:[ |
|
179 |
(JavaVM class compiledMethodAt: oldSel) category: 'native - old-style (converted)' |
|
180 |
] ifFalse:[ |
|
181 |
(JavaVM class compiledMethodAt: oldSel) category: 'native - old-style (FAILED to convert)' |
|
182 |
] |
|
183 |
||
184 |
"Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
185 |
"Modified: / 01-05-2011 / 13:15:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
186 |
! |
|
187 |
||
188 |
compileNativeImplementationStub: sel |
|
189 |
||
190 |
(JavaVM class |
|
191 |
compile: |
|
192 |
(self nativeMethodTemplate bindWith:sel with: 'nativeContext' with:('^ UnimplementedNativeMethodSignal raise')) |
|
193 |
classified: |
|
194 |
'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$.)) |
|
195 |
package: JavaVM package |
|
196 |
||
197 |
"Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
198 |
! |
|
199 |
||
200 |
nativeMethodTemplate |
|
201 |
||
202 |
^'%1 %2 |
|
203 |
||
204 |
<javanative: ''', javaClass name , ''' name: ''', (selector copyWithoutLast:signature size), '''> |
|
205 |
||
206 |
%3' |
|
207 |
||
208 |
"Created: / 01-05-2011 / 00:12:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
209 |
! |
|
210 |
||
211 |
searchNativeImplementation |
|
212 |
||
213 |
"Returns a SELECTOR of native method implementation. |
|
214 |
For now, two naming schemes are used. The onld one uses |
|
215 |
just a class name and selector as a name for native method impl. |
|
216 |
The new one uses fully qualified class name. |
|
217 |
" |
|
218 |
||
219 |
| nm newStyleSel oldStyleSel | |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
220 |
nm := selector upTo: $(. |
761 | 221 |
newStyleSel := ('_' , ((javaClass name copyReplaceAll:$/ with:$_) replaceAll:$$ with:$_), '_' , nm , ':') asSymbol. |
222 |
(JavaVM class canUnderstand: newStyleSel) ifTrue: |
|
223 |
["Good, a JavaVM understands new style native selectors" |
|
224 |
^newStyleSel]. |
|
225 |
||
226 |
oldStyleSel := ('_' , (javaClass lastName copyReplaceAll:$$ with:$_) , '_' , nm , ':') asSymbol. |
|
227 |
(JavaVM class canUnderstand: oldStyleSel) ifTrue: |
|
228 |
[ |
|
229 |
"Convert method on the fly only if Im Jan Vrany |
|
230 |
(to avoid confusion of other developers :-)" |
|
231 |
OperatingSystem getLoginName = 'jv' ifTrue:[ |
|
232 |
"OK, old style method has not yet been converted to a newstyle one. |
|
233 |
Converts old-style method to a new-style one" |
|
234 |
self compileNativeImplementation: newStyleSel dispatchingTo: oldStyleSel. |
|
235 |
^newStyleSel |
|
236 |
] ifFalse:[ |
|
237 |
^oldStyleSel |
|
238 |
]]. |
|
239 |
self compileNativeImplementationStub: newStyleSel. |
|
240 |
^newStyleSel |
|
241 |
||
242 |
"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
|
243 |
"Modified: / 13-08-2011 / 01:08:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 244 |
! ! |
245 |
||
752 | 246 |
!JavaNativeMethod methodsFor:'vm support'! |
247 |
||
248 |
nativeMethodInvokation |
|
761 | 249 |
"Called by the VM when a native method is |
1748 | 250 |
to be executed - old (slow) implementation" |
251 |
||
252 |
^self nativeMethodInvokation: thisContext sender. |
|
253 |
||
254 |
" |
|
255 |
JavaNativeMethod flushAllCachedNativeMethods" |
|
256 |
||
257 |
"Modified: / 27-01-2000 / 13:34:53 / cg" |
|
258 |
"Modified: / 03-11-2011 / 10:47:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
259 |
"Modified: / 27-10-2012 / 15:15:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
260 |
! |
|
261 |
||
262 |
nativeMethodInvokation: context |
|
263 |
"Called by the VM when a native method is |
|
264 |
to be executed. |
|
265 |
||
266 |
'context' is the context of being-invoked native method" |
|
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
267 |
|
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
268 |
| 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
|
269 |
(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
|
270 |
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
|
271 |
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
|
272 |
(mthd isNil or: [ mthd isLazyMethod ]) ifTrue: [ |
1748 | 273 |
sender := context. |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
274 |
sender sender selector == #noByteCode ifTrue: [ |
752 | 275 |
sender := sender sender. |
276 |
sender := sender sender. |
|
277 |
sender := sender sender. |
|
278 |
]. |
|
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
279 |
^ JavaVM perform: sel with: sender. |
752 | 280 |
]. |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
281 |
CacheNativeImplementation ifTrue: [ nativeImplementation := mthd. ] |
752 | 282 |
]. |
1075
927aeb3649fc
Fix in native method imp -> class loading java tests all pass.. I'm getting drunk tonight :)
hlopkmar
parents:
1073
diff
changeset
|
283 |
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
|
284 |
^ mthd |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
285 |
valueWithReceiver: JavaVM |
1748 | 286 |
arguments: (Array with: context) |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
sender: nil |
752 | 290 |
|
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
291 |
" |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
292 |
JavaNativeMethod flushAllCachedNativeMethods" |
752 | 293 |
|
1748 | 294 |
"Created: / 27-10-2012 / 15:13:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 295 |
! ! |
296 |
||
297 |
!JavaNativeMethod class methodsFor:'documentation'! |
|
298 |
||
299 |
version |
|
1022 | 300 |
^ '$Id$' |
752 | 301 |
! |
302 |
||
303 |
version_SVN |
|
1022 | 304 |
^ '$Id$' |
923 | 305 |
|
752 | 306 |
! ! |
307 |
||
308 |
JavaNativeMethod initialize! |