1 // interpret.cc - Code for the interpreter
3 /* Copyright (C) 1999, 2000, 2001, 2002, 2003 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 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); \
244 _Jv_InterpMethod::run_normal (ffi_cif *,
249 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
250 _this->run (ret, args);
254 _Jv_InterpMethod::run_synch_object (ffi_cif *,
259 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
261 jobject rcv = (jobject) args[0].ptr;
262 JvSynchronize mutex (rcv);
264 _this->run (ret, args);
268 _Jv_InterpMethod::run_class (ffi_cif *,
273 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
274 _Jv_InitClass (_this->defining_class);
275 _this->run (ret, args);
279 _Jv_InterpMethod::run_synch_class (ffi_cif *,
284 _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
286 jclass sync = _this->defining_class;
287 _Jv_InitClass (sync);
288 JvSynchronize mutex (sync);
290 _this->run (ret, args);
293 #ifdef DIRECT_THREADED
294 // "Compile" a method by turning it from bytecode to direct-threaded
297 _Jv_InterpMethod::compile (const void * const *insn_targets)
299 insn_slot *insns = NULL;
301 unsigned char *codestart = bytecode ();
302 unsigned char *end = codestart + code_length;
303 _Jv_word *pool_data = defining_class->constants.data;
305 #define SET_ONE(Field, Value) \
311 insns[next++].Field = Value; \
315 #define SET_INSN(Value) SET_ONE (insn, (void *) Value)
316 #define SET_INT(Value) SET_ONE (int_val, Value)
317 #define SET_DATUM(Value) SET_ONE (datum, Value)
319 // Map from bytecode PC to slot in INSNS.
320 int *pc_mapping = (int *) __builtin_alloca (sizeof (int) * code_length);
321 for (int i = 0; i < code_length; ++i)
324 for (int i = 0; i < 2; ++i)
326 jboolean first_pass = i == 0;
330 insns = (insn_slot *) _Jv_AllocBytes (sizeof (insn_slot) * next);
334 unsigned char *pc = codestart;
337 int base_pc_val = pc - codestart;
339 pc_mapping[base_pc_val] = next;
341 java_opcode opcode = (java_opcode) *pc++;
343 if (opcode == op_nop)
345 SET_INSN (insn_targets[opcode]);
486 case op_monitorenter:
496 // No argument, nothing else to do.
500 SET_INT (get1s (pc));
506 int index = get1u (pc);
508 SET_DATUM (pool_data[index].o);
524 SET_INT (get1u (pc));
529 SET_INT (get1u (pc));
530 SET_INT (get1s (pc + 1));
536 int index = get2u (pc);
538 SET_DATUM (pool_data[index].o);
544 int index = get2u (pc);
546 SET_DATUM (&pool_data[index]);
551 SET_INT (get2s (pc));
563 case op_invokespecial:
564 case op_invokestatic:
565 case op_invokevirtual:
566 SET_INT (get2u (pc));
570 case op_multianewarray:
571 SET_INT (get2u (pc));
572 SET_INT (get1u (pc + 2));
595 int offset = get2s (pc);
598 int new_pc = base_pc_val + offset;
600 bool orig_was_goto = opcode == op_goto;
602 // Thread jumps. We limit the loop count; this lets
603 // us avoid infinite loops if the bytecode contains
604 // such. `10' is arbitrary.
606 while (codestart[new_pc] == op_goto && count-- > 0)
607 new_pc += get2s (&codestart[new_pc + 1]);
609 // If the jump takes us to a `return' instruction and
610 // the original branch was an unconditional goto, then
611 // we hoist the return.
612 opcode = (java_opcode) codestart[new_pc];
614 && (opcode == op_ireturn || opcode == op_lreturn
615 || opcode == op_freturn || opcode == op_dreturn
616 || opcode == op_areturn || opcode == op_return))
619 SET_INSN (insn_targets[opcode]);
622 SET_DATUM (&insns[pc_mapping[new_pc]]);
628 while ((pc - codestart) % 4 != 0)
631 jint def = get4 (pc);
632 SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
638 int high = get4 (pc);
642 for (int i = low; i <= high; ++i)
644 SET_DATUM (&insns[pc_mapping[base_pc_val + get4 (pc)]]);
650 case op_lookupswitch:
652 while ((pc - codestart) % 4 != 0)
655 jint def = get4 (pc);
656 SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
659 jint npairs = get4 (pc);
665 jint match = get4 (pc);
666 jint offset = get4 (pc + 4);
668 SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
674 case op_invokeinterface:
676 jint index = get2u (pc);
678 // We ignore the next two bytes.
686 opcode = (java_opcode) get1u (pc);
688 jint val = get2u (pc);
691 // We implement narrow and wide instructions using the
692 // same code in the interpreter. So we rewrite the
693 // instruction slot here.
695 insns[next - 1].insn = (void *) insn_targets[opcode];
698 if (opcode == op_iinc)
700 SET_INT (get2s (pc));
709 jint offset = get4 (pc);
711 SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
715 // Some "can't happen" cases that we include for
716 // error-checking purposes.
734 case op_getstatic_2s:
735 case op_getstatic_2u:
746 // Now update exceptions.
747 _Jv_InterpException *exc = exceptions ();
748 for (int i = 0; i < exc_count; ++i)
750 exc[i].start_pc.p = &insns[pc_mapping[exc[i].start_pc.i]];
751 exc[i].end_pc.p = &insns[pc_mapping[exc[i].end_pc.i]];
752 exc[i].handler_pc.p = &insns[pc_mapping[exc[i].handler_pc.i]];
753 jclass handler = (_Jv_ResolvePoolEntry (defining_class,
754 exc[i].handler_type.i)).clazz;
755 exc[i].handler_type.p = handler;
760 #endif /* DIRECT_THREADED */
762 // This function exists so that the stack-tracing code can find the
763 // boundaries of the interpreter.
765 _Jv_StartOfInterpreter (void)
770 _Jv_InterpMethod::run (void *retp, ffi_raw *args)
772 using namespace java::lang::reflect;
774 // FRAME_DESC registers this particular invocation as the top-most
775 // interpreter frame. This lets the stack tracing code (for
776 // Throwable) print information about the method being interpreted
777 // rather than about the interpreter itself. FRAME_DESC has a
778 // destructor so it cleans up automatically when the interpreter
780 java::lang::Thread *thread = java::lang::Thread::currentThread();
781 _Jv_MethodChain frame_desc (this,
782 (_Jv_MethodChain **) &thread->interp_frame);
784 _Jv_word stack[max_stack];
785 _Jv_word *sp = stack;
787 _Jv_word locals[max_locals];
789 /* Go straight at it! the ffi raw format matches the internal
790 stack representation exactly. At least, that's the idea.
792 memcpy ((void*) locals, (void*) args, args_raw_size);
794 _Jv_word *pool_data = defining_class->constants.data;
796 /* These three are temporaries for common code used by several
799 _Jv_ResolvedMethod* rmeth;
802 #define INSN_LABEL(op) &&insn_##op
804 static const void *const insn_target[] =
807 INSN_LABEL(aconst_null),
808 INSN_LABEL(iconst_m1),
809 INSN_LABEL(iconst_0),
810 INSN_LABEL(iconst_1),
811 INSN_LABEL(iconst_2),
812 INSN_LABEL(iconst_3),
813 INSN_LABEL(iconst_4),
814 INSN_LABEL(iconst_5),
815 INSN_LABEL(lconst_0),
816 INSN_LABEL(lconst_1),
817 INSN_LABEL(fconst_0),
818 INSN_LABEL(fconst_1),
819 INSN_LABEL(fconst_2),
820 INSN_LABEL(dconst_0),
821 INSN_LABEL(dconst_1),
865 INSN_LABEL(istore_0),
866 INSN_LABEL(istore_1),
867 INSN_LABEL(istore_2),
868 INSN_LABEL(istore_3),
869 INSN_LABEL(lstore_0),
870 INSN_LABEL(lstore_1),
871 INSN_LABEL(lstore_2),
872 INSN_LABEL(lstore_3),
873 INSN_LABEL(fstore_0),
874 INSN_LABEL(fstore_1),
875 INSN_LABEL(fstore_2),
876 INSN_LABEL(fstore_3),
877 INSN_LABEL(dstore_0),
878 INSN_LABEL(dstore_1),
879 INSN_LABEL(dstore_2),
880 INSN_LABEL(dstore_3),
881 INSN_LABEL(astore_0),
882 INSN_LABEL(astore_1),
883 INSN_LABEL(astore_2),
884 INSN_LABEL(astore_3),
965 INSN_LABEL(if_icmpeq),
966 INSN_LABEL(if_icmpne),
967 INSN_LABEL(if_icmplt),
968 INSN_LABEL(if_icmpge),
969 INSN_LABEL(if_icmpgt),
970 INSN_LABEL(if_icmple),
971 INSN_LABEL(if_acmpeq),
972 INSN_LABEL(if_acmpne),
976 INSN_LABEL(tableswitch),
977 INSN_LABEL(lookupswitch),
984 INSN_LABEL(getstatic),
985 INSN_LABEL(putstatic),
986 INSN_LABEL(getfield),
987 INSN_LABEL(putfield),
988 INSN_LABEL(invokevirtual),
989 INSN_LABEL(invokespecial),
990 INSN_LABEL(invokestatic),
991 INSN_LABEL(invokeinterface),
994 INSN_LABEL(newarray),
995 INSN_LABEL(anewarray),
996 INSN_LABEL(arraylength),
998 INSN_LABEL(checkcast),
999 INSN_LABEL(instanceof),
1000 INSN_LABEL(monitorenter),
1001 INSN_LABEL(monitorexit),
1002 #ifdef DIRECT_THREADED
1007 INSN_LABEL(multianewarray),
1009 INSN_LABEL(ifnonnull),
1017 #ifdef DIRECT_THREADED
1019 #define NEXT_INSN goto *((pc++)->insn)
1020 #define INTVAL() ((pc++)->int_val)
1021 #define AVAL() ((pc++)->datum)
1023 #define GET1S() INTVAL ()
1024 #define GET2S() INTVAL ()
1025 #define GET1U() INTVAL ()
1026 #define GET2U() INTVAL ()
1027 #define AVAL1U() AVAL ()
1028 #define AVAL2U() AVAL ()
1029 #define AVAL2UP() AVAL ()
1030 #define SKIP_GOTO ++pc
1031 #define GOTO_VAL() (insn_slot *) pc->datum
1032 #define PCVAL(unionval) unionval.p
1033 #define AMPAMP(label) &&label
1035 // Compile if we must.
1036 if (prepared == NULL)
1037 compile (insn_target);
1038 pc = (insn_slot *) prepared;
1042 #define NEXT_INSN goto *(insn_target[*pc++])
1044 #define GET1S() get1s (pc++)
1045 #define GET2S() (pc += 2, get2s (pc- 2))
1046 #define GET1U() get1u (pc++)
1047 #define GET2U() (pc += 2, get2u (pc - 2))
1048 #define AVAL1U() ({ int index = get1u (pc++); pool_data[index].o; })
1049 #define AVAL2U() ({ int index = get2u (pc); pc += 2; pool_data[index].o; })
1050 #define AVAL2UP() ({ int index = get2u (pc); pc += 2; &pool_data[index]; })
1051 #define SKIP_GOTO pc += 2
1052 #define GOTO_VAL() pc - 1 + get2s (pc)
1053 #define PCVAL(unionval) unionval.i
1054 #define AMPAMP(label) NULL
1058 #endif /* DIRECT_THREADED */
1060 #define TAKE_GOTO pc = GOTO_VAL ()
1064 // We keep nop around. It is used if we're interpreting the
1065 // bytecodes and not doing direct threading.
1069 /* The first few instructions here are ordered according to their
1070 frequency, in the hope that this will improve code locality a
1073 insn_aload_0: // 0x2a
1081 insn_iload_1: // 0x1b
1085 insn_invokevirtual: // 0xb6
1087 int index = GET2U ();
1089 /* _Jv_ResolvePoolEntry returns immediately if the value already
1090 * is resolved. If we want to clutter up the code here to gain
1091 * a little performance, then we can check the corresponding bit
1092 * JV_CONSTANT_ResolvedFlag in the tag directly. For now, I
1093 * don't think it is worth it. */
1095 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
1097 sp -= rmeth->stack_item_count;
1098 // We don't use NULLCHECK here because we can't rely on that
1099 // working if the method is final. So instead we do an
1102 throw new java::lang::NullPointerException;
1104 if (rmeth->vtable_index == -1)
1106 // final methods do not appear in the vtable,
1107 // if it does not appear in the superclass.
1108 fun = (void (*)()) rmeth->method->ncode;
1112 jobject rcv = sp[0].o;
1113 _Jv_VTable *table = *(_Jv_VTable**) rcv;
1114 fun = (void (*)()) table->get_method (rmeth->vtable_index);
1117 #ifdef DIRECT_THREADED
1118 // Rewrite instruction so that we use a faster pre-resolved
1120 pc[-2].insn = &&invokevirtual_resolved;
1121 pc[-1].datum = rmeth;
1122 #endif /* DIRECT_THREADED */
1124 goto perform_invoke;
1126 #ifdef DIRECT_THREADED
1127 invokevirtual_resolved:
1129 rmeth = (_Jv_ResolvedMethod *) AVAL ();
1130 sp -= rmeth->stack_item_count;
1131 // We don't use NULLCHECK here because we can't rely on that
1132 // working if the method is final. So instead we do an
1135 throw new java::lang::NullPointerException;
1137 if (rmeth->vtable_index == -1)
1139 // final methods do not appear in the vtable,
1140 // if it does not appear in the superclass.
1141 fun = (void (*)()) rmeth->method->ncode;
1145 jobject rcv = sp[0].o;
1146 _Jv_VTable *table = *(_Jv_VTable**) rcv;
1147 fun = (void (*)()) table->get_method (rmeth->vtable_index);
1150 goto perform_invoke;
1151 #endif /* DIRECT_THREADED */
1155 /* here goes the magic again... */
1156 ffi_cif *cif = &rmeth->cif;
1157 ffi_raw *raw = (ffi_raw*) sp;
1161 #if FFI_NATIVE_RAW_API
1162 /* We assume that this is only implemented if it's correct */
1163 /* to use it here. On a 64 bit machine, it never is. */
1164 ffi_raw_call (cif, fun, (void*)&rvalue, raw);
1166 ffi_java_raw_call (cif, fun, (void*)&rvalue, raw);
1169 int rtype = cif->rtype->type;
1171 /* the likelyhood of object, int, or void return is very high,
1172 * so those are checked before the switch */
1173 if (rtype == FFI_TYPE_POINTER)
1175 PUSHA (*(jobject*)&rvalue);
1177 else if (rtype == FFI_TYPE_SINT32)
1179 PUSHI (*(jint*)&rvalue);
1181 else if (rtype == FFI_TYPE_VOID)
1189 case FFI_TYPE_SINT8:
1191 jbyte value = (*(jint*)&rvalue) & 0xff;
1196 case FFI_TYPE_SINT16:
1198 jshort value = (*(jint*)&rvalue) & 0xffff;
1203 case FFI_TYPE_UINT16:
1205 jint value = (*(jint*)&rvalue) & 0xffff;
1210 case FFI_TYPE_FLOAT:
1211 PUSHF (*(jfloat*)&rvalue);
1214 case FFI_TYPE_DOUBLE:
1218 case FFI_TYPE_SINT64:
1219 PUSHL (*(jlong*)&rvalue);
1223 throw_internal_error ("unknown return type in invokeXXX");
1290 // For direct threaded, bipush and sipush are the same.
1291 #ifndef DIRECT_THREADED
1294 #endif /* DIRECT_THREADED */
1300 // For direct threaded, ldc and ldc_w are the same.
1301 #ifndef DIRECT_THREADED
1302 PUSHA ((jobject) AVAL1U ());
1304 #endif /* DIRECT_THREADED */
1306 PUSHA ((jobject) AVAL2U ());
1311 void *where = AVAL2UP ();
1312 memcpy (sp, where, 2*sizeof (_Jv_word));
1407 jint index = POPI();
1408 jintArray arr = (jintArray) POPA();
1409 NULLARRAYCHECK (arr);
1410 ARRAYBOUNDSCHECK (arr, index);
1411 PUSHI( elements(arr)[index] );
1417 jint index = POPI();
1418 jlongArray arr = (jlongArray) POPA();
1419 NULLARRAYCHECK (arr);
1420 ARRAYBOUNDSCHECK (arr, index);
1421 PUSHL( elements(arr)[index] );
1427 jint index = POPI();
1428 jfloatArray arr = (jfloatArray) POPA();
1429 NULLARRAYCHECK (arr);
1430 ARRAYBOUNDSCHECK (arr, index);
1431 PUSHF( elements(arr)[index] );
1437 jint index = POPI();
1438 jdoubleArray arr = (jdoubleArray) POPA();
1439 NULLARRAYCHECK (arr);
1440 ARRAYBOUNDSCHECK (arr, index);
1441 PUSHD( elements(arr)[index] );
1447 jint index = POPI();
1448 jobjectArray arr = (jobjectArray) POPA();
1449 NULLARRAYCHECK (arr);
1450 ARRAYBOUNDSCHECK (arr, index);
1451 PUSHA( elements(arr)[index] );
1457 jint index = POPI();
1458 jbyteArray arr = (jbyteArray) POPA();
1459 NULLARRAYCHECK (arr);
1460 ARRAYBOUNDSCHECK (arr, index);
1461 PUSHI( elements(arr)[index] );
1467 jint index = POPI();
1468 jcharArray arr = (jcharArray) POPA();
1469 NULLARRAYCHECK (arr);
1470 ARRAYBOUNDSCHECK (arr, index);
1471 PUSHI( elements(arr)[index] );
1477 jint index = POPI();
1478 jshortArray arr = (jshortArray) POPA();
1479 NULLARRAYCHECK (arr);
1480 ARRAYBOUNDSCHECK (arr, index);
1481 PUSHI( elements(arr)[index] );
1587 jint value = POPI();
1588 jint index = POPI();
1589 jintArray arr = (jintArray) POPA();
1590 NULLARRAYCHECK (arr);
1591 ARRAYBOUNDSCHECK (arr, index);
1592 elements(arr)[index] = value;
1598 jlong value = POPL();
1599 jint index = POPI();
1600 jlongArray arr = (jlongArray) POPA();
1601 NULLARRAYCHECK (arr);
1602 ARRAYBOUNDSCHECK (arr, index);
1603 elements(arr)[index] = value;
1609 jfloat value = POPF();
1610 jint index = POPI();
1611 jfloatArray arr = (jfloatArray) POPA();
1612 NULLARRAYCHECK (arr);
1613 ARRAYBOUNDSCHECK (arr, index);
1614 elements(arr)[index] = value;
1620 jdouble value = POPD();
1621 jint index = POPI();
1622 jdoubleArray arr = (jdoubleArray) POPA();
1623 NULLARRAYCHECK (arr);
1624 ARRAYBOUNDSCHECK (arr, index);
1625 elements(arr)[index] = value;
1631 jobject value = POPA();
1632 jint index = POPI();
1633 jobjectArray arr = (jobjectArray) POPA();
1634 NULLARRAYCHECK (arr);
1635 ARRAYBOUNDSCHECK (arr, index);
1636 _Jv_CheckArrayStore (arr, value);
1637 elements(arr)[index] = value;
1643 jbyte value = (jbyte) POPI();
1644 jint index = POPI();
1645 jbyteArray arr = (jbyteArray) POPA();
1646 NULLARRAYCHECK (arr);
1647 ARRAYBOUNDSCHECK (arr, index);
1648 elements(arr)[index] = value;
1654 jchar value = (jchar) POPI();
1655 jint index = POPI();
1656 jcharArray arr = (jcharArray) POPA();
1657 NULLARRAYCHECK (arr);
1658 ARRAYBOUNDSCHECK (arr, index);
1659 elements(arr)[index] = value;
1665 jshort value = (jshort) POPI();
1666 jint index = POPI();
1667 jshortArray arr = (jshortArray) POPA();
1668 NULLARRAYCHECK (arr);
1669 ARRAYBOUNDSCHECK (arr, index);
1670 elements(arr)[index] = value;
1688 dupx (sp, 1, 1); sp+=1;
1692 dupx (sp, 1, 2); sp+=1;
1702 dupx (sp, 2, 1); sp+=2;
1706 dupx (sp, 2, 2); sp+=2;
1711 jobject tmp1 = POPA();
1712 jobject tmp2 = POPA();
1768 jint value2 = POPI();
1769 jint value1 = POPI();
1770 jint res = _Jv_divI (value1, value2);
1777 jlong value2 = POPL();
1778 jlong value1 = POPL();
1779 jlong res = _Jv_divJ (value1, value2);
1786 jfloat value2 = POPF();
1787 jfloat value1 = POPF();
1788 jfloat res = value1 / value2;
1795 jdouble value2 = POPD();
1796 jdouble value1 = POPD();
1797 jdouble res = value1 / value2;
1804 jint value2 = POPI();
1805 jint value1 = POPI();
1806 jint res = _Jv_remI (value1, value2);
1813 jlong value2 = POPL();
1814 jlong value1 = POPL();
1815 jlong res = _Jv_remJ (value1, value2);
1822 jfloat value2 = POPF();
1823 jfloat value1 = POPF();
1824 jfloat res = __ieee754_fmod (value1, value2);
1831 jdouble value2 = POPD();
1832 jdouble value1 = POPD();
1833 jdouble res = __ieee754_fmod (value1, value2);
1840 jint value = POPI();
1847 jlong value = POPL();
1854 jfloat value = POPF();
1861 jdouble value = POPD();
1868 jint shift = (POPI() & 0x1f);
1869 jint value = POPI();
1870 PUSHI (value << shift);
1876 jint shift = (POPI() & 0x3f);
1877 jlong value = POPL();
1878 PUSHL (value << shift);
1884 jint shift = (POPI() & 0x1f);
1885 jint value = POPI();
1886 PUSHI (value >> shift);
1892 jint shift = (POPI() & 0x3f);
1893 jlong value = POPL();
1894 PUSHL (value >> shift);
1900 jint shift = (POPI() & 0x1f);
1901 _Jv_uint value = (_Jv_uint) POPI();
1902 PUSHI ((jint) (value >> shift));
1908 jint shift = (POPI() & 0x3f);
1909 _Jv_ulong value = (_Jv_ulong) POPL();
1910 PUSHL ((jlong) (value >> shift));
1940 jint index = GET1U ();
1941 jint amount = GET1S ();
1942 locals[index].i += amount;
1947 {jlong value = POPI(); PUSHL (value);}
1951 {jfloat value = POPI(); PUSHF (value);}
1955 {jdouble value = POPI(); PUSHD (value);}
1959 {jint value = POPL(); PUSHI (value);}
1963 {jfloat value = POPL(); PUSHF (value);}
1967 {jdouble value = POPL(); PUSHD (value);}
1972 using namespace java::lang;
1973 jint value = convert (POPF (), Integer::MIN_VALUE, Integer::MAX_VALUE);
1980 using namespace java::lang;
1981 jlong value = convert (POPF (), Long::MIN_VALUE, Long::MAX_VALUE);
1987 { jdouble value = POPF (); PUSHD(value); }
1992 using namespace java::lang;
1993 jint value = convert (POPD (), Integer::MIN_VALUE, Integer::MAX_VALUE);
2000 using namespace java::lang;
2001 jlong value = convert (POPD (), Long::MIN_VALUE, Long::MAX_VALUE);
2007 { jfloat value = POPD (); PUSHF(value); }
2011 { jbyte value = POPI (); PUSHI(value); }
2015 { jchar value = POPI (); PUSHI(value); }
2019 { jshort value = POPI (); PUSHI(value); }
2024 jlong value2 = POPL ();
2025 jlong value1 = POPL ();
2026 if (value1 > value2)
2028 else if (value1 == value2)
2044 jfloat value2 = POPF ();
2045 jfloat value1 = POPF ();
2046 if (value1 > value2)
2048 else if (value1 == value2)
2050 else if (value1 < value2)
2066 jdouble value2 = POPD ();
2067 jdouble value1 = POPD ();
2068 if (value1 > value2)
2070 else if (value1 == value2)
2072 else if (value1 < value2)
2135 jint value2 = POPI();
2136 jint value1 = POPI();
2137 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 jobject value2 = POPA();
2202 jobject value1 = POPA();
2203 if (value1 == value2)
2212 jobject value2 = POPA();
2213 jobject value1 = POPA();
2214 if (value1 != value2)
2222 #ifndef DIRECT_THREADED
2223 // For direct threaded, goto and goto_w are the same.
2224 pc = pc - 1 + get4 (pc);
2226 #endif /* DIRECT_THREADED */
2232 #ifndef DIRECT_THREADED
2233 // For direct threaded, jsr and jsr_w are the same.
2235 pc_t next = pc - 1 + get4 (pc);
2237 PUSHA ((jobject) pc);
2241 #endif /* DIRECT_THREADED */
2244 pc_t next = GOTO_VAL();
2246 PUSHA ((jobject) pc);
2253 jint index = GET1U ();
2254 pc = (pc_t) PEEKA (index);
2260 #ifdef DIRECT_THREADED
2261 void *def = (pc++)->datum;
2265 jint low = INTVAL ();
2266 jint high = INTVAL ();
2268 if (index < low || index > high)
2269 pc = (insn_slot *) def;
2271 pc = (insn_slot *) ((pc + index - low)->datum);
2273 pc_t base_pc = pc - 1;
2274 int index = POPI ();
2276 pc_t base = (pc_t) bytecode ();
2277 while ((pc - base) % 4 != 0)
2280 jint def = get4 (pc);
2281 jint low = get4 (pc + 4);
2282 jint high = get4 (pc + 8);
2283 if (index < low || index > high)
2286 pc = base_pc + get4 (pc + 4 * (index - low + 3));
2287 #endif /* DIRECT_THREADED */
2293 #ifdef DIRECT_THREADED
2294 void *def = (pc++)->insn;
2298 jint npairs = INTVAL ();
2300 int max = npairs - 1;
2303 // Simple binary search...
2306 int half = (min + max) / 2;
2307 int match = pc[2 * half].int_val;
2312 pc = (insn_slot *) pc[2 * half + 1].datum;
2315 else if (index < match)
2316 // We can use HALF - 1 here because we check again on
2320 // We can use HALF + 1 here because we check again on
2324 if (index == pc[2 * min].int_val)
2325 pc = (insn_slot *) pc[2 * min + 1].datum;
2327 pc = (insn_slot *) def;
2329 unsigned char *base_pc = pc-1;
2332 unsigned char* base = bytecode ();
2333 while ((pc-base) % 4 != 0)
2336 jint def = get4 (pc);
2337 jint npairs = get4 (pc+4);
2342 // Simple binary search...
2345 int half = (min+max)/2;
2346 int match = get4 (pc+ 4*(2 + 2*half));
2350 else if (index < match)
2351 // We can use HALF - 1 here because we check again on
2355 // We can use HALF + 1 here because we check again on
2360 if (index == get4 (pc+ 4*(2 + 2*min)))
2361 pc = base_pc + get4 (pc+ 4*(2 + 2*min + 1));
2364 #endif /* DIRECT_THREADED */
2369 *(jobject *) retp = POPA ();
2373 *(jlong *) retp = POPL ();
2377 *(jfloat *) retp = POPF ();
2381 *(jdouble *) retp = POPD ();
2385 *(jint *) retp = POPI ();
2393 jint fieldref_index = GET2U ();
2394 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2395 _Jv_Field *field = pool_data[fieldref_index].field;
2397 if ((field->flags & Modifier::STATIC) == 0)
2398 throw_incompatible_class_change_error
2399 (JvNewStringLatin1 ("field no longer static"));
2401 jclass type = field->type;
2403 // We rewrite the instruction once we discover what it refers
2405 void *newinsn = NULL;
2406 if (type->isPrimitive ())
2408 switch (type->size_in_bytes)
2411 PUSHI (*(jbyte*) (field->u.addr));
2412 newinsn = AMPAMP (getstatic_resolved_1);
2416 if (type == JvPrimClass (char))
2418 PUSHI(*(jchar*) (field->u.addr));
2419 newinsn = AMPAMP (getstatic_resolved_char);
2423 PUSHI(*(jshort*) (field->u.addr));
2424 newinsn = AMPAMP (getstatic_resolved_short);
2429 PUSHI(*(jint*) (field->u.addr));
2430 newinsn = AMPAMP (getstatic_resolved_4);
2434 PUSHL(*(jlong*) (field->u.addr));
2435 newinsn = AMPAMP (getstatic_resolved_8);
2441 PUSHA(*(jobject*) (field->u.addr));
2442 newinsn = AMPAMP (getstatic_resolved_obj);
2445 #ifdef DIRECT_THREADED
2446 pc[-2].insn = newinsn;
2447 pc[-1].datum = field->u.addr;
2448 #endif /* DIRECT_THREADED */
2452 #ifdef DIRECT_THREADED
2453 getstatic_resolved_1:
2454 PUSHI (*(jbyte *) AVAL ());
2457 getstatic_resolved_char:
2458 PUSHI (*(jchar *) AVAL ());
2461 getstatic_resolved_short:
2462 PUSHI (*(jshort *) AVAL ());
2465 getstatic_resolved_4:
2466 PUSHI (*(jint *) AVAL ());
2469 getstatic_resolved_8:
2470 PUSHL (*(jlong *) AVAL ());
2473 getstatic_resolved_obj:
2474 PUSHA (*(jobject *) AVAL ());
2476 #endif /* DIRECT_THREADED */
2480 jint fieldref_index = GET2U ();
2481 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2482 _Jv_Field *field = pool_data[fieldref_index].field;
2484 if ((field->flags & Modifier::STATIC) != 0)
2485 throw_incompatible_class_change_error
2486 (JvNewStringLatin1 ("field is static"));
2488 jclass type = field->type;
2489 jint field_offset = field->u.boffset;
2490 if (field_offset > 0xffff)
2491 throw new java::lang::VirtualMachineError;
2493 jobject obj = POPA();
2496 void *newinsn = NULL;
2497 if (type->isPrimitive ())
2499 switch (type->size_in_bytes)
2502 PUSHI (*(jbyte*) ((char*)obj + field_offset));
2503 newinsn = AMPAMP (getfield_resolved_1);
2507 if (type == JvPrimClass (char))
2509 PUSHI (*(jchar*) ((char*)obj + field_offset));
2510 newinsn = AMPAMP (getfield_resolved_char);
2514 PUSHI (*(jshort*) ((char*)obj + field_offset));
2515 newinsn = AMPAMP (getfield_resolved_short);
2520 PUSHI (*(jint*) ((char*)obj + field_offset));
2521 newinsn = AMPAMP (getfield_resolved_4);
2525 PUSHL(*(jlong*) ((char*)obj + field_offset));
2526 newinsn = AMPAMP (getfield_resolved_8);
2532 PUSHA(*(jobject*) ((char*)obj + field_offset));
2533 newinsn = AMPAMP (getfield_resolved_obj);
2536 #ifdef DIRECT_THREADED
2537 pc[-2].insn = newinsn;
2538 pc[-1].int_val = field_offset;
2539 #endif /* DIRECT_THREADED */
2543 #ifdef DIRECT_THREADED
2544 getfield_resolved_1:
2546 char *obj = (char *) POPA ();
2548 PUSHI (*(jbyte *) (obj + INTVAL ()));
2552 getfield_resolved_char:
2554 char *obj = (char *) POPA ();
2556 PUSHI (*(jchar *) (obj + INTVAL ()));
2560 getfield_resolved_short:
2562 char *obj = (char *) POPA ();
2564 PUSHI (*(jshort *) (obj + INTVAL ()));
2568 getfield_resolved_4:
2570 char *obj = (char *) POPA ();
2572 PUSHI (*(jint *) (obj + INTVAL ()));
2576 getfield_resolved_8:
2578 char *obj = (char *) POPA ();
2580 PUSHL (*(jlong *) (obj + INTVAL ()));
2584 getfield_resolved_obj:
2586 char *obj = (char *) POPA ();
2588 PUSHA (*(jobject *) (obj + INTVAL ()));
2591 #endif /* DIRECT_THREADED */
2595 jint fieldref_index = GET2U ();
2596 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2597 _Jv_Field *field = pool_data[fieldref_index].field;
2599 jclass type = field->type;
2601 // ResolvePoolEntry cannot check this
2602 if ((field->flags & Modifier::STATIC) == 0)
2603 throw_incompatible_class_change_error
2604 (JvNewStringLatin1 ("field no longer static"));
2606 void *newinsn = NULL;
2607 if (type->isPrimitive ())
2609 switch (type->size_in_bytes)
2613 jint value = POPI();
2614 *(jbyte*) (field->u.addr) = value;
2615 newinsn = AMPAMP (putstatic_resolved_1);
2621 jint value = POPI();
2622 *(jchar*) (field->u.addr) = value;
2623 newinsn = AMPAMP (putstatic_resolved_2);
2629 jint value = POPI();
2630 *(jint*) (field->u.addr) = value;
2631 newinsn = AMPAMP (putstatic_resolved_4);
2637 jlong value = POPL();
2638 *(jlong*) (field->u.addr) = value;
2639 newinsn = AMPAMP (putstatic_resolved_8);
2646 jobject value = POPA();
2647 *(jobject*) (field->u.addr) = value;
2648 newinsn = AMPAMP (putstatic_resolved_obj);
2651 #ifdef DIRECT_THREADED
2652 pc[-2].insn = newinsn;
2653 pc[-1].datum = field->u.addr;
2654 #endif /* DIRECT_THREADED */
2658 #ifdef DIRECT_THREADED
2659 putstatic_resolved_1:
2660 *(jbyte *) AVAL () = POPI ();
2663 putstatic_resolved_2:
2664 *(jchar *) AVAL () = POPI ();
2667 putstatic_resolved_4:
2668 *(jint *) AVAL () = POPI ();
2671 putstatic_resolved_8:
2672 *(jlong *) AVAL () = POPL ();
2675 putstatic_resolved_obj:
2676 *(jobject *) AVAL () = POPA ();
2678 #endif /* DIRECT_THREADED */
2682 jint fieldref_index = GET2U ();
2683 _Jv_ResolvePoolEntry (defining_class, fieldref_index);
2684 _Jv_Field *field = pool_data[fieldref_index].field;
2686 jclass type = field->type;
2688 if ((field->flags & Modifier::STATIC) != 0)
2689 throw_incompatible_class_change_error
2690 (JvNewStringLatin1 ("field is static"));
2692 jint field_offset = field->u.boffset;
2693 if (field_offset > 0xffff)
2694 throw new java::lang::VirtualMachineError;
2696 void *newinsn = NULL;
2697 if (type->isPrimitive ())
2699 switch (type->size_in_bytes)
2703 jint value = POPI();
2704 jobject obj = POPA();
2706 *(jbyte*) ((char*)obj + field_offset) = value;
2707 newinsn = AMPAMP (putfield_resolved_1);
2713 jint value = POPI();
2714 jobject obj = POPA();
2716 *(jchar*) ((char*)obj + field_offset) = value;
2717 newinsn = AMPAMP (putfield_resolved_2);
2723 jint value = POPI();
2724 jobject obj = POPA();
2726 *(jint*) ((char*)obj + field_offset) = value;
2727 newinsn = AMPAMP (putfield_resolved_4);
2733 jlong value = POPL();
2734 jobject obj = POPA();
2736 *(jlong*) ((char*)obj + field_offset) = value;
2737 newinsn = AMPAMP (putfield_resolved_8);
2744 jobject value = POPA();
2745 jobject obj = POPA();
2747 *(jobject*) ((char*)obj + field_offset) = value;
2748 newinsn = AMPAMP (putfield_resolved_obj);
2751 #ifdef DIRECT_THREADED
2752 pc[-2].insn = newinsn;
2753 pc[-1].int_val = field_offset;
2754 #endif /* DIRECT_THREADED */
2758 #ifdef DIRECT_THREADED
2759 putfield_resolved_1:
2762 char *obj = (char *) POPA ();
2764 *(jbyte *) (obj + INTVAL ()) = val;
2768 putfield_resolved_2:
2771 char *obj = (char *) POPA ();
2773 *(jchar *) (obj + INTVAL ()) = val;
2777 putfield_resolved_4:
2780 char *obj = (char *) POPA ();
2782 *(jint *) (obj + INTVAL ()) = val;
2786 putfield_resolved_8:
2788 jlong val = POPL ();
2789 char *obj = (char *) POPA ();
2791 *(jlong *) (obj + INTVAL ()) = val;
2795 putfield_resolved_obj:
2797 jobject val = POPA ();
2798 char *obj = (char *) POPA ();
2800 *(jobject *) (obj + INTVAL ()) = val;
2803 #endif /* DIRECT_THREADED */
2807 int index = GET2U ();
2809 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
2811 sp -= rmeth->stack_item_count;
2813 // We don't use NULLCHECK here because we can't rely on that
2814 // working for <init>. So instead we do an explicit test.
2816 throw new java::lang::NullPointerException;
2818 fun = (void (*)()) rmeth->method->ncode;
2820 #ifdef DIRECT_THREADED
2821 // Rewrite instruction so that we use a faster pre-resolved
2823 pc[-2].insn = &&invokespecial_resolved;
2824 pc[-1].datum = rmeth;
2825 #endif /* DIRECT_THREADED */
2827 goto perform_invoke;
2829 #ifdef DIRECT_THREADED
2830 invokespecial_resolved:
2832 rmeth = (_Jv_ResolvedMethod *) AVAL ();
2833 sp -= rmeth->stack_item_count;
2834 // We don't use NULLCHECK here because we can't rely on that
2835 // working for <init>. So instead we do an explicit test.
2837 throw new java::lang::NullPointerException;
2838 fun = (void (*)()) rmeth->method->ncode;
2840 goto perform_invoke;
2841 #endif /* DIRECT_THREADED */
2845 int index = GET2U ();
2847 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
2849 sp -= rmeth->stack_item_count;
2851 fun = (void (*)()) rmeth->method->ncode;
2853 #ifdef DIRECT_THREADED
2854 // Rewrite instruction so that we use a faster pre-resolved
2856 pc[-2].insn = &&invokestatic_resolved;
2857 pc[-1].datum = rmeth;
2858 #endif /* DIRECT_THREADED */
2860 goto perform_invoke;
2862 #ifdef DIRECT_THREADED
2863 invokestatic_resolved:
2865 rmeth = (_Jv_ResolvedMethod *) AVAL ();
2866 sp -= rmeth->stack_item_count;
2867 fun = (void (*)()) rmeth->method->ncode;
2869 goto perform_invoke;
2870 #endif /* DIRECT_THREADED */
2872 insn_invokeinterface:
2874 int index = GET2U ();
2876 rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
2878 sp -= rmeth->stack_item_count;
2880 jobject rcv = sp[0].o;
2885 _Jv_LookupInterfaceMethod (rcv->getClass (),
2886 rmeth->method->name,
2887 rmeth->method->signature);
2889 #ifdef DIRECT_THREADED
2890 // Rewrite instruction so that we use a faster pre-resolved
2892 pc[-2].insn = &&invokeinterface_resolved;
2893 pc[-1].datum = rmeth;
2895 // Skip dummy bytes.
2897 #endif /* DIRECT_THREADED */
2899 goto perform_invoke;
2901 #ifdef DIRECT_THREADED
2902 invokeinterface_resolved:
2904 rmeth = (_Jv_ResolvedMethod *) AVAL ();
2905 sp -= rmeth->stack_item_count;
2906 jobject rcv = sp[0].o;
2909 _Jv_LookupInterfaceMethod (rcv->getClass (),
2910 rmeth->method->name,
2911 rmeth->method->signature);
2913 goto perform_invoke;
2914 #endif /* DIRECT_THREADED */
2918 int index = GET2U ();
2919 jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
2920 // We initialize here because otherwise `size_in_bytes' may
2921 // not be set correctly, leading us to pass `0' as the size.
2922 // FIXME: fix in the allocator? There is a PR for this.
2923 _Jv_InitClass (klass);
2924 jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
2927 #ifdef DIRECT_THREADED
2928 pc[-2].insn = &&new_resolved;
2929 pc[-1].datum = klass;
2930 #endif /* DIRECT_THREADED */
2934 #ifdef DIRECT_THREADED
2937 jclass klass = (jclass) AVAL ();
2938 jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
2942 #endif /* DIRECT_THREADED */
2946 int atype = GET1U ();
2948 jobject result = _Jv_NewArray (atype, size);
2955 int index = GET2U ();
2956 jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
2958 jobject result = _Jv_NewObjectArray (size, klass, 0);
2961 #ifdef DIRECT_THREADED
2962 pc[-2].insn = &&anewarray_resolved;
2963 pc[-1].datum = klass;
2964 #endif /* DIRECT_THREADED */
2968 #ifdef DIRECT_THREADED
2971 jclass klass = (jclass) AVAL ();
2973 jobject result = _Jv_NewObjectArray (size, klass, 0);
2977 #endif /* DIRECT_THREADED */
2981 __JArray *arr = (__JArray*)POPA();
2982 NULLARRAYCHECK (arr);
2983 PUSHI (arr->length);
2989 jobject value = POPA();
2990 throw static_cast<jthrowable>(value);
2996 jobject value = POPA();
2997 jint index = GET2U ();
2998 jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
3000 if (value != NULL && ! to->isInstance (value))
3001 throw new java::lang::ClassCastException (to->getName());
3005 #ifdef DIRECT_THREADED
3006 pc[-2].insn = &&checkcast_resolved;
3008 #endif /* DIRECT_THREADED */
3012 #ifdef DIRECT_THREADED
3015 jobject value = POPA ();
3016 jclass to = (jclass) AVAL ();
3017 if (value != NULL && ! to->isInstance (value))
3018 throw new java::lang::ClassCastException (to->getName());
3022 #endif /* DIRECT_THREADED */
3026 jobject value = POPA();
3027 jint index = GET2U ();
3028 jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
3029 PUSHI (to->isInstance (value));
3031 #ifdef DIRECT_THREADED
3032 pc[-2].insn = &&instanceof_resolved;
3034 #endif /* DIRECT_THREADED */
3038 #ifdef DIRECT_THREADED
3039 instanceof_resolved:
3041 jobject value = POPA ();
3042 jclass to = (jclass) AVAL ();
3043 PUSHI (to->isInstance (value));
3046 #endif /* DIRECT_THREADED */
3050 jobject value = POPA();
3052 _Jv_MonitorEnter (value);
3058 jobject value = POPA();
3060 _Jv_MonitorExit (value);
3066 jobject val = POPA();
3076 jobject val = POPA();
3084 insn_multianewarray:
3086 int kind_index = GET2U ();
3090 = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
3091 jint *sizes = (jint*) __builtin_alloca (sizeof (jint)*dim);
3093 for (int i = dim - 1; i >= 0; i--)
3098 jobject res = _Jv_NewMultiArray (type,dim, sizes);
3104 #ifndef DIRECT_THREADED
3107 jint the_mod_op = get1u (pc++);
3108 jint wide = get2u (pc); pc += 2;
3149 pc = (unsigned char*) PEEKA (wide);
3154 jint amount = get2s (pc); pc += 2;
3155 jint value = PEEKI (wide);
3156 POKEI (wide, value+amount);
3161 throw_internal_error ("illegal bytecode modified by wide");
3165 #endif /* DIRECT_THREADED */
3167 catch (java::lang::Throwable *ex)
3169 #ifdef DIRECT_THREADED
3170 void *logical_pc = (void *) ((insn_slot *) pc - 1);
3172 int logical_pc = pc - 1 - bytecode ();
3174 _Jv_InterpException *exc = exceptions ();
3175 jclass exc_class = ex->getClass ();
3177 for (int i = 0; i < exc_count; i++)
3179 if (PCVAL (exc[i].start_pc) <= logical_pc
3180 && logical_pc < PCVAL (exc[i].end_pc))
3182 #ifdef DIRECT_THREADED
3183 jclass handler = (jclass) exc[i].handler_type.p;
3185 jclass handler = NULL;
3186 if (exc[i].handler_type.i != 0)
3187 handler = (_Jv_ResolvePoolEntry (defining_class,
3188 exc[i].handler_type.i)).clazz;
3189 #endif /* DIRECT_THREADED */
3191 if (handler == NULL || handler->isAssignableFrom (exc_class))
3193 #ifdef DIRECT_THREADED
3194 pc = (insn_slot *) exc[i].handler_pc.p;
3196 pc = bytecode () + exc[i].handler_pc.i;
3197 #endif /* DIRECT_THREADED */
3199 sp++->o = ex; // Push exception.
3205 // No handler, so re-throw.
3210 // This function exists so that the stack-tracing code can find the
3211 // boundaries of the interpreter.
3213 _Jv_EndOfInterpreter (void)
3218 throw_internal_error (char *msg)
3220 throw new java::lang::InternalError (JvNewStringLatin1 (msg));
3224 throw_incompatible_class_change_error (jstring msg)
3226 throw new java::lang::IncompatibleClassChangeError (msg);
3230 static java::lang::NullPointerException *null_pointer_exc;
3232 throw_null_pointer_exception ()
3234 if (null_pointer_exc == NULL)
3235 null_pointer_exc = new java::lang::NullPointerException;
3237 throw null_pointer_exc;
3241 #endif // INTERPRETER