// interpret.cc - Code for the interpreter
-/* Copyright (C) 1999 Cygnus Solutions
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
This file is part of libgcj.
/* Author: Kresten Krab Thorup <krab@gnu.org> */
-/* define this to get instruction timings. */
-/* #define TIME_MAINLOOP */
-
#include <config.h>
+// Define this to get the direct-threaded interpreter. If undefined,
+// we revert to a basic bytecode interpreter. The former is faster
+// but uses more memory.
+#define DIRECT_THREADED
+
#pragma implementation "java-interp.h"
-#include <cni.h>
#include <jvm.h>
-#include <java-field.h>
#include <java-cpool.h>
#include <java-interp.h>
-#include <java/lang/fdlibm.h>
#include <java/lang/System.h>
#include <java/lang/String.h>
#include <java/lang/Integer.h>
+#include <java/lang/Long.h>
#include <java/lang/StringBuffer.h>
-#include <java/io/PrintStream.h>
#include <java/lang/Class.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/ClassCastException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/ArithmeticException.h>
#include <java/lang/IncompatibleClassChangeError.h>
+#include <java/lang/Thread.h>
#include <java-insns.h>
#include <java-signal.h>
-#ifdef TIME_MAINLOOP
-#include <sys/time.h>
-#include <stdio.h>
-#endif
-
-#ifndef INTERPRETER
-
-#include <gnu/gcj/runtime/MethodInvocation.h>
-
-/* This should never happen. */
-void
-gnu::gcj::runtime::MethodInvocation::continue1 (gnu::gcj::RawData *,
- gnu::gcj::RawData *)
-{
- JvFail ("no interpreter");
-}
-#else
-
-#define ClassError _CL_Q34java4lang5Error
-extern java::lang::Class ClassError;
+#ifdef INTERPRETER
-static const int PUBLIC = 0x001;
-static const int PRIVATE = 0x002;
-static const int PROTECTED = 0x004;
-static const int STATIC = 0x008;
-static const int FINAL = 0x010;
-static const int SYNCHRONIZED = 0x020;
-static const int VOLATILE = 0x040;
-static const int TRANSIENT = 0x080;
-static const int NATIVE = 0x100;
-static const int INTERFACE = 0x200;
-static const int ABSTRACT = 0x400;
-static const int ALL_FLAGS = 0x7FF;
+#include <stdlib.h>
-static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
+using namespace gcj;
static void throw_internal_error (char *msg)
__attribute__ ((__noreturn__));
static void throw_incompatible_class_change_error (jstring msg)
__attribute__ ((__noreturn__));
-#if !HANDLE_SEGV
+#ifndef HANDLE_SEGV
static void throw_null_pointer_exception ()
__attribute__ ((__noreturn__));
#endif
-#if !HANDLE_FPE
-static void throw_arithmetic_exception ()
- __attribute__ ((__noreturn__));
-#endif
+extern "C" double __ieee754_fmod (double,double);
+
+// This represents a single slot in the "compiled" form of the
+// bytecode.
+union insn_slot
+{
+ // Address of code.
+ void *insn;
+ // An integer value used by an instruction.
+ jint int_val;
+ // A pointer value used by an instruction.
+ void *datum;
+};
+
+// The type of the PC depends on whether we're doing direct threading
+// or a more ordinary bytecode interpreter.
+#ifdef DIRECT_THREADED
+typedef insn_slot *pc_t;
+#else
+typedef unsigned char *pc_t;
+#endif
-static inline void dupx (_Jv_word *&sp, int n, int x)
+static inline void dupx (_Jv_word *sp, int n, int x)
{
// first "slide" n+x elements n to the right
int top = n-1;
sp[top-(n+x)-i] = sp[top-i];
}
- // the net effect
- sp += n;
-};
+}
+// Used to convert from floating types to integral types.
+template<typename TO, typename FROM>
+static inline TO
+convert (FROM val, TO min, TO max)
+{
+ TO ret;
+ if (val >= (FROM) max)
+ ret = max;
+ else if (val <= (FROM) min)
+ ret = min;
+ else if (val != val)
+ ret = 0;
+ else
+ ret = (TO) val;
+ return ret;
+}
-#define PUSHA(V) \
- ({ jobject __v=(V); (sp++)->o = __v; })
-#define PUSHI(V) \
- ({ jint __v=(V); (sp++)->i = __v; })
-#define PUSHF(V) \
- ({ jfloat __v=(V); (sp++)->f = __v; })
-#define PUSHL(V) \
- ({ jlong __v=(V); _Jv_storeLong(sp,__v); sp+=2; })
-#define PUSHD(V) \
- ({ jdouble __v=(V); _Jv_storeDouble(sp,__v); sp+=2; })
+#define PUSHA(V) (sp++)->o = (V)
+#define PUSHI(V) (sp++)->i = (V)
+#define PUSHF(V) (sp++)->f = (V)
+#if SIZEOF_VOID_P == 8
+# define PUSHL(V) (sp->l = (V), sp += 2)
+# define PUSHD(V) (sp->d = (V), sp += 2)
+#else
+# define PUSHL(V) do { _Jv_word2 w2; w2.l=(V); \
+ (sp++)->ia[0] = w2.ia[0]; \
+ (sp++)->ia[0] = w2.ia[1]; } while (0)
+# define PUSHD(V) do { _Jv_word2 w2; w2.d=(V); \
+ (sp++)->ia[0] = w2.ia[0]; \
+ (sp++)->ia[0] = w2.ia[1]; } while (0)
+#endif
#define POPA() ((--sp)->o)
#define POPI() ((jint) (--sp)->i) // cast since it may be promoted
#define POPF() ((jfloat) (--sp)->f)
-#define POPL() ({ sp-=2; _Jv_loadLong (sp); })
-#define POPD() ({ sp-=2; _Jv_loadDouble (sp); })
+#if SIZEOF_VOID_P == 8
+# define POPL() (sp -= 2, (jlong) sp->l)
+# define POPD() (sp -= 2, (jdouble) sp->d)
+#else
+# define POPL() ({ _Jv_word2 w2; \
+ w2.ia[1] = (--sp)->ia[0]; \
+ w2.ia[0] = (--sp)->ia[0]; w2.l; })
+# define POPD() ({ _Jv_word2 w2; \
+ w2.ia[1] = (--sp)->ia[0]; \
+ w2.ia[0] = (--sp)->ia[0]; w2.d; })
+#endif
#define LOADA(I) (sp++)->o = locals[I].o
#define LOADI(I) (sp++)->i = locals[I].i
#define LOADF(I) (sp++)->f = locals[I].f
-#define LOADL(I) ({ jint __idx = (I); \
- (sp++)->ia[0] = locals[__idx].ia[0]; \
- (sp++)->ia[0] = locals[__idx+1].ia[0]; \
- })
-#define LOADD(I) LOADL(I)
-
+#if SIZEOF_VOID_P == 8
+# define LOADL(I) (sp->l = locals[I].l, sp += 2)
+# define LOADD(I) (sp->d = locals[I].d, sp += 2)
+#else
+# define LOADL(I) do { jint __idx = (I); \
+ (sp++)->ia[0] = locals[__idx].ia[0]; \
+ (sp++)->ia[0] = locals[__idx+1].ia[0]; \
+ } while (0)
+# define LOADD(I) LOADL(I)
+#endif
#define STOREA(I) locals[I].o = (--sp)->o
#define STOREI(I) locals[I].i = (--sp)->i
#define STOREF(I) locals[I].f = (--sp)->f
-#define STOREL(I) ({ jint __idx = (I); \
- locals[__idx+1].ia[0] = (--sp)->ia[0]; \
- locals[__idx].ia[0] = (--sp)->ia[0]; \
- })
-#define STORED(I) STOREL(I)
+#if SIZEOF_VOID_P == 8
+# define STOREL(I) (sp -= 2, locals[I].l = sp->l)
+# define STORED(I) (sp -= 2, locals[I].d = sp->d)
+#else
+# define STOREL(I) do { jint __idx = (I); \
+ locals[__idx+1].ia[0] = (--sp)->ia[0]; \
+ locals[__idx].ia[0] = (--sp)->ia[0]; \
+ } while (0)
+# define STORED(I) STOREL(I)
+#endif
#define PEEKI(I) (locals+(I))->i
#define PEEKA(I) (locals+(I))->o
-#define POKEI(I,V) (*(jint*) (locals+(I)) = (V))
+#define POKEI(I,V) ((locals+(I))->i = (V))
#define BINOPI(OP) { \
}
-#if HANDLE_SEGV
+#ifdef HANDLE_SEGV
#define NULLCHECK(X)
+#define NULLARRAYCHECK(X)
#else
#define NULLCHECK(X) \
do { if ((X)==NULL) throw_null_pointer_exception (); } while (0)
+#define NULLARRAYCHECK(X) \
+ do { if ((X)==NULL) { throw_null_pointer_exception (); } } while (0)
#endif
-#if HANDLE_FPE
-#define ZEROCHECK(X)
-#else
-#define ZEROCHECK(X) \
- do { if ((X) == 0) throw_arithmetic_exception (); } while (0)
-#endif
+#define ARRAYBOUNDSCHECK(array, index) \
+ do \
+ { \
+ if (((unsigned) index) >= (unsigned) (array->length)) \
+ _Jv_ThrowBadArrayIndex (index); \
+ } \
+ while (0)
-// this method starts the actual running of the method. It is inlined
-// in three different variants in the static methods run_normal,
-// run_sync_object and run_sync_class (see below). Those static methods
-// are installed directly in the stub for this method (by
-// _Jv_InterpMethod::ncode, in resolve.cc).
-
-inline jobject
-_Jv_InterpMethod::run (ffi_cif* cif,
- void *retp,
- ffi_raw *args,
- _Jv_InterpMethodInvocation *inv)
+void
+_Jv_InterpMethod::run_normal (ffi_cif *,
+ void* ret,
+ ffi_raw * args,
+ void* __this)
{
- inv->running = this;
- inv->pc = bytecode ();
- inv->sp = inv->stack_base ();
- _Jv_word *locals = inv->local_base ();
-
- /* Go straight at it! the ffi raw format matches the internal
- stack representation exactly. At leat, that's the idea.
- */
- memcpy ((void*) locals, (void*) args, args_raw_size);
-
- next_segment:
- /* this will call the method _Jv_InterpMethod::continue0, see below */
- jobject ex =
- gnu::gcj::runtime::MethodInvocation::continue0
- ((gnu::gcj::RawData *)this, (gnu::gcj::RawData *)inv);
-
- if (ex == 0) // no exception...
- {
- /* define sp locally, so the POP? macros will pick it up */
- _Jv_word *sp = inv->sp;
- int rtype = cif->rtype->type;
-
- if (rtype == FFI_TYPE_POINTER)
- {
- jobject r = POPA();
- *(jobject*) retp = r;
- return 0;
- }
- else if (rtype == FFI_TYPE_SINT32)
- {
- jint r = POPI();
- *(jint*)retp = r;
- return 0;
- }
- else if (rtype == FFI_TYPE_VOID)
- {
- return 0;
- }
- else switch (rtype)
- {
- case FFI_TYPE_FLOAT:
- {
- jfloat r = POPF();
- *(jfloat*)retp = r;
- return 0;
- }
-
- case FFI_TYPE_DOUBLE:
- {
- jdouble r = POPD();
- *(jdouble*)retp = r;
- return 0;
- }
-
- case FFI_TYPE_UINT8:
- case FFI_TYPE_UINT16:
- case FFI_TYPE_UINT32:
- case FFI_TYPE_SINT8:
- case FFI_TYPE_SINT16:
- {
- jint r = POPI();
- *(jint*)retp = r;
- return 0;
- }
-
- case FFI_TYPE_SINT64:
- {
- jlong r = POPL();
- *(jlong*)retp = r;
- return 0;
- }
-
- default:
- throw_internal_error ("unknown return type");
- }
-
- }
+ _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
+ _this->run (ret, args);
+}
- /** handle an exception */
- if ( find_exception (ex, inv) )
- goto next_segment;
+void
+_Jv_InterpMethod::run_synch_object (ffi_cif *,
+ void* ret,
+ ffi_raw * args,
+ void* __this)
+{
+ _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
- java::lang::System::out->println
- (_Jv_NewStringUTF (self->name->data));
+ jobject rcv = (jobject) args[0].ptr;
+ JvSynchronize mutex (rcv);
- return ex;
+ _this->run (ret, args);
}
-bool _Jv_InterpMethod::find_exception (jobject ex,
- _Jv_InterpMethodInvocation *inv)
+void
+_Jv_InterpMethod::run_class (ffi_cif *,
+ void* ret,
+ ffi_raw * args,
+ void* __this)
{
- int logical_pc = inv->pc - bytecode ();
- _Jv_InterpException *exc = exceptions ();
- jclass exc_class = ex->getClass ();
-
- for (int i = 0; i < exc_count; i++)
- {
- if (exc[i].start_pc <= logical_pc && logical_pc < exc[i].end_pc)
- {
- jclass handler;
-
- if (exc[i].handler_type != 0)
- handler = (_Jv_ResolvePoolEntry (defining_class,
- exc[i].handler_type)).clazz;
- else
- handler = NULL;
-
- if (handler==NULL || handler->isAssignableFrom (exc_class))
- {
- inv->pc = bytecode () + exc[i].handler_pc;
- inv->sp = inv->stack_base (); // reset stack
- (inv->sp++)->o = ex; // push exception
- return true;
- }
- }
- }
- return false;
+ _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
+ _Jv_InitClass (_this->defining_class);
+ _this->run (ret, args);
}
-void _Jv_InterpMethod::run_normal (ffi_cif* cif,
+void
+_Jv_InterpMethod::run_synch_class (ffi_cif *,
void* ret,
ffi_raw * args,
void* __this)
{
- _Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
+ _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
- // we do the alloca of the method invocation here, to allow the method
- // "run" ro be inlined. Otherwise gcc will ignore the inline directive.
- int storage_size = _this->max_stack+_this->max_locals;
- _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*)
- alloca (sizeof (_Jv_InterpMethodInvocation)
- + storage_size * sizeof (_Jv_word));
+ jclass sync = _this->defining_class;
+ _Jv_InitClass (sync);
+ JvSynchronize mutex (sync);
- jobject ex = _this->run (cif, ret, args, inv);
- if (ex != 0) _Jv_Throw (ex);
+ _this->run (ret, args);
}
-void _Jv_InterpMethod::run_synch_object (ffi_cif* cif,
- void* ret,
- ffi_raw * args,
- void* __this)
+#ifdef DIRECT_THREADED
+// "Compile" a method by turning it from bytecode to direct-threaded
+// code.
+void
+_Jv_InterpMethod::compile (const void * const *insn_targets)
{
- _Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
- jobject rcv = (jobject)args[0].ptr;
-
- int storage_size = _this->max_stack+_this->max_locals;
- _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*)
- alloca (sizeof (_Jv_InterpMethodInvocation)
- + storage_size * sizeof (_Jv_word));
-
- _Jv_MonitorEnter (rcv);
- jobject ex = _this->run (cif, ret, args, inv);
- _Jv_MonitorExit (rcv);
-
- if (ex != 0) _Jv_Throw (ex);
-}
+ insn_slot *insns = NULL;
+ int next = 0;
+ unsigned char *codestart = bytecode ();
+ unsigned char *end = codestart + code_length;
+ _Jv_word *pool_data = defining_class->constants.data;
+
+#define SET_ONE(Field, Value) \
+ do \
+ { \
+ if (first_pass) \
+ ++next; \
+ else \
+ insns[next++].Field = Value; \
+ } \
+ while (0)
+
+#define SET_INSN(Value) SET_ONE (insn, (void *) Value)
+#define SET_INT(Value) SET_ONE (int_val, Value)
+#define SET_DATUM(Value) SET_ONE (datum, Value)
+
+ // Map from bytecode PC to slot in INSNS.
+ int *pc_mapping = (int *) __builtin_alloca (sizeof (int) * code_length);
+ for (int i = 0; i < code_length; ++i)
+ pc_mapping[i] = -1;
+
+ for (int i = 0; i < 2; ++i)
+ {
+ jboolean first_pass = i == 0;
-void _Jv_InterpMethod::run_synch_class (ffi_cif* cif,
- void* ret,
- ffi_raw * args,
- void* __this)
-{
- _Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
- jclass sync = _this->defining_class;
+ if (! first_pass)
+ {
+ insns = (insn_slot *) _Jv_AllocBytes (sizeof (insn_slot) * next);
+ next = 0;
+ }
- int storage_size = _this->max_stack+_this->max_locals;
- _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*)
- alloca (sizeof (_Jv_InterpMethodInvocation)
- + storage_size * sizeof (_Jv_word));
+ unsigned char *pc = codestart;
+ while (pc < end)
+ {
+ int base_pc_val = pc - codestart;
+ if (first_pass)
+ pc_mapping[base_pc_val] = next;
- _Jv_MonitorEnter (sync);
- jobject ex = _this->run (cif, ret, args, inv);
- _Jv_MonitorExit (sync);
+ java_opcode opcode = (java_opcode) *pc++;
+ // Just elide NOPs.
+ if (opcode == op_nop)
+ continue;
+ SET_INSN (insn_targets[opcode]);
- if (ex != 0) _Jv_Throw (ex);
-}
+ switch (opcode)
+ {
+ case op_nop:
+ case op_aconst_null:
+ case op_iconst_m1:
+ case op_iconst_0:
+ case op_iconst_1:
+ case op_iconst_2:
+ case op_iconst_3:
+ case op_iconst_4:
+ case op_iconst_5:
+ case op_lconst_0:
+ case op_lconst_1:
+ case op_fconst_0:
+ case op_fconst_1:
+ case op_fconst_2:
+ case op_dconst_0:
+ case op_dconst_1:
+ case op_iload_0:
+ case op_iload_1:
+ case op_iload_2:
+ case op_iload_3:
+ case op_lload_0:
+ case op_lload_1:
+ case op_lload_2:
+ case op_lload_3:
+ case op_fload_0:
+ case op_fload_1:
+ case op_fload_2:
+ case op_fload_3:
+ case op_dload_0:
+ case op_dload_1:
+ case op_dload_2:
+ case op_dload_3:
+ case op_aload_0:
+ case op_aload_1:
+ case op_aload_2:
+ case op_aload_3:
+ case op_iaload:
+ case op_laload:
+ case op_faload:
+ case op_daload:
+ case op_aaload:
+ case op_baload:
+ case op_caload:
+ case op_saload:
+ case op_istore_0:
+ case op_istore_1:
+ case op_istore_2:
+ case op_istore_3:
+ case op_lstore_0:
+ case op_lstore_1:
+ case op_lstore_2:
+ case op_lstore_3:
+ case op_fstore_0:
+ case op_fstore_1:
+ case op_fstore_2:
+ case op_fstore_3:
+ case op_dstore_0:
+ case op_dstore_1:
+ case op_dstore_2:
+ case op_dstore_3:
+ case op_astore_0:
+ case op_astore_1:
+ case op_astore_2:
+ case op_astore_3:
+ case op_iastore:
+ case op_lastore:
+ case op_fastore:
+ case op_dastore:
+ case op_aastore:
+ case op_bastore:
+ case op_castore:
+ case op_sastore:
+ case op_pop:
+ case op_pop2:
+ case op_dup:
+ case op_dup_x1:
+ case op_dup_x2:
+ case op_dup2:
+ case op_dup2_x1:
+ case op_dup2_x2:
+ case op_swap:
+ case op_iadd:
+ case op_isub:
+ case op_imul:
+ case op_idiv:
+ case op_irem:
+ case op_ishl:
+ case op_ishr:
+ case op_iushr:
+ case op_iand:
+ case op_ior:
+ case op_ixor:
+ case op_ladd:
+ case op_lsub:
+ case op_lmul:
+ case op_ldiv:
+ case op_lrem:
+ case op_lshl:
+ case op_lshr:
+ case op_lushr:
+ case op_land:
+ case op_lor:
+ case op_lxor:
+ case op_fadd:
+ case op_fsub:
+ case op_fmul:
+ case op_fdiv:
+ case op_frem:
+ case op_dadd:
+ case op_dsub:
+ case op_dmul:
+ case op_ddiv:
+ case op_drem:
+ case op_ineg:
+ case op_i2b:
+ case op_i2c:
+ case op_i2s:
+ case op_lneg:
+ case op_fneg:
+ case op_dneg:
+ case op_i2l:
+ case op_i2f:
+ case op_i2d:
+ case op_l2i:
+ case op_l2f:
+ case op_l2d:
+ case op_f2i:
+ case op_f2l:
+ case op_f2d:
+ case op_d2i:
+ case op_d2l:
+ case op_d2f:
+ case op_lcmp:
+ case op_fcmpl:
+ case op_fcmpg:
+ case op_dcmpl:
+ case op_dcmpg:
+ case op_monitorenter:
+ case op_monitorexit:
+ case op_ireturn:
+ case op_lreturn:
+ case op_freturn:
+ case op_dreturn:
+ case op_areturn:
+ case op_return:
+ case op_athrow:
+ case op_arraylength:
+ // No argument, nothing else to do.
+ break;
+
+ case op_bipush:
+ SET_INT (get1s (pc));
+ ++pc;
+ break;
+
+ case op_ldc:
+ {
+ int index = get1u (pc);
+ ++pc;
+ SET_DATUM (pool_data[index].o);
+ }
+ break;
+
+ case op_ret:
+ case op_iload:
+ case op_lload:
+ case op_fload:
+ case op_dload:
+ case op_aload:
+ case op_istore:
+ case op_lstore:
+ case op_fstore:
+ case op_dstore:
+ case op_astore:
+ case op_newarray:
+ SET_INT (get1u (pc));
+ ++pc;
+ break;
+
+ case op_iinc:
+ SET_INT (get1u (pc));
+ SET_INT (get1s (pc + 1));
+ pc += 2;
+ break;
+
+ case op_ldc_w:
+ {
+ int index = get2u (pc);
+ pc += 2;
+ SET_DATUM (pool_data[index].o);
+ }
+ break;
-/* this is the exception handler hack, for the interpreter */
-void
-gnu::gcj::runtime::MethodInvocation::continue1 (gnu::gcj::RawData *meth,
- gnu::gcj::RawData *inv)
-{
- _Jv_InterpMethod *meth0 = (_Jv_InterpMethod*)meth;
- _Jv_InterpMethodInvocation *inv0 = (_Jv_InterpMethodInvocation*)inv;
- meth0->continue1 (inv0);
-}
+ case op_ldc2_w:
+ {
+ int index = get2u (pc);
+ pc += 2;
+ SET_DATUM (&pool_data[index]);
+ }
+ break;
+
+ case op_sipush:
+ SET_INT (get2s (pc));
+ pc += 2;
+ break;
+
+ case op_new:
+ case op_getstatic:
+ case op_getfield:
+ case op_putfield:
+ case op_putstatic:
+ case op_anewarray:
+ case op_instanceof:
+ case op_checkcast:
+ case op_invokespecial:
+ case op_invokestatic:
+ case op_invokevirtual:
+ SET_INT (get2u (pc));
+ pc += 2;
+ break;
+
+ case op_multianewarray:
+ SET_INT (get2u (pc));
+ SET_INT (get1u (pc + 2));
+ pc += 3;
+ break;
+
+ case op_jsr:
+ case op_ifeq:
+ case op_ifne:
+ case op_iflt:
+ case op_ifge:
+ case op_ifgt:
+ case op_ifle:
+ case op_if_icmpeq:
+ case op_if_icmpne:
+ case op_if_icmplt:
+ case op_if_icmpge:
+ case op_if_icmpgt:
+ case op_if_icmple:
+ case op_if_acmpeq:
+ case op_if_acmpne:
+ case op_ifnull:
+ case op_ifnonnull:
+ case op_goto:
+ {
+ int offset = get2s (pc);
+ pc += 2;
+
+ int new_pc = base_pc_val + offset;
+
+ bool orig_was_goto = opcode == op_goto;
+
+ // Thread jumps. We limit the loop count; this lets
+ // us avoid infinite loops if the bytecode contains
+ // such. `10' is arbitrary.
+ int count = 10;
+ while (codestart[new_pc] == op_goto && count-- > 0)
+ new_pc += get2s (&codestart[new_pc + 1]);
+
+ // If the jump takes us to a `return' instruction and
+ // the original branch was an unconditional goto, then
+ // we hoist the return.
+ opcode = (java_opcode) codestart[new_pc];
+ if (orig_was_goto
+ && (opcode == op_ireturn || opcode == op_lreturn
+ || opcode == op_freturn || opcode == op_dreturn
+ || opcode == op_areturn || opcode == op_return))
+ {
+ --next;
+ SET_INSN (insn_targets[opcode]);
+ }
+ else
+ SET_DATUM (&insns[pc_mapping[new_pc]]);
+ }
+ break;
-/*
- This proceeds execution, as designated in "inv". If an exception
- happens, then it is simply thrown, and handled in Java. Thus, the pc
- needs to be stored in the invocation at all times, so we can figure
- out which handler (if any) to invoke.
+ case op_tableswitch:
+ {
+ while ((pc - codestart) % 4 != 0)
+ ++pc;
+
+ jint def = get4 (pc);
+ SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
+ pc += 4;
+
+ int low = get4 (pc);
+ SET_INT (low);
+ pc += 4;
+ int high = get4 (pc);
+ SET_INT (high);
+ pc += 4;
+
+ for (int i = low; i <= high; ++i)
+ {
+ SET_DATUM (&insns[pc_mapping[base_pc_val + get4 (pc)]]);
+ pc += 4;
+ }
+ }
+ break;
- One design issue, which I have not completely considered, is if it
- should be possible to have interpreted classes linked in! Seldom used
- (or non-critical) classes could reasonably be interpreted.
-*/
+ case op_lookupswitch:
+ {
+ while ((pc - codestart) % 4 != 0)
+ ++pc;
+
+ jint def = get4 (pc);
+ SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
+ pc += 4;
+
+ jint npairs = get4 (pc);
+ pc += 4;
+ SET_INT (npairs);
+
+ while (npairs-- > 0)
+ {
+ jint match = get4 (pc);
+ jint offset = get4 (pc + 4);
+ SET_INT (match);
+ SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
+ pc += 8;
+ }
+ }
+ break;
+ case op_invokeinterface:
+ {
+ jint index = get2u (pc);
+ pc += 2;
+ // We ignore the next two bytes.
+ pc += 2;
+ SET_INT (index);
+ }
+ break;
-#ifdef TIME_MAINLOOP
-static jlong insn_time [256] = { 0 };
-static jlong insn_count[256] = { 0 };
+ case op_wide:
+ {
+ opcode = (java_opcode) get1u (pc);
+ pc += 1;
+ jint val = get2u (pc);
+ pc += 2;
+
+ // We implement narrow and wide instructions using the
+ // same code in the interpreter. So we rewrite the
+ // instruction slot here.
+ if (! first_pass)
+ insns[next - 1].insn = (void *) insn_targets[opcode];
+ SET_INT (val);
+
+ if (opcode == op_iinc)
+ {
+ SET_INT (get2s (pc));
+ pc += 2;
+ }
+ }
+ break;
-static void
-dump_time ()
-{
- double total_all = 0;
- for (int i = 0; i < 256; i++)
- {
- total_all += insn_time[i];
+ case op_jsr_w:
+ case op_goto_w:
+ {
+ jint offset = get4 (pc);
+ pc += 4;
+ SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
+ }
+ break;
+
+ // Some "can't happen" cases that we include for
+ // error-checking purposes.
+ case op_putfield_1:
+ case op_putfield_2:
+ case op_putfield_4:
+ case op_putfield_8:
+ case op_putfield_a:
+ case op_putstatic_1:
+ case op_putstatic_2:
+ case op_putstatic_4:
+ case op_putstatic_8:
+ case op_putstatic_a:
+ case op_getfield_1:
+ case op_getfield_2s:
+ case op_getfield_2u:
+ case op_getfield_4:
+ case op_getfield_8:
+ case op_getfield_a:
+ case op_getstatic_1:
+ case op_getstatic_2s:
+ case op_getstatic_2u:
+ case op_getstatic_4:
+ case op_getstatic_8:
+ case op_getstatic_a:
+ default:
+ // Fail somehow.
+ break;
+ }
+ }
}
- for (int i = 0; i < 256; i++)
+ // Now update exceptions.
+ _Jv_InterpException *exc = exceptions ();
+ for (int i = 0; i < exc_count; ++i)
{
- jlong total = insn_time[i];
- jlong count = insn_count[i];
-
- if (count == 0) continue;
+ exc[i].start_pc.p = &insns[pc_mapping[exc[i].start_pc.i]];
+ exc[i].end_pc.p = &insns[pc_mapping[exc[i].end_pc.i]];
+ exc[i].handler_pc.p = &insns[pc_mapping[exc[i].handler_pc.i]];
+ jclass handler = (_Jv_ResolvePoolEntry (defining_class,
+ exc[i].handler_type.i)).clazz;
+ exc[i].handler_type.p = handler;
+ }
- jlong amount = total/count;
+ prepared = insns;
+}
+#endif /* DIRECT_THREADED */
- printf ("in 0x%02x: %7Li %7Li %7Li %2.1f%%\n", i,
- (long long)count, (long long)total, (long long)amount,
- (float) (100.0*(double)total/total_all)
- );
- }
+// This function exists so that the stack-tracing code can find the
+// boundaries of the interpreter.
+void
+_Jv_StartOfInterpreter (void)
+{
}
-#endif
-
-void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
+
+void
+_Jv_InterpMethod::run (void *retp, ffi_raw *args)
{
- /* for some reason, which I do not understand, the compiler on x86
- * allocates almost 4k stack space for this function! Even though
- * there are many local variables, they are all nicely contained
- * within a block scope, except for the few declared right below
- * here. What's going on?? It could well be, that there in fact is
- * on the order of 1000 local variables, including all those inlined
- * and expanded from macros... Compiling with -O0, it allocates a
- * "modest" 300 bytes of stack space. Among all those options of
- * gcc, why isn't there a -fpack-stack, allowing reuse of stack
- * locations? */
-
- _Jv_word *sp = inv->sp;
- unsigned char *pc = inv->pc;
- _Jv_word *locals = inv->local_base ();
- int opcode;
+ using namespace java::lang::reflect;
- jclass defining_class = this->defining_class;
- _Jv_word *pool_data = defining_class->constants.data;
-
- /* these two are used in the invokeXXX instructions */
- void (*fun)(...);
- _Jv_ResolvedMethod* rmeth;
+ // FRAME_DESC registers this particular invocation as the top-most
+ // interpreter frame. This lets the stack tracing code (for
+ // Throwable) print information about the method being interpreted
+ // rather than about the interpreter itself. FRAME_DESC has a
+ // destructor so it cleans up automatically when the interpreter
+ // returns.
+ java::lang::Thread *thread = java::lang::Thread::currentThread();
+ _Jv_MethodChain frame_desc (this,
+ (_Jv_MethodChain **) &thread->interp_frame);
-#ifdef TIME_MAINLOOP
- struct timeval tv;
- int last_opcode;
- jlong last_time;
- static jlong time_warp = 0;
+ _Jv_word stack[max_stack];
+ _Jv_word *sp = stack;
-#define USEC(TV) \
- ((jlong) (TV).tv_sec * 1000000LL + (jlong)(TV).tv_usec)
+ _Jv_word locals[max_locals];
+ /* Go straight at it! the ffi raw format matches the internal
+ stack representation exactly. At least, that's the idea.
+ */
+ memcpy ((void*) locals, (void*) args, args_raw_size);
- if (time_warp == 0)
- {
- struct timeval tv2;
-
- gettimeofday (&tv, 0);
- for (int i = 0; i < 100; i++)
- gettimeofday (&tv2, 0);
-
- jlong then = USEC(tv);
- jlong now = USEC(tv2);
- time_warp = (now - then) / 100;
-
- if (time_warp == 0)
- time_warp = 1;
- }
-
-#define TIME_SUSPEND do { \
- gettimeofday (&tv, 0); \
- jlong now = USEC(tv); \
- insn_time[last_opcode] += (now - last_time) - time_warp; \
-} while(0)
-
-#define TIME_RESUME do { \
- gettimeofday (&tv, 0); \
- last_time = USEC(tv); \
-} while(0)
-
- last_opcode = 0;
- gettimeofday (&tv, 0);
- last_time = (jlong)tv.tv_sec * 1000000LL + (jlong)tv.tv_usec;
+ _Jv_word *pool_data = defining_class->constants.data;
+ /* These three are temporaries for common code used by several
+ instructions. */
+ void (*fun)();
+ _Jv_ResolvedMethod* rmeth;
+ int tmpval;
+
+#define INSN_LABEL(op) &&insn_##op
+
+ static const void *const insn_target[] =
+ {
+ INSN_LABEL(nop),
+ INSN_LABEL(aconst_null),
+ INSN_LABEL(iconst_m1),
+ INSN_LABEL(iconst_0),
+ INSN_LABEL(iconst_1),
+ INSN_LABEL(iconst_2),
+ INSN_LABEL(iconst_3),
+ INSN_LABEL(iconst_4),
+ INSN_LABEL(iconst_5),
+ INSN_LABEL(lconst_0),
+ INSN_LABEL(lconst_1),
+ INSN_LABEL(fconst_0),
+ INSN_LABEL(fconst_1),
+ INSN_LABEL(fconst_2),
+ INSN_LABEL(dconst_0),
+ INSN_LABEL(dconst_1),
+ INSN_LABEL(bipush),
+ INSN_LABEL(sipush),
+ INSN_LABEL(ldc),
+ INSN_LABEL(ldc_w),
+ INSN_LABEL(ldc2_w),
+ INSN_LABEL(iload),
+ INSN_LABEL(lload),
+ INSN_LABEL(fload),
+ INSN_LABEL(dload),
+ INSN_LABEL(aload),
+ INSN_LABEL(iload_0),
+ INSN_LABEL(iload_1),
+ INSN_LABEL(iload_2),
+ INSN_LABEL(iload_3),
+ INSN_LABEL(lload_0),
+ INSN_LABEL(lload_1),
+ INSN_LABEL(lload_2),
+ INSN_LABEL(lload_3),
+ INSN_LABEL(fload_0),
+ INSN_LABEL(fload_1),
+ INSN_LABEL(fload_2),
+ INSN_LABEL(fload_3),
+ INSN_LABEL(dload_0),
+ INSN_LABEL(dload_1),
+ INSN_LABEL(dload_2),
+ INSN_LABEL(dload_3),
+ INSN_LABEL(aload_0),
+ INSN_LABEL(aload_1),
+ INSN_LABEL(aload_2),
+ INSN_LABEL(aload_3),
+ INSN_LABEL(iaload),
+ INSN_LABEL(laload),
+ INSN_LABEL(faload),
+ INSN_LABEL(daload),
+ INSN_LABEL(aaload),
+ INSN_LABEL(baload),
+ INSN_LABEL(caload),
+ INSN_LABEL(saload),
+ INSN_LABEL(istore),
+ INSN_LABEL(lstore),
+ INSN_LABEL(fstore),
+ INSN_LABEL(dstore),
+ INSN_LABEL(astore),
+ INSN_LABEL(istore_0),
+ INSN_LABEL(istore_1),
+ INSN_LABEL(istore_2),
+ INSN_LABEL(istore_3),
+ INSN_LABEL(lstore_0),
+ INSN_LABEL(lstore_1),
+ INSN_LABEL(lstore_2),
+ INSN_LABEL(lstore_3),
+ INSN_LABEL(fstore_0),
+ INSN_LABEL(fstore_1),
+ INSN_LABEL(fstore_2),
+ INSN_LABEL(fstore_3),
+ INSN_LABEL(dstore_0),
+ INSN_LABEL(dstore_1),
+ INSN_LABEL(dstore_2),
+ INSN_LABEL(dstore_3),
+ INSN_LABEL(astore_0),
+ INSN_LABEL(astore_1),
+ INSN_LABEL(astore_2),
+ INSN_LABEL(astore_3),
+ INSN_LABEL(iastore),
+ INSN_LABEL(lastore),
+ INSN_LABEL(fastore),
+ INSN_LABEL(dastore),
+ INSN_LABEL(aastore),
+ INSN_LABEL(bastore),
+ INSN_LABEL(castore),
+ INSN_LABEL(sastore),
+ INSN_LABEL(pop),
+ INSN_LABEL(pop2),
+ INSN_LABEL(dup),
+ INSN_LABEL(dup_x1),
+ INSN_LABEL(dup_x2),
+ INSN_LABEL(dup2),
+ INSN_LABEL(dup2_x1),
+ INSN_LABEL(dup2_x2),
+ INSN_LABEL(swap),
+ INSN_LABEL(iadd),
+ INSN_LABEL(ladd),
+ INSN_LABEL(fadd),
+ INSN_LABEL(dadd),
+ INSN_LABEL(isub),
+ INSN_LABEL(lsub),
+ INSN_LABEL(fsub),
+ INSN_LABEL(dsub),
+ INSN_LABEL(imul),
+ INSN_LABEL(lmul),
+ INSN_LABEL(fmul),
+ INSN_LABEL(dmul),
+ INSN_LABEL(idiv),
+ INSN_LABEL(ldiv),
+ INSN_LABEL(fdiv),
+ INSN_LABEL(ddiv),
+ INSN_LABEL(irem),
+ INSN_LABEL(lrem),
+ INSN_LABEL(frem),
+ INSN_LABEL(drem),
+ INSN_LABEL(ineg),
+ INSN_LABEL(lneg),
+ INSN_LABEL(fneg),
+ INSN_LABEL(dneg),
+ INSN_LABEL(ishl),
+ INSN_LABEL(lshl),
+ INSN_LABEL(ishr),
+ INSN_LABEL(lshr),
+ INSN_LABEL(iushr),
+ INSN_LABEL(lushr),
+ INSN_LABEL(iand),
+ INSN_LABEL(land),
+ INSN_LABEL(ior),
+ INSN_LABEL(lor),
+ INSN_LABEL(ixor),
+ INSN_LABEL(lxor),
+ INSN_LABEL(iinc),
+ INSN_LABEL(i2l),
+ INSN_LABEL(i2f),
+ INSN_LABEL(i2d),
+ INSN_LABEL(l2i),
+ INSN_LABEL(l2f),
+ INSN_LABEL(l2d),
+ INSN_LABEL(f2i),
+ INSN_LABEL(f2l),
+ INSN_LABEL(f2d),
+ INSN_LABEL(d2i),
+ INSN_LABEL(d2l),
+ INSN_LABEL(d2f),
+ INSN_LABEL(i2b),
+ INSN_LABEL(i2c),
+ INSN_LABEL(i2s),
+ INSN_LABEL(lcmp),
+ INSN_LABEL(fcmpl),
+ INSN_LABEL(fcmpg),
+ INSN_LABEL(dcmpl),
+ INSN_LABEL(dcmpg),
+ INSN_LABEL(ifeq),
+ INSN_LABEL(ifne),
+ INSN_LABEL(iflt),
+ INSN_LABEL(ifge),
+ INSN_LABEL(ifgt),
+ INSN_LABEL(ifle),
+ INSN_LABEL(if_icmpeq),
+ INSN_LABEL(if_icmpne),
+ INSN_LABEL(if_icmplt),
+ INSN_LABEL(if_icmpge),
+ INSN_LABEL(if_icmpgt),
+ INSN_LABEL(if_icmple),
+ INSN_LABEL(if_acmpeq),
+ INSN_LABEL(if_acmpne),
+ INSN_LABEL(goto),
+ INSN_LABEL(jsr),
+ INSN_LABEL(ret),
+ INSN_LABEL(tableswitch),
+ INSN_LABEL(lookupswitch),
+ INSN_LABEL(ireturn),
+ INSN_LABEL(lreturn),
+ INSN_LABEL(freturn),
+ INSN_LABEL(dreturn),
+ INSN_LABEL(areturn),
+ INSN_LABEL(return),
+ INSN_LABEL(getstatic),
+ INSN_LABEL(putstatic),
+ INSN_LABEL(getfield),
+ INSN_LABEL(putfield),
+ INSN_LABEL(invokevirtual),
+ INSN_LABEL(invokespecial),
+ INSN_LABEL(invokestatic),
+ INSN_LABEL(invokeinterface),
+ 0, /* Unused. */
+ INSN_LABEL(new),
+ INSN_LABEL(newarray),
+ INSN_LABEL(anewarray),
+ INSN_LABEL(arraylength),
+ INSN_LABEL(athrow),
+ INSN_LABEL(checkcast),
+ INSN_LABEL(instanceof),
+ INSN_LABEL(monitorenter),
+ INSN_LABEL(monitorexit),
+#ifdef DIRECT_THREADED
+ 0, // wide
#else
-
-#define TIME_SUSPEND
-#define TIME_RESUME
-
+ INSN_LABEL(wide),
#endif
+ INSN_LABEL(multianewarray),
+ INSN_LABEL(ifnull),
+ INSN_LABEL(ifnonnull),
+ INSN_LABEL(goto_w),
+ INSN_LABEL(jsr_w),
+ 0
+ };
+
+ pc_t pc;
+
+#ifdef DIRECT_THREADED
+
+#define NEXT_INSN goto *((pc++)->insn)
+#define INTVAL() ((pc++)->int_val)
+#define AVAL() ((pc++)->datum)
+
+#define GET1S() INTVAL ()
+#define GET2S() INTVAL ()
+#define GET1U() INTVAL ()
+#define GET2U() INTVAL ()
+#define AVAL1U() AVAL ()
+#define AVAL2U() AVAL ()
+#define AVAL2UP() AVAL ()
+#define SKIP_GOTO ++pc
+#define GOTO_VAL() (insn_slot *) pc->datum
+#define PCVAL(unionval) unionval.p
+#define AMPAMP(label) &&label
+
+ // Compile if we must.
+ if (prepared == NULL)
+ compile (insn_target);
+ pc = (insn_slot *) prepared;
- next_insn:
- inv->pc = pc;
+#else
-#ifdef TIME_MAINLOOP
+#define NEXT_INSN goto *(insn_target[*pc++])
- gettimeofday (&tv, 0);
- jlong now = USEC(tv);
- insn_time[last_opcode] += (now - last_time) - time_warp;
- last_time = now;
- last_opcode = *pc;
- insn_count[last_opcode] += 1;
+#define GET1S() get1s (pc++)
+#define GET2S() (pc += 2, get2s (pc- 2))
+#define GET1U() get1u (pc++)
+#define GET2U() (pc += 2, get2u (pc - 2))
+#define AVAL1U() ({ int index = get1u (pc++); pool_data[index].o; })
+#define AVAL2U() ({ int index = get2u (pc); pc += 2; pool_data[index].o; })
+#define AVAL2UP() ({ int index = get2u (pc); pc += 2; &pool_data[index]; })
+#define SKIP_GOTO pc += 2
+#define GOTO_VAL() pc - 1 + get2s (pc)
+#define PCVAL(unionval) unionval.i
+#define AMPAMP(label) NULL
-#endif
- opcode = *pc++;
+ pc = bytecode ();
- /* we special-case the single opcode aload_0 -- it makes
- up 10% of the time spent in the main loop. */
+#endif /* DIRECT_THREADED */
- switch (opcode)
+#define TAKE_GOTO pc = GOTO_VAL ()
+
+ try
{
- case op_aload_0: // 0x2a
- LOADA(0);
- goto next_insn;
+ // We keep nop around. It is used if we're interpreting the
+ // bytecodes and not doing direct threading.
+ insn_nop:
+ NEXT_INSN;
- case op_iload: // 0x15
- LOADI (get1u (pc++));
- goto next_insn;
+ /* The first few instructions here are ordered according to their
+ frequency, in the hope that this will improve code locality a
+ little. */
- case op_getfield_4: // 0xd8
- {
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- PUSHI (*(jint*) ((char*)obj + field_offset));
- }
- goto next_insn;
+ insn_aload_0: // 0x2a
+ LOADA (0);
+ NEXT_INSN;
- case op_iload_1: // 0x1b
- LOADI (1);
- goto next_insn;
+ insn_iload: // 0x15
+ LOADI (GET1U ());
+ NEXT_INSN;
- case op_getfield_a: // 0xda
- {
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- PUSHA(*(jobject*) ((char*)obj + field_offset));
- }
- goto next_insn;
+ insn_iload_1: // 0x1b
+ LOADI (1);
+ NEXT_INSN;
- case op_invokevirtual: // 0xb6
+ insn_invokevirtual: // 0xb6
{
- int index = get2u (pc); pc += 2;
+ int index = GET2U ();
/* _Jv_ResolvePoolEntry returns immediately if the value already
* is resolved. If we want to clutter up the code here to gain
rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
sp -= rmeth->stack_item_count;
- NULLCHECK(sp[0]);
+ // We don't use NULLCHECK here because we can't rely on that
+ // working if the method is final. So instead we do an
+ // explicit test.
+ if (! sp[0].o)
+ throw new java::lang::NullPointerException;
+
+ if (rmeth->vtable_index == -1)
+ {
+ // final methods do not appear in the vtable,
+ // if it does not appear in the superclass.
+ fun = (void (*)()) rmeth->method->ncode;
+ }
+ else
+ {
+ jobject rcv = sp[0].o;
+ _Jv_VTable *table = *(_Jv_VTable**) rcv;
+ fun = (void (*)()) table->get_method (rmeth->vtable_index);
+ }
+
+#ifdef DIRECT_THREADED
+ // Rewrite instruction so that we use a faster pre-resolved
+ // method.
+ pc[-2].insn = &&invokevirtual_resolved;
+ pc[-1].datum = rmeth;
+#endif /* DIRECT_THREADED */
+ }
+ goto perform_invoke;
+
+#ifdef DIRECT_THREADED
+ invokevirtual_resolved:
+ {
+ rmeth = (_Jv_ResolvedMethod *) AVAL ();
+ sp -= rmeth->stack_item_count;
+ // We don't use NULLCHECK here because we can't rely on that
+ // working if the method is final. So instead we do an
+ // explicit test.
+ if (! sp[0].o)
+ throw new java::lang::NullPointerException;
if (rmeth->vtable_index == -1)
{
// final methods do not appear in the vtable,
// if it does not appear in the superclass.
- fun = (void (*) (...)) rmeth->method->ncode;
+ fun = (void (*)()) rmeth->method->ncode;
}
else
{
jobject rcv = sp[0].o;
- _Jv_VTable *table = *(_Jv_VTable**)rcv;
- fun = (void (*) (...))table->method[rmeth->vtable_index];
+ _Jv_VTable *table = *(_Jv_VTable**) rcv;
+ fun = (void (*)()) table->get_method (rmeth->vtable_index);
}
}
goto perform_invoke;
+#endif /* DIRECT_THREADED */
perform_invoke:
{
jdouble rvalue;
- TIME_SUSPEND;
+#if FFI_NATIVE_RAW_API
+ /* We assume that this is only implemented if it's correct */
+ /* to use it here. On a 64 bit machine, it never is. */
ffi_raw_call (cif, fun, (void*)&rvalue, raw);
- TIME_RESUME;
+#else
+ ffi_java_raw_call (cif, fun, (void*)&rvalue, raw);
+#endif
int rtype = cif->rtype->type;
{
/* skip */
}
- else switch (rtype)
+ else
{
- case FFI_TYPE_SINT8:
- {
- jbyte value = (*(jint*)&rvalue) & 0xff;
- PUSHI (value);
- }
- break;
+ switch (rtype)
+ {
+ case FFI_TYPE_SINT8:
+ {
+ jbyte value = (*(jint*)&rvalue) & 0xff;
+ PUSHI (value);
+ }
+ break;
- case FFI_TYPE_SINT16:
- {
- jshort value = (*(jint*)&rvalue) & 0xffff;
- PUSHI (value);
- }
- break;
+ case FFI_TYPE_SINT16:
+ {
+ jshort value = (*(jint*)&rvalue) & 0xffff;
+ PUSHI (value);
+ }
+ break;
- case FFI_TYPE_UINT16:
- {
- jint value = (*(jint*)&rvalue) & 0xffff;
- PUSHI (value);
- }
- break;
+ case FFI_TYPE_UINT16:
+ {
+ jint value = (*(jint*)&rvalue) & 0xffff;
+ PUSHI (value);
+ }
+ break;
+
+ case FFI_TYPE_FLOAT:
+ PUSHF (*(jfloat*)&rvalue);
+ break;
- case FFI_TYPE_FLOAT:
- PUSHF (*(jfloat*)&rvalue);
- break;
+ case FFI_TYPE_DOUBLE:
+ PUSHD (rvalue);
+ break;
- case FFI_TYPE_DOUBLE:
- PUSHD (rvalue);
- break;
+ case FFI_TYPE_SINT64:
+ PUSHL (*(jlong*)&rvalue);
+ break;
- case FFI_TYPE_SINT64:
- PUSHL (*(jlong*)&rvalue);
- break;
-
- default:
- throw_internal_error ("unknown return type in invokeXXX");
+ default:
+ throw_internal_error ("unknown return type in invokeXXX");
+ }
}
-
}
- goto next_insn;
+ NEXT_INSN;
-
- case op_nop:
- goto next_insn;
-
- case op_aconst_null:
+ insn_aconst_null:
PUSHA (NULL);
- goto next_insn;
-
- case op_iconst_m1:
- case op_iconst_0:
- case op_iconst_1:
- case op_iconst_2:
- case op_iconst_3:
- case op_iconst_4:
- case op_iconst_5:
- PUSHI (opcode-op_iconst_0);
- goto next_insn;
-
- case op_lconst_0:
- case op_lconst_1:
- PUSHL ((jlong) (opcode-op_lconst_0));
- goto next_insn;
-
- case op_fconst_0:
- case op_fconst_1:
- case op_fconst_2:
- PUSHF ((jfloat) (opcode-op_fconst_0));
- goto next_insn;
-
- case op_dconst_0:
- case op_dconst_1:
- PUSHD ((jdouble) (opcode-op_dconst_0));
- goto next_insn;
-
- case op_bipush:
- PUSHI (get1s(pc++));
- goto next_insn;
-
- case op_sipush:
- PUSHI (get2s(pc)); pc += 2;
- goto next_insn;
-
- case op_ldc:
- {
- int index = get1u (pc++);
- PUSHA(pool_data[index].o);
- }
- goto next_insn;
-
- case op_ldc_w:
- {
- int index = get2u (pc); pc += 2;
- PUSHA(pool_data[index].o);
- }
- goto next_insn;
-
- case op_ldc2_w:
- {
- int index = get2u (pc); pc += 2;
- memcpy (sp, &pool_data[index], 2*sizeof (_Jv_word));
+ NEXT_INSN;
+
+ insn_iconst_m1:
+ PUSHI (-1);
+ NEXT_INSN;
+
+ insn_iconst_0:
+ PUSHI (0);
+ NEXT_INSN;
+
+ insn_iconst_1:
+ PUSHI (1);
+ NEXT_INSN;
+
+ insn_iconst_2:
+ PUSHI (2);
+ NEXT_INSN;
+
+ insn_iconst_3:
+ PUSHI (3);
+ NEXT_INSN;
+
+ insn_iconst_4:
+ PUSHI (4);
+ NEXT_INSN;
+
+ insn_iconst_5:
+ PUSHI (5);
+ NEXT_INSN;
+
+ insn_lconst_0:
+ PUSHL (0);
+ NEXT_INSN;
+
+ insn_lconst_1:
+ PUSHL (1);
+ NEXT_INSN;
+
+ insn_fconst_0:
+ PUSHF (0);
+ NEXT_INSN;
+
+ insn_fconst_1:
+ PUSHF (1);
+ NEXT_INSN;
+
+ insn_fconst_2:
+ PUSHF (2);
+ NEXT_INSN;
+
+ insn_dconst_0:
+ PUSHD (0);
+ NEXT_INSN;
+
+ insn_dconst_1:
+ PUSHD (1);
+ NEXT_INSN;
+
+ insn_bipush:
+ // For direct threaded, bipush and sipush are the same.
+#ifndef DIRECT_THREADED
+ PUSHI (GET1S ());
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+ insn_sipush:
+ PUSHI (GET2S ());
+ NEXT_INSN;
+
+ insn_ldc:
+ // For direct threaded, ldc and ldc_w are the same.
+#ifndef DIRECT_THREADED
+ PUSHA ((jobject) AVAL1U ());
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+ insn_ldc_w:
+ PUSHA ((jobject) AVAL2U ());
+ NEXT_INSN;
+
+ insn_ldc2_w:
+ {
+ void *where = AVAL2UP ();
+ memcpy (sp, where, 2*sizeof (_Jv_word));
sp += 2;
}
- goto next_insn;
+ NEXT_INSN;
- case op_lload:
- LOADL (get1u (pc++));
- goto next_insn;
+ insn_lload:
+ LOADL (GET1U ());
+ NEXT_INSN;
- case op_fload:
- LOADF (get1u (pc++));
- goto next_insn;
+ insn_fload:
+ LOADF (GET1U ());
+ NEXT_INSN;
- case op_dload:
- LOADD (get1u (pc++));
- goto next_insn;
+ insn_dload:
+ LOADD (GET1U ());
+ NEXT_INSN;
- case op_aload:
- LOADA (get1u (pc++));
- goto next_insn;
+ insn_aload:
+ LOADA (GET1U ());
+ NEXT_INSN;
- case op_iload_0:
+ insn_iload_0:
LOADI (0);
- goto next_insn;
+ NEXT_INSN;
- case op_iload_2:
+ insn_iload_2:
LOADI (2);
- goto next_insn;
+ NEXT_INSN;
- case op_iload_3:
+ insn_iload_3:
LOADI (3);
- goto next_insn;
-
- case op_lload_0:
- case op_lload_1:
- case op_lload_2:
- case op_lload_3:
- LOADL (opcode-op_lload_0);
- goto next_insn;
-
- case op_fload_0:
- case op_fload_1:
- case op_fload_2:
- case op_fload_3:
- LOADF (opcode-op_fload_0);
- goto next_insn;
-
- case op_dload_0:
- case op_dload_1:
- case op_dload_2:
- case op_dload_3:
- LOADD (opcode-op_dload_0);
- goto next_insn;
-
- case op_aload_1:
+ NEXT_INSN;
+
+ insn_lload_0:
+ LOADL (0);
+ NEXT_INSN;
+
+ insn_lload_1:
+ LOADL (1);
+ NEXT_INSN;
+
+ insn_lload_2:
+ LOADL (2);
+ NEXT_INSN;
+
+ insn_lload_3:
+ LOADL (3);
+ NEXT_INSN;
+
+ insn_fload_0:
+ LOADF (0);
+ NEXT_INSN;
+
+ insn_fload_1:
+ LOADF (1);
+ NEXT_INSN;
+
+ insn_fload_2:
+ LOADF (2);
+ NEXT_INSN;
+
+ insn_fload_3:
+ LOADF (3);
+ NEXT_INSN;
+
+ insn_dload_0:
+ LOADD (0);
+ NEXT_INSN;
+
+ insn_dload_1:
+ LOADD (1);
+ NEXT_INSN;
+
+ insn_dload_2:
+ LOADD (2);
+ NEXT_INSN;
+
+ insn_dload_3:
+ LOADD (3);
+ NEXT_INSN;
+
+ insn_aload_1:
LOADA(1);
- goto next_insn;
+ NEXT_INSN;
- case op_aload_2:
+ insn_aload_2:
LOADA(2);
- goto next_insn;
+ NEXT_INSN;
- case op_aload_3:
+ insn_aload_3:
LOADA(3);
- goto next_insn;
+ NEXT_INSN;
- case op_iaload:
+ insn_iaload:
{
jint index = POPI();
jintArray arr = (jintArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHI( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_laload:
+ insn_laload:
{
jint index = POPI();
jlongArray arr = (jlongArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHL( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_faload:
+ insn_faload:
{
jint index = POPI();
jfloatArray arr = (jfloatArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHF( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_daload:
+ insn_daload:
{
jint index = POPI();
jdoubleArray arr = (jdoubleArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHD( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_aaload:
+ insn_aaload:
{
jint index = POPI();
jobjectArray arr = (jobjectArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHA( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_baload:
+ insn_baload:
{
jint index = POPI();
jbyteArray arr = (jbyteArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHI( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_caload:
+ insn_caload:
{
jint index = POPI();
jcharArray arr = (jcharArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHI( elements(arr)[index] );
}
- goto next_insn;
+ NEXT_INSN;
- case op_saload:
+ insn_saload:
{
jint index = POPI();
jshortArray arr = (jshortArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
PUSHI( elements(arr)[index] );
}
- goto next_insn;
-
- case op_istore:
- STOREI (get1u (pc++));
- goto next_insn;
-
- case op_lstore:
- STOREL (get1u (pc++));
- goto next_insn;
-
- case op_fstore:
- STOREF (get1u (pc++));
- goto next_insn;
-
- case op_dstore:
- STORED (get1u (pc++));
- goto next_insn;
-
- case op_astore:
- STOREI (get1u (pc++));
- goto next_insn;
-
- case op_istore_0:
- case op_istore_1:
- case op_istore_2:
- case op_istore_3:
- STOREI (opcode-op_istore_0);
- goto next_insn;
-
- case op_lstore_0:
- case op_lstore_1:
- case op_lstore_2:
- case op_lstore_3:
- STOREL (opcode-op_lstore_0);
- goto next_insn;
-
- case op_fstore_0:
- case op_fstore_1:
- case op_fstore_2:
- case op_fstore_3:
- STOREF (opcode-op_fstore_0);
- goto next_insn;
-
- case op_dstore_0:
- case op_dstore_1:
- case op_dstore_2:
- case op_dstore_3:
- STORED (opcode-op_dstore_0);
- goto next_insn;
-
- case op_astore_0:
- case op_astore_1:
- case op_astore_2:
- case op_astore_3:
- STOREA (opcode-op_astore_0);
- goto next_insn;
-
- case op_iastore:
+ NEXT_INSN;
+
+ insn_istore:
+ STOREI (GET1U ());
+ NEXT_INSN;
+
+ insn_lstore:
+ STOREL (GET1U ());
+ NEXT_INSN;
+
+ insn_fstore:
+ STOREF (GET1U ());
+ NEXT_INSN;
+
+ insn_dstore:
+ STORED (GET1U ());
+ NEXT_INSN;
+
+ insn_astore:
+ STOREA (GET1U ());
+ NEXT_INSN;
+
+ insn_istore_0:
+ STOREI (0);
+ NEXT_INSN;
+
+ insn_istore_1:
+ STOREI (1);
+ NEXT_INSN;
+
+ insn_istore_2:
+ STOREI (2);
+ NEXT_INSN;
+
+ insn_istore_3:
+ STOREI (3);
+ NEXT_INSN;
+
+ insn_lstore_0:
+ STOREL (0);
+ NEXT_INSN;
+
+ insn_lstore_1:
+ STOREL (1);
+ NEXT_INSN;
+
+ insn_lstore_2:
+ STOREL (2);
+ NEXT_INSN;
+
+ insn_lstore_3:
+ STOREL (3);
+ NEXT_INSN;
+
+ insn_fstore_0:
+ STOREF (0);
+ NEXT_INSN;
+
+ insn_fstore_1:
+ STOREF (1);
+ NEXT_INSN;
+
+ insn_fstore_2:
+ STOREF (2);
+ NEXT_INSN;
+
+ insn_fstore_3:
+ STOREF (3);
+ NEXT_INSN;
+
+ insn_dstore_0:
+ STORED (0);
+ NEXT_INSN;
+
+ insn_dstore_1:
+ STORED (1);
+ NEXT_INSN;
+
+ insn_dstore_2:
+ STORED (2);
+ NEXT_INSN;
+
+ insn_dstore_3:
+ STORED (3);
+ NEXT_INSN;
+
+ insn_astore_0:
+ STOREA(0);
+ NEXT_INSN;
+
+ insn_astore_1:
+ STOREA(1);
+ NEXT_INSN;
+
+ insn_astore_2:
+ STOREA(2);
+ NEXT_INSN;
+
+ insn_astore_3:
+ STOREA(3);
+ NEXT_INSN;
+
+ insn_iastore:
{
jint value = POPI();
jint index = POPI();
jintArray arr = (jintArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_lastore:
+ insn_lastore:
{
jlong value = POPL();
jint index = POPI();
jlongArray arr = (jlongArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_fastore:
+ insn_fastore:
{
jfloat value = POPF();
jint index = POPI();
jfloatArray arr = (jfloatArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_dastore:
+ insn_dastore:
{
jdouble value = POPD();
jint index = POPI();
jdoubleArray arr = (jdoubleArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_aastore:
+ insn_aastore:
{
jobject value = POPA();
jint index = POPI();
jobjectArray arr = (jobjectArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
_Jv_CheckArrayStore (arr, value);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_bastore:
+ insn_bastore:
{
jbyte value = (jbyte) POPI();
jint index = POPI();
jbyteArray arr = (jbyteArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_castore:
+ insn_castore:
{
jchar value = (jchar) POPI();
jint index = POPI();
jcharArray arr = (jcharArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_sastore:
+ insn_sastore:
{
jshort value = (jshort) POPI();
jint index = POPI();
jshortArray arr = (jshortArray) POPA();
- NULLCHECK (arr);
- if (index < 0 || index >= arr->length)
- {
- TIME_SUSPEND;
- _Jv_ThrowBadArrayIndex (index);
- }
+ NULLARRAYCHECK (arr);
+ ARRAYBOUNDSCHECK (arr, index);
elements(arr)[index] = value;
}
- goto next_insn;
+ NEXT_INSN;
- case op_pop:
+ insn_pop:
sp -= 1;
- goto next_insn;
+ NEXT_INSN;
- case op_pop2:
+ insn_pop2:
sp -= 2;
- goto next_insn;
+ NEXT_INSN;
- case op_dup:
+ insn_dup:
sp[0] = sp[-1];
sp += 1;
- goto next_insn;
+ NEXT_INSN;
- case op_dup_x1:
- dupx (sp, 1, 1);
- goto next_insn;
+ insn_dup_x1:
+ dupx (sp, 1, 1); sp+=1;
+ NEXT_INSN;
- case op_dup_x2:
- dupx (sp, 1, 2);
- goto next_insn;
+ insn_dup_x2:
+ dupx (sp, 1, 2); sp+=1;
+ NEXT_INSN;
- case op_dup2:
+ insn_dup2:
sp[0] = sp[-2];
sp[1] = sp[-1];
sp += 2;
- goto next_insn;
+ NEXT_INSN;
- case op_dup2_x1:
- dupx (sp, 2, 1);
- goto next_insn;
+ insn_dup2_x1:
+ dupx (sp, 2, 1); sp+=2;
+ NEXT_INSN;
- case op_dup2_x2:
- dupx (sp, 2, 2);
- goto next_insn;
+ insn_dup2_x2:
+ dupx (sp, 2, 2); sp+=2;
+ NEXT_INSN;
- case op_swap:
+ insn_swap:
{
jobject tmp1 = POPA();
jobject tmp2 = POPA();
PUSHA (tmp1);
PUSHA (tmp2);
}
- goto next_insn;
+ NEXT_INSN;
- case op_iadd:
+ insn_iadd:
BINOPI(+);
- goto next_insn;
+ NEXT_INSN;
- case op_ladd:
+ insn_ladd:
BINOPL(+);
- goto next_insn;
+ NEXT_INSN;
- case op_fadd:
+ insn_fadd:
BINOPF(+);
- goto next_insn;
+ NEXT_INSN;
- case op_dadd:
+ insn_dadd:
BINOPD(+);
- goto next_insn;
+ NEXT_INSN;
- case op_isub:
+ insn_isub:
BINOPI(-);
- goto next_insn;
+ NEXT_INSN;
- case op_lsub:
+ insn_lsub:
BINOPL(-);
- goto next_insn;
+ NEXT_INSN;
- case op_fsub:
+ insn_fsub:
BINOPF(-);
- goto next_insn;
+ NEXT_INSN;
- case op_dsub:
+ insn_dsub:
BINOPD(-);
- goto next_insn;
+ NEXT_INSN;
- case op_imul:
+ insn_imul:
BINOPI(*);
- goto next_insn;
+ NEXT_INSN;
- case op_lmul:
+ insn_lmul:
BINOPL(*);
- goto next_insn;
+ NEXT_INSN;
- case op_fmul:
+ insn_fmul:
BINOPF(*);
- goto next_insn;
+ NEXT_INSN;
- case op_dmul:
+ insn_dmul:
BINOPD(*);
- goto next_insn;
+ NEXT_INSN;
- case op_idiv:
+ insn_idiv:
{
jint value2 = POPI();
jint value1 = POPI();
- ZEROCHECK (value2);
- jint res = value1 / value2;
+ jint res = _Jv_divI (value1, value2);
PUSHI (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_ldiv:
- {
+ insn_ldiv:
+ {
jlong value2 = POPL();
jlong value1 = POPL();
- ZEROCHECK (value2);
- jlong res = value1 / value2;
+ jlong res = _Jv_divJ (value1, value2);
PUSHL (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_fdiv:
+ insn_fdiv:
{
jfloat value2 = POPF();
jfloat value1 = POPF();
- ZEROCHECK (value2);
jfloat res = value1 / value2;
PUSHF (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_ddiv:
+ insn_ddiv:
{
jdouble value2 = POPD();
jdouble value1 = POPD();
- ZEROCHECK (value2);
jdouble res = value1 / value2;
PUSHD (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_irem:
+ insn_irem:
{
jint value2 = POPI();
- jint value1 = POPI();
- ZEROCHECK (value2);
- jint res = value1 % value2;
+ jint value1 = POPI();
+ jint res = _Jv_remI (value1, value2);
PUSHI (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_lrem:
- {
+ insn_lrem:
+ {
jlong value2 = POPL();
jlong value1 = POPL();
- ZEROCHECK (value2);
- jlong res = value1 % value2;
+ jlong res = _Jv_remJ (value1, value2);
PUSHL (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_frem:
+ insn_frem:
{
jfloat value2 = POPF();
jfloat value1 = POPF();
- ZEROCHECK (value2);
jfloat res = __ieee754_fmod (value1, value2);
PUSHF (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_drem:
+ insn_drem:
{
jdouble value2 = POPD();
jdouble value1 = POPD();
- ZEROCHECK (value2);
jdouble res = __ieee754_fmod (value1, value2);
PUSHD (res);
}
- goto next_insn;
+ NEXT_INSN;
- case op_ineg:
- *(jint*) (sp-1) *= -1;
- goto next_insn;
+ insn_ineg:
+ {
+ jint value = POPI();
+ PUSHI (value * -1);
+ }
+ NEXT_INSN;
- case op_lneg:
- *(jlong*) (sp-1) *= -1;
- goto next_insn;
+ insn_lneg:
+ {
+ jlong value = POPL();
+ PUSHL (value * -1);
+ }
+ NEXT_INSN;
- case op_fneg:
- *(jfloat*) (sp-1) *= -1;
- goto next_insn;
+ insn_fneg:
+ {
+ jfloat value = POPF();
+ PUSHF (value * -1);
+ }
+ NEXT_INSN;
- case op_dneg:
- *(jdouble*) (sp-1) *= -1;
- goto next_insn;
+ insn_dneg:
+ {
+ jdouble value = POPD();
+ PUSHD (value * -1);
+ }
+ NEXT_INSN;
- case op_ishl:
+ insn_ishl:
{
jint shift = (POPI() & 0x1f);
jint value = POPI();
PUSHI (value << shift);
}
- goto next_insn;
+ NEXT_INSN;
- case op_lshl:
+ insn_lshl:
{
jint shift = (POPI() & 0x3f);
jlong value = POPL();
PUSHL (value << shift);
}
- goto next_insn;
+ NEXT_INSN;
- case op_ishr:
+ insn_ishr:
{
jint shift = (POPI() & 0x1f);
jint value = POPI();
PUSHI (value >> shift);
}
- goto next_insn;
+ NEXT_INSN;
- case op_lshr:
+ insn_lshr:
{
jint shift = (POPI() & 0x3f);
jlong value = POPL();
PUSHL (value >> shift);
}
- goto next_insn;
+ NEXT_INSN;
- case op_iushr:
+ insn_iushr:
{
jint shift = (POPI() & 0x1f);
- unsigned long value = POPI();
+ _Jv_uint value = (_Jv_uint) POPI();
PUSHI ((jint) (value >> shift));
}
- goto next_insn;
+ NEXT_INSN;
- case op_lushr:
+ insn_lushr:
{
jint shift = (POPI() & 0x3f);
- UINT64 value = (UINT64) POPL();
- PUSHL ((value >> shift));
+ _Jv_ulong value = (_Jv_ulong) POPL();
+ PUSHL ((jlong) (value >> shift));
}
- goto next_insn;
+ NEXT_INSN;
- case op_iand:
+ insn_iand:
BINOPI (&);
- goto next_insn;
+ NEXT_INSN;
- case op_land:
+ insn_land:
BINOPL (&);
- goto next_insn;
+ NEXT_INSN;
- case op_ior:
+ insn_ior:
BINOPI (|);
- goto next_insn;
+ NEXT_INSN;
- case op_lor:
+ insn_lor:
BINOPL (|);
- goto next_insn;
+ NEXT_INSN;
- case op_ixor:
+ insn_ixor:
BINOPI (^);
- goto next_insn;
+ NEXT_INSN;
- case op_lxor:
+ insn_lxor:
BINOPL (^);
- goto next_insn;
+ NEXT_INSN;
- case op_iinc:
+ insn_iinc:
{
- jint index = get1u (pc++);
- jint amount = get1s (pc++);
- *(jint*) (locals + index) += amount;
+ jint index = GET1U ();
+ jint amount = GET1S ();
+ locals[index].i += amount;
}
- goto next_insn;
+ NEXT_INSN;
- case op_i2l:
- PUSHL ((jlong)POPI ());
- goto next_insn;
+ insn_i2l:
+ {jlong value = POPI(); PUSHL (value);}
+ NEXT_INSN;
- case op_i2f:
- PUSHF ((jfloat)POPI ());
- goto next_insn;
+ insn_i2f:
+ {jfloat value = POPI(); PUSHF (value);}
+ NEXT_INSN;
- case op_i2d:
- PUSHD ((jdouble)POPI ());
- goto next_insn;
+ insn_i2d:
+ {jdouble value = POPI(); PUSHD (value);}
+ NEXT_INSN;
- case op_l2i:
- PUSHI ((jint)POPL ());
- goto next_insn;
+ insn_l2i:
+ {jint value = POPL(); PUSHI (value);}
+ NEXT_INSN;
- case op_l2f:
- PUSHF ((jfloat)POPL ());
- goto next_insn;
+ insn_l2f:
+ {jfloat value = POPL(); PUSHF (value);}
+ NEXT_INSN;
- case op_l2d:
- PUSHD ((jdouble)POPL ());
- goto next_insn;
+ insn_l2d:
+ {jdouble value = POPL(); PUSHD (value);}
+ NEXT_INSN;
- case op_f2i:
- PUSHI ((jint)POPF ());
- goto next_insn;
+ insn_f2i:
+ {
+ using namespace java::lang;
+ jint value = convert (POPF (), Integer::MIN_VALUE, Integer::MAX_VALUE);
+ PUSHI(value);
+ }
+ NEXT_INSN;
- case op_f2l:
- PUSHL ((jlong)POPF ());
- goto next_insn;
+ insn_f2l:
+ {
+ using namespace java::lang;
+ jlong value = convert (POPF (), Long::MIN_VALUE, Long::MAX_VALUE);
+ PUSHL(value);
+ }
+ NEXT_INSN;
- case op_f2d:
- PUSHD ((jdouble)POPF ());
- goto next_insn;
+ insn_f2d:
+ { jdouble value = POPF (); PUSHD(value); }
+ NEXT_INSN;
- case op_d2i:
- PUSHI ((jint)POPD ());
- goto next_insn;
+ insn_d2i:
+ {
+ using namespace java::lang;
+ jint value = convert (POPD (), Integer::MIN_VALUE, Integer::MAX_VALUE);
+ PUSHI(value);
+ }
+ NEXT_INSN;
- case op_d2l:
- PUSHL ((jlong)POPD ());
- goto next_insn;
+ insn_d2l:
+ {
+ using namespace java::lang;
+ jlong value = convert (POPD (), Long::MIN_VALUE, Long::MAX_VALUE);
+ PUSHL(value);
+ }
+ NEXT_INSN;
- case op_d2f:
- PUSHF ((jfloat)POPD ());
- goto next_insn;
+ insn_d2f:
+ { jfloat value = POPD (); PUSHF(value); }
+ NEXT_INSN;
- case op_i2b:
- PUSHI ((jbyte)POPI ());
- goto next_insn;
+ insn_i2b:
+ { jbyte value = POPI (); PUSHI(value); }
+ NEXT_INSN;
- case op_i2c:
- PUSHI ((jchar)POPI ());
- goto next_insn;
+ insn_i2c:
+ { jchar value = POPI (); PUSHI(value); }
+ NEXT_INSN;
- case op_i2s:
- PUSHI ((jshort)POPI ());
- goto next_insn;
+ insn_i2s:
+ { jshort value = POPI (); PUSHI(value); }
+ NEXT_INSN;
- case op_lcmp:
+ insn_lcmp:
{
jlong value2 = POPL ();
jlong value1 = POPL ();
else
{ PUSHI (-1); }
}
- goto next_insn;
+ NEXT_INSN;
+
+ insn_fcmpl:
+ tmpval = -1;
+ goto fcmp;
- case op_fcmpl:
- case op_fcmpg:
+ insn_fcmpg:
+ tmpval = 1;
+
+ fcmp:
{
jfloat value2 = POPF ();
jfloat value1 = POPF ();
PUSHI (0);
else if (value1 < value2)
PUSHI (-1);
- else if (opcode == op_fcmpg)
- PUSHI (1);
else
- PUSHI (-1);
+ PUSHI (tmpval);
}
- goto next_insn;
+ NEXT_INSN;
+
+ insn_dcmpl:
+ tmpval = 1;
+ goto dcmp;
+
+ insn_dcmpg:
+ tmpval = -1;
- case op_dcmpl:
- case op_dcmpg:
+ dcmp:
{
jdouble value2 = POPD ();
jdouble value1 = POPD ();
PUSHI (0);
else if (value1 < value2)
PUSHI (-1);
- else if (opcode == op_dcmpg)
- PUSHI (1);
else
- PUSHI (-1);
+ PUSHI (tmpval);
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifeq:
+ insn_ifeq:
{
- jint offset = get2s (pc);
if (POPI() == 0)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifne:
+ insn_ifne:
{
- jint offset = get2s (pc);
if (POPI() != 0)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_iflt:
+ insn_iflt:
{
- jint offset = get2s (pc);
if (POPI() < 0)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifge:
+ insn_ifge:
{
- jint offset = get2s (pc);
if (POPI() >= 0)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifgt:
+ insn_ifgt:
{
- jint offset = get2s (pc);
if (POPI() > 0)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifle:
+ insn_ifle:
{
- jint offset = get2s (pc);
if (POPI() <= 0)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_icmpeq:
+ insn_if_icmpeq:
{
- jint offset = get2s (pc);
jint value2 = POPI();
jint value1 = POPI();
if (value1 == value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_icmpne:
+ insn_if_icmpne:
{
- jint offset = get2s (pc);
jint value2 = POPI();
jint value1 = POPI();
if (value1 != value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_icmplt:
+ insn_if_icmplt:
{
- jint offset = get2s (pc);
jint value2 = POPI();
jint value1 = POPI();
if (value1 < value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_icmpge:
+ insn_if_icmpge:
{
- jint offset = get2s (pc);
jint value2 = POPI();
jint value1 = POPI();
if (value1 >= value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_icmpgt:
+ insn_if_icmpgt:
{
- jint offset = get2s (pc);
jint value2 = POPI();
jint value1 = POPI();
if (value1 > value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_icmple:
+ insn_if_icmple:
{
- jint offset = get2s (pc);
jint value2 = POPI();
jint value1 = POPI();
if (value1 <= value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_acmpeq:
+ insn_if_acmpeq:
{
- jint offset = get2s (pc);
jobject value2 = POPA();
jobject value1 = POPA();
if (value1 == value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_if_acmpne:
+ insn_if_acmpne:
{
- jint offset = get2s (pc);
jobject value2 = POPA();
jobject value1 = POPA();
if (value1 != value2)
- pc = pc-1+offset;
+ TAKE_GOTO;
else
- pc = pc+2;
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
+
+ insn_goto_w:
+#ifndef DIRECT_THREADED
+ // For direct threaded, goto and goto_w are the same.
+ pc = pc - 1 + get4 (pc);
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+ insn_goto:
+ TAKE_GOTO;
+ NEXT_INSN;
- case op_goto:
+ insn_jsr_w:
+#ifndef DIRECT_THREADED
+ // For direct threaded, jsr and jsr_w are the same.
{
- jint offset = get2s (pc);
- pc = pc-1+offset;
+ pc_t next = pc - 1 + get4 (pc);
+ pc += 4;
+ PUSHA ((jobject) pc);
+ pc = next;
}
- goto next_insn;
-
- case op_jsr:
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+ insn_jsr:
{
- unsigned char *base_pc = pc-1;
- jint offset = get2s (pc); pc += 2;
- PUSHA ((jobject)pc);
- pc = base_pc+offset;
+ pc_t next = GOTO_VAL();
+ SKIP_GOTO;
+ PUSHA ((jobject) pc);
+ pc = next;
}
- goto next_insn;
+ NEXT_INSN;
- case op_ret:
+ insn_ret:
{
- jint index = get1u (pc);
- pc = (unsigned char*) PEEKA (index);
+ jint index = GET1U ();
+ pc = (pc_t) PEEKA (index);
}
- goto next_insn;
+ NEXT_INSN;
- case op_tableswitch:
+ insn_tableswitch:
{
- unsigned char *base_pc = pc-1;
+#ifdef DIRECT_THREADED
+ void *def = (pc++)->datum;
+
int index = POPI();
-
- unsigned char* base = bytecode ();
- while ((pc-base) % 4 != 0)
- pc++;
- jint def = get4 (pc);
- jint low = get4 (pc+4);
- jint high = get4 (pc+8);
+ jint low = INTVAL ();
+ jint high = INTVAL ();
if (index < low || index > high)
- pc = base_pc + def;
+ pc = (insn_slot *) def;
+ else
+ pc = (insn_slot *) ((pc + index - low)->datum);
+#else
+ pc_t base_pc = pc - 1;
+ int index = POPI ();
+
+ pc_t base = (pc_t) bytecode ();
+ while ((pc - base) % 4 != 0)
+ ++pc;
+
+ jint def = get4 (pc);
+ jint low = get4 (pc + 4);
+ jint high = get4 (pc + 8);
+ if (index < low || index > high)
+ pc = base_pc + def;
else
- pc = base_pc + get4 (pc+4*(index-low+3));
+ pc = base_pc + get4 (pc + 4 * (index - low + 3));
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ NEXT_INSN;
- case op_lookupswitch:
+ insn_lookupswitch:
{
+#ifdef DIRECT_THREADED
+ void *def = (pc++)->insn;
+
+ int index = POPI();
+
+ jint npairs = INTVAL ();
+
+ int max = npairs - 1;
+ int min = 0;
+
+ // Simple binary search...
+ while (min < max)
+ {
+ int half = (min + max) / 2;
+ int match = pc[2 * half].int_val;
+
+ if (index == match)
+ {
+ // Found it.
+ pc = (insn_slot *) pc[2 * half + 1].datum;
+ NEXT_INSN;
+ }
+ else if (index < match)
+ // We can use HALF - 1 here because we check again on
+ // loop exit.
+ max = half - 1;
+ else
+ // We can use HALF + 1 here because we check again on
+ // loop exit.
+ min = half + 1;
+ }
+ if (index == pc[2 * min].int_val)
+ pc = (insn_slot *) pc[2 * min + 1].datum;
+ else
+ pc = (insn_slot *) def;
+#else
unsigned char *base_pc = pc-1;
int index = POPI();
-
+
unsigned char* base = bytecode ();
while ((pc-base) % 4 != 0)
- pc++;
-
+ ++pc;
+
jint def = get4 (pc);
jint npairs = get4 (pc+4);
-
+
int max = npairs-1;
int min = 0;
- // simple binary search...
+ // Simple binary search...
while (min < max)
{
int half = (min+max)/2;
if (index == match)
min = max = half;
-
else if (index < match)
- max = half-1;
-
+ // We can use HALF - 1 here because we check again on
+ // loop exit.
+ max = half - 1;
else
- min = half+1;
+ // We can use HALF + 1 here because we check again on
+ // loop exit.
+ min = half + 1;
}
-
+
if (index == get4 (pc+ 4*(2 + 2*min)))
pc = base_pc + get4 (pc+ 4*(2 + 2*min + 1));
else
pc = base_pc + def;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
-
- /* on return, just save the sp and return to caller */
- case op_ireturn:
- case op_lreturn:
- case op_freturn:
- case op_dreturn:
- case op_areturn:
- case op_return:
- inv->sp = sp;
- TIME_SUSPEND;
+ NEXT_INSN;
+
+ insn_areturn:
+ *(jobject *) retp = POPA ();
+ return;
+
+ insn_lreturn:
+ *(jlong *) retp = POPL ();
+ return;
+
+ insn_freturn:
+ *(jfloat *) retp = POPF ();
+ return;
+
+ insn_dreturn:
+ *(jdouble *) retp = POPD ();
+ return;
+
+ insn_ireturn:
+ *(jint *) retp = POPI ();
return;
- case op_getstatic:
+ insn_return:
+ return;
+
+ insn_getstatic:
{
- unsigned char *base_pc = pc-1;
- jint fieldref_index = get2u (pc); pc += 2;
+ jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
- if ((field->flags & STATIC) == 0)
+ if ((field->flags & Modifier::STATIC) == 0)
throw_incompatible_class_change_error
(JvNewStringLatin1 ("field no longer static"));
jclass type = field->type;
+ // We rewrite the instruction once we discover what it refers
+ // to.
+ void *newinsn = NULL;
if (type->isPrimitive ())
{
switch (type->size_in_bytes)
{
case 1:
- *base_pc = op_getstatic_1;
+ PUSHI (*(jbyte*) (field->u.addr));
+ newinsn = AMPAMP (getstatic_resolved_1);
break;
-
+
case 2:
if (type == JvPrimClass (char))
- *base_pc = op_getstatic_2u;
+ {
+ PUSHI(*(jchar*) (field->u.addr));
+ newinsn = AMPAMP (getstatic_resolved_char);
+ }
else
- *base_pc = op_getstatic_2s;
+ {
+ PUSHI(*(jshort*) (field->u.addr));
+ newinsn = AMPAMP (getstatic_resolved_short);
+ }
break;
case 4:
- *base_pc = op_getstatic_4;
+ PUSHI(*(jint*) (field->u.addr));
+ newinsn = AMPAMP (getstatic_resolved_4);
break;
case 8:
- *base_pc = op_getstatic_8;
+ PUSHL(*(jlong*) (field->u.addr));
+ newinsn = AMPAMP (getstatic_resolved_8);
break;
}
}
else
{
- *base_pc = op_getstatic_a;
+ PUSHA(*(jobject*) (field->u.addr));
+ newinsn = AMPAMP (getstatic_resolved_obj);
}
-
- pc = base_pc;
+
+#ifdef DIRECT_THREADED
+ pc[-2].insn = newinsn;
+ pc[-1].datum = field->u.addr;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ NEXT_INSN;
+
+#ifdef DIRECT_THREADED
+ getstatic_resolved_1:
+ PUSHI (*(jbyte *) AVAL ());
+ NEXT_INSN;
+
+ getstatic_resolved_char:
+ PUSHI (*(jchar *) AVAL ());
+ NEXT_INSN;
+
+ getstatic_resolved_short:
+ PUSHI (*(jshort *) AVAL ());
+ NEXT_INSN;
+
+ getstatic_resolved_4:
+ PUSHI (*(jint *) AVAL ());
+ NEXT_INSN;
- case op_getfield:
+ getstatic_resolved_8:
+ PUSHL (*(jlong *) AVAL ());
+ NEXT_INSN;
+
+ getstatic_resolved_obj:
+ PUSHA (*(jobject *) AVAL ());
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
+ insn_getfield:
{
- unsigned char *base_pc = pc-1;
- jint fieldref_index = get2u (pc); pc += 2;
+ jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
- if ((field->flags & STATIC) != 0)
+ if ((field->flags & Modifier::STATIC) != 0)
throw_incompatible_class_change_error
(JvNewStringLatin1 ("field is static"));
jclass type = field->type;
+ jint field_offset = field->u.boffset;
+ if (field_offset > 0xffff)
+ throw new java::lang::VirtualMachineError;
+ jobject obj = POPA();
+ NULLCHECK(obj);
+
+ void *newinsn = NULL;
if (type->isPrimitive ())
{
switch (type->size_in_bytes)
{
case 1:
- *base_pc = op_getfield_1;
+ PUSHI (*(jbyte*) ((char*)obj + field_offset));
+ newinsn = AMPAMP (getfield_resolved_1);
break;
-
+
case 2:
if (type == JvPrimClass (char))
- *base_pc = op_getfield_2u;
+ {
+ PUSHI (*(jchar*) ((char*)obj + field_offset));
+ newinsn = AMPAMP (getfield_resolved_char);
+ }
else
- *base_pc = op_getfield_2s;
+ {
+ PUSHI (*(jshort*) ((char*)obj + field_offset));
+ newinsn = AMPAMP (getfield_resolved_short);
+ }
break;
case 4:
- *base_pc = op_getfield_4;
+ PUSHI (*(jint*) ((char*)obj + field_offset));
+ newinsn = AMPAMP (getfield_resolved_4);
break;
case 8:
- *base_pc = op_getfield_8;
+ PUSHL(*(jlong*) ((char*)obj + field_offset));
+ newinsn = AMPAMP (getfield_resolved_8);
break;
}
}
else
{
- *base_pc = op_getfield_a;
+ PUSHA(*(jobject*) ((char*)obj + field_offset));
+ newinsn = AMPAMP (getfield_resolved_obj);
}
-
- if (field->u.boffset > 0xffff)
- JvThrow (new java::lang::VirtualMachineError);
- base_pc[1] = (field->u.boffset>>8) & 0xff;
- base_pc[2] = field->u.boffset & 0xff;
+#ifdef DIRECT_THREADED
+ pc[-2].insn = newinsn;
+ pc[-1].int_val = field_offset;
+#endif /* DIRECT_THREADED */
+ }
+ NEXT_INSN;
+
+#ifdef DIRECT_THREADED
+ getfield_resolved_1:
+ {
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ PUSHI (*(jbyte *) (obj + INTVAL ()));
+ }
+ NEXT_INSN;
+
+ getfield_resolved_char:
+ {
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ PUSHI (*(jchar *) (obj + INTVAL ()));
+ }
+ NEXT_INSN;
- pc = base_pc;
+ getfield_resolved_short:
+ {
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ PUSHI (*(jshort *) (obj + INTVAL ()));
}
- goto next_insn;
+ NEXT_INSN;
- case op_putstatic:
+ getfield_resolved_4:
{
- unsigned char* base_pc = pc-1;
- jint fieldref_index = get2u (pc); pc += 2;
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ PUSHI (*(jint *) (obj + INTVAL ()));
+ }
+ NEXT_INSN;
+
+ getfield_resolved_8:
+ {
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ PUSHL (*(jlong *) (obj + INTVAL ()));
+ }
+ NEXT_INSN;
+
+ getfield_resolved_obj:
+ {
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ PUSHA (*(jobject *) (obj + INTVAL ()));
+ }
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
+ insn_putstatic:
+ {
+ jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
jclass type = field->type;
// ResolvePoolEntry cannot check this
- if ((field->flags & STATIC) == 0)
+ if ((field->flags & Modifier::STATIC) == 0)
throw_incompatible_class_change_error
(JvNewStringLatin1 ("field no longer static"));
- /* if this is patented, then maybe we could install
- a function in the constant pool, to do the right thing */
-
+ void *newinsn = NULL;
if (type->isPrimitive ())
{
switch (type->size_in_bytes)
{
case 1:
- *base_pc = op_putstatic_1;
- break;
+ {
+ jint value = POPI();
+ *(jbyte*) (field->u.addr) = value;
+ newinsn = AMPAMP (putstatic_resolved_1);
+ break;
+ }
case 2:
- *base_pc = op_putstatic_2;
- break;
-
+ {
+ jint value = POPI();
+ *(jchar*) (field->u.addr) = value;
+ newinsn = AMPAMP (putstatic_resolved_2);
+ break;
+ }
+
case 4:
- *base_pc = op_putstatic_4;
- break;
-
+ {
+ jint value = POPI();
+ *(jint*) (field->u.addr) = value;
+ newinsn = AMPAMP (putstatic_resolved_4);
+ break;
+ }
+
case 8:
- *base_pc = op_putstatic_8;
- break;
+ {
+ jlong value = POPL();
+ *(jlong*) (field->u.addr) = value;
+ newinsn = AMPAMP (putstatic_resolved_8);
+ break;
+ }
}
}
else
{
- *base_pc = op_putstatic_a;
+ jobject value = POPA();
+ *(jobject*) (field->u.addr) = value;
+ newinsn = AMPAMP (putstatic_resolved_obj);
}
- // do the instruction again!
- pc = base_pc;
+#ifdef DIRECT_THREADED
+ pc[-2].insn = newinsn;
+ pc[-1].datum = field->u.addr;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ NEXT_INSN;
+
+#ifdef DIRECT_THREADED
+ putstatic_resolved_1:
+ *(jbyte *) AVAL () = POPI ();
+ NEXT_INSN;
+
+ putstatic_resolved_2:
+ *(jchar *) AVAL () = POPI ();
+ NEXT_INSN;
+ putstatic_resolved_4:
+ *(jint *) AVAL () = POPI ();
+ NEXT_INSN;
- case op_putfield:
+ putstatic_resolved_8:
+ *(jlong *) AVAL () = POPL ();
+ NEXT_INSN;
+
+ putstatic_resolved_obj:
+ *(jobject *) AVAL () = POPA ();
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
+ insn_putfield:
{
- unsigned char* base_pc = pc-1;
- jint fieldref_index = get2u (pc); pc += 2;
+ jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
jclass type = field->type;
- if ((field->flags & STATIC) != 0)
+ if ((field->flags & Modifier::STATIC) != 0)
throw_incompatible_class_change_error
(JvNewStringLatin1 ("field is static"));
+ jint field_offset = field->u.boffset;
+ if (field_offset > 0xffff)
+ throw new java::lang::VirtualMachineError;
+
+ void *newinsn = NULL;
if (type->isPrimitive ())
{
switch (type->size_in_bytes)
{
case 1:
- *base_pc = op_putfield_1;
- break;
+ {
+ jint value = POPI();
+ jobject obj = POPA();
+ NULLCHECK(obj);
+ *(jbyte*) ((char*)obj + field_offset) = value;
+ newinsn = AMPAMP (putfield_resolved_1);
+ break;
+ }
case 2:
- *base_pc = op_putfield_2;
- break;
+ {
+ jint value = POPI();
+ jobject obj = POPA();
+ NULLCHECK(obj);
+ *(jchar*) ((char*)obj + field_offset) = value;
+ newinsn = AMPAMP (putfield_resolved_2);
+ break;
+ }
case 4:
- *base_pc = op_putfield_4;
- break;
+ {
+ jint value = POPI();
+ jobject obj = POPA();
+ NULLCHECK(obj);
+ *(jint*) ((char*)obj + field_offset) = value;
+ newinsn = AMPAMP (putfield_resolved_4);
+ break;
+ }
case 8:
- *base_pc = op_putfield_8;
- break;
+ {
+ jlong value = POPL();
+ jobject obj = POPA();
+ NULLCHECK(obj);
+ *(jlong*) ((char*)obj + field_offset) = value;
+ newinsn = AMPAMP (putfield_resolved_8);
+ break;
+ }
}
}
else
{
- *base_pc = op_putfield_a;
+ jobject value = POPA();
+ jobject obj = POPA();
+ NULLCHECK(obj);
+ *(jobject*) ((char*)obj + field_offset) = value;
+ newinsn = AMPAMP (putfield_resolved_obj);
}
- if (field->u.boffset > 0xffff)
- JvThrow (new java::lang::VirtualMachineError);
-
- base_pc[1] = (field->u.boffset>>8) & 0xff;
- base_pc[2] = field->u.boffset & 0xff;
-
- // do the instruction again!
- pc = base_pc;
+#ifdef DIRECT_THREADED
+ pc[-2].insn = newinsn;
+ pc[-1].int_val = field_offset;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
-
+ NEXT_INSN;
- case op_getfield_1:
+#ifdef DIRECT_THREADED
+ putfield_resolved_1:
{
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- PUSHI (*(jbyte*) ((char*)obj + field_offset));
+ jint val = POPI ();
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ *(jbyte *) (obj + INTVAL ()) = val;
}
- goto next_insn;
+ NEXT_INSN;
- case op_getfield_2s:
+ putfield_resolved_2:
{
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- PUSHI (*(jshort*) ((char*)obj + field_offset));
+ jint val = POPI ();
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ *(jchar *) (obj + INTVAL ()) = val;
}
- goto next_insn;
+ NEXT_INSN;
- case op_getfield_2u:
+ putfield_resolved_4:
{
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- PUSHI (*(jchar*) ((char*)obj + field_offset));
+ jint val = POPI ();
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ *(jint *) (obj + INTVAL ()) = val;
}
- goto next_insn;
+ NEXT_INSN;
- case op_getfield_8:
+ putfield_resolved_8:
{
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- PUSHL(*(jlong*) ((char*)obj + field_offset));
+ jlong val = POPL ();
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ *(jlong *) (obj + INTVAL ()) = val;
}
- goto next_insn;
+ NEXT_INSN;
- case op_getstatic_1:
+ putfield_resolved_obj:
{
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- PUSHI (*(jbyte*) (field->u.addr));
+ jobject val = POPA ();
+ char *obj = (char *) POPA ();
+ NULLCHECK (obj);
+ *(jobject *) (obj + INTVAL ()) = val;
}
- goto next_insn;
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
- case op_getstatic_2s:
+ insn_invokespecial:
{
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- PUSHI(*(jshort*) (field->u.addr));
- }
- goto next_insn;
+ int index = GET2U ();
- case op_getstatic_2u:
- {
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- PUSHI(*(jchar*) (field->u.addr));
- }
- goto next_insn;
-
- case op_getstatic_4:
- {
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- PUSHI(*(jint*) (field->u.addr));
- }
- goto next_insn;
-
- case op_getstatic_8:
- {
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- PUSHL(*(jlong*) (field->u.addr));
- }
- goto next_insn;
+ rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
- case op_getstatic_a:
- {
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- PUSHA(*(jobject*) (field->u.addr));
- }
- goto next_insn;
+ sp -= rmeth->stack_item_count;
- case op_putfield_1:
- {
- jint value = POPI();
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- *(jbyte*) ((char*)obj + field_offset) = value;
- }
- goto next_insn;
+ // We don't use NULLCHECK here because we can't rely on that
+ // working for <init>. So instead we do an explicit test.
+ if (! sp[0].o)
+ throw new java::lang::NullPointerException;
- case op_putfield_2:
- {
- jint value = POPI();
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- *(jchar*) ((char*)obj + field_offset) = value;
- }
- goto next_insn;
+ fun = (void (*)()) rmeth->method->ncode;
- case op_putfield_4:
- {
- jint value = POPI();
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- *(jint*) ((char*)obj + field_offset) = value;
+#ifdef DIRECT_THREADED
+ // Rewrite instruction so that we use a faster pre-resolved
+ // method.
+ pc[-2].insn = &&invokespecial_resolved;
+ pc[-1].datum = rmeth;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ goto perform_invoke;
- case op_putfield_8:
+#ifdef DIRECT_THREADED
+ invokespecial_resolved:
{
- jlong value = POPL();
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- *(jlong*) ((char*)obj + field_offset) = value;
+ rmeth = (_Jv_ResolvedMethod *) AVAL ();
+ sp -= rmeth->stack_item_count;
+ // We don't use NULLCHECK here because we can't rely on that
+ // working for <init>. So instead we do an explicit test.
+ if (! sp[0].o)
+ throw new java::lang::NullPointerException;
+ fun = (void (*)()) rmeth->method->ncode;
}
- goto next_insn;
+ goto perform_invoke;
+#endif /* DIRECT_THREADED */
- case op_putfield_a:
+ insn_invokestatic:
{
- jobject value = POPA();
- jobject obj = POPA();
- NULLCHECK(obj);
- jint field_offset = get2u (pc); pc += 2;
- *(jobject*) ((char*)obj + field_offset) = value;
- }
- goto next_insn;
+ int index = GET2U ();
- case op_putstatic_1:
- {
- jint value = POPI();
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- *(jbyte*) (field->u.addr) = value;
- }
- goto next_insn;
+ rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
- case op_putstatic_2:
- {
- jint value = POPI();
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- *(jchar*) (field->u.addr) = value;
- }
- goto next_insn;
+ sp -= rmeth->stack_item_count;
- case op_putstatic_4:
- {
- jint value = POPI();
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- *(jint*) (field->u.addr) = value;
- }
- goto next_insn;
+ fun = (void (*)()) rmeth->method->ncode;
- case op_putstatic_8:
- {
- jlong value = POPL();
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- *(jlong*) (field->u.addr) = value;
+#ifdef DIRECT_THREADED
+ // Rewrite instruction so that we use a faster pre-resolved
+ // method.
+ pc[-2].insn = &&invokestatic_resolved;
+ pc[-1].datum = rmeth;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ goto perform_invoke;
- case op_putstatic_a:
+#ifdef DIRECT_THREADED
+ invokestatic_resolved:
{
- jobject value = POPA();
- jint fieldref_index = get2u (pc); pc += 2;
- _Jv_Field *field = pool_data[fieldref_index].field;
- *(jobject*) (field->u.addr) = value;
+ rmeth = (_Jv_ResolvedMethod *) AVAL ();
+ sp -= rmeth->stack_item_count;
+ fun = (void (*)()) rmeth->method->ncode;
}
- goto next_insn;
+ goto perform_invoke;
+#endif /* DIRECT_THREADED */
- case op_invokespecial:
+ insn_invokeinterface:
{
- int index = get2u (pc); pc += 2;
+ int index = GET2U ();
rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
sp -= rmeth->stack_item_count;
-
- NULLCHECK(sp[0]);
- fun = (void (*) (...))rmeth->method->ncode;
- }
- goto perform_invoke;
+ jobject rcv = sp[0].o;
- case op_invokestatic:
- {
- int index = get2u (pc); pc += 2;
+ NULLCHECK (rcv);
- rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
+ fun = (void (*)())
+ _Jv_LookupInterfaceMethod (rcv->getClass (),
+ rmeth->method->name,
+ rmeth->method->signature);
- sp -= rmeth->stack_item_count;
-
- _Jv_InitClass (rmeth->klass);
- fun = (void (*) (...))rmeth->method->ncode;
+#ifdef DIRECT_THREADED
+ // Rewrite instruction so that we use a faster pre-resolved
+ // method.
+ pc[-2].insn = &&invokeinterface_resolved;
+ pc[-1].datum = rmeth;
+#else
+ // Skip dummy bytes.
+ pc += 2;
+#endif /* DIRECT_THREADED */
}
goto perform_invoke;
- case op_invokeinterface:
+#ifdef DIRECT_THREADED
+ invokeinterface_resolved:
{
- int index = get2u (pc); pc += 2;
-
- // invokeinterface has two unused bytes...
- pc += 2;
-
- rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
-
+ rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
- NULLCHECK(sp[0]);
-
jobject rcv = sp[0].o;
-
- fun = (void (*) (...))
+ NULLCHECK (rcv);
+ fun = (void (*)())
_Jv_LookupInterfaceMethod (rcv->getClass (),
rmeth->method->name,
rmeth->method->signature);
}
goto perform_invoke;
+#endif /* DIRECT_THREADED */
-
- case op_new:
+ insn_new:
{
- int index = get2u (pc); pc += 2;
+ int index = GET2U ();
jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
+ // We initialize here because otherwise `size_in_bytes' may
+ // not be set correctly, leading us to pass `0' as the size.
+ // FIXME: fix in the allocator? There is a PR for this.
_Jv_InitClass (klass);
jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
PUSHA (res);
+
+#ifdef DIRECT_THREADED
+ pc[-2].insn = &&new_resolved;
+ pc[-1].datum = klass;
+#endif /* DIRECT_THREADED */
+ }
+ NEXT_INSN;
+
+#ifdef DIRECT_THREADED
+ new_resolved:
+ {
+ jclass klass = (jclass) AVAL ();
+ jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
+ PUSHA (res);
}
- goto next_insn;
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
- case op_newarray:
+ insn_newarray:
{
- int atype = get1u (pc++);
+ int atype = GET1U ();
int size = POPI();
jobject result = _Jv_NewArray (atype, size);
PUSHA (result);
}
- goto next_insn;
-
- case op_anewarray:
+ NEXT_INSN;
+
+ insn_anewarray:
{
- int index = get2u (pc); pc += 2;
+ int index = GET2U ();
jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
int size = POPI();
- _Jv_InitClass (klass);
jobject result = _Jv_NewObjectArray (size, klass, 0);
PUSHA (result);
+
+#ifdef DIRECT_THREADED
+ pc[-2].insn = &&anewarray_resolved;
+ pc[-1].datum = klass;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ NEXT_INSN;
- case op_arraylength:
+#ifdef DIRECT_THREADED
+ anewarray_resolved:
+ {
+ jclass klass = (jclass) AVAL ();
+ int size = POPI ();
+ jobject result = _Jv_NewObjectArray (size, klass, 0);
+ PUSHA (result);
+ }
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
+ insn_arraylength:
{
__JArray *arr = (__JArray*)POPA();
+ NULLARRAYCHECK (arr);
PUSHI (arr->length);
}
- goto next_insn;
+ NEXT_INSN;
- case op_athrow:
+ insn_athrow:
{
jobject value = POPA();
- TIME_SUSPEND;
- JvThrow (value);
+ throw static_cast<jthrowable>(value);
}
- goto next_insn;
+ NEXT_INSN;
- case op_checkcast:
+ insn_checkcast:
{
jobject value = POPA();
- jint index = get2u (pc); pc += 2;
+ jint index = GET2U ();
jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
if (value != NULL && ! to->isInstance (value))
- {
- TIME_SUSPEND;
- JvThrow (new java::lang::ClassCastException
- (to->getName()));
- }
+ throw new java::lang::ClassCastException (to->getName());
PUSHA (value);
+
+#ifdef DIRECT_THREADED
+ pc[-2].insn = &&checkcast_resolved;
+ pc[-1].datum = to;
+#endif /* DIRECT_THREADED */
}
- goto next_insn;
+ NEXT_INSN;
- case op_instanceof:
+#ifdef DIRECT_THREADED
+ checkcast_resolved:
+ {
+ jobject value = POPA ();
+ jclass to = (jclass) AVAL ();
+ if (value != NULL && ! to->isInstance (value))
+ throw new java::lang::ClassCastException (to->getName());
+ PUSHA (value);
+ }
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
+ insn_instanceof:
{
jobject value = POPA();
- jint index = get2u (pc); pc += 2;
+ jint index = GET2U ();
jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
PUSHI (to->isInstance (value));
+
+#ifdef DIRECT_THREADED
+ pc[-2].insn = &&instanceof_resolved;
+ pc[-1].datum = to;
+#endif /* DIRECT_THREADED */
+ }
+ NEXT_INSN;
+
+#ifdef DIRECT_THREADED
+ instanceof_resolved:
+ {
+ jobject value = POPA ();
+ jclass to = (jclass) AVAL ();
+ PUSHI (to->isInstance (value));
}
- goto next_insn;
+ NEXT_INSN;
+#endif /* DIRECT_THREADED */
- case op_monitorenter:
+ insn_monitorenter:
{
jobject value = POPA();
NULLCHECK(value);
_Jv_MonitorEnter (value);
}
- goto next_insn;
+ NEXT_INSN;
- case op_monitorexit:
+ insn_monitorexit:
{
jobject value = POPA();
NULLCHECK(value);
_Jv_MonitorExit (value);
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifnull:
+ insn_ifnull:
{
- unsigned char* base_pc = pc-1;
- jint offset = get2s (pc); pc += 2;
jobject val = POPA();
if (val == NULL)
- pc = base_pc+offset;
+ TAKE_GOTO;
+ else
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_ifnonnull:
+ insn_ifnonnull:
{
- unsigned char* base_pc = pc-1;
- jint offset = get2s (pc); pc += 2;
jobject val = POPA();
if (val != NULL)
- pc = base_pc+offset;
+ TAKE_GOTO;
+ else
+ SKIP_GOTO;
}
- goto next_insn;
+ NEXT_INSN;
- case op_wide:
+ insn_multianewarray:
+ {
+ int kind_index = GET2U ();
+ int dim = GET1U ();
+
+ jclass type
+ = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
+ jint *sizes = (jint*) __builtin_alloca (sizeof (jint)*dim);
+
+ for (int i = dim - 1; i >= 0; i--)
+ {
+ sizes[i] = POPI ();
+ }
+
+ jobject res = _Jv_NewMultiArray (type,dim, sizes);
+
+ PUSHA (res);
+ }
+ NEXT_INSN;
+
+#ifndef DIRECT_THREADED
+ insn_wide:
{
jint the_mod_op = get1u (pc++);
jint wide = get2u (pc); pc += 2;
{
case op_istore:
STOREI (wide);
- goto next_insn;
+ NEXT_INSN;
case op_fstore:
STOREF (wide);
- goto next_insn;
+ NEXT_INSN;
case op_astore:
STOREA (wide);
- goto next_insn;
+ NEXT_INSN;
case op_lload:
LOADL (wide);
- goto next_insn;
+ NEXT_INSN;
case op_dload:
LOADD (wide);
- goto next_insn;
+ NEXT_INSN;
case op_iload:
LOADI (wide);
- goto next_insn;
+ NEXT_INSN;
case op_aload:
LOADA (wide);
- goto next_insn;
+ NEXT_INSN;
case op_lstore:
STOREL (wide);
- goto next_insn;
+ NEXT_INSN;
case op_dstore:
STORED (wide);
- goto next_insn;
+ NEXT_INSN;
case op_ret:
pc = (unsigned char*) PEEKA (wide);
- goto next_insn;
+ NEXT_INSN;
case op_iinc:
{
jint value = PEEKI (wide);
POKEI (wide, value+amount);
}
- goto next_insn;
+ NEXT_INSN;
default:
throw_internal_error ("illegal bytecode modified by wide");
}
}
+#endif /* DIRECT_THREADED */
+ }
+ catch (java::lang::Throwable *ex)
+ {
+#ifdef DIRECT_THREADED
+ void *logical_pc = (void *) ((insn_slot *) pc - 1);
+#else
+ int logical_pc = pc - 1 - bytecode ();
+#endif
+ _Jv_InterpException *exc = exceptions ();
+ jclass exc_class = ex->getClass ();
- case op_multianewarray:
- {
- int kind_index = get2u (pc); pc += 2;
- int dim = get1u (pc); pc += 1;
-
- jclass type
- = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
- _Jv_InitClass (type);
- jint *sizes = (jint*) alloca (sizeof (jint)*dim);
-
- for (int i = dim - 1; i >= 0; i--)
- {
- sizes[i] = POPI ();
- }
-
- jobject res = _Jv_NewMultiArray (type,dim, sizes);
-
- PUSHA (res);
- }
- goto next_insn;
-
- case op_goto_w:
- {
- unsigned char* base_pc = pc-1;
- int offset = get4 (pc); pc += 4;
- pc = base_pc+offset;
- }
- goto next_insn;
-
- case op_jsr_w:
- {
- unsigned char* base_pc = pc-1;
- int offset = get4 (pc); pc += 4;
- PUSHA((jobject)pc);
- pc = base_pc+offset;
- }
- goto next_insn;
-
- default:
- throw_internal_error ("opcode not implemented");
+ for (int i = 0; i < exc_count; i++)
+ {
+ if (PCVAL (exc[i].start_pc) <= logical_pc
+ && logical_pc < PCVAL (exc[i].end_pc))
+ {
+#ifdef DIRECT_THREADED
+ jclass handler = (jclass) exc[i].handler_type.p;
+#else
+ jclass handler = NULL;
+ if (exc[i].handler_type.i != 0)
+ handler = (_Jv_ResolvePoolEntry (defining_class,
+ exc[i].handler_type.i)).clazz;
+#endif /* DIRECT_THREADED */
+
+ if (handler == NULL || handler->isAssignableFrom (exc_class))
+ {
+#ifdef DIRECT_THREADED
+ pc = (insn_slot *) exc[i].handler_pc.p;
+#else
+ pc = bytecode () + exc[i].handler_pc.i;
+#endif /* DIRECT_THREADED */
+ sp = stack;
+ sp++->o = ex; // Push exception.
+ NEXT_INSN;
+ }
+ }
+ }
+ // No handler, so re-throw.
+ throw ex;
}
- goto next_insn;
}
+// This function exists so that the stack-tracing code can find the
+// boundaries of the interpreter.
+void
+_Jv_EndOfInterpreter (void)
+{
+}
static void
throw_internal_error (char *msg)
{
- JvThrow (new java::lang::InternalError (JvNewStringLatin1 (msg)));
+ throw new java::lang::InternalError (JvNewStringLatin1 (msg));
}
static void
throw_incompatible_class_change_error (jstring msg)
{
- JvThrow (new java::lang::IncompatibleClassChangeError (msg));
+ throw new java::lang::IncompatibleClassChangeError (msg);
}
-#if !HANDLE_SEGV
+#ifndef HANDLE_SEGV
static java::lang::NullPointerException *null_pointer_exc;
static void
throw_null_pointer_exception ()
if (null_pointer_exc == NULL)
null_pointer_exc = new java::lang::NullPointerException;
- JvThrow (null_pointer_exc);
+ throw null_pointer_exc;
}
#endif
-#if !HANDLE_FPE
-static java::lang::ArithmeticException *arithmetic_exc;
-static void
-throw_arithmetic_exception ()
-{
- if (arithmetic_exc == NULL)
- arithmetic_exc = new java::lang::ArithmeticException
- (JvNewStringLatin1 ("/ by zero"));
-
- JvThrow (arithmetic_exc);
-}
-#endif
-
-void
-jvdump(jobject o)
-{
- _Jv_InterpMethod::dump_object(o);
-}
-
-/* FIXME: This is not finished! */
-void
-_Jv_InterpMethod::dump_object(jobject o)
-{
- java::io::PrintStream *out = java::lang::System::out;
-
- if (o == NULL)
- {
- out->println (JvNewStringLatin1 ("<null>"));
- return;
- }
-
- jclass klass = o->getClass ();
-
- out->print (klass->getName ());
- out->print (JvNewStringLatin1 ("@0x"));
- out->print (java::lang::Integer::toHexString ((jint)o));
- out->print (JvNewStringLatin1 ("{"));
-#if 0
- while (klass && klass != &ObjectClass)
- {
- _Jv_Field *fields = klass->fields;
- int max = klass->field_count;
-
- for (int i = 0; i < max; ++i)
- {
- out->print (_Jv_NewStringUTF (field->name->data));
- out->print (JvNewStringLatin1 ("="));
-
- if (JvFieldIsRef (field))
- {
- if (field->flags & STATIC)
- out->print (JvGetSt)
- }
- field = field->getNextInstanceField ();
-
- if (i+1 < max && klass->getSuperclass () != null)
- out->print (JvNewStringLatin1 ("; "));
- }
-
- klass = klass->getSuperclass();
- }
-#endif
- out->print (JvNewStringLatin1 ("}\n"));
-
-}
-
#endif // INTERPRETER