1 // interpret.cc - Code for the interpreter
3 /* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 /* Author: Kresten Krab Thorup <krab@gnu.org> */
15 // Define this to get the direct-threaded interpreter. If undefined,
16 // we revert to a basic bytecode interpreter. The former is faster
17 // but uses more memory.
18 #define DIRECT_THREADED
20 #pragma implementation "java-interp.h"
23 #include <java-cpool.h>
24 #include <java-interp.h>
25 // #include <java/lang/fdlibm.h>
26 #include <java/lang/System.h>
27 #include <java/lang/String.h>
28 #include <java/lang/Integer.h>
29 #include <java/lang/Long.h>
30 #include <java/lang/StringBuffer.h>
31 #include <java/lang/Class.h>
32 #include <java/lang/reflect/Modifier.h>
33 #include <java/lang/ClassCastException.h>
34 #include <java/lang/VirtualMachineError.h>
35 #include <java/lang/InternalError.h>
36 #include <java/lang/NullPointerException.h>
37 #include <java/lang/ArithmeticException.h>
38 #include <java/lang/IncompatibleClassChangeError.h>
39 #include <java-insns.h>
40 #include <java-signal.h>
48 static void throw_internal_error (char *msg
)
49 __attribute__ ((__noreturn__
));
50 static void throw_incompatible_class_change_error (jstring msg
)
51 __attribute__ ((__noreturn__
));
53 static void throw_null_pointer_exception ()
54 __attribute__ ((__noreturn__
));
57 extern "C" double __ieee754_fmod (double,double);
59 // This represents a single slot in the "compiled" form of the
65 // An integer value used by an instruction.
67 // A pointer value used by an instruction.
71 // The type of the PC depends on whether we're doing direct threading
72 // or a more ordinary bytecode interpreter.
73 #ifdef DIRECT_THREADED
74 typedef insn_slot
*pc_t
;
76 typedef unsigned char *pc_t
;
79 static inline void dupx (_Jv_word
*sp
, int n
, int x
)
81 // first "slide" n+x elements n to the right
83 for (int i
= 0; i
< n
+x
; i
++)
85 sp
[(top
-i
)] = sp
[(top
-i
)-n
];
88 // next, copy the n top elements, n+x down
89 for (int i
= 0; i
< n
; i
++)
91 sp
[top
-(n
+x
)-i
] = sp
[top
-i
];
96 // Used to convert from floating types to integral types.
97 template<typename TO
, typename FROM
>
99 convert (FROM val
, TO min
, TO max
)
102 if (val
>= (FROM
) max
)
104 else if (val
<= (FROM
) min
)
113 #define PUSHA(V) (sp++)->o = (V)
114 #define PUSHI(V) (sp++)->i = (V)
115 #define PUSHF(V) (sp++)->f = (V)
116 #if SIZEOF_VOID_P == 8
117 # define PUSHL(V) (sp->l = (V), sp += 2)
118 # define PUSHD(V) (sp->d = (V), sp += 2)
120 # define PUSHL(V) do { _Jv_word2 w2; w2.l=(V); \
121 (sp++)->ia[0] = w2.ia[0]; \
122 (sp++)->ia[0] = w2.ia[1]; } while (0)
123 # define PUSHD(V) do { _Jv_word2 w2; w2.d=(V); \
124 (sp++)->ia[0] = w2.ia[0]; \
125 (sp++)->ia[0] = w2.ia[1]; } while (0)
128 #define POPA() ((--sp)->o)
129 #define POPI() ((jint) (--sp)->i) // cast since it may be promoted
130 #define POPF() ((jfloat) (--sp)->f)
131 #if SIZEOF_VOID_P == 8
132 # define POPL() (sp -= 2, (jlong) sp->l)
133 # define POPD() (sp -= 2, (jdouble) sp->d)
135 # define POPL() ({ _Jv_word2 w2; \
136 w2.ia[1] = (--sp)->ia[0]; \
137 w2.ia[0] = (--sp)->ia[0]; w2.l; })
138 # define POPD() ({ _Jv_word2 w2; \
139 w2.ia[1] = (--sp)->ia[0]; \
140 w2.ia[0] = (--sp)->ia[0]; w2.d; })
143 #define LOADA(I) (sp++)->o = locals[I].o
144 #define LOADI(I) (sp++)->i = locals[I].i
145 #define LOADF(I) (sp++)->f = locals[I].f
146 #if SIZEOF_VOID_P == 8
147 # define LOADL(I) (sp->l = locals[I].l, sp += 2)
148 # define LOADD(I) (sp->d = locals[I].d, sp += 2)
150 # define LOADL(I) do { jint __idx = (I); \
151 (sp++)->ia[0] = locals[__idx].ia[0]; \
152 (sp++)->ia[0] = locals[__idx+1].ia[0]; \
154 # define LOADD(I) LOADL(I)
157 #define STOREA(I) locals[I].o = (--sp)->o
158 #define STOREI(I) locals[I].i = (--sp)->i
159 #define STOREF(I) locals[I].f = (--sp)->f
160 #if SIZEOF_VOID_P == 8
161 # define STOREL(I) (sp -= 2, locals[I].l = sp->l)
162 # define STORED(I) (sp -= 2, locals[I].d = sp->d)
164 # define STOREL(I) do { jint __idx = (I); \
165 locals[__idx+1].ia[0] = (--sp)->ia[0]; \
166 locals[__idx].ia[0] = (--sp)->ia[0]; \
168 # define STORED(I) STOREL(I)
171 #define PEEKI(I) (locals+(I))->i
172 #define PEEKA(I) (locals+(I))->o
174 #define POKEI(I,V) ((locals+(I))->i = (V))
177 #define BINOPI(OP) { \
178 jint value2 = POPI(); \
179 jint value1 = POPI(); \
180 PUSHI(value1 OP value2); \
183 #define BINOPF(OP) { \
184 jfloat value2 = POPF(); \
185 jfloat value1 = POPF(); \
186 PUSHF(value1 OP value2); \
189 #define BINOPL(OP) { \
190 jlong value2 = POPL(); \
191 jlong value1 = POPL(); \
192 PUSHL(value1 OP value2); \
195 #define BINOPD(OP) { \
196 jdouble value2 = POPD(); \
197 jdouble value1 = POPD(); \
198 PUSHD(value1 OP value2); \
201 static inline jint
get1s(unsigned char* loc
) {
202 return *(signed char*)loc
;
205 static inline jint
get1u(unsigned char* loc
) {
209 static inline jint
get2s(unsigned char* loc
) {
210 return (((jint
)*(signed char*)loc
) << 8) | ((jint
)*(loc
+1));
213 static inline jint
get2u(unsigned char* loc
) {
214 return (((jint
)(*loc
)) << 8) | ((jint
)*(loc
+1));
217 static jint
get4(unsigned char* loc
) {
218 return (((jint
)(loc
[0])) << 24)
219 | (((jint
)(loc
[1])) << 16)
220 | (((jint
)(loc
[2])) << 8)
221 | (((jint
)(loc
[3])) << 0);
227 #define NULLARRAYCHECK(X)
229 #define NULLCHECK(X) \
230 do { if ((X)==NULL) throw_null_pointer_exception (); } while (0)
231 #define NULLARRAYCHECK(X) \
232 do { if ((X)==NULL) { throw_null_pointer_exception (); } } while (0)
235 #define ARRAYBOUNDSCHECK(array, index) \
238 if (((unsigned) index) >= (unsigned) (array->length)) \
239 _Jv_ThrowBadArrayIndex (index); \
243 void _Jv_InterpMethod::run_normal (ffi_cif
*,
248 _Jv_InterpMethod
*_this
= (_Jv_InterpMethod
*) __this
;
249 _this
->run (ret
, args
);
252 void _Jv_InterpMethod::run_synch_object (ffi_cif
*,
257 _Jv_InterpMethod
*_this
= (_Jv_InterpMethod
*) __this
;
259 jobject rcv
= (jobject
) args
[0].ptr
;
260 JvSynchronize
mutex (rcv
);
262 _this
->run (ret
, args
);
265 void _Jv_InterpMethod::run_synch_class (ffi_cif
*,
270 _Jv_InterpMethod
*_this
= (_Jv_InterpMethod
*) __this
;
272 jclass sync
= _this
->defining_class
;
273 JvSynchronize
mutex (sync
);
275 _this
->run (ret
, args
);
278 #ifdef DIRECT_THREADED
279 // "Compile" a method by turning it from bytecode to direct-threaded
282 _Jv_InterpMethod::compile (const void * const *insn_targets
)
284 insn_slot
*insns
= NULL
;
286 unsigned char *codestart
= bytecode ();
287 unsigned char *end
= codestart
+ code_length
;
288 _Jv_word
*pool_data
= defining_class
->constants
.data
;
290 #define SET_ONE(Field, Value) \
296 insns[next++].Field = Value; \
300 #define SET_INSN(Value) SET_ONE (insn, (void *) Value)
301 #define SET_INT(Value) SET_ONE (int_val, Value)
302 #define SET_DATUM(Value) SET_ONE (datum, Value)
304 // Map from bytecode PC to slot in INSNS.
305 int *pc_mapping
= (int *) __builtin_alloca (sizeof (int) * code_length
);
306 for (int i
= 0; i
< code_length
; ++i
)
309 for (int i
= 0; i
< 2; ++i
)
311 jboolean first_pass
= i
== 0;
315 insns
= (insn_slot
*) _Jv_Malloc (sizeof (insn_slot
) * next
);
319 unsigned char *pc
= codestart
;
322 int base_pc_val
= pc
- codestart
;
324 pc_mapping
[base_pc_val
] = next
;
326 java_opcode opcode
= (java_opcode
) *pc
++;
328 if (opcode
== op_nop
)
330 SET_INSN (insn_targets
[opcode
]);
471 case op_monitorenter
:
481 // No argument, nothing else to do.
485 SET_INT (get1s (pc
));
491 int index
= get1u (pc
);
493 SET_DATUM (pool_data
[index
].o
);
509 SET_INT (get1u (pc
));
514 SET_INT (get1u (pc
));
515 SET_INT (get1s (pc
+ 1));
521 int index
= get2u (pc
);
523 SET_DATUM (pool_data
[index
].o
);
529 int index
= get2u (pc
);
531 SET_DATUM (&pool_data
[index
]);
536 SET_INT (get2s (pc
));
548 case op_invokespecial
:
549 case op_invokestatic
:
550 case op_invokevirtual
:
551 SET_INT (get2u (pc
));
555 case op_multianewarray
:
556 SET_INT (get2u (pc
));
557 SET_INT (get1u (pc
+ 2));
580 int offset
= get2s (pc
);
583 int new_pc
= base_pc_val
+ offset
;
585 bool orig_was_goto
= opcode
== op_goto
;
587 // Thread jumps. We limit the loop count; this lets
588 // us avoid infinite loops if the bytecode contains
589 // such. `10' is arbitrary.
591 while (codestart
[new_pc
] == op_goto
&& count
-- > 0)
592 new_pc
+= get2s (&codestart
[new_pc
+ 1]);
594 // If the jump takes us to a `return' instruction and
595 // the original branch was an unconditional goto, then
596 // we hoist the return.
597 opcode
= (java_opcode
) codestart
[new_pc
];
599 && (opcode
== op_ireturn
|| opcode
== op_lreturn
600 || opcode
== op_freturn
|| opcode
== op_dreturn
601 || opcode
== op_areturn
|| opcode
== op_return
))
604 SET_INSN (insn_targets
[opcode
]);
607 SET_DATUM (&insns
[pc_mapping
[new_pc
]]);
613 while ((pc
- codestart
) % 4 != 0)
616 jint def
= get4 (pc
);
617 SET_DATUM (&insns
[pc_mapping
[base_pc_val
+ def
]]);
623 int high
= get4 (pc
);
627 for (int i
= low
; i
<= high
; ++i
)
629 SET_DATUM (&insns
[pc_mapping
[base_pc_val
+ get4 (pc
)]]);
635 case op_lookupswitch
:
637 while ((pc
- codestart
) % 4 != 0)
640 jint def
= get4 (pc
);
641 SET_DATUM (&insns
[pc_mapping
[base_pc_val
+ def
]]);
644 jint npairs
= get4 (pc
);
650 jint match
= get4 (pc
);
651 jint offset
= get4 (pc
+ 4);
653 SET_DATUM (&insns
[pc_mapping
[base_pc_val
+ offset
]]);
659 case op_invokeinterface
:
661 jint index
= get2u (pc
);
663 // We ignore the next two bytes.
671 opcode
= (java_opcode
) get1u (pc
);
673 jint val
= get2u (pc
);
676 // We implement narrow and wide instructions using the
677 // same code in the interpreter. So we rewrite the
678 // instruction slot here.
680 insns
[next
- 1].insn
= (void *) insn_targets
[opcode
];
683 if (opcode
== op_iinc
)
685 SET_INT (get2s (pc
));
694 jint offset
= get4 (pc
);
696 SET_DATUM (&insns
[pc_mapping
[base_pc_val
+ offset
]]);
700 // Some "can't happen" cases that we include for
701 // error-checking purposes.
719 case op_getstatic_2s
:
720 case op_getstatic_2u
:
731 // Now update exceptions.
732 _Jv_InterpException
*exc
= exceptions ();
733 for (int i
= 0; i
< exc_count
; ++i
)
735 exc
[i
].start_pc
.p
= &insns
[pc_mapping
[exc
[i
].start_pc
.i
]];
736 exc
[i
].end_pc
.p
= &insns
[pc_mapping
[exc
[i
].end_pc
.i
]];
737 exc
[i
].handler_pc
.p
= &insns
[pc_mapping
[exc
[i
].handler_pc
.i
]];
738 jclass handler
= (_Jv_ResolvePoolEntry (defining_class
,
739 exc
[i
].handler_type
.i
)).clazz
;
740 exc
[i
].handler_type
.p
= handler
;
745 #endif /* DIRECT_THREADED */
748 _Jv_InterpMethod::run (void *retp
, ffi_raw
*args
)
750 using namespace java::lang::reflect
;
752 _Jv_word stack
[max_stack
];
753 _Jv_word
*sp
= stack
;
755 _Jv_word locals
[max_locals
];
757 /* Go straight at it! the ffi raw format matches the internal
758 stack representation exactly. At least, that's the idea.
760 memcpy ((void*) locals
, (void*) args
, args_raw_size
);
762 _Jv_word
*pool_data
= defining_class
->constants
.data
;
764 /* These three are temporaries for common code used by several
767 _Jv_ResolvedMethod
* rmeth
;
770 #define INSN_LABEL(op) &&insn_##op
772 static const void *const insn_target
[] =
775 INSN_LABEL(aconst_null
),
776 INSN_LABEL(iconst_m1
),
777 INSN_LABEL(iconst_0
),
778 INSN_LABEL(iconst_1
),
779 INSN_LABEL(iconst_2
),
780 INSN_LABEL(iconst_3
),
781 INSN_LABEL(iconst_4
),
782 INSN_LABEL(iconst_5
),
783 INSN_LABEL(lconst_0
),
784 INSN_LABEL(lconst_1
),
785 INSN_LABEL(fconst_0
),
786 INSN_LABEL(fconst_1
),
787 INSN_LABEL(fconst_2
),
788 INSN_LABEL(dconst_0
),
789 INSN_LABEL(dconst_1
),
833 INSN_LABEL(istore_0
),
834 INSN_LABEL(istore_1
),
835 INSN_LABEL(istore_2
),
836 INSN_LABEL(istore_3
),
837 INSN_LABEL(lstore_0
),
838 INSN_LABEL(lstore_1
),
839 INSN_LABEL(lstore_2
),
840 INSN_LABEL(lstore_3
),
841 INSN_LABEL(fstore_0
),
842 INSN_LABEL(fstore_1
),
843 INSN_LABEL(fstore_2
),
844 INSN_LABEL(fstore_3
),
845 INSN_LABEL(dstore_0
),
846 INSN_LABEL(dstore_1
),
847 INSN_LABEL(dstore_2
),
848 INSN_LABEL(dstore_3
),
849 INSN_LABEL(astore_0
),
850 INSN_LABEL(astore_1
),
851 INSN_LABEL(astore_2
),
852 INSN_LABEL(astore_3
),
933 INSN_LABEL(if_icmpeq
),
934 INSN_LABEL(if_icmpne
),
935 INSN_LABEL(if_icmplt
),
936 INSN_LABEL(if_icmpge
),
937 INSN_LABEL(if_icmpgt
),
938 INSN_LABEL(if_icmple
),
939 INSN_LABEL(if_acmpeq
),
940 INSN_LABEL(if_acmpne
),
944 INSN_LABEL(tableswitch
),
945 INSN_LABEL(lookupswitch
),
952 INSN_LABEL(getstatic
),
953 INSN_LABEL(putstatic
),
954 INSN_LABEL(getfield
),
955 INSN_LABEL(putfield
),
956 INSN_LABEL(invokevirtual
),
957 INSN_LABEL(invokespecial
),
958 INSN_LABEL(invokestatic
),
959 INSN_LABEL(invokeinterface
),
962 INSN_LABEL(newarray
),
963 INSN_LABEL(anewarray
),
964 INSN_LABEL(arraylength
),
966 INSN_LABEL(checkcast
),
967 INSN_LABEL(instanceof
),
968 INSN_LABEL(monitorenter
),
969 INSN_LABEL(monitorexit
),
970 #ifdef DIRECT_THREADED
975 INSN_LABEL(multianewarray
),
977 INSN_LABEL(ifnonnull
),
985 #ifdef DIRECT_THREADED
987 #define NEXT_INSN goto *((pc++)->insn)
988 #define INTVAL() ((pc++)->int_val)
989 #define AVAL() ((pc++)->datum)
991 #define GET1S() INTVAL ()
992 #define GET2S() INTVAL ()
993 #define GET1U() INTVAL ()
994 #define GET2U() INTVAL ()
995 #define AVAL1U() AVAL ()
996 #define AVAL2U() AVAL ()
997 #define AVAL2UP() AVAL ()
998 #define SKIP_GOTO ++pc
999 #define GOTO_VAL() (insn_slot *) pc->datum
1000 #define PCVAL(unionval) unionval.p
1001 #define AMPAMP(label) &&label
1003 // Compile if we must.
1004 if (prepared
== NULL
)
1005 compile (insn_target
);
1006 pc
= (insn_slot
*) prepared
;
1010 #define NEXT_INSN goto *(insn_target[*pc++])
1012 #define GET1S() get1s (pc++)
1013 #define GET2S() (pc += 2, get2s (pc- 2))
1014 #define GET1U() get1u (pc++)
1015 #define GET2U() (pc += 2, get2u (pc - 2))
1016 #define AVAL1U() ({ int index = get1u (pc++); pool_data[index].o; })
1017 #define AVAL2U() ({ int index = get2u (pc); pc += 2; pool_data[index].o; })
1018 #define AVAL2UP() ({ int index = get2u (pc); pc += 2; &pool_data[index]; })
1019 #define SKIP_GOTO pc += 2
1020 #define GOTO_VAL() pc - 1 + get2s (pc)
1021 #define PCVAL(unionval) unionval.i
1022 #define AMPAMP(label) NULL
1026 #endif /* DIRECT_THREADED */
1028 #define TAKE_GOTO pc = GOTO_VAL ()
1032 // We keep nop around. It is used if we're interpreting the
1033 // bytecodes and not doing direct threading.
1037 /* The first few instructions here are ordered according to their
1038 frequency, in the hope that this will improve code locality a
1041 insn_aload_0
: // 0x2a
1049 insn_iload_1
: // 0x1b
1053 insn_invokevirtual
: // 0xb6
1055 int index
= GET2U ();
1057 /* _Jv_ResolvePoolEntry returns immediately if the value already
1058 * is resolved. If we want to clutter up the code here to gain
1059 * a little performance, then we can check the corresponding bit
1060 * JV_CONSTANT_ResolvedFlag in the tag directly. For now, I
1061 * don't think it is worth it. */
1063 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
1065 sp
-= rmeth
->stack_item_count
;
1066 // We don't use NULLCHECK here because we can't rely on that
1067 // working if the method is final. So instead we do an
1070 throw new java::lang::NullPointerException
;
1072 if (rmeth
->vtable_index
== -1)
1074 // final methods do not appear in the vtable,
1075 // if it does not appear in the superclass.
1076 fun
= (void (*)()) rmeth
->method
->ncode
;
1080 jobject rcv
= sp
[0].o
;
1081 _Jv_VTable
*table
= *(_Jv_VTable
**) rcv
;
1082 fun
= (void (*)()) table
->get_method (rmeth
->vtable_index
);
1085 #ifdef DIRECT_THREADED
1086 // Rewrite instruction so that we use a faster pre-resolved
1088 pc
[-2].insn
= &&invokevirtual_resolved
;
1089 pc
[-1].datum
= rmeth
;
1090 #endif /* DIRECT_THREADED */
1092 goto perform_invoke
;
1094 #ifdef DIRECT_THREADED
1095 invokevirtual_resolved
:
1097 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
1098 sp
-= rmeth
->stack_item_count
;
1099 // We don't use NULLCHECK here because we can't rely on that
1100 // working if the method is final. So instead we do an
1103 throw new java::lang::NullPointerException
;
1105 if (rmeth
->vtable_index
== -1)
1107 // final methods do not appear in the vtable,
1108 // if it does not appear in the superclass.
1109 fun
= (void (*)()) rmeth
->method
->ncode
;
1113 jobject rcv
= sp
[0].o
;
1114 _Jv_VTable
*table
= *(_Jv_VTable
**) rcv
;
1115 fun
= (void (*)()) table
->get_method (rmeth
->vtable_index
);
1118 goto perform_invoke
;
1119 #endif /* DIRECT_THREADED */
1123 /* here goes the magic again... */
1124 ffi_cif
*cif
= &rmeth
->cif
;
1125 ffi_raw
*raw
= (ffi_raw
*) sp
;
1129 #if FFI_NATIVE_RAW_API
1130 /* We assume that this is only implemented if it's correct */
1131 /* to use it here. On a 64 bit machine, it never is. */
1132 ffi_raw_call (cif
, fun
, (void*)&rvalue
, raw
);
1134 ffi_java_raw_call (cif
, fun
, (void*)&rvalue
, raw
);
1137 int rtype
= cif
->rtype
->type
;
1139 /* the likelyhood of object, int, or void return is very high,
1140 * so those are checked before the switch */
1141 if (rtype
== FFI_TYPE_POINTER
)
1143 PUSHA (*(jobject
*)&rvalue
);
1145 else if (rtype
== FFI_TYPE_SINT32
)
1147 PUSHI (*(jint
*)&rvalue
);
1149 else if (rtype
== FFI_TYPE_VOID
)
1157 case FFI_TYPE_SINT8
:
1159 jbyte value
= (*(jint
*)&rvalue
) & 0xff;
1164 case FFI_TYPE_SINT16
:
1166 jshort value
= (*(jint
*)&rvalue
) & 0xffff;
1171 case FFI_TYPE_UINT16
:
1173 jint value
= (*(jint
*)&rvalue
) & 0xffff;
1178 case FFI_TYPE_FLOAT
:
1179 PUSHF (*(jfloat
*)&rvalue
);
1182 case FFI_TYPE_DOUBLE
:
1186 case FFI_TYPE_SINT64
:
1187 PUSHL (*(jlong
*)&rvalue
);
1191 throw_internal_error ("unknown return type in invokeXXX");
1258 // For direct threaded, bipush and sipush are the same.
1259 #ifndef DIRECT_THREADED
1262 #endif /* DIRECT_THREADED */
1268 // For direct threaded, ldc and ldc_w are the same.
1269 #ifndef DIRECT_THREADED
1270 PUSHA ((jobject
) AVAL1U ());
1272 #endif /* DIRECT_THREADED */
1274 PUSHA ((jobject
) AVAL2U ());
1279 void *where
= AVAL2UP ();
1280 memcpy (sp
, where
, 2*sizeof (_Jv_word
));
1375 jint index
= POPI();
1376 jintArray arr
= (jintArray
) POPA();
1377 NULLARRAYCHECK (arr
);
1378 ARRAYBOUNDSCHECK (arr
, index
);
1379 PUSHI( elements(arr
)[index
] );
1385 jint index
= POPI();
1386 jlongArray arr
= (jlongArray
) POPA();
1387 NULLARRAYCHECK (arr
);
1388 ARRAYBOUNDSCHECK (arr
, index
);
1389 PUSHL( elements(arr
)[index
] );
1395 jint index
= POPI();
1396 jfloatArray arr
= (jfloatArray
) POPA();
1397 NULLARRAYCHECK (arr
);
1398 ARRAYBOUNDSCHECK (arr
, index
);
1399 PUSHF( elements(arr
)[index
] );
1405 jint index
= POPI();
1406 jdoubleArray arr
= (jdoubleArray
) POPA();
1407 NULLARRAYCHECK (arr
);
1408 ARRAYBOUNDSCHECK (arr
, index
);
1409 PUSHD( elements(arr
)[index
] );
1415 jint index
= POPI();
1416 jobjectArray arr
= (jobjectArray
) POPA();
1417 NULLARRAYCHECK (arr
);
1418 ARRAYBOUNDSCHECK (arr
, index
);
1419 PUSHA( elements(arr
)[index
] );
1425 jint index
= POPI();
1426 jbyteArray arr
= (jbyteArray
) POPA();
1427 NULLARRAYCHECK (arr
);
1428 ARRAYBOUNDSCHECK (arr
, index
);
1429 PUSHI( elements(arr
)[index
] );
1435 jint index
= POPI();
1436 jcharArray arr
= (jcharArray
) POPA();
1437 NULLARRAYCHECK (arr
);
1438 ARRAYBOUNDSCHECK (arr
, index
);
1439 PUSHI( elements(arr
)[index
] );
1445 jint index
= POPI();
1446 jshortArray arr
= (jshortArray
) POPA();
1447 NULLARRAYCHECK (arr
);
1448 ARRAYBOUNDSCHECK (arr
, index
);
1449 PUSHI( elements(arr
)[index
] );
1555 jint value
= POPI();
1556 jint index
= POPI();
1557 jintArray arr
= (jintArray
) POPA();
1558 NULLARRAYCHECK (arr
);
1559 ARRAYBOUNDSCHECK (arr
, index
);
1560 elements(arr
)[index
] = value
;
1566 jlong value
= POPL();
1567 jint index
= POPI();
1568 jlongArray arr
= (jlongArray
) POPA();
1569 NULLARRAYCHECK (arr
);
1570 ARRAYBOUNDSCHECK (arr
, index
);
1571 elements(arr
)[index
] = value
;
1577 jfloat value
= POPF();
1578 jint index
= POPI();
1579 jfloatArray arr
= (jfloatArray
) POPA();
1580 NULLARRAYCHECK (arr
);
1581 ARRAYBOUNDSCHECK (arr
, index
);
1582 elements(arr
)[index
] = value
;
1588 jdouble value
= POPD();
1589 jint index
= POPI();
1590 jdoubleArray arr
= (jdoubleArray
) POPA();
1591 NULLARRAYCHECK (arr
);
1592 ARRAYBOUNDSCHECK (arr
, index
);
1593 elements(arr
)[index
] = value
;
1599 jobject value
= POPA();
1600 jint index
= POPI();
1601 jobjectArray arr
= (jobjectArray
) POPA();
1602 NULLARRAYCHECK (arr
);
1603 ARRAYBOUNDSCHECK (arr
, index
);
1604 _Jv_CheckArrayStore (arr
, value
);
1605 elements(arr
)[index
] = value
;
1611 jbyte value
= (jbyte
) POPI();
1612 jint index
= POPI();
1613 jbyteArray arr
= (jbyteArray
) POPA();
1614 NULLARRAYCHECK (arr
);
1615 ARRAYBOUNDSCHECK (arr
, index
);
1616 elements(arr
)[index
] = value
;
1622 jchar value
= (jchar
) POPI();
1623 jint index
= POPI();
1624 jcharArray arr
= (jcharArray
) POPA();
1625 NULLARRAYCHECK (arr
);
1626 ARRAYBOUNDSCHECK (arr
, index
);
1627 elements(arr
)[index
] = value
;
1633 jshort value
= (jshort
) POPI();
1634 jint index
= POPI();
1635 jshortArray arr
= (jshortArray
) POPA();
1636 NULLARRAYCHECK (arr
);
1637 ARRAYBOUNDSCHECK (arr
, index
);
1638 elements(arr
)[index
] = value
;
1656 dupx (sp
, 1, 1); sp
+=1;
1660 dupx (sp
, 1, 2); sp
+=1;
1670 dupx (sp
, 2, 1); sp
+=2;
1674 dupx (sp
, 2, 2); sp
+=2;
1679 jobject tmp1
= POPA();
1680 jobject tmp2
= POPA();
1736 jint value2
= POPI();
1737 jint value1
= POPI();
1738 jint res
= _Jv_divI (value1
, value2
);
1745 jlong value2
= POPL();
1746 jlong value1
= POPL();
1747 jlong res
= _Jv_divJ (value1
, value2
);
1754 jfloat value2
= POPF();
1755 jfloat value1
= POPF();
1756 jfloat res
= value1
/ value2
;
1763 jdouble value2
= POPD();
1764 jdouble value1
= POPD();
1765 jdouble res
= value1
/ value2
;
1772 jint value2
= POPI();
1773 jint value1
= POPI();
1774 jint res
= _Jv_remI (value1
, value2
);
1781 jlong value2
= POPL();
1782 jlong value1
= POPL();
1783 jlong res
= _Jv_remJ (value1
, value2
);
1790 jfloat value2
= POPF();
1791 jfloat value1
= POPF();
1792 jfloat res
= __ieee754_fmod (value1
, value2
);
1799 jdouble value2
= POPD();
1800 jdouble value1
= POPD();
1801 jdouble res
= __ieee754_fmod (value1
, value2
);
1808 jint value
= POPI();
1815 jlong value
= POPL();
1822 jfloat value
= POPF();
1829 jdouble value
= POPD();
1836 jint shift
= (POPI() & 0x1f);
1837 jint value
= POPI();
1838 PUSHI (value
<< shift
);
1844 jint shift
= (POPI() & 0x3f);
1845 jlong value
= POPL();
1846 PUSHL (value
<< shift
);
1852 jint shift
= (POPI() & 0x1f);
1853 jint value
= POPI();
1854 PUSHI (value
>> shift
);
1860 jint shift
= (POPI() & 0x3f);
1861 jlong value
= POPL();
1862 PUSHL (value
>> shift
);
1868 jint shift
= (POPI() & 0x1f);
1869 unsigned long value
= POPI();
1870 PUSHI ((jint
) (value
>> shift
));
1876 jint shift
= (POPI() & 0x3f);
1877 UINT64 value
= (UINT64
) POPL();
1878 PUSHL ((value
>> shift
));
1908 jint index
= GET1U ();
1909 jint amount
= GET1S ();
1910 locals
[index
].i
+= amount
;
1915 {jlong value
= POPI(); PUSHL (value
);}
1919 {jfloat value
= POPI(); PUSHF (value
);}
1923 {jdouble value
= POPI(); PUSHD (value
);}
1927 {jint value
= POPL(); PUSHI (value
);}
1931 {jfloat value
= POPL(); PUSHF (value
);}
1935 {jdouble value
= POPL(); PUSHD (value
);}
1940 using namespace java::lang
;
1941 jint value
= convert (POPF (), Integer::MIN_VALUE
, Integer::MAX_VALUE
);
1948 using namespace java::lang
;
1949 jlong value
= convert (POPF (), Long::MIN_VALUE
, Long::MAX_VALUE
);
1955 { jdouble value
= POPF (); PUSHD(value
); }
1960 using namespace java::lang
;
1961 jint value
= convert (POPD (), Integer::MIN_VALUE
, Integer::MAX_VALUE
);
1968 using namespace java::lang
;
1969 jlong value
= convert (POPD (), Long::MIN_VALUE
, Long::MAX_VALUE
);
1975 { jfloat value
= POPD (); PUSHF(value
); }
1979 { jbyte value
= POPI (); PUSHI(value
); }
1983 { jchar value
= POPI (); PUSHI(value
); }
1987 { jshort value
= POPI (); PUSHI(value
); }
1992 jlong value2
= POPL ();
1993 jlong value1
= POPL ();
1994 if (value1
> value2
)
1996 else if (value1
== value2
)
2012 jfloat value2
= POPF ();
2013 jfloat value1
= POPF ();
2014 if (value1
> value2
)
2016 else if (value1
== value2
)
2018 else if (value1
< value2
)
2034 jdouble value2
= POPD ();
2035 jdouble value1
= POPD ();
2036 if (value1
> value2
)
2038 else if (value1
== value2
)
2040 else if (value1
< value2
)
2103 jint value2
= POPI();
2104 jint value1
= POPI();
2105 if (value1
== value2
)
2114 jint value2
= POPI();
2115 jint value1
= POPI();
2116 if (value1
!= value2
)
2125 jint value2
= POPI();
2126 jint value1
= POPI();
2127 if (value1
< value2
)
2136 jint value2
= POPI();
2137 jint value1
= POPI();
2138 if (value1
>= value2
)
2147 jint value2
= POPI();
2148 jint value1
= POPI();
2149 if (value1
> value2
)
2158 jint value2
= POPI();
2159 jint value1
= POPI();
2160 if (value1
<= value2
)
2169 jobject value2
= POPA();
2170 jobject value1
= POPA();
2171 if (value1
== value2
)
2180 jobject value2
= POPA();
2181 jobject value1
= POPA();
2182 if (value1
!= value2
)
2190 #ifndef DIRECT_THREADED
2191 // For direct threaded, goto and goto_w are the same.
2192 pc
= pc
- 1 + get4 (pc
);
2194 #endif /* DIRECT_THREADED */
2200 #ifndef DIRECT_THREADED
2201 // For direct threaded, jsr and jsr_w are the same.
2203 pc_t next
= pc
- 1 + get4 (pc
);
2205 PUSHA ((jobject
) pc
);
2209 #endif /* DIRECT_THREADED */
2212 pc_t next
= GOTO_VAL();
2214 PUSHA ((jobject
) pc
);
2221 jint index
= GET1U ();
2222 pc
= (pc_t
) PEEKA (index
);
2228 #ifdef DIRECT_THREADED
2229 void *def
= (pc
++)->datum
;
2233 jint low
= INTVAL ();
2234 jint high
= INTVAL ();
2236 if (index
< low
|| index
> high
)
2237 pc
= (insn_slot
*) def
;
2239 pc
= (insn_slot
*) ((pc
+ index
- low
)->datum
);
2241 pc_t base_pc
= pc
- 1;
2242 int index
= POPI ();
2244 pc_t base
= (pc_t
) bytecode ();
2245 while ((pc
- base
) % 4 != 0)
2248 jint def
= get4 (pc
);
2249 jint low
= get4 (pc
+ 4);
2250 jint high
= get4 (pc
+ 8);
2251 if (index
< low
|| index
> high
)
2254 pc
= base_pc
+ get4 (pc
+ 4 * (index
- low
+ 3));
2255 #endif /* DIRECT_THREADED */
2261 #ifdef DIRECT_THREADED
2262 void *def
= (pc
++)->insn
;
2266 jint npairs
= INTVAL ();
2268 int max
= npairs
- 1;
2271 // Simple binary search...
2274 int half
= (min
+ max
) / 2;
2275 int match
= pc
[2 * half
].int_val
;
2280 pc
= (insn_slot
*) pc
[2 * half
+ 1].datum
;
2283 else if (index
< match
)
2284 // We can use HALF - 1 here because we check again on
2288 // We can use HALF + 1 here because we check again on
2292 if (index
== pc
[2 * min
].int_val
)
2293 pc
= (insn_slot
*) pc
[2 * min
+ 1].datum
;
2295 pc
= (insn_slot
*) def
;
2297 unsigned char *base_pc
= pc
-1;
2300 unsigned char* base
= bytecode ();
2301 while ((pc
-base
) % 4 != 0)
2304 jint def
= get4 (pc
);
2305 jint npairs
= get4 (pc
+4);
2310 // Simple binary search...
2313 int half
= (min
+max
)/2;
2314 int match
= get4 (pc
+ 4*(2 + 2*half
));
2318 else if (index
< match
)
2319 // We can use HALF - 1 here because we check again on
2323 // We can use HALF + 1 here because we check again on
2328 if (index
== get4 (pc
+ 4*(2 + 2*min
)))
2329 pc
= base_pc
+ get4 (pc
+ 4*(2 + 2*min
+ 1));
2332 #endif /* DIRECT_THREADED */
2337 *(jobject
*) retp
= POPA ();
2341 *(jlong
*) retp
= POPL ();
2345 *(jfloat
*) retp
= POPF ();
2349 *(jdouble
*) retp
= POPD ();
2353 *(jint
*) retp
= POPI ();
2361 jint fieldref_index
= GET2U ();
2362 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2363 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2365 if ((field
->flags
& Modifier::STATIC
) == 0)
2366 throw_incompatible_class_change_error
2367 (JvNewStringLatin1 ("field no longer static"));
2369 jclass type
= field
->type
;
2371 // We rewrite the instruction once we discover what it refers
2373 void *newinsn
= NULL
;
2374 if (type
->isPrimitive ())
2376 switch (type
->size_in_bytes
)
2379 PUSHI (*(jbyte
*) (field
->u
.addr
));
2380 newinsn
= AMPAMP (getstatic_resolved_1
);
2384 if (type
== JvPrimClass (char))
2386 PUSHI(*(jchar
*) (field
->u
.addr
));
2387 newinsn
= AMPAMP (getstatic_resolved_char
);
2391 PUSHI(*(jshort
*) (field
->u
.addr
));
2392 newinsn
= AMPAMP (getstatic_resolved_short
);
2397 PUSHI(*(jint
*) (field
->u
.addr
));
2398 newinsn
= AMPAMP (getstatic_resolved_4
);
2402 PUSHL(*(jlong
*) (field
->u
.addr
));
2403 newinsn
= AMPAMP (getstatic_resolved_8
);
2409 PUSHA(*(jobject
*) (field
->u
.addr
));
2410 newinsn
= AMPAMP (getstatic_resolved_obj
);
2413 #ifdef DIRECT_THREADED
2414 pc
[-2].insn
= newinsn
;
2415 pc
[-1].datum
= field
->u
.addr
;
2416 #endif /* DIRECT_THREADED */
2420 #ifdef DIRECT_THREADED
2421 getstatic_resolved_1
:
2422 PUSHI (*(jbyte
*) AVAL ());
2425 getstatic_resolved_char
:
2426 PUSHI (*(jchar
*) AVAL ());
2429 getstatic_resolved_short
:
2430 PUSHI (*(jshort
*) AVAL ());
2433 getstatic_resolved_4
:
2434 PUSHI (*(jint
*) AVAL ());
2437 getstatic_resolved_8
:
2438 PUSHL (*(jlong
*) AVAL ());
2441 getstatic_resolved_obj
:
2442 PUSHA (*(jobject
*) AVAL ());
2444 #endif /* DIRECT_THREADED */
2448 jint fieldref_index
= GET2U ();
2449 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2450 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2452 if ((field
->flags
& Modifier::STATIC
) != 0)
2453 throw_incompatible_class_change_error
2454 (JvNewStringLatin1 ("field is static"));
2456 jclass type
= field
->type
;
2457 jint field_offset
= field
->u
.boffset
;
2458 if (field_offset
> 0xffff)
2459 throw new java::lang::VirtualMachineError
;
2461 jobject obj
= POPA();
2464 void *newinsn
= NULL
;
2465 if (type
->isPrimitive ())
2467 switch (type
->size_in_bytes
)
2470 PUSHI (*(jbyte
*) ((char*)obj
+ field_offset
));
2471 newinsn
= AMPAMP (getfield_resolved_1
);
2475 if (type
== JvPrimClass (char))
2477 PUSHI (*(jchar
*) ((char*)obj
+ field_offset
));
2478 newinsn
= AMPAMP (getfield_resolved_char
);
2482 PUSHI (*(jshort
*) ((char*)obj
+ field_offset
));
2483 newinsn
= AMPAMP (getfield_resolved_short
);
2488 PUSHI (*(jint
*) ((char*)obj
+ field_offset
));
2489 newinsn
= AMPAMP (getfield_resolved_4
);
2493 PUSHL(*(jlong
*) ((char*)obj
+ field_offset
));
2494 newinsn
= AMPAMP (getfield_resolved_8
);
2500 PUSHA(*(jobject
*) ((char*)obj
+ field_offset
));
2501 newinsn
= AMPAMP (getfield_resolved_obj
);
2504 #ifdef DIRECT_THREADED
2505 pc
[-2].insn
= newinsn
;
2506 pc
[-1].int_val
= field_offset
;
2507 #endif /* DIRECT_THREADED */
2511 #ifdef DIRECT_THREADED
2512 getfield_resolved_1
:
2514 char *obj
= (char *) POPA ();
2516 PUSHI (*(jbyte
*) (obj
+ INTVAL ()));
2520 getfield_resolved_char
:
2522 char *obj
= (char *) POPA ();
2524 PUSHI (*(jchar
*) (obj
+ INTVAL ()));
2528 getfield_resolved_short
:
2530 char *obj
= (char *) POPA ();
2532 PUSHI (*(jshort
*) (obj
+ INTVAL ()));
2536 getfield_resolved_4
:
2538 char *obj
= (char *) POPA ();
2540 PUSHI (*(jint
*) (obj
+ INTVAL ()));
2544 getfield_resolved_8
:
2546 char *obj
= (char *) POPA ();
2548 PUSHL (*(jlong
*) (obj
+ INTVAL ()));
2552 getfield_resolved_obj
:
2554 char *obj
= (char *) POPA ();
2556 PUSHA (*(jobject
*) (obj
+ INTVAL ()));
2559 #endif /* DIRECT_THREADED */
2563 jint fieldref_index
= GET2U ();
2564 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2565 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2567 jclass type
= field
->type
;
2569 // ResolvePoolEntry cannot check this
2570 if ((field
->flags
& Modifier::STATIC
) == 0)
2571 throw_incompatible_class_change_error
2572 (JvNewStringLatin1 ("field no longer static"));
2574 void *newinsn
= NULL
;
2575 if (type
->isPrimitive ())
2577 switch (type
->size_in_bytes
)
2581 jint value
= POPI();
2582 *(jbyte
*) (field
->u
.addr
) = value
;
2583 newinsn
= AMPAMP (putstatic_resolved_1
);
2589 jint value
= POPI();
2590 *(jchar
*) (field
->u
.addr
) = value
;
2591 newinsn
= AMPAMP (putstatic_resolved_2
);
2597 jint value
= POPI();
2598 *(jint
*) (field
->u
.addr
) = value
;
2599 newinsn
= AMPAMP (putstatic_resolved_4
);
2605 jlong value
= POPL();
2606 *(jlong
*) (field
->u
.addr
) = value
;
2607 newinsn
= AMPAMP (putstatic_resolved_8
);
2614 jobject value
= POPA();
2615 *(jobject
*) (field
->u
.addr
) = value
;
2616 newinsn
= AMPAMP (putstatic_resolved_obj
);
2619 #ifdef DIRECT_THREADED
2620 pc
[-2].insn
= newinsn
;
2621 pc
[-1].datum
= field
->u
.addr
;
2622 #endif /* DIRECT_THREADED */
2626 #ifdef DIRECT_THREADED
2627 putstatic_resolved_1
:
2628 *(jbyte
*) AVAL () = POPI ();
2631 putstatic_resolved_2
:
2632 *(jchar
*) AVAL () = POPI ();
2635 putstatic_resolved_4
:
2636 *(jint
*) AVAL () = POPI ();
2639 putstatic_resolved_8
:
2640 *(jlong
*) AVAL () = POPL ();
2643 putstatic_resolved_obj
:
2644 *(jobject
*) AVAL () = POPA ();
2646 #endif /* DIRECT_THREADED */
2650 jint fieldref_index
= GET2U ();
2651 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2652 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2654 jclass type
= field
->type
;
2656 if ((field
->flags
& Modifier::STATIC
) != 0)
2657 throw_incompatible_class_change_error
2658 (JvNewStringLatin1 ("field is static"));
2660 jint field_offset
= field
->u
.boffset
;
2661 if (field_offset
> 0xffff)
2662 throw new java::lang::VirtualMachineError
;
2664 void *newinsn
= NULL
;
2665 if (type
->isPrimitive ())
2667 switch (type
->size_in_bytes
)
2671 jint value
= POPI();
2672 jobject obj
= POPA();
2674 *(jbyte
*) ((char*)obj
+ field_offset
) = value
;
2675 newinsn
= AMPAMP (putfield_resolved_1
);
2681 jint value
= POPI();
2682 jobject obj
= POPA();
2684 *(jchar
*) ((char*)obj
+ field_offset
) = value
;
2685 newinsn
= AMPAMP (putfield_resolved_2
);
2691 jint value
= POPI();
2692 jobject obj
= POPA();
2694 *(jint
*) ((char*)obj
+ field_offset
) = value
;
2695 newinsn
= AMPAMP (putfield_resolved_4
);
2701 jlong value
= POPL();
2702 jobject obj
= POPA();
2704 *(jlong
*) ((char*)obj
+ field_offset
) = value
;
2705 newinsn
= AMPAMP (putfield_resolved_8
);
2712 jobject value
= POPA();
2713 jobject obj
= POPA();
2715 *(jobject
*) ((char*)obj
+ field_offset
) = value
;
2716 newinsn
= AMPAMP (putfield_resolved_obj
);
2719 #ifdef DIRECT_THREADED
2720 pc
[-2].insn
= newinsn
;
2721 pc
[-1].int_val
= field_offset
;
2722 #endif /* DIRECT_THREADED */
2726 #ifdef DIRECT_THREADED
2727 putfield_resolved_1
:
2730 char *obj
= (char *) POPA ();
2732 *(jbyte
*) (obj
+ INTVAL ()) = val
;
2736 putfield_resolved_2
:
2739 char *obj
= (char *) POPA ();
2741 *(jchar
*) (obj
+ INTVAL ()) = val
;
2745 putfield_resolved_4
:
2748 char *obj
= (char *) POPA ();
2750 *(jint
*) (obj
+ INTVAL ()) = val
;
2754 putfield_resolved_8
:
2756 jlong val
= POPL ();
2757 char *obj
= (char *) POPA ();
2759 *(jlong
*) (obj
+ INTVAL ()) = val
;
2763 putfield_resolved_obj
:
2765 jobject val
= POPA ();
2766 char *obj
= (char *) POPA ();
2768 *(jobject
*) (obj
+ INTVAL ()) = val
;
2771 #endif /* DIRECT_THREADED */
2775 int index
= GET2U ();
2777 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2779 sp
-= rmeth
->stack_item_count
;
2781 NULLCHECK (sp
[0].o
);
2783 fun
= (void (*)()) rmeth
->method
->ncode
;
2785 #ifdef DIRECT_THREADED
2786 // Rewrite instruction so that we use a faster pre-resolved
2788 pc
[-2].insn
= &&invokespecial_resolved
;
2789 pc
[-1].datum
= rmeth
;
2790 #endif /* DIRECT_THREADED */
2792 goto perform_invoke
;
2794 #ifdef DIRECT_THREADED
2795 invokespecial_resolved
:
2797 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2798 sp
-= rmeth
->stack_item_count
;
2799 NULLCHECK (sp
[0].o
);
2800 fun
= (void (*)()) rmeth
->method
->ncode
;
2802 goto perform_invoke
;
2803 #endif /* DIRECT_THREADED */
2807 int index
= GET2U ();
2809 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2811 sp
-= rmeth
->stack_item_count
;
2813 _Jv_InitClass (rmeth
->klass
);
2814 fun
= (void (*)()) rmeth
->method
->ncode
;
2816 #ifdef DIRECT_THREADED
2817 // Rewrite instruction so that we use a faster pre-resolved
2819 pc
[-2].insn
= &&invokestatic_resolved
;
2820 pc
[-1].datum
= rmeth
;
2821 #endif /* DIRECT_THREADED */
2823 goto perform_invoke
;
2825 #ifdef DIRECT_THREADED
2826 invokestatic_resolved
:
2828 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2829 sp
-= rmeth
->stack_item_count
;
2830 fun
= (void (*)()) rmeth
->method
->ncode
;
2832 goto perform_invoke
;
2833 #endif /* DIRECT_THREADED */
2835 insn_invokeinterface
:
2837 int index
= GET2U ();
2839 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2841 sp
-= rmeth
->stack_item_count
;
2843 jobject rcv
= sp
[0].o
;
2848 _Jv_LookupInterfaceMethod (rcv
->getClass (),
2849 rmeth
->method
->name
,
2850 rmeth
->method
->signature
);
2852 #ifdef DIRECT_THREADED
2853 // Rewrite instruction so that we use a faster pre-resolved
2855 pc
[-2].insn
= &&invokeinterface_resolved
;
2856 pc
[-1].datum
= rmeth
;
2858 // Skip dummy bytes.
2860 #endif /* DIRECT_THREADED */
2862 goto perform_invoke
;
2864 #ifdef DIRECT_THREADED
2865 invokeinterface_resolved
:
2867 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2868 sp
-= rmeth
->stack_item_count
;
2869 jobject rcv
= sp
[0].o
;
2872 _Jv_LookupInterfaceMethod (rcv
->getClass (),
2873 rmeth
->method
->name
,
2874 rmeth
->method
->signature
);
2876 goto perform_invoke
;
2877 #endif /* DIRECT_THREADED */
2881 int index
= GET2U ();
2882 jclass klass
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2883 _Jv_InitClass (klass
);
2884 jobject res
= _Jv_AllocObject (klass
, klass
->size_in_bytes
);
2887 #ifdef DIRECT_THREADED
2888 pc
[-2].insn
= &&new_resolved
;
2889 pc
[-1].datum
= klass
;
2890 #endif /* DIRECT_THREADED */
2894 #ifdef DIRECT_THREADED
2897 jclass klass
= (jclass
) AVAL ();
2898 jobject res
= _Jv_AllocObject (klass
, klass
->size_in_bytes
);
2902 #endif /* DIRECT_THREADED */
2906 int atype
= GET1U ();
2908 jobject result
= _Jv_NewArray (atype
, size
);
2915 int index
= GET2U ();
2916 jclass klass
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2918 _Jv_InitClass (klass
);
2919 jobject result
= _Jv_NewObjectArray (size
, klass
, 0);
2922 #ifdef DIRECT_THREADED
2923 pc
[-2].insn
= &&anewarray_resolved
;
2924 pc
[-1].datum
= klass
;
2925 #endif /* DIRECT_THREADED */
2929 #ifdef DIRECT_THREADED
2932 jclass klass
= (jclass
) AVAL ();
2934 jobject result
= _Jv_NewObjectArray (size
, klass
, 0);
2938 #endif /* DIRECT_THREADED */
2942 __JArray
*arr
= (__JArray
*)POPA();
2943 NULLARRAYCHECK (arr
);
2944 PUSHI (arr
->length
);
2950 jobject value
= POPA();
2951 throw static_cast<jthrowable
>(value
);
2957 jobject value
= POPA();
2958 jint index
= GET2U ();
2959 jclass to
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2961 if (value
!= NULL
&& ! to
->isInstance (value
))
2962 throw new java::lang::ClassCastException (to
->getName());
2966 #ifdef DIRECT_THREADED
2967 pc
[-2].insn
= &&checkcast_resolved
;
2969 #endif /* DIRECT_THREADED */
2973 #ifdef DIRECT_THREADED
2976 jobject value
= POPA ();
2977 jclass to
= (jclass
) AVAL ();
2978 if (value
!= NULL
&& ! to
->isInstance (value
))
2979 throw new java::lang::ClassCastException (to
->getName());
2983 #endif /* DIRECT_THREADED */
2987 jobject value
= POPA();
2988 jint index
= GET2U ();
2989 jclass to
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2990 PUSHI (to
->isInstance (value
));
2992 #ifdef DIRECT_THREADED
2993 pc
[-2].insn
= &&instanceof_resolved
;
2995 #endif /* DIRECT_THREADED */
2999 #ifdef DIRECT_THREADED
3000 instanceof_resolved
:
3002 jobject value
= POPA ();
3003 jclass to
= (jclass
) AVAL ();
3004 PUSHI (to
->isInstance (value
));
3007 #endif /* DIRECT_THREADED */
3011 jobject value
= POPA();
3013 _Jv_MonitorEnter (value
);
3019 jobject value
= POPA();
3021 _Jv_MonitorExit (value
);
3027 jobject val
= POPA();
3037 jobject val
= POPA();
3045 insn_multianewarray
:
3047 int kind_index
= GET2U ();
3051 = (_Jv_ResolvePoolEntry (defining_class
, kind_index
)).clazz
;
3052 _Jv_InitClass (type
);
3053 jint
*sizes
= (jint
*) __builtin_alloca (sizeof (jint
)*dim
);
3055 for (int i
= dim
- 1; i
>= 0; i
--)
3060 jobject res
= _Jv_NewMultiArray (type
,dim
, sizes
);
3066 #ifndef DIRECT_THREADED
3069 jint the_mod_op
= get1u (pc
++);
3070 jint wide
= get2u (pc
); pc
+= 2;
3111 pc
= (unsigned char*) PEEKA (wide
);
3116 jint amount
= get2s (pc
); pc
+= 2;
3117 jint value
= PEEKI (wide
);
3118 POKEI (wide
, value
+amount
);
3123 throw_internal_error ("illegal bytecode modified by wide");
3127 #endif /* DIRECT_THREADED */
3129 catch (java::lang::Throwable
*ex
)
3131 #ifdef DIRECT_THREADED
3132 void *logical_pc
= (void *) ((insn_slot
*) pc
- 1);
3134 int logical_pc
= pc
- 1 - bytecode ();
3136 _Jv_InterpException
*exc
= exceptions ();
3137 jclass exc_class
= ex
->getClass ();
3139 for (int i
= 0; i
< exc_count
; i
++)
3141 if (PCVAL (exc
[i
].start_pc
) <= logical_pc
3142 && logical_pc
< PCVAL (exc
[i
].end_pc
))
3144 #ifdef DIRECT_THREADED
3145 jclass handler
= (jclass
) exc
[i
].handler_type
.p
;
3147 jclass handler
= NULL
;
3148 if (exc
[i
].handler_type
.i
!= 0)
3149 handler
= (_Jv_ResolvePoolEntry (defining_class
,
3150 exc
[i
].handler_type
.i
)).clazz
;
3151 #endif /* DIRECT_THREADED */
3153 if (handler
== NULL
|| handler
->isAssignableFrom (exc_class
))
3155 #ifdef DIRECT_THREADED
3156 pc
= (insn_slot
*) exc
[i
].handler_pc
.p
;
3158 pc
= bytecode () + exc
[i
].handler_pc
.i
;
3159 #endif /* DIRECT_THREADED */
3161 sp
++->o
= ex
; // Push exception.
3167 // No handler, so re-throw.
3173 throw_internal_error (char *msg
)
3175 throw new java::lang::InternalError (JvNewStringLatin1 (msg
));
3179 throw_incompatible_class_change_error (jstring msg
)
3181 throw new java::lang::IncompatibleClassChangeError (msg
);
3185 static java::lang::NullPointerException
*null_pointer_exc
;
3187 throw_null_pointer_exception ()
3189 if (null_pointer_exc
== NULL
)
3190 null_pointer_exc
= new java::lang::NullPointerException
;
3192 throw null_pointer_exc
;
3196 #endif // INTERPRETER