Commit fdae83ab by Tom Tromey Committed by Tom Tromey

verify.cc (branch_prepass): Updated for change to exception handler type.

	* verify.cc (branch_prepass): Updated for change to exception
	handler type.
	(verify_instructions_0): Likewise.
	* defineclass.cc (handleCodeAttribute): Initialize `prepared'.
	(handleExceptionTableEntry): Updated for change to exception
	handler type.
	* java/lang/Class.h (Class): Removed _Jv_InterpMethodInvocation.
	* include/java-interp.h (_Jv_InterpMethodInvocation): Removed.
	(union _Jv_InterpPC): New.
	(class _Jv_InterpException): Changed types to _Jv_InterpPC.
	(class _Jv_InterpMethod): Added new `prepared' field.
	(class _Jv_InterpMethod): Added `compile' method.  Removed
	`continue1' and `find_exception'.  Changed arguments to `run'.
	* interpret.cc (union insn_slot): New.
	(find_exception): Removed.
	(run_normal): Removed most logic.
	(run_synch_object): Likewise; also, use JvSynchronize.
	(run_synch_class): Likewise.
	(run): Removed.
	(continue1): Renamed as `run'.  Compile bytecode if required.
	Add new code to allow refinement of direct-threaded code at
	runtime.  Handle exceptions.
	(SAVE_PC): Removed.
	(compile): New method.
	(SET_ONE, SET_INSN, SET_INT, SET_DATUM): New defines.
	(NULLARRAYCHECK): Don't use SAVE_PC.
	(pc_t): New typedef.
	(TAKE_GOTO, GET1S, GET1U, GET2U, AVAL1U, AVAL2U, AVAL2UP,
	SKIP_GOTO, GOTO_VAL, PCVAL, AMPAMP): New macros.

From-SVN: r54968
parent 7691fc06
2002-06-24 Tom Tromey <tromey@redhat.com>
* verify.cc (branch_prepass): Updated for change to exception
handler type.
(verify_instructions_0): Likewise.
* defineclass.cc (handleCodeAttribute): Initialize `prepared'.
(handleExceptionTableEntry): Updated for change to exception
handler type.
* java/lang/Class.h (Class): Removed _Jv_InterpMethodInvocation.
* include/java-interp.h (_Jv_InterpMethodInvocation): Removed.
(union _Jv_InterpPC): New.
(class _Jv_InterpException): Changed types to _Jv_InterpPC.
(class _Jv_InterpMethod): Added new `prepared' field.
(class _Jv_InterpMethod): Added `compile' method. Removed
`continue1' and `find_exception'. Changed arguments to `run'.
* interpret.cc (union insn_slot): New.
(find_exception): Removed.
(run_normal): Removed most logic.
(run_synch_object): Likewise; also, use JvSynchronize.
(run_synch_class): Likewise.
(run): Removed.
(continue1): Renamed as `run'. Compile bytecode if required.
Add new code to allow refinement of direct-threaded code at
runtime. Handle exceptions.
(SAVE_PC): Removed.
(compile): New method.
(SET_ONE, SET_INSN, SET_INT, SET_DATUM): New defines.
(NULLARRAYCHECK): Don't use SAVE_PC.
(pc_t): New typedef.
(TAKE_GOTO, GET1S, GET1U, GET2U, AVAL1U, AVAL2U, AVAL2UP,
SKIP_GOTO, GOTO_VAL, PCVAL, AMPAMP): New macros.
2002-06-23 Tom Tromey <tromey@redhat.com> 2002-06-23 Tom Tromey <tromey@redhat.com>
* configure: Rebuilt. * configure: Rebuilt.
......
...@@ -1258,6 +1258,7 @@ void _Jv_ClassReader::handleCodeAttribute ...@@ -1258,6 +1258,7 @@ void _Jv_ClassReader::handleCodeAttribute
method->exc_count = exc_table_length; method->exc_count = exc_table_length;
method->defining_class = def; method->defining_class = def;
method->self = &def->methods[method_index]; method->self = &def->methods[method_index];
method->prepared = NULL;
// grab the byte code! // grab the byte code!
memcpy ((void*) method->bytecode (), memcpy ((void*) method->bytecode (),
...@@ -1275,10 +1276,10 @@ void _Jv_ClassReader::handleExceptionTableEntry ...@@ -1275,10 +1276,10 @@ void _Jv_ClassReader::handleExceptionTableEntry
(def->interpreted_methods[method_index]); (def->interpreted_methods[method_index]);
_Jv_InterpException *exc = method->exceptions (); _Jv_InterpException *exc = method->exceptions ();
exc[exc_index].start_pc = start_pc; exc[exc_index].start_pc.i = start_pc;
exc[exc_index].end_pc = end_pc; exc[exc_index].end_pc.i = end_pc;
exc[exc_index].handler_pc = handler_pc; exc[exc_index].handler_pc.i = handler_pc;
exc[exc_index].handler_type = catch_type; exc[exc_index].handler_type.i = catch_type;
} }
void _Jv_ClassReader::handleMethodsEnd () void _Jv_ClassReader::handleMethodsEnd ()
......
// java-interp.h - Header file for the bytecode interpreter. -*- c++ -*- // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation /* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -49,14 +49,22 @@ void _Jv_VerifyMethod (_Jv_InterpMethod *method); ...@@ -49,14 +49,22 @@ void _Jv_VerifyMethod (_Jv_InterpMethod *method);
class _Jv_InterpClass; class _Jv_InterpClass;
class _Jv_InterpMethod; class _Jv_InterpMethod;
class _Jv_InterpMethodInvocation;
// Before a method is "compiled" we store values as the bytecode PC,
// an int. Afterwards we store them as pointers into the prepared
// code itself.
union _Jv_InterpPC
{
int i;
void *p;
};
class _Jv_InterpException class _Jv_InterpException
{ {
int start_pc; _Jv_InterpPC start_pc;
int end_pc; _Jv_InterpPC end_pc;
int handler_pc; _Jv_InterpPC handler_pc;
int handler_type; _Jv_InterpPC handler_type;
friend class _Jv_ClassReader; friend class _Jv_ClassReader;
friend class _Jv_InterpMethod; friend class _Jv_InterpMethod;
...@@ -92,6 +100,8 @@ class _Jv_InterpMethod : public _Jv_MethodBase ...@@ -92,6 +100,8 @@ class _Jv_InterpMethod : public _Jv_MethodBase
_Jv_ushort exc_count; _Jv_ushort exc_count;
void *prepared;
unsigned char* bytecode () unsigned char* bytecode ()
{ {
return return
...@@ -115,40 +125,23 @@ class _Jv_InterpMethod : public _Jv_MethodBase ...@@ -115,40 +125,23 @@ class _Jv_InterpMethod : public _Jv_MethodBase
// return the method's invocation pointer (a stub). // return the method's invocation pointer (a stub).
void *ncode (); void *ncode ();
void continue1 (_Jv_InterpMethodInvocation *inv); void compile (const void * const *);
static void run_normal (ffi_cif*, void*, ffi_raw*, void*); static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*); static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*); static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
inline jobject run (ffi_cif*, void*, ffi_raw*, void run (void*, ffi_raw *);
_Jv_InterpMethodInvocation*);
bool find_exception (jobject ex,
_Jv_InterpMethodInvocation *inv);
public: public:
static void dump_object(jobject o); static void dump_object(jobject o);
friend class _Jv_ClassReader; friend class _Jv_ClassReader;
friend class _Jv_InterpMethodInvocation;
friend class _Jv_BytecodeVerifier; friend class _Jv_BytecodeVerifier;
friend void _Jv_PrepareClass(jclass); friend void _Jv_PrepareClass(jclass);
}; };
class _Jv_InterpMethodInvocation {
_Jv_InterpMethod *running;
_Jv_word *sp;
unsigned char *pc;
_Jv_word state[0];
_Jv_word* stack_base () { return &state[0]; }
_Jv_word* local_base () { return &state[running->max_stack]; }
friend class _Jv_InterpMethod;
};
class _Jv_InterpClass : public java::lang::Class class _Jv_InterpClass : public java::lang::Class
{ {
_Jv_MethodBase **interpreted_methods; _Jv_MethodBase **interpreted_methods;
......
// interpret.cc - Code for the interpreter // interpret.cc - Code for the interpreter
/* Copyright (C) 1999, 2000, 2001 , 2002 Free Software Foundation /* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -12,6 +12,11 @@ details. */ ...@@ -12,6 +12,11 @@ details. */
#include <config.h> #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" #pragma implementation "java-interp.h"
#include <jvm.h> #include <jvm.h>
...@@ -51,6 +56,26 @@ static void throw_null_pointer_exception () ...@@ -51,6 +56,26 @@ static void throw_null_pointer_exception ()
extern "C" double __ieee754_fmod (double,double); 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 // first "slide" n+x elements n to the right
...@@ -199,12 +224,12 @@ static jint get4(unsigned char* loc) { ...@@ -199,12 +224,12 @@ static jint get4(unsigned char* loc) {
#ifdef HANDLE_SEGV #ifdef HANDLE_SEGV
#define NULLCHECK(X) #define NULLCHECK(X)
#define NULLARRAYCHECK(X) do { SAVE_PC; } while (0) #define NULLARRAYCHECK(X)
#else #else
#define NULLCHECK(X) \ #define NULLCHECK(X) \
do { if ((X)==NULL) throw_null_pointer_exception (); } while (0) do { if ((X)==NULL) throw_null_pointer_exception (); } while (0)
#define NULLARRAYCHECK(X) \ #define NULLARRAYCHECK(X) \
do { if ((X)==NULL) { SAVE_PC; throw_null_pointer_exception (); } } while (0) do { if ((X)==NULL) { throw_null_pointer_exception (); } } while (0)
#endif #endif
#define ARRAYBOUNDSCHECK(array, index) \ #define ARRAYBOUNDSCHECK(array, index) \
...@@ -215,230 +240,534 @@ static jint get4(unsigned char* loc) { ...@@ -215,230 +240,534 @@ static jint get4(unsigned char* loc) {
} \ } \
while (0) while (0)
// this method starts the actual running of the method. It is inlined void _Jv_InterpMethod::run_normal (ffi_cif *,
// in three different variants in the static methods run_normal, void* ret,
// run_sync_object and run_sync_class (see below). Those static methods ffi_raw * args,
// are installed directly in the stub for this method (by void* __this)
// _Jv_InterpMethod::ncode, in resolve.cc).
inline jobject
_Jv_InterpMethod::run (ffi_cif* cif,
void *retp,
ffi_raw *args,
_Jv_InterpMethodInvocation *inv)
{ {
inv->running = this; _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
inv->pc = bytecode (); _this->run (ret, args);
inv->sp = inv->stack_base (); }
_Jv_word *locals = inv->local_base ();
/* Go straight at it! the ffi raw format matches the internal void _Jv_InterpMethod::run_synch_object (ffi_cif *,
stack representation exactly. At least, that's the idea. void* ret,
*/ ffi_raw * args,
memcpy ((void*) locals, (void*) args, args_raw_size); void* __this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
next_segment: jobject rcv = (jobject) args[0].ptr;
JvSynchronize mutex (rcv);
jobject ex = NULL; _this->run (ret, args);
}
try void _Jv_InterpMethod::run_synch_class (ffi_cif *,
{ void* ret,
continue1 (inv); ffi_raw * args,
} void* __this)
catch (java::lang::Throwable *ex2) {
{ _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
ex = ex2;
}
if (ex == 0) // no exception... jclass sync = _this->defining_class;
{ JvSynchronize mutex (sync);
/* 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) _this->run (ret, args);
{ }
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: #ifdef DIRECT_THREADED
// "Compile" a method by turning it from bytecode to direct-threaded
// code.
void
_Jv_InterpMethod::compile (const void * const *insn_targets)
{
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;
if (! first_pass)
{
insns = (insn_slot *) _Jv_Malloc (sizeof (insn_slot) * next);
next = 0;
}
unsigned char *pc = codestart;
while (pc < end)
{
int base_pc_val = pc - codestart;
if (first_pass)
pc_mapping[base_pc_val] = next;
java_opcode opcode = (java_opcode) *pc++;
// Just elide NOPs.
if (opcode == op_nop)
continue;
SET_INSN (insn_targets[opcode]);
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:
{ {
jdouble r = POPD(); int index = get1u (pc);
*(jdouble*)retp = r; ++pc;
return 0; SET_DATUM (pool_data[index].o);
} }
break;
case FFI_TYPE_UINT8: case op_ret:
case FFI_TYPE_UINT16: case op_iload:
case FFI_TYPE_UINT32: case op_lload:
case FFI_TYPE_SINT8: case op_fload:
case FFI_TYPE_SINT16: 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:
{ {
jint r = POPI(); int index = get2u (pc);
*(jint*)retp = r; pc += 2;
return 0; SET_DATUM (pool_data[index].o);
} }
break;
case FFI_TYPE_SINT64: case op_ldc2_w:
{ {
jlong r = POPL(); int index = get2u (pc);
*(jlong*)retp = r; pc += 2;
return 0; SET_DATUM (&pool_data[index]);
} }
break;
default: case op_sipush:
throw_internal_error ("unknown return type"); SET_INT (get2s (pc));
} pc += 2;
} break;
/** handle an exception */ case op_new:
if ( find_exception (ex, inv) ) case op_getstatic:
goto next_segment; 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;
return ex; case op_multianewarray:
} SET_INT (get2u (pc));
SET_INT (get1u (pc + 2));
pc += 3;
break;
#define SAVE_PC inv->pc = pc 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;
bool _Jv_InterpMethod::find_exception (jobject ex, int new_pc = base_pc_val + offset;
_Jv_InterpMethodInvocation *inv)
{
// We subtract one because the PC was incremented before it was
// saved.
int logical_pc = inv->pc - 1 - bytecode ();
_Jv_InterpException *exc = exceptions ();
jclass exc_class = ex->getClass ();
for (int i = 0; i < exc_count; i++) bool orig_was_goto = opcode == op_goto;
{
if (exc[i].start_pc <= logical_pc && logical_pc < exc[i].end_pc)
{
jclass handler;
if (exc[i].handler_type != 0) // Thread jumps. We limit the loop count; this lets
handler = (_Jv_ResolvePoolEntry (defining_class, // us avoid infinite loops if the bytecode contains
exc[i].handler_type)).clazz; // such. `10' is arbitrary.
else int count = 10;
handler = NULL; while (codestart[new_pc] == op_goto && count-- > 0)
new_pc += get2s (&codestart[new_pc + 1]);
if (handler==NULL || handler->isAssignableFrom (exc_class)) // 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))
{ {
inv->pc = bytecode () + exc[i].handler_pc; --next;
inv->sp = inv->stack_base (); // reset stack SET_INSN (insn_targets[opcode]);
(inv->sp++)->o = ex; // push exception
return true;
}
} }
else
SET_DATUM (&insns[pc_mapping[new_pc]]);
} }
return false; break;
}
void _Jv_InterpMethod::run_normal (ffi_cif* cif, case op_tableswitch:
void* ret, {
ffi_raw * args, while ((pc - codestart) % 4 != 0)
void* __this) ++pc;
{
_Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
// we do the alloca of the method invocation here, to allow the method jint def = get4 (pc);
// "run" ro be inlined. Otherwise gcc will ignore the inline directive. SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
int storage_size = _this->max_stack+_this->max_locals; pc += 4;
_Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*)
__builtin_alloca (sizeof (_Jv_InterpMethodInvocation)
+ storage_size * sizeof (_Jv_word));
jobject ex = _this->run (cif, ret, args, inv); int low = get4 (pc);
if (ex != 0) throw static_cast<jthrowable>(ex); SET_INT (low);
} pc += 4;
int high = get4 (pc);
SET_INT (high);
pc += 4;
void _Jv_InterpMethod::run_synch_object (ffi_cif* cif, for (int i = low; i <= high; ++i)
void* ret, {
ffi_raw * args, SET_DATUM (&insns[pc_mapping[base_pc_val + get4 (pc)]]);
void* __this) pc += 4;
{ }
_Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this; }
jobject rcv = (jobject)args[0].ptr; break;
int storage_size = _this->max_stack+_this->max_locals; case op_lookupswitch:
_Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) {
__builtin_alloca (sizeof (_Jv_InterpMethodInvocation) while ((pc - codestart) % 4 != 0)
+ storage_size * sizeof (_Jv_word)); ++pc;
_Jv_MonitorEnter (rcv); jint def = get4 (pc);
jobject ex = _this->run (cif, ret, args, inv); SET_DATUM (&insns[pc_mapping[base_pc_val + def]]);
_Jv_MonitorExit (rcv); pc += 4;
if (ex != 0) throw static_cast<jthrowable>(ex); jint npairs = get4 (pc);
} pc += 4;
SET_INT (npairs);
void _Jv_InterpMethod::run_synch_class (ffi_cif* cif, while (npairs-- > 0)
void* ret, {
ffi_raw * args, jint match = get4 (pc);
void* __this) jint offset = get4 (pc + 4);
{ SET_INT (match);
_Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this; SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
jclass sync = _this->defining_class; pc += 8;
}
}
break;
case op_invokeinterface:
{
jint index = get2u (pc);
pc += 2;
// We ignore the next two bytes.
pc += 2;
SET_INT (index);
}
break;
int storage_size = _this->max_stack+_this->max_locals; case op_wide:
_Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) {
__builtin_alloca (sizeof (_Jv_InterpMethodInvocation) opcode = (java_opcode) get1u (pc);
+ storage_size * sizeof (_Jv_word)); pc += 1;
jint val = get2u (pc);
pc += 2;
_Jv_MonitorEnter (sync); // We implement narrow and wide instructions using the
jobject ex = _this->run (cif, ret, args, inv); // same code in the interpreter. So we rewrite the
_Jv_MonitorExit (sync); // instruction slot here.
if (! first_pass)
insns[next - 1].insn = (void *) insn_targets[opcode];
SET_INT (val);
if (ex != 0) throw static_cast<jthrowable>(ex); if (opcode == op_iinc)
} {
SET_INT (get2s (pc));
pc += 2;
}
}
break;
/* case op_jsr_w:
This proceeds execution, as designated in "inv". If an exception case op_goto_w:
happens, then it is simply thrown, and handled in Java. Thus, the pc {
needs to be stored in the inv->pc at all times, so we can figure jint offset = get4 (pc);
out which handler (if any) to invoke. pc += 4;
SET_DATUM (&insns[pc_mapping[base_pc_val + offset]]);
}
break;
One design issue, which I have not completely considered, is if it // Some "can't happen" cases that we include for
should be possible to have interpreted classes linked in! Seldom used // error-checking purposes.
(or non-critical) classes could reasonably be interpreted. 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;
}
}
}
// Now update exceptions.
_Jv_InterpException *exc = exceptions ();
for (int i = 0; i < exc_count; ++i)
{
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;
}
prepared = insns;
}
#endif /* DIRECT_THREADED */
void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) void
_Jv_InterpMethod::run (void *retp, ffi_raw *args)
{ {
using namespace java::lang::reflect; using namespace java::lang::reflect;
_Jv_word *sp = inv->sp; _Jv_word stack[max_stack];
unsigned char *pc = inv->pc; _Jv_word *sp = stack;
_Jv_word *locals = inv->local_base ();
_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);
_Jv_word *pool_data = defining_class->constants.data; _Jv_word *pool_data = defining_class->constants.data;
/* these two are used in the invokeXXX instructions */ /* These three are temporaries for common code used by several
instructions. */
void (*fun)(); void (*fun)();
_Jv_ResolvedMethod* rmeth; _Jv_ResolvedMethod* rmeth;
int tmpval;
#define INSN_LABEL(op) &&insn_##op #define INSN_LABEL(op) &&insn_##op
#define GOTO_INSN(op) goto *(insn_target[op])
static const void *const insn_target[] = static const void *const insn_target[] =
{ {
...@@ -638,52 +967,83 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -638,52 +967,83 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
INSN_LABEL(instanceof), INSN_LABEL(instanceof),
INSN_LABEL(monitorenter), INSN_LABEL(monitorenter),
INSN_LABEL(monitorexit), INSN_LABEL(monitorexit),
#ifdef DIRECT_THREADED
0, // wide
#else
INSN_LABEL(wide), INSN_LABEL(wide),
#endif
INSN_LABEL(multianewarray), INSN_LABEL(multianewarray),
INSN_LABEL(ifnull), INSN_LABEL(ifnull),
INSN_LABEL(ifnonnull), INSN_LABEL(ifnonnull),
INSN_LABEL(goto_w), INSN_LABEL(goto_w),
INSN_LABEL(jsr_w), INSN_LABEL(jsr_w),
0
}; };
/* If the macro INLINE_SWITCH is not defined, then the main loop pc_t pc;
operates as one big (normal) switch statement. If it is defined,
then the case selection is performed `inline' in the end of the
code for each case. The latter saves a native branch instruction
for each java-instruction, but expands the code size somewhat.
NOTE: On i386 defining INLINE_SWITCH improves over all
performance approximately seven percent, but it may be different
for other machines. At some point, this may be made into a proper
configuration parameter. */
#define INLINE_SWITCH #ifdef DIRECT_THREADED
#ifdef INLINE_SWITCH #define NEXT_INSN goto *((pc++)->insn)
#define INTVAL() ((pc++)->int_val)
#define AVAL() ((pc++)->datum)
#define NEXT_INSN do { GOTO_INSN(*pc++); } while (0) #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;
#else #else
#define NEXT_INSN goto next_insn #define NEXT_INSN goto *(insn_target[*pc++])
next_insn: #define GET1S() get1s (pc++)
GOTO_INSN (*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 pc = bytecode ();
#endif /* DIRECT_THREADED */
#define TAKE_GOTO pc = GOTO_VAL ()
try
{
// We keep nop around. It is used if we're interpreting the
// bytecodes and not doing direct threading.
insn_nop:
NEXT_INSN;
/* The first few instructions here are ordered according to their /* The first few instructions here are ordered according to their
frequency, in the hope that this will improve code locality a frequency, in the hope that this will improve code locality a
little. */ little. */
insn_aload_0: // 0x2a insn_aload_0: // 0x2a
LOADA(0); LOADA (0);
NEXT_INSN; NEXT_INSN;
insn_iload: // 0x15 insn_iload: // 0x15
LOADI (get1u (pc++)); LOADI (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_iload_1: // 0x1b insn_iload_1: // 0x1b
...@@ -691,9 +1051,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -691,9 +1051,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_invokevirtual: // 0xb6 insn_invokevirtual: // 0xb6
SAVE_PC;
{ {
int index = get2u (pc); pc += 2; int index = GET2U ();
/* _Jv_ResolvePoolEntry returns immediately if the value already /* _Jv_ResolvePoolEntry returns immediately if the value already
* is resolved. If we want to clutter up the code here to gain * is resolved. If we want to clutter up the code here to gain
...@@ -719,12 +1078,46 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -719,12 +1078,46 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
else else
{ {
jobject rcv = sp[0].o; jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**)rcv; _Jv_VTable *table = *(_Jv_VTable**) rcv;
fun = (void (*)()) table->get_method(rmeth->vtable_index); 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; 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;
}
else
{
jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**) rcv;
fun = (void (*)()) table->get_method (rmeth->vtable_index);
}
}
goto perform_invoke;
#endif /* DIRECT_THREADED */
perform_invoke: perform_invoke:
{ {
/* here goes the magic again... */ /* here goes the magic again... */
...@@ -757,7 +1150,9 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -757,7 +1150,9 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
{ {
/* skip */ /* skip */
} }
else switch (rtype) else
{
switch (rtype)
{ {
case FFI_TYPE_SINT8: case FFI_TYPE_SINT8:
{ {
...@@ -795,12 +1190,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -795,12 +1190,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
default: default:
throw_internal_error ("unknown return type in invokeXXX"); throw_internal_error ("unknown return type in invokeXXX");
} }
} }
NEXT_INSN; }
insn_nop:
NEXT_INSN; NEXT_INSN;
insn_aconst_null: insn_aconst_null:
...@@ -864,49 +1255,47 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -864,49 +1255,47 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_bipush: insn_bipush:
PUSHI (get1s(pc++)); // For direct threaded, bipush and sipush are the same.
#ifndef DIRECT_THREADED
PUSHI (GET1S ());
NEXT_INSN; NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_sipush: insn_sipush:
PUSHI (get2s(pc)); pc += 2; PUSHI (GET2S ());
NEXT_INSN; NEXT_INSN;
insn_ldc: insn_ldc:
{ // For direct threaded, ldc and ldc_w are the same.
int index = get1u (pc++); #ifndef DIRECT_THREADED
PUSHA(pool_data[index].o); PUSHA ((jobject) AVAL1U ());
}
NEXT_INSN; NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_ldc_w: insn_ldc_w:
{ PUSHA ((jobject) AVAL2U ());
int index = get2u (pc); pc += 2;
PUSHA(pool_data[index].o);
}
NEXT_INSN; NEXT_INSN;
insn_ldc2_w: insn_ldc2_w:
{ {
int index = get2u (pc); pc += 2; void *where = AVAL2UP ();
memcpy (sp, &pool_data[index], 2*sizeof (_Jv_word)); memcpy (sp, where, 2*sizeof (_Jv_word));
sp += 2; sp += 2;
} }
NEXT_INSN; NEXT_INSN;
insn_lload: insn_lload:
LOADL (get1u (pc++)); LOADL (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_fload: insn_fload:
LOADF (get1u (pc++)); LOADF (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_dload: insn_dload:
LOADD (get1u (pc++)); LOADD (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_aload: insn_aload:
LOADA (get1u (pc++)); LOADA (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_iload_0: insn_iload_0:
...@@ -1062,23 +1451,23 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1062,23 +1451,23 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_istore: insn_istore:
STOREI (get1u (pc++)); STOREI (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_lstore: insn_lstore:
STOREL (get1u (pc++)); STOREL (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_fstore: insn_fstore:
STOREF (get1u (pc++)); STOREF (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_dstore: insn_dstore:
STORED (get1u (pc++)); STORED (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_astore: insn_astore:
STOREA (get1u (pc++)); STOREA (GET1U ());
NEXT_INSN; NEXT_INSN;
insn_istore_0: insn_istore_0:
...@@ -1343,7 +1732,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1343,7 +1732,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_idiv: insn_idiv:
SAVE_PC;
{ {
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
...@@ -1353,7 +1741,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1353,7 +1741,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_ldiv: insn_ldiv:
SAVE_PC;
{ {
jlong value2 = POPL(); jlong value2 = POPL();
jlong value1 = POPL(); jlong value1 = POPL();
...@@ -1381,7 +1768,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1381,7 +1768,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_irem: insn_irem:
SAVE_PC;
{ {
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
...@@ -1391,7 +1777,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1391,7 +1777,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_lrem: insn_lrem:
SAVE_PC;
{ {
jlong value2 = POPL(); jlong value2 = POPL();
jlong value1 = POPL(); jlong value1 = POPL();
...@@ -1520,8 +1905,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1520,8 +1905,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
insn_iinc: insn_iinc:
{ {
jint index = get1u (pc++); jint index = GET1U ();
jint amount = get1s (pc++); jint amount = GET1S ();
locals[index].i += amount; locals[index].i += amount;
} }
NEXT_INSN; NEXT_INSN;
...@@ -1616,7 +2001,13 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1616,7 +2001,13 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_fcmpl: insn_fcmpl:
tmpval = -1;
goto fcmp;
insn_fcmpg: insn_fcmpg:
tmpval = 1;
fcmp:
{ {
jfloat value2 = POPF (); jfloat value2 = POPF ();
jfloat value1 = POPF (); jfloat value1 = POPF ();
...@@ -1626,15 +2017,19 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1626,15 +2017,19 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
PUSHI (0); PUSHI (0);
else if (value1 < value2) else if (value1 < value2)
PUSHI (-1); PUSHI (-1);
else if ((*(pc-1)) == op_fcmpg)
PUSHI (1);
else else
PUSHI (-1); PUSHI (tmpval);
} }
NEXT_INSN; NEXT_INSN;
insn_dcmpl: insn_dcmpl:
tmpval = 1;
goto dcmp;
insn_dcmpg: insn_dcmpg:
tmpval = -1;
dcmp:
{ {
jdouble value2 = POPD (); jdouble value2 = POPD ();
jdouble value1 = POPD (); jdouble value1 = POPD ();
...@@ -1644,220 +2039,267 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1644,220 +2039,267 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
PUSHI (0); PUSHI (0);
else if (value1 < value2) else if (value1 < value2)
PUSHI (-1); PUSHI (-1);
else if ((*(pc-1)) == op_dcmpg)
PUSHI (1);
else else
PUSHI (-1); PUSHI (tmpval);
} }
NEXT_INSN; NEXT_INSN;
insn_ifeq: insn_ifeq:
{ {
jint offset = get2s (pc);
if (POPI() == 0) if (POPI() == 0)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_ifne: insn_ifne:
{ {
jint offset = get2s (pc);
if (POPI() != 0) if (POPI() != 0)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_iflt: insn_iflt:
{ {
jint offset = get2s (pc);
if (POPI() < 0) if (POPI() < 0)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_ifge: insn_ifge:
{ {
jint offset = get2s (pc);
if (POPI() >= 0) if (POPI() >= 0)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_ifgt: insn_ifgt:
{ {
jint offset = get2s (pc);
if (POPI() > 0) if (POPI() > 0)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_ifle: insn_ifle:
{ {
jint offset = get2s (pc);
if (POPI() <= 0) if (POPI() <= 0)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_icmpeq: insn_if_icmpeq:
{ {
jint offset = get2s (pc);
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
if (value1 == value2) if (value1 == value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_icmpne: insn_if_icmpne:
{ {
jint offset = get2s (pc);
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
if (value1 != value2) if (value1 != value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_icmplt: insn_if_icmplt:
{ {
jint offset = get2s (pc);
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
if (value1 < value2) if (value1 < value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_icmpge: insn_if_icmpge:
{ {
jint offset = get2s (pc);
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
if (value1 >= value2) if (value1 >= value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_icmpgt: insn_if_icmpgt:
{ {
jint offset = get2s (pc);
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
if (value1 > value2) if (value1 > value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_icmple: insn_if_icmple:
{ {
jint offset = get2s (pc);
jint value2 = POPI(); jint value2 = POPI();
jint value1 = POPI(); jint value1 = POPI();
if (value1 <= value2) if (value1 <= value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_acmpeq: insn_if_acmpeq:
{ {
jint offset = get2s (pc);
jobject value2 = POPA(); jobject value2 = POPA();
jobject value1 = POPA(); jobject value1 = POPA();
if (value1 == value2) if (value1 == value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_if_acmpne: insn_if_acmpne:
{ {
jint offset = get2s (pc);
jobject value2 = POPA(); jobject value2 = POPA();
jobject value1 = POPA(); jobject value1 = POPA();
if (value1 != value2) if (value1 != value2)
pc = pc-1+offset; TAKE_GOTO;
else else
pc = pc+2; SKIP_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: insn_goto:
TAKE_GOTO;
NEXT_INSN;
insn_jsr_w:
#ifndef DIRECT_THREADED
// For direct threaded, jsr and jsr_w are the same.
{ {
jint offset = get2s (pc); pc_t next = pc - 1 + get4 (pc);
pc = pc-1+offset; pc += 4;
PUSHA ((jobject) pc);
pc = next;
} }
NEXT_INSN; NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_jsr: insn_jsr:
{ {
unsigned char *base_pc = pc-1; pc_t next = GOTO_VAL();
jint offset = get2s (pc); pc += 2; SKIP_GOTO;
PUSHA ((jobject)pc); PUSHA ((jobject) pc);
pc = base_pc+offset; pc = next;
} }
NEXT_INSN; NEXT_INSN;
insn_ret: insn_ret:
{ {
jint index = get1u (pc); jint index = GET1U ();
pc = (unsigned char*) PEEKA (index); pc = (pc_t) PEEKA (index);
} }
NEXT_INSN; NEXT_INSN;
insn_tableswitch: insn_tableswitch:
{ {
unsigned char *base_pc = pc-1; #ifdef DIRECT_THREADED
void *def = (pc++)->datum;
int index = POPI(); int index = POPI();
unsigned char* base = bytecode (); jint low = INTVAL ();
while ((pc-base) % 4 != 0) jint high = INTVAL ();
pc++;
jint def = get4 (pc); if (index < low || index > high)
jint low = get4 (pc+4); pc = (insn_slot *) def;
jint high = get4 (pc+8); 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) if (index < low || index > high)
pc = base_pc + def; pc = base_pc + def;
else else
pc = base_pc + get4 (pc+4*(index-low+3)); pc = base_pc + get4 (pc + 4 * (index - low + 3));
#endif /* DIRECT_THREADED */
} }
NEXT_INSN; NEXT_INSN;
insn_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; unsigned char *base_pc = pc-1;
int index = POPI(); int index = POPI();
unsigned char* base = bytecode (); unsigned char* base = bytecode ();
while ((pc-base) % 4 != 0) while ((pc-base) % 4 != 0)
pc++; ++pc;
jint def = get4 (pc); jint def = get4 (pc);
jint npairs = get4 (pc+4); jint npairs = get4 (pc+4);
...@@ -1865,7 +2307,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1865,7 +2307,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
int max = npairs-1; int max = npairs-1;
int min = 0; int min = 0;
// simple binary search... // Simple binary search...
while (min < max) while (min < max)
{ {
int half = (min+max)/2; int half = (min+max)/2;
...@@ -1873,35 +2315,50 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1873,35 +2315,50 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
if (index == match) if (index == match)
min = max = half; min = max = half;
else if (index < match) else if (index < match)
max = half-1; // We can use HALF - 1 here because we check again on
// loop exit.
max = half - 1;
else 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))) if (index == get4 (pc+ 4*(2 + 2*min)))
pc = base_pc + get4 (pc+ 4*(2 + 2*min + 1)); pc = base_pc + get4 (pc+ 4*(2 + 2*min + 1));
else else
pc = base_pc + def; pc = base_pc + def;
#endif /* DIRECT_THREADED */
} }
NEXT_INSN; NEXT_INSN;
/* on return, just save the sp and return to caller */ insn_areturn:
insn_ireturn: *(jobject *) retp = POPA ();
return;
insn_lreturn: insn_lreturn:
*(jlong *) retp = POPL ();
return;
insn_freturn: insn_freturn:
*(jfloat *) retp = POPF ();
return;
insn_dreturn: insn_dreturn:
insn_areturn: *(jdouble *) retp = POPD ();
return;
insn_ireturn:
*(jint *) retp = POPI ();
return;
insn_return: insn_return:
inv->sp = sp;
return; return;
insn_getstatic: insn_getstatic:
SAVE_PC;
{ {
jint fieldref_index = get2u (pc); pc += 2; jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index); _Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field; _Jv_Field *field = pool_data[fieldref_index].field;
...@@ -1911,41 +2368,84 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1911,41 +2368,84 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jclass type = field->type; jclass type = field->type;
// We rewrite the instruction once we discover what it refers
// to.
void *newinsn = NULL;
if (type->isPrimitive ()) if (type->isPrimitive ())
{ {
switch (type->size_in_bytes) switch (type->size_in_bytes)
{ {
case 1: case 1:
PUSHI (*(jbyte*) (field->u.addr)); PUSHI (*(jbyte*) (field->u.addr));
newinsn = AMPAMP (getstatic_resolved_1);
break; break;
case 2: case 2:
if (type == JvPrimClass (char)) if (type == JvPrimClass (char))
{
PUSHI(*(jchar*) (field->u.addr)); PUSHI(*(jchar*) (field->u.addr));
newinsn = AMPAMP (getstatic_resolved_char);
}
else else
{
PUSHI(*(jshort*) (field->u.addr)); PUSHI(*(jshort*) (field->u.addr));
newinsn = AMPAMP (getstatic_resolved_short);
}
break; break;
case 4: case 4:
PUSHI(*(jint*) (field->u.addr)); PUSHI(*(jint*) (field->u.addr));
newinsn = AMPAMP (getstatic_resolved_4);
break; break;
case 8: case 8:
PUSHL(*(jlong*) (field->u.addr)); PUSHL(*(jlong*) (field->u.addr));
newinsn = AMPAMP (getstatic_resolved_8);
break; break;
} }
} }
else else
{ {
PUSHA(*(jobject*) (field->u.addr)); PUSHA(*(jobject*) (field->u.addr));
newinsn = AMPAMP (getstatic_resolved_obj);
} }
#ifdef DIRECT_THREADED
pc[-2].insn = newinsn;
pc[-1].datum = field->u.addr;
#endif /* DIRECT_THREADED */
} }
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;
getstatic_resolved_8:
PUSHL (*(jlong *) AVAL ());
NEXT_INSN;
getstatic_resolved_obj:
PUSHA (*(jobject *) AVAL ());
NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_getfield: insn_getfield:
SAVE_PC;
{ {
jint fieldref_index = get2u (pc); pc += 2; jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index); _Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field; _Jv_Field *field = pool_data[fieldref_index].field;
...@@ -1961,41 +2461,106 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -1961,41 +2461,106 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jobject obj = POPA(); jobject obj = POPA();
NULLCHECK(obj); NULLCHECK(obj);
void *newinsn = NULL;
if (type->isPrimitive ()) if (type->isPrimitive ())
{ {
switch (type->size_in_bytes) switch (type->size_in_bytes)
{ {
case 1: case 1:
PUSHI (*(jbyte*) ((char*)obj + field_offset)); PUSHI (*(jbyte*) ((char*)obj + field_offset));
newinsn = AMPAMP (getfield_resolved_1);
break; break;
case 2: case 2:
if (type == JvPrimClass (char)) if (type == JvPrimClass (char))
{
PUSHI (*(jchar*) ((char*)obj + field_offset)); PUSHI (*(jchar*) ((char*)obj + field_offset));
newinsn = AMPAMP (getfield_resolved_char);
}
else else
{
PUSHI (*(jshort*) ((char*)obj + field_offset)); PUSHI (*(jshort*) ((char*)obj + field_offset));
newinsn = AMPAMP (getfield_resolved_short);
}
break; break;
case 4: case 4:
PUSHI (*(jint*) ((char*)obj + field_offset)); PUSHI (*(jint*) ((char*)obj + field_offset));
newinsn = AMPAMP (getfield_resolved_4);
break; break;
case 8: case 8:
PUSHL(*(jlong*) ((char*)obj + field_offset)); PUSHL(*(jlong*) ((char*)obj + field_offset));
newinsn = AMPAMP (getfield_resolved_8);
break; break;
} }
} }
else else
{ {
PUSHA(*(jobject*) ((char*)obj + field_offset)); PUSHA(*(jobject*) ((char*)obj + field_offset));
newinsn = AMPAMP (getfield_resolved_obj);
}
#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;
getfield_resolved_short:
{
char *obj = (char *) POPA ();
NULLCHECK (obj);
PUSHI (*(jshort *) (obj + INTVAL ()));
}
NEXT_INSN;
getfield_resolved_4:
{
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; NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_putstatic: insn_putstatic:
SAVE_PC;
{ {
jint fieldref_index = get2u (pc); pc += 2; jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index); _Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field; _Jv_Field *field = pool_data[fieldref_index].field;
...@@ -2006,6 +2571,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2006,6 +2571,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
throw_incompatible_class_change_error throw_incompatible_class_change_error
(JvNewStringLatin1 ("field no longer static")); (JvNewStringLatin1 ("field no longer static"));
void *newinsn = NULL;
if (type->isPrimitive ()) if (type->isPrimitive ())
{ {
switch (type->size_in_bytes) switch (type->size_in_bytes)
...@@ -2014,6 +2580,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2014,6 +2580,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
{ {
jint value = POPI(); jint value = POPI();
*(jbyte*) (field->u.addr) = value; *(jbyte*) (field->u.addr) = value;
newinsn = AMPAMP (putstatic_resolved_1);
break; break;
} }
...@@ -2021,6 +2588,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2021,6 +2588,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
{ {
jint value = POPI(); jint value = POPI();
*(jchar*) (field->u.addr) = value; *(jchar*) (field->u.addr) = value;
newinsn = AMPAMP (putstatic_resolved_2);
break; break;
} }
...@@ -2028,6 +2596,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2028,6 +2596,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
{ {
jint value = POPI(); jint value = POPI();
*(jint*) (field->u.addr) = value; *(jint*) (field->u.addr) = value;
newinsn = AMPAMP (putstatic_resolved_4);
break; break;
} }
...@@ -2035,6 +2604,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2035,6 +2604,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
{ {
jlong value = POPL(); jlong value = POPL();
*(jlong*) (field->u.addr) = value; *(jlong*) (field->u.addr) = value;
newinsn = AMPAMP (putstatic_resolved_8);
break; break;
} }
} }
...@@ -2043,15 +2613,41 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2043,15 +2613,41 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
{ {
jobject value = POPA(); jobject value = POPA();
*(jobject*) (field->u.addr) = value; *(jobject*) (field->u.addr) = value;
newinsn = AMPAMP (putstatic_resolved_obj);
} }
#ifdef DIRECT_THREADED
pc[-2].insn = newinsn;
pc[-1].datum = field->u.addr;
#endif /* DIRECT_THREADED */
} }
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;
putstatic_resolved_8:
*(jlong *) AVAL () = POPL ();
NEXT_INSN;
putstatic_resolved_obj:
*(jobject *) AVAL () = POPA ();
NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_putfield: insn_putfield:
SAVE_PC;
{ {
jint fieldref_index = get2u (pc); pc += 2; jint fieldref_index = GET2U ();
_Jv_ResolvePoolEntry (defining_class, fieldref_index); _Jv_ResolvePoolEntry (defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field; _Jv_Field *field = pool_data[fieldref_index].field;
...@@ -2065,6 +2661,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2065,6 +2661,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
if (field_offset > 0xffff) if (field_offset > 0xffff)
throw new java::lang::VirtualMachineError; throw new java::lang::VirtualMachineError;
void *newinsn = NULL;
if (type->isPrimitive ()) if (type->isPrimitive ())
{ {
switch (type->size_in_bytes) switch (type->size_in_bytes)
...@@ -2075,6 +2672,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2075,6 +2672,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jobject obj = POPA(); jobject obj = POPA();
NULLCHECK(obj); NULLCHECK(obj);
*(jbyte*) ((char*)obj + field_offset) = value; *(jbyte*) ((char*)obj + field_offset) = value;
newinsn = AMPAMP (putfield_resolved_1);
break; break;
} }
...@@ -2084,6 +2682,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2084,6 +2682,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jobject obj = POPA(); jobject obj = POPA();
NULLCHECK(obj); NULLCHECK(obj);
*(jchar*) ((char*)obj + field_offset) = value; *(jchar*) ((char*)obj + field_offset) = value;
newinsn = AMPAMP (putfield_resolved_2);
break; break;
} }
...@@ -2093,6 +2692,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2093,6 +2692,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jobject obj = POPA(); jobject obj = POPA();
NULLCHECK(obj); NULLCHECK(obj);
*(jint*) ((char*)obj + field_offset) = value; *(jint*) ((char*)obj + field_offset) = value;
newinsn = AMPAMP (putfield_resolved_4);
break; break;
} }
...@@ -2102,6 +2702,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2102,6 +2702,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jobject obj = POPA(); jobject obj = POPA();
NULLCHECK(obj); NULLCHECK(obj);
*(jlong*) ((char*)obj + field_offset) = value; *(jlong*) ((char*)obj + field_offset) = value;
newinsn = AMPAMP (putfield_resolved_8);
break; break;
} }
} }
...@@ -2112,14 +2713,66 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2112,14 +2713,66 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
jobject obj = POPA(); jobject obj = POPA();
NULLCHECK(obj); NULLCHECK(obj);
*(jobject*) ((char*)obj + field_offset) = value; *(jobject*) ((char*)obj + field_offset) = value;
newinsn = AMPAMP (putfield_resolved_obj);
} }
#ifdef DIRECT_THREADED
pc[-2].insn = newinsn;
pc[-1].int_val = field_offset;
#endif /* DIRECT_THREADED */
} }
NEXT_INSN; NEXT_INSN;
#ifdef DIRECT_THREADED
putfield_resolved_1:
{
jint val = POPI ();
char *obj = (char *) POPA ();
NULLCHECK (obj);
*(jbyte *) (obj + INTVAL ()) = val;
}
NEXT_INSN;
putfield_resolved_2:
{
jint val = POPI ();
char *obj = (char *) POPA ();
NULLCHECK (obj);
*(jchar *) (obj + INTVAL ()) = val;
}
NEXT_INSN;
putfield_resolved_4:
{
jint val = POPI ();
char *obj = (char *) POPA ();
NULLCHECK (obj);
*(jint *) (obj + INTVAL ()) = val;
}
NEXT_INSN;
putfield_resolved_8:
{
jlong val = POPL ();
char *obj = (char *) POPA ();
NULLCHECK (obj);
*(jlong *) (obj + INTVAL ()) = val;
}
NEXT_INSN;
putfield_resolved_obj:
{
jobject val = POPA ();
char *obj = (char *) POPA ();
NULLCHECK (obj);
*(jobject *) (obj + INTVAL ()) = val;
}
NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_invokespecial: insn_invokespecial:
SAVE_PC;
{ {
int index = get2u (pc); pc += 2; int index = GET2U ();
rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod; rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
...@@ -2128,13 +2781,30 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2128,13 +2781,30 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NULLCHECK (sp[0].o); NULLCHECK (sp[0].o);
fun = (void (*)()) rmeth->method->ncode; fun = (void (*)()) rmeth->method->ncode;
#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 perform_invoke; goto perform_invoke;
#ifdef DIRECT_THREADED
invokespecial_resolved:
{
rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
NULLCHECK (sp[0].o);
fun = (void (*)()) rmeth->method->ncode;
}
goto perform_invoke;
#endif /* DIRECT_THREADED */
insn_invokestatic: insn_invokestatic:
SAVE_PC;
{ {
int index = get2u (pc); pc += 2; int index = GET2U ();
rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod; rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
...@@ -2142,16 +2812,29 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2142,16 +2812,29 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
_Jv_InitClass (rmeth->klass); _Jv_InitClass (rmeth->klass);
fun = (void (*)()) rmeth->method->ncode; fun = (void (*)()) rmeth->method->ncode;
#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 perform_invoke; goto perform_invoke;
insn_invokeinterface: #ifdef DIRECT_THREADED
SAVE_PC; invokestatic_resolved:
{ {
int index = get2u (pc); pc += 2; rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
fun = (void (*)()) rmeth->method->ncode;
}
goto perform_invoke;
#endif /* DIRECT_THREADED */
// invokeinterface has two unused bytes... insn_invokeinterface:
pc += 2; {
int index = GET2U ();
rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod; rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
...@@ -2165,25 +2848,62 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2165,25 +2848,62 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
_Jv_LookupInterfaceMethod (rcv->getClass (), _Jv_LookupInterfaceMethod (rcv->getClass (),
rmeth->method->name, rmeth->method->name,
rmeth->method->signature); rmeth->method->signature);
#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; goto perform_invoke;
#ifdef DIRECT_THREADED
invokeinterface_resolved:
{
rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
jobject rcv = sp[0].o;
NULLCHECK (rcv);
fun = (void (*)())
_Jv_LookupInterfaceMethod (rcv->getClass (),
rmeth->method->name,
rmeth->method->signature);
}
goto perform_invoke;
#endif /* DIRECT_THREADED */
insn_new: insn_new:
SAVE_PC;
{ {
int index = get2u (pc); pc += 2; int index = GET2U ();
jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz; jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
_Jv_InitClass (klass); _Jv_InitClass (klass);
jobject res = _Jv_AllocObject (klass, klass->size_in_bytes); jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
PUSHA (res); PUSHA (res);
#ifdef DIRECT_THREADED
pc[-2].insn = &&new_resolved;
pc[-1].datum = klass;
#endif /* DIRECT_THREADED */
} }
NEXT_INSN; NEXT_INSN;
#ifdef DIRECT_THREADED
new_resolved:
{
jclass klass = (jclass) AVAL ();
jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
PUSHA (res);
}
NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_newarray: insn_newarray:
SAVE_PC;
{ {
int atype = get1u (pc++); int atype = GET1U ();
int size = POPI(); int size = POPI();
jobject result = _Jv_NewArray (atype, size); jobject result = _Jv_NewArray (atype, size);
PUSHA (result); PUSHA (result);
...@@ -2191,17 +2911,32 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2191,17 +2911,32 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_anewarray: insn_anewarray:
SAVE_PC;
{ {
int index = get2u (pc); pc += 2; int index = GET2U ();
jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz; jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
int size = POPI(); int size = POPI();
_Jv_InitClass (klass); _Jv_InitClass (klass);
jobject result = _Jv_NewObjectArray (size, klass, 0); jobject result = _Jv_NewObjectArray (size, klass, 0);
PUSHA (result); PUSHA (result);
#ifdef DIRECT_THREADED
pc[-2].insn = &&anewarray_resolved;
pc[-1].datum = klass;
#endif /* DIRECT_THREADED */
} }
NEXT_INSN; NEXT_INSN;
#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: insn_arraylength:
{ {
__JArray *arr = (__JArray*)POPA(); __JArray *arr = (__JArray*)POPA();
...@@ -2211,7 +2946,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2211,7 +2946,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_athrow: insn_athrow:
SAVE_PC;
{ {
jobject value = POPA(); jobject value = POPA();
throw static_cast<jthrowable>(value); throw static_cast<jthrowable>(value);
...@@ -2219,33 +2953,60 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2219,33 +2953,60 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_checkcast: insn_checkcast:
SAVE_PC;
{ {
jobject value = POPA(); jobject value = POPA();
jint index = get2u (pc); pc += 2; jint index = GET2U ();
jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz; jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
if (value != NULL && ! to->isInstance (value)) if (value != NULL && ! to->isInstance (value))
{
throw 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 */
} }
NEXT_INSN;
#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); PUSHA (value);
} }
NEXT_INSN; NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_instanceof: insn_instanceof:
SAVE_PC;
{ {
jobject value = POPA(); jobject value = POPA();
jint index = get2u (pc); pc += 2; jint index = GET2U ();
jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz; jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
PUSHI (to->isInstance (value)); PUSHI (to->isInstance (value));
#ifdef DIRECT_THREADED
pc[-2].insn = &&instanceof_resolved;
pc[-1].datum = to;
#endif /* DIRECT_THREADED */
} }
NEXT_INSN; NEXT_INSN;
#ifdef DIRECT_THREADED
instanceof_resolved:
{
jobject value = POPA ();
jclass to = (jclass) AVAL ();
PUSHI (to->isInstance (value));
}
NEXT_INSN;
#endif /* DIRECT_THREADED */
insn_monitorenter: insn_monitorenter:
SAVE_PC;
{ {
jobject value = POPA(); jobject value = POPA();
NULLCHECK(value); NULLCHECK(value);
...@@ -2254,7 +3015,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2254,7 +3015,6 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
NEXT_INSN; NEXT_INSN;
insn_monitorexit: insn_monitorexit:
SAVE_PC;
{ {
jobject value = POPA(); jobject value = POPA();
NULLCHECK(value); NULLCHECK(value);
...@@ -2264,26 +3024,47 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2264,26 +3024,47 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
insn_ifnull: insn_ifnull:
{ {
unsigned char* base_pc = pc-1;
jint offset = get2s (pc); pc += 2;
jobject val = POPA(); jobject val = POPA();
if (val == NULL) if (val == NULL)
pc = base_pc+offset; TAKE_GOTO;
else
SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_ifnonnull: insn_ifnonnull:
{ {
unsigned char* base_pc = pc-1;
jint offset = get2s (pc); pc += 2;
jobject val = POPA(); jobject val = POPA();
if (val != NULL) if (val != NULL)
pc = base_pc+offset; TAKE_GOTO;
else
SKIP_GOTO;
} }
NEXT_INSN; NEXT_INSN;
insn_multianewarray:
{
int kind_index = GET2U ();
int dim = GET1U ();
jclass type
= (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
_Jv_InitClass (type);
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: insn_wide:
SAVE_PC;
{ {
jint the_mod_op = get1u (pc++); jint the_mod_op = get1u (pc++);
jint wide = get2u (pc); pc += 2; jint wide = get2u (pc); pc += 2;
...@@ -2343,48 +3124,51 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv) ...@@ -2343,48 +3124,51 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
} }
} }
#endif /* DIRECT_THREADED */
insn_multianewarray: }
SAVE_PC; catch (java::lang::Throwable *ex)
{ {
int kind_index = get2u (pc); pc += 2; #ifdef DIRECT_THREADED
int dim = get1u (pc); pc += 1; 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 ();
jclass type for (int i = 0; i < exc_count; i++)
= (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz; {
_Jv_InitClass (type); if (PCVAL (exc[i].start_pc) <= logical_pc
jint *sizes = (jint*) __builtin_alloca (sizeof (jint)*dim); && 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 */
for (int i = dim - 1; i >= 0; i--) if (handler == NULL || handler->isAssignableFrom (exc_class))
{ {
sizes[i] = POPI (); #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;
} }
jobject res = _Jv_NewMultiArray (type,dim, sizes);
PUSHA (res);
} }
NEXT_INSN;
insn_goto_w:
{
unsigned char* base_pc = pc-1;
int offset = get4 (pc); pc += 4;
pc = base_pc+offset;
} }
NEXT_INSN;
insn_jsr_w: // No handler, so re-throw.
{ throw ex;
unsigned char* base_pc = pc-1;
int offset = get4 (pc); pc += 4;
PUSHA((jobject)pc);
pc = base_pc+offset;
} }
NEXT_INSN;
} }
static void static void
throw_internal_error (char *msg) throw_internal_error (char *msg)
{ {
......
...@@ -338,7 +338,6 @@ private: ...@@ -338,7 +338,6 @@ private:
friend class _Jv_ClassReader; friend class _Jv_ClassReader;
friend class _Jv_InterpClass; friend class _Jv_InterpClass;
friend class _Jv_InterpMethod; friend class _Jv_InterpMethod;
friend class _Jv_InterpMethodInvocation;
#endif #endif
#ifdef JV_MARKOBJ_DECL #ifdef JV_MARKOBJ_DECL
......
...@@ -1882,18 +1882,18 @@ private: ...@@ -1882,18 +1882,18 @@ private:
// Verify exception handlers. // Verify exception handlers.
for (int i = 0; i < current_method->exc_count; ++i) for (int i = 0; i < current_method->exc_count; ++i)
{ {
if (! (flags[exception[i].handler_pc] & FLAG_INSN_START)) if (! (flags[exception[i].handler_pc.i] & FLAG_INSN_START))
verify_fail ("exception handler not at instruction start", verify_fail ("exception handler not at instruction start",
exception[i].handler_pc); exception[i].handler_pc.i);
if (! (flags[exception[i].start_pc] & FLAG_INSN_START)) if (! (flags[exception[i].start_pc.i] & FLAG_INSN_START))
verify_fail ("exception start not at instruction start", verify_fail ("exception start not at instruction start",
exception[i].start_pc); exception[i].start_pc.i);
if (exception[i].end_pc != current_method->code_length if (exception[i].end_pc.i != current_method->code_length
&& ! (flags[exception[i].end_pc] & FLAG_INSN_START)) && ! (flags[exception[i].end_pc.i] & FLAG_INSN_START))
verify_fail ("exception end not at instruction start", verify_fail ("exception end not at instruction start",
exception[i].end_pc); exception[i].end_pc.i);
flags[exception[i].handler_pc] |= FLAG_BRANCH_TARGET; flags[exception[i].handler_pc.i] |= FLAG_BRANCH_TARGET;
} }
} }
...@@ -2186,12 +2186,12 @@ private: ...@@ -2186,12 +2186,12 @@ private:
// through them all. // through them all.
for (int i = 0; i < current_method->exc_count; ++i) for (int i = 0; i < current_method->exc_count; ++i)
{ {
if (PC >= exception[i].start_pc && PC < exception[i].end_pc) if (PC >= exception[i].start_pc.i && PC < exception[i].end_pc.i)
{ {
type handler (&java::lang::Throwable::class$); type handler (&java::lang::Throwable::class$);
if (exception[i].handler_type != 0) if (exception[i].handler_type.i != 0)
handler = check_class_constant (exception[i].handler_type); handler = check_class_constant (exception[i].handler_type.i);
push_exception_jump (handler, exception[i].handler_pc); push_exception_jump (handler, exception[i].handler_pc.i);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment