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 // These exist so that the stack-tracing code can find the boundaries
778 // of the interpreter.
779 void *_Jv_StartOfInterpreter
;
780 void *_Jv_EndOfInterpreter
;
781 extern "C" void *_Unwind_FindEnclosingFunction (void *pc
);
784 _Jv_InterpMethod::run (void *retp
, ffi_raw
*args
)
786 using namespace java::lang::reflect
;
788 // Record the address of the start of this member function in
789 // _Jv_StartOfInterpreter. Such a write to a global variable
790 // without acquiring a lock is correct iff reads and writes of words
791 // in memory are atomic, but Java requires that anyway.
793 if (_Jv_StartOfInterpreter
== NULL
)
794 _Jv_StartOfInterpreter
= _Unwind_FindEnclosingFunction (&&foo
);
796 // FRAME_DESC registers this particular invocation as the top-most
797 // interpreter frame. This lets the stack tracing code (for
798 // Throwable) print information about the method being interpreted
799 // rather than about the interpreter itself. FRAME_DESC has a
800 // destructor so it cleans up automatically when the interpreter
802 java::lang::Thread
*thread
= java::lang::Thread::currentThread();
803 _Jv_MethodChain
frame_desc (this,
804 (_Jv_MethodChain
**) &thread
->interp_frame
);
806 _Jv_word stack
[max_stack
];
807 _Jv_word
*sp
= stack
;
809 _Jv_word locals
[max_locals
];
811 /* Go straight at it! the ffi raw format matches the internal
812 stack representation exactly. At least, that's the idea.
814 memcpy ((void*) locals
, (void*) args
, args_raw_size
);
816 _Jv_word
*pool_data
= defining_class
->constants
.data
;
818 /* These three are temporaries for common code used by several
821 _Jv_ResolvedMethod
* rmeth
;
824 #define INSN_LABEL(op) &&insn_##op
826 static const void *const insn_target
[] =
829 INSN_LABEL(aconst_null
),
830 INSN_LABEL(iconst_m1
),
831 INSN_LABEL(iconst_0
),
832 INSN_LABEL(iconst_1
),
833 INSN_LABEL(iconst_2
),
834 INSN_LABEL(iconst_3
),
835 INSN_LABEL(iconst_4
),
836 INSN_LABEL(iconst_5
),
837 INSN_LABEL(lconst_0
),
838 INSN_LABEL(lconst_1
),
839 INSN_LABEL(fconst_0
),
840 INSN_LABEL(fconst_1
),
841 INSN_LABEL(fconst_2
),
842 INSN_LABEL(dconst_0
),
843 INSN_LABEL(dconst_1
),
887 INSN_LABEL(istore_0
),
888 INSN_LABEL(istore_1
),
889 INSN_LABEL(istore_2
),
890 INSN_LABEL(istore_3
),
891 INSN_LABEL(lstore_0
),
892 INSN_LABEL(lstore_1
),
893 INSN_LABEL(lstore_2
),
894 INSN_LABEL(lstore_3
),
895 INSN_LABEL(fstore_0
),
896 INSN_LABEL(fstore_1
),
897 INSN_LABEL(fstore_2
),
898 INSN_LABEL(fstore_3
),
899 INSN_LABEL(dstore_0
),
900 INSN_LABEL(dstore_1
),
901 INSN_LABEL(dstore_2
),
902 INSN_LABEL(dstore_3
),
903 INSN_LABEL(astore_0
),
904 INSN_LABEL(astore_1
),
905 INSN_LABEL(astore_2
),
906 INSN_LABEL(astore_3
),
987 INSN_LABEL(if_icmpeq
),
988 INSN_LABEL(if_icmpne
),
989 INSN_LABEL(if_icmplt
),
990 INSN_LABEL(if_icmpge
),
991 INSN_LABEL(if_icmpgt
),
992 INSN_LABEL(if_icmple
),
993 INSN_LABEL(if_acmpeq
),
994 INSN_LABEL(if_acmpne
),
998 INSN_LABEL(tableswitch
),
999 INSN_LABEL(lookupswitch
),
1000 INSN_LABEL(ireturn
),
1001 INSN_LABEL(lreturn
),
1002 INSN_LABEL(freturn
),
1003 INSN_LABEL(dreturn
),
1004 INSN_LABEL(areturn
),
1006 INSN_LABEL(getstatic
),
1007 INSN_LABEL(putstatic
),
1008 INSN_LABEL(getfield
),
1009 INSN_LABEL(putfield
),
1010 INSN_LABEL(invokevirtual
),
1011 INSN_LABEL(invokespecial
),
1012 INSN_LABEL(invokestatic
),
1013 INSN_LABEL(invokeinterface
),
1016 INSN_LABEL(newarray
),
1017 INSN_LABEL(anewarray
),
1018 INSN_LABEL(arraylength
),
1020 INSN_LABEL(checkcast
),
1021 INSN_LABEL(instanceof
),
1022 INSN_LABEL(monitorenter
),
1023 INSN_LABEL(monitorexit
),
1024 #ifdef DIRECT_THREADED
1029 INSN_LABEL(multianewarray
),
1031 INSN_LABEL(ifnonnull
),
1039 #ifdef DIRECT_THREADED
1041 #define NEXT_INSN goto *((pc++)->insn)
1042 #define INTVAL() ((pc++)->int_val)
1043 #define AVAL() ((pc++)->datum)
1045 #define GET1S() INTVAL ()
1046 #define GET2S() INTVAL ()
1047 #define GET1U() INTVAL ()
1048 #define GET2U() INTVAL ()
1049 #define AVAL1U() AVAL ()
1050 #define AVAL2U() AVAL ()
1051 #define AVAL2UP() AVAL ()
1052 #define SKIP_GOTO ++pc
1053 #define GOTO_VAL() (insn_slot *) pc->datum
1054 #define PCVAL(unionval) unionval.p
1055 #define AMPAMP(label) &&label
1057 // Compile if we must. NOTE: Double-check locking.
1058 if (prepared
== NULL
)
1060 _Jv_MutexLock (&compile_mutex
);
1061 if (prepared
== NULL
)
1062 compile (insn_target
);
1063 _Jv_MutexUnlock (&compile_mutex
);
1065 pc
= (insn_slot
*) prepared
;
1069 #define NEXT_INSN goto *(insn_target[*pc++])
1071 #define GET1S() get1s (pc++)
1072 #define GET2S() (pc += 2, get2s (pc- 2))
1073 #define GET1U() get1u (pc++)
1074 #define GET2U() (pc += 2, get2u (pc - 2))
1075 #define AVAL1U() ({ int index = get1u (pc++); pool_data[index].o; })
1076 #define AVAL2U() ({ int index = get2u (pc); pc += 2; pool_data[index].o; })
1077 #define AVAL2UP() ({ int index = get2u (pc); pc += 2; &pool_data[index]; })
1078 #define SKIP_GOTO pc += 2
1079 #define GOTO_VAL() pc - 1 + get2s (pc)
1080 #define PCVAL(unionval) unionval.i
1081 #define AMPAMP(label) NULL
1085 #endif /* DIRECT_THREADED */
1087 #define TAKE_GOTO pc = GOTO_VAL ()
1091 // We keep nop around. It is used if we're interpreting the
1092 // bytecodes and not doing direct threading.
1096 /* The first few instructions here are ordered according to their
1097 frequency, in the hope that this will improve code locality a
1100 insn_aload_0
: // 0x2a
1108 insn_iload_1
: // 0x1b
1112 insn_invokevirtual
: // 0xb6
1114 int index
= GET2U ();
1116 /* _Jv_ResolvePoolEntry returns immediately if the value already
1117 * is resolved. If we want to clutter up the code here to gain
1118 * a little performance, then we can check the corresponding bit
1119 * JV_CONSTANT_ResolvedFlag in the tag directly. For now, I
1120 * don't think it is worth it. */
1122 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
1124 sp
-= rmeth
->stack_item_count
;
1125 // We don't use NULLCHECK here because we can't rely on that
1126 // working if the method is final. So instead we do an
1129 throw new java::lang::NullPointerException
;
1131 if (rmeth
->vtable_index
== -1)
1133 // final methods do not appear in the vtable,
1134 // if it does not appear in the superclass.
1135 fun
= (void (*)()) rmeth
->method
->ncode
;
1139 jobject rcv
= sp
[0].o
;
1140 _Jv_VTable
*table
= *(_Jv_VTable
**) rcv
;
1141 fun
= (void (*)()) table
->get_method (rmeth
->vtable_index
);
1144 #ifdef DIRECT_THREADED
1145 // Rewrite instruction so that we use a faster pre-resolved
1147 pc
[-2].insn
= &&invokevirtual_resolved
;
1148 pc
[-1].datum
= rmeth
;
1149 #endif /* DIRECT_THREADED */
1151 goto perform_invoke
;
1153 #ifdef DIRECT_THREADED
1154 invokevirtual_resolved
:
1156 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
1157 sp
-= rmeth
->stack_item_count
;
1158 // We don't use NULLCHECK here because we can't rely on that
1159 // working if the method is final. So instead we do an
1162 throw new java::lang::NullPointerException
;
1164 if (rmeth
->vtable_index
== -1)
1166 // final methods do not appear in the vtable,
1167 // if it does not appear in the superclass.
1168 fun
= (void (*)()) rmeth
->method
->ncode
;
1172 jobject rcv
= sp
[0].o
;
1173 _Jv_VTable
*table
= *(_Jv_VTable
**) rcv
;
1174 fun
= (void (*)()) table
->get_method (rmeth
->vtable_index
);
1177 goto perform_invoke
;
1178 #endif /* DIRECT_THREADED */
1182 /* here goes the magic again... */
1183 ffi_cif
*cif
= &rmeth
->cif
;
1184 ffi_raw
*raw
= (ffi_raw
*) sp
;
1188 #if FFI_NATIVE_RAW_API
1189 /* We assume that this is only implemented if it's correct */
1190 /* to use it here. On a 64 bit machine, it never is. */
1191 ffi_raw_call (cif
, fun
, (void*)&rvalue
, raw
);
1193 ffi_java_raw_call (cif
, fun
, (void*)&rvalue
, raw
);
1196 int rtype
= cif
->rtype
->type
;
1198 /* the likelyhood of object, int, or void return is very high,
1199 * so those are checked before the switch */
1200 if (rtype
== FFI_TYPE_POINTER
)
1202 PUSHA (rvalue
.object_value
);
1204 else if (rtype
== FFI_TYPE_SINT32
)
1206 PUSHI (rvalue
.int_value
);
1208 else if (rtype
== FFI_TYPE_VOID
)
1216 case FFI_TYPE_SINT8
:
1217 PUSHI ((jbyte
)(rvalue
.int_value
& 0xff));
1220 case FFI_TYPE_SINT16
:
1221 PUSHI ((jshort
)(rvalue
.int_value
& 0xffff));
1224 case FFI_TYPE_UINT16
:
1225 PUSHI (rvalue
.int_value
& 0xffff);
1228 case FFI_TYPE_FLOAT
:
1229 PUSHF (rvalue
.float_value
);
1232 case FFI_TYPE_DOUBLE
:
1233 PUSHD (rvalue
.double_value
);
1236 case FFI_TYPE_SINT64
:
1237 PUSHL (rvalue
.long_value
);
1241 throw_internal_error ("unknown return type in invokeXXX");
1308 // For direct threaded, bipush and sipush are the same.
1309 #ifndef DIRECT_THREADED
1312 #endif /* DIRECT_THREADED */
1318 // For direct threaded, ldc and ldc_w are the same.
1319 #ifndef DIRECT_THREADED
1320 PUSHA ((jobject
) AVAL1U ());
1322 #endif /* DIRECT_THREADED */
1324 PUSHA ((jobject
) AVAL2U ());
1329 void *where
= AVAL2UP ();
1330 memcpy (sp
, where
, 2*sizeof (_Jv_word
));
1425 jint index
= POPI();
1426 jintArray arr
= (jintArray
) POPA();
1427 NULLARRAYCHECK (arr
);
1428 ARRAYBOUNDSCHECK (arr
, index
);
1429 PUSHI( elements(arr
)[index
] );
1435 jint index
= POPI();
1436 jlongArray arr
= (jlongArray
) POPA();
1437 NULLARRAYCHECK (arr
);
1438 ARRAYBOUNDSCHECK (arr
, index
);
1439 PUSHL( elements(arr
)[index
] );
1445 jint index
= POPI();
1446 jfloatArray arr
= (jfloatArray
) POPA();
1447 NULLARRAYCHECK (arr
);
1448 ARRAYBOUNDSCHECK (arr
, index
);
1449 PUSHF( elements(arr
)[index
] );
1455 jint index
= POPI();
1456 jdoubleArray arr
= (jdoubleArray
) POPA();
1457 NULLARRAYCHECK (arr
);
1458 ARRAYBOUNDSCHECK (arr
, index
);
1459 PUSHD( elements(arr
)[index
] );
1465 jint index
= POPI();
1466 jobjectArray arr
= (jobjectArray
) POPA();
1467 NULLARRAYCHECK (arr
);
1468 ARRAYBOUNDSCHECK (arr
, index
);
1469 PUSHA( elements(arr
)[index
] );
1475 jint index
= POPI();
1476 jbyteArray arr
= (jbyteArray
) POPA();
1477 NULLARRAYCHECK (arr
);
1478 ARRAYBOUNDSCHECK (arr
, index
);
1479 PUSHI( elements(arr
)[index
] );
1485 jint index
= POPI();
1486 jcharArray arr
= (jcharArray
) POPA();
1487 NULLARRAYCHECK (arr
);
1488 ARRAYBOUNDSCHECK (arr
, index
);
1489 PUSHI( elements(arr
)[index
] );
1495 jint index
= POPI();
1496 jshortArray arr
= (jshortArray
) POPA();
1497 NULLARRAYCHECK (arr
);
1498 ARRAYBOUNDSCHECK (arr
, index
);
1499 PUSHI( elements(arr
)[index
] );
1605 jint value
= POPI();
1606 jint index
= POPI();
1607 jintArray arr
= (jintArray
) POPA();
1608 NULLARRAYCHECK (arr
);
1609 ARRAYBOUNDSCHECK (arr
, index
);
1610 elements(arr
)[index
] = value
;
1616 jlong value
= POPL();
1617 jint index
= POPI();
1618 jlongArray arr
= (jlongArray
) POPA();
1619 NULLARRAYCHECK (arr
);
1620 ARRAYBOUNDSCHECK (arr
, index
);
1621 elements(arr
)[index
] = value
;
1627 jfloat value
= POPF();
1628 jint index
= POPI();
1629 jfloatArray arr
= (jfloatArray
) POPA();
1630 NULLARRAYCHECK (arr
);
1631 ARRAYBOUNDSCHECK (arr
, index
);
1632 elements(arr
)[index
] = value
;
1638 jdouble value
= POPD();
1639 jint index
= POPI();
1640 jdoubleArray arr
= (jdoubleArray
) POPA();
1641 NULLARRAYCHECK (arr
);
1642 ARRAYBOUNDSCHECK (arr
, index
);
1643 elements(arr
)[index
] = value
;
1649 jobject value
= POPA();
1650 jint index
= POPI();
1651 jobjectArray arr
= (jobjectArray
) POPA();
1652 NULLARRAYCHECK (arr
);
1653 ARRAYBOUNDSCHECK (arr
, index
);
1654 _Jv_CheckArrayStore (arr
, value
);
1655 elements(arr
)[index
] = value
;
1661 jbyte value
= (jbyte
) POPI();
1662 jint index
= POPI();
1663 jbyteArray arr
= (jbyteArray
) POPA();
1664 NULLARRAYCHECK (arr
);
1665 ARRAYBOUNDSCHECK (arr
, index
);
1666 elements(arr
)[index
] = value
;
1672 jchar value
= (jchar
) POPI();
1673 jint index
= POPI();
1674 jcharArray arr
= (jcharArray
) POPA();
1675 NULLARRAYCHECK (arr
);
1676 ARRAYBOUNDSCHECK (arr
, index
);
1677 elements(arr
)[index
] = value
;
1683 jshort value
= (jshort
) POPI();
1684 jint index
= POPI();
1685 jshortArray arr
= (jshortArray
) POPA();
1686 NULLARRAYCHECK (arr
);
1687 ARRAYBOUNDSCHECK (arr
, index
);
1688 elements(arr
)[index
] = value
;
1706 dupx (sp
, 1, 1); sp
+=1;
1710 dupx (sp
, 1, 2); sp
+=1;
1720 dupx (sp
, 2, 1); sp
+=2;
1724 dupx (sp
, 2, 2); sp
+=2;
1729 jobject tmp1
= POPA();
1730 jobject tmp2
= POPA();
1786 jint value2
= POPI();
1787 jint value1
= POPI();
1788 jint res
= _Jv_divI (value1
, value2
);
1795 jlong value2
= POPL();
1796 jlong value1
= POPL();
1797 jlong res
= _Jv_divJ (value1
, value2
);
1804 jfloat value2
= POPF();
1805 jfloat value1
= POPF();
1806 jfloat res
= value1
/ value2
;
1813 jdouble value2
= POPD();
1814 jdouble value1
= POPD();
1815 jdouble res
= value1
/ value2
;
1822 jint value2
= POPI();
1823 jint value1
= POPI();
1824 jint res
= _Jv_remI (value1
, value2
);
1831 jlong value2
= POPL();
1832 jlong value1
= POPL();
1833 jlong res
= _Jv_remJ (value1
, value2
);
1840 jfloat value2
= POPF();
1841 jfloat value1
= POPF();
1842 jfloat res
= __ieee754_fmod (value1
, value2
);
1849 jdouble value2
= POPD();
1850 jdouble value1
= POPD();
1851 jdouble res
= __ieee754_fmod (value1
, value2
);
1858 jint value
= POPI();
1865 jlong value
= POPL();
1872 jfloat value
= POPF();
1879 jdouble value
= POPD();
1886 jint shift
= (POPI() & 0x1f);
1887 jint value
= POPI();
1888 PUSHI (value
<< shift
);
1894 jint shift
= (POPI() & 0x3f);
1895 jlong value
= POPL();
1896 PUSHL (value
<< shift
);
1902 jint shift
= (POPI() & 0x1f);
1903 jint value
= POPI();
1904 PUSHI (value
>> shift
);
1910 jint shift
= (POPI() & 0x3f);
1911 jlong value
= POPL();
1912 PUSHL (value
>> shift
);
1918 jint shift
= (POPI() & 0x1f);
1919 _Jv_uint value
= (_Jv_uint
) POPI();
1920 PUSHI ((jint
) (value
>> shift
));
1926 jint shift
= (POPI() & 0x3f);
1927 _Jv_ulong value
= (_Jv_ulong
) POPL();
1928 PUSHL ((jlong
) (value
>> shift
));
1958 jint index
= GET1U ();
1959 jint amount
= GET1S ();
1960 locals
[index
].i
+= amount
;
1965 {jlong value
= POPI(); PUSHL (value
);}
1969 {jfloat value
= POPI(); PUSHF (value
);}
1973 {jdouble value
= POPI(); PUSHD (value
);}
1977 {jint value
= POPL(); PUSHI (value
);}
1981 {jfloat value
= POPL(); PUSHF (value
);}
1985 {jdouble value
= POPL(); PUSHD (value
);}
1990 using namespace java::lang
;
1991 jint value
= convert (POPF (), Integer::MIN_VALUE
, Integer::MAX_VALUE
);
1998 using namespace java::lang
;
1999 jlong value
= convert (POPF (), Long::MIN_VALUE
, Long::MAX_VALUE
);
2005 { jdouble value
= POPF (); PUSHD(value
); }
2010 using namespace java::lang
;
2011 jint value
= convert (POPD (), Integer::MIN_VALUE
, Integer::MAX_VALUE
);
2018 using namespace java::lang
;
2019 jlong value
= convert (POPD (), Long::MIN_VALUE
, Long::MAX_VALUE
);
2025 { jfloat value
= POPD (); PUSHF(value
); }
2029 { jbyte value
= POPI (); PUSHI(value
); }
2033 { jchar value
= POPI (); PUSHI(value
); }
2037 { jshort value
= POPI (); PUSHI(value
); }
2042 jlong value2
= POPL ();
2043 jlong value1
= POPL ();
2044 if (value1
> value2
)
2046 else if (value1
== value2
)
2062 jfloat value2
= POPF ();
2063 jfloat value1
= POPF ();
2064 if (value1
> value2
)
2066 else if (value1
== value2
)
2068 else if (value1
< value2
)
2084 jdouble value2
= POPD ();
2085 jdouble value1
= POPD ();
2086 if (value1
> value2
)
2088 else if (value1
== value2
)
2090 else if (value1
< value2
)
2153 jint value2
= POPI();
2154 jint value1
= POPI();
2155 if (value1
== value2
)
2164 jint value2
= POPI();
2165 jint value1
= POPI();
2166 if (value1
!= value2
)
2175 jint value2
= POPI();
2176 jint value1
= POPI();
2177 if (value1
< value2
)
2186 jint value2
= POPI();
2187 jint value1
= POPI();
2188 if (value1
>= value2
)
2197 jint value2
= POPI();
2198 jint value1
= POPI();
2199 if (value1
> value2
)
2208 jint value2
= POPI();
2209 jint value1
= POPI();
2210 if (value1
<= value2
)
2219 jobject value2
= POPA();
2220 jobject value1
= POPA();
2221 if (value1
== value2
)
2230 jobject value2
= POPA();
2231 jobject value1
= POPA();
2232 if (value1
!= value2
)
2240 #ifndef DIRECT_THREADED
2241 // For direct threaded, goto and goto_w are the same.
2242 pc
= pc
- 1 + get4 (pc
);
2244 #endif /* DIRECT_THREADED */
2250 #ifndef DIRECT_THREADED
2251 // For direct threaded, jsr and jsr_w are the same.
2253 pc_t next
= pc
- 1 + get4 (pc
);
2255 PUSHA ((jobject
) pc
);
2259 #endif /* DIRECT_THREADED */
2262 pc_t next
= GOTO_VAL();
2264 PUSHA ((jobject
) pc
);
2271 jint index
= GET1U ();
2272 pc
= (pc_t
) PEEKA (index
);
2278 #ifdef DIRECT_THREADED
2279 void *def
= (pc
++)->datum
;
2283 jint low
= INTVAL ();
2284 jint high
= INTVAL ();
2286 if (index
< low
|| index
> high
)
2287 pc
= (insn_slot
*) def
;
2289 pc
= (insn_slot
*) ((pc
+ index
- low
)->datum
);
2291 pc_t base_pc
= pc
- 1;
2292 int index
= POPI ();
2294 pc_t base
= (pc_t
) bytecode ();
2295 while ((pc
- base
) % 4 != 0)
2298 jint def
= get4 (pc
);
2299 jint low
= get4 (pc
+ 4);
2300 jint high
= get4 (pc
+ 8);
2301 if (index
< low
|| index
> high
)
2304 pc
= base_pc
+ get4 (pc
+ 4 * (index
- low
+ 3));
2305 #endif /* DIRECT_THREADED */
2311 #ifdef DIRECT_THREADED
2312 void *def
= (pc
++)->insn
;
2316 jint npairs
= INTVAL ();
2318 int max
= npairs
- 1;
2321 // Simple binary search...
2324 int half
= (min
+ max
) / 2;
2325 int match
= pc
[2 * half
].int_val
;
2330 pc
= (insn_slot
*) pc
[2 * half
+ 1].datum
;
2333 else if (index
< match
)
2334 // We can use HALF - 1 here because we check again on
2338 // We can use HALF + 1 here because we check again on
2342 if (index
== pc
[2 * min
].int_val
)
2343 pc
= (insn_slot
*) pc
[2 * min
+ 1].datum
;
2345 pc
= (insn_slot
*) def
;
2347 unsigned char *base_pc
= pc
-1;
2350 unsigned char* base
= bytecode ();
2351 while ((pc
-base
) % 4 != 0)
2354 jint def
= get4 (pc
);
2355 jint npairs
= get4 (pc
+4);
2360 // Simple binary search...
2363 int half
= (min
+max
)/2;
2364 int match
= get4 (pc
+ 4*(2 + 2*half
));
2368 else if (index
< match
)
2369 // We can use HALF - 1 here because we check again on
2373 // We can use HALF + 1 here because we check again on
2378 if (index
== get4 (pc
+ 4*(2 + 2*min
)))
2379 pc
= base_pc
+ get4 (pc
+ 4*(2 + 2*min
+ 1));
2382 #endif /* DIRECT_THREADED */
2387 *(jobject
*) retp
= POPA ();
2391 *(jlong
*) retp
= POPL ();
2395 *(jfloat
*) retp
= POPF ();
2399 *(jdouble
*) retp
= POPD ();
2403 *(jint
*) retp
= POPI ();
2411 jint fieldref_index
= GET2U ();
2412 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2413 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2415 if ((field
->flags
& Modifier::STATIC
) == 0)
2416 throw_incompatible_class_change_error
2417 (JvNewStringLatin1 ("field no longer static"));
2419 jclass type
= field
->type
;
2421 // We rewrite the instruction once we discover what it refers
2423 void *newinsn
= NULL
;
2424 if (type
->isPrimitive ())
2426 switch (type
->size_in_bytes
)
2429 PUSHI (*field
->u
.byte_addr
);
2430 newinsn
= AMPAMP (getstatic_resolved_1
);
2434 if (type
== JvPrimClass (char))
2436 PUSHI (*field
->u
.char_addr
);
2437 newinsn
= AMPAMP (getstatic_resolved_char
);
2441 PUSHI (*field
->u
.short_addr
);
2442 newinsn
= AMPAMP (getstatic_resolved_short
);
2447 PUSHI(*field
->u
.int_addr
);
2448 newinsn
= AMPAMP (getstatic_resolved_4
);
2452 PUSHL(*field
->u
.long_addr
);
2453 newinsn
= AMPAMP (getstatic_resolved_8
);
2459 PUSHA(*field
->u
.object_addr
);
2460 newinsn
= AMPAMP (getstatic_resolved_obj
);
2463 #ifdef DIRECT_THREADED
2464 pc
[-2].insn
= newinsn
;
2465 pc
[-1].datum
= field
->u
.addr
;
2466 #endif /* DIRECT_THREADED */
2470 #ifdef DIRECT_THREADED
2471 getstatic_resolved_1
:
2472 PUSHI (*(jbyte
*) AVAL ());
2475 getstatic_resolved_char
:
2476 PUSHI (*(jchar
*) AVAL ());
2479 getstatic_resolved_short
:
2480 PUSHI (*(jshort
*) AVAL ());
2483 getstatic_resolved_4
:
2484 PUSHI (*(jint
*) AVAL ());
2487 getstatic_resolved_8
:
2488 PUSHL (*(jlong
*) AVAL ());
2491 getstatic_resolved_obj
:
2492 PUSHA (*(jobject
*) AVAL ());
2494 #endif /* DIRECT_THREADED */
2498 jint fieldref_index
= GET2U ();
2499 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2500 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2502 if ((field
->flags
& Modifier::STATIC
) != 0)
2503 throw_incompatible_class_change_error
2504 (JvNewStringLatin1 ("field is static"));
2506 jclass type
= field
->type
;
2507 jint field_offset
= field
->u
.boffset
;
2508 if (field_offset
> 0xffff)
2509 throw new java::lang::VirtualMachineError
;
2511 jobject obj
= POPA();
2514 void *newinsn
= NULL
;
2515 _Jv_value
*val
= (_Jv_value
*) ((char *)obj
+ field_offset
);
2516 if (type
->isPrimitive ())
2518 switch (type
->size_in_bytes
)
2521 PUSHI (val
->byte_value
);
2522 newinsn
= AMPAMP (getfield_resolved_1
);
2526 if (type
== JvPrimClass (char))
2528 PUSHI (val
->char_value
);
2529 newinsn
= AMPAMP (getfield_resolved_char
);
2533 PUSHI (val
->short_value
);
2534 newinsn
= AMPAMP (getfield_resolved_short
);
2539 PUSHI (val
->int_value
);
2540 newinsn
= AMPAMP (getfield_resolved_4
);
2544 PUSHL (val
->long_value
);
2545 newinsn
= AMPAMP (getfield_resolved_8
);
2551 PUSHA (val
->object_value
);
2552 newinsn
= AMPAMP (getfield_resolved_obj
);
2555 #ifdef DIRECT_THREADED
2556 pc
[-2].insn
= newinsn
;
2557 pc
[-1].int_val
= field_offset
;
2558 #endif /* DIRECT_THREADED */
2562 #ifdef DIRECT_THREADED
2563 getfield_resolved_1
:
2565 char *obj
= (char *) POPA ();
2567 PUSHI (*(jbyte
*) (obj
+ INTVAL ()));
2571 getfield_resolved_char
:
2573 char *obj
= (char *) POPA ();
2575 PUSHI (*(jchar
*) (obj
+ INTVAL ()));
2579 getfield_resolved_short
:
2581 char *obj
= (char *) POPA ();
2583 PUSHI (*(jshort
*) (obj
+ INTVAL ()));
2587 getfield_resolved_4
:
2589 char *obj
= (char *) POPA ();
2591 PUSHI (*(jint
*) (obj
+ INTVAL ()));
2595 getfield_resolved_8
:
2597 char *obj
= (char *) POPA ();
2599 PUSHL (*(jlong
*) (obj
+ INTVAL ()));
2603 getfield_resolved_obj
:
2605 char *obj
= (char *) POPA ();
2607 PUSHA (*(jobject
*) (obj
+ INTVAL ()));
2610 #endif /* DIRECT_THREADED */
2614 jint fieldref_index
= GET2U ();
2615 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2616 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2618 jclass type
= field
->type
;
2620 // ResolvePoolEntry cannot check this
2621 if ((field
->flags
& Modifier::STATIC
) == 0)
2622 throw_incompatible_class_change_error
2623 (JvNewStringLatin1 ("field no longer static"));
2625 void *newinsn
= NULL
;
2626 if (type
->isPrimitive ())
2628 switch (type
->size_in_bytes
)
2632 jint value
= POPI();
2633 *field
->u
.byte_addr
= value
;
2634 newinsn
= AMPAMP (putstatic_resolved_1
);
2640 jint value
= POPI();
2641 *field
->u
.char_addr
= value
;
2642 newinsn
= AMPAMP (putstatic_resolved_2
);
2648 jint value
= POPI();
2649 *field
->u
.int_addr
= value
;
2650 newinsn
= AMPAMP (putstatic_resolved_4
);
2656 jlong value
= POPL();
2657 *field
->u
.long_addr
= value
;
2658 newinsn
= AMPAMP (putstatic_resolved_8
);
2665 jobject value
= POPA();
2666 *field
->u
.object_addr
= value
;
2667 newinsn
= AMPAMP (putstatic_resolved_obj
);
2670 #ifdef DIRECT_THREADED
2671 pc
[-2].insn
= newinsn
;
2672 pc
[-1].datum
= field
->u
.addr
;
2673 #endif /* DIRECT_THREADED */
2677 #ifdef DIRECT_THREADED
2678 putstatic_resolved_1
:
2679 *(jbyte
*) AVAL () = POPI ();
2682 putstatic_resolved_2
:
2683 *(jchar
*) AVAL () = POPI ();
2686 putstatic_resolved_4
:
2687 *(jint
*) AVAL () = POPI ();
2690 putstatic_resolved_8
:
2691 *(jlong
*) AVAL () = POPL ();
2694 putstatic_resolved_obj
:
2695 *(jobject
*) AVAL () = POPA ();
2697 #endif /* DIRECT_THREADED */
2701 jint fieldref_index
= GET2U ();
2702 _Jv_ResolvePoolEntry (defining_class
, fieldref_index
);
2703 _Jv_Field
*field
= pool_data
[fieldref_index
].field
;
2705 jclass type
= field
->type
;
2707 if ((field
->flags
& Modifier::STATIC
) != 0)
2708 throw_incompatible_class_change_error
2709 (JvNewStringLatin1 ("field is static"));
2711 jint field_offset
= field
->u
.boffset
;
2712 if (field_offset
> 0xffff)
2713 throw new java::lang::VirtualMachineError
;
2715 void *newinsn
= NULL
;
2716 if (type
->isPrimitive ())
2718 switch (type
->size_in_bytes
)
2722 jint value
= POPI();
2723 jobject obj
= POPA();
2725 *(jbyte
*) ((char*)obj
+ field_offset
) = value
;
2726 newinsn
= AMPAMP (putfield_resolved_1
);
2732 jint value
= POPI();
2733 jobject obj
= POPA();
2735 *(jchar
*) ((char*)obj
+ field_offset
) = value
;
2736 newinsn
= AMPAMP (putfield_resolved_2
);
2742 jint value
= POPI();
2743 jobject obj
= POPA();
2745 *(jint
*) ((char*)obj
+ field_offset
) = value
;
2746 newinsn
= AMPAMP (putfield_resolved_4
);
2752 jlong value
= POPL();
2753 jobject obj
= POPA();
2755 *(jlong
*) ((char*)obj
+ field_offset
) = value
;
2756 newinsn
= AMPAMP (putfield_resolved_8
);
2763 jobject value
= POPA();
2764 jobject obj
= POPA();
2766 *(jobject
*) ((char*)obj
+ field_offset
) = value
;
2767 newinsn
= AMPAMP (putfield_resolved_obj
);
2770 #ifdef DIRECT_THREADED
2771 pc
[-2].insn
= newinsn
;
2772 pc
[-1].int_val
= field_offset
;
2773 #endif /* DIRECT_THREADED */
2777 #ifdef DIRECT_THREADED
2778 putfield_resolved_1
:
2781 char *obj
= (char *) POPA ();
2783 *(jbyte
*) (obj
+ INTVAL ()) = val
;
2787 putfield_resolved_2
:
2790 char *obj
= (char *) POPA ();
2792 *(jchar
*) (obj
+ INTVAL ()) = val
;
2796 putfield_resolved_4
:
2799 char *obj
= (char *) POPA ();
2801 *(jint
*) (obj
+ INTVAL ()) = val
;
2805 putfield_resolved_8
:
2807 jlong val
= POPL ();
2808 char *obj
= (char *) POPA ();
2810 *(jlong
*) (obj
+ INTVAL ()) = val
;
2814 putfield_resolved_obj
:
2816 jobject val
= POPA ();
2817 char *obj
= (char *) POPA ();
2819 *(jobject
*) (obj
+ INTVAL ()) = val
;
2822 #endif /* DIRECT_THREADED */
2826 int index
= GET2U ();
2828 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2830 sp
-= rmeth
->stack_item_count
;
2832 // We don't use NULLCHECK here because we can't rely on that
2833 // working for <init>. So instead we do an explicit test.
2835 throw new java::lang::NullPointerException
;
2837 fun
= (void (*)()) rmeth
->method
->ncode
;
2839 #ifdef DIRECT_THREADED
2840 // Rewrite instruction so that we use a faster pre-resolved
2842 pc
[-2].insn
= &&invokespecial_resolved
;
2843 pc
[-1].datum
= rmeth
;
2844 #endif /* DIRECT_THREADED */
2846 goto perform_invoke
;
2848 #ifdef DIRECT_THREADED
2849 invokespecial_resolved
:
2851 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2852 sp
-= rmeth
->stack_item_count
;
2853 // We don't use NULLCHECK here because we can't rely on that
2854 // working for <init>. So instead we do an explicit test.
2856 throw new java::lang::NullPointerException
;
2857 fun
= (void (*)()) rmeth
->method
->ncode
;
2859 goto perform_invoke
;
2860 #endif /* DIRECT_THREADED */
2864 int index
= GET2U ();
2866 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2868 sp
-= rmeth
->stack_item_count
;
2870 fun
= (void (*)()) rmeth
->method
->ncode
;
2872 #ifdef DIRECT_THREADED
2873 // Rewrite instruction so that we use a faster pre-resolved
2875 pc
[-2].insn
= &&invokestatic_resolved
;
2876 pc
[-1].datum
= rmeth
;
2877 #endif /* DIRECT_THREADED */
2879 goto perform_invoke
;
2881 #ifdef DIRECT_THREADED
2882 invokestatic_resolved
:
2884 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2885 sp
-= rmeth
->stack_item_count
;
2886 fun
= (void (*)()) rmeth
->method
->ncode
;
2888 goto perform_invoke
;
2889 #endif /* DIRECT_THREADED */
2891 insn_invokeinterface
:
2893 int index
= GET2U ();
2895 rmeth
= (_Jv_ResolvePoolEntry (defining_class
, index
)).rmethod
;
2897 sp
-= rmeth
->stack_item_count
;
2899 jobject rcv
= sp
[0].o
;
2904 _Jv_LookupInterfaceMethod (rcv
->getClass (),
2905 rmeth
->method
->name
,
2906 rmeth
->method
->signature
);
2908 #ifdef DIRECT_THREADED
2909 // Rewrite instruction so that we use a faster pre-resolved
2911 pc
[-2].insn
= &&invokeinterface_resolved
;
2912 pc
[-1].datum
= rmeth
;
2914 // Skip dummy bytes.
2916 #endif /* DIRECT_THREADED */
2918 goto perform_invoke
;
2920 #ifdef DIRECT_THREADED
2921 invokeinterface_resolved
:
2923 rmeth
= (_Jv_ResolvedMethod
*) AVAL ();
2924 sp
-= rmeth
->stack_item_count
;
2925 jobject rcv
= sp
[0].o
;
2928 _Jv_LookupInterfaceMethod (rcv
->getClass (),
2929 rmeth
->method
->name
,
2930 rmeth
->method
->signature
);
2932 goto perform_invoke
;
2933 #endif /* DIRECT_THREADED */
2937 int index
= GET2U ();
2938 jclass klass
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2939 jobject res
= _Jv_AllocObject (klass
);
2942 #ifdef DIRECT_THREADED
2943 pc
[-2].insn
= &&new_resolved
;
2944 pc
[-1].datum
= klass
;
2945 #endif /* DIRECT_THREADED */
2949 #ifdef DIRECT_THREADED
2952 jclass klass
= (jclass
) AVAL ();
2953 jobject res
= _Jv_AllocObject (klass
);
2957 #endif /* DIRECT_THREADED */
2961 int atype
= GET1U ();
2963 jobject result
= _Jv_NewArray (atype
, size
);
2970 int index
= GET2U ();
2971 jclass klass
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
2973 jobject result
= _Jv_NewObjectArray (size
, klass
, 0);
2976 #ifdef DIRECT_THREADED
2977 pc
[-2].insn
= &&anewarray_resolved
;
2978 pc
[-1].datum
= klass
;
2979 #endif /* DIRECT_THREADED */
2983 #ifdef DIRECT_THREADED
2986 jclass klass
= (jclass
) AVAL ();
2988 jobject result
= _Jv_NewObjectArray (size
, klass
, 0);
2992 #endif /* DIRECT_THREADED */
2996 __JArray
*arr
= (__JArray
*)POPA();
2997 NULLARRAYCHECK (arr
);
2998 PUSHI (arr
->length
);
3004 jobject value
= POPA();
3005 throw static_cast<jthrowable
>(value
);
3011 jobject value
= POPA();
3012 jint index
= GET2U ();
3013 jclass to
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
3015 if (value
!= NULL
&& ! to
->isInstance (value
))
3016 throw new java::lang::ClassCastException (to
->getName());
3020 #ifdef DIRECT_THREADED
3021 pc
[-2].insn
= &&checkcast_resolved
;
3023 #endif /* DIRECT_THREADED */
3027 #ifdef DIRECT_THREADED
3030 jobject value
= POPA ();
3031 jclass to
= (jclass
) AVAL ();
3032 if (value
!= NULL
&& ! to
->isInstance (value
))
3033 throw new java::lang::ClassCastException (to
->getName());
3037 #endif /* DIRECT_THREADED */
3041 jobject value
= POPA();
3042 jint index
= GET2U ();
3043 jclass to
= (_Jv_ResolvePoolEntry (defining_class
, index
)).clazz
;
3044 PUSHI (to
->isInstance (value
));
3046 #ifdef DIRECT_THREADED
3047 pc
[-2].insn
= &&instanceof_resolved
;
3049 #endif /* DIRECT_THREADED */
3053 #ifdef DIRECT_THREADED
3054 instanceof_resolved
:
3056 jobject value
= POPA ();
3057 jclass to
= (jclass
) AVAL ();
3058 PUSHI (to
->isInstance (value
));
3061 #endif /* DIRECT_THREADED */
3065 jobject value
= POPA();
3067 _Jv_MonitorEnter (value
);
3073 jobject value
= POPA();
3075 _Jv_MonitorExit (value
);
3081 jobject val
= POPA();
3091 jobject val
= POPA();
3099 insn_multianewarray
:
3101 int kind_index
= GET2U ();
3105 = (_Jv_ResolvePoolEntry (defining_class
, kind_index
)).clazz
;
3106 jint
*sizes
= (jint
*) __builtin_alloca (sizeof (jint
)*dim
);
3108 for (int i
= dim
- 1; i
>= 0; i
--)
3113 jobject res
= _Jv_NewMultiArray (type
,dim
, sizes
);
3119 #ifndef DIRECT_THREADED
3122 jint the_mod_op
= get1u (pc
++);
3123 jint wide
= get2u (pc
); pc
+= 2;
3168 pc
= (unsigned char*) PEEKA (wide
);
3173 jint amount
= get2s (pc
); pc
+= 2;
3174 jint value
= PEEKI (wide
);
3175 POKEI (wide
, value
+amount
);
3180 throw_internal_error ("illegal bytecode modified by wide");
3184 #endif /* DIRECT_THREADED */
3186 catch (java::lang::Throwable
*ex
)
3188 #ifdef DIRECT_THREADED
3189 void *logical_pc
= (void *) ((insn_slot
*) pc
- 1);
3191 int logical_pc
= pc
- 1 - bytecode ();
3193 _Jv_InterpException
*exc
= exceptions ();
3194 jclass exc_class
= ex
->getClass ();
3196 for (int i
= 0; i
< exc_count
; i
++)
3198 if (PCVAL (exc
[i
].start_pc
) <= logical_pc
3199 && logical_pc
< PCVAL (exc
[i
].end_pc
))
3201 #ifdef DIRECT_THREADED
3202 jclass handler
= (jclass
) exc
[i
].handler_type
.p
;
3204 jclass handler
= NULL
;
3205 if (exc
[i
].handler_type
.i
!= 0)
3206 handler
= (_Jv_ResolvePoolEntry (defining_class
,
3207 exc
[i
].handler_type
.i
)).clazz
;
3208 #endif /* DIRECT_THREADED */
3210 if (handler
== NULL
|| handler
->isAssignableFrom (exc_class
))
3212 #ifdef DIRECT_THREADED
3213 pc
= (insn_slot
*) exc
[i
].handler_pc
.p
;
3215 pc
= bytecode () + exc
[i
].handler_pc
.i
;
3216 #endif /* DIRECT_THREADED */
3218 sp
++->o
= ex
; // Push exception.
3224 // No handler, so re-throw.
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