author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 19 Jan 2013 23:19:12 +0000 | |
branch | refactoring-vmdata |
changeset 1985 | 7c5a14d663ba |
parent 1974 | 9dc799a359ac |
child 1986 | 9e63ab553922 |
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 |
|
1749 | 24 |
instanceVariableNames:'nativeImplementation nCalls' |
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 |
||
1749 | 110 |
nCalls |
111 |
^ nCalls ? 0 |
|
112 |
||
113 |
"Modified: / 27-10-2012 / 18:05:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
114 |
! |
|
115 |
||
1754
b3cde0c1c2b1
- do not enforce Java native code optimization off
vranyj1
parents:
1749
diff
changeset
|
116 |
nCallsReset |
b3cde0c1c2b1
- do not enforce Java native code optimization off
vranyj1
parents:
1749
diff
changeset
|
117 |
nCalls := 0 |
b3cde0c1c2b1
- do not enforce Java native code optimization off
vranyj1
parents:
1749
diff
changeset
|
118 |
|
b3cde0c1c2b1
- do not enforce Java native code optimization off
vranyj1
parents:
1749
diff
changeset
|
119 |
"Modified: / 27-10-2012 / 18:05:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b3cde0c1c2b1
- do not enforce Java native code optimization off
vranyj1
parents:
1749
diff
changeset
|
120 |
! |
b3cde0c1c2b1
- do not enforce Java native code optimization off
vranyj1
parents:
1749
diff
changeset
|
121 |
|
752 | 122 |
nativeImplementation |
123 |
"return the value of the instance variable 'nativeImplementation' (automatically generated)" |
|
124 |
||
125 |
^ nativeImplementation |
|
126 |
||
127 |
"Created: / 25.9.1999 / 23:08:00 / cg" |
|
128 |
! |
|
129 |
||
130 |
nativeImplementation:something |
|
131 |
"set the value of the instance variable 'nativeImplementation' (automatically generated)" |
|
132 |
||
133 |
nativeImplementation := something. |
|
134 |
||
135 |
"Created: / 25.9.1999 / 23:08:00 / cg" |
|
136 |
! |
|
137 |
||
138 |
sourceLineNumber |
|
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
139 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
140 |
^super sourceLineNumber |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
141 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
142 |
"/ ForceByteCodeDisplay == true ifTrue:[ ^ 1]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
143 |
"/ lineNumberTable notNil ifTrue:[ ^ lineNumberTable at:2]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1155
diff
changeset
|
144 |
"/ ^1 |
752 | 145 |
|
146 |
||
147 |
" |
|
148 |
^ (JavaSourceCodeCache new) |
|
149 |
findLineForMethod:(self selector) |
|
150 |
inClass:javaClass. |
|
151 |
" |
|
152 |
||
153 |
"Modified: / 13-12-2010 / 13:55:55 / Jan Kurs <kurs.jan@post.cz>" |
|
154 |
"Modified: / 13-12-2010 / 23:46:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
155 |
"Created: / 17-12-2010 / 10:34:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
156 |
! ! |
|
157 |
||
761 | 158 |
!JavaNativeMethod methodsFor:'private'! |
159 |
||
160 |
compileNativeImplementation: sel dispatchingTo: oldSel |
|
161 |
||
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
162 |
| src arg converted header | |
761 | 163 |
src := (JavaVM class compiledMethodAt: oldSel) source. |
164 |
src := src asStringCollection. |
|
165 |
(src first includesString: 'aJavaContext') ifTrue:[ |
|
166 |
arg := 'aJavaContext' |
|
167 |
] ifFalse:[ |
|
168 |
(src first includesString: 'nativeContext') ifTrue:[ |
|
169 |
arg := 'nativeContext' |
|
170 |
] |
|
171 |
]. |
|
172 |
arg ifNotNil:[ |
|
173 |
src removeFirst asString. |
|
174 |
converted := true. |
|
175 |
] ifNil:[ |
|
176 |
arg := 'nativeContext'. |
|
177 |
src := ' self breakPoint: #jv info: ''Convert it to new-style natives''. |
|
178 |
||
179 |
^ self ', oldSel, ' nativeContext'. |
|
180 |
converted := false. |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
181 |
]. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
182 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
183 |
header := String streamContents:[:s| |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
184 |
sel numArgs == 1 ifTrue:[ |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
185 |
s nextPutAll: sel; space; nextPutAll: 'nativeContext'. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
186 |
] ifFalse:[ |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
187 |
| kw | |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
188 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
189 |
kw := sel keywords. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
190 |
self assert: kw last = '_context:'. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
191 |
1 to: kw size - 1 do:[:i| |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
192 |
sel nextPutAll: (kw at: i); space; nextPut:$a; nextPutAll: i printString; space. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
193 |
]. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
194 |
s nextPutAll: '_context:'. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
195 |
] |
761 | 196 |
]. |
197 |
||
198 |
(JavaVM class |
|
199 |
compile: |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
200 |
(self nativeMethodTemplate bindWith:header with: arg with: src asString) |
761 | 201 |
classified: |
202 |
'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$. )) |
|
203 |
package: JavaVM package. |
|
204 |
||
205 |
converted ifTrue:[ |
|
206 |
(JavaVM class compiledMethodAt: oldSel) category: 'native - old-style (converted)' |
|
207 |
] ifFalse:[ |
|
208 |
(JavaVM class compiledMethodAt: oldSel) category: 'native - old-style (FAILED to convert)' |
|
209 |
] |
|
210 |
||
211 |
"Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
212 |
"Modified: / 19-01-2013 / 22:20:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 213 |
! |
214 |
||
215 |
compileNativeImplementationStub: sel |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
216 |
| header | |
761 | 217 |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
218 |
header := String streamContents:[:s| |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
219 |
sel numArgs == 1 ifTrue:[ |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
220 |
s nextPutAll: sel. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
221 |
] ifFalse:[ |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
222 |
| kw | |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
223 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
224 |
kw := sel keywords. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
225 |
self assert: kw last = '_context:'. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
226 |
1 to: kw size - 1 do:[:i| |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
227 |
s nextPutAll: (kw at: i); space; nextPut:$a; nextPutAll: i printString; space. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
228 |
]. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
229 |
s nextPutAll: '_context:'. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
230 |
] |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
231 |
]. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
232 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
233 |
(JavaVM natives class |
761 | 234 |
compile: |
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
235 |
(self nativeMethodTemplate bindWith:header with: 'nativeContext' with:('^ JavaVM unimplementedNativeMethodSignal raise')) |
761 | 236 |
classified: |
237 |
'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$.)) |
|
238 |
package: JavaVM package |
|
239 |
||
240 |
"Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
241 |
"Modified: / 19-01-2013 / 22:52:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 242 |
! |
243 |
||
244 |
nativeMethodTemplate |
|
245 |
||
246 |
^'%1 %2 |
|
247 |
||
248 |
<javanative: ''', javaClass name , ''' name: ''', (selector copyWithoutLast:signature size), '''> |
|
249 |
||
250 |
%3' |
|
251 |
||
252 |
"Created: / 01-05-2011 / 00:12:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
253 |
"Modified: / 19-01-2013 / 22:20:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 254 |
! |
255 |
||
256 |
searchNativeImplementation |
|
257 |
||
258 |
"Returns a SELECTOR of native method implementation. |
|
259 |
For now, two naming schemes are used. The onld one uses |
|
260 |
just a class name and selector as a name for native method impl. |
|
261 |
The new one uses fully qualified class name. |
|
262 |
" |
|
263 |
||
264 |
| nm newStyleSel oldStyleSel | |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
265 |
nm := selector upTo: $(. |
761 | 266 |
newStyleSel := ('_' , ((javaClass name copyReplaceAll:$/ with:$_) replaceAll:$$ with:$_), '_' , nm , ':') asSymbol. |
1974 | 267 |
(JavaVM natives class canUnderstand: newStyleSel) ifTrue:[ |
268 |
"Good, a JavaVM understands new style native selectors" |
|
269 |
^newStyleSel |
|
270 |
]. |
|
761 | 271 |
|
272 |
oldStyleSel := ('_' , (javaClass lastName copyReplaceAll:$$ with:$_) , '_' , nm , ':') asSymbol. |
|
1974 | 273 |
(JavaVM natives canUnderstand: oldStyleSel) ifTrue:[ |
761 | 274 |
"Convert method on the fly only if Im Jan Vrany |
275 |
(to avoid confusion of other developers :-)" |
|
276 |
OperatingSystem getLoginName = 'jv' ifTrue:[ |
|
277 |
"OK, old style method has not yet been converted to a newstyle one. |
|
278 |
Converts old-style method to a new-style one" |
|
279 |
self compileNativeImplementation: newStyleSel dispatchingTo: oldStyleSel. |
|
280 |
^newStyleSel |
|
281 |
] ifFalse:[ |
|
282 |
^oldStyleSel |
|
1974 | 283 |
] |
284 |
]. |
|
761 | 285 |
self compileNativeImplementationStub: newStyleSel. |
286 |
^newStyleSel |
|
287 |
||
288 |
"Created: / 30-04-2011 / 23:50:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1974 | 289 |
"Modified: / 16-01-2013 / 21:25:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
290 |
! |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
291 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
292 |
searchNativeImplementation: numArgs |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
293 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
294 |
"Returns a SELECTOR of native method implementation." |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
295 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
296 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
297 |
| nm newStyleSel args | |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
298 |
nm := selector upTo: $(. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
299 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
300 |
args := #( |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
301 |
"0" '_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
302 |
"1" ':_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
303 |
"2" ':_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
304 |
"3" ':_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
305 |
"4" ':_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
306 |
"5" ':_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
307 |
"6" ':_:_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
308 |
"7" ':_:_:_:_:_:_:_:context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
309 |
"8" ':_:_:_:_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
310 |
"9" ':_:_:_:_:_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
311 |
"10" ':_:_:_:_:_:_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
312 |
"11" ':_:_:_:_:_:_:_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
313 |
"12" ':_:_:_:_:_:_:_:_:_:_:_:_context:' |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
314 |
) at: numArgs + 1. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
315 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
316 |
newStyleSel := ('_' , ((javaClass name copyReplaceAll:$/ with:$_) replaceAll:$$ with:$_), '_' , nm , args) asSymbol. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
317 |
(JavaVM natives class canUnderstand: newStyleSel) ifTrue:[ |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
318 |
"Good, a JavaVM understands new style native selectors" |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
319 |
^newStyleSel |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
320 |
]. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
321 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
322 |
self compileNativeImplementationStub: newStyleSel. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
323 |
^newStyleSel |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
324 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
325 |
"Created: / 19-01-2013 / 22:11:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 326 |
! ! |
327 |
||
752 | 328 |
!JavaNativeMethod methodsFor:'vm support'! |
329 |
||
330 |
nativeMethodInvokation |
|
761 | 331 |
"Called by the VM when a native method is |
1748 | 332 |
to be executed - old (slow) implementation" |
333 |
||
334 |
^self nativeMethodInvokation: thisContext sender. |
|
335 |
||
336 |
" |
|
337 |
JavaNativeMethod flushAllCachedNativeMethods" |
|
338 |
||
339 |
"Modified: / 27-01-2000 / 13:34:53 / cg" |
|
340 |
"Modified: / 03-11-2011 / 10:47:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
341 |
"Modified: / 27-10-2012 / 15:15:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
342 |
! |
|
343 |
||
344 |
nativeMethodInvokation: context |
|
345 |
"Called by the VM when a native method is |
|
346 |
to be executed. |
|
347 |
||
348 |
'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
|
349 |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
350 |
| sel mthd sender nArgs argsAndContext | |
1749 | 351 |
nCalls := (nCalls ? 0) + 1. |
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
352 |
argsAndContext := Array new: (nArgs := context numArgs) + 1. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
353 |
argsAndContext replaceFrom:1 to:nArgs with: context. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
354 |
argsAndContext at: nArgs + 1 put: context. |
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
355 |
|
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
356 |
|
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
357 |
(mthd := nativeImplementation) isNil ifTrue: [ |
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
358 |
sel := self searchNativeImplementation: nArgs. |
1971
e75c1790521c
Java native implementation refactoring (phase 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1864
diff
changeset
|
359 |
mthd := (JavaVM natives class compiledMethodAt: sel). |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
360 |
(mthd isNil or: [ mthd isLazyMethod ]) ifTrue: [ |
1748 | 361 |
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
|
362 |
sender sender selector == #noByteCode ifTrue: [ |
752 | 363 |
sender := sender sender. |
364 |
sender := sender sender. |
|
365 |
sender := sender sender. |
|
366 |
]. |
|
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
367 |
^ JavaVM natives perform: sel withArguments: argsAndContext |
752 | 368 |
]. |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
369 |
CacheNativeImplementation ifTrue: [ nativeImplementation := mthd. ] |
752 | 370 |
]. |
1075
927aeb3649fc
Fix in native method imp -> class loading java tests all pass.. I'm getting drunk tonight :)
hlopkmar
parents:
1073
diff
changeset
|
371 |
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
|
372 |
^ mthd |
1971
e75c1790521c
Java native implementation refactoring (phase 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1864
diff
changeset
|
373 |
valueWithReceiver: JavaVM natives |
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
374 |
arguments: argsAndContext |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
375 |
selector: selector |
1971
e75c1790521c
Java native implementation refactoring (phase 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1864
diff
changeset
|
376 |
search: JavaVM natives class |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
377 |
sender: nil |
752 | 378 |
|
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
379 |
" |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1022
diff
changeset
|
380 |
JavaNativeMethod flushAllCachedNativeMethods" |
752 | 381 |
|
1748 | 382 |
"Created: / 27-10-2012 / 15:13:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
383 |
"Modified: / 19-01-2013 / 22:22:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 384 |
! ! |
385 |
||
386 |
!JavaNativeMethod class methodsFor:'documentation'! |
|
387 |
||
388 |
version |
|
1864 | 389 |
^ '$Header$' |
390 |
! |
|
391 |
||
392 |
version_HG |
|
393 |
||
394 |
^ '$Changeset: <not expanded> $' |
|
752 | 395 |
! |
396 |
||
397 |
version_SVN |
|
1864 | 398 |
^ '§Id§' |
923 | 399 |
|
752 | 400 |
! ! |
401 |
||
1985
7c5a14d663ba
Temporary commit. JavaNativeMethod refactored to use new-style native methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1974
diff
changeset
|
402 |
|
752 | 403 |
JavaNativeMethod initialize! |