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 #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 (*(jobject
*)&rvalue
);
1197 else if (rtype
== FFI_TYPE_SINT32
)
1199 PUSHI (*(jint
*)&rvalue
);
1201 else if (rtype
== FFI_TYPE_VOID
)
1209 case FFI_TYPE_SINT8
:
1211 jbyte value
= (*(jint
*)&rvalue
) & 0xff;
1216 case FFI_TYPE_SINT16
:
1218 jshort value
= (*(jint
*)&rvalue
) & 0xffff;
1223 case FFI_TYPE_UINT16
:
1225 jint value
= (*(jint
*)&rvalue
) & 0xffff;
1230 case FFI_TYPE_FLOAT
:
1231 PUSHF (*(jfloat
*)&rvalue
);
1234 case FFI_TYPE_DOUBLE
:
1238 case FFI_TYPE_SINT64
:
1239 PUSHL (*(jlong
*)&rvalue
);
1243 throw_internal_error ("unknown return type in invokeXXX");
1310 // For direct threaded, bipush and sipush are the same.
1311 #ifndef DIRECT_THREADED
1314 #endif /* DIRECT_THREADED */
1320 // For direct threaded, ldc and ldc_w are the same.
1321 #ifndef DIRECT_THREADED
1322 PUSHA ((jobject
) AVAL1U ());
1324 #endif /* DIRECT_THREADED */
1326 PUSHA ((jobject
) AVAL2U ());
1331 void *where
= AVAL2UP ();
1332 memcpy (sp
, where
, 2*sizeof (_Jv_word
));
1427 jint index
= POPI();
1428 jintArray arr
= (jintArray
) POPA();
1429 NULLARRAYCHECK (arr
);
1430 ARRAYBOUNDSCHECK (arr
, index
);
1431 PUSHI( elements(arr
)[index
] );
1437 jint index
= POPI();
1438 jlongArray arr
= (jlongArray
) POPA();
1439 NULLARRAYCHECK (arr
);
1440 ARRAYBOUNDSCHECK (arr
, index
);
1441 PUSHL( elements(arr
)[index
] );
1447 jint index
= POPI();
1448 jfloatArray arr
= (jfloatArray
) POPA();
1449 NULLARRAYCHECK (arr
);
1450 ARRAYBOUNDSCHECK (arr
, index
);
1451 PUSHF( elements(arr
)[index
] );
1457 jint index
= POPI();
1458 jdoubleArray arr
= (jdoubleArray
) POPA();
1459 NULLARRAYCHECK (arr
);
1460 ARRAYBOUNDSCHECK (arr
, index
);
1461 PUSHD( elements(arr
)[index
] );
1467 jint index
= POPI();
1468 jobjectArray arr
= (jobjectArray
) POPA();
1469 NULLARRAYCHECK (arr
);
1470 ARRAYBOUNDSCHECK (arr
, index
);
1471 PUSHA( elements(arr
)[index
] );
1477 jint index
= POPI();
1478 jbyteArray arr
= (jbyteArray
) POPA();
1479 NULLARRAYCHECK (arr
);
1480 ARRAYBOUNDSCHECK (arr
, index
);
1481 PUSHI( elements(arr
)[index
] );
1487 jint index
= POPI();
1488 jcharArray arr
= (jcharArray
) POPA();
1489 NULLARRAYCHECK (arr
);
1490 ARRAYBOUNDSCHECK (arr
, index
);
1491 PUSHI( elements(arr
)[index
] );
1497 jint index
= POPI();
1498 jshortArray arr
= (jshortArray
) POPA();
1499 NULLARRAYCHECK (arr
);
1500 ARRAYBOUNDSCHECK (arr
, index
);
1501 PUSHI( elements(arr
)[index
] );
1607 jint value
= POPI();
1608 jint index
= POPI();
1609 jintArray arr
= (jintArray
) POPA();
1610 NULLARRAYCHECK (arr
);
1611 ARRAYBOUNDSCHECK (arr
, index
);
1612 elements(arr
)[index
] = value
;
1618 jlong value
= POPL();
1619 jint index
= POPI();
1620 jlongArray arr
= (jlongArray
) POPA();
1621 NULLARRAYCHECK (arr
);
1622 ARRAYBOUNDSCHECK (arr
, index
);
1623 elements(arr
)[index
] = value
;
1629 jfloat value
= POPF();
1630 jint index
= POPI();
1631 jfloatArray arr
= (jfloatArray
) POPA();
1632 NULLARRAYCHECK (arr
);
1633 ARRAYBOUNDSCHECK (arr
, index
);
1634 elements(arr
)[index
] = value
;
1640 jdouble value
= POPD();
1641 jint index
= POPI();
1642 jdoubleArray arr
= (jdoubleArray
) POPA();
1643 NULLARRAYCHECK (arr
);
1644 ARRAYBOUNDSCHECK (arr
, index
);
1645 elements(arr
)[index
] = value
;
1651 jobject value
= POPA();
1652 jint index
= POPI();
1653 jobjectArray arr
= (jobjectArray
) POPA();
1654 NULLARRAYCHECK (arr
);
1655 ARRAYBOUNDSCHECK (arr
, index
);
1656 _Jv_CheckArrayStore (arr
, value
);
1657 elements(arr
)[index
] = value
;
1663 jbyte value
= (jbyte
) POPI();
1664 jint index
= POPI();
1665 jbyteArray arr
= (jbyteArray
) POPA();
1666 NULLARRAYCHECK (arr
);
1667 ARRAYBOUNDSCHECK (arr
, index
);
1668 elements(arr
)[index
] = value
;
1674 jchar value
= (jchar
) POPI();
1675 jint index
= POPI();
1676 jcharArray arr
= (jcharArray
) POPA();
1677 NULLARRAYCHECK (arr
);
1678 ARRAYBOUNDSCHECK (arr
, index
);
1679 elements(arr
)[index
] = value
;
1685 jshort value
= (jshort
) POPI();
1686 jint index
= POPI();
1687 jshortArray arr
= (jshortArray
) POPA();
1688 NULLARRAYCHECK (arr
);
1689 ARRAYBOUNDSCHECK (arr
, index
);
1690 elements(arr
)[index
] = value
;
1708 dupx (sp
, 1, 1); sp
+=1;
1712 dupx (sp
, 1, 2); sp
+=1;
1722 dupx (sp
, 2, 1); sp
+=2;
1726 dupx (sp
, 2, 2); sp
+=2;
1731 jobject tmp1
= POPA();
1732 jobject tmp2
= POPA();
1788 jint value2
= POPI();
1789 jint value1
= POPI();
1790 jint res
= _Jv_divI (value1
, value2
);
1797 jlong value2
= POPL();
1798 jlong value1
= POPL();
1799 jlong res
= _Jv_divJ (value1
, value2
);
1806 jfloat value2
= POPF();
1807 jfloat value1
= POPF();
1808 jfloat res
= value1
/ value2
;
1815 jdouble value2
= POPD();
1816 jdouble value1
= POPD();
1817 jdouble res
= value1
/ value2
;
1824 jint value2
= POPI();
1825 jint value1
= POPI();
1826 jint res
= _Jv_remI (value1
, value2
);
1833 jlong value2
= POPL();
1834 jlong value1
= POPL();
1835 jlong res
= _Jv_remJ (value1
, value2
);
1842 jfloat value2
= POPF();
1843 jfloat value1
= POPF();
1844 jfloat res
= __ieee754_fmod (value1
, value2
);
1851 jdouble value2
= POPD();
1852 jdouble value1
= POPD();
1853 jdouble res
= __ieee754_fmod (value1
, value2
);
1860 jint value
= POPI();
1867 jlong value
= POPL();
1874 jfloat value
= POPF();
1881 jdouble value
= POPD();
1888 jint shift
= (POPI() & 0x1f);
1889 jint value
= POPI();
1890 PUSHI (value
<< shift
);
1896 jint shift
= (POPI() & 0x3f);
1897 jlong value
= POPL();
1898 PUSHL (value
<< shift
);
1904 jint shift
= (POPI() & 0x1f);
1905 jint value
= POPI();
1906 PUSHI (value
>> shift
);
1912 jint shift
= (POPI() & 0x3f);
1913 jlong value
= POPL();
1914 PUSHL (value
>> shift
);
1920 jint shift
= (POPI() & 0x1f);
1921 _Jv_uint value
= (_Jv_uint
) POPI();
1922 PUSHI ((jint
) (value
>> shift
));
1928 jint shift
= (POPI() & 0x3f);
1929 _Jv_ulong value
= (_Jv_ulong
) POPL();
1930 PUSHL ((jlong
) (value
>> shift
));
1960 jint index
= GET1U ();
1961 jint amount
= GET1S ();
1962 locals
[index
].i
+= amount
;
1967 {jlong value
= POPI(); PUSHL (value
);}
1971 {jfloat value
= POPI(); PUSHF (value
);}
1975 {jdouble value
= POPI(); PUSHD (value
);}
1979 {jint value
= POPL(); PUSHI (value
);}
1983 {jfloat value
= POPL(); PUSHF (value
);}
1987 {jdouble value
= POPL(); PUSHD (value
);}
1992 using namespace java::lang
;
1993 jint value
= convert (POPF (), Integer::MIN_VALUE
, Integer::MAX_VALUE
);
2000 using namespace java::lang
;
2001 jlong value
= convert (POPF (), Long::MIN_VALUE
, Long::MAX_VALUE
);
2007 { jdouble value
= POPF (); PUSHD(value
); }
2012 using namespace java::lang
;
2013 jint value
= convert (POPD (), Integer::MIN_VALUE
, Integer::MAX_VALUE
);
2020 using namespace java::lang
;
2021 jlong value
= convert (POPD (), Long::MIN_VALUE
, Long::MAX_VALUE
);
2027 { jfloat value
= POPD (); PUSHF(value
); }
2031 { jbyte value
= POPI (); PUSHI(value
); }
2035 { jchar value
= POPI (); PUSHI(value
); }
2039 { jshort value
= POPI (); PUSHI(value
); }
2044 jlong value2
= POPL ();
2045 jlong value1
= POPL ();
2046 if (value1
> value2
)
2048 else if (value1
== value2
)
2064 jfloat value2
= POPF ();
2065 jfloat value1
= POPF ();
2066 if (value1
> value2
)
2068 else if (value1
== value2
)
2070 else if (value1
< value2
)
2086 jdouble value2
= POPD ();
2087 jdouble value1
= POPD ();
2088 if (value1
> value2
)
2090 else if (value1
== value2
)
2092 else if (value1
< value2
)
2155 jint value2
= POPI();
2156 jint value1
= POPI();
2157 if (value1
== value2
)
2166 jint value2
= POPI();
2167 jint value1
= POPI();
2168 if (value1
!= value2
)
2177 jint value2
= POPI();
2178 jint value1
= POPI();
2179 if (value1
< value2
)
2188 jint value2
= POPI();
2189 jint value1
= POPI();
2190 if (value1
>= value2
)
2199 jint value2
= POPI();
2200 jint value1
= POPI();
2201 if (value1
> value2
)
2210 jint value2
= POPI();
2211 jint value1
= POPI();
2212 if (value1
<= value2
)
2221 jobject value2
= POPA();
2222 jobject value1
= POPA();
2223 if (value1
== value2
)
2232 jobject value2
= POPA();
2233 jobject value1
= POPA();
2234 if (value1
!= value2
)
2242 #ifndef DIRECT_THREADED
2243 // For direct threaded, goto and goto_w are the same.
2244 pc
= pc
- 1 + get4 (pc
);
2246 #endif /* DIRECT_THREADED */
2252 #ifndef DIRECT_THREADED
2253 // For direct threaded, jsr and jsr_w are the same.
2255 pc_t next
= pc
- 1 + get4 (pc
);
2257 PUSHA ((jobject
) pc
);
2261 #endif /* DIRECT_THREADED */
2264 pc_t next
= GOTO_VAL();
2266 PUSHA ((jobject
) pc
);
2273 jint index
= GET1U ();
2274 pc
= (pc_t
) PEEKA (index
);
2280 #ifdef DIRECT_THREADED
2281 void *def
= (pc
++)->datum
;
2285 jint low
= INTVAL ();
2286 jint high
= INTVAL ();
2288 if (index
< low
|| index
> high
)
2289 pc
= (insn_slot
*) def
;
2291 pc
= (insn_slot
*) ((pc
+ index
- low
)->datum
);
2293 pc_t base_pc
= pc
- 1;
2294 int index
= POPI ();
2296 pc_t base
= (pc_t
) bytecode ();
2297 while ((pc
- base
) % 4 != 0)
2300 jint def
= get4 (pc
);
2301 jint low
= get4 (pc
+ 4);
2302 jint high
= get4 (pc
+ 8);
2303 if (index
< low
|| index
> high
)
2306 pc
= base_pc
+ get4 (pc
+ 4 * (index
- low
+ 3));
2307 #endif /* DIRECT_THREADED */
2313 #ifdef DIRECT_THREADED
2314 void *def
= (pc
++)->insn
;
2318 jint npairs
= INTVAL ();
2320 int max
= npairs
- 1;
2323 // Simple binary search...
2326 int half
= (min
+ max
) / 2;
2327 int match
= pc
[2 * half
].int_val
;
2332 pc
= (insn_slot
*) pc
[2 * half
+ 1].datum
;
2335 else if (index
< match
)
2336 // We can use HALF - 1 here because we check again on
2340 // We can use HALF + 1 here because we check again on
2344 if (index
== pc
[2 * min
].int_val
)
2345 pc
= (insn_slot
*) pc
[2 * min
+ 1].datum
;
2347 pc
= (insn_slot
*) def
;
2349 unsigned char *base_pc
= pc
-1;
2352 unsigned char* base
= bytecode ();
2353 while ((pc
-base
) % 4 != 0)
2356 jint def
= get4 (pc
);
2357 jint npairs
= get4 (pc
+4);
2362 // Simple binary search...
2365 int half
= (min
+max
)/2;
2366 int match
= get4 (pc
+ 4*(2 + 2*half
));
2370 else if (index
< match
)
2371 // We can use HALF - 1 here because we check again on
2375 // We can use HALF + 1 here because we check again on
2380 if (index
== get4 (pc
+ 4*(2 + 2*min
)))
2381 pc
= base_pc
+ get4 (pc
+ 4*(2 + 2*min
+ 1));
2384 #endif /* DIRECT_THREADED */
2389 *(jobject
*) retp
= POPA ();
2393 *(jlong
*) retp
= POPL ();
2397 *(jfloat
*) retp
= POPF ();
2401 *(jdouble
*) retp
= POPD ();
2405 *(jint
*) retp
= POPI ();
2413 jint fieldref_index
= GET2U ();
2414 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2415 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2417 if ((field
->flags
& Modifier::STATIC
) == 0)
2418 throw_incompatible_class_change_error
2419 (JvNewStringLatin1 ("field no longer static"));
2421 jclass type
= field
->type
;
2423 // We rewrite the instruction once we discover what it refers
2425 void *newinsn
= NULL
;
2426 if (type
->isPrimitive ())
2428 switch (type
->size_in_bytes
)
2431 PUSHI (*(jbyte
*) (field
->u
.addr
));
2432 newinsn
= AMPAMP (getstatic_resolved_1
);
2436 if (type
== JvPrimClass (char))
2438 PUSHI(*(jchar
*) (field
->u
.addr
));
2439 newinsn
= AMPAMP (getstatic_resolved_char
);
2443 PUSHI(*(jshort
*) (field
->u
.addr
));
2444 newinsn
= AMPAMP (getstatic_resolved_short
);
2449 PUSHI(*(jint
*) (field
->u
.addr
));
2450 newinsn
= AMPAMP (getstatic_resolved_4
);
2454 PUSHL(*(jlong
*) (field
->u
.addr
));
2455 newinsn
= AMPAMP (getstatic_resolved_8
);
2461 PUSHA(*(jobject
*) (field
->u
.addr
));
2462 newinsn
= AMPAMP (getstatic_resolved_obj
);
2465 #ifdef DIRECT_THREADED
2466 pc
[-2].insn
= newinsn
;
2467 pc
[-1].datum
= field
->u
.addr
;
2468 #endif /* DIRECT_THREADED */
2472 #ifdef DIRECT_THREADED
2473 getstatic_resolved_1
:
2474 PUSHI (*(jbyte
*) AVAL ());
2477 getstatic_resolved_char
:
2478 PUSHI (*(jchar
*) AVAL ());
2481 getstatic_resolved_short
:
2482 PUSHI (*(jshort
*) AVAL ());
2485 getstatic_resolved_4
:
2486 PUSHI (*(jint
*) AVAL ());
2489 getstatic_resolved_8
:
2490 PUSHL (*(jlong
*) AVAL ());
2493 getstatic_resolved_obj
:
2494 PUSHA (*(jobject
*) AVAL ());
2496 #endif /* DIRECT_THREADED */
2500 jint fieldref_index
= GET2U ();
2501 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2502 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2504 if ((field
->flags
& Modifier::STATIC
) != 0)
2505 throw_incompatible_class_change_error
2506 (JvNewStringLatin1 ("field is static"));
2508 jclass type
= field
->type
;
2509 jint field_offset
= field
->u
.boffset
;
2510 if (field_offset
> 0xffff)
2511 throw new java::lang::VirtualMachineError
;
2513 jobject obj
= POPA();
2516 void *newinsn
= NULL
;
2517 if (type
->isPrimitive ())
2519 switch (type
->size_in_bytes
)
2522 PUSHI (*(jbyte
*) ((char*)obj
+ field_offset
));
2523 newinsn
= AMPAMP (getfield_resolved_1
);
2527 if (type
== JvPrimClass (char))
2529 PUSHI (*(jchar
*) ((char*)obj
+ field_offset
));
2530 newinsn
= AMPAMP (getfield_resolved_char
);
2534 PUSHI (*(jshort
*) ((char*)obj
+ field_offset
));
2535 newinsn
= AMPAMP (getfield_resolved_short
);
2540 PUSHI (*(jint
*) ((char*)obj
+ field_offset
));
2541 newinsn
= AMPAMP (getfield_resolved_4
);
2545 PUSHL(*(jlong
*) ((char*)obj
+ field_offset
));
2546 newinsn
= AMPAMP (getfield_resolved_8
);
2552 PUSHA(*(jobject
*) ((char*)obj
+ field_offset
));
2553 newinsn
= AMPAMP (getfield_resolved_obj
);
2556 #ifdef DIRECT_THREADED
2557 pc
[-2].insn
= newinsn
;
2558 pc
[-1].int_val
= field_offset
;
2559 #endif /* DIRECT_THREADED */
2563 #ifdef DIRECT_THREADED
2564 getfield_resolved_1
:
2566 char *obj
= (char *) POPA ();
2568 PUSHI (*(jbyte
*) (obj
+ INTVAL ()));
2572 getfield_resolved_char
:
2574 char *obj
= (char *) POPA ();
2576 PUSHI (*(jchar
*) (obj
+ INTVAL ()));
2580 getfield_resolved_short
:
2582 char *obj
= (char *) POPA ();
2584 PUSHI (*(jshort
*) (obj
+ INTVAL ()));
2588 getfield_resolved_4
:
2590 char *obj
= (char *) POPA ();
2592 PUSHI (*(jint
*) (obj
+ INTVAL ()));
2596 getfield_resolved_8
:
2598 char *obj
= (char *) POPA ();
2600 PUSHL (*(jlong
*) (obj
+ INTVAL ()));
2604 getfield_resolved_obj
:
2606 char *obj
= (char *) POPA ();
2608 PUSHA (*(jobject
*) (obj
+ INTVAL ()));
2611 #endif /* DIRECT_THREADED */
2615 jint fieldref_index
= GET2U ();
2616 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2617 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2619 jclass type
= field
->type
;
2621 // ResolvePoolEntry cannot check this
2622 if ((field
->flags
& Modifier::STATIC
) == 0)
2623 throw_incompatible_class_change_error
2624 (JvNewStringLatin1 ("field no longer static"));
2626 void *newinsn
= NULL
;
2627 if (type
->isPrimitive ())
2629 switch (type
->size_in_bytes
)
2633 jint value
= POPI();
2634 *(jbyte
*) (field
->u
.addr
) = value
;
2635 newinsn
= AMPAMP (putstatic_resolved_1
);
2641 jint value
= POPI();
2642 *(jchar
*) (field
->u
.addr
) = value
;
2643 newinsn
= AMPAMP (putstatic_resolved_2
);
2649 jint value
= POPI();
2650 *(jint
*) (field
->u
.addr
) = value
;
2651 newinsn
= AMPAMP (putstatic_resolved_4
);
2657 jlong value
= POPL();
2658 *(jlong
*) (field
->u
.addr
) = value
;
2659 newinsn
= AMPAMP (putstatic_resolved_8
);
2666 jobject value
= POPA();
2667 *(jobject
*) (field
->u
.addr
) = value
;
2668 newinsn
= AMPAMP (putstatic_resolved_obj
);
2671 #ifdef DIRECT_THREADED
2672 pc
[-2].insn
= newinsn
;
2673 pc
[-1].datum
= field
->u
.addr
;
2674 #endif /* DIRECT_THREADED */
2678 #ifdef DIRECT_THREADED
2679 putstatic_resolved_1
:
2680 *(jbyte
*) AVAL () = POPI ();
2683 putstatic_resolved_2
:
2684 *(jchar
*) AVAL () = POPI ();
2687 putstatic_resolved_4
:
2688 *(jint
*) AVAL () = POPI ();
2691 putstatic_resolved_8
:
2692 *(jlong
*) AVAL () = POPL ();
2695 putstatic_resolved_obj
:
2696 *(jobject
*) AVAL () = POPA ();
2698 #endif /* DIRECT_THREADED */
2702 jint fieldref_index
= GET2U ();
2703 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2704 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2706 jclass type
= field
->type
;
2708 if ((field
->flags
& Modifier::STATIC
) != 0)
2709 throw_incompatible_class_change_error
2710 (JvNewStringLatin1 ("field is static"));
2712 jint field_offset
= field
->u
.boffset
;
2713 if (field_offset
> 0xffff)
2714 throw new java::lang::VirtualMachineError
;
2716 void *newinsn
= NULL
;
2717 if (type
->isPrimitive ())
2719 switch (type
->size_in_bytes
)
2723 jint value
= POPI();
2724 jobject obj
= POPA();
2726 *(jbyte
*) ((char*)obj
+ field_offset
) = value
;
2727 newinsn
= AMPAMP (putfield_resolved_1
);
2733 jint value
= POPI();
2734 jobject obj
= POPA();
2736 *(jchar
*) ((char*)obj
+ field_offset
) = value
;
2737 newinsn
= AMPAMP (putfield_resolved_2
);
2743 jint value
= POPI();
2744 jobject obj
= POPA();
2746 *(jint
*) ((char*)obj
+ field_offset
) = value
;
2747 newinsn
= AMPAMP (putfield_resolved_4
);
2753 jlong value
= POPL();
2754 jobject obj
= POPA();
2756 *(jlong
*) ((char*)obj
+ field_offset
) = value
;
2757 newinsn
= AMPAMP (putfield_resolved_8
);
2764 jobject value
= POPA();
2765 jobject obj
= POPA();
2767 *(jobject
*) ((char*)obj
+ field_offset
) = value
;
2768 newinsn
= AMPAMP (putfield_resolved_obj
);
2771 #ifdef DIRECT_THREADED
2772 pc
[-2].insn
= newinsn
;
2773 pc
[-1].int_val
= field_offset
;
2774 #endif /* DIRECT_THREADED */
2778 #ifdef DIRECT_THREADED
2779 putfield_resolved_1
:
2782 char *obj
= (char *) POPA ();
2784 *(jbyte
*) (obj
+ INTVAL ()) = val
;
2788 putfield_resolved_2
:
2791 char *obj
= (char *) POPA ();
2793 *(jchar
*) (obj
+ INTVAL ()) = val
;
2797 putfield_resolved_4
:
2800 char *obj
= (char *) POPA ();
2802 *(jint
*) (obj
+ INTVAL ()) = val
;
2806 putfield_resolved_8
:
2808 jlong val
= POPL ();
2809 char *obj
= (char *) POPA ();
2811 *(jlong
*) (obj
+ INTVAL ()) = val
;
2815 putfield_resolved_obj
:
2817 jobject val
= POPA ();
2818 char *obj
= (char *) POPA ();
2820 *(jobject
*) (obj
+ INTVAL ()) = val
;
2823 #endif /* DIRECT_THREADED */
2827 int index
= GET2U ();
2829 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2831 sp
-= rmeth
->stack_item_count
;
2833 // We don't use NULLCHECK here because we can't rely on that
2834 // working for <init>. So instead we do an explicit test.
2836 throw new java::lang::NullPointerException
;
2838 fun
= (void (*)()) rmeth
->method
->ncode
;
2840 #ifdef DIRECT_THREADED
2841 // Rewrite instruction so that we use a faster pre-resolved
2843 pc
[-2].insn
= &&invokespecial_resolved
;
2844 pc
[-1].datum
= rmeth
;
2845 #endif /* DIRECT_THREADED */
2847 goto perform_invoke
;
2849 #ifdef DIRECT_THREADED
2850 invokespecial_resolved
:
2852 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2853 sp
-= rmeth
->stack_item_count
;
2854 // We don't use NULLCHECK here because we can't rely on that
2855 // working for <init>. So instead we do an explicit test.
2857 throw new java::lang::NullPointerException
;
2858 fun
= (void (*)()) rmeth
->method
->ncode
;
2860 goto perform_invoke
;
2861 #endif /* DIRECT_THREADED */
2865 int index
= GET2U ();
2867 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2869 sp
-= rmeth
->stack_item_count
;
2871 fun
= (void (*)()) rmeth
->method
->ncode
;
2873 #ifdef DIRECT_THREADED
2874 // Rewrite instruction so that we use a faster pre-resolved
2876 pc
[-2].insn
= &&invokestatic_resolved
;
2877 pc
[-1].datum
= rmeth
;
2878 #endif /* DIRECT_THREADED */
2880 goto perform_invoke
;
2882 #ifdef DIRECT_THREADED
2883 invokestatic_resolved
:
2885 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2886 sp
-= rmeth
->stack_item_count
;
2887 fun
= (void (*)()) rmeth
->method
->ncode
;
2889 goto perform_invoke
;
2890 #endif /* DIRECT_THREADED */
2892 insn_invokeinterface
:
2894 int index
= GET2U ();
2896 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2898 sp
-= rmeth
->stack_item_count
;
2900 jobject rcv
= sp
[0].o
;
2905 _Jv_LookupInterfaceMethod (rcv
->getClass (),
2906 rmeth
->method
->name
,
2907 rmeth
->method
->signature
);
2909 #ifdef DIRECT_THREADED
2910 // Rewrite instruction so that we use a faster pre-resolved
2912 pc
[-2].insn
= &&invokeinterface_resolved
;
2913 pc
[-1].datum
= rmeth
;
2915 // Skip dummy bytes.
2917 #endif /* DIRECT_THREADED */
2919 goto perform_invoke
;
2921 #ifdef DIRECT_THREADED
2922 invokeinterface_resolved
:
2924 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2925 sp
-= rmeth
->stack_item_count
;
2926 jobject rcv
= sp
[0].o
;
2929 _Jv_LookupInterfaceMethod (rcv
->getClass (),
2930 rmeth
->method
->name
,
2931 rmeth
->method
->signature
);
2933 goto perform_invoke
;
2934 #endif /* DIRECT_THREADED */
2938 int index
= GET2U ();
2939 jclass klass
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2940 // We initialize here because otherwise `size_in_bytes' may
2941 // not be set correctly, leading us to pass `0' as the size.
2942 // FIXME: fix in the allocator? There is a PR for this.
2943 _Jv_InitClass (klass
);
2944 jobject res
= _Jv_AllocObject (klass
, klass
->size_in_bytes
);
2947 #ifdef DIRECT_THREADED
2948 pc
[-2].insn
= &&new_resolved
;
2949 pc
[-1].datum
= klass
;
2950 #endif /* DIRECT_THREADED */
2954 #ifdef DIRECT_THREADED
2957 jclass klass
= (jclass
) AVAL ();
2958 jobject res
= _Jv_AllocObject (klass
, klass
->size_in_bytes
);
2962 #endif /* DIRECT_THREADED */
2966 int atype
= GET1U ();
2968 jobject result
= _Jv_NewArray (atype
, size
);
2975 int index
= GET2U ();
2976 jclass klass
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2978 jobject result
= _Jv_NewObjectArray (size
, klass
, 0);
2981 #ifdef DIRECT_THREADED
2982 pc
[-2].insn
= &&anewarray_resolved
;
2983 pc
[-1].datum
= klass
;
2984 #endif /* DIRECT_THREADED */
2988 #ifdef DIRECT_THREADED
2991 jclass klass
= (jclass
) AVAL ();
2993 jobject result
= _Jv_NewObjectArray (size
, klass
, 0);
2997 #endif /* DIRECT_THREADED */
3001 __JArray
*arr
= (__JArray
*)POPA();
3002 NULLARRAYCHECK (arr
);
3003 PUSHI (arr
->length
);
3009 jobject value
= POPA();
3010 throw static_cast<jthrowable
>(value
);
3016 jobject value
= POPA();
3017 jint index
= GET2U ();
3018 jclass to
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
3020 if (value
!= NULL
&& ! to
->isInstance (value
))
3021 throw new java::lang::ClassCastException (to
->getName());
3025 #ifdef DIRECT_THREADED
3026 pc
[-2].insn
= &&checkcast_resolved
;
3028 #endif /* DIRECT_THREADED */
3032 #ifdef DIRECT_THREADED
3035 jobject value
= POPA ();
3036 jclass to
= (jclass
) AVAL ();
3037 if (value
!= NULL
&& ! to
->isInstance (value
))
3038 throw new java::lang::ClassCastException (to
->getName());
3042 #endif /* DIRECT_THREADED */
3046 jobject value
= POPA();
3047 jint index
= GET2U ();
3048 jclass to
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
3049 PUSHI (to
->isInstance (value
));
3051 #ifdef DIRECT_THREADED
3052 pc
[-2].insn
= &&instanceof_resolved
;
3054 #endif /* DIRECT_THREADED */
3058 #ifdef DIRECT_THREADED
3059 instanceof_resolved
:
3061 jobject value
= POPA ();
3062 jclass to
= (jclass
) AVAL ();
3063 PUSHI (to
->isInstance (value
));
3066 #endif /* DIRECT_THREADED */
3070 jobject value
= POPA();
3072 _Jv_MonitorEnter (value
);
3078 jobject value
= POPA();
3080 _Jv_MonitorExit (value
);
3086 jobject val
= POPA();
3096 jobject val
= POPA();
3104 insn_multianewarray
:
3106 int kind_index
= GET2U ();
3110 = (_Jv_ResolvePoolEntry (defining_class
, kind_index
)).clazz
;
3111 jint
*sizes
= (jint
*) __builtin_alloca (sizeof (jint
)*dim
);
3113 for (int i
= dim
- 1; i
>= 0; i
--)
3118 jobject res
= _Jv_NewMultiArray (type
,dim
, sizes
);
3124 #ifndef DIRECT_THREADED
3127 jint the_mod_op
= get1u (pc
++);
3128 jint wide
= get2u (pc
); pc
+= 2;
3169 pc
= (unsigned char*) PEEKA (wide
);
3174 jint amount
= get2s (pc
); pc
+= 2;
3175 jint value
= PEEKI (wide
);
3176 POKEI (wide
, value
+amount
);
3181 throw_internal_error ("illegal bytecode modified by wide");
3185 #endif /* DIRECT_THREADED */
3187 catch (java::lang::Throwable
*ex
)
3189 #ifdef DIRECT_THREADED
3190 void *logical_pc
= (void *) ((insn_slot
*) pc
- 1);
3192 int logical_pc
= pc
- 1 - bytecode ();
3194 _Jv_InterpException
*exc
= exceptions ();
3195 jclass exc_class
= ex
->getClass ();
3197 for (int i
= 0; i
< exc_count
; i
++)
3199 if (PCVAL (exc
[i
].start_pc
) <= logical_pc
3200 && logical_pc
< PCVAL (exc
[i
].end_pc
))
3202 #ifdef DIRECT_THREADED
3203 jclass handler
= (jclass
) exc
[i
].handler_type
.p
;
3205 jclass handler
= NULL
;
3206 if (exc
[i
].handler_type
.i
!= 0)
3207 handler
= (_Jv_ResolvePoolEntry (defining_class
,
3208 exc
[i
].handler_type
.i
)).clazz
;
3209 #endif /* DIRECT_THREADED */
3211 if (handler
== NULL
|| handler
->isAssignableFrom (exc_class
))
3213 #ifdef DIRECT_THREADED
3214 pc
= (insn_slot
*) exc
[i
].handler_pc
.p
;
3216 pc
= bytecode () + exc
[i
].handler_pc
.i
;
3217 #endif /* DIRECT_THREADED */
3219 sp
++->o
= ex
; // Push exception.
3225 // No handler, so re-throw.
3230 // This function exists so that the stack-tracing code can find the
3231 // boundaries of the interpreter.
3233 _Jv_EndOfInterpreter (void)
3238 throw_internal_error (char *msg
)
3240 throw new java::lang::InternalError (JvNewStringLatin1 (msg
));
3244 throw_incompatible_class_change_error (jstring msg
)
3246 throw new java::lang::IncompatibleClassChangeError (msg
);
3250 static java::lang::NullPointerException
*null_pointer_exc
;
3252 throw_null_pointer_exception ()
3254 if (null_pointer_exc
== NULL
)
3255 null_pointer_exc
= new java::lang::NullPointerException
;
3257 throw null_pointer_exc
;
3261 #endif // INTERPRETER