1 // interpret.cc - Code for the interpreter
3 /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 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/System.h>
26 #include <java/lang/String.h>
27 #include <java/lang/Integer.h>
28 #include <java/lang/Long.h>
29 #include <java/lang/StringBuffer.h>
30 #include <java/lang/Class.h>
31 #include <java/lang/reflect/Modifier.h>
32 #include <java/lang/ClassCastException.h>
33 #include <java/lang/VirtualMachineError.h>
34 #include <java/lang/InternalError.h>
35 #include <java/lang/NullPointerException.h>
36 #include <java/lang/ArithmeticException.h>
37 #include <java/lang/IncompatibleClassChangeError.h>
38 #include <java/lang/Thread.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 #ifdef DIRECT_THREADED
58 // Lock to ensure that methods are not compiled concurrently.
59 // We could use a finer-grained lock here, however it is not safe to use
60 // the Class monitor as user code in another thread could hold it.
61 static _Jv_Mutex_t compile_mutex;
66 _Jv_MutexInit (&compile_mutex);
69 void _Jv_InitInterpreter() {}
72 extern "C" double __ieee754_fmod (double,double);
74 // This represents a single slot in the "compiled" form of the
80 // An integer value used by an instruction.
82 // A pointer value used by an instruction.
86 // The type of the PC depends on whether we're doing direct threading
87 // or a more ordinary bytecode interpreter.
88 #ifdef DIRECT_THREADED
89 typedef insn_slot *pc_t;
91 typedef unsigned char *pc_t;
94 static inline void dupx (_Jv_word *sp, int n, int x)
96 // first "slide" n+x elements n to the right
98 for (int i = 0; i < n+x; i++)
100 sp[(top-i)] = sp[(top-i)-n];
103 // next, copy the n top elements, n+x down
104 for (int i = 0; i < n; i++)
106 sp[top-(n+x)-i] = sp[top-i];
111 // Used to convert from floating types to integral types.
112 template<typename TO, typename FROM>
114 convert (FROM val, TO min, TO max)
117 if (val >= (FROM) max)
119 else if (val <= (FROM) min)
128 #define PUSHA(V) (sp++)->o = (V)
129 #define PUSHI(V) (sp++)->i = (V)
130 #define PUSHF(V) (sp++)->f = (V)
131 #if SIZEOF_VOID_P == 8
132 # define PUSHL(V) (sp->l = (V), sp += 2)
133 # define PUSHD(V) (sp->d = (V), sp += 2)
135 # define PUSHL(V) do { _Jv_word2 w2; w2.l=(V); \
136 (sp++)->ia[0] = w2.ia[0]; \
137 (sp++)->ia[0] = w2.ia[1]; } while (0)
138 # define PUSHD(V) do { _Jv_word2 w2; w2.d=(V); \
139 (sp++)->ia[0] = w2.ia[0]; \
140 (sp++)->ia[0] = w2.ia[1]; } while (0)
143 #define POPA() ((--sp)->o)
144 #define POPI() ((jint) (--sp)->i) // cast since it may be promoted
145 #define POPF() ((jfloat) (--sp)->f)
146 #if SIZEOF_VOID_P == 8
147 # define POPL() (sp -= 2, (jlong) sp->l)
148 # define POPD() (sp -= 2, (jdouble) sp->d)
150 # define POPL() ({ _Jv_word2 w2; \
151 w2.ia[1] = (--sp)->ia[0]; \
152 w2.ia[0] = (--sp)->ia[0]; w2.l; })
153 # define POPD() ({ _Jv_word2 w2; \
154 w2.ia[1] = (--sp)->ia[0]; \
155 w2.ia[0] = (--sp)->ia[0]; w2.d; })
158 #define LOADA(I) (sp++)->o = locals[I].o
159 #define LOADI(I) (sp++)->i = locals[I].i
160 #define LOADF(I) (sp++)->f = locals[I].f
161 #if SIZEOF_VOID_P == 8
162 # define LOADL(I) (sp->l = locals[I].l, sp += 2)
163 # define LOADD(I) (sp->d = locals[I].d, sp += 2)
165 # define LOADL(I) do { jint __idx = (I); \
166 (sp++)->ia[0] = locals[__idx].ia[0]; \
167 (sp++)->ia[0] = locals[__idx+1].ia[0]; \
169 # define LOADD(I) LOADL(I)
172 #define STOREA(I) locals[I].o = (--sp)->o
173 #define STOREI(I) locals[I].i = (--sp)->i
174 #define STOREF(I) locals[I].f = (--sp)->f
175 #if SIZEOF_VOID_P == 8
176 # define STOREL(I) (sp -= 2, locals[I].l = sp->l)
177 # define STORED(I) (sp -= 2, locals[I].d = sp->d)
179 # define STOREL(I) do { jint __idx = (I); \
180 locals[__idx+1].ia[0] = (--sp)->ia[0]; \
181 locals[__idx].ia[0] = (--sp)->ia[0]; \
183 # define STORED(I) STOREL(I)
186 #define PEEKI(I) (locals+(I))->i
187 #define PEEKA(I) (locals+(I))->o
189 #define POKEI(I,V) ((locals+(I))->i = (V))
192 #define BINOPI(OP) { \
193 jint value2 = POPI(); \
194 jint value1 = POPI(); \
195 PUSHI(value1 OP value2); \
198 #define BINOPF(OP) { \
199 jfloat value2 = POPF(); \
200 jfloat value1 = POPF(); \
201 PUSHF(value1 OP value2); \
204 #define BINOPL(OP) { \
205 jlong value2 = POPL(); \
206 jlong value1 = POPL(); \
207 PUSHL(value1 OP value2); \
210 #define BINOPD(OP) { \
211 jdouble value2 = POPD(); \
212 jdouble value1 = POPD(); \
213 PUSHD(value1 OP value2); \
216 static inline jint get1s(unsigned char* loc) {
217 return *(signed char*)loc;
220 static inline jint get1u(unsigned char* loc) {
224 static inline jint get2s(unsigned char* loc) {
225 return (((jint)*(signed char*)loc) << 8) | ((jint)*(loc+1));
228 static inline jint get2u(unsigned char* loc) {
229 return (((jint)(*loc)) << 8) | ((jint)*(loc+1));
232 static jint get4(unsigned char* loc) {
233 return (((jint)(loc[0])) << 24)
234 | (((jint)(loc[1])) << 16)
235 | (((jint)(loc[2])) << 8)
236 | (((jint)(loc[3])) << 0);
242 #define NULLARRAYCHECK(X)
244 #define NULLCHECK(X) \
245 do { if ((X)==NULL) throw_null_pointer_exception (); } while (0)
246 #define NULLARRAYCHECK(X) \
247 do { if ((X)==NULL) { throw_null_pointer_exception (); } } while (0)
250 #define ARRAYBOUNDSCHECK(array, index) \
253 if (((unsigned) index) >= (unsigned) (array->length)) \
254 _Jv_ThrowBadArrayIndex (index); \
259 _Jv_InterpMethod::run_normal (ffi_cif *,
264 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
265 _this->run (ret, args);
269 _Jv_InterpMethod::run_synch_object (ffi_cif *,
274 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
276 jobject rcv = (jobject) args[0].ptr;
277 JvSynchronize mutex (rcv);
279 _this->run (ret, args);
283 _Jv_InterpMethod::run_class (ffi_cif *,
288 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
289 _Jv_InitClass (_this->defining_class);
290 _this->run (ret, args);
294 _Jv_InterpMethod::run_synch_class (ffi_cif *,
299 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
301 jclass sync = _this->defining_class;
302 _Jv_InitClass (sync);
303 JvSynchronize mutex (sync);
305 _this->run (ret, args);
308 #ifdef DIRECT_THREADED
309 // "Compile" a method by turning it from bytecode to direct-threaded
312 _Jv_InterpMethod::compile (const void * const *insn_targets)
314 insn_slot *insns = NULL;
316 unsigned char *codestart = bytecode ();
317 unsigned char *end = codestart + code_length;
318 _Jv_word *pool_data = defining_class->constants.data;
320 #define SET_ONE(Field, Value) \
326 insns[next++].Field = Value; \
330 #define SET_INSN(Value) SET_ONE (insn, (void *) Value)
331 #define SET_INT(Value) SET_ONE (int_val, Value)
332 #define SET_DATUM(Value) SET_ONE (datum, Value)
334 // Map from bytecode PC to slot in INSNS.
335 int *pc_mapping = (int *) __builtin_alloca (sizeof (int) * code_length);
336 for (int i = 0; i < code_length; ++i)
339 for (int i = 0; i < 2; ++i)
341 jboolean first_pass = i == 0;
345 insns = (insn_slot *) _Jv_AllocBytes (sizeof (insn_slot) * next);
349 unsigned char *pc = codestart;
352 int base_pc_val = pc - codestart;
354 pc_mapping[base_pc_val] = next;
356 java_opcode opcode = (java_opcode) *pc++;
358 if (opcode == op_nop)
360 SET_INSN (insn_targets[opcode]);
501 case op_monitorenter:
511 // No argument, nothing else to do.
515 SET_INT (get1s (pc));
521 int index = get1u (pc);
523 SET_DATUM (pool_data[index].o);
539 SET_INT (get1u (pc));
544 SET_INT (get1u (pc));
545 SET_INT (get1s (pc + 1));
551 int index = get2u (pc);
553 SET_DATUM (pool_data[index].o);
559 int index = get2u (pc);
561 SET_DATUM (&pool_data[index]);
566 SET_INT (get2s (pc));
578 case op_invokespecial:
579 case op_invokestatic:
580 case op_invokevirtual:
581 SET_INT (get2u (pc));
585 case op_multianewarray:
586 SET_INT (get2u (pc));
587 SET_INT (get1u (pc + 2));
610 int offset = get2s (pc);
613 int new_pc = base_pc_val + offset;
615 bool orig_was_goto = opcode == op_goto;
617 // Thread jumps. We limit the loop count; this lets
618 // us avoid infinite loops if the bytecode contains
619 // such. `10' is arbitrary.
621 while (codestart[new_pc] == op_goto && count-- > 0)
622 new_pc += get2s (&codestart[new_pc + 1]);
624 // If the jump takes us to a `return' instruction and
625 // the original branch was an unconditional goto, then
626 // we hoist the return.
627 opcode = (java_opcode) codestart[new_pc];
629 && (opcode == op_ireturn || opcode == op_lreturn
630 || opcode == op_freturn || opcode == op_dreturn
631 || opcode == op_areturn || opcode == op_return))
634 SET_INSN (insn_targets[opcode]);
637 SET_DATUM (&insns[pc_mapping[new_pc]]);
643 while ((pc - codestart) % 4 != 0)
646 jint def = get4 (pc);
647 SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
653 int high = get4 (pc);
657 for (int i = low; i <= high; ++i)
659 SET_DATUM (&insns[pc_mapping[base_pc_val + get4 (pc)]]);
665 case op_lookupswitch:
667 while ((pc - codestart) % 4 != 0)
670 jint def = get4 (pc);
671 SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
674 jint npairs = get4 (pc);
680 jint match = get4 (pc);
681 jint offset = get4 (pc + 4);
683 SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
689 case op_invokeinterface:
691 jint index = get2u (pc);
693 // We ignore the next two bytes.
701 opcode = (java_opcode) get1u (pc);
703 jint val = get2u (pc);
706 // We implement narrow and wide instructions using the
707 // same code in the interpreter. So we rewrite the
708 // instruction slot here.
710 insns[next - 1].insn = (void *) insn_targets[opcode];
713 if (opcode == op_iinc)
715 SET_INT (get2s (pc));
724 jint offset = get4 (pc);
726 SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
730 // Some "can't happen" cases that we include for
731 // error-checking purposes.
749 case op_getstatic_2s:
750 case op_getstatic_2u:
761 // Now update exceptions.
762 _Jv_InterpException *exc = exceptions ();
763 for (int i = 0; i < exc_count; ++i)
765 exc[i].start_pc.p = &insns[pc_mapping[exc[i].start_pc.i]];
766 exc[i].end_pc.p = &insns[pc_mapping[exc[i].end_pc.i]];
767 exc[i].handler_pc.p = &insns[pc_mapping[exc[i].handler_pc.i]];
768 jclass handler = (_Jv_ResolvePoolEntry (defining_class,
769 exc[i].handler_type.i)).clazz;
770 exc[i].handler_type.p = handler;
775 #endif /* DIRECT_THREADED */
777 // This function exists so that the stack-tracing code can find the
778 // boundaries of the interpreter.
780 _Jv_StartOfInterpreter (void)
785 _Jv_InterpMethod::run (void *retp, ffi_raw *args)
787 using namespace java::lang::reflect;
789 // FRAME_DESC registers this particular invocation as the top-most
790 // interpreter frame. This lets the stack tracing code (for
791 // Throwable) print information about the method being interpreted
792 // rather than about the interpreter itself. FRAME_DESC has a
793 // destructor so it cleans up automatically when the interpreter
795 java::lang::Thread *thread = java::lang::Thread::currentThread();
796 _Jv_MethodChain frame_desc (this,
797 (_Jv_MethodChain **) &thread->interp_frame);
799 _Jv_word stack[max_stack];
800 _Jv_word *sp = stack;
802 _Jv_word locals[max_locals];
804 /* Go straight at it! the ffi raw format matches the internal
805 stack representation exactly. At least, that's the idea.
807 memcpy ((void*) locals, (void*) args, args_raw_size);
809 _Jv_word *pool_data = defining_class->constants.data;
811 /* These three are temporaries for common code used by several
814 _Jv_ResolvedMethod* rmeth;
817 #define INSN_LABEL(op) &&insn_##op
819 static const void *const insn_target[] =
822 INSN_LABEL(aconst_null),
823 INSN_LABEL(iconst_m1),
824 INSN_LABEL(iconst_0),
825 INSN_LABEL(iconst_1),
826 INSN_LABEL(iconst_2),
827 INSN_LABEL(iconst_3),
828 INSN_LABEL(iconst_4),
829 INSN_LABEL(iconst_5),
830 INSN_LABEL(lconst_0),
831 INSN_LABEL(lconst_1),
832 INSN_LABEL(fconst_0),
833 INSN_LABEL(fconst_1),
834 INSN_LABEL(fconst_2),
835 INSN_LABEL(dconst_0),
836 INSN_LABEL(dconst_1),
880 INSN_LABEL(istore_0),
881 INSN_LABEL(istore_1),
882 INSN_LABEL(istore_2),
883 INSN_LABEL(istore_3),
884 INSN_LABEL(lstore_0),
885 INSN_LABEL(lstore_1),
886 INSN_LABEL(lstore_2),
887 INSN_LABEL(lstore_3),
888 INSN_LABEL(fstore_0),
889 INSN_LABEL(fstore_1),
890 INSN_LABEL(fstore_2),
891 INSN_LABEL(fstore_3),
892 INSN_LABEL(dstore_0),
893 INSN_LABEL(dstore_1),
894 INSN_LABEL(dstore_2),
895 INSN_LABEL(dstore_3),
896 INSN_LABEL(astore_0),
897 INSN_LABEL(astore_1),
898 INSN_LABEL(astore_2),
899 INSN_LABEL(astore_3),
980 INSN_LABEL(if_icmpeq),
981 INSN_LABEL(if_icmpne),
982 INSN_LABEL(if_icmplt),
983 INSN_LABEL(if_icmpge),
984 INSN_LABEL(if_icmpgt),
985 INSN_LABEL(if_icmple),
986 INSN_LABEL(if_acmpeq),
987 INSN_LABEL(if_acmpne),
991 INSN_LABEL(tableswitch),
992 INSN_LABEL(lookupswitch),
999 INSN_LABEL(getstatic),
1000 INSN_LABEL(putstatic),
1001 INSN_LABEL(getfield),
1002 INSN_LABEL(putfield),
1003 INSN_LABEL(invokevirtual),
1004 INSN_LABEL(invokespecial),
1005 INSN_LABEL(invokestatic),
1006 INSN_LABEL(invokeinterface),
1009 INSN_LABEL(newarray),
1010 INSN_LABEL(anewarray),
1011 INSN_LABEL(arraylength),
1013 INSN_LABEL(checkcast),
1014 INSN_LABEL(instanceof),
1015 INSN_LABEL(monitorenter),
1016 INSN_LABEL(monitorexit),
1017 #ifdef DIRECT_THREADED
1022 INSN_LABEL(multianewarray),
1024 INSN_LABEL(ifnonnull),
1032 #ifdef DIRECT_THREADED
1034 #define NEXT_INSN goto *((pc++)->insn)
1035 #define INTVAL() ((pc++)->int_val)
1036 #define AVAL() ((pc++)->datum)
1038 #define GET1S() INTVAL ()
1039 #define GET2S() INTVAL ()
1040 #define GET1U() INTVAL ()
1041 #define GET2U() INTVAL ()
1042 #define AVAL1U() AVAL ()
1043 #define AVAL2U() AVAL ()
1044 #define AVAL2UP() AVAL ()
1045 #define SKIP_GOTO ++pc
1046 #define GOTO_VAL() (insn_slot *) pc->datum
1047 #define PCVAL(unionval) unionval.p
1048 #define AMPAMP(label) &&label
1050 // Compile if we must. NOTE: Double-check locking.
1051 if (prepared == NULL)
1053 _Jv_MutexLock (&compile_mutex);
1054 if (prepared == NULL)
1055 compile (insn_target);
1056 _Jv_MutexUnlock (&compile_mutex);
1058 pc = (insn_slot *) prepared;
1062 #define NEXT_INSN goto *(insn_target[*pc++])
1064 #define GET1S() get1s (pc++)
1065 #define GET2S() (pc += 2, get2s (pc- 2))
1066 #define GET1U() get1u (pc++)
1067 #define GET2U() (pc += 2, get2u (pc - 2))
1068 #define AVAL1U() ({ int index = get1u (pc++); pool_data[index].o; })
1069 #define AVAL2U() ({ int index = get2u (pc); pc += 2; pool_data[index].o; })
1070 #define AVAL2UP() ({ int index = get2u (pc); pc += 2; &pool_data[index]; })
1071 #define SKIP_GOTO pc += 2
1072 #define GOTO_VAL() pc - 1 + get2s (pc)
1073 #define PCVAL(unionval) unionval.i
1074 #define AMPAMP(label) NULL
1078 #endif /* DIRECT_THREADED */
1080 #define TAKE_GOTO pc = GOTO_VAL ()
1084 // We keep nop around. It is used if we're interpreting the
1085 // bytecodes and not doing direct threading.
1089 /* The first few instructions here are ordered according to their
1090 frequency, in the hope that this will improve code locality a
1093 insn_aload_0: // 0x2a
1101 insn_iload_1: // 0x1b
1105 insn_invokevirtual: // 0xb6
1107 int index = GET2U ();
1109 /* _Jv_ResolvePoolEntry returns immediately if the value already
1110 * is resolved. If we want to clutter up the code here to gain
1111 * a little performance, then we can check the corresponding bit
1112 * JV_CONSTANT_ResolvedFlag in the tag directly. For now, I
1113 * don't think it is worth it. */
1115 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
1117 sp -= rmeth->stack_item_count;
1118 // We don't use NULLCHECK here because we can't rely on that
1119 // working if the method is final. So instead we do an
1122 throw new java::lang::NullPointerException;
1124 if (rmeth->vtable_index == -1)
1126 // final methods do not appear in the vtable,
1127 // if it does not appear in the superclass.
1128 fun = (void (*)()) rmeth->method->ncode;
1132 jobject rcv = sp[0].o;
1133 _Jv_VTable *table = *(_Jv_VTable**) rcv;
1134 fun = (void (*)()) table->get_method (rmeth->vtable_index);
1137 #ifdef DIRECT_THREADED
1138 // Rewrite instruction so that we use a faster pre-resolved
1140 pc[-2].insn = &&invokevirtual_resolved;
1141 pc[-1].datum = rmeth;
1142 #endif /* DIRECT_THREADED */
1144 goto perform_invoke;
1146 #ifdef DIRECT_THREADED
1147 invokevirtual_resolved:
1149 rmeth = (_Jv_ResolvedMethod *) AVAL ();
1150 sp -= rmeth->stack_item_count;
1151 // We don't use NULLCHECK here because we can't rely on that
1152 // working if the method is final. So instead we do an
1155 throw new java::lang::NullPointerException;
1157 if (rmeth->vtable_index == -1)
1159 // final methods do not appear in the vtable,
1160 // if it does not appear in the superclass.
1161 fun = (void (*)()) rmeth->method->ncode;
1165 jobject rcv = sp[0].o;
1166 _Jv_VTable *table = *(_Jv_VTable**) rcv;
1167 fun = (void (*)()) table->get_method (rmeth->vtable_index);
1170 goto perform_invoke;
1171 #endif /* DIRECT_THREADED */
1175 /* here goes the magic again... */
1176 ffi_cif *cif = &rmeth->cif;
1177 ffi_raw *raw = (ffi_raw*) sp;
1181 #if FFI_NATIVE_RAW_API
1182 /* We assume that this is only implemented if it's correct */
1183 /* to use it here. On a 64 bit machine, it never is. */
1184 ffi_raw_call (cif, fun, (void*)&rvalue, raw);
1186 ffi_java_raw_call (cif, fun, (void*)&rvalue, raw);
1189 int rtype = cif->rtype->type;
1191 /* the likelyhood of object, int, or void return is very high,
1192 * so those are checked before the switch */
1193 if (rtype == FFI_TYPE_POINTER)
1195 PUSHA (rvalue.object_value);
1197 else if (rtype == FFI_TYPE_SINT32)
1199 PUSHI (rvalue.int_value);
1201 else if (rtype == FFI_TYPE_VOID)
1209 case FFI_TYPE_SINT8:
1210 PUSHI ((jbyte)(rvalue.int_value & 0xff));
1213 case FFI_TYPE_SINT16:
1214 PUSHI ((jshort)(rvalue.int_value & 0xffff));
1217 case FFI_TYPE_UINT16:
1218 PUSHI (rvalue.int_value & 0xffff);
1221 case FFI_TYPE_FLOAT:
1222 PUSHF (rvalue.float_value);
1225 case FFI_TYPE_DOUBLE:
1226 PUSHD (rvalue.double_value);
1229 case FFI_TYPE_SINT64:
1230 PUSHL (rvalue.long_value);
1234 throw_internal_error ("unknown return type in invokeXXX");
1301 // For direct threaded, bipush and sipush are the same.
1302 #ifndef DIRECT_THREADED
1305 #endif /* DIRECT_THREADED */
1311 // For direct threaded, ldc and ldc_w are the same.
1312 #ifndef DIRECT_THREADED
1313 PUSHA ((jobject) AVAL1U ());
1315 #endif /* DIRECT_THREADED */
1317 PUSHA ((jobject) AVAL2U ());
1322 void *where = AVAL2UP ();
1323 memcpy (sp, where, 2*sizeof (_Jv_word));
1418 jint index = POPI();
1419 jintArray arr = (jintArray) POPA();
1420 NULLARRAYCHECK (arr);
1421 ARRAYBOUNDSCHECK (arr, index);
1422 PUSHI( elements(arr)[index] );
1428 jint index = POPI();
1429 jlongArray arr = (jlongArray) POPA();
1430 NULLARRAYCHECK (arr);
1431 ARRAYBOUNDSCHECK (arr, index);
1432 PUSHL( elements(arr)[index] );
1438 jint index = POPI();
1439 jfloatArray arr = (jfloatArray) POPA();
1440 NULLARRAYCHECK (arr);
1441 ARRAYBOUNDSCHECK (arr, index);
1442 PUSHF( elements(arr)[index] );
1448 jint index = POPI();
1449 jdoubleArray arr = (jdoubleArray) POPA();
1450 NULLARRAYCHECK (arr);
1451 ARRAYBOUNDSCHECK (arr, index);
1452 PUSHD( elements(arr)[index] );
1458 jint index = POPI();
1459 jobjectArray arr = (jobjectArray) POPA();
1460 NULLARRAYCHECK (arr);
1461 ARRAYBOUNDSCHECK (arr, index);
1462 PUSHA( elements(arr)[index] );
1468 jint index = POPI();
1469 jbyteArray arr = (jbyteArray) POPA();
1470 NULLARRAYCHECK (arr);
1471 ARRAYBOUNDSCHECK (arr, index);
1472 PUSHI( elements(arr)[index] );
1478 jint index = POPI();
1479 jcharArray arr = (jcharArray) POPA();
1480 NULLARRAYCHECK (arr);
1481 ARRAYBOUNDSCHECK (arr, index);
1482 PUSHI( elements(arr)[index] );
1488 jint index = POPI();
1489 jshortArray arr = (jshortArray) POPA();
1490 NULLARRAYCHECK (arr);
1491 ARRAYBOUNDSCHECK (arr, index);
1492 PUSHI( elements(arr)[index] );
1598 jint value = POPI();
1599 jint index = POPI();
1600 jintArray arr = (jintArray) POPA();
1601 NULLARRAYCHECK (arr);
1602 ARRAYBOUNDSCHECK (arr, index);
1603 elements(arr)[index] = value;
1609 jlong value = POPL();
1610 jint index = POPI();
1611 jlongArray arr = (jlongArray) POPA();
1612 NULLARRAYCHECK (arr);
1613 ARRAYBOUNDSCHECK (arr, index);
1614 elements(arr)[index] = value;
1620 jfloat value = POPF();
1621 jint index = POPI();
1622 jfloatArray arr = (jfloatArray) POPA();
1623 NULLARRAYCHECK (arr);
1624 ARRAYBOUNDSCHECK (arr, index);
1625 elements(arr)[index] = value;
1631 jdouble value = POPD();
1632 jint index = POPI();
1633 jdoubleArray arr = (jdoubleArray) POPA();
1634 NULLARRAYCHECK (arr);
1635 ARRAYBOUNDSCHECK (arr, index);
1636 elements(arr)[index] = value;
1642 jobject value = POPA();
1643 jint index = POPI();
1644 jobjectArray arr = (jobjectArray) POPA();
1645 NULLARRAYCHECK (arr);
1646 ARRAYBOUNDSCHECK (arr, index);
1647 _Jv_CheckArrayStore (arr, value);
1648 elements(arr)[index] = value;
1654 jbyte value = (jbyte) POPI();
1655 jint index = POPI();
1656 jbyteArray arr = (jbyteArray) POPA();
1657 NULLARRAYCHECK (arr);
1658 ARRAYBOUNDSCHECK (arr, index);
1659 elements(arr)[index] = value;
1665 jchar value = (jchar) POPI();
1666 jint index = POPI();
1667 jcharArray arr = (jcharArray) POPA();
1668 NULLARRAYCHECK (arr);
1669 ARRAYBOUNDSCHECK (arr, index);
1670 elements(arr)[index] = value;
1676 jshort value = (jshort) POPI();
1677 jint index = POPI();
1678 jshortArray arr = (jshortArray) POPA();
1679 NULLARRAYCHECK (arr);
1680 ARRAYBOUNDSCHECK (arr, index);
1681 elements(arr)[index] = value;
1699 dupx (sp, 1, 1); sp+=1;
1703 dupx (sp, 1, 2); sp+=1;
1713 dupx (sp, 2, 1); sp+=2;
1717 dupx (sp, 2, 2); sp+=2;
1722 jobject tmp1 = POPA();
1723 jobject tmp2 = POPA();
1779 jint value2 = POPI();
1780 jint value1 = POPI();
1781 jint res = _Jv_divI (value1, value2);
1788 jlong value2 = POPL();
1789 jlong value1 = POPL();
1790 jlong res = _Jv_divJ (value1, value2);
1797 jfloat value2 = POPF();
1798 jfloat value1 = POPF();
1799 jfloat res = value1 / value2;
1806 jdouble value2 = POPD();
1807 jdouble value1 = POPD();
1808 jdouble res = value1 / value2;
1815 jint value2 = POPI();
1816 jint value1 = POPI();
1817 jint res = _Jv_remI (value1, value2);
1824 jlong value2 = POPL();
1825 jlong value1 = POPL();
1826 jlong res = _Jv_remJ (value1, value2);
1833 jfloat value2 = POPF();
1834 jfloat value1 = POPF();
1835 jfloat res = __ieee754_fmod (value1, value2);
1842 jdouble value2 = POPD();
1843 jdouble value1 = POPD();
1844 jdouble res = __ieee754_fmod (value1, value2);
1851 jint value = POPI();
1858 jlong value = POPL();
1865 jfloat value = POPF();
1872 jdouble value = POPD();
1879 jint shift = (POPI() & 0x1f);
1880 jint value = POPI();
1881 PUSHI (value << shift);
1887 jint shift = (POPI() & 0x3f);
1888 jlong value = POPL();
1889 PUSHL (value << shift);
1895 jint shift = (POPI() & 0x1f);
1896 jint value = POPI();
1897 PUSHI (value >> shift);
1903 jint shift = (POPI() & 0x3f);
1904 jlong value = POPL();
1905 PUSHL (value >> shift);
1911 jint shift = (POPI() & 0x1f);
1912 _Jv_uint value = (_Jv_uint) POPI();
1913 PUSHI ((jint) (value >> shift));
1919 jint shift = (POPI() & 0x3f);
1920 _Jv_ulong value = (_Jv_ulong) POPL();
1921 PUSHL ((jlong) (value >> shift));
1951 jint index = GET1U ();
1952 jint amount = GET1S ();
1953 locals[index].i += amount;
1958 {jlong value = POPI(); PUSHL (value);}
1962 {jfloat value = POPI(); PUSHF (value);}
1966 {jdouble value = POPI(); PUSHD (value);}
1970 {jint value = POPL(); PUSHI (value);}
1974 {jfloat value = POPL(); PUSHF (value);}
1978 {jdouble value = POPL(); PUSHD (value);}
1983 using namespace java::lang;
1984 jint value = convert (POPF (), Integer::MIN_VALUE, Integer::MAX_VALUE);
1991 using namespace java::lang;
1992 jlong value = convert (POPF (), Long::MIN_VALUE, Long::MAX_VALUE);
1998 { jdouble value = POPF (); PUSHD(value); }
2003 using namespace java::lang;
2004 jint value = convert (POPD (), Integer::MIN_VALUE, Integer::MAX_VALUE);
2011 using namespace java::lang;
2012 jlong value = convert (POPD (), Long::MIN_VALUE, Long::MAX_VALUE);
2018 { jfloat value = POPD (); PUSHF(value); }
2022 { jbyte value = POPI (); PUSHI(value); }
2026 { jchar value = POPI (); PUSHI(value); }
2030 { jshort value = POPI (); PUSHI(value); }
2035 jlong value2 = POPL ();
2036 jlong value1 = POPL ();
2037 if (value1 > value2)
2039 else if (value1 == value2)
2055 jfloat value2 = POPF ();
2056 jfloat value1 = POPF ();
2057 if (value1 > value2)
2059 else if (value1 == value2)
2061 else if (value1 < value2)
2077 jdouble value2 = POPD ();
2078 jdouble value1 = POPD ();
2079 if (value1 > value2)
2081 else if (value1 == value2)
2083 else if (value1 < value2)
2146 jint value2 = POPI();
2147 jint value1 = POPI();
2148 if (value1 == value2)
2157 jint value2 = POPI();
2158 jint value1 = POPI();
2159 if (value1 != value2)
2168 jint value2 = POPI();
2169 jint value1 = POPI();
2170 if (value1 < value2)
2179 jint value2 = POPI();
2180 jint value1 = POPI();
2181 if (value1 >= value2)
2190 jint value2 = POPI();
2191 jint value1 = POPI();
2192 if (value1 > value2)
2201 jint value2 = POPI();
2202 jint value1 = POPI();
2203 if (value1 <= value2)
2212 jobject value2 = POPA();
2213 jobject value1 = POPA();
2214 if (value1 == value2)
2223 jobject value2 = POPA();
2224 jobject value1 = POPA();
2225 if (value1 != value2)
2233 #ifndef DIRECT_THREADED
2234 // For direct threaded, goto and goto_w are the same.
2235 pc = pc - 1 + get4 (pc);
2237 #endif /* DIRECT_THREADED */
2243 #ifndef DIRECT_THREADED
2244 // For direct threaded, jsr and jsr_w are the same.
2246 pc_t next = pc - 1 + get4 (pc);
2248 PUSHA ((jobject) pc);
2252 #endif /* DIRECT_THREADED */
2255 pc_t next = GOTO_VAL();
2257 PUSHA ((jobject) pc);
2264 jint index = GET1U ();
2265 pc = (pc_t) PEEKA (index);
2271 #ifdef DIRECT_THREADED
2272 void *def = (pc++)->datum;
2276 jint low = INTVAL ();
2277 jint high = INTVAL ();
2279 if (index < low || index > high)
2280 pc = (insn_slot *) def;
2282 pc = (insn_slot *) ((pc + index - low)->datum);
2284 pc_t base_pc = pc - 1;
2285 int index = POPI ();
2287 pc_t base = (pc_t) bytecode ();
2288 while ((pc - base) % 4 != 0)
2291 jint def = get4 (pc);
2292 jint low = get4 (pc + 4);
2293 jint high = get4 (pc + 8);
2294 if (index < low || index > high)
2297 pc = base_pc + get4 (pc + 4 * (index - low + 3));
2298 #endif /* DIRECT_THREADED */
2304 #ifdef DIRECT_THREADED
2305 void *def = (pc++)->insn;
2309 jint npairs = INTVAL ();
2311 int max = npairs - 1;
2314 // Simple binary search...
2317 int half = (min + max) / 2;
2318 int match = pc[2 * half].int_val;
2323 pc = (insn_slot *) pc[2 * half + 1].datum;
2326 else if (index < match)
2327 // We can use HALF - 1 here because we check again on
2331 // We can use HALF + 1 here because we check again on
2335 if (index == pc[2 * min].int_val)
2336 pc = (insn_slot *) pc[2 * min + 1].datum;
2338 pc = (insn_slot *) def;
2340 unsigned char *base_pc = pc-1;
2343 unsigned char* base = bytecode ();
2344 while ((pc-base) % 4 != 0)
2347 jint def = get4 (pc);
2348 jint npairs = get4 (pc+4);
2353 // Simple binary search...
2356 int half = (min+max)/2;
2357 int match = get4 (pc+ 4*(2 + 2*half));
2361 else if (index < match)
2362 // We can use HALF - 1 here because we check again on
2366 // We can use HALF + 1 here because we check again on
2371 if (index == get4 (pc+ 4*(2 + 2*min)))
2372 pc = base_pc + get4 (pc+ 4*(2 + 2*min + 1));
2375 #endif /* DIRECT_THREADED */
2380 *(jobject *) retp = POPA ();
2384 *(jlong *) retp = POPL ();
2388 *(jfloat *) retp = POPF ();
2392 *(jdouble *) retp = POPD ();
2396 *(jint *) retp = POPI ();
2404 jint fieldref_index = GET2U ();
2405 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2406 _Jv_Field *field = pool_data[fieldref_index].field;
2408 if ((field->flags & Modifier::STATIC) == 0)
2409 throw_incompatible_class_change_error
2410 (JvNewStringLatin1 ("field no longer static"));
2412 jclass type = field->type;
2414 // We rewrite the instruction once we discover what it refers
2416 void *newinsn = NULL;
2417 if (type->isPrimitive ())
2419 switch (type->size_in_bytes)
2422 PUSHI (*field->u.byte_addr);
2423 newinsn = AMPAMP (getstatic_resolved_1);
2427 if (type == JvPrimClass (char))
2429 PUSHI (*field->u.char_addr);
2430 newinsn = AMPAMP (getstatic_resolved_char);
2434 PUSHI (*field->u.short_addr);
2435 newinsn = AMPAMP (getstatic_resolved_short);
2440 PUSHI(*field->u.int_addr);
2441 newinsn = AMPAMP (getstatic_resolved_4);
2445 PUSHL(*field->u.long_addr);
2446 newinsn = AMPAMP (getstatic_resolved_8);
2452 PUSHA(*field->u.object_addr);
2453 newinsn = AMPAMP (getstatic_resolved_obj);
2456 #ifdef DIRECT_THREADED
2457 pc[-2].insn = newinsn;
2458 pc[-1].datum = field->u.addr;
2459 #endif /* DIRECT_THREADED */
2463 #ifdef DIRECT_THREADED
2464 getstatic_resolved_1:
2465 PUSHI (*(jbyte *) AVAL ());
2468 getstatic_resolved_char:
2469 PUSHI (*(jchar *) AVAL ());
2472 getstatic_resolved_short:
2473 PUSHI (*(jshort *) AVAL ());
2476 getstatic_resolved_4:
2477 PUSHI (*(jint *) AVAL ());
2480 getstatic_resolved_8:
2481 PUSHL (*(jlong *) AVAL ());
2484 getstatic_resolved_obj:
2485 PUSHA (*(jobject *) AVAL ());
2487 #endif /* DIRECT_THREADED */
2491 jint fieldref_index = GET2U ();
2492 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2493 _Jv_Field *field = pool_data[fieldref_index].field;
2495 if ((field->flags & Modifier::STATIC) != 0)
2496 throw_incompatible_class_change_error
2497 (JvNewStringLatin1 ("field is static"));
2499 jclass type = field->type;
2500 jint field_offset = field->u.boffset;
2501 if (field_offset > 0xffff)
2502 throw new java::lang::VirtualMachineError;
2504 jobject obj = POPA();
2507 void *newinsn = NULL;
2508 _Jv_value *val = (_Jv_value *) ((char *)obj + field_offset);
2509 if (type->isPrimitive ())
2511 switch (type->size_in_bytes)
2514 PUSHI (val->byte_value);
2515 newinsn = AMPAMP (getfield_resolved_1);
2519 if (type == JvPrimClass (char))
2521 PUSHI (val->char_value);
2522 newinsn = AMPAMP (getfield_resolved_char);
2526 PUSHI (val->short_value);
2527 newinsn = AMPAMP (getfield_resolved_short);
2532 PUSHI (val->int_value);
2533 newinsn = AMPAMP (getfield_resolved_4);
2537 PUSHL (val->long_value);
2538 newinsn = AMPAMP (getfield_resolved_8);
2544 PUSHA (val->object_value);
2545 newinsn = AMPAMP (getfield_resolved_obj);
2548 #ifdef DIRECT_THREADED
2549 pc[-2].insn = newinsn;
2550 pc[-1].int_val = field_offset;
2551 #endif /* DIRECT_THREADED */
2555 #ifdef DIRECT_THREADED
2556 getfield_resolved_1:
2558 char *obj = (char *) POPA ();
2560 PUSHI (*(jbyte *) (obj + INTVAL ()));
2564 getfield_resolved_char:
2566 char *obj = (char *) POPA ();
2568 PUSHI (*(jchar *) (obj + INTVAL ()));
2572 getfield_resolved_short:
2574 char *obj = (char *) POPA ();
2576 PUSHI (*(jshort *) (obj + INTVAL ()));
2580 getfield_resolved_4:
2582 char *obj = (char *) POPA ();
2584 PUSHI (*(jint *) (obj + INTVAL ()));
2588 getfield_resolved_8:
2590 char *obj = (char *) POPA ();
2592 PUSHL (*(jlong *) (obj + INTVAL ()));
2596 getfield_resolved_obj:
2598 char *obj = (char *) POPA ();
2600 PUSHA (*(jobject *) (obj + INTVAL ()));
2603 #endif /* DIRECT_THREADED */
2607 jint fieldref_index = GET2U ();
2608 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2609 _Jv_Field *field = pool_data[fieldref_index].field;
2611 jclass type = field->type;
2613 // ResolvePoolEntry cannot check this
2614 if ((field->flags & Modifier::STATIC) == 0)
2615 throw_incompatible_class_change_error
2616 (JvNewStringLatin1 ("field no longer static"));
2618 void *newinsn = NULL;
2619 if (type->isPrimitive ())
2621 switch (type->size_in_bytes)
2625 jint value = POPI();
2626 *field->u.byte_addr = value;
2627 newinsn = AMPAMP (putstatic_resolved_1);
2633 jint value = POPI();
2634 *field->u.char_addr = value;
2635 newinsn = AMPAMP (putstatic_resolved_2);
2641 jint value = POPI();
2642 *field->u.int_addr = value;
2643 newinsn = AMPAMP (putstatic_resolved_4);
2649 jlong value = POPL();
2650 *field->u.long_addr = value;
2651 newinsn = AMPAMP (putstatic_resolved_8);
2658 jobject value = POPA();
2659 *field->u.object_addr = value;
2660 newinsn = AMPAMP (putstatic_resolved_obj);
2663 #ifdef DIRECT_THREADED
2664 pc[-2].insn = newinsn;
2665 pc[-1].datum = field->u.addr;
2666 #endif /* DIRECT_THREADED */
2670 #ifdef DIRECT_THREADED
2671 putstatic_resolved_1:
2672 *(jbyte *) AVAL () = POPI ();
2675 putstatic_resolved_2:
2676 *(jchar *) AVAL () = POPI ();
2679 putstatic_resolved_4:
2680 *(jint *) AVAL () = POPI ();
2683 putstatic_resolved_8:
2684 *(jlong *) AVAL () = POPL ();
2687 putstatic_resolved_obj:
2688 *(jobject *) AVAL () = POPA ();
2690 #endif /* DIRECT_THREADED */
2694 jint fieldref_index = GET2U ();
2695 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2696 _Jv_Field *field = pool_data[fieldref_index].field;
2698 jclass type = field->type;
2700 if ((field->flags & Modifier::STATIC) != 0)
2701 throw_incompatible_class_change_error
2702 (JvNewStringLatin1 ("field is static"));
2704 jint field_offset = field->u.boffset;
2705 if (field_offset > 0xffff)
2706 throw new java::lang::VirtualMachineError;
2708 void *newinsn = NULL;
2709 if (type->isPrimitive ())
2711 switch (type->size_in_bytes)
2715 jint value = POPI();
2716 jobject obj = POPA();
2718 *(jbyte*) ((char*)obj + field_offset) = value;
2719 newinsn = AMPAMP (putfield_resolved_1);
2725 jint value = POPI();
2726 jobject obj = POPA();
2728 *(jchar*) ((char*)obj + field_offset) = value;
2729 newinsn = AMPAMP (putfield_resolved_2);
2735 jint value = POPI();
2736 jobject obj = POPA();
2738 *(jint*) ((char*)obj + field_offset) = value;
2739 newinsn = AMPAMP (putfield_resolved_4);
2745 jlong value = POPL();
2746 jobject obj = POPA();
2748 *(jlong*) ((char*)obj + field_offset) = value;
2749 newinsn = AMPAMP (putfield_resolved_8);
2756 jobject value = POPA();
2757 jobject obj = POPA();
2759 *(jobject*) ((char*)obj + field_offset) = value;
2760 newinsn = AMPAMP (putfield_resolved_obj);
2763 #ifdef DIRECT_THREADED
2764 pc[-2].insn = newinsn;
2765 pc[-1].int_val = field_offset;
2766 #endif /* DIRECT_THREADED */
2770 #ifdef DIRECT_THREADED
2771 putfield_resolved_1:
2774 char *obj = (char *) POPA ();
2776 *(jbyte *) (obj + INTVAL ()) = val;
2780 putfield_resolved_2:
2783 char *obj = (char *) POPA ();
2785 *(jchar *) (obj + INTVAL ()) = val;
2789 putfield_resolved_4:
2792 char *obj = (char *) POPA ();
2794 *(jint *) (obj + INTVAL ()) = val;
2798 putfield_resolved_8:
2800 jlong val = POPL ();
2801 char *obj = (char *) POPA ();
2803 *(jlong *) (obj + INTVAL ()) = val;
2807 putfield_resolved_obj:
2809 jobject val = POPA ();
2810 char *obj = (char *) POPA ();
2812 *(jobject *) (obj + INTVAL ()) = val;
2815 #endif /* DIRECT_THREADED */
2819 int index = GET2U ();
2821 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
2823 sp -= rmeth->stack_item_count;
2825 // We don't use NULLCHECK here because we can't rely on that
2826 // working for <init>. So instead we do an explicit test.
2828 throw new java::lang::NullPointerException;
2830 fun = (void (*)()) rmeth->method->ncode;
2832 #ifdef DIRECT_THREADED
2833 // Rewrite instruction so that we use a faster pre-resolved
2835 pc[-2].insn = &&invokespecial_resolved;
2836 pc[-1].datum = rmeth;
2837 #endif /* DIRECT_THREADED */
2839 goto perform_invoke;
2841 #ifdef DIRECT_THREADED
2842 invokespecial_resolved:
2844 rmeth = (_Jv_ResolvedMethod *) AVAL ();
2845 sp -= rmeth->stack_item_count;
2846 // We don't use NULLCHECK here because we can't rely on that
2847 // working for <init>. So instead we do an explicit test.
2849 throw new java::lang::NullPointerException;
2850 fun = (void (*)()) rmeth->method->ncode;
2852 goto perform_invoke;
2853 #endif /* DIRECT_THREADED */
2857 int index = GET2U ();
2859 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
2861 sp -= rmeth->stack_item_count;
2863 fun = (void (*)()) rmeth->method->ncode;
2865 #ifdef DIRECT_THREADED
2866 // Rewrite instruction so that we use a faster pre-resolved
2868 pc[-2].insn = &&invokestatic_resolved;
2869 pc[-1].datum = rmeth;
2870 #endif /* DIRECT_THREADED */
2872 goto perform_invoke;
2874 #ifdef DIRECT_THREADED
2875 invokestatic_resolved:
2877 rmeth = (_Jv_ResolvedMethod *) AVAL ();
2878 sp -= rmeth->stack_item_count;
2879 fun = (void (*)()) rmeth->method->ncode;
2881 goto perform_invoke;
2882 #endif /* DIRECT_THREADED */
2884 insn_invokeinterface:
2886 int index = GET2U ();
2888 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
2890 sp -= rmeth->stack_item_count;
2892 jobject rcv = sp[0].o;
2897 _Jv_LookupInterfaceMethod (rcv->getClass (),
2898 rmeth->method->name,
2899 rmeth->method->signature);
2901 #ifdef DIRECT_THREADED
2902 // Rewrite instruction so that we use a faster pre-resolved
2904 pc[-2].insn = &&invokeinterface_resolved;
2905 pc[-1].datum = rmeth;
2907 // Skip dummy bytes.
2909 #endif /* DIRECT_THREADED */
2911 goto perform_invoke;
2913 #ifdef DIRECT_THREADED
2914 invokeinterface_resolved:
2916 rmeth = (_Jv_ResolvedMethod *) AVAL ();
2917 sp -= rmeth->stack_item_count;
2918 jobject rcv = sp[0].o;
2921 _Jv_LookupInterfaceMethod (rcv->getClass (),
2922 rmeth->method->name,
2923 rmeth->method->signature);
2925 goto perform_invoke;
2926 #endif /* DIRECT_THREADED */
2930 int index = GET2U ();
2931 jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
2932 jobject res = _Jv_AllocObject (klass);
2935 #ifdef DIRECT_THREADED
2936 pc[-2].insn = &&new_resolved;
2937 pc[-1].datum = klass;
2938 #endif /* DIRECT_THREADED */
2942 #ifdef DIRECT_THREADED
2945 jclass klass = (jclass) AVAL ();
2946 jobject res = _Jv_AllocObject (klass);
2950 #endif /* DIRECT_THREADED */
2954 int atype = GET1U ();
2956 jobject result = _Jv_NewArray (atype, size);
2963 int index = GET2U ();
2964 jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
2966 jobject result = _Jv_NewObjectArray (size, klass, 0);
2969 #ifdef DIRECT_THREADED
2970 pc[-2].insn = &&anewarray_resolved;
2971 pc[-1].datum = klass;
2972 #endif /* DIRECT_THREADED */
2976 #ifdef DIRECT_THREADED
2979 jclass klass = (jclass) AVAL ();
2981 jobject result = _Jv_NewObjectArray (size, klass, 0);
2985 #endif /* DIRECT_THREADED */
2989 __JArray *arr = (__JArray*)POPA();
2990 NULLARRAYCHECK (arr);
2991 PUSHI (arr->length);
2997 jobject value = POPA();
2998 throw static_cast<jthrowable>(value);
3004 jobject value = POPA();
3005 jint index = GET2U ();
3006 jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
3008 if (value != NULL && ! to->isInstance (value))
3009 throw new java::lang::ClassCastException (to->getName());
3013 #ifdef DIRECT_THREADED
3014 pc[-2].insn = &&checkcast_resolved;
3016 #endif /* DIRECT_THREADED */
3020 #ifdef DIRECT_THREADED
3023 jobject value = POPA ();
3024 jclass to = (jclass) AVAL ();
3025 if (value != NULL && ! to->isInstance (value))
3026 throw new java::lang::ClassCastException (to->getName());
3030 #endif /* DIRECT_THREADED */
3034 jobject value = POPA();
3035 jint index = GET2U ();
3036 jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
3037 PUSHI (to->isInstance (value));
3039 #ifdef DIRECT_THREADED
3040 pc[-2].insn = &&instanceof_resolved;
3042 #endif /* DIRECT_THREADED */
3046 #ifdef DIRECT_THREADED
3047 instanceof_resolved:
3049 jobject value = POPA ();
3050 jclass to = (jclass) AVAL ();
3051 PUSHI (to->isInstance (value));
3054 #endif /* DIRECT_THREADED */
3058 jobject value = POPA();
3060 _Jv_MonitorEnter (value);
3066 jobject value = POPA();
3068 _Jv_MonitorExit (value);
3074 jobject val = POPA();
3084 jobject val = POPA();
3092 insn_multianewarray:
3094 int kind_index = GET2U ();
3098 = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
3099 jint *sizes = (jint*) __builtin_alloca (sizeof (jint)*dim);
3101 for (int i = dim - 1; i >= 0; i--)
3106 jobject res = _Jv_NewMultiArray (type,dim, sizes);
3112 #ifndef DIRECT_THREADED
3115 jint the_mod_op = get1u (pc++);
3116 jint wide = get2u (pc); pc += 2;
3161 pc = (unsigned char*) PEEKA (wide);
3166 jint amount = get2s (pc); pc += 2;
3167 jint value = PEEKI (wide);
3168 POKEI (wide, value+amount);
3173 throw_internal_error ("illegal bytecode modified by wide");
3177 #endif /* DIRECT_THREADED */
3179 catch (java::lang::Throwable *ex)
3181 #ifdef DIRECT_THREADED
3182 void *logical_pc = (void *) ((insn_slot *) pc - 1);
3184 int logical_pc = pc - 1 - bytecode ();
3186 _Jv_InterpException *exc = exceptions ();
3187 jclass exc_class = ex->getClass ();
3189 for (int i = 0; i < exc_count; i++)
3191 if (PCVAL (exc[i].start_pc) <= logical_pc
3192 && logical_pc < PCVAL (exc[i].end_pc))
3194 #ifdef DIRECT_THREADED
3195 jclass handler = (jclass) exc[i].handler_type.p;
3197 jclass handler = NULL;
3198 if (exc[i].handler_type.i != 0)
3199 handler = (_Jv_ResolvePoolEntry (defining_class,
3200 exc[i].handler_type.i)).clazz;
3201 #endif /* DIRECT_THREADED */
3203 if (handler == NULL || handler->isAssignableFrom (exc_class))
3205 #ifdef DIRECT_THREADED
3206 pc = (insn_slot *) exc[i].handler_pc.p;
3208 pc = bytecode () + exc[i].handler_pc.i;
3209 #endif /* DIRECT_THREADED */
3211 sp++->o = ex; // Push exception.
3217 // No handler, so re-throw.
3222 // This function exists so that the stack-tracing code can find the
3223 // boundaries of the interpreter.
3225 _Jv_EndOfInterpreter (void)
3230 throw_internal_error (char *msg)
3232 throw new java::lang::InternalError (JvNewStringLatin1 (msg));
3236 throw_incompatible_class_change_error (jstring msg)
3238 throw new java::lang::IncompatibleClassChangeError (msg);
3242 static java::lang::NullPointerException *null_pointer_exc;
3244 throw_null_pointer_exception ()
3246 if (null_pointer_exc == NULL)
3247 null_pointer_exc = new java::lang::NullPointerException;
3249 throw null_pointer_exc;
3253 #endif // INTERPRETER