author | Claus Gittinger <cg@exept.de> |
Thu, 24 Nov 2011 12:54:59 +0100 | |
changeset 2305 | c11e70f81f74 |
parent 2303 | f02352bc0228 |
permissions | -rw-r--r-- |
749 | 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 |
" |
|
42 |
"{ Package: 'stx:libjava' }" |
|
43 |
||
44 |
JavaByteCodeProcessor subclass:#JavaByteCodeInterpreter |
|
45 |
instanceVariableNames:'' |
|
46 |
classVariableNames:'' |
|
47 |
poolDictionaries:'' |
|
48 |
category:'Languages-Java-Bytecode' |
|
49 |
! |
|
50 |
||
51 |
!JavaByteCodeInterpreter 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 |
! |
|
97 |
||
98 |
documentation |
|
99 |
" |
|
100 |
Base class for intepreting Java bytecode. |
|
101 |
This class is based on NewCompiler::JavaByteCodeInterpreter |
|
102 |
written originally by Claus Gittinger |
|
103 |
||
104 |
||
105 |
[author:] |
|
106 |
Jan Vrany (jan.vrany@fit.cvut.cz) |
|
107 |
||
108 |
[instance variables:] |
|
109 |
||
110 |
[class variables:] |
|
111 |
||
112 |
[see also:] |
|
113 |
||
114 |
" |
|
115 |
! ! |
|
116 |
||
117 |
!JavaByteCodeInterpreter class methodsFor:'interpretation'! |
|
118 |
||
119 |
interpret:aMethod receiver:aReceiver arguments:argArray |
|
120 |
^ self new interpret:aMethod receiver:aReceiver arguments:argArray |
|
121 |
! ! |
|
122 |
||
123 |
!JavaByteCodeInterpreter methodsFor:'instructions'! |
|
124 |
||
125 |
aaload |
|
126 |
"loads onto the stack a reference from an array |
|
127 |
stack: arrayref, index -> value |
|
128 |
args: nothing" |
|
129 |
||
130 |
| arrayref index | |
|
131 |
||
132 |
index := self pop. |
|
133 |
arrayref := self pop. |
|
134 |
arrayref ifNil: [ ^ JavaVM throwNullPointerException ]. |
|
135 |
^ self pushRef: (arrayref at: index + 1). |
|
136 |
||
137 |
" |
|
138 |
The arrayref must be of type reference and must refer to an array whose |
|
139 |
components are of type reference. The index must be of type int. Both arrayref |
|
140 |
and index are popped from the operand stack. The reference value in the component |
|
141 |
of the array at index is retrieved and pushed onto the operand stack. |
|
142 |
||
143 |
If arrayref is null, aaload throws a NullPointerException. |
|
144 |
Otherwise, if index is not within the bounds of the array referenced by arrayref, |
|
145 |
the aaload instruction throws an ArrayIndexOutOfBoundsException." |
|
146 |
||
147 |
"Modified: / 16-03-2011 / 15:27:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
148 |
"Modified: / 21-03-2011 / 17:20:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
149 |
! |
|
150 |
||
151 |
aastore |
|
152 |
"stores into a reference in an array |
|
153 |
stack: arrayref, index, value -> nothing |
|
154 |
args: nothing" |
|
155 |
||
156 |
| arrayref index value | |
|
157 |
value := self pop. |
|
158 |
index := self pop. |
|
159 |
arrayref := self pop. |
|
160 |
arrayref ifNil: [ ^ JavaVM throwNullPointerException ]. |
|
161 |
arrayref at: index + 1 put: value. |
|
162 |
||
163 |
" |
|
164 |
The arrayref must be of type reference and must refer to an array whose components are of |
|
165 |
type reference. The index must be of type int and value must be of type reference. The arrayref, |
|
166 |
index, and value are popped from the operand stack. The reference value is stored as the |
|
167 |
component of the array at index. |
|
168 |
||
169 |
The type of value must be assignment compatible (§2.6.7) with the type of the components |
|
170 |
of the array referenced by arrayref. Assignment of a value of reference type S (source) |
|
171 |
to a variable of reference type T (target) is allowed only when the type S supports all |
|
172 |
the operations defined on type T. The detailed rules follow: |
|
173 |
||
174 |
If S is a class type, then: |
|
175 |
If T is a class type, then S must be the same class (§2.8.1) as T, or S must be a subclass of T; |
|
176 |
If T is an interface type, S must implement (§2.13) interface T. |
|
177 |
If S is an interface type, then: |
|
178 |
If T is a class type, then T must be Object (§2.4.7). |
|
179 |
If T is an interface type, then T must be the same interface as S or a superinterface of S (§2.13.2). |
|
180 |
||
181 |
If S is an array type, namely, the type SC[], that is, an array of components of type SC, then: |
|
182 |
If T is a class type, then T must be Object (§2.4.7). |
|
183 |
If T is an array type TC[], that is, an array of components of type TC, then one of the following must be true: |
|
184 |
TC and SC are the same primitive type (§2.4.1). |
|
185 |
TC and SC are reference types (§2.4.6), and type SC is assignable to TC by these runtime rules. |
|
186 |
If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15). |
|
187 |
||
188 |
||
189 |
If arrayref is null, aastore throws a NullPointerException. |
|
190 |
Otherwise, if index is not within the bounds of the array referenced by arrayref, |
|
191 |
the aastore instruction throws an ArrayIndexOutOfBoundsException. |
|
192 |
Otherwise, if arrayref is not null and the actual type of value is not assignment |
|
193 |
compatible (§2.6.7) with the actual type of the components of the array, aastore |
|
194 |
throws an ArrayStoreException." |
|
195 |
||
196 |
"Modified: / 22-03-2011 / 12:27:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
197 |
! |
|
198 |
||
199 |
aconst_null |
|
200 |
" |
|
201 |
Push null |
|
202 |
stack: nothing -> null |
|
203 |
args: nothing" |
|
204 |
||
205 |
self pushConstant: nil. |
|
206 |
||
207 |
" |
|
208 |
Description |
|
209 |
Push the null object reference onto the operand stack. |
|
210 |
||
211 |
Notes |
|
212 |
The Java virtual machine does not mandate a concrete |
|
213 |
value for null." |
|
214 |
||
215 |
"Created: / 24-02-2011 / 22:40:50 / Marcel Hlopko <hlopik@gmail.com>" |
|
216 |
"Modified: / 24-02-2011 / 22:07:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
217 |
"Modified: / 14-03-2011 / 20:55:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
218 |
! |
|
219 |
||
220 |
aload |
|
221 |
"raise an error: must be redefined in concrete subclass(es)" |
|
222 |
||
223 |
^ self shouldImplement |
|
224 |
! |
|
225 |
||
226 |
aload: idx |
|
227 |
"Load reference from local variable |
|
228 |
nothing -> objectRef |
|
229 |
args: index" |
|
230 |
||
231 |
self pushRef: (context at: idx + 1). |
|
232 |
||
233 |
"Description |
|
234 |
The index is an unsigned byte that must be an index into the local |
|
235 |
variable array of the current frame (§3.6). The local variable at |
|
236 |
index must contain a reference. The objectref in the local variable |
|
237 |
at index is pushed onto the operand stack. |
|
238 |
||
239 |
Notes |
|
240 |
The aload instruction cannot be used to load a value of type returnAddress |
|
241 |
from a local variable onto the operand stack. This asymmetry with the |
|
242 |
astore instruction is intentional. |
|
243 |
The aload opcode can be used in conjunction with the wide instruction |
|
244 |
to access a local variable using a two-byte unsigned index." |
|
245 |
||
246 |
"Modified: / 13-03-2011 / 20:59:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
247 |
! |
|
248 |
||
249 |
anewarray |
|
250 |
" |
|
251 |
Create new array of reference |
|
252 |
stack: count -> arrayRef |
|
253 |
args: arrayType" |
|
254 |
||
255 |
| type size | |
|
256 |
||
257 |
type := constantPool at: self fetchIndex2. |
|
258 |
size := self pop. |
|
259 |
||
260 |
self pushNewArrayOf: type sized: size. |
|
261 |
||
262 |
" |
|
263 |
Description |
|
264 |
The count must be of type int. It is popped off the operand stack. The count |
|
265 |
represents the number of components of the array to be created. The unsigned |
|
266 |
indexbyte1 and indexbyte2 are used to construct an index into the runtime |
|
267 |
constant pool of the current class (§3.6), where the value of the index is |
|
268 |
(indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index |
|
269 |
must be a symbolic reference to a class, array, or interface type. The named |
|
270 |
class, array, or interface type is resolved (§5.4.3.1). A new array with components |
|
271 |
of that type, of length count, is allocated from the garbage-collected heap, |
|
272 |
and a reference arrayref to this new array object is pushed onto the operand |
|
273 |
stack. All components of the new array are initialized to null, the default |
|
274 |
value for reference types (§2.5.1). |
|
275 |
||
276 |
Linking Exceptions |
|
277 |
During resolution of the symbolic reference to the class, array, or interface |
|
278 |
type, any of the exceptions documented in §5.4.3.1 can be thrown. |
|
279 |
||
280 |
Runtime Exception |
|
281 |
Otherwise, if count is less than zero, the anewarray instruction throws a |
|
282 |
NegativeArraySizeException. |
|
283 |
||
284 |
Notes |
|
285 |
The anewarray instruction is used to create a single dimension of an array of |
|
286 |
object references or part of a multidimensional array." |
|
287 |
||
288 |
"Created: / 14-03-2011 / 18:24:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
289 |
"Modified: / 27-03-2011 / 21:12:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
290 |
! |
|
291 |
||
292 |
areturn |
|
293 |
" |
|
294 |
Return reference from method |
|
295 |
stack: objectRef -> empty |
|
296 |
args: nothing" |
|
297 |
||
298 |
self leaveProcessorWith: (self pop). |
|
299 |
||
300 |
" |
|
301 |
Description |
|
302 |
The objectref must be of type reference and must refer to an object of a type |
|
303 |
that is assignment compatible (§2.6.7) with the type represented by the return |
|
304 |
descriptor (§4.3.3) of the current method. If the current method is a synchronized |
|
305 |
method, the monitor acquired or reentered on invocation of the method is released |
|
306 |
or exited (respectively) as if by execution of a monitorexit instruction. If no |
|
307 |
exception is thrown, objectref is popped from the operand stack of the current |
|
308 |
frame (§3.6) and pushed onto the operand stack of the frame of the invoker. Any |
|
309 |
other values on the operand stack of the current method are discarded. |
|
310 |
The interpreter then reinstates the frame of the invoker and returns control to |
|
311 |
the invoker. |
|
312 |
||
313 |
Runtime Exceptions |
|
314 |
If the current method is a synchronized method and the current thread is not the |
|
315 |
owner of the monitor acquired or reentered on invocation of the method, areturn |
|
316 |
throws an IllegalMonitorStateException. This can happen, for example, if a synchronized |
|
317 |
method contains a monitorexit instruction, but no monitorenter instruction, on the object |
|
318 |
on which the method is synchronized. |
|
319 |
Otherwise, if the virtual machine implementation enforces the rules on structured use |
|
320 |
of locks described in §8.13 and if the first of those rules is violated during invocation |
|
321 |
of the current method, then areturn throws an IllegalMonitorStateException." |
|
322 |
"Created: / 14-03-2011 / 13:45:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
323 |
! |
|
324 |
||
325 |
arraylength |
|
326 |
" |
|
327 |
Get length of array |
|
328 |
stack: arrayRef -> length |
|
329 |
args: nothing" |
|
330 |
self pushInt: self pop size. |
|
331 |
||
332 |
" |
|
333 |
Description |
|
334 |
The arrayref must be of type reference and must refer to an array. It is |
|
335 |
popped from the operand stack. The length of the array it references is |
|
336 |
determined. That length is pushed onto the operand stack as an int. |
|
337 |
||
338 |
Runtime Exception |
|
339 |
If the arrayref is null, the arraylength instruction throws a NullPointerException." |
|
340 |
||
341 |
"Created: / 14-03-2011 / 18:41:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
342 |
! |
|
343 |
||
344 |
astore |
|
345 |
"raise an error: must be redefined in concrete subclass(es)" |
|
346 |
||
347 |
^ self shouldImplement |
|
348 |
! |
|
349 |
||
350 |
astore: idx |
|
351 |
" |
|
352 |
stores a reference into a local variable #index |
|
353 |
stack: objectref -> nothing |
|
354 |
args: index" |
|
355 |
||
356 |
context at: idx + 1 put: (self pop). |
|
357 |
||
358 |
"Description |
|
359 |
The index is an unsigned byte that must be an index into the local |
|
360 |
variable array of the current frame (§3.6). The objectref on the |
|
361 |
top of the operand stack must be of type returnAddress or of type |
|
362 |
reference. It is popped from the operand stack, and the value of |
|
363 |
the local variable at index is set to objectref. |
|
364 |
||
365 |
Notes |
|
366 |
The astore instruction is used with an objectref of type returnAddress |
|
367 |
when implementing the finally clauses of the Java programming language |
|
368 |
(see Section 7.13, Compiling finally). The aload instruction cannot be |
|
369 |
used to load a value of type returnAddress from a local variable onto |
|
370 |
he operand stack. This asymmetry with the astore instruction is intentional. |
|
371 |
The astore opcode can be used in conjunction with the wide instruction |
|
372 |
to access a local variable using a two-byte unsigned index." |
|
373 |
||
374 |
"Modified: / 13-03-2011 / 16:57:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
375 |
! |
|
376 |
||
377 |
athrow |
|
378 |
"raise an error: must be redefined in concrete subclass(es)" |
|
379 |
||
380 |
^ self shouldImplement |
|
381 |
! |
|
382 |
||
383 |
baload |
|
384 |
self halt |
|
385 |
! |
|
386 |
||
387 |
bastore |
|
388 |
self halt |
|
389 |
! |
|
390 |
||
391 |
bipush |
|
392 |
" |
|
393 |
pushes a byte onto the stack as an integer value |
|
394 |
stack: nothing -> value |
|
395 |
args: byte" |
|
396 |
||
397 |
self pushInt: (self fetchByte). |
|
398 |
||
399 |
" |
|
400 |
The immediate byte is sign-extended to an int value. That value is pushed onto the operand stack. |
|
401 |
" |
|
402 |
||
403 |
"Modified: / 13-03-2011 / 16:58:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
404 |
! |
|
405 |
||
406 |
breakpoint |
|
407 |
"raise an error: must be redefined in concrete subclass(es)" |
|
408 |
||
409 |
^ self shouldImplement |
|
410 |
! |
|
411 |
||
412 |
caload |
|
413 |
self halt |
|
414 |
! |
|
415 |
||
416 |
castore |
|
417 |
self halt |
|
418 |
! |
|
419 |
||
420 |
checkcast |
|
421 |
" |
|
422 |
Check whether object is of given type |
|
423 |
stack: objref -> objRef |
|
424 |
args: indexByte1 indexByte2" |
|
425 |
||
426 |
| ref objRef | |
|
427 |
||
428 |
ref := constantPool at: self fetchIndex2. |
|
429 |
ref isUnresolved |
|
430 |
ifTrue: |
|
431 |
[ ref := ref javaClass |
|
432 |
]. |
|
433 |
objRef := self pop. |
|
434 |
(objRef isNil or: [ (JavaVM canCast: objRef class to: ref) ]) |
|
435 |
ifTrue: [ self pushRef: objRef. ] |
|
436 |
ifFalse: [ JavaVM throwClassCastException ]. |
|
437 |
||
438 |
" |
|
439 |
Description |
|
440 |
The objectref must be of type reference. The unsigned indexbyte1 and indexbyte2 are used to |
|
441 |
construct an index into the runtime constant pool of the current class (§3.6), where the value |
|
442 |
of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at the index |
|
443 |
must be a symbolic reference to a class, array, or interface type. The named class, array, |
|
444 |
or interface type is resolved (§5.4.3.1). |
|
445 |
If objectref is null or can be cast to the resolved class, array, or interface type, the |
|
446 |
operand stack is unchanged; otherwise, the checkcast instruction throws a ClassCastException. |
|
447 |
The following rules are used to determine whether an objectref that is not null can be cast |
|
448 |
to the resolved type: if S is the class of the object referred to by objectref and T is the |
|
449 |
resolved class, array, or interface type, checkcast determines whether objectref can be cast |
|
450 |
to type T as follows: |
|
451 |
If S is an ordinary (nonarray) class, then: |
|
452 |
If T is a class type, then S must be the same class (§2.8.1) as T, or a subclass of T. |
|
453 |
If T is an interface type, then S must implement (§2.13) interface T. |
|
454 |
If S is an interface type, then: |
|
455 |
If T is a class type, then T must be Object (§2.4.7). |
|
456 |
If T is an interface type, then T must be the same interface as S or a superinterface |
|
457 |
of S (§2.13.2). |
|
458 |
If S is a class representing the array type SC[], that is, an array of components of |
|
459 |
type SC, then: |
|
460 |
If T is a class type, then T must be Object (§2.4.7). |
|
461 |
If T is an array type TC[], that is, an array of components of type TC, then one of the |
|
462 |
following must be true: |
|
463 |
TC and SC are the same primitive type (§2.4.1). |
|
464 |
TC and SC are reference types (§2.4.6), and type SC can be cast to TC by recursive |
|
465 |
application of these rules. |
|
466 |
If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15). |
|
467 |
Linking Exceptions |
|
468 |
During resolution of the symbolic reference to the class, array, or interface type, any of the |
|
469 |
exceptions documented in Section 5.4.3.1 can be thrown. |
|
470 |
||
471 |
Runtime Exception |
|
472 |
Otherwise, if objectref cannot be cast to the resolved class, array, or interface type, |
|
473 |
the checkcast instruction throws a ClassCastException. |
|
474 |
||
475 |
Notes |
|
476 |
The checkcast instruction is very similar to the instanceof instruction. It differs in |
|
477 |
its treatment of null, its behavior when its test fails (checkcast throws an exception, |
|
478 |
instanceof pushes a result code), and its effect on the operand stack." |
|
479 |
||
480 |
"Modified: / 21-03-2011 / 18:15:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
481 |
! |
|
482 |
||
483 |
d2f |
|
484 |
"raise an error: must be redefined in concrete subclass(es)" |
|
485 |
||
486 |
^ self shouldImplement |
|
487 |
! |
|
488 |
||
489 |
d2i |
|
490 |
"raise an error: must be redefined in concrete subclass(es)" |
|
491 |
||
492 |
^ self shouldImplement |
|
493 |
! |
|
494 |
||
495 |
d2l |
|
496 |
"raise an error: must be redefined in concrete subclass(es)" |
|
497 |
||
498 |
^ self shouldImplement |
|
499 |
! |
|
500 |
||
501 |
dadd |
|
502 |
" |
|
503 |
adds two doubles together |
|
504 |
stack: value1, value2 -> result |
|
505 |
args: nothing" |
|
506 |
||
507 |
self pushDouble: (self pop + self pop). |
|
508 |
||
509 |
" |
|
510 |
Description |
|
511 |
Both value1 and value2 must be of type double. The values are popped from the operand |
|
512 |
stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. |
|
513 |
The double result is value1' + value2'. The result is pushed onto the operand stack. |
|
514 |
The result of a dadd instruction is governed by the rules of IEEE arithmetic: |
|
515 |
If either value1' or value2' is NaN, the result is NaN. |
|
516 |
The sum of two infinities of opposite sign is NaN. |
|
517 |
The sum of two infinities of the same sign is the infinity of that sign. |
|
518 |
The sum of an infinity and any finite value is equal to the infinity. |
|
519 |
The sum of two zeroes of opposite sign is positive zero. |
|
520 |
The sum of two zeroes of the same sign is the zero of that sign. |
|
521 |
The sum of a zero and a nonzero finite value is equal to the nonzero value. |
|
522 |
The sum of two nonzero finite values of the same magnitude and opposite sign is |
|
523 |
positive zero. |
|
524 |
In the remaining cases, where neither operand is an infinity, a zero, or NaN and |
|
525 |
the values have the same sign or have different magnitudes, the sum is computed |
|
526 |
and rounded to the nearest representable value using IEEE 754 round to nearest mode. |
|
527 |
If the magnitude is too large to represent as a double, we say the operation overflows; |
|
528 |
the result is then an infinity of appropriate sign. If the magnitude is too small to |
|
529 |
represent as a double, we say the operation underflows; the result is then a zero of |
|
530 |
appropriate sign. |
|
531 |
The Java virtual machine requires support of gradual underflow as defined by IEEE 754. |
|
532 |
Despite the fact that overflow, underflow, or loss of precision may occur, execution |
|
533 |
of a dadd instruction never throws a runtime exception. |
|
534 |
" |
|
535 |
||
536 |
"Created: / 14-03-2011 / 20:53:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
537 |
! |
|
538 |
||
539 |
daload |
|
540 |
" |
|
541 |
Load double from array |
|
542 |
stack: arrayRef index -> value |
|
543 |
args: nothing" |
|
544 |
||
545 |
self swap. |
|
546 |
self pushDouble: (self pop at: (self pop + 1)). |
|
547 |
||
548 |
" |
|
549 |
Description |
|
550 |
The arrayref must be of type reference and must refer to an array whose components are of |
|
551 |
type double. The index must be of type int. Both arrayref and index are popped from the |
|
552 |
operand stack. The double value in the component of the array at index is retrieved and |
|
553 |
pushed onto the operand stack. |
|
554 |
||
555 |
Runtime Exceptions |
|
556 |
If arrayref is null, daload throws a NullPointerException. |
|
557 |
Otherwise, if index is not within the bounds of the array referenced by arrayref, the |
|
558 |
daload instruction throws an ArrayIndexOutOfBoundsException. |
|
559 |
" |
|
560 |
||
561 |
"Modified: / 14-03-2011 / 20:52:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
562 |
! |
|
563 |
||
564 |
dastore |
|
565 |
self halt |
|
566 |
! |
|
567 |
||
568 |
dcmpg |
|
569 |
"raise an error: must be redefined in concrete subclass(es)" |
|
570 |
||
571 |
^ self shouldImplement |
|
572 |
! |
|
573 |
||
574 |
dcmpl |
|
575 |
"raise an error: must be redefined in concrete subclass(es)" |
|
576 |
||
577 |
^ self shouldImplement |
|
578 |
! |
|
579 |
||
580 |
dconst: arg |
|
581 |
self pushDouble: arg. |
|
582 |
||
583 |
"Created: / 14-03-2011 / 18:01:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
584 |
! |
|
585 |
||
586 |
ddiv |
|
587 |
"raise an error: must be redefined in concrete subclass(es)" |
|
588 |
||
589 |
^ self shouldImplement |
|
590 |
! |
|
591 |
||
592 |
dload |
|
593 |
"raise an error: must be redefined in concrete subclass(es)" |
|
594 |
||
595 |
^ self shouldImplement |
|
596 |
! |
|
597 |
||
598 |
dload: idx |
|
599 |
" |
|
600 |
Load double from local variable |
|
601 |
stack: nothing -> value |
|
602 |
args: index |
|
603 |
" |
|
604 |
self pushDouble: (context at: idx + 1). |
|
605 |
||
606 |
" |
|
607 |
Description |
|
608 |
The index is an unsigned byte. Both index and index + 1 must be indices into the local |
|
609 |
variable array of the current frame (§3.6). The local variable at index must contain a |
|
610 |
double. The value of the local variable at index is pushed onto the operand stack. |
|
611 |
||
612 |
Notes |
|
613 |
The dload opcode can be used in conjunction with the wide instruction to access a local |
|
614 |
variable using a two-byte unsigned index. |
|
615 |
" |
|
616 |
||
617 |
"Modified: / 13-03-2011 / 16:59:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
618 |
! |
|
619 |
||
620 |
dmul |
|
621 |
"raise an error: must be redefined in concrete subclass(es)" |
|
622 |
||
623 |
^ self shouldImplement |
|
624 |
! |
|
625 |
||
626 |
dneg |
|
627 |
"raise an error: must be redefined in concrete subclass(es)" |
|
628 |
||
629 |
^ self shouldImplement |
|
630 |
! |
|
631 |
||
632 |
drem |
|
633 |
"raise an error: must be redefined in concrete subclass(es)" |
|
634 |
||
635 |
^ self shouldImplement |
|
636 |
! |
|
637 |
||
638 |
dreturn |
|
639 |
" |
|
640 |
Return double from method |
|
641 |
stack: value -> empty |
|
642 |
args: nothing" |
|
643 |
||
644 |
self leaveProcessorWith: (self popDouble). |
|
645 |
||
646 |
" |
|
647 |
Description |
|
648 |
The current method must have return type double. The value must be of |
|
649 |
type double. If the current method is a synchronized method, the monitor |
|
650 |
acquired or reentered on invocation of the method is released or exited |
|
651 |
(respectively) as if by execution of a monitorexit instruction. If no |
|
652 |
exception is thrown, value is popped from the operand stack of the current |
|
653 |
frame (§3.6) and undergoes value set conversion (§3.8.3), resulting in |
|
654 |
value'. The value' is pushed onto the operand stack of the frame of the |
|
655 |
invoker. Any other values on the operand stack of the current method are |
|
656 |
discarded. |
|
657 |
The interpreter then returns control to the invoker of the method, |
|
658 |
reinstating the frame of the invoker. |
|
659 |
||
660 |
Runtime Exceptions |
|
661 |
If the current method is a synchronized method and the current thread |
|
662 |
is not the owner of the monitor acquired or reentered on invocation of |
|
663 |
the method, dreturn throws an IllegalMonitorStateException. This can |
|
664 |
happen, for example, if a synchronized method contains a monitorexit |
|
665 |
instruction, but no monitorenter instruction, on the object on which |
|
666 |
the method is synchronized. |
|
667 |
Otherwise, if the virtual machine implementation enforces the rules |
|
668 |
on structured use of locks described in §8.13 and if the first of |
|
669 |
those rules is violated during invocation of the current method, |
|
670 |
then dreturn throws an IllegalMonitorStateException." |
|
671 |
"Created: / 14-03-2011 / 13:33:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
672 |
"Modified: / 14-03-2011 / 18:04:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
673 |
! |
|
674 |
||
675 |
dstore |
|
676 |
" |
|
677 |
Store double into local variable |
|
678 |
stack: value -> nothing |
|
679 |
args: index" |
|
680 |
||
681 |
context at: self fetchIndex put: (self popDouble). |
|
682 |
||
683 |
" |
|
684 |
Description |
|
685 |
The index is an unsigned byte. Both index and index + 1 must be indices |
|
686 |
into the local variable array of the current frame (§3.6). The value on |
|
687 |
the top of the operand stack must be of type double. It is popped from |
|
688 |
the operand stack and undergoes value set conversion (§3.8.3), resulting |
|
689 |
in value'. The local variables at index and index + 1 are set to value'. |
|
690 |
||
691 |
Notes |
|
692 |
The dstore opcode can be used in conjunction with the wide instruction |
|
693 |
to access a local variable using a two-byte unsigned index." |
|
694 |
||
695 |
"Created: / 14-03-2011 / 18:04:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
696 |
! |
|
697 |
||
698 |
dstore: idx |
|
699 |
" |
|
700 |
Store double into local variable |
|
701 |
stack: value -> nothing |
|
702 |
args: index" |
|
703 |
||
704 |
context at: idx + 1 put: (self popDouble). |
|
705 |
||
706 |
" |
|
707 |
Description |
|
708 |
The index is an unsigned byte. Both index and index + 1 must be indices |
|
709 |
into the local variable array of the current frame (§3.6). The value on |
|
710 |
the top of the operand stack must be of type double. It is popped from |
|
711 |
the operand stack and undergoes value set conversion (§3.8.3), resulting |
|
712 |
in value'. The local variables at index and index + 1 are set to value'. |
|
713 |
||
714 |
Notes |
|
715 |
The dstore opcode can be used in conjunction with the wide instruction |
|
716 |
to access a local variable using a two-byte unsigned index." |
|
717 |
||
718 |
"Modified: / 14-03-2011 / 18:04:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
719 |
! |
|
720 |
||
721 |
dsub |
|
722 |
"raise an error: must be redefined in concrete subclass(es)" |
|
723 |
||
724 |
^ self shouldImplement |
|
725 |
! |
|
726 |
||
727 |
dup |
|
728 |
" |
|
729 |
Duplicate the top operand stack value |
|
730 |
stack: value -> value value |
|
731 |
args: nothing |
|
732 |
" |
|
733 |
self pushRef: self tos. |
|
734 |
||
735 |
" |
|
736 |
Description |
|
737 |
Duplicate the top value on the operand stack and push the duplicated value onto the operand stack. |
|
738 |
The dup instruction must not be used unless value is a value of a category 1 computational type (§3.11.1). |
|
739 |
" |
|
740 |
||
741 |
"Modified: / 27-03-2011 / 21:19:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
742 |
! |
|
743 |
||
744 |
dup2 |
|
745 |
" |
|
746 |
Duplicate the top one or two operand stack values |
|
747 |
stack v 1: value2 value1 -> value2 value 1 value2 value1 where both value1 and value2 are values of a category 1 computational type (§3.11.1). |
|
748 |
stack v 2: value1 -> value1 value1 where value is a value of a category 2 computational type (§3.11.1). |
|
749 |
args: nothing |
|
750 |
" |
|
751 |
| tos | |
|
752 |
||
753 |
tos := self popLong. |
|
754 |
self pushLong: tos. |
|
755 |
self pushLong: tos. |
|
756 |
self breakPoint:#mh_instructions. |
|
757 |
" |
|
758 |
Description |
|
759 |
Duplicate the top one or two values on the operand stack and |
|
760 |
push the duplicated value or values back onto the operand |
|
761 |
stack in the original order. |
|
762 |
" |
|
763 |
||
764 |
"Modified: / 13-03-2011 / 17:03:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
765 |
! |
|
766 |
||
767 |
dup2_x1 |
|
768 |
self halt |
|
769 |
! |
|
770 |
||
771 |
dup2_x2 |
|
772 |
self halt |
|
773 |
! |
|
774 |
||
775 |
dup_x1 |
|
776 |
self halt |
|
777 |
! |
|
778 |
||
779 |
dup_x2 |
|
780 |
self halt |
|
781 |
! |
|
782 |
||
783 |
f2d |
|
784 |
"raise an error: must be redefined in concrete subclass(es)" |
|
785 |
||
786 |
^ self shouldImplement |
|
787 |
! |
|
788 |
||
789 |
f2i |
|
790 |
"raise an error: must be redefined in concrete subclass(es)" |
|
791 |
||
792 |
^ self shouldImplement |
|
793 |
! |
|
794 |
||
795 |
f2l |
|
796 |
"raise an error: must be redefined in concrete subclass(es)" |
|
797 |
||
798 |
^ self shouldImplement |
|
799 |
! |
|
800 |
||
801 |
fadd |
|
802 |
"raise an error: must be redefined in concrete subclass(es)" |
|
803 |
||
804 |
^ self shouldImplement |
|
805 |
! |
|
806 |
||
807 |
faload |
|
808 |
self halt |
|
809 |
! |
|
810 |
||
811 |
fastore |
|
812 |
self halt |
|
813 |
! |
|
814 |
||
815 |
fcmpg |
|
816 |
"raise an error: must be redefined in concrete subclass(es)" |
|
817 |
||
818 |
^ self shouldImplement |
|
819 |
! |
|
820 |
||
821 |
fcmpl |
|
822 |
"raise an error: must be redefined in concrete subclass(es)" |
|
823 |
||
824 |
^ self shouldImplement |
|
825 |
! |
|
826 |
||
827 |
fconst: arg |
|
828 |
self pushFloat: arg. |
|
829 |
||
830 |
"Created: / 14-03-2011 / 17:57:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
831 |
! |
|
832 |
||
833 |
fdiv |
|
834 |
"raise an error: must be redefined in concrete subclass(es)" |
|
835 |
||
836 |
^ self shouldImplement |
|
837 |
! |
|
838 |
||
839 |
fload |
|
840 |
"raise an error: must be redefined in concrete subclass(es)" |
|
841 |
||
842 |
^ self shouldImplement |
|
843 |
! |
|
844 |
||
845 |
fload: idx |
|
846 |
" |
|
847 |
Load float from local variable |
|
848 |
stack: nothing -> value |
|
849 |
args: index |
|
850 |
" |
|
851 |
self pushFloat: (context at: idx + 1). |
|
852 |
||
853 |
" |
|
854 |
Description |
|
855 |
The index is an unsigned byte that must be an index into the local |
|
856 |
variable array of the current frame (§3.6). The local variable at |
|
857 |
index must contain a float. The value of the local variable at index |
|
858 |
is pushed onto the operand stack. |
|
859 |
||
860 |
Notes |
|
861 |
The fload opcode can be used in conjunction with the wide instruction |
|
862 |
to access a local variable using a two-byte unsigned index. |
|
863 |
" |
|
864 |
||
865 |
"Modified: / 13-03-2011 / 17:05:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
866 |
! |
|
867 |
||
868 |
fmul |
|
869 |
"raise an error: must be redefined in concrete subclass(es)" |
|
870 |
||
871 |
^ self shouldImplement |
|
872 |
! |
|
873 |
||
874 |
fneg |
|
875 |
"raise an error: must be redefined in concrete subclass(es)" |
|
876 |
||
877 |
^ self shouldImplement |
|
878 |
! |
|
879 |
||
880 |
frem |
|
881 |
"raise an error: must be redefined in concrete subclass(es)" |
|
882 |
||
883 |
^ self shouldImplement |
|
884 |
! |
|
885 |
||
886 |
freturn |
|
887 |
"raise an error: must be redefined in concrete subclass(es)" |
|
888 |
||
889 |
^ self shouldImplement |
|
890 |
! |
|
891 |
||
892 |
fstore |
|
893 |
" |
|
894 |
Store float into local variable |
|
895 |
stack: value -> nothing |
|
896 |
args: index" |
|
897 |
||
898 |
self fstore: self fetchIndex. |
|
899 |
||
900 |
" |
|
901 |
Description |
|
902 |
The index is an unsigned byte that must be an index into the local |
|
903 |
variable array of the current frame (§3.6). The value on the top of |
|
904 |
the operand stack must be of type float. It is popped from the operand |
|
905 |
stack and undergoes value set conversion (§3.8.3), resulting in value'. |
|
906 |
The value of the local variable at index is set to value'. |
|
907 |
||
908 |
Notes |
|
909 |
The fstore opcode can be used in conjunction with the wide instruction |
|
910 |
to access a local variable using a two-byte unsigned index." |
|
911 |
||
912 |
"Created: / 14-03-2011 / 18:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
913 |
! |
|
914 |
||
915 |
fstore: idx |
|
916 |
" |
|
917 |
Store float into local variable |
|
918 |
stack: value -> nothing |
|
919 |
args: index |
|
920 |
" |
|
921 |
context at: idx + 1 put: (self pop). |
|
922 |
||
923 |
" |
|
924 |
Description |
|
925 |
The index is an unsigned byte that must be an index into the local |
|
926 |
variable array of the current frame (§3.6). The value on the top of |
|
927 |
the operand stack must be of type float. It is popped from the operand |
|
928 |
stack and undergoes value set conversion (§3.8.3), resulting in value'. |
|
929 |
The value of the local variable at index is set to value'. |
|
930 |
||
931 |
Notes |
|
932 |
The fstore opcode can be used in conjunction with the wide instruction |
|
933 |
to access a local variable using a two-byte unsigned index. |
|
934 |
" |
|
935 |
||
936 |
"Modified: / 13-03-2011 / 17:06:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
937 |
! |
|
938 |
||
939 |
fsub |
|
940 |
"raise an error: must be redefined in concrete subclass(es)" |
|
941 |
||
942 |
^ self shouldImplement |
|
943 |
! |
|
944 |
||
945 |
getfield |
|
946 |
"gets a field value of an object objectref, where the field is |
|
947 |
identified by field reference in the constant pool index (index1 << 8 + index2) |
|
948 |
stack: objectRef -> value |
|
949 |
args: indexByte1 indexByte2" |
|
950 |
||
951 |
| fieldref fieldOwner | |
|
952 |
||
953 |
fieldOwner := self pop. |
|
954 |
fieldref := constantPool at: self fetchIndex2. |
|
955 |
fieldref resolve. |
|
956 |
self pushConstant: (fieldref offset). |
|
957 |
||
958 |
" |
|
959 |
Description |
|
960 |
The objectref, which must be of type reference, is popped from the operand stack. |
|
961 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the |
|
962 |
runtime constant pool of the current class (§3.6), where the value of the index |
|
963 |
is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index |
|
964 |
must be a symbolic reference to a field (§5.1), which gives the name and |
|
965 |
descriptor of the field as well as a symbolic reference to the class in which |
|
966 |
the field is to be found. The referenced field is resolved (§5.4.3.2). The value |
|
967 |
of the referenced field in objectref is fetched and pushed onto the operand stack. |
|
968 |
The class of objectref must not be an array. If the field is protected (§4.6), |
|
969 |
and it is either a member of the current class or a member of a superclass of |
|
970 |
the current class, then the class of objectref must be either the current class |
|
971 |
or a subclass of the current class. |
|
972 |
||
973 |
Linking Exceptions |
|
974 |
During resolution of the symbolic reference to the field, any of the errors |
|
975 |
pertaining to field resolution documented in Section 5.4.3.2 can be thrown. |
|
976 |
Otherwise, if the resolved field is a static field, getfield throws an |
|
977 |
IncompatibleClassChangeError. |
|
978 |
||
979 |
Runtime Exception |
|
980 |
Otherwise, if objectref is null, the getfield instruction throws a NullPointerException. |
|
981 |
||
982 |
Notes |
|
983 |
The getfield instruction cannot be used to access the length field of an array. |
|
984 |
The arraylength instruction is used instead." |
|
985 |
||
986 |
"Created: / 10-03-2011 / 23:34:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
987 |
"Modified: / 16-03-2011 / 15:22:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
988 |
"Modified: / 04-06-2011 / 18:12:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
989 |
! |
|
990 |
||
991 |
getstatic |
|
992 |
" |
|
993 |
Get static field from class |
|
994 |
stack: .. -> value |
|
995 |
args: indexByte1 indexByte2" |
|
996 |
||
997 |
| fieldref | |
|
998 |
||
999 |
fieldref := constantPool at: self fetchIndex2. |
|
1000 |
fieldref resolveStatic. |
|
1001 |
self pushConstant: (fieldref offset). |
|
1002 |
||
1003 |
" |
|
1004 |
Description |
|
1005 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the |
|
1006 |
runtime constant pool of the current class (§3.6), where the value of the index |
|
1007 |
is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index |
|
1008 |
must be a symbolic reference to a field (§5.1), which gives the name and descriptor |
|
1009 |
of the field as well as a symbolic reference to the class or interface in which the |
|
1010 |
field is to be found. The referenced field is resolved (§5.4.3.2). |
|
1011 |
On successful resolution of the field, the class or interface that declared the |
|
1012 |
resolved field is initialized (§5.5) if that class or interface has not already |
|
1013 |
been initialized. |
|
1014 |
The value of the class or interface field is fetched and pushed onto the operand stack. |
|
1015 |
||
1016 |
Linking Exceptions |
|
1017 |
During resolution of the symbolic reference to the class or interface field, |
|
1018 |
any of the exceptions pertaining to field resolution documented in Section 5.4.3.2 |
|
1019 |
can be thrown. |
|
1020 |
Otherwise, if the resolved field is not a static (class) field or an interface field, |
|
1021 |
getstatic throws an IncompatibleClassChangeError. |
|
1022 |
||
1023 |
Runtime Exception |
|
1024 |
Otherwise, if execution of this getstatic instruction causes initialization of the |
|
1025 |
referenced class or interface, getstatic may throw an Error as detailed in Section 2.17.5." |
|
1026 |
||
1027 |
"Modified: / 04-06-2011 / 18:15:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1028 |
! |
|
1029 |
||
1030 |
goto |
|
1031 |
" |
|
1032 |
Branch always |
|
1033 |
stack: nothing -> nothing |
|
1034 |
args: branchByte1 branchByte2" |
|
1035 |
||
1036 |
self relativeJump: self fetchBytes2. |
|
1037 |
||
1038 |
" |
|
1039 |
Description |
|
1040 |
The unsigned bytes branchbyte1 and branchbyte2 are used to construct a signed 16-bit |
|
1041 |
branchoffset, where branchoffset is (branchbyte1 << 8) | branchbyte2. Execution proceeds |
|
1042 |
at that offset from the address of the opcode of this goto instruction. The target |
|
1043 |
address must be that of an opcode of an instruction within the method that contains |
|
1044 |
this goto instruction." |
|
1045 |
||
1046 |
"Created: / 14-03-2011 / 20:21:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1047 |
"Modified: / 21-03-2011 / 18:20:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1048 |
! |
|
1049 |
||
1050 |
goto_w |
|
1051 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1052 |
||
1053 |
^ self shouldImplement |
|
1054 |
! |
|
1055 |
||
1056 |
i2d |
|
1057 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1058 |
||
1059 |
^ self shouldImplement |
|
1060 |
! |
|
1061 |
||
1062 |
i2f |
|
1063 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1064 |
||
1065 |
^ self shouldImplement |
|
1066 |
! |
|
1067 |
||
1068 |
i2l |
|
1069 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1070 |
||
1071 |
^ self shouldImplement |
|
1072 |
! |
|
1073 |
||
1074 |
i_dup |
|
1075 |
self pushInt: (self tos). |
|
1076 |
||
1077 |
"Modified: / 13-03-2011 / 16:40:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1078 |
! |
|
1079 |
||
1080 |
iadd |
|
1081 |
" |
|
1082 |
adds two ints together |
|
1083 |
stack: value1, value2 -> result |
|
1084 |
args: nothing" |
|
1085 |
self pushInt: (self pop + self pop). |
|
1086 |
||
1087 |
" |
|
1088 |
Description |
|
1089 |
Both value1 and value2 must be of type int. The values are popped |
|
1090 |
from the operand stack. The int result is value1 + value2. The result |
|
1091 |
is pushed onto the operand stack. |
|
1092 |
The result is the 32 low-order bits of the true mathematical result |
|
1093 |
in a sufficiently wide two's-complement format, represented as a value |
|
1094 |
of type int. If overflow occurs, then the sign of the result may not be |
|
1095 |
the same as the sign of the mathematical sum of the two values. |
|
1096 |
Despite the fact that overflow may occur, execution of an iadd instruction |
|
1097 |
never throws a runtime exception." |
|
1098 |
||
1099 |
"Created: / 06-03-2011 / 21:23:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1100 |
"Modified: / 13-03-2011 / 21:51:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1101 |
! |
|
1102 |
||
1103 |
iaload |
|
1104 |
" |
|
1105 |
Load int from array |
|
1106 |
stack: arrayRef index -> value |
|
1107 |
args: nothing" |
|
1108 |
||
1109 |
self swap. |
|
1110 |
self pushInt: (self pop at: (self pop + 1)). |
|
1111 |
||
1112 |
" |
|
1113 |
Description |
|
1114 |
The arrayref must be of type reference and must refer to an array whose |
|
1115 |
components are of type int. The index must be of type int. Both arrayref |
|
1116 |
and index are popped from the operand stack. The int value in the |
|
1117 |
component of the array at index is retrieved and pushed onto the operand |
|
1118 |
stack. |
|
1119 |
||
1120 |
Runtime Exceptions |
|
1121 |
If arrayref is null, iaload throws a NullPointerException. |
|
1122 |
Otherwise, if index is not within the bounds of the array referenced by |
|
1123 |
arrayref, the iaload instruction throws an ArrayIndexOutOfBoundsException." |
|
1124 |
||
1125 |
"Modified: / 14-03-2011 / 20:20:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1126 |
! |
|
1127 |
||
1128 |
iand |
|
1129 |
" |
|
1130 |
Boolean AND int |
|
1131 |
stack: val1 val2 -> result |
|
1132 |
args: nothing |
|
1133 |
" |
|
1134 |
self pushInt:(self pop bitAnd: self pop). |
|
1135 |
" |
|
1136 |
Both value1 and value2 must be of type int. They are popped from the |
|
1137 |
operand stack. An int result is calculated by taking the bitwise AND |
|
1138 |
(conjunction) of value1 and value2. The result is pushed onto the |
|
1139 |
operand stack. |
|
1140 |
" |
|
1141 |
||
1142 |
"Created: / 14-03-2011 / 17:10:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1143 |
! |
|
1144 |
||
1145 |
iastore |
|
1146 |
self halt |
|
1147 |
! |
|
1148 |
||
1149 |
iconst: arg |
|
1150 |
self pushInt: arg. |
|
1151 |
||
1152 |
"Created: / 20-03-2011 / 23:35:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1153 |
! |
|
1154 |
||
1155 |
idiv |
|
1156 |
" |
|
1157 |
Divide int |
|
1158 |
stack: value1 value2 -> result |
|
1159 |
args: nothing" |
|
1160 |
self swap. |
|
1161 |
self pushInt: (self pop // self pop). |
|
1162 |
||
1163 |
" |
|
1164 |
Description |
|
1165 |
Both value1 and value2 must be of type int. The values are popped from the operand stack. |
|
1166 |
The int result is the value of the Java programming language expression value1 / value2. |
|
1167 |
The result is pushed onto the operand stack. |
|
1168 |
An int division rounds towards 0; that is, the quotient produced for int values in n/d is |
|
1169 |
an int value q whose magnitude is as large as possible while satisfying . Moreover, q is |
|
1170 |
positive when and n and d have the same sign, but q is negative when and n and d have |
|
1171 |
opposite signs. |
|
1172 |
There is one special case that does not satisfy this rule: if the dividend is the negative |
|
1173 |
integer of largest possible magnitude for the int type, and the divisor is -1, then overflow |
|
1174 |
occurs, and the result is equal to the dividend. Despite the overflow, no exception is thrown |
|
1175 |
in this case. |
|
1176 |
||
1177 |
Runtime Exception |
|
1178 |
If the value of the divisor in an int division is 0, idiv throws an ArithmeticException." |
|
1179 |
||
1180 |
"Created: / 14-03-2011 / 17:50:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1181 |
! |
|
1182 |
||
1183 |
ifacmpeq |
|
1184 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1185 |
||
1186 |
^ self shouldImplement |
|
1187 |
! |
|
1188 |
||
1189 |
ifacmpne |
|
1190 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1191 |
||
1192 |
^ self shouldImplement |
|
1193 |
! |
|
1194 |
||
1195 |
ifeq |
|
1196 |
" |
|
1197 |
if true, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
|
1198 |
stack: value -> nothing |
|
1199 |
args: branchByte1 branchByte2" |
|
1200 |
||
1201 |
| dest | |
|
1202 |
||
1203 |
dest := self fetchBytes2. |
|
1204 |
self pop = 0 ifTrue: [ self relativeJump: dest ]. |
|
1205 |
||
1206 |
" |
|
1207 |
The value must be of type int. It is popped from the operand stack and |
|
1208 |
compared against zero. All comparisons are signed. The results of the |
|
1209 |
comparisons are as follows: |
|
1210 |
eq succeeds if and only if value = 0 |
|
1211 |
ne succeeds if and only if value 0 |
|
1212 |
lt succeeds if and only if value < 0 |
|
1213 |
le succeeds if and only if value 0 |
|
1214 |
gt succeeds if and only if value > 0 |
|
1215 |
ge succeeds if and only if value 0 |
|
1216 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 |
|
1217 |
are used to construct a signed 16-bit offset, where the offset is |
|
1218 |
calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds |
|
1219 |
at that offset from the address of the opcode of this if<cond> instruction. |
|
1220 |
The target address must be that of an opcode of an instruction within the |
|
1221 |
method that contains this if<cond> instruction. |
|
1222 |
Otherwise, execution proceeds at the address of the instruction following |
|
1223 |
this if<cond> instruction." |
|
1224 |
||
1225 |
"Created: / 14-03-2011 / 18:47:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1226 |
"Modified: / 21-03-2011 / 18:20:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1227 |
! |
|
1228 |
||
1229 |
ifge |
|
1230 |
" |
|
1231 |
if true, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
|
1232 |
stack: value -> nothing |
|
1233 |
args: branchByte1 branchByte2" |
|
1234 |
||
1235 |
| dest | |
|
1236 |
||
1237 |
dest := self fetchBytes2. |
|
1238 |
self pop >= 0 ifTrue: [ self relativeJump: dest ]. |
|
1239 |
||
1240 |
" |
|
1241 |
The value must be of type int. It is popped from the operand stack and |
|
1242 |
compared against zero. All comparisons are signed. The results of the |
|
1243 |
comparisons are as follows: |
|
1244 |
eq succeeds if and only if value = 0 |
|
1245 |
ne succeeds if and only if value 0 |
|
1246 |
lt succeeds if and only if value < 0 |
|
1247 |
le succeeds if and only if value 0 |
|
1248 |
gt succeeds if and only if value > 0 |
|
1249 |
ge succeeds if and only if value 0 |
|
1250 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 |
|
1251 |
are used to construct a signed 16-bit offset, where the offset is |
|
1252 |
calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds |
|
1253 |
at that offset from the address of the opcode of this if<cond> instruction. |
|
1254 |
The target address must be that of an opcode of an instruction within the |
|
1255 |
method that contains this if<cond> instruction. |
|
1256 |
Otherwise, execution proceeds at the address of the instruction following |
|
1257 |
this if<cond> instruction." |
|
1258 |
||
1259 |
"Created: / 14-03-2011 / 18:48:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1260 |
"Modified: / 21-03-2011 / 18:20:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1261 |
! |
|
1262 |
||
1263 |
ifgt |
|
1264 |
" |
|
1265 |
if true, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
|
1266 |
stack: value -> nothing |
|
1267 |
args: branchByte1 branchByte2" |
|
1268 |
||
1269 |
| dest | |
|
1270 |
||
1271 |
dest := self fetchBytes2. |
|
1272 |
self pop > 0 ifTrue: [ self relativeJump: dest ]. |
|
1273 |
||
1274 |
" |
|
1275 |
The value must be of type int. It is popped from the operand stack and |
|
1276 |
compared against zero. All comparisons are signed. The results of the |
|
1277 |
comparisons are as follows: |
|
1278 |
eq succeeds if and only if value = 0 |
|
1279 |
ne succeeds if and only if value 0 |
|
1280 |
lt succeeds if and only if value < 0 |
|
1281 |
le succeeds if and only if value 0 |
|
1282 |
gt succeeds if and only if value > 0 |
|
1283 |
ge succeeds if and only if value 0 |
|
1284 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 |
|
1285 |
are used to construct a signed 16-bit offset, where the offset is |
|
1286 |
calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds |
|
1287 |
at that offset from the address of the opcode of this if<cond> instruction. |
|
1288 |
The target address must be that of an opcode of an instruction within the |
|
1289 |
method that contains this if<cond> instruction. |
|
1290 |
Otherwise, execution proceeds at the address of the instruction following |
|
1291 |
this if<cond> instruction." |
|
1292 |
||
1293 |
"Created: / 14-03-2011 / 18:48:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1294 |
"Modified: / 21-03-2011 / 18:20:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1295 |
! |
|
1296 |
||
1297 |
ificmpeq |
|
1298 |
" |
|
1299 |
Branch if int comparison succeeds |
|
1300 |
stack: value1 value2 -> nothing |
|
1301 |
args: branchByte1 branchByte2" |
|
1302 |
||
1303 |
| dest | |
|
1304 |
||
1305 |
dest := self fetchBytes2. |
|
1306 |
(self pop = self pop) ifTrue: [ self relativeJump: dest ]. |
|
1307 |
||
1308 |
" |
|
1309 |
Description |
|
1310 |
Both value1 and value2 must be of type int. They are both popped from |
|
1311 |
the operand stack and compared. All comparisons are signed. The results |
|
1312 |
of the comparison are as follows: |
|
1313 |
eq succeeds if and only if value1 = value2 |
|
1314 |
ne succeeds if and only if value1 ~= value2 |
|
1315 |
lt succeeds if and only if value1 < value2 |
|
1316 |
le succeeds if and only if value1 value2 |
|
1317 |
gt succeeds if and only if value1 > value2 |
|
1318 |
ge succeeds if and only if value1 value2 |
|
1319 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are |
|
1320 |
used to construct a signed 16-bit offset, where the offset is calculated |
|
1321 |
to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that |
|
1322 |
offset from the address of the opcode of this if_icmp<cond> instruction. |
|
1323 |
The target address must be that of an opcode of an instruction within the |
|
1324 |
method that contains this if_icmp<cond> instruction. |
|
1325 |
Otherwise, execution proceeds at the address of the instruction following |
|
1326 |
this if_icmp<cond> instruction." |
|
1327 |
||
1328 |
"Created: / 14-03-2011 / 18:49:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1329 |
"Modified: / 21-03-2011 / 18:20:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1330 |
! |
|
1331 |
||
1332 |
ificmpge |
|
1333 |
" |
|
1334 |
Branch if int comparison succeeds |
|
1335 |
stack: value1 value2 -> nothing |
|
1336 |
args: branchByte1 branchByte2" |
|
1337 |
||
1338 |
| dest | |
|
1339 |
||
1340 |
dest := self fetchBytes2. |
|
1341 |
self swap. |
|
1342 |
(self pop >= self pop) ifTrue: [ self relativeJump: dest ] |
|
1343 |
||
1344 |
" |
|
1345 |
Description |
|
1346 |
Both value1 and value2 must be of type int. They are both popped from |
|
1347 |
the operand stack and compared. All comparisons are signed. The results |
|
1348 |
of the comparison are as follows: |
|
1349 |
eq succeeds if and only if value1 = value2 |
|
1350 |
ne succeeds if and only if value1 ~= value2 |
|
1351 |
lt succeeds if and only if value1 < value2 |
|
1352 |
le succeeds if and only if value1 <= value2 |
|
1353 |
gt succeeds if and only if value1 > value2 |
|
1354 |
ge succeeds if and only if value1 >= value2 |
|
1355 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are |
|
1356 |
used to construct a signed 16-bit offset, where the offset is calculated |
|
1357 |
to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that |
|
1358 |
offset from the address of the opcode of this if_icmp<cond> instruction. |
|
1359 |
The target address must be that of an opcode of an instruction within the |
|
1360 |
method that contains this if_icmp<cond> instruction. |
|
1361 |
Otherwise, execution proceeds at the address of the instruction following |
|
1362 |
this if_icmp<cond> instruction." |
|
1363 |
||
1364 |
"Created: / 14-03-2011 / 18:52:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1365 |
"Modified: / 21-03-2011 / 18:20:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1366 |
! |
|
1367 |
||
1368 |
ificmpgt |
|
1369 |
" |
|
1370 |
Branch if int comparison succeeds |
|
1371 |
stack: value1 value2 -> nothing |
|
1372 |
args: branchByte1 branchByte2" |
|
1373 |
||
1374 |
| dest | |
|
1375 |
||
1376 |
dest := self fetchBytes2. |
|
1377 |
self swap. |
|
1378 |
(self pop > self pop) ifTrue: [ self relativeJump: dest ] |
|
1379 |
||
1380 |
" |
|
1381 |
Description |
|
1382 |
Both value1 and value2 must be of type int. They are both popped from |
|
1383 |
the operand stack and compared. All comparisons are signed. The results |
|
1384 |
of the comparison are as follows: |
|
1385 |
eq succeeds if and only if value1 = value2 |
|
1386 |
ne succeeds if and only if value1 ~= value2 |
|
1387 |
lt succeeds if and only if value1 < value2 |
|
1388 |
le succeeds if and only if value1 <= value2 |
|
1389 |
gt succeeds if and only if value1 > value2 |
|
1390 |
ge succeeds if and only if value1 >= value2 |
|
1391 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are |
|
1392 |
used to construct a signed 16-bit offset, where the offset is calculated |
|
1393 |
to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that |
|
1394 |
offset from the address of the opcode of this if_icmp<cond> instruction. |
|
1395 |
The target address must be that of an opcode of an instruction within the |
|
1396 |
method that contains this if_icmp<cond> instruction. |
|
1397 |
Otherwise, execution proceeds at the address of the instruction following |
|
1398 |
this if_icmp<cond> instruction." |
|
1399 |
||
1400 |
"Created: / 14-03-2011 / 21:00:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1401 |
"Modified: / 21-03-2011 / 18:20:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1402 |
! |
|
1403 |
||
1404 |
ificmple |
|
1405 |
" |
|
1406 |
Branch if int comparison succeeds |
|
1407 |
stack: value1 value2 -> nothing |
|
1408 |
args: branchByte1 branchByte2" |
|
1409 |
||
1410 |
| dest | |
|
1411 |
||
1412 |
dest := self fetchBytes2. |
|
1413 |
self swap. |
|
1414 |
(self pop <= self pop) ifTrue: [ self relativeJump: dest ] |
|
1415 |
||
1416 |
" |
|
1417 |
Description |
|
1418 |
Both value1 and value2 must be of type int. They are both popped from |
|
1419 |
the operand stack and compared. All comparisons are signed. The results |
|
1420 |
of the comparison are as follows: |
|
1421 |
eq succeeds if and only if value1 = value2 |
|
1422 |
ne succeeds if and only if value1 ~= value2 |
|
1423 |
lt succeeds if and only if value1 < value2 |
|
1424 |
le succeeds if and only if value1 <= value2 |
|
1425 |
gt succeeds if and only if value1 > value2 |
|
1426 |
ge succeeds if and only if value1 >= value2 |
|
1427 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are |
|
1428 |
used to construct a signed 16-bit offset, where the offset is calculated |
|
1429 |
to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that |
|
1430 |
offset from the address of the opcode of this if_icmp<cond> instruction. |
|
1431 |
The target address must be that of an opcode of an instruction within the |
|
1432 |
method that contains this if_icmp<cond> instruction. |
|
1433 |
Otherwise, execution proceeds at the address of the instruction following |
|
1434 |
this if_icmp<cond> instruction." |
|
1435 |
||
1436 |
"Created: / 14-03-2011 / 21:00:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1437 |
"Modified: / 21-03-2011 / 18:20:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1438 |
! |
|
1439 |
||
1440 |
ificmplt |
|
1441 |
" |
|
1442 |
Branch if int comparison succeeds |
|
1443 |
stack: value1 value2 -> nothing |
|
1444 |
args: branchByte1 branchByte2" |
|
1445 |
||
1446 |
| dest | |
|
1447 |
||
1448 |
dest := self fetchBytes2. |
|
1449 |
self swap. |
|
1450 |
(self pop < self pop) ifTrue: [ self relativeJump: dest ] |
|
1451 |
||
1452 |
" |
|
1453 |
Description |
|
1454 |
Both value1 and value2 must be of type int. They are both popped from |
|
1455 |
the operand stack and compared. All comparisons are signed. The results |
|
1456 |
of the comparison are as follows: |
|
1457 |
eq succeeds if and only if value1 = value2 |
|
1458 |
ne succeeds if and only if value1 ~= value2 |
|
1459 |
lt succeeds if and only if value1 < value2 |
|
1460 |
le succeeds if and only if value1 <= value2 |
|
1461 |
gt succeeds if and only if value1 > value2 |
|
1462 |
ge succeeds if and only if value1 >= value2 |
|
1463 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are |
|
1464 |
used to construct a signed 16-bit offset, where the offset is calculated |
|
1465 |
to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that |
|
1466 |
offset from the address of the opcode of this if_icmp<cond> instruction. |
|
1467 |
The target address must be that of an opcode of an instruction within the |
|
1468 |
method that contains this if_icmp<cond> instruction. |
|
1469 |
Otherwise, execution proceeds at the address of the instruction following |
|
1470 |
this if_icmp<cond> instruction." |
|
1471 |
||
1472 |
"Created: / 14-03-2011 / 21:00:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1473 |
"Modified: / 21-03-2011 / 18:20:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1474 |
! |
|
1475 |
||
1476 |
ificmpne |
|
1477 |
" |
|
1478 |
Branch if int comparison succeeds |
|
1479 |
stack: value1 value2 -> nothing |
|
1480 |
args: branchByte1 branchByte2" |
|
1481 |
||
1482 |
| dest | |
|
1483 |
||
1484 |
dest := self fetchBytes2. |
|
1485 |
(self pop ~= self pop) ifTrue: [ self relativeJump: dest ]. |
|
1486 |
||
1487 |
" |
|
1488 |
Description |
|
1489 |
Both value1 and value2 must be of type int. They are both popped from |
|
1490 |
the operand stack and compared. All comparisons are signed. The results |
|
1491 |
of the comparison are as follows: |
|
1492 |
eq succeeds if and only if value1 = value2 |
|
1493 |
ne succeeds if and only if value1 ~= value2 |
|
1494 |
lt succeeds if and only if value1 < value2 |
|
1495 |
le succeeds if and only if value1 value2 |
|
1496 |
gt succeeds if and only if value1 > value2 |
|
1497 |
ge succeeds if and only if value1 value2 |
|
1498 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are |
|
1499 |
used to construct a signed 16-bit offset, where the offset is calculated |
|
1500 |
to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that |
|
1501 |
offset from the address of the opcode of this if_icmp<cond> instruction. |
|
1502 |
The target address must be that of an opcode of an instruction within the |
|
1503 |
method that contains this if_icmp<cond> instruction. |
|
1504 |
Otherwise, execution proceeds at the address of the instruction following |
|
1505 |
this if_icmp<cond> instruction." |
|
1506 |
||
1507 |
"Created: / 14-03-2011 / 20:59:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1508 |
"Modified: / 21-03-2011 / 18:20:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1509 |
! |
|
1510 |
||
1511 |
ifle |
|
1512 |
" |
|
1513 |
if true, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
|
1514 |
stack: value -> nothing |
|
1515 |
args: branchByte1 branchByte2" |
|
1516 |
||
1517 |
| dest | |
|
1518 |
||
1519 |
dest := self fetchBytes2. |
|
1520 |
self pop <= 0 ifTrue: [ self relativeJump: dest ]. |
|
1521 |
||
1522 |
" |
|
1523 |
The value must be of type int. It is popped from the operand stack and |
|
1524 |
compared against zero. All comparisons are signed. The results of the |
|
1525 |
comparisons are as follows: |
|
1526 |
eq succeeds if and only if value = 0 |
|
1527 |
ne succeeds if and only if value 0 |
|
1528 |
lt succeeds if and only if value < 0 |
|
1529 |
le succeeds if and only if value 0 |
|
1530 |
gt succeeds if and only if value > 0 |
|
1531 |
ge succeeds if and only if value 0 |
|
1532 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 |
|
1533 |
are used to construct a signed 16-bit offset, where the offset is |
|
1534 |
calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds |
|
1535 |
at that offset from the address of the opcode of this if<cond> instruction. |
|
1536 |
The target address must be that of an opcode of an instruction within the |
|
1537 |
method that contains this if<cond> instruction. |
|
1538 |
Otherwise, execution proceeds at the address of the instruction following |
|
1539 |
this if<cond> instruction." |
|
1540 |
||
1541 |
"Created: / 14-03-2011 / 18:48:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1542 |
"Modified: / 21-03-2011 / 18:20:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1543 |
! |
|
1544 |
||
1545 |
iflt |
|
1546 |
" |
|
1547 |
if true, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
|
1548 |
stack: value -> nothing |
|
1549 |
args: branchByte1 branchByte2" |
|
1550 |
||
1551 |
| dest | |
|
1552 |
||
1553 |
dest := self fetchBytes2. |
|
1554 |
self pop < 0 ifTrue: [ self relativeJump: dest ]. |
|
1555 |
||
1556 |
" |
|
1557 |
The value must be of type int. It is popped from the operand stack and |
|
1558 |
compared against zero. All comparisons are signed. The results of the |
|
1559 |
comparisons are as follows: |
|
1560 |
eq succeeds if and only if value = 0 |
|
1561 |
ne succeeds if and only if value 0 |
|
1562 |
lt succeeds if and only if value < 0 |
|
1563 |
le succeeds if and only if value 0 |
|
1564 |
gt succeeds if and only if value > 0 |
|
1565 |
ge succeeds if and only if value 0 |
|
1566 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 |
|
1567 |
are used to construct a signed 16-bit offset, where the offset is |
|
1568 |
calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds |
|
1569 |
at that offset from the address of the opcode of this if<cond> instruction. |
|
1570 |
The target address must be that of an opcode of an instruction within the |
|
1571 |
method that contains this if<cond> instruction. |
|
1572 |
Otherwise, execution proceeds at the address of the instruction following |
|
1573 |
this if<cond> instruction." |
|
1574 |
||
1575 |
"Created: / 14-03-2011 / 18:47:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1576 |
"Modified: / 21-03-2011 / 18:20:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1577 |
! |
|
1578 |
||
1579 |
ifne |
|
1580 |
" |
|
1581 |
if value is not 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
|
1582 |
stack: value -> nothing |
|
1583 |
args: branchByte1 branchByte2" |
|
1584 |
"/ -1 in block - because we already increased pc to point to the next instruction |
|
1585 |
||
1586 |
| dest | |
|
1587 |
||
1588 |
dest := self fetchBytes2. |
|
1589 |
self pop ~= 0 ifTrue: [ self relativeJump: dest ]. |
|
1590 |
||
1591 |
" |
|
1592 |
The value must be of type int. It is popped from the operand stack and |
|
1593 |
compared against zero. All comparisons are signed. The results of the |
|
1594 |
comparisons are as follows: |
|
1595 |
eq succeeds if and only if value = 0 |
|
1596 |
ne succeeds if and only if value ~= 0 |
|
1597 |
lt succeeds if and only if value < 0 |
|
1598 |
le succeeds if and only if value <= 0 |
|
1599 |
gt succeeds if and only if value > 0 |
|
1600 |
ge succeeds if and only if value >= 0 |
|
1601 |
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 |
|
1602 |
are used to construct a signed 16-bit offset, where the offset is |
|
1603 |
calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds |
|
1604 |
at that offset from the address of the opcode of this if<cond> instruction. |
|
1605 |
The target address must be that of an opcode of an instruction within the |
|
1606 |
method that contains this if<cond> instruction. |
|
1607 |
Otherwise, execution proceeds at the address of the instruction following |
|
1608 |
this if<cond> instruction." |
|
1609 |
||
1610 |
"Created: / 06-03-2011 / 22:57:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1611 |
"Modified: / 21-03-2011 / 18:20:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1612 |
! |
|
1613 |
||
1614 |
ifnonnull |
|
1615 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1616 |
||
1617 |
^ self shouldImplement |
|
1618 |
! |
|
1619 |
||
1620 |
ifnull |
|
1621 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1622 |
||
1623 |
^ self shouldImplement |
|
1624 |
! |
|
1625 |
||
1626 |
iinc |
|
1627 |
" |
|
1628 |
Increment local variable by constant |
|
1629 |
stack: nothing -> nothing |
|
1630 |
args: index const |
|
1631 |
" |
|
1632 |
| index const | |
|
1633 |
||
1634 |
index := self fetchIndex. |
|
1635 |
const := self fetchByte. |
|
1636 |
context at: index + 1 put: ((context at: index + 1) + const). |
|
1637 |
" |
|
1638 |
Description |
|
1639 |
The index is an unsigned byte that must be an index into the local variable |
|
1640 |
array of the current frame (§3.6). The const is an immediate signed byte. |
|
1641 |
The local variable at index must contain an int. The value const is first |
|
1642 |
sign-extended to an int, and then the local variable at index is incremented |
|
1643 |
by that amount. |
|
1644 |
||
1645 |
Notes |
|
1646 |
The iinc opcode can be used in conjunction with the wide instruction to access |
|
1647 |
a local variable using a two-byte unsigned index and to increment it by a two-byte |
|
1648 |
immediate value. |
|
1649 |
" |
|
1650 |
||
1651 |
"Created: / 14-03-2011 / 17:22:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1652 |
! |
|
1653 |
||
1654 |
iload |
|
1655 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1656 |
||
1657 |
^ self shouldImplement |
|
1658 |
! |
|
1659 |
||
1660 |
iload: idx |
|
1661 |
" |
|
1662 |
loads an int value from a local variable #index |
|
1663 |
stack: nothing -> value |
|
1664 |
args: index" |
|
1665 |
||
1666 |
self pushInt: (context at: idx + 1). |
|
1667 |
||
1668 |
" |
|
1669 |
The index is an unsigned byte that must be an index into the local variable array |
|
1670 |
of the current frame (§3.6). The local variable at index must contain an int. |
|
1671 |
The value of the local variable at index is pushed onto the operand stack. |
|
1672 |
||
1673 |
Notes |
|
1674 |
The iload opcode can be used in conjunction with the wide instruction to |
|
1675 |
access a local variable using a two-byte unsigned index." |
|
1676 |
||
1677 |
"Modified: / 17-03-2011 / 17:33:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1678 |
! |
|
1679 |
||
1680 |
imul |
|
1681 |
"multiply two integers |
|
1682 |
stack: value1, value2 -> result |
|
1683 |
args: nothing" |
|
1684 |
||
1685 |
self pushInt: (self pop * self pop). |
|
1686 |
||
1687 |
" |
|
1688 |
Both value1 and value2 must be of type int. The values are popped |
|
1689 |
from the operand stack. The int result is value1 * value2. The result |
|
1690 |
is pushed onto the operand stack. |
|
1691 |
The result is the 32 low-order bits of the true mathematical result |
|
1692 |
in a sufficiently wide two's-complement format, represented as a value |
|
1693 |
of type int. If overflow occurs, then the sign of the result may not |
|
1694 |
be the same as the sign of the mathematical sum of the two values. |
|
1695 |
Despite the fact that overflow may occur, execution of an imul |
|
1696 |
instruction never throws a runtime exception." |
|
1697 |
||
1698 |
"Created: / 06-03-2011 / 22:42:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1699 |
"Modified: / 13-03-2011 / 17:24:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1700 |
! |
|
1701 |
||
1702 |
ineg |
|
1703 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1704 |
||
1705 |
^ self shouldImplement |
|
1706 |
! |
|
1707 |
||
1708 |
instanceof |
|
1709 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1710 |
||
1711 |
^ self shouldImplement |
|
1712 |
! |
|
1713 |
||
1714 |
int2byte |
|
1715 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1716 |
||
1717 |
^ self shouldImplement |
|
1718 |
! |
|
1719 |
||
1720 |
int2char |
|
1721 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1722 |
||
1723 |
^ self shouldImplement |
|
1724 |
! |
|
1725 |
||
1726 |
int2short |
|
1727 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1728 |
||
1729 |
^ self shouldImplement |
|
1730 |
! |
|
1731 |
||
1732 |
invinterface |
|
1733 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1734 |
||
1735 |
^ self shouldImplement |
|
1736 |
! |
|
1737 |
||
1738 |
invnonvirt |
|
1739 |
" |
|
1740 |
Invoke instance method; special handling for superclass, private, and instance initialization method invocations |
|
1741 |
stack: objRef [args] -> .. |
|
1742 |
args: indexByte1 indexByte2" |
|
1743 |
||
1744 |
| methodToBeInvoked methodReceiver methodNumArgs methodArgs result | |
|
1745 |
||
1746 |
methodToBeInvoked := constantPool at: self fetchIndex2. |
|
1747 |
methodReceiver := self pop. |
|
1748 |
methodNumArgs := methodToBeInvoked javaNumArgs. |
|
1749 |
methodArgs := Array new: methodNumArgs. |
|
1750 |
methodNumArgs to: 1 |
|
1751 |
by: -1 |
|
1752 |
do: [:index | methodArgs at: index put: self pop ]. |
|
1753 |
result := self |
|
1754 |
interpretInner: methodToBeInvoked |
|
1755 |
receiver: methodReceiver |
|
1756 |
arguments: methodArgs. |
|
1757 |
self pushRef: result. |
|
1758 |
||
1759 |
" |
|
1760 |
Description |
|
1761 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool |
|
1762 |
of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The |
|
1763 |
runtime constant pool item at that index must be a symbolic reference to a method (§5.1), which gives |
|
1764 |
the name and descriptor (§4.3.3) of the method as well as a symbolic reference to the class in which |
|
1765 |
the method is to be found. The named method is resolved (§5.4.3.3). Finally, if the resolved method |
|
1766 |
is protected (§4.6), and it is either a member of the current class or a member of a superclass of |
|
1767 |
the current class, then the class of objectref must be either the current class or a subclass of the |
|
1768 |
current class. |
|
1769 |
Next, the resolved method is selected for invocation unless all of the following conditions are true: |
|
1770 |
The ACC_SUPER flag (see Table 4.1, Class access and property modifiers) is set for the current class. |
|
1771 |
The class of the resolved method is a superclass of the current class. |
|
1772 |
The resolved method is not an instance initialization method (§3.9). |
|
1773 |
If the above conditions are true, the actual method to be invoked is selected by the following lookup |
|
1774 |
procedure. Let C be the direct superclass of the current class: |
|
1775 |
If C contains a declaration for an instance method with the same name and descriptor as the resolved |
|
1776 |
method, then this method will be invoked. The lookup procedure terminates. |
|
1777 |
Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct |
|
1778 |
superclass of C. The method to be invoked is the result of the recursive invocation of this lookup |
|
1779 |
procedure. |
|
1780 |
Otherwise, an AbstractMethodError is raised. |
|
1781 |
The objectref must be of type reference and must be followed on the operand stack by nargs argument |
|
1782 |
values, where the number, type, and order of the values must be consistent with the descriptor of the |
|
1783 |
selected instance method. |
|
1784 |
If the method is synchronized, the monitor associated with objectref is acquired or reentered. |
|
1785 |
If the method is not native, the nargs argument values and objectref are popped from the operand stack. |
|
1786 |
A new frame is created on the Java virtual machine stack for the method being invoked. The objectref |
|
1787 |
and the argument values are consecutively made the values of local variables of the new frame, with |
|
1788 |
objectref in local variable 0, arg1 in local variable 1 (or, if arg1 is of type long or double, in |
|
1789 |
local variables 1 and 2), and so on. Any argument value that is of a floating-point type undergoes |
|
1790 |
value set conversion (§3.8.3) prior to being stored in a local variable. The new frame is then made |
|
1791 |
current, and the Java virtual machine pc is set to the opcode of the first instruction of the method |
|
1792 |
to be invoked. Execution continues with the first instruction of the method. |
|
1793 |
If the method is native and the platform-dependent code that implements it has not yet been bound (§5.6) |
|
1794 |
into the Java virtual machine, that is done. The nargs argument values and objectref are popped from |
|
1795 |
the operand stack and are passed as parameters to the code that implements the method. Any argument |
|
1796 |
value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being passed |
|
1797 |
as a parameter. The parameters are passed and the code is invoked in an implementation-dependent |
|
1798 |
manner. When the platform-dependent code returns, the following take place: |
|
1799 |
If the native method is synchronized, the monitor associated with objectref is released or exited as |
|
1800 |
if by execution of a monitorexit instruction. |
|
1801 |
If the native method returns a value, the return value of the platform-dependent code is converted in |
|
1802 |
an implementation-dependent way to the return type of the native method and pushed onto the operand stack. |
|
1803 |
Linking Exceptions |
|
1804 |
During resolution of the symbolic reference to the method, any of the exceptions pertaining to method |
|
1805 |
resolution documented in Section 5.4.3.3 can be thrown. |
|
1806 |
Otherwise, if the resolved method is an instance initialization method, and the class in which it is |
|
1807 |
declared is not the class symbolically referenced by the instruction, a NoSuchMethodError is thrown. |
|
1808 |
Otherwise, if the resolved method is a class (static) method, the invokespecial instruction throws an |
|
1809 |
IncompatibleClassChangeError. |
|
1810 |
Otherwise, if no method matching the resolved name and descriptor is selected, invokespecial throws |
|
1811 |
an AbstractMethodError. |
|
1812 |
Otherwise, if the selected method is abstract, invokespecial throws an AbstractMethodError. |
|
1813 |
||
1814 |
Runtime Exceptions |
|
1815 |
Otherwise, if objectref is null, the invokespecial instruction throws a NullPointerException. |
|
1816 |
Otherwise, if the selected method is native and the code that implements the method cannot be bound, |
|
1817 |
invokespecial throws an UnsatisfiedLinkError. |
|
1818 |
||
1819 |
Notes |
|
1820 |
The difference between the invokespecial and the invokevirtual instructions is that invokevirtual |
|
1821 |
invokes a method based on the class of the object. The invokespecial instruction is used to invoke |
|
1822 |
instance initialization methods (§3.9) as well as private methods and methods of a superclass of |
|
1823 |
the current class. |
|
1824 |
The invokespecial instruction was named invokenonvirtual prior to Sun's JDK release 1.0.2. |
|
1825 |
The nargs argument values and objectref are not one-to-one with the first nargs + 1 local variables. |
|
1826 |
Argument values of types long and double must be stored in two consecutive local variables, thus more |
|
1827 |
than nargs local variables may be required to pass nargs argument values to the invoked method." |
|
1828 |
||
1829 |
"Modified: / 31-03-2011 / 16:34:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1830 |
! |
|
1831 |
||
1832 |
invstatic |
|
1833 |
" |
|
1834 |
Invoke a class (static) method |
|
1835 |
stack: [arg1 [args2 ...]] -> nothing |
|
1836 |
args: indexByte1 indexByte2" |
|
1837 |
||
1838 |
| methodToBeInvoked methodNumArgs args argSignatures result | |
|
1839 |
||
1840 |
methodToBeInvoked := (constantPool at: self fetchIndex2) resolve. |
|
1841 |
methodToBeInvoked ifNil: [self halt]. |
|
1842 |
methodNumArgs := methodToBeInvoked javaNumArgs. |
|
1843 |
argSignatures := methodToBeInvoked argSignature. |
|
1844 |
args := Array new: methodNumArgs. |
|
1845 |
methodNumArgs to: 1 by: -1 do: [ |
|
1846 |
:index | |
|
1847 |
args at: index put: self pop |
|
1848 |
]. |
|
1849 |
result := self |
|
1850 |
interpretInner: methodToBeInvoked |
|
1851 |
receiver: receiver |
|
1852 |
arguments: args. |
|
1853 |
methodToBeInvoked returnsVoid ifFalse: [ |
|
1854 |
self pushConstant: result |
|
1855 |
]. |
|
1856 |
||
1857 |
" |
|
1858 |
Description |
|
1859 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the |
|
1860 |
runtime constant pool of the current class (§3.6), where the value of the index is |
|
1861 |
(indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must |
|
1862 |
be a symbolic reference to a method (§5.1), which gives the name and descriptor (§4.3.3) |
|
1863 |
of the method as well as a symbolic reference to the class in which the method is to |
|
1864 |
be found. The named method is resolved (§5.4.3.3). The method must not be the class |
|
1865 |
or interface initialization method (§3.9). It must be static, and therefore cannot be |
|
1866 |
abstract. |
|
1867 |
On successful resolution of the method, the class that declared the resolved field is |
|
1868 |
initialized (§5.5) if that class has not already been initialized. |
|
1869 |
The operand stack must contain nargs argument values, where the number, type, and order |
|
1870 |
of the values must be consistent with the descriptor of the resolved method. |
|
1871 |
If the method is synchronized, the monitor associated with the resolved class is acquired |
|
1872 |
or reentered. |
|
1873 |
If the method is not native, the nargs argument values are popped from the operand stack. |
|
1874 |
A new frame is created on the Java virtual machine stack for the method being invoked. |
|
1875 |
The nargs argument values are consecutively made the values of local variables of the |
|
1876 |
new frame, with arg1 in local variable 0 (or, if arg1 is of type long or double, in local |
|
1877 |
variables 0 and 1) and so on. Any argument value that is of a floating-point type undergoes |
|
1878 |
value set conversion (§3.8.3) prior to being stored in a local variable. The new frame is |
|
1879 |
then made current, and the Java virtual machine pc is set to the opcode of the first |
|
1880 |
nstruction of the method to be invoked. Execution continues with the first instruction |
|
1881 |
of the method. |
|
1882 |
If the method is native and the platform-dependent code that implements it has not yet |
|
1883 |
been bound (§5.6) into the Java virtual machine, that is done. The nargs argument values |
|
1884 |
are popped from the operand stack and are passed as parameters to the code that |
|
1885 |
implements the method. Any argument value that is of a floating-point type undergoes |
|
1886 |
value set conversion (§3.8.3) prior to being passed as a parameter. The parameters are |
|
1887 |
passed and the code is invoked in an implementation-dependent manner. When the |
|
1888 |
platform-dependent code returns, the following take place: |
|
1889 |
If the native method is synchronized, the monitor associated with the resolved class |
|
1890 |
is released or exited as if by execution of a monitorexit instruction. |
|
1891 |
If the native method returns a value, the return value of the platform-dependent code |
|
1892 |
is converted in an implementation-dependent way to the return type of the native |
|
1893 |
method and pushed onto the operand stack. |
|
1894 |
Linking Exceptions |
|
1895 |
During resolution of the symbolic reference to the method, any of the exceptions |
|
1896 |
pertaining to method resolution documented in Section 5.4.3.3 can be thrown. |
|
1897 |
Otherwise, if the resolved method is an instance method, the invokestatic instruction |
|
1898 |
throws an IncompatibleClassChangeError. |
|
1899 |
||
1900 |
Runtime Exceptions |
|
1901 |
Otherwise, if execution of this invokestatic instruction causes initialization of the |
|
1902 |
referenced class, invokestatic may throw an Error as detailed in Section 2.17.5. |
|
1903 |
Otherwise, if the resolved method is native and the code that implements the method |
|
1904 |
cannot be bound, invokestatic throws an UnsatisfiedLinkError. |
|
1905 |
||
1906 |
Notes |
|
1907 |
The nargs argument values are not one-to-one with the first nargs local variables. |
|
1908 |
Argument values of types long and double must be stored in two consecutive local variables, |
|
1909 |
thus more than nargs local variables may be required to pass nargs argument values to |
|
1910 |
the invoked method." |
|
1911 |
||
1912 |
"Created: / 24-02-2011 / 10:37:05 / Marcel Hlopko <hlopik@gmail.com>" |
|
1913 |
"Modified: / 25-02-2011 / 00:18:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
1914 |
"Modified: / 24-02-2011 / 22:13:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1915 |
"Modified: / 04-06-2011 / 18:13:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1916 |
! |
|
1917 |
||
1918 |
invvirt |
|
1919 |
" |
|
1920 |
Invoke instance method; dispatch based on class |
|
1921 |
stack: objRef args -> .. |
|
1922 |
args: indexByte1 indexByte2" |
|
1923 |
||
1924 |
| methodOwner methodRef resolvedMethod methodNumArgs args result | |
|
1925 |
||
1926 |
methodRef := constantPool at: self fetchIndex2. |
|
1927 |
methodOwner := self pop. |
|
1928 |
resolvedMethod := methodRef resolve. |
|
1929 |
methodNumArgs := resolvedMethod javaNumArgs. |
|
1930 |
args := Array new: methodNumArgs. |
|
1931 |
methodNumArgs to: 1 by: -1 do: [ |
|
1932 |
:index | |
|
1933 |
args at: index put: self pop |
|
1934 |
]. |
|
1935 |
result := self |
|
1936 |
interpretInner: (methodOwner class lookupMethodFor: resolvedMethod selector) |
|
1937 |
receiver: methodOwner |
|
1938 |
arguments: args. |
|
1939 |
resolvedMethod returnsVoid ifFalse: [ |
|
1940 |
self pushConstant: result |
|
1941 |
]. |
|
1942 |
||
1943 |
" |
|
1944 |
Description |
|
1945 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the |
|
1946 |
runtime constant pool of the current class (§3.6), where the value of the index |
|
1947 |
is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index |
|
1948 |
must be a symbolic reference to a method (§5.1), which gives the name and descriptor |
|
1949 |
(§4.3.3) of the method as well as a symbolic reference to the class in which the |
|
1950 |
method is to be found. The named method is resolved (§5.4.3.3). The method must |
|
1951 |
not be an instance initialization method (§3.9) or the class or interface |
|
1952 |
initialization method (§3.9). Finally, if the resolved method is protected (§4.6), |
|
1953 |
and it is either a member of the current class or a member of a superclass of the |
|
1954 |
current class, then the class of objectref must be either the current class or a |
|
1955 |
subclass of the current class. |
|
1956 |
Let C be the class of objectref. The actual method to be invoked is selected by |
|
1957 |
the following lookup procedure: |
|
1958 |
If C contains a declaration for an instance method with the same name and descriptor |
|
1959 |
as the resolved method, and the resolved method is accessible from C, then this is |
|
1960 |
the method to be invoked, and the lookup procedure terminates. |
|
1961 |
Otherwise, if C has a superclass, this same lookup procedure is performed recursively |
|
1962 |
using the direct superclass of C ; the method to be invoked is the result of the |
|
1963 |
recursive invocation of this lookup procedure. |
|
1964 |
Otherwise, an AbstractMethodError is raised. |
|
1965 |
The objectref must be followed on the operand stack by nargs argument values, |
|
1966 |
where the number, type, and order of the values must be consistent with the descriptor |
|
1967 |
of the selected instance method. |
|
1968 |
If the method is synchronized, the monitor associated with objectref is acquired or |
|
1969 |
reentered. |
|
1970 |
If the method is not native, the nargs argument values and objectref are popped from |
|
1971 |
the operand stack. A new frame is created on the Java virtual machine stack for the |
|
1972 |
method being invoked. The objectref and the argument values are consecutively made |
|
1973 |
the values of local variables of the new frame, with objectref in local variable 0, |
|
1974 |
arg1 in local variable 1 (or, if arg1 is of type long or double, in local variables 1 |
|
1975 |
and 2), and so on. Any argument value that is of a floating-point type undergoes |
|
1976 |
value set conversion (§3.8.3) prior to being stored in a local variable. The new |
|
1977 |
frame is then made current, and the Java virtual machine pc is set to the opcode |
|
1978 |
of the first instruction of the method to be invoked. Execution continues with the |
|
1979 |
first instruction of the method. |
|
1980 |
If the method is native and the platform-dependent code that implements it has not |
|
1981 |
yet been bound (§5.6) into the Java virtual machine, that is done. The nargs argument |
|
1982 |
values and objectref are popped from the operand stack and are passed as parameters |
|
1983 |
to the code that implements the method. Any argument value that is of a floating-point |
|
1984 |
type undergoes value set conversion (§3.8.3) prior to being passed as a parameter. The |
|
1985 |
parameters are passed and the code is invoked in an implementation-dependent manner. |
|
1986 |
When the platform-dependent code returns, the following take place: |
|
1987 |
If the native method is synchronized, the monitor associated with objectref is released |
|
1988 |
or exited as if by execution of a monitorexit instruction. |
|
1989 |
If the native method returns a value, the return value of the platform-dependent code |
|
1990 |
is converted in an implementation-dependent way to the return type of the native method |
|
1991 |
and pushed onto the operand stack. |
|
1992 |
Linking Exceptions |
|
1993 |
During resolution of the symbolic reference to the method, any of the exceptions |
|
1994 |
pertaining to method resolution documented in Section 5.4.3.3 can be thrown. |
|
1995 |
Otherwise, if the resolved method is a class (static) method, the invokevirtual instruction |
|
1996 |
throws an IncompatibleClassChangeError. |
|
1997 |
||
1998 |
Runtime Exceptions |
|
1999 |
Otherwise, if objectref is null, the invokevirtual instruction throws a NullPointerException. |
|
2000 |
Otherwise, if no method matching the resolved name and descriptor is selected, invokevirtual |
|
2001 |
throws an AbstractMethodError. |
|
2002 |
Otherwise, if the selected method is abstract, invokevirtual throws an AbstractMethodError. |
|
2003 |
Otherwise, if the selected method is native and the code that implements the method cannot |
|
2004 |
be bound, invokevirtual throws an UnsatisfiedLinkError. |
|
2005 |
||
2006 |
Notes |
|
2007 |
The nargs argument values and objectref are not one-to-one with the first nargs + 1 local |
|
2008 |
variables. Argument values of types long and double must be stored in two consecutive local |
|
2009 |
variables, thus more than nargs local variables may be required to pass nargs argument |
|
2010 |
values to the invoked method." |
|
2011 |
||
2012 |
"Modified: / 04-06-2011 / 18:13:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2013 |
! |
|
2014 |
||
2015 |
ior |
|
2016 |
" |
|
2017 |
Boolean OR int |
|
2018 |
stack: val1 val2 -> result |
|
2019 |
args: nothing" |
|
2020 |
||
2021 |
self pushInt: (self pop bitOr: self pop). |
|
2022 |
||
2023 |
" |
|
2024 |
Description |
|
2025 |
Both value1 and value2 must be of type int. They are popped from the operand stack. |
|
2026 |
An int result is calculated by taking the bitwise inclusive OR of value1 and value2. |
|
2027 |
The result is pushed onto the operand stack. |
|
2028 |
" |
|
2029 |
||
2030 |
"Created: / 14-03-2011 / 18:20:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2031 |
! |
|
2032 |
||
2033 |
irem |
|
2034 |
" |
|
2035 |
Remainder int |
|
2036 |
stack: value1 value2 -> result |
|
2037 |
args: nothing" |
|
2038 |
||
2039 |
| value1 value2 | |
|
2040 |
||
2041 |
value2 := self pop. |
|
2042 |
value1 := self pop. |
|
2043 |
self pushInt: (value1 - ((value1 // value2) * value2)). |
|
2044 |
||
2045 |
" |
|
2046 |
Description |
|
2047 |
Both value1 and value2 must be of type int. The values are popped from the operand stack. |
|
2048 |
The int result is value1 - (value1 / value2) * value2. The result is pushed onto the |
|
2049 |
operand stack. |
|
2050 |
The result of the irem instruction is such that (a/b)*b + (a%b) is equal to a. This identity |
|
2051 |
holds even in the special case in which the dividend is the negative int of largest possible |
|
2052 |
magnitude for its type and the divisor is -1 (the remainder is 0). It follows from this rule |
|
2053 |
that the result of the remainder operation can be negative only if the dividend is negative |
|
2054 |
and can be positive only if the dividend is positive. Moreover, the magnitude of the result |
|
2055 |
is always less than the magnitude of the divisor. |
|
2056 |
||
2057 |
Runtime Exception |
|
2058 |
If the value of the divisor for an int remainder operator is 0, irem throws an ArithmeticException." |
|
2059 |
||
2060 |
"Modified: / 14-03-2011 / 17:32:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2061 |
! |
|
2062 |
||
2063 |
ireturn |
|
2064 |
" |
|
2065 |
Return int from method |
|
2066 |
stack: value -> nothing |
|
2067 |
args: nothing" |
|
2068 |
||
2069 |
self leaveProcessorWith: (self pop). |
|
2070 |
||
2071 |
" |
|
2072 |
Description |
|
2073 |
The current method must have return type boolean, byte, short, |
|
2074 |
char, or int. The value must be of type int. If the current method |
|
2075 |
is a synchronized method, the monitor acquired or reentered on |
|
2076 |
invocation of the method is released or exited (respectively) as |
|
2077 |
if by execution of a monitorexit instruction. If no exception is |
|
2078 |
thrown, value is popped from the operand stack of the current frame |
|
2079 |
(§3.6) and pushed onto the operand stack of the frame of the invoker. |
|
2080 |
Any other values on the operand stack of the current method are discarded. |
|
2081 |
The interpreter then returns control to the invoker of the method, |
|
2082 |
reinstating the frame of the invoker. |
|
2083 |
||
2084 |
Runtime Exceptions |
|
2085 |
If the current method is a synchronized method and the current thread |
|
2086 |
is not the owner of the monitor acquired or reentered on invocation of |
|
2087 |
the method, ireturn throws an IllegalMonitorStateException. This can |
|
2088 |
happen, for example, if a synchronized method contains a monitorexit |
|
2089 |
instruction, but no monitorenter instruction, on the object on which |
|
2090 |
the method is synchronized. |
|
2091 |
Otherwise, if the virtual machine implementation enforces the rules |
|
2092 |
on structured use of locks described in Section 8.13 and if the first |
|
2093 |
of those rules is violated during invocation of the current method, |
|
2094 |
then ireturn throws an IllegalMonitorStateException." |
|
2095 |
"Created: / 06-03-2011 / 21:24:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2096 |
"Modified: / 13-03-2011 / 17:42:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2097 |
! |
|
2098 |
||
2099 |
ishl |
|
2100 |
" |
|
2101 |
Shift left int |
|
2102 |
stack: val1 val2 -> result |
|
2103 |
args: nothing" |
|
2104 |
||
2105 |
self swap. |
|
2106 |
self pushInt: (self pop bitShift32: self pop). |
|
2107 |
||
2108 |
" |
|
2109 |
Description |
|
2110 |
Both value1 and value2 must be of type int. The values are popped from the operand |
|
2111 |
stack. An int result is calculated by shifting value1 left by s bit positions, where |
|
2112 |
s is the value of the low 5 bits of value2. The result is pushed onto the operand stack. |
|
2113 |
||
2114 |
Notes |
|
2115 |
This is equivalent (even if overflow occurs) to multiplication by 2 to the power s. |
|
2116 |
The shift distance actually used is always in the range 0 to 31, inclusive, as if |
|
2117 |
value2 were subjected to a bitwise logical AND with the mask value 0x1f." |
|
2118 |
||
2119 |
"Created: / 14-03-2011 / 17:12:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2120 |
"Modified: / 14-03-2011 / 19:01:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2121 |
! |
|
2122 |
||
2123 |
ishr |
|
2124 |
" |
|
2125 |
Shift right int |
|
2126 |
stack: val1 val2 -> result |
|
2127 |
args: nothing" |
|
2128 |
||
2129 |
self swap. |
|
2130 |
self pushInt: (self pop rightShift: (self pop bitAnd: 2r11111)). |
|
2131 |
||
2132 |
" |
|
2133 |
Description |
|
2134 |
Both value1 and value2 must be of type int. The values are popped from the operand |
|
2135 |
stack. An int result is calculated by shifting value1 right by s bit positions, |
|
2136 |
with sign extension, where s is the value of the low 5 bits of value2. The result |
|
2137 |
is pushed onto the operand stack. |
|
2138 |
||
2139 |
Notes |
|
2140 |
The resulting value is , where s is value2 & 0x1f. For nonnegative value1, this |
|
2141 |
is equivalent to truncating int division by 2 to the power s. The shift distance |
|
2142 |
actually used is always in the range 0 to 31, inclusive, as if value2 were |
|
2143 |
subjected to a bitwise logical AND with the mask value 0x1f." |
|
2144 |
||
2145 |
"Created: / 14-03-2011 / 17:19:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2146 |
! |
|
2147 |
||
2148 |
istore |
|
2149 |
"superclass JavaByteCodeProcessor says that I am responsible to implement this method" |
|
2150 |
||
2151 |
^ self shouldImplement |
|
2152 |
! |
|
2153 |
||
2154 |
istore: idx |
|
2155 |
"store int value into variable #index |
|
2156 |
stack: value -> nothing |
|
2157 |
args: index" |
|
2158 |
||
2159 |
context at: (idx + 1) put: (self pop). |
|
2160 |
||
2161 |
" |
|
2162 |
Description |
|
2163 |
The index is an unsigned byte that must be an index into the local variable |
|
2164 |
array of the current frame (§3.6). The value on the top of the operand stack |
|
2165 |
must be of type int. It is popped from the operand stack, and the value of |
|
2166 |
the local variable at index is set to value. |
|
2167 |
||
2168 |
Notes |
|
2169 |
The istore opcode can be used in conjunction with the wide instruction to |
|
2170 |
access a local variable using a two-byte unsigned index." |
|
2171 |
||
2172 |
"Modified: / 14-03-2011 / 20:03:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2173 |
! |
|
2174 |
||
2175 |
isub |
|
2176 |
" |
|
2177 |
int substract |
|
2178 |
stack: value1, value2 -> result |
|
2179 |
args: nothing" |
|
2180 |
||
2181 |
self pushInt: (0 - self pop + self pop). |
|
2182 |
||
2183 |
" |
|
2184 |
Both value1 and value2 must be of type int. The values are |
|
2185 |
popped from the operand stack. The int result is value1 - value2. |
|
2186 |
The result is pushed onto the operand stack. |
|
2187 |
For int subtraction, a - b produces the same result as a + (-b). |
|
2188 |
For int values, subtraction from zero is the same as negation. |
|
2189 |
The result is the 32 low-order bits of the true mathematical result |
|
2190 |
in a sufficiently wide two's-complement format, represented |
|
2191 |
as a value of type int. If overflow occurs, then the sign of |
|
2192 |
the result may not be the same as the sign of the mathematical |
|
2193 |
sum of the two values. |
|
2194 |
Despite the fact that overflow may occur, execution of an isub |
|
2195 |
instruction never throws a runtime exception." |
|
2196 |
||
2197 |
"Created: / 06-03-2011 / 23:14:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2198 |
"Modified: / 13-03-2011 / 17:13:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2199 |
! |
|
2200 |
||
2201 |
iushr |
|
2202 |
" |
|
2203 |
Logical shift right int |
|
2204 |
stack: value1 value2 -> result |
|
2205 |
args: nothing" |
|
2206 |
||
2207 |
self swap. |
|
2208 |
self pushInt: (self pop unsignedBitShift32: self pop). |
|
2209 |
||
2210 |
" |
|
2211 |
Description |
|
2212 |
Both value1 and value2 must be of type int. The values are popped from the |
|
2213 |
operand stack. An int result is calculated by shifting value1 right by s |
|
2214 |
bit positions, with zero extension, where s is the value of the low 5 bits |
|
2215 |
of value2. The result is pushed onto the operand stack. |
|
2216 |
||
2217 |
Notes |
|
2218 |
If value1 is positive and s is value2 & 0x1f, the result is the same as |
|
2219 |
that of value1 >> s; if value1 is negative, the result is equal to the |
|
2220 |
value of the expression (value1 >> s) + (2 << ~s). The addition of the |
|
2221 |
(2 << ~s) term cancels out the propagated sign bit. The shift distance |
|
2222 |
actually used is always in the range 0 to 31, inclusive." |
|
2223 |
||
2224 |
"Created: / 14-03-2011 / 18:58:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2225 |
! |
|
2226 |
||
2227 |
ixor |
|
2228 |
" |
|
2229 |
Boolean XOR int |
|
2230 |
stack: value1 value -> result |
|
2231 |
args: nothing" |
|
2232 |
||
2233 |
self pushInt: (self pop bitXor: self pop). |
|
2234 |
||
2235 |
" |
|
2236 |
Description |
|
2237 |
Both value1 and value2 must be of type int. They are popped from the operand |
|
2238 |
stack. An int result is calculated by taking the bitwise exclusive OR of |
|
2239 |
value1 and value2. The result is pushed onto the operand stack." |
|
2240 |
||
2241 |
"Created: / 14-03-2011 / 18:07:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2242 |
"Modified: / 17-03-2011 / 17:35:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2243 |
! |
|
2244 |
||
2245 |
jsr |
|
2246 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2247 |
||
2248 |
^ self shouldImplement |
|
2249 |
! |
|
2250 |
||
2251 |
jsr_w |
|
2252 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2253 |
||
2254 |
^ self shouldImplement |
|
2255 |
! |
|
2256 |
||
2257 |
l2d |
|
2258 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2259 |
||
2260 |
^ self shouldImplement |
|
2261 |
! |
|
2262 |
||
2263 |
l2f |
|
2264 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2265 |
||
2266 |
^ self shouldImplement |
|
2267 |
! |
|
2268 |
||
2269 |
l2i |
|
2270 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2271 |
||
2272 |
^ self shouldImplement |
|
2273 |
! |
|
2274 |
||
2275 |
ladd |
|
2276 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2277 |
||
2278 |
^ self shouldImplement |
|
2279 |
! |
|
2280 |
||
2281 |
laload |
|
2282 |
self halt |
|
2283 |
! |
|
2284 |
||
2285 |
land |
|
2286 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2287 |
||
2288 |
^ self shouldImplement |
|
2289 |
! |
|
2290 |
||
2291 |
lastore |
|
2292 |
self halt |
|
2293 |
! |
|
2294 |
||
2295 |
lcmp |
|
2296 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2297 |
||
2298 |
^ self shouldImplement |
|
2299 |
! |
|
2300 |
||
2301 |
lconst: arg |
|
2302 |
" |
|
2303 |
Push long constant |
|
2304 |
stack: nothing -> const |
|
2305 |
arg: nothing" |
|
2306 |
||
2307 |
self pushLong: arg. |
|
2308 |
||
2309 |
" |
|
2310 |
Push the long constant <l> (0 or 1) onto the operand stack." |
|
2311 |
||
2312 |
"Created: / 17-03-2011 / 15:31:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2313 |
"Modified: / 17-03-2011 / 17:03:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2314 |
! |
|
2315 |
||
2316 |
ldc1 |
|
2317 |
" |
|
2318 |
Push item from runtime constant pool |
|
2319 |
stack: nothing -> value |
|
2320 |
args: index" |
|
2321 |
||
2322 |
self pushRef: (constantPool at: self fetchIndex). |
|
2323 |
||
2324 |
" |
|
2325 |
Description |
|
2326 |
The index is an unsigned byte that must be a valid index into the runtime constant |
|
2327 |
pool of the current class (§3.6). The runtime constant pool entry at index either |
|
2328 |
must be a runtime constant of type int or float, or must be a symbolic reference |
|
2329 |
to a string literal (§5.1). |
|
2330 |
If the runtime constant pool entry is a runtime constant of type int or float, the |
|
2331 |
numeric value of that runtime constant is pushed onto the operand stack as an int |
|
2332 |
or float, respectively. |
|
2333 |
Otherwise, the runtime constant pool entry must be a reference to an instance of |
|
2334 |
class String representing a string literal (§5.1). A reference to that instance, |
|
2335 |
value, is pushed onto the operand stack. |
|
2336 |
||
2337 |
Notes |
|
2338 |
The ldc instruction can only be used to push a value of type float taken from the float value set (§3.3.2) because a constant of type float in the constant pool (§4.4.4) must be taken from the float value set." |
|
2339 |
||
2340 |
"Modified: / 14-03-2011 / 16:04:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2341 |
! |
|
2342 |
||
2343 |
ldc2 |
|
2344 |
" |
|
2345 |
push item from runtime constant pool (wide index) |
|
2346 |
stack: .. -> value |
|
2347 |
args: indexByte1 indexByte2" |
|
2348 |
||
2349 |
self pushRef: (constantPool at: self fetchIndex2). |
|
2350 |
||
2351 |
" |
|
2352 |
Description |
|
2353 |
The unsigned indexbyte1 and indexbyte2 are assembled into an unsigned 16-bit |
|
2354 |
index into the runtime constant pool of the current class (§3.6), where the |
|
2355 |
value of the index is calculated as (indexbyte1 << 8) | indexbyte2. The index |
|
2356 |
must be a valid index into the runtime constant pool of the current class. |
|
2357 |
The runtime constant pool entry at the index either must be a runtime constant |
|
2358 |
of type int or float, or must be a symbolic reference to a string literal (§5.1). |
|
2359 |
If the runtime constant pool entry is a runtime constant of type int or float, |
|
2360 |
the numeric value of that runtime constant is pushed onto the operand stack as |
|
2361 |
an int or float, respectively. |
|
2362 |
Otherwise, the runtime constant pool entry must be a reference to an instance |
|
2363 |
of class String representing a string literal (§5.1). A reference to that |
|
2364 |
instance, value, is pushed onto the operand stack. |
|
2365 |
||
2366 |
Notes |
|
2367 |
The ldc_w instruction is identical to the ldc instruction except for its wider |
|
2368 |
runtime constant pool index. |
|
2369 |
The ldc_w instruction can only be used to push a value of type float taken from |
|
2370 |
the float value set (§3.3.2) because a constant of type float in the constant |
|
2371 |
pool (§4.4.4) must be taken from the float value set." |
|
2372 |
||
2373 |
"Modified: / 28-03-2011 / 18:04:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2374 |
! |
|
2375 |
||
2376 |
ldc2w |
|
2377 |
" |
|
2378 |
Push long or double from runtime constant pool (wide index) |
|
2379 |
stack: .. -> value |
|
2380 |
args: indexByte1 indexByte2 |
|
2381 |
" |
|
2382 |
self ldc2. |
|
2383 |
" |
|
2384 |
Description |
|
2385 |
The unsigned indexbyte1 and indexbyte2 are assembled into an unsigned 16-bit index |
|
2386 |
into the runtime constant pool of the current class (§3.6), where the value of the |
|
2387 |
index is calculated as (indexbyte1 << 8) | indexbyte2. The index must be a valid |
|
2388 |
index into the runtime constant pool of the current class. The runtime constant pool |
|
2389 |
entry at the index must be a runtime constant of type long or double (§5.1). The |
|
2390 |
numeric value of that runtime constant is pushed onto the operand stack as a long |
|
2391 |
or double, respectively. |
|
2392 |
||
2393 |
Notes |
|
2394 |
Only a wide-index version of the ldc2_w instruction exists; there is no ldc2 instruction |
|
2395 |
that pushes a long or double with a single-byte index. |
|
2396 |
The ldc2_w instruction can only be used to push a value of type double taken from the |
|
2397 |
double value set (§3.3.2) because a constant of type double in the constant pool (§4.4.5) |
|
2398 |
must be taken from the double value set. |
|
2399 |
" |
|
2400 |
||
2401 |
"Modified: / 27-03-2011 / 21:12:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2402 |
! |
|
2403 |
||
2404 |
ldiv |
|
2405 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2406 |
||
2407 |
^ self shouldImplement |
|
2408 |
! |
|
2409 |
||
2410 |
lload |
|
2411 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2412 |
||
2413 |
^ self shouldImplement |
|
2414 |
! |
|
2415 |
||
2416 |
lload: idx |
|
2417 |
" |
|
2418 |
Load long from local variable |
|
2419 |
stack: nothing -> value |
|
2420 |
args: index" |
|
2421 |
||
2422 |
self pushLong: (context at: idx + 1). |
|
2423 |
||
2424 |
" |
|
2425 |
Description |
|
2426 |
The index is an unsigned byte. Both index and index + 1 must be indices |
|
2427 |
into the local variable array of the current frame (§3.6). The local variable |
|
2428 |
at index must contain a long. The value of the local variable at index is |
|
2429 |
pushed onto the operand stack. |
|
2430 |
||
2431 |
Notes |
|
2432 |
The lload opcode can be used in conjunction with the wide instruction to |
|
2433 |
access a local variable using a two-byte unsigned index." |
|
2434 |
||
2435 |
"Modified: / 13-03-2011 / 17:24:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2436 |
! |
|
2437 |
||
2438 |
lmul |
|
2439 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2440 |
||
2441 |
^ self shouldImplement |
|
2442 |
! |
|
2443 |
||
2444 |
lneg |
|
2445 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2446 |
||
2447 |
^ self shouldImplement |
|
2448 |
! |
|
2449 |
||
2450 |
lookupswtch |
|
2451 |
" |
|
2452 |
Access jump table by key match and jump |
|
2453 |
stack: key -> .. |
|
2454 |
args: insane" |
|
2455 |
||
2456 |
| key jmpDest default npairs result | |
|
2457 |
||
2458 |
key := self pop asInteger. |
|
2459 |
self skipPadding. |
|
2460 |
default := self fetchBytes4. |
|
2461 |
npairs := self fetchBytes4. |
|
2462 |
npairs |
|
2463 |
timesRepeat: |
|
2464 |
[ |
|
2465 |
key = self fetchBytes4 |
|
2466 |
ifTrue: [ jmpDest := self fetchBytes4 ] |
|
2467 |
ifFalse: [ self fetchBytes4 ] ]. |
|
2468 |
jmpDest ifNil: [ jmpDest := default. ]. |
|
2469 |
self relativeJump: jmpDest. |
|
2470 |
||
2471 |
" |
|
2472 |
Description |
|
2473 |
A lookupswitch is a variable-length instruction. Immediately after the lookupswitch |
|
2474 |
opcode, between zero and three null bytes (zeroed bytes, not the null object) are |
|
2475 |
inserted as padding. The number of null bytes is chosen so that the defaultbyte1 begins |
|
2476 |
at an address that is a multiple of four bytes from the start of the current method |
|
2477 |
(the opcode of its first instruction). Immediately after the padding follow a series |
|
2478 |
of signed 32-bit values: default, npairs, and then npairs pairs of signed 32-bit values. |
|
2479 |
The npairs must be greater than or equal to 0. Each of the npairs pairs consists of an |
|
2480 |
int match and a signed 32-bit offset. Each of these signed 32-bit values is constructed |
|
2481 |
from four unsigned bytes as (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4. |
|
2482 |
The table match-offset pairs of the lookupswitch instruction must be sorted in increasing |
|
2483 |
numerical order by match. |
|
2484 |
The key must be of type int and is popped from the operand stack. The key is compared |
|
2485 |
against the match values. If it is equal to one of them, then a target address is |
|
2486 |
calculated by adding the corresponding offset to the address of the opcode of this |
|
2487 |
lookupswitch instruction. If the key does not match any of the match values, the target |
|
2488 |
address is calculated by adding default to the address of the opcode of this lookupswitch |
|
2489 |
instruction. Execution then continues at the target address. |
|
2490 |
The target address that can be calculated from the offset of each match-offset pair, as |
|
2491 |
well as the one calculated from default, must be the address of an opcode of an instruction |
|
2492 |
within the method that contains this lookupswitch instruction. |
|
2493 |
||
2494 |
Notes |
|
2495 |
The alignment required of the 4-byte operands of the lookupswitch instruction guarantees |
|
2496 |
4-byte alignment of those operands if and only if the method that contains the lookupswitch |
|
2497 |
is positioned on a 4-byte boundary. |
|
2498 |
The match-offset pairs are sorted to support lookup routines that are quicker than linear |
|
2499 |
search." |
|
2500 |
||
2501 |
"Modified: / 21-03-2011 / 18:38:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2502 |
! |
|
2503 |
||
2504 |
lor |
|
2505 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2506 |
||
2507 |
^ self shouldImplement |
|
2508 |
! |
|
2509 |
||
2510 |
lrem |
|
2511 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2512 |
||
2513 |
^ self shouldImplement |
|
2514 |
! |
|
2515 |
||
2516 |
lreturn |
|
2517 |
" |
|
2518 |
Return long from method |
|
2519 |
stack: value -> empty |
|
2520 |
args: nothing" |
|
2521 |
||
2522 |
self leaveProcessorWith: (self pop). |
|
2523 |
||
2524 |
" |
|
2525 |
Description |
|
2526 |
The current method must have return type long. The value must be of type |
|
2527 |
long. If the current method is a synchronized method, the monitor acquired |
|
2528 |
or reentered on invocation of the method is released or exited (respectively) |
|
2529 |
as if by execution of a monitorexit instruction. If no exception is thrown, |
|
2530 |
value is popped from the operand stack of the current frame (§3.6) and pushed |
|
2531 |
onto the operand stack of the frame of the invoker. Any other values on the |
|
2532 |
operand stack of the current method are discarded. |
|
2533 |
The interpreter then returns control to the invoker of the method, reinstating |
|
2534 |
the frame of the invoker. |
|
2535 |
||
2536 |
Runtime Exceptions |
|
2537 |
If the current method is a synchronized method and the current thread is not |
|
2538 |
the owner of the monitor acquired or reentered on invocation of the method, |
|
2539 |
lreturn throws an IllegalMonitorStateException. This can happen, for example, |
|
2540 |
if a synchronized method contains a monitorexit instruction, but no monitorenter |
|
2541 |
instruction, on the object on which the method is synchronized. |
|
2542 |
Otherwise, if the virtual machine implementation enforces the rules on structured |
|
2543 |
use of locks described in Section 8.13 and if the first of those rules is |
|
2544 |
violated during invocation of the current method, then lreturn throws an |
|
2545 |
IllegalMonitorStateException." |
|
2546 |
"Created: / 14-03-2011 / 13:40:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2547 |
! |
|
2548 |
||
2549 |
lshl |
|
2550 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2551 |
||
2552 |
^ self shouldImplement |
|
2553 |
! |
|
2554 |
||
2555 |
lshr |
|
2556 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2557 |
||
2558 |
^ self shouldImplement |
|
2559 |
! |
|
2560 |
||
2561 |
lstore |
|
2562 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2563 |
||
2564 |
^ self shouldImplement |
|
2565 |
! |
|
2566 |
||
2567 |
lstore: idx |
|
2568 |
" |
|
2569 |
Store long into local variable |
|
2570 |
stack: value -> nothing |
|
2571 |
args: index" |
|
2572 |
||
2573 |
self istore: idx. |
|
2574 |
||
2575 |
" |
|
2576 |
Description |
|
2577 |
The index is an unsigned byte. Both index and index + 1 must be indices |
|
2578 |
into the local variable array of the current frame (§3.6). The value on |
|
2579 |
the top of the operand stack must be of type long. It is popped from the |
|
2580 |
operand stack, and the local variables at index and index + 1 are set to |
|
2581 |
value. |
|
2582 |
||
2583 |
Notes |
|
2584 |
The lstore opcode can be used in conjunction with the wide instruction to |
|
2585 |
access a local variable using a two-byte unsigned index." |
|
2586 |
||
2587 |
"Modified: / 14-03-2011 / 17:55:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2588 |
! |
|
2589 |
||
2590 |
lsub |
|
2591 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2592 |
||
2593 |
^ self shouldImplement |
|
2594 |
! |
|
2595 |
||
2596 |
lushr |
|
2597 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2598 |
||
2599 |
^ self shouldImplement |
|
2600 |
! |
|
2601 |
||
2602 |
lxor |
|
2603 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2604 |
||
2605 |
^ self shouldImplement |
|
2606 |
! |
|
2607 |
||
2608 |
monenter |
|
2609 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2610 |
||
2611 |
^ self shouldImplement |
|
2612 |
! |
|
2613 |
||
2614 |
monexit |
|
2615 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2616 |
||
2617 |
^ self shouldImplement |
|
2618 |
! |
|
2619 |
||
2620 |
multianewarray |
|
2621 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2622 |
||
2623 |
^ self shouldImplement |
|
2624 |
! |
|
2625 |
||
2626 |
new |
|
2627 |
" |
|
2628 |
Create new object |
|
2629 |
stack: nothing -> objectRef |
|
2630 |
args: indexByte1 indexByte2" |
|
2631 |
||
2632 |
| classRef result | |
|
2633 |
||
2634 |
classRef := constantPool at: self fetchIndex2. |
|
2635 |
self breakPoint:#mh_instructions. |
|
2636 |
result := (JavaVM classForName: classRef name) new. |
|
2637 |
||
2638 |
" |
|
2639 |
Description |
|
2640 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into |
|
2641 |
the runtime constant pool of the current class (§3.6), where the value of |
|
2642 |
the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item |
|
2643 |
at the index must be a symbolic reference to a class, array, or interface |
|
2644 |
type. The named class, array, or interface type is resolved (§5.4.3.1) and |
|
2645 |
should result in a class type (it should not result in an array or interface |
|
2646 |
type). Memory for a new instance of that class is allocated from the |
|
2647 |
garbage-collected heap, and the instance variables of the new object are |
|
2648 |
initialized to their default initial values (§2.5.1). The objectref, a reference |
|
2649 |
to the instance, is pushed onto the operand stack. |
|
2650 |
On successful resolution of the class, it is initialized (§5.5) if it has not |
|
2651 |
already been initialized. |
|
2652 |
||
2653 |
Linking Exceptions |
|
2654 |
During resolution of the symbolic reference to the class, array, or interface |
|
2655 |
type, any of the exceptions documented in Section 5.4.3.1 can be thrown. |
|
2656 |
Otherwise, if the symbolic reference to the class, array, or interface type |
|
2657 |
resolves to an interface or is an abstract class, new throws an InstantiationError. |
|
2658 |
||
2659 |
Runtime Exception |
|
2660 |
Otherwise, if execution of this new instruction causes initialization of the |
|
2661 |
referenced class, new may throw an Error as detailed in Section 2.17.5. |
|
2662 |
||
2663 |
Note |
|
2664 |
The new instruction does not completely create a new instance; instance creation |
|
2665 |
is not completed until an instance initialization method has been invoked on |
|
2666 |
the uninitialized instance." |
|
2667 |
||
2668 |
"Created: / 25-02-2011 / 00:17:39 / Marcel Hlopko <hlopik@gmail.com>" |
|
2669 |
"Modified: / 24-02-2011 / 22:13:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2670 |
"Modified: / 13-03-2011 / 17:18:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2671 |
! |
|
2672 |
||
2673 |
newarray |
|
2674 |
" |
|
2675 |
Create new array |
|
2676 |
stack: count -> arrayRef |
|
2677 |
args: arrayType" |
|
2678 |
||
2679 |
| type size | |
|
2680 |
||
2681 |
type := self fetchByte. |
|
2682 |
size := self pop. |
|
2683 |
type = 4 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'boolean' sized: size ]. |
|
2684 |
type = 5 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'char' sized: size ]. |
|
2685 |
type = 6 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'float' sized: size ]. |
|
2686 |
type = 7 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'double' sized: size ]. |
|
2687 |
type = 8 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'byte' sized: size ]. |
|
2688 |
type = 9 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'short' sized: size ]. |
|
2689 |
type = 10 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'int' sized: size ]. |
|
2690 |
type = 11 ifTrue: [ ^ self pushNewPrimitiveArrayOf: 'long' sized: size ]. |
|
2691 |
self halt: 'Type not recognized - tell mh'. |
|
2692 |
||
2693 |
" |
|
2694 |
Description |
|
2695 |
The count must be of type int. It is popped off the operand stack. The count represents |
|
2696 |
the number of elements in the array to be created. |
|
2697 |
The atype is a code that indicates the type of array to create. It must take one of the |
|
2698 |
following values: |
|
2699 |
Array Type atype |
|
2700 |
T_BOOLEAN 4 |
|
2701 |
T_CHAR 5 |
|
2702 |
T_FLOAT 6 |
|
2703 |
T_DOUBLE 7 |
|
2704 |
T_BYTE 8 |
|
2705 |
T_SHORT 9 |
|
2706 |
T_INT 10 |
|
2707 |
T_LONG 11 |
|
2708 |
||
2709 |
||
2710 |
A new array whose components are of type atype and of length count is allocated |
|
2711 |
from the garbage-collected heap. A reference arrayref to this new array object is pushed |
|
2712 |
into the operand stack. Each of the elements of the new array is initialized to the |
|
2713 |
default initial value for the type of the array (§2.5.1). |
|
2714 |
||
2715 |
Runtime Exception |
|
2716 |
If count is less than zero, newarray throws a NegativeArraySizeException. |
|
2717 |
||
2718 |
Notes |
|
2719 |
In Sun's implementation of the Java virtual machine, arrays of type boolean (atype |
|
2720 |
is T_BOOLEAN) are stored as arrays of 8-bit values and are manipulated using the baload |
|
2721 |
and bastore instructions, instructions that also access arrays of type byte. Other |
|
2722 |
implementations may implement packed boolean arrays; the baload and bastore instructions |
|
2723 |
must still be used to access those arrays. |
|
2724 |
" |
|
2725 |
||
2726 |
"Created: / 14-03-2011 / 18:24:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2727 |
"Modified: / 27-03-2011 / 21:07:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2728 |
! |
|
2729 |
||
2730 |
nop |
|
2731 |
"Do nothing" |
|
2732 |
||
2733 |
"Created: / 14-03-2011 / 18:52:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2734 |
! |
|
2735 |
||
2736 |
pop1 |
|
2737 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2738 |
||
2739 |
^ self shouldImplement |
|
2740 |
! |
|
2741 |
||
2742 |
pop2 |
|
2743 |
" |
|
2744 |
Pop the top one or two operand stack values |
|
2745 |
stack v1: value2 value1 -> nothing where each of value1 and value2 is a value of a category 1 computational type (§3.11.1). |
|
2746 |
stack v2: value -> nothing where value is a value of a category 2 computational type (§3.11.1). |
|
2747 |
args: nothing |
|
2748 |
" |
|
2749 |
||
2750 |
sp := sp - 2. |
|
2751 |
" |
|
2752 |
Description |
|
2753 |
Pop the top one or two values from the operand stack. |
|
2754 |
" |
|
2755 |
||
2756 |
"Modified: / 13-03-2011 / 17:20:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2757 |
! |
|
2758 |
||
2759 |
putfield |
|
2760 |
"Set field in object |
|
2761 |
stack: objectRef value -> nothing |
|
2762 |
args: indexbyte1 indexbyte2" |
|
2763 |
||
2764 |
| newValue fieldOwner fieldref | |
|
2765 |
||
2766 |
newValue := self pop. |
|
2767 |
fieldOwner := self pop. |
|
2768 |
fieldref := constantPool at: self fetchIndex2. |
|
2769 |
fieldref resolve. |
|
2770 |
fieldOwner instVarAt: fieldref offset put: newValue. |
|
2771 |
||
2772 |
"Description |
|
2773 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index |
|
2774 |
into the runtime constant pool of the current class (§3.6), where the value |
|
2775 |
of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool |
|
2776 |
item at that index must be a symbolic reference to a field (§5.1), which |
|
2777 |
gives the name and descriptor of the field as well as a symbolic reference |
|
2778 |
to the class in which the field is to be found. The class of objectref must |
|
2779 |
not be an array. If the field is protected (§4.6), and it is either a member |
|
2780 |
of the current class or a member of a superclass of the current class, then |
|
2781 |
the class of objectref must be either the current class or a subclass of |
|
2782 |
the current class. |
|
2783 |
The referenced field is resolved (§5.4.3.2). The type of a value stored |
|
2784 |
by a putfield instruction must be compatible with the descriptor of the |
|
2785 |
referenced field (§4.3.2). If the field descriptor type is boolean, byte, |
|
2786 |
char, short, or int, then the value must be an int. If the field descriptor |
|
2787 |
type is float, long, or double, then the value must be a float, long, or |
|
2788 |
double, respectively. If the field descriptor type is a reference type, then |
|
2789 |
the value must be of a type that is assignment compatible (§2.6.7) with the |
|
2790 |
field descriptor type. If the field is final, it should be declared in the |
|
2791 |
current class. Otherwise, an IllegalAccessError is thrown. |
|
2792 |
The value and objectref are popped from the operand stack. The objectref |
|
2793 |
must be of type reference. The value undergoes value set conversion (§3.8.3), |
|
2794 |
resulting in value', and the referenced field in objectref is set to value'. |
|
2795 |
||
2796 |
Linking Exceptions |
|
2797 |
During resolution of the symbolic reference to the field, any of the |
|
2798 |
exceptions pertaining to field resolution documented in Section 5.4.3.2 can be thrown. |
|
2799 |
||
2800 |
||
2801 |
Otherwise, if the resolved field is a static field, putfield throws |
|
2802 |
an IncompatibleClassChangeError. |
|
2803 |
Otherwise, if the field is final, it must be declared in the current |
|
2804 |
class. Otherwise, an IllegalAccessError is thrown. |
|
2805 |
||
2806 |
Runtime Exception |
|
2807 |
Otherwise, if objectref is null, the putfield instruction throws a NullPointerException." |
|
2808 |
||
2809 |
"Modified: / 04-06-2011 / 18:14:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2810 |
! |
|
2811 |
||
2812 |
putstatic |
|
2813 |
" |
|
2814 |
Set static field in class |
|
2815 |
stack: value -> nothing |
|
2816 |
args: indexByte1 indexByte2" |
|
2817 |
||
2818 |
| newValue fieldref | |
|
2819 |
||
2820 |
newValue := self pop. |
|
2821 |
fieldref := constantPool at: self fetchIndex2. |
|
2822 |
fieldref resolveStatic. |
|
2823 |
fieldref owner instVarAt: fieldref offset put: newValue. |
|
2824 |
||
2825 |
" |
|
2826 |
Description |
|
2827 |
The unsigned indexbyte1 and indexbyte2 are used to construct an index into |
|
2828 |
the runtime constant pool of the current class (§3.6), where the value of |
|
2829 |
the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool |
|
2830 |
item at that index must be a symbolic reference to a field (§5.1), which |
|
2831 |
gives the name and descriptor of the field as well as a symbolic reference |
|
2832 |
to the class or interface in which the field is to be found. The referenced |
|
2833 |
field is resolved (§5.4.3.2). |
|
2834 |
On successful resolution of the field the class or interface that declared |
|
2835 |
the resolved field is initialized (§5.5) if that class or interface has not |
|
2836 |
already been initialized. |
|
2837 |
The type of a value stored by a putstatic instruction must be compatible with |
|
2838 |
the descriptor of the referenced field (§4.3.2). If the field descriptor type |
|
2839 |
is boolean, byte, char, short, or int, then the value must be an int. If the |
|
2840 |
field descriptor type is float, long, or double, then the value must be a float, |
|
2841 |
long, or double, respectively. If the field descriptor type is a reference type, |
|
2842 |
then the value must be of a type that is assignment compatible (§2.6.7) with |
|
2843 |
the field descriptor type. If the field is final, it should be declared in |
|
2844 |
the current class. Otherwise, an IllegalAccessError is thrown. |
|
2845 |
The value is popped from the operand stack and undergoes value set conversion |
|
2846 |
(§3.8.3), resulting in value'. The class field is set to value'. |
|
2847 |
||
2848 |
Linking Exceptions |
|
2849 |
During resolution of the symbolic reference to the class or interface field, |
|
2850 |
any of the exceptions pertaining to field resolution documented in Section |
|
2851 |
5.4.3.2 can be thrown. |
|
2852 |
Otherwise, if the resolved field is not a static (class) field or an interface |
|
2853 |
field, putstatic throws an IncompatibleClassChangeError. |
|
2854 |
Otherwise, if the field is final, it must be declared in the current class. |
|
2855 |
Otherwise, an IllegalAccessError is thrown. |
|
2856 |
||
2857 |
Runtime Exception |
|
2858 |
Otherwise, if execution of this putstatic instruction causes initialization |
|
2859 |
of the referenced class or interface, putstatic may throw an Error as detailed |
|
2860 |
in Section 2.17.5. |
|
2861 |
||
2862 |
Notes |
|
2863 |
A putstatic instruction may be used only to set the value of an interface field |
|
2864 |
on the initialization of that field. Interface fields may be assigned to only |
|
2865 |
once, on execution of an interface variable initialization expression when the |
|
2866 |
interface is initialized (§2.17.4)." |
|
2867 |
||
2868 |
"Created: / 24-02-2011 / 23:21:16 / Marcel Hlopko <hlopik@gmail.com>" |
|
2869 |
"Modified: / 24-02-2011 / 22:14:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2870 |
"Modified: / 04-06-2011 / 18:14:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2871 |
! |
|
2872 |
||
2873 |
ret |
|
2874 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2875 |
||
2876 |
^ self shouldImplement |
|
2877 |
! |
|
2878 |
||
2879 |
ret_w |
|
2880 |
"raise an error: must be redefined in concrete subclass(es)" |
|
2881 |
||
2882 |
^ self shouldImplement |
|
2883 |
! |
|
2884 |
||
2885 |
return |
|
2886 |
"Return void from method |
|
2887 |
stack: nothing -> nothing |
|
2888 |
args: nothing" |
|
2889 |
||
2890 |
self leaveProcessorWith: nil. |
|
2891 |
||
2892 |
" |
|
2893 |
Description |
|
2894 |
The current method must have return type void. If the current method is a synchronized |
|
2895 |
method, the monitor acquired or reentered on invocation of the method is released or |
|
2896 |
exited (respectively) as if by execution of a monitorexit instruction. If no exception |
|
2897 |
is thrown, any values on the operand stack of the current frame (§3.6) are discarded. |
|
2898 |
The interpreter then returns control to the invoker of the method, reinstating the |
|
2899 |
frame of the invoker. |
|
2900 |
||
2901 |
Runtime Exceptions |
|
2902 |
If the current method is a synchronized method and the current thread is not the owner |
|
2903 |
of the monitor acquired or reentered on invocation of the method, return throws an |
|
2904 |
IllegalMonitorStateException. This can happen, for example, if a synchronized method |
|
2905 |
||
2906 |
contains a monitorexit instruction, but no monitorenter instruction, on the object on |
|
2907 |
which the method is synchronized. |
|
2908 |
Otherwise, if the virtual machine implementation enforces the rules on structured use |
|
2909 |
of locks described in Section 8.13 and if the first of those rules is violated during |
|
2910 |
invocation of the current method, then return throws an IllegalMonitorStateException." |
|
2911 |
"Created: / 24-02-2011 / 11:38:13 / Marcel Hlopko <hlopik@gmail.com>" |
|
2912 |
"Modified: / 24-02-2011 / 23:10:54 / Marcel Hlopko <hlopik@gmail.com>" |
|
2913 |
"Modified: / 13-03-2011 / 17:22:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2914 |
! |
|
2915 |
||
2916 |
saload |
|
2917 |
self halt |
|
2918 |
! |
|
2919 |
||
2920 |
sastore |
|
2921 |
self halt |
|
2922 |
! |
|
2923 |
||
2924 |
sipush |
|
2925 |
"pushes a short onto the stack |
|
2926 |
stack: nothing -> value |
|
2927 |
args: byte1 byte2" |
|
2928 |
||
2929 |
self pushInt: (self fetchBytes2). |
|
2930 |
||
2931 |
" |
|
2932 |
Description |
|
2933 |
The immediate unsigned byte1 and byte2 values are assembled |
|
2934 |
into an intermediate short where the value of the short is (byte1 << 8) | byte2. |
|
2935 |
The intermediate value is then sign-extended to an int value. That value is |
|
2936 |
pushed onto the operand stack." |
|
2937 |
||
2938 |
"Modified: / 17-03-2011 / 17:03:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2939 |
! |
|
2940 |
||
2941 |
swap |
|
2942 |
" |
|
2943 |
Swap the top two operand stack values |
|
2944 |
stack: value2 value1 -> value1 value2 |
|
2945 |
args: nothing |
|
2946 |
" |
|
2947 |
| v1 v2 | |
|
2948 |
||
2949 |
v1 := self pop. |
|
2950 |
v2 := self pop. |
|
2951 |
self pushInt: v1. |
|
2952 |
self pushInt: v2. |
|
2953 |
||
2954 |
" |
|
2955 |
Description |
|
2956 |
Swap the top two values on the operand stack. |
|
2957 |
The swap instruction must not be used unless value1 and value2 are both |
|
2958 |
values of a category 1 computational type (§3.11.1). |
|
2959 |
||
2960 |
Notes |
|
2961 |
The Java virtual machine does not provide an instruction implementing a |
|
2962 |
swap on operands of category 2 computational types. |
|
2963 |
" |
|
2964 |
||
2965 |
"Modified: / 13-03-2011 / 17:24:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2966 |
! |
|
2967 |
||
2968 |
tableswtch |
|
2969 |
" |
|
2970 |
Access jump table by index and jump |
|
2971 |
stack: index -> .. |
|
2972 |
args: insane :)" |
|
2973 |
||
2974 |
| index jmpDest default low high result | |
|
2975 |
||
2976 |
index := self pop asInteger. |
|
2977 |
self skipPadding. |
|
2978 |
default := self fetchBytes4. |
|
2979 |
low := self fetchBytes4. |
|
2980 |
high := self fetchBytes4. |
|
2981 |
low to: high |
|
2982 |
do: |
|
2983 |
[:idx | |
|
2984 |
idx = index |
|
2985 |
ifTrue: [ jmpDest := self fetchBytes4 ] |
|
2986 |
ifFalse: [ self fetchBytes4 ] ]. |
|
2987 |
jmpDest ifNil: [ jmpDest := default. ]. |
|
2988 |
self relativeJump: jmpDest. |
|
2989 |
||
2990 |
" |
|
2991 |
Description |
|
2992 |
A tableswitch is a variable-length instruction. Immediately after the tableswitch opcode, |
|
2993 |
between 0 and 3 null bytes (zeroed bytes, not the null object) are inserted as padding. |
|
2994 |
The number of null bytes is chosen so that the following byte begins at an address that |
|
2995 |
is a multiple of 4 bytes from the start of the current method (the opcode of its first |
|
2996 |
instruction). Immediately after the padding follow bytes constituting three signed 32-bit |
|
2997 |
values: default, low, and high. Immediately following those bytes are bytes constituting a |
|
2998 |
series of high - low + 1 signed 32-bit offsets. The value low must be less than or equal |
|
2999 |
to high. The high - low + 1 signed 32-bit offsets are treated as a 0-based jump table. |
|
3000 |
Each of these signed 32-bit values is constructed as (byte1 << 24) | (byte2 << 16) | |
|
3001 |
(byte3 << 8) | byte4. |
|
3002 |
The index must be of type int and is popped from the operand stack. If index is less than |
|
3003 |
low or index is greater than high, then a target address is calculated by adding default |
|
3004 |
to the address of the opcode of this tableswitch instruction. Otherwise, the offset at |
|
3005 |
position index - low of the jump table is extracted. The target address is calculated by |
|
3006 |
adding that offset to the address of the opcode of this tableswitch instruction. Execution |
|
3007 |
then continues at the target address. |
|
3008 |
The target address that can be calculated from each jump table offset, as well as the ones |
|
3009 |
that can be calculated from default, must be the address of an opcode of an instruction |
|
3010 |
within the method that contains this tableswitch instruction. |
|
3011 |
||
3012 |
Notes |
|
3013 |
The alignment required of the 4-byte operands of the tableswitch instruction guarantees 4-byte |
|
3014 |
alignment of those operands if and only if the method that contains the tableswitch starts |
|
3015 |
on a 4-byte boundary." |
|
3016 |
||
3017 |
"Modified: / 21-03-2011 / 18:35:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
3018 |
! |
|
3019 |
||
3020 |
wide |
|
3021 |
"raise an error: must be redefined in concrete subclass(es)" |
|
3022 |
||
3023 |
^ self shouldImplement |
|
3024 |
! ! |
|
3025 |
||
3026 |
!JavaByteCodeInterpreter methodsFor:'interpretation'! |
|
3027 |
||
3028 |
handleAbstractMethod |
|
3029 |
self halt: 'Is it allowed to interpret abstract method? I dont think so :)'. |
|
3030 |
||
3031 |
"Created: / 22-03-2011 / 14:50:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
3032 |
! |
|
3033 |
||
3034 |
interpret: aMethod receiver: aReceiver arguments: args |
|
3035 |
self |
|
3036 |
log: ('Invoking method ' , aMethod name , ' on ' , aReceiver printString |
|
3037 |
, ' with ' , args printString). |
|
3038 |
||
3039 |
^ self |
|
3040 |
process: aMethod |
|
3041 |
receiver: aReceiver |
|
3042 |
arguments: args. |
|
3043 |
||
3044 |
"Created: / 17-03-2011 / 17:25:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
3045 |
"Modified: / 28-03-2011 / 18:03:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
3046 |
! |
|
3047 |
||
3048 |
interpretInner: aJavaMethod receiver: aReceiver arguments: anArgs |
|
3049 |
^ aJavaMethod interpretWithReceiver: aReceiver arguments: anArgs. |
|
3050 |
||
3051 |
"Created: / 31-03-2011 / 16:29:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
3052 |
! ! |
|
3053 |
||
3054 |
!JavaByteCodeInterpreter class methodsFor:'documentation'! |
|
3055 |
||
2303
f02352bc0228
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2188
diff
changeset
|
3056 |
version |
f02352bc0228
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2188
diff
changeset
|
3057 |
^ '$Header: /cvs/stx/stx/libjava/Attic/JavaByteCodeInterpreter.st,v 1.3 2011-11-24 11:54:55 cg Exp $' |
f02352bc0228
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2188
diff
changeset
|
3058 |
! |
f02352bc0228
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2188
diff
changeset
|
3059 |
|
2188 | 3060 |
version_CVS |
2303
f02352bc0228
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2188
diff
changeset
|
3061 |
^ '$Header: /cvs/stx/stx/libjava/Attic/JavaByteCodeInterpreter.st,v 1.3 2011-11-24 11:54:55 cg Exp $' |
2188 | 3062 |
! |
3063 |
||
749 | 3064 |
version_SVN |
2188 | 3065 |
^ '§Id: JavaByteCodeInterpreter.st,v 1.1 2011/08/18 19:06:53 vrany Exp §' |
2152 | 3066 |
! ! |