OSDN Git Service

2006-07-13 Bryce McKinlay <mckinlay@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / interpret.cc
index 4db9dca..b9abb01 100644 (file)
@@ -1,6 +1,6 @@
 // interpret.cc - Code for the interpreter
 
-/* Copyright (C) 1999, 2000, 2001 , 2002 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -11,13 +11,13 @@ details.  */
 /* Author: Kresten Krab Thorup <krab@gnu.org>  */
 
 #include <config.h>
+#include <platform.h>
 
 #pragma implementation "java-interp.h"
 
 #include <jvm.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>
@@ -25,28 +25,52 @@ details.  */
 #include <java/lang/StringBuffer.h>
 #include <java/lang/Class.h>
 #include <java/lang/reflect/Modifier.h>
-#include <java/lang/ClassCastException.h>
-#include <java/lang/VirtualMachineError.h>
 #include <java/lang/InternalError.h>
 #include <java/lang/NullPointerException.h>
 #include <java/lang/ArithmeticException.h>
 #include <java/lang/IncompatibleClassChangeError.h>
+#include <java/lang/InstantiationException.h>
+#include <java/lang/Thread.h>
 #include <java-insns.h>
 #include <java-signal.h>
+#include <java/lang/ClassFormatError.h>
+#include <execution.h>
+#include <java/lang/reflect/Modifier.h>
 
 #ifdef INTERPRETER
 
+// Execution engine for interpreted code.
+_Jv_InterpreterEngine _Jv_soleInterpreterEngine;
+
 #include <stdlib.h>
 
 using namespace gcj;
 
-static void throw_internal_error (char *msg)
+static void throw_internal_error (const char *msg)
   __attribute__ ((__noreturn__));
 static void throw_incompatible_class_change_error (jstring msg)
   __attribute__ ((__noreturn__));
-#ifndef HANDLE_SEGV
 static void throw_null_pointer_exception ()
   __attribute__ ((__noreturn__));
+
+static void throw_class_format_error (jstring msg)
+       __attribute__ ((__noreturn__));
+static void throw_class_format_error (const char *msg)
+       __attribute__ ((__noreturn__));
+
+#ifdef DIRECT_THREADED
+// Lock to ensure that methods are not compiled concurrently.
+// We could use a finer-grained lock here, however it is not safe to use
+// the Class monitor as user code in another thread could hold it.
+static _Jv_Mutex_t compile_mutex;
+
+void
+_Jv_InitInterpreter()
+{
+  _Jv_MutexInit (&compile_mutex);
+}
+#else
+void _Jv_InitInterpreter() {}
 #endif
 
 extern "C" double __ieee754_fmod (double,double);
@@ -65,8 +89,7 @@ static inline void dupx (_Jv_word *sp, int n, int x)
     {
       sp[top-(n+x)-i] = sp[top-i];
     }
-  
-};
+}
 
 // Used to convert from floating types to integral types.
 template<typename TO, typename FROM>
@@ -196,15 +219,24 @@ static jint get4(unsigned char* loc) {
        | (((jint)(loc[3])) << 0);
 }
 
+#define SAVE_PC() frame_desc.pc = pc
+
+// We used to define this conditionally, depending on HANDLE_SEGV.
+// However, that runs into a problem if a chunk in low memory is
+// mapped and we try to look at a field near the end of a large
+// object.  See PR 26858 for details.  It is, most likely, relatively
+// inexpensive to simply do this check always.
+#define NULLCHECK(X) \
+  do { SAVE_PC(); if ((X)==NULL) throw_null_pointer_exception (); } while (0)
 
+// Note that we can still conditionally define NULLARRAYCHECK, since
+// we know that all uses of an array will first reference the length
+// field, which is first -- and thus will trigger a SEGV.
 #ifdef HANDLE_SEGV
-#define NULLCHECK(X) 
-#define NULLARRAYCHECK(X) do { SAVE_PC; } while (0)
+#define NULLARRAYCHECK(X) SAVE_PC()
 #else
-#define NULLCHECK(X) \
-  do { if ((X)==NULL) throw_null_pointer_exception (); } while (0)
 #define NULLARRAYCHECK(X) \
-  do { if ((X)==NULL) { SAVE_PC; throw_null_pointer_exception (); } } while (0)
+  do { SAVE_PC(); if ((X)==NULL) { throw_null_pointer_exception (); } } while (0)
 #endif
 
 #define ARRAYBOUNDSCHECK(array, index)                                       \
@@ -215,230 +247,581 @@ static jint get4(unsigned char* loc) {
     }                                                                        \
   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 least, that's the idea.
-  */
-  memcpy ((void*) locals, (void*) args, args_raw_size);
-
- next_segment:
-
-  jobject ex = NULL;
-
-  try
-    {
-      continue1 (inv);
-    }
-  catch (java::lang::Throwable *ex2)
-    {
-      ex = ex2;
-    }
-
-  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;
-         }
+  _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
+  run (ret, args, _this);
+}
 
-       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");
-       }
-    }
+void
+_Jv_InterpMethod::run_synch_object (ffi_cif *,
+                                   void* ret,
+                                   ffi_raw * args,
+                                   void* __this)
+{
+  _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
 
-  /** handle an exception */
-  if ( find_exception (ex, inv) )
-    goto next_segment;
+  jobject rcv = (jobject) args[0].ptr;
+  JvSynchronize mutex (rcv);
 
-  return ex;
+  run (ret, args, _this);
 }
 
-#define SAVE_PC   inv->pc = pc
-
-bool _Jv_InterpMethod::find_exception (jobject ex,
-                                      _Jv_InterpMethodInvocation *inv)
+void
+_Jv_InterpMethod::run_class (ffi_cif *,
+                            void* ret,
+                            ffi_raw * args,
+                            void* __this)
 {
-  // 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++)
-    {
-      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);
+  run (ret, args, _this);
 }
 
-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*) 
-    __builtin_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) throw static_cast<jthrowable>(ex);
+  run (ret, args, _this);
 }
 
-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;
+  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;
 
-  int storage_size = _this->max_stack+_this->max_locals;
-  _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
-    __builtin_alloca (sizeof (_Jv_InterpMethodInvocation)
-                     + storage_size * sizeof (_Jv_word));
+#define SET_ONE(Field, Value)                                                \
+  do                                                                         \
+    {                                                                        \
+      if (first_pass)                                                        \
+       ++next;                                                               \
+      else                                                                   \
+       insns[next++].Field = Value;                                          \
+    }                                                                        \
+  while (0)
 
-  _Jv_MonitorEnter (rcv);
-  jobject ex = _this->run (cif, ret, args, inv);
-  _Jv_MonitorExit (rcv);
+#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)
 
-  if (ex != 0) throw static_cast<jthrowable>(ex);
-}
+  // 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;
 
-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;
+  for (int i = 0; i < 2; ++i)
+    {
+      jboolean first_pass = i == 0;
+
+      if (! first_pass)
+       {
+         insns = (insn_slot *) _Jv_AllocBytes (sizeof (insn_slot) * next);
+         number_insn_slots = next;
+         next = 0;
+       }
 
-  int storage_size = _this->max_stack+_this->max_locals;
-  _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
-    __builtin_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) throw static_cast<jthrowable>(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;
+               // For an unresolved class we want to delay resolution
+               // until execution.
+               if (defining_class->constants.tags[index] == JV_CONSTANT_Class)
+                 {
+                   --next;
+                   SET_INSN (insn_targets[int (op_jsr_w) + 1]);
+                   SET_INT (index);
+                 }
+               else
+                 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;
+               // For an unresolved class we want to delay resolution
+               // until execution.
+               if (defining_class->constants.tags[index] == JV_CONSTANT_Class)
+                 {
+                   --next;
+                   SET_INSN (insn_targets[int (op_jsr_w) + 1]);
+                   SET_INT (index);
+                 }
+               else
+                 SET_DATUM (pool_data[index].o);
+             }
+             break;
+
+           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;
+
+           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;
+
+           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;
+
+           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;
 
-/*
-  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 inv->pc at all times, so we can figure
-  out which handler (if any) to invoke.
+           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;
+           }
+       }
+    }
 
-  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.  
-*/
+  // 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]];
+      // FIXME: resolve_pool_entry can throw - we shouldn't be doing this
+      // during compilation.
+      jclass handler
+       = (_Jv_Linker::resolve_pool_entry (defining_class,
+                                            exc[i].handler_type.i)).clazz;
+      exc[i].handler_type.p = handler;
+    }
 
+  // Translate entries in the LineNumberTable from bytecode PC's to direct
+  // threaded interpreter instruction values.
+  for (int i = 0; i < line_table_len; i++)
+    {
+      int byte_pc = line_table[i].bytecode_pc;
+      // It isn't worth throwing an exception if this table is
+      // corrupted, but at the same time we don't want a crash.
+      if (byte_pc < 0 || byte_pc >= code_length)
+       byte_pc = 0;
+      line_table[i].pc = &insns[pc_mapping[byte_pc]];
+    }  
+
+  prepared = insns;
+}
+#endif /* DIRECT_THREADED */
 
-void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
+/* Run the given method.
+   When args is NULL, don't run anything -- just compile it. */
+void
+_Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
 {
   using namespace java::lang::reflect;
 
-  _Jv_word      *sp     = inv->sp;
-  unsigned char *pc     = inv->pc;
-  _Jv_word               *locals = inv->local_base ();
+  // 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_InterpFrame frame_desc (meth, thread);
 
-  _Jv_word *pool_data   = defining_class->constants.data;
-  
-  /* these two are used in the invokeXXX instructions */
-  void (*fun)();
-  _Jv_ResolvedMethod* rmeth;
+  _Jv_word stack[meth->max_stack];
+  _Jv_word *sp = stack;
+
+  _Jv_word locals[meth->max_locals];
 
 #define INSN_LABEL(op) &&insn_##op
-#define GOTO_INSN(op) goto *(insn_target[op])
 
   static const void *const insn_target[] = 
   {
@@ -638,100 +1021,199 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
     INSN_LABEL(instanceof),
     INSN_LABEL(monitorenter),
     INSN_LABEL(monitorexit),
+#ifdef DIRECT_THREADED
+    0, // wide
+#else
     INSN_LABEL(wide),
+#endif
     INSN_LABEL(multianewarray),
     INSN_LABEL(ifnull),
     INSN_LABEL(ifnonnull),
     INSN_LABEL(goto_w),
     INSN_LABEL(jsr_w),
+#ifdef DIRECT_THREADED
+    INSN_LABEL (ldc_class)
+#else
+    0
+#endif
   };
 
-  /* If the macro INLINE_SWITCH is not defined, then the main loop
-     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.
+  pc_t pc;
 
-     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.  */
+#ifdef DIRECT_THREADED
 
-#define INLINE_SWITCH 
+#define NEXT_INSN goto *((pc++)->insn)
+#define INTVAL() ((pc++)->int_val)
+#define AVAL() ((pc++)->datum)
 
-#ifdef  INLINE_SWITCH
+#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. NOTE: Double-check locking.
+  if (meth->prepared == NULL)
+    {
+      _Jv_MutexLock (&compile_mutex);
+      if (meth->prepared == NULL)
+       meth->compile (insn_target);
+      _Jv_MutexUnlock (&compile_mutex);
+    }
 
-#define NEXT_INSN do { GOTO_INSN(*pc++); } while (0)
+  // If we're only compiling, stop here
+  if (args == NULL)
+    return;
 
+  pc = (insn_slot *) meth->prepared;
 
-  NEXT_INSN;
 #else
 
-#define NEXT_INSN goto next_insn
+#define NEXT_INSN goto *(insn_target[*pc++])
+
+#define GET1S() get1s (pc++)
+#define GET2S() (pc += 2, get2s (pc- 2))
+#define GET1U() get1u (pc++)
+#define GET2U() (pc += 2, get2u (pc - 2))
+  // Note that these could be more efficient when not handling 'ldc
+  // class'.
+#define AVAL1U()                                               \
+  ({ int index = get1u (pc++);                                 \
+      resolve_pool_entry (meth->defining_class, index).o; })
+#define AVAL2U()                                               \
+  ({ int index = get2u (pc); pc += 2;                          \
+      resolve_pool_entry (meth->defining_class, index).o; })
+  // Note that we don't need to resolve the pool entry here as class
+  // constants are never wide.
+#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
+
+  pc = bytecode ();
+
+#endif /* DIRECT_THREADED */
+
+#define TAKE_GOTO pc = GOTO_VAL ()
+
+  /* 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, meth->args_raw_size);
+
+  _Jv_word *pool_data = meth->defining_class->constants.data;
 
- next_insn:
-  GOTO_INSN (*pc++);
+  /* These three are temporaries for common code used by several
+     instructions.  */
+  void (*fun)();
+  _Jv_ResolvedMethod* rmeth;
+  int tmpval;
 
-#endif
+  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
-     frequency, in the hope that this will improve code locality a
-     little.  */
+      /* The first few instructions here are ordered according to their
+        frequency, in the hope that this will improve code locality a
+        little.  */
 
-     insn_aload_0:             // 0x2a
-      LOADA(0);
+    insn_aload_0:              // 0x2a
+      LOADA (0);
       NEXT_INSN;
 
-     insn_iload:               // 0x15
-      LOADI (get1u (pc++));
+    insn_iload:                // 0x15
+      LOADI (GET1U ());
       NEXT_INSN;
 
-     insn_iload_1:             // 0x1b
+    insn_iload_1:              // 0x1b
       LOADI (1);
       NEXT_INSN;
 
-     insn_invokevirtual:       // 0xb6
-      SAVE_PC;
+    insn_invokevirtual:        // 0xb6
       {
-       int index = get2u (pc); pc += 2;
+       SAVE_PC();
+       int index = GET2U ();
 
-       /* _Jv_ResolvePoolEntry returns immediately if the value already
-        * is resolved.  If we want to clutter up the code here to gain
-        * a little performance, then we can check the corresponding bit
-        * JV_CONSTANT_ResolvedFlag in the tag directly.  For now, I
-        * don't think it is worth it.  */
+       /* _Jv_Linker::resolve_pool_entry returns immediately if the
+        * value already is resolved.  If we want to clutter up the
+        * code here to gain a little performance, then we can check
+        * the corresponding bit JV_CONSTANT_ResolvedFlag in the tag
+        * directly.  For now, I don't think it is worth it.  */
 
-       rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
+       rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                  index)).rmethod;
 
        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)
+       if (rmeth->method->accflags & Modifier::FINAL)
+         {
+           // We can't rely on NULLCHECK working if the method is final.
+           if (! sp[0].o)
+             throw_null_pointer_exception ();
+
+           // Final methods might not appear in the vtable.
+           fun = (void (*)()) rmeth->method->ncode;
+         }
+       else
+         {
+           NULLCHECK (sp[0].o);
+           jobject rcv = sp[0].o;
+           _Jv_VTable *table = *(_Jv_VTable**) rcv;
+           fun = (void (*)()) table->get_method (rmeth->method->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:
+      {
+       SAVE_PC();
+       rmeth = (_Jv_ResolvedMethod *) AVAL ();
+       sp -= rmeth->stack_item_count;
+
+       if (rmeth->method->accflags & Modifier::FINAL)
          {
-           // final methods do not appear in the vtable,
-           // if it does not appear in the superclass.
+           // We can't rely on NULLCHECK working if the method is final.
+           if (! sp[0].o)
+             throw_null_pointer_exception ();
+
+           // Final methods might not appear in the vtable.
            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);
+           _Jv_VTable *table = *(_Jv_VTable**) rcv;
+           fun = (void (*)()) table->get_method (rmeth->method->index);
          }
       }
       goto perform_invoke;
+#endif /* DIRECT_THREADED */
 
-     perform_invoke:
+    perform_invoke:
       {
        /* here goes the magic again... */
        ffi_cif *cif = &rmeth->cif;
        ffi_raw *raw = (ffi_raw*) sp;
 
-       jdouble rvalue;
+       _Jv_value rvalue;
 
 #if FFI_NATIVE_RAW_API
        /* We assume that this is only implemented if it's correct      */
@@ -747,241 +1229,242 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
         * so those are checked before the switch */
        if (rtype == FFI_TYPE_POINTER)
          {
-           PUSHA (*(jobject*)&rvalue);
+           PUSHA (rvalue.object_value);
          }
        else if (rtype == FFI_TYPE_SINT32)
          {
-           PUSHI (*(jint*)&rvalue);
+           PUSHI (rvalue.int_value);
          }
        else if (rtype == FFI_TYPE_VOID)
          {
            /* skip */
          }
-       else switch (rtype) 
+       else
          {
-         case FFI_TYPE_SINT8:
-           {
-             jbyte value = (*(jint*)&rvalue) & 0xff;
-             PUSHI (value);
-           }
-           break;
+           switch (rtype)
+             {
+             case FFI_TYPE_SINT8:
+               PUSHI ((jbyte)(rvalue.int_value & 0xff));
+               break;
 
-         case FFI_TYPE_SINT16:
-           {
-             jshort value = (*(jint*)&rvalue) & 0xffff;
-             PUSHI (value);
-           }
-           break;
+             case FFI_TYPE_SINT16:
+               PUSHI ((jshort)(rvalue.int_value & 0xffff));
+               break;
 
-         case FFI_TYPE_UINT16:
-           {
-             jint value = (*(jint*)&rvalue) & 0xffff;
-             PUSHI (value);
-           }
-           break;
+             case FFI_TYPE_UINT16:
+               PUSHI (rvalue.int_value & 0xffff);
+               break;
 
-         case FFI_TYPE_FLOAT:
-           PUSHF (*(jfloat*)&rvalue);
-           break;
+             case FFI_TYPE_FLOAT:
+               PUSHF (rvalue.float_value);
+               break;
 
-         case FFI_TYPE_DOUBLE:
-           PUSHD (rvalue);
-           break;
+             case FFI_TYPE_DOUBLE:
+               PUSHD (rvalue.double_value);
+               break;
 
-         case FFI_TYPE_SINT64:
-           PUSHL (*(jlong*)&rvalue);
-           break;
+             case FFI_TYPE_SINT64:
+               PUSHL (rvalue.long_value);
+               break;
 
-         default:
-           throw_internal_error ("unknown return type in invokeXXX");
+             default:
+               throw_internal_error ("unknown return type in invokeXXX");
+             }
          }
-
       }
       NEXT_INSN;
 
-
-     insn_nop:
-      NEXT_INSN;
-
-     insn_aconst_null:
+    insn_aconst_null:
       PUSHA (NULL);
       NEXT_INSN;
 
-     insn_iconst_m1:
+    insn_iconst_m1:
       PUSHI (-1);
       NEXT_INSN;
 
-     insn_iconst_0:
+    insn_iconst_0:
       PUSHI (0);
       NEXT_INSN;
 
-     insn_iconst_1:
+    insn_iconst_1:
       PUSHI (1);
       NEXT_INSN;
 
-     insn_iconst_2:
+    insn_iconst_2:
       PUSHI (2);
       NEXT_INSN;
 
-     insn_iconst_3:
+    insn_iconst_3:
       PUSHI (3);
       NEXT_INSN;
 
-     insn_iconst_4:
+    insn_iconst_4:
       PUSHI (4);
       NEXT_INSN;
 
-     insn_iconst_5:
+    insn_iconst_5:
       PUSHI (5);
       NEXT_INSN;
 
-     insn_lconst_0:
+    insn_lconst_0:
       PUSHL (0);
       NEXT_INSN;
 
-     insn_lconst_1:
+    insn_lconst_1:
       PUSHL (1);
       NEXT_INSN;
 
-     insn_fconst_0:
+    insn_fconst_0:
       PUSHF (0);
       NEXT_INSN;
 
-     insn_fconst_1:
+    insn_fconst_1:
       PUSHF (1);
       NEXT_INSN;
 
-     insn_fconst_2:
+    insn_fconst_2:
       PUSHF (2);
       NEXT_INSN;
 
-     insn_dconst_0:
+    insn_dconst_0:
       PUSHD (0);
       NEXT_INSN;
 
-     insn_dconst_1:
+    insn_dconst_1:
       PUSHD (1);
       NEXT_INSN;
 
-     insn_bipush:
-      PUSHI (get1s(pc++));
+    insn_bipush:
+      // For direct threaded, bipush and sipush are the same.
+#ifndef DIRECT_THREADED
+      PUSHI (GET1S ());
       NEXT_INSN;
-
-     insn_sipush:
-      PUSHI (get2s(pc)); pc += 2;
+#endif /* DIRECT_THREADED */
+    insn_sipush:
+      PUSHI (GET2S ());
       NEXT_INSN;
 
-     insn_ldc:
-      {
-       int index = get1u (pc++);
-       PUSHA(pool_data[index].o);
-      }
+    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_ldc_w:
+#ifdef DIRECT_THREADED
+      // For direct threaded we have a separate 'ldc class' operation.
+    insn_ldc_class:
       {
-       int index = get2u (pc); pc += 2;
-       PUSHA(pool_data[index].o);
+       SAVE_PC();
+       // We could rewrite the instruction at this point.
+       int index = INTVAL ();
+       jobject k = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                    index)).o;
+       PUSHA (k);
       }
       NEXT_INSN;
+#endif /* DIRECT_THREADED */
 
-     insn_ldc2_w:
+    insn_ldc2_w:
       {
-       int index = get2u (pc); pc += 2;
-       memcpy (sp, &pool_data[index], 2*sizeof (_Jv_word));
+       void *where = AVAL2UP ();
+       memcpy (sp, where, 2*sizeof (_Jv_word));
        sp += 2;
       }
       NEXT_INSN;
 
-     insn_lload:
-      LOADL (get1u (pc++));
+    insn_lload:
+      LOADL (GET1U ());
       NEXT_INSN;
 
-     insn_fload:
-      LOADF (get1u (pc++));
+    insn_fload:
+      LOADF (GET1U ());
       NEXT_INSN;
 
-     insn_dload:
-      LOADD (get1u (pc++));
+    insn_dload:
+      LOADD (GET1U ());
       NEXT_INSN;
 
-     insn_aload:
-      LOADA (get1u (pc++));
+    insn_aload:
+      LOADA (GET1U ());
       NEXT_INSN;
 
-     insn_iload_0:
+    insn_iload_0:
       LOADI (0);
       NEXT_INSN;
 
-     insn_iload_2:
+    insn_iload_2:
       LOADI (2);
       NEXT_INSN;
 
-     insn_iload_3:
+    insn_iload_3:
       LOADI (3);
       NEXT_INSN;
 
-     insn_lload_0:
+    insn_lload_0:
       LOADL (0);
       NEXT_INSN;
 
-     insn_lload_1:
+    insn_lload_1:
       LOADL (1);
       NEXT_INSN;
 
-     insn_lload_2:
+    insn_lload_2:
       LOADL (2);
       NEXT_INSN;
 
-     insn_lload_3:
+    insn_lload_3:
       LOADL (3);
       NEXT_INSN;
 
-     insn_fload_0:
+    insn_fload_0:
       LOADF (0);
       NEXT_INSN;
 
-     insn_fload_1:
+    insn_fload_1:
       LOADF (1);
       NEXT_INSN;
 
-     insn_fload_2:
+    insn_fload_2:
       LOADF (2);
       NEXT_INSN;
 
-     insn_fload_3:
+    insn_fload_3:
       LOADF (3);
       NEXT_INSN;
 
-     insn_dload_0:
+    insn_dload_0:
       LOADD (0);
       NEXT_INSN;
 
-     insn_dload_1:
+    insn_dload_1:
       LOADD (1);
       NEXT_INSN;
 
-     insn_dload_2:
+    insn_dload_2:
       LOADD (2);
       NEXT_INSN;
 
-     insn_dload_3:
+    insn_dload_3:
       LOADD (3);
       NEXT_INSN;
 
-     insn_aload_1:
+    insn_aload_1:
       LOADA(1);
       NEXT_INSN;
 
-     insn_aload_2:
+    insn_aload_2:
       LOADA(2);
       NEXT_INSN;
 
-     insn_aload_3:
+    insn_aload_3:
       LOADA(3);
       NEXT_INSN;
 
-     insn_iaload:
+    insn_iaload:
       {
        jint index = POPI();
        jintArray arr = (jintArray) POPA();
@@ -991,7 +1474,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_laload:
+    insn_laload:
       {
        jint index = POPI();
        jlongArray arr = (jlongArray) POPA();
@@ -1001,7 +1484,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_faload:
+    insn_faload:
       {
        jint index = POPI();
        jfloatArray arr = (jfloatArray) POPA();
@@ -1011,7 +1494,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_daload:
+    insn_daload:
       {
        jint index = POPI();
        jdoubleArray arr = (jdoubleArray) POPA();
@@ -1021,7 +1504,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_aaload:
+    insn_aaload:
       {
        jint index = POPI();
        jobjectArray arr = (jobjectArray) POPA();
@@ -1031,7 +1514,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_baload:
+    insn_baload:
       {
        jint index = POPI();
        jbyteArray arr = (jbyteArray) POPA();
@@ -1041,7 +1524,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_caload:
+    insn_caload:
       {
        jint index = POPI();
        jcharArray arr = (jcharArray) POPA();
@@ -1051,7 +1534,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_saload:
+    insn_saload:
       {
        jint index = POPI();
        jshortArray arr = (jshortArray) POPA();
@@ -1061,107 +1544,107 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_istore:
-      STOREI (get1u (pc++));
+    insn_istore:
+      STOREI (GET1U ());
       NEXT_INSN;
 
-     insn_lstore:
-      STOREL (get1u (pc++));
+    insn_lstore:
+      STOREL (GET1U ());
       NEXT_INSN;
 
-     insn_fstore:
-      STOREF (get1u (pc++));
+    insn_fstore:
+      STOREF (GET1U ());
       NEXT_INSN;
 
-     insn_dstore:
-      STORED (get1u (pc++));
+    insn_dstore:
+      STORED (GET1U ());
       NEXT_INSN;
 
-     insn_astore:
-      STOREA (get1u (pc++));
+    insn_astore:
+      STOREA (GET1U ());
       NEXT_INSN;
 
-     insn_istore_0:
+    insn_istore_0:
       STOREI (0);
       NEXT_INSN;
 
-     insn_istore_1:
+    insn_istore_1:
       STOREI (1);
       NEXT_INSN;
 
-     insn_istore_2:
+    insn_istore_2:
       STOREI (2);
       NEXT_INSN;
 
-     insn_istore_3:
+    insn_istore_3:
       STOREI (3);
       NEXT_INSN;
 
-     insn_lstore_0:
+    insn_lstore_0:
       STOREL (0);
       NEXT_INSN;
 
-     insn_lstore_1:
+    insn_lstore_1:
       STOREL (1);
       NEXT_INSN;
 
-     insn_lstore_2:
+    insn_lstore_2:
       STOREL (2);
       NEXT_INSN;
 
-     insn_lstore_3:
+    insn_lstore_3:
       STOREL (3);
       NEXT_INSN;
 
-     insn_fstore_0:
+    insn_fstore_0:
       STOREF (0);
       NEXT_INSN;
 
-     insn_fstore_1:
+    insn_fstore_1:
       STOREF (1);
       NEXT_INSN;
 
-     insn_fstore_2:
+    insn_fstore_2:
       STOREF (2);
       NEXT_INSN;
 
-     insn_fstore_3:
+    insn_fstore_3:
       STOREF (3);
       NEXT_INSN;
 
-     insn_dstore_0:
+    insn_dstore_0:
       STORED (0);
       NEXT_INSN;
 
-     insn_dstore_1:
+    insn_dstore_1:
       STORED (1);
       NEXT_INSN;
 
-     insn_dstore_2:
+    insn_dstore_2:
       STORED (2);
       NEXT_INSN;
 
-     insn_dstore_3:
+    insn_dstore_3:
       STORED (3);
       NEXT_INSN;
 
-     insn_astore_0:
+    insn_astore_0:
       STOREA(0);
       NEXT_INSN;
 
-     insn_astore_1:
+    insn_astore_1:
       STOREA(1);
       NEXT_INSN;
 
-     insn_astore_2:
+    insn_astore_2:
       STOREA(2);
       NEXT_INSN;
 
-     insn_astore_3:
+    insn_astore_3:
       STOREA(3);
       NEXT_INSN;
 
-     insn_iastore:
+    insn_iastore:
       {
        jint value = POPI();
        jint index  = POPI();
@@ -1172,7 +1655,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_lastore:
+    insn_lastore:
       {
        jlong value = POPL();
        jint index  = POPI();
@@ -1183,7 +1666,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_fastore:
+    insn_fastore:
       {
        jfloat value = POPF();
        jint index  = POPI();
@@ -1194,7 +1677,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_dastore:
+    insn_dastore:
       {
        jdouble value = POPD();
        jint index  = POPI();
@@ -1205,7 +1688,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_aastore:
+    insn_aastore:
       {
        jobject value = POPA();
        jint index  = POPI();
@@ -1217,7 +1700,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_bastore:
+    insn_bastore:
       {
        jbyte value = (jbyte) POPI();
        jint index  = POPI();
@@ -1228,7 +1711,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_castore:
+    insn_castore:
       {
        jchar value = (jchar) POPI();
        jint index  = POPI();
@@ -1239,7 +1722,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_sastore:
+    insn_sastore:
       {
        jshort value = (jshort) POPI();
        jint index  = POPI();
@@ -1250,42 +1733,42 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_pop:
+    insn_pop:
       sp -= 1;
       NEXT_INSN;
 
-     insn_pop2:
+    insn_pop2:
       sp -= 2;
       NEXT_INSN;
 
-     insn_dup:
+    insn_dup:
       sp[0] = sp[-1];
       sp += 1;
       NEXT_INSN;
 
-     insn_dup_x1:
+    insn_dup_x1:
       dupx (sp, 1, 1); sp+=1;
       NEXT_INSN;
 
-     insn_dup_x2:
+    insn_dup_x2:
       dupx (sp, 1, 2); sp+=1;
       NEXT_INSN;
 
-     insn_dup2:
+    insn_dup2:
       sp[0] = sp[-2];
       sp[1] = sp[-1];
       sp += 2;
       NEXT_INSN;
 
-     insn_dup2_x1:
+    insn_dup2_x1:
       dupx (sp, 2, 1); sp+=2;
       NEXT_INSN;
 
-     insn_dup2_x2:
+    insn_dup2_x2:
       dupx (sp, 2, 2); sp+=2;
       NEXT_INSN;
 
-     insn_swap:
+    insn_swap:
       {
        jobject tmp1 = POPA();
        jobject tmp2 = POPA();
@@ -1294,57 +1777,57 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_iadd:
+    insn_iadd:
       BINOPI(+);
       NEXT_INSN;
 
-     insn_ladd:
+    insn_ladd:
       BINOPL(+);
       NEXT_INSN;
 
-     insn_fadd:
+    insn_fadd:
       BINOPF(+);
       NEXT_INSN;
 
-     insn_dadd:
+    insn_dadd:
       BINOPD(+);
       NEXT_INSN;
 
-     insn_isub:
+    insn_isub:
       BINOPI(-);
       NEXT_INSN;
 
-     insn_lsub:
+    insn_lsub:
       BINOPL(-);
       NEXT_INSN;
 
-     insn_fsub:
+    insn_fsub:
       BINOPF(-);
       NEXT_INSN;
 
-     insn_dsub:
+    insn_dsub:
       BINOPD(-);
       NEXT_INSN;
 
-     insn_imul:
+    insn_imul:
       BINOPI(*);
       NEXT_INSN;
 
-     insn_lmul:
+    insn_lmul:
       BINOPL(*);
       NEXT_INSN;
 
-     insn_fmul:
+    insn_fmul:
       BINOPF(*);
       NEXT_INSN;
 
-     insn_dmul:
+    insn_dmul:
       BINOPD(*);
       NEXT_INSN;
 
-     insn_idiv:
-      SAVE_PC;
+    insn_idiv:
       {
+       SAVE_PC();
        jint value2 = POPI();
        jint value1 = POPI();
        jint res = _Jv_divI (value1, value2);
@@ -1352,9 +1835,9 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_ldiv:
-      SAVE_PC;
+    insn_ldiv:
       {
+       SAVE_PC();
        jlong value2 = POPL();
        jlong value1 = POPL();
        jlong res = _Jv_divJ (value1, value2);
@@ -1362,8 +1845,9 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_fdiv:
+    insn_fdiv:
       {
+       SAVE_PC();
        jfloat value2 = POPF();
        jfloat value1 = POPF();
        jfloat res = value1 / value2;
@@ -1371,7 +1855,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_ddiv:
+    insn_ddiv:
       {
        jdouble value2 = POPD();
        jdouble value1 = POPD();
@@ -1380,9 +1864,9 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_irem:
-      SAVE_PC;
+    insn_irem:
       {
+       SAVE_PC();
        jint value2 = POPI();
        jint value1 =  POPI();
        jint res = _Jv_remI (value1, value2);
@@ -1390,9 +1874,9 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_lrem:
-      SAVE_PC;
+    insn_lrem:
       {
+       SAVE_PC();
        jlong value2 = POPL();
        jlong value1 = POPL();
        jlong res = _Jv_remJ (value1, value2);
@@ -1400,7 +1884,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_frem:
+    insn_frem:
       {
        jfloat value2 = POPF();
        jfloat value1 = POPF();
@@ -1409,7 +1893,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_drem:
+    insn_drem:
       {
        jdouble value2 = POPD();
        jdouble value1 = POPD();
@@ -1418,35 +1902,35 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_ineg:
+    insn_ineg:
       {
        jint value = POPI();
        PUSHI (value * -1);
       }
       NEXT_INSN;
 
-     insn_lneg:
+    insn_lneg:
       {
        jlong value = POPL();
        PUSHL (value * -1);
       }
       NEXT_INSN;
 
-     insn_fneg:
+    insn_fneg:
       {
        jfloat value = POPF();
        PUSHF (value * -1);
       }
       NEXT_INSN;
 
-     insn_dneg:
+    insn_dneg:
       {
        jdouble value = POPD();
        PUSHD (value * -1);
       }
       NEXT_INSN;
 
-     insn_ishl:
+    insn_ishl:
       {
        jint shift = (POPI() & 0x1f);
        jint value = POPI();
@@ -1454,7 +1938,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_lshl:
+    insn_lshl:
       {
        jint shift = (POPI() & 0x3f);
        jlong value = POPL();
@@ -1462,7 +1946,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_ishr:
+    insn_ishr:
       {
        jint shift = (POPI() & 0x1f);
        jint value = POPI();
@@ -1470,7 +1954,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_lshr:
+    insn_lshr:
       {
        jint shift = (POPI() & 0x3f);
        jlong value = POPL();
@@ -1478,79 +1962,79 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_iushr:
+    insn_iushr:
       {
        jint shift = (POPI() & 0x1f);
-       unsigned long value = POPI();
+       _Jv_uint value = (_Jv_uint) POPI();
        PUSHI ((jint) (value >> shift));
       }
       NEXT_INSN;
 
-     insn_lushr:
+    insn_lushr:
       {
        jint shift = (POPI() & 0x3f);
-       UINT64 value = (UINT64) POPL();
-       PUSHL ((value >> shift));
+       _Jv_ulong value = (_Jv_ulong) POPL();
+       PUSHL ((jlong) (value >> shift));
       }
       NEXT_INSN;
 
-     insn_iand:
+    insn_iand:
       BINOPI (&);
       NEXT_INSN;
 
-     insn_land:
+    insn_land:
       BINOPL (&);
       NEXT_INSN;
 
-     insn_ior:
+    insn_ior:
       BINOPI (|);
       NEXT_INSN;
 
-     insn_lor:
+    insn_lor:
       BINOPL (|);
       NEXT_INSN;
 
-     insn_ixor:
+    insn_ixor:
       BINOPI (^);
       NEXT_INSN;
 
-     insn_lxor:
+    insn_lxor:
       BINOPL (^);
       NEXT_INSN;
 
-     insn_iinc:
+    insn_iinc:
       {
-       jint index  = get1u (pc++);
-       jint amount = get1s (pc++);
+       jint index  = GET1U ();
+       jint amount = GET1S ();
        locals[index].i += amount;
       }
       NEXT_INSN;
 
-     insn_i2l:
+    insn_i2l:
       {jlong value = POPI(); PUSHL (value);}
       NEXT_INSN;
 
-     insn_i2f:
+    insn_i2f:
       {jfloat value = POPI(); PUSHF (value);}
       NEXT_INSN;
 
-     insn_i2d:
+    insn_i2d:
       {jdouble value = POPI(); PUSHD (value);}
       NEXT_INSN;
 
-     insn_l2i:
+    insn_l2i:
       {jint value = POPL(); PUSHI (value);}
       NEXT_INSN;
 
-     insn_l2f:
+    insn_l2f:
       {jfloat value = POPL(); PUSHF (value);}
       NEXT_INSN;
 
-     insn_l2d:
+    insn_l2d:
       {jdouble value = POPL(); PUSHD (value);}
       NEXT_INSN;
 
-     insn_f2i:
+    insn_f2i:
       {
        using namespace java::lang;
        jint value = convert (POPF (), Integer::MIN_VALUE, Integer::MAX_VALUE);
@@ -1558,7 +2042,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_f2l:
+    insn_f2l:
       {
        using namespace java::lang;
        jlong value = convert (POPF (), Long::MIN_VALUE, Long::MAX_VALUE);
@@ -1566,11 +2050,11 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_f2d:
+    insn_f2d:
       { jdouble value = POPF (); PUSHD(value); }
       NEXT_INSN;
 
-     insn_d2i:
+    insn_d2i:
       {
        using namespace java::lang;
        jint value = convert (POPD (), Integer::MIN_VALUE, Integer::MAX_VALUE);
@@ -1578,7 +2062,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_d2l:
+    insn_d2l:
       {
        using namespace java::lang;
        jlong value = convert (POPD (), Long::MIN_VALUE, Long::MAX_VALUE);
@@ -1586,23 +2070,23 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_d2f:
+    insn_d2f:
       { jfloat value = POPD (); PUSHF(value); }
       NEXT_INSN;
 
-     insn_i2b:
+    insn_i2b:
       { jbyte value = POPI (); PUSHI(value); }
       NEXT_INSN;
 
-     insn_i2c:
+    insn_i2c:
       { jchar value = POPI (); PUSHI(value); }
       NEXT_INSN;
 
-     insn_i2s:
+    insn_i2s:
       { jshort value = POPI (); PUSHI(value); }
       NEXT_INSN;
 
-     insn_lcmp:
+    insn_lcmp:
       {
        jlong value2 = POPL ();
        jlong value1 = POPL ();
@@ -1615,8 +2099,14 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_fcmpl:
-     insn_fcmpg:
+    insn_fcmpl:
+      tmpval = -1;
+      goto fcmp;
+
+    insn_fcmpg:
+      tmpval = 1;
+
+    fcmp:
       {
        jfloat value2 = POPF ();
        jfloat value1 = POPF ();
@@ -1626,15 +2116,19 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
          PUSHI (0);
        else if (value1 < value2)
          PUSHI (-1);
-       else if ((*(pc-1)) == op_fcmpg)
-         PUSHI (1);
        else
-         PUSHI (-1);
+         PUSHI (tmpval);
       }
       NEXT_INSN;
 
-     insn_dcmpl:
-     insn_dcmpg:
+    insn_dcmpl:
+      tmpval = -1;
+      goto dcmp;
+
+    insn_dcmpg:
+      tmpval = 1;
+
+    dcmp:
       {
        jdouble value2 = POPD ();
        jdouble value1 = POPD ();
@@ -1644,220 +2138,267 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
          PUSHI (0);
        else if (value1 < value2)
          PUSHI (-1);
-       else if ((*(pc-1)) == op_dcmpg)
-         PUSHI (1);
        else
-         PUSHI (-1);
+         PUSHI (tmpval);
       }
       NEXT_INSN;
 
-     insn_ifeq:
+    insn_ifeq:
       {
-       jint offset = get2s (pc); 
        if (POPI() == 0)
-         pc = pc-1+offset;
+         TAKE_GOTO;
        else
-         pc = pc+2;
+         SKIP_GOTO;
       }
       NEXT_INSN;
 
-     insn_ifne:
+    insn_ifne:
       {
-       jint offset = get2s (pc); 
        if (POPI() != 0)
-         pc = pc-1+offset;
+         TAKE_GOTO;
        else
-         pc = pc+2;
+         SKIP_GOTO;
       }
       NEXT_INSN;
 
-     insn_iflt:
+    insn_iflt:
       {
-       jint offset = get2s (pc); 
        if (POPI() < 0)
-         pc = pc-1+offset;
+         TAKE_GOTO;
        else
-         pc = pc+2;
+         SKIP_GOTO;
       }
       NEXT_INSN;
 
-     insn_ifge:
+    insn_ifge:
       {
-       jint offset = get2s (pc); 
        if (POPI() >= 0)
-         pc = pc-1+offset;
+         TAKE_GOTO;
        else
-         pc = pc+2;
+         SKIP_GOTO;
       }
       NEXT_INSN;
 
-     insn_ifgt:
+    insn_ifgt:
       {
-       jint offset = get2s (pc); 
        if (POPI() > 0)
-         pc = pc-1+offset;
+         TAKE_GOTO;
        else
-         pc = pc+2;
+         SKIP_GOTO;
       }
       NEXT_INSN;
 
-     insn_ifle:
+    insn_ifle:
       {
-       jint offset = get2s (pc); 
        if (POPI() <= 0)
-         pc = pc-1+offset;
+         TAKE_GOTO;
        else
-         pc = pc+2;
+         SKIP_GOTO;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_goto: 
+    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;
+
+    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;
       }
       NEXT_INSN;
-
-     insn_jsr:
+#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;
       }
       NEXT_INSN;
 
-     insn_ret:
+    insn_ret:
       {
-       jint index = get1u (pc);
-       pc = (unsigned char*) PEEKA (index);
+       jint index = GET1U ();
+       pc = (pc_t) PEEKA (index);
       }
       NEXT_INSN;
 
-     insn_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 low = INTVAL ();
+       jint high = INTVAL ();
 
-       jint def     = get4 (pc);
-       jint low     = get4 (pc+4);
-       jint high    = get4 (pc+8);
+       if (index < low || index > high)
+         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;    
+         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 */
       }
       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;
        int index = POPI();
 
        unsigned char* base = bytecode ();
        while ((pc-base) % 4 != 0)
-         pc++;
+         ++pc;
 
        jint def     = get4 (pc);
        jint npairs  = get4 (pc+4);
@@ -1865,7 +2406,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
        int max = npairs-1;
        int min = 0;
 
-       // simple binary search...
+       // Simple binary search...
        while (min < max)
          {
            int half = (min+max)/2;
@@ -1873,36 +2414,52 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
 
            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 */
       }
       NEXT_INSN;
 
-      /* on return, just save the sp and return to caller */
-     insn_ireturn:
-     insn_lreturn:
-     insn_freturn:
-     insn_dreturn:
-     insn_areturn:
-     insn_return:
-      inv->sp = sp;
+    insn_areturn:
+      *(jobject *) retp = POPA ();
+      return;
+
+    insn_lreturn:
+      *(jlong *) retp = POPL ();
+      return;
+
+    insn_freturn:
+      *(jfloat *) retp = POPF ();
       return;
 
-     insn_getstatic:
-      SAVE_PC;
+    insn_dreturn:
+      *(jdouble *) retp = POPD ();
+      return;
+
+    insn_ireturn:
+      *(jint *) retp = POPI ();
+      return;
+
+    insn_return:
+      return;
+
+    insn_getstatic:
       {
-       jint fieldref_index = get2u (pc); pc += 2;
-       _Jv_ResolvePoolEntry (defining_class, fieldref_index);
+       jint fieldref_index = GET2U ();
+        SAVE_PC(); // Constant pool resolution could throw.
+       _Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
        _Jv_Field *field = pool_data[fieldref_index].field;
 
        if ((field->flags & Modifier::STATIC) == 0)
@@ -1911,42 +2468,86 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
 
        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:
-               PUSHI (*(jbyte*) (field->u.addr));
+               PUSHI (*field->u.byte_addr);
+               newinsn = AMPAMP (getstatic_resolved_1);
                break;
 
              case 2:
                if (type == JvPrimClass (char))
-                 PUSHI(*(jchar*) (field->u.addr));
+                 {
+                   PUSHI (*field->u.char_addr);
+                   newinsn = AMPAMP (getstatic_resolved_char);
+                 }
                else
-                 PUSHI(*(jshort*) (field->u.addr));
+                 {
+                   PUSHI (*field->u.short_addr);
+                   newinsn = AMPAMP (getstatic_resolved_short);
+                 }
                break;
 
              case 4:
-               PUSHI(*(jint*) (field->u.addr));
+               PUSHI(*field->u.int_addr);
+               newinsn = AMPAMP (getstatic_resolved_4);
                break;
 
              case 8:
-               PUSHL(*(jlong*) (field->u.addr));
+               PUSHL(*field->u.long_addr);
+               newinsn = AMPAMP (getstatic_resolved_8);
                break;
              }
          }
        else
          {
-           PUSHA(*(jobject*) (field->u.addr));
+           PUSHA(*field->u.object_addr);
+           newinsn = AMPAMP (getstatic_resolved_obj);
          }
+
+#ifdef DIRECT_THREADED
+       pc[-2].insn = newinsn;
+       pc[-1].datum = field->u.addr;
+#endif /* DIRECT_THREADED */
       }
       NEXT_INSN;
 
-     insn_getfield:
-      SAVE_PC;
+#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:
       {
-       jint fieldref_index = get2u (pc); pc += 2;
-       _Jv_ResolvePoolEntry (defining_class, fieldref_index);
+       SAVE_PC();
+       jint fieldref_index = GET2U ();
+       _Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
        _Jv_Field *field = pool_data[fieldref_index].field;
 
        if ((field->flags & Modifier::STATIC) != 0)
@@ -1955,86 +2556,156 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
 
        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;
+       _Jv_value *val = (_Jv_value *) ((char *)obj + field_offset);
        if (type->isPrimitive ())
          {
            switch (type->size_in_bytes)
              {
              case 1:
-               PUSHI (*(jbyte*) ((char*)obj + field_offset));
+               PUSHI (val->byte_value);
+               newinsn = AMPAMP (getfield_resolved_1);
                break;
 
              case 2:
                if (type == JvPrimClass (char))
-                 PUSHI (*(jchar*) ((char*)obj + field_offset));
+                 {
+                   PUSHI (val->char_value);
+                   newinsn = AMPAMP (getfield_resolved_char);
+                 }
                else
-                 PUSHI (*(jshort*) ((char*)obj + field_offset));
+                 {
+                   PUSHI (val->short_value);
+                   newinsn = AMPAMP (getfield_resolved_short);
+                 }
                break;
 
              case 4:
-               PUSHI (*(jint*) ((char*)obj + field_offset));
+               PUSHI (val->int_value);
+               newinsn = AMPAMP (getfield_resolved_4);
                break;
 
              case 8:
-               PUSHL(*(jlong*) ((char*)obj + field_offset));
+               PUSHL (val->long_value);
+               newinsn = AMPAMP (getfield_resolved_8);
                break;
              }
          }
        else
          {
-           PUSHA(*(jobject*) ((char*)obj + field_offset));
+           PUSHA (val->object_value);
+           newinsn = AMPAMP (getfield_resolved_obj);
          }
+
+#ifdef DIRECT_THREADED
+       pc[-2].insn = newinsn;
+       pc[-1].int_val = field_offset;
+#endif /* DIRECT_THREADED */
       }
       NEXT_INSN;
 
-     insn_putstatic:
-      SAVE_PC;
+#ifdef DIRECT_THREADED
+    getfield_resolved_1:
       {
-       jint fieldref_index = get2u (pc); pc += 2;
-       _Jv_ResolvePoolEntry (defining_class, fieldref_index);
-       _Jv_Field *field = pool_data[fieldref_index].field;
+       char *obj = (char *) POPA ();
+       NULLCHECK (obj);
+       PUSHI (*(jbyte *) (obj + INTVAL ()));
+      }
+      NEXT_INSN;
 
-       jclass type = field->type;
+    getfield_resolved_char:
+      {
+       char *obj = (char *) POPA ();
+       NULLCHECK (obj);
+       PUSHI (*(jchar *) (obj + INTVAL ()));
+      }
+      NEXT_INSN;
 
-       // ResolvePoolEntry cannot check this
-       if ((field->flags & Modifier::STATIC) == 0)
-         throw_incompatible_class_change_error 
-           (JvNewStringLatin1 ("field no longer static"));
+    getfield_resolved_short:
+      {
+       char *obj = (char *) POPA ();
+       NULLCHECK (obj);
+       PUSHI (*(jshort *) (obj + INTVAL ()));
+      }
+      NEXT_INSN;
 
-       if (type->isPrimitive ())
-         {
-           switch (type->size_in_bytes) 
-             {
-             case 1:
-               {
+    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;
+#endif /* DIRECT_THREADED */
+
+    insn_putstatic:
+      {
+       SAVE_PC();
+       jint fieldref_index = GET2U ();
+       _Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
+       _Jv_Field *field = pool_data[fieldref_index].field;
+
+       jclass type = field->type;
+
+       // ResolvePoolEntry cannot check this
+       if ((field->flags & Modifier::STATIC) == 0)
+         throw_incompatible_class_change_error 
+           (JvNewStringLatin1 ("field no longer static"));
+
+       void *newinsn = NULL;
+       if (type->isPrimitive ())
+         {
+           switch (type->size_in_bytes) 
+             {
+             case 1:
+               {
                  jint value = POPI();
-                 *(jbyte*) (field->u.addr) = value;
+                 *field->u.byte_addr = value;
+                 newinsn = AMPAMP (putstatic_resolved_1);
                  break;
                }
 
              case 2:
                {
                  jint value = POPI();
-                 *(jchar*) (field->u.addr) = value;
+                 *field->u.char_addr = value;
+                 newinsn = AMPAMP (putstatic_resolved_2);
                  break;
                }
 
              case 4:
                {
                  jint value = POPI();
-                 *(jint*) (field->u.addr) = value;
+                 *field->u.int_addr = value;
+                 newinsn = AMPAMP (putstatic_resolved_4);
                  break;
                }
 
              case 8:
                {
                  jlong value = POPL();
-                 *(jlong*) (field->u.addr) = value;
+                 *field->u.long_addr = value;
+                 newinsn = AMPAMP (putstatic_resolved_8);
                  break;
                }
              }
@@ -2042,17 +2713,44 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
        else
          {
            jobject value = POPA();
-           *(jobject*) (field->u.addr) = value;
+           *field->u.object_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;
 
+#ifdef DIRECT_THREADED
+    putstatic_resolved_1:
+      *(jbyte *) AVAL () = POPI ();
+      NEXT_INSN;
+
+    putstatic_resolved_2:
+      *(jchar *) AVAL () = POPI ();
+      NEXT_INSN;
 
-     insn_putfield:
-      SAVE_PC;
+    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:
       {
-       jint fieldref_index = get2u (pc); pc += 2;
-       _Jv_ResolvePoolEntry (defining_class, fieldref_index);
+       SAVE_PC();
+       jint fieldref_index = GET2U ();
+       _Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
        _Jv_Field *field = pool_data[fieldref_index].field;
 
        jclass type = field->type;
@@ -2062,9 +2760,8 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
            (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) 
@@ -2075,6 +2772,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
                  jobject obj   = POPA();
                  NULLCHECK(obj);
                  *(jbyte*) ((char*)obj + field_offset) = value;
+                 newinsn = AMPAMP (putfield_resolved_1);
                  break;
                }
 
@@ -2084,6 +2782,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
                  jobject obj   = POPA();
                  NULLCHECK(obj);
                  *(jchar*) ((char*)obj + field_offset) = value;
+                 newinsn = AMPAMP (putfield_resolved_2);
                  break;
                }
 
@@ -2093,6 +2792,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
                  jobject obj   = POPA();
                  NULLCHECK(obj);
                  *(jint*) ((char*)obj + field_offset) = value;
+                 newinsn = AMPAMP (putfield_resolved_4);
                  break;
                }
 
@@ -2102,6 +2802,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
                  jobject obj   = POPA();
                  NULLCHECK(obj);
                  *(jlong*) ((char*)obj + field_offset) = value;
+                 newinsn = AMPAMP (putfield_resolved_8);
                  break;
                }
              }
@@ -2112,48 +2813,148 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
            jobject obj   = POPA();
            NULLCHECK(obj);
            *(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;
+
+#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;
 
-     insn_invokespecial:
-      SAVE_PC;
+    putfield_resolved_obj:
       {
-       int index = get2u (pc); pc += 2;
+       jobject val = POPA ();
+       char *obj = (char *) POPA ();
+       NULLCHECK (obj);
+       *(jobject *) (obj + INTVAL ()) = val;
+      }
+      NEXT_INSN;
+#endif /* DIRECT_THREADED */
 
-       rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
+    insn_invokespecial:
+      {
+       SAVE_PC();
+       int index = GET2U ();
+
+       rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                  index)).rmethod;
 
        sp -= rmeth->stack_item_count;
 
-       NULLCHECK (sp[0].o);
+       // 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)
+         {
+           SAVE_PC();
+           throw_null_pointer_exception ();
+         }
 
        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;
+
+#ifdef DIRECT_THREADED
+    invokespecial_resolved:
+      {
+       SAVE_PC();
+       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_null_pointer_exception ();
+         }
+       fun = (void (*)()) rmeth->method->ncode;
       }
       goto perform_invoke;
+#endif /* DIRECT_THREADED */
 
-     insn_invokestatic:
-      SAVE_PC;
+    insn_invokestatic:
       {
-       int index = get2u (pc); pc += 2;
+       SAVE_PC();
+       int index = GET2U ();
 
-       rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
+       rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                  index)).rmethod;
 
        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 = &&invokestatic_resolved;
+       pc[-1].datum = rmeth;
+#endif /* DIRECT_THREADED */
       }
       goto perform_invoke;
 
-     insn_invokeinterface:
-      SAVE_PC;
+#ifdef DIRECT_THREADED
+    invokestatic_resolved:
       {
-       int index = get2u (pc); pc += 2;
+       SAVE_PC();
+       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...
-       pc += 2;
+    insn_invokeinterface:
+      {
+       SAVE_PC();
+       int index = GET2U ();
 
-       rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
+       rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                  index)).rmethod;
 
        sp -= rmeth->stack_item_count;
 
@@ -2165,44 +2966,103 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
          _Jv_LookupInterfaceMethod (rcv->getClass (),
                                     rmeth->method->name,
                                     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;
 
+#ifdef DIRECT_THREADED
+    invokeinterface_resolved:
+      {
+       SAVE_PC();
+       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:
+      {
+       SAVE_PC();
+       int index = GET2U ();
+       jclass klass = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                         index)).clazz;
+       /* VM spec, section 3.11.5 */
+       if ((klass->getModifiers() & Modifier::ABSTRACT)
+           || klass->isInterface())
+         throw new java::lang::InstantiationException;
+       jobject res = _Jv_AllocObject (klass);
+       PUSHA (res);
+
+#ifdef DIRECT_THREADED
+       pc[-2].insn = &&new_resolved;
+       pc[-1].datum = klass;
+#endif /* DIRECT_THREADED */
+      }
+      NEXT_INSN;
 
-     insn_new:
-      SAVE_PC;
+#ifdef DIRECT_THREADED
+    new_resolved:
       {
-       int index = get2u (pc); pc += 2;
-       jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
-       _Jv_InitClass (klass);
-       jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
+       jclass klass = (jclass) AVAL ();
+       jobject res = _Jv_AllocObject (klass);
        PUSHA (res);
       }
       NEXT_INSN;
+#endif /* DIRECT_THREADED */
 
-     insn_newarray:
-      SAVE_PC;
+    insn_newarray:
       {
-       int atype = get1u (pc++);
+       int atype = GET1U ();
        int size  = POPI();
        jobject result = _Jv_NewArray (atype, size);
        PUSHA (result);
       }
       NEXT_INSN;
 
-     insn_anewarray:
-      SAVE_PC;
+    insn_anewarray:
       {
-       int index = get2u (pc); pc += 2;
-       jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
+       SAVE_PC();
+       int index = GET2U ();
+       jclass klass = (_Jv_Linker::resolve_pool_entry (meth->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 */
       }
       NEXT_INSN;
 
-     insn_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);
@@ -2210,42 +3070,71 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_athrow:
-      SAVE_PC;
+    insn_athrow:
       {
        jobject value = POPA();
        throw static_cast<jthrowable>(value);
       }
       NEXT_INSN;
 
-     insn_checkcast:
-      SAVE_PC;
+    insn_checkcast:
       {
+        SAVE_PC();
        jobject value = POPA();
-       jint index = get2u (pc); pc += 2;
-       jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
+       jint index = GET2U ();
+       jclass to = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+                                                      index)).clazz;
 
-       if (value != NULL && ! to->isInstance (value))
-         {
-           throw new java::lang::ClassCastException (to->getName());
-         }
+       value = (jobject) _Jv_CheckCast (to, value);
 
        PUSHA (value);
+
+#ifdef DIRECT_THREADED
+       pc[-2].insn = &&checkcast_resolved;
+       pc[-1].datum = to;
+#endif /* DIRECT_THREADED */
       }
       NEXT_INSN;
 
-     insn_instanceof:
-      SAVE_PC;
+#ifdef DIRECT_THREADED
+    checkcast_resolved:
       {
+        SAVE_PC();
+       jobject value = POPA ();
+       jclass to = (jclass) AVAL ();
+       value = (jobject) _Jv_CheckCast (to, value);
+       PUSHA (value);
+      }
+      NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
+    insn_instanceof:
+      {
+        SAVE_PC();
        jobject value = POPA();
-       jint index = get2u (pc); pc += 2;
-       jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
+       jint index = GET2U ();
+       jclass to = (_Jv_Linker::resolve_pool_entry (meth->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));
       }
       NEXT_INSN;
+#endif /* DIRECT_THREADED */
 
-     insn_monitorenter:
-      SAVE_PC;
+    insn_monitorenter:
       {
        jobject value = POPA();
        NULLCHECK(value);
@@ -2253,8 +3142,7 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_monitorexit:
-      SAVE_PC;
+    insn_monitorexit:
       {
        jobject value = POPA();
        NULLCHECK(value);
@@ -2262,28 +3150,50 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_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;
       }
       NEXT_INSN;
 
-     insn_wide:
-      SAVE_PC;
+    insn_multianewarray:
+      {
+       SAVE_PC();
+       int kind_index = GET2U ();
+       int dim        = GET1U ();
+
+       jclass type    
+         = (_Jv_Linker::resolve_pool_entry (meth->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;
@@ -2314,6 +3224,10 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
            LOADI (wide);
            NEXT_INSN;
 
+         case op_fload:
+           LOADF (wide);
+           NEXT_INSN;
+
          case op_aload:
            LOADA (wide);
            NEXT_INSN;
@@ -2343,70 +3257,721 @@ void _Jv_InterpMethod::continue1 (_Jv_InterpMethodInvocation *inv)
          }
 
       }
+#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 = meth->exceptions ();
+      jclass exc_class = ex->getClass ();
 
-     insn_multianewarray:
-      SAVE_PC;
-      {
-       int kind_index = get2u (pc); pc += 2;
-       int dim        = get1u (pc); pc += 1;
+      for (int i = 0; i < meth->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_Linker::resolve_pool_entry (defining_class,
+                                                            exc[i].handler_type.i)).clazz;
+#endif /* DIRECT_THREADED */
 
-       jclass type    
-         = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
-       _Jv_InitClass (type);
-       jint *sizes    = (jint*) __builtin_alloca (sizeof (jint)*dim);
+             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;
+               }
+           }
+       }
 
-       for (int i = dim - 1; i >= 0; i--)
-         {
-           sizes[i] = POPI ();
-         }
+      // No handler, so re-throw.
+      throw ex;
+    }
+}
 
-       jobject res    = _Jv_NewMultiArray (type,dim, sizes);
+static void
+throw_internal_error (const char *msg)
+{
+  throw new java::lang::InternalError (JvNewStringLatin1 (msg));
+}
 
-       PUSHA (res);
-      }
-      NEXT_INSN;
+static void 
+throw_incompatible_class_change_error (jstring msg)
+{
+  throw new java::lang::IncompatibleClassChangeError (msg);
+}
+
+static void 
+throw_null_pointer_exception ()
+{
+  throw new java::lang::NullPointerException;
+}
 
-     insn_goto_w:
+/* Look up source code line number for given bytecode (or direct threaded
+   interpreter) PC. */
+int
+_Jv_InterpMethod::get_source_line(pc_t mpc)
+{
+  int line = line_table_len > 0 ? line_table[0].line : -1;
+  for (int i = 1; i < line_table_len; i++)
+    if (line_table[i].pc > mpc)
+      break;
+    else
+      line = line_table[i].line;
+
+  return line;
+}
+
+/** Do static initialization for fields with a constant initializer */
+void
+_Jv_InitField (jobject obj, jclass klass, int index)
+{
+  using namespace java::lang::reflect;
+
+  if (obj != 0 && klass == 0)
+    klass = obj->getClass ();
+
+  if (!_Jv_IsInterpretedClass (klass))
+    return;
+
+  _Jv_InterpClass *iclass = (_Jv_InterpClass*)klass->aux_info;
+
+  _Jv_Field * field = (&klass->fields[0]) + index;
+
+  if (index > klass->field_count)
+    throw_internal_error ("field out of range");
+
+  int init = iclass->field_initializers[index];
+  if (init == 0)
+    return;
+
+  _Jv_Constants *pool = &klass->constants;
+  int tag = pool->tags[init];
+
+  if (! field->isResolved ())
+    throw_internal_error ("initializing unresolved field");
+
+  if (obj==0 && ((field->flags & Modifier::STATIC) == 0))
+    throw_internal_error ("initializing non-static field with no object");
+
+  void *addr = 0;
+
+  if ((field->flags & Modifier::STATIC) != 0)
+    addr = (void*) field->u.addr;
+  else
+    addr = (void*) (((char*)obj) + field->u.boffset);
+
+  switch (tag)
+    {
+    case JV_CONSTANT_String:
       {
-       unsigned char* base_pc = pc-1;
-       int offset = get4 (pc); pc += 4;
-       pc = base_pc+offset;
+       jstring str;
+       str = _Jv_NewStringUtf8Const (pool->data[init].utf8);
+       pool->data[init].string = str;
+       pool->tags[init] = JV_CONSTANT_ResolvedString;
       }
-      NEXT_INSN;
+      /* fall through */
 
-     insn_jsr_w:
+    case JV_CONSTANT_ResolvedString:
+      if (! (field->type == &java::lang::String::class$
+            || field->type == &java::lang::Class::class$))
+       throw_class_format_error ("string initialiser to non-string field");
+
+      *(jstring*)addr = pool->data[init].string;
+      break;
+
+    case JV_CONSTANT_Integer:
       {
-       unsigned char* base_pc = pc-1;
-       int offset = get4 (pc); pc += 4;
-       PUSHA((jobject)pc);
-       pc = base_pc+offset;
-      }
-      NEXT_INSN;
+       int value = pool->data[init].i;
+
+       if (field->type == JvPrimClass (boolean))
+         *(jboolean*)addr = (jboolean)value;
+       
+       else if (field->type == JvPrimClass (byte))
+         *(jbyte*)addr = (jbyte)value;
+       
+       else if (field->type == JvPrimClass (char))
+         *(jchar*)addr = (jchar)value;
+
+       else if (field->type == JvPrimClass (short))
+         *(jshort*)addr = (jshort)value;
+       
+       else if (field->type == JvPrimClass (int))
+         *(jint*)addr = (jint)value;
+
+       else
+         throw_class_format_error ("erroneous field initializer");
+      }  
+      break;
+
+    case JV_CONSTANT_Long:
+      if (field->type != JvPrimClass (long))
+       throw_class_format_error ("erroneous field initializer");
+
+      *(jlong*)addr = _Jv_loadLong (&pool->data[init]);
+      break;
+
+    case JV_CONSTANT_Float:
+      if (field->type != JvPrimClass (float))
+       throw_class_format_error ("erroneous field initializer");
+
+      *(jfloat*)addr = pool->data[init].f;
+      break;
+
+    case JV_CONSTANT_Double:
+      if (field->type != JvPrimClass (double))
+       throw_class_format_error ("erroneous field initializer");
+
+      *(jdouble*)addr = _Jv_loadDouble (&pool->data[init]);
+      break;
+
+    default:
+      throw_class_format_error ("erroneous field initializer");
+    }
 }
 
+inline static unsigned char*
+skip_one_type (unsigned char* ptr)
+{
+  int ch = *ptr++;
 
-static void
-throw_internal_error (char *msg)
+  while (ch == '[')
+    { 
+      ch = *ptr++;
+    }
+  
+  if (ch == 'L')
+    {
+      do { ch = *ptr++; } while (ch != ';');
+    }
+
+  return ptr;
+}
+
+static ffi_type*
+get_ffi_type_from_signature (unsigned char* ptr)
 {
-  throw new java::lang::InternalError (JvNewStringLatin1 (msg));
+  switch (*ptr) 
+    {
+    case 'L':
+    case '[':
+      return &ffi_type_pointer;
+      break;
+
+    case 'Z':
+      // On some platforms a bool is a byte, on others an int.
+      if (sizeof (jboolean) == sizeof (jbyte))
+       return &ffi_type_sint8;
+      else
+       {
+         JvAssert (sizeof (jbyte) == sizeof (jint));
+         return &ffi_type_sint32;
+       }
+      break;
+
+    case 'B':
+      return &ffi_type_sint8;
+      break;
+      
+    case 'C':
+      return &ffi_type_uint16;
+      break;
+         
+    case 'S': 
+      return &ffi_type_sint16;
+      break;
+         
+    case 'I':
+      return &ffi_type_sint32;
+      break;
+         
+    case 'J':
+      return &ffi_type_sint64;
+      break;
+         
+    case 'F':
+      return &ffi_type_float;
+      break;
+         
+    case 'D':
+      return &ffi_type_double;
+      break;
+
+    case 'V':
+      return &ffi_type_void;
+      break;
+    }
+
+  throw_internal_error ("unknown type in signature");
 }
 
-static void 
-throw_incompatible_class_change_error (jstring msg)
+/* this function yields the number of actual arguments, that is, if the
+ * function is non-static, then one is added to the number of elements
+ * found in the signature */
+
+int 
+_Jv_count_arguments (_Jv_Utf8Const *signature,
+                    jboolean staticp)
 {
-  throw new java::lang::IncompatibleClassChangeError (msg);
+  unsigned char *ptr = (unsigned char*) signature->chars();
+  int arg_count = staticp ? 0 : 1;
+
+  /* first, count number of arguments */
+
+  // skip '('
+  ptr++;
+
+  // count args
+  while (*ptr != ')')
+    {
+      ptr = skip_one_type (ptr);
+      arg_count += 1;
+    }
+
+  return arg_count;
 }
 
-#ifndef HANDLE_SEGV
-static java::lang::NullPointerException *null_pointer_exc;
-static void 
-throw_null_pointer_exception ()
+/* This beast will build a cif, given the signature.  Memory for
+ * the cif itself and for the argument types must be allocated by the
+ * caller.
+ */
+
+static int 
+init_cif (_Jv_Utf8Const* signature,
+         int arg_count,
+         jboolean staticp,
+         ffi_cif *cif,
+         ffi_type **arg_types,
+         ffi_type **rtype_p)
 {
-  if (null_pointer_exc == NULL)
-    null_pointer_exc = new java::lang::NullPointerException;
+  unsigned char *ptr = (unsigned char*) signature->chars();
 
-  throw null_pointer_exc;
+  int arg_index = 0;           // arg number
+  int item_count = 0;          // stack-item count
+
+  // setup receiver
+  if (!staticp)
+    {
+      arg_types[arg_index++] = &ffi_type_pointer;
+      item_count += 1;
+    }
+
+  // skip '('
+  ptr++;
+
+  // assign arg types
+  while (*ptr != ')')
+    {
+      arg_types[arg_index++] = get_ffi_type_from_signature (ptr);
+
+      if (*ptr == 'J' || *ptr == 'D')
+       item_count += 2;
+      else
+       item_count += 1;
+
+      ptr = skip_one_type (ptr);
+    }
+
+  // skip ')'
+  ptr++;
+  ffi_type *rtype = get_ffi_type_from_signature (ptr);
+
+  ptr = skip_one_type (ptr);
+  if (ptr != (unsigned char*)signature->chars() + signature->len())
+    throw_internal_error ("did not find end of signature");
+
+  if (ffi_prep_cif (cif, FFI_DEFAULT_ABI,
+                   arg_count, rtype, arg_types) != FFI_OK)
+    throw_internal_error ("ffi_prep_cif failed");
+
+  if (rtype_p != NULL)
+    *rtype_p = rtype;
+
+  return item_count;
 }
+
+#if FFI_NATIVE_RAW_API
+#   define FFI_PREP_RAW_CLOSURE ffi_prep_raw_closure
+#   define FFI_RAW_SIZE ffi_raw_size
+#else
+#   define FFI_PREP_RAW_CLOSURE ffi_prep_java_raw_closure
+#   define FFI_RAW_SIZE ffi_java_raw_size
 #endif
 
+/* we put this one here, and not in interpret.cc because it
+ * calls the utility routines _Jv_count_arguments 
+ * which are static to this module.  The following struct defines the
+ * layout we use for the stubs, it's only used in the ncode method. */
+
+typedef struct {
+  ffi_raw_closure  closure;
+  ffi_cif   cif;
+  ffi_type *arg_types[0];
+} ncode_closure;
+
+typedef void (*ffi_closure_fun) (ffi_cif*,void*,ffi_raw*,void*);
+
+void *
+_Jv_InterpMethod::ncode ()
+{
+  using namespace java::lang::reflect;
+
+  if (self->ncode != 0)
+    return self->ncode;
+
+  jboolean staticp = (self->accflags & Modifier::STATIC) != 0;
+  int arg_count = _Jv_count_arguments (self->signature, staticp);
+
+  ncode_closure *closure =
+    (ncode_closure*)_Jv_AllocBytes (sizeof (ncode_closure)
+                                       + arg_count * sizeof (ffi_type*));
+
+  init_cif (self->signature,
+           arg_count,
+           staticp,
+           &closure->cif,
+           &closure->arg_types[0],
+           NULL);
+
+  ffi_closure_fun fun;
+
+  args_raw_size = FFI_RAW_SIZE (&closure->cif);
+
+  JvAssert ((self->accflags & Modifier::NATIVE) == 0);
+
+  if ((self->accflags & Modifier::SYNCHRONIZED) != 0)
+    {
+      if (staticp)
+       fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_class;
+      else
+       fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_object; 
+    }
+  else
+    {
+      if (staticp)
+       fun = (ffi_closure_fun)&_Jv_InterpMethod::run_class;
+      else
+       fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal;
+    }
+
+  FFI_PREP_RAW_CLOSURE (&closure->closure,
+                       &closure->cif, 
+                       fun,
+                       (void*)this);
+
+  self->ncode = (void*)closure;
+  return self->ncode;
+}
+
+#ifdef DIRECT_THREADED
+/* Find the index of the given insn in the array of insn slots
+   for this method. Returns -1 if not found. */
+jlong
+_Jv_InterpMethod::insn_index (pc_t pc)
+{
+  jlong left = 0;
+  jlong right = number_insn_slots;
+  insn_slot* slots = reinterpret_cast<insn_slot*> (prepared);
+
+  while (right >= 0)
+    {
+      jlong mid = (left + right) / 2;
+      if (&slots[mid] == pc)
+       return mid;
+
+      if (pc < &slots[mid])
+       right = mid - 1;
+      else
+        left = mid + 1;
+    }
+
+  return -1;
+}
+#endif // DIRECT_THREADED
+
+void
+_Jv_InterpMethod::get_line_table (jlong& start, jlong& end,
+                                 jintArray& line_numbers,
+                                 jlongArray& code_indices)
+{
+#ifdef DIRECT_THREADED
+  /* For the DIRECT_THREADED case, if the method has not yet been
+   * compiled, the linetable will change to insn slots instead of
+   * bytecode PCs. It is probably easiest, in this case, to simply
+   * compile the method and guarantee that we are using insn
+   * slots.
+   */
+  _Jv_CompileMethod (this);
+
+  if (line_table_len > 0)
+    {
+      start = 0;
+      end = number_insn_slots;
+      line_numbers = JvNewIntArray (line_table_len);
+      code_indices = JvNewLongArray (line_table_len);
+
+      jint* lines = elements (line_numbers);
+      jlong* indices = elements (code_indices);
+      for (int i = 0; i < line_table_len; ++i)
+       {
+         lines[i] = line_table[i].line;
+         indices[i] = insn_index (line_table[i].pc);
+       }
+    }
+#else // !DIRECT_THREADED
+  if (line_table_len > 0)
+    {
+      start = 0;
+      end = code_length;
+      line_numbers = JvNewIntArray (line_table_len);
+      code_indices = JvNewLongArray (line_table_len);
+
+      jint* lines = elements (line_numbers);
+      jlong* indices = elements (code_indices);
+      for (int i = 0; i < line_table_len; ++i)
+       {
+         lines[i] = line_table[i].line;
+         indices[i] = (jlong) line_table[i].bytecode_pc;
+       }
+    }
+#endif // !DIRECT_THREADED
+}
+
+void *
+_Jv_JNIMethod::ncode ()
+{
+  using namespace java::lang::reflect;
+
+  if (self->ncode != 0)
+    return self->ncode;
+
+  jboolean staticp = (self->accflags & Modifier::STATIC) != 0;
+  int arg_count = _Jv_count_arguments (self->signature, staticp);
+
+  ncode_closure *closure =
+    (ncode_closure*)_Jv_AllocBytes (sizeof (ncode_closure)
+                                   + arg_count * sizeof (ffi_type*));
+
+  ffi_type *rtype;
+  init_cif (self->signature,
+           arg_count,
+           staticp,
+           &closure->cif,
+           &closure->arg_types[0],
+           &rtype);
+
+  ffi_closure_fun fun;
+
+  args_raw_size = FFI_RAW_SIZE (&closure->cif);
+
+  // Initialize the argument types and CIF that represent the actual
+  // underlying JNI function.
+  int extra_args = 1;
+  if ((self->accflags & Modifier::STATIC))
+    ++extra_args;
+  jni_arg_types = (ffi_type **) _Jv_AllocBytes ((extra_args + arg_count)
+                                               * sizeof (ffi_type *));
+  int offset = 0;
+  jni_arg_types[offset++] = &ffi_type_pointer;
+  if ((self->accflags & Modifier::STATIC))
+    jni_arg_types[offset++] = &ffi_type_pointer;
+  memcpy (&jni_arg_types[offset], &closure->arg_types[0],
+         arg_count * sizeof (ffi_type *));
+
+  if (ffi_prep_cif (&jni_cif, _Jv_platform_ffi_abi,
+                   extra_args + arg_count, rtype,
+                   jni_arg_types) != FFI_OK)
+    throw_internal_error ("ffi_prep_cif failed for JNI function");
+
+  JvAssert ((self->accflags & Modifier::NATIVE) != 0);
+
+  // FIXME: for now we assume that all native methods for
+  // interpreted code use JNI.
+  fun = (ffi_closure_fun) &_Jv_JNIMethod::call;
+
+  FFI_PREP_RAW_CLOSURE (&closure->closure,
+                       &closure->cif, 
+                       fun,
+                       (void*) this);
+
+  self->ncode = (void *) closure;
+  return self->ncode;
+}
+
+static void
+throw_class_format_error (jstring msg)
+{
+  throw (msg
+        ? new java::lang::ClassFormatError (msg)
+        : new java::lang::ClassFormatError);
+}
+
+static void
+throw_class_format_error (const char *msg)
+{
+  throw_class_format_error (JvNewStringLatin1 (msg));
+}
+
+\f
+
+void
+_Jv_InterpreterEngine::do_verify (jclass klass)
+{
+  _Jv_InterpClass *iclass = (_Jv_InterpClass *) klass->aux_info;
+  for (int i = 0; i < klass->method_count; i++)
+    {
+      using namespace java::lang::reflect;
+      _Jv_MethodBase *imeth = iclass->interpreted_methods[i];
+      _Jv_ushort accflags = klass->methods[i].accflags;
+      if ((accflags & (Modifier::NATIVE | Modifier::ABSTRACT)) == 0)
+       {
+         _Jv_InterpMethod *im = reinterpret_cast<_Jv_InterpMethod *> (imeth);
+         _Jv_VerifyMethod (im);
+       }
+    }
+}
+
+void
+_Jv_InterpreterEngine::do_create_ncode (jclass klass)
+{
+  _Jv_InterpClass *iclass = (_Jv_InterpClass *) klass->aux_info;
+  for (int i = 0; i < klass->method_count; i++)
+    {
+      // Just skip abstract methods.  This is particularly important
+      // because we don't resize the interpreted_methods array when
+      // miranda methods are added to it.
+      if ((klass->methods[i].accflags
+          & java::lang::reflect::Modifier::ABSTRACT)
+         != 0)
+       continue;
+
+      _Jv_MethodBase *imeth = iclass->interpreted_methods[i];
+
+      if ((klass->methods[i].accflags & java::lang::reflect::Modifier::NATIVE)
+         != 0)
+       {
+         // You might think we could use a virtual `ncode' method in
+         // the _Jv_MethodBase and unify the native and non-native
+         // cases.  Well, we can't, because we don't allocate these
+         // objects using `new', and thus they don't get a vtable.
+         _Jv_JNIMethod *jnim = reinterpret_cast<_Jv_JNIMethod *> (imeth);
+         klass->methods[i].ncode = jnim->ncode ();
+       }
+      else if (imeth != 0)             // it could be abstract
+       {
+         _Jv_InterpMethod *im = reinterpret_cast<_Jv_InterpMethod *> (imeth);
+         klass->methods[i].ncode = im->ncode ();
+       }
+    }
+}
+
+void
+_Jv_InterpreterEngine::do_allocate_static_fields (jclass klass,
+                                                 int pointer_size,
+                                                 int other_size)
+{
+  _Jv_InterpClass *iclass = (_Jv_InterpClass *) klass->aux_info;
+
+  // Splitting the allocations here lets us scan reference fields and
+  // avoid scanning non-reference fields.  How reference fields are
+  // scanned is a bit tricky: we allocate using _Jv_AllocRawObj, which
+  // means that this memory will be scanned conservatively (same
+  // difference, since we know all the contents here are pointers).
+  // Then we put pointers into this memory into the 'fields'
+  // structure.  Most of these are interior pointers, which is ok (but
+  // even so the pointer to the first reference field will be used and
+  // that is not an interior pointer).  The 'fields' array is also
+  // allocated with _Jv_AllocRawObj (see defineclass.cc), so it will
+  // be scanned.  A pointer to this array is held by Class and thus
+  // seen by the collector.
+  char *reference_fields = (char *) _Jv_AllocRawObj (pointer_size);
+  char *non_reference_fields = (char *) _Jv_AllocBytes (other_size);
+
+  for (int i = 0; i < klass->field_count; i++)
+    {
+      _Jv_Field *field = &klass->fields[i];
+
+      if ((field->flags & java::lang::reflect::Modifier::STATIC) == 0)
+       continue;
+
+      char *base = field->isRef() ? reference_fields : non_reference_fields;
+      field->u.addr  = base + field->u.boffset;
+
+      if (iclass->field_initializers[i] != 0)
+       {
+         _Jv_Linker::resolve_field (field, klass->loader);
+         _Jv_InitField (0, klass, i);
+       }
+    }
+
+  // Now we don't need the field_initializers anymore, so let the
+  // collector get rid of it.
+  iclass->field_initializers = 0;
+}
+
+_Jv_ResolvedMethod *
+_Jv_InterpreterEngine::do_resolve_method (_Jv_Method *method, jclass klass,
+                                         jboolean staticp)
+{
+  int arg_count = _Jv_count_arguments (method->signature, staticp);
+
+  _Jv_ResolvedMethod* result = (_Jv_ResolvedMethod*)
+    _Jv_AllocBytes (sizeof (_Jv_ResolvedMethod)
+                   + arg_count*sizeof (ffi_type*));
+
+  result->stack_item_count
+    = init_cif (method->signature,
+               arg_count,
+               staticp,
+               &result->cif,
+               &result->arg_types[0],
+               NULL);
+
+  result->method              = method;
+  result->klass               = klass;
+
+  return result;
+}
+
+void
+_Jv_InterpreterEngine::do_post_miranda_hook (jclass klass)
+{
+  _Jv_InterpClass *iclass = (_Jv_InterpClass *) klass->aux_info;
+  for (int i = 0; i < klass->method_count; i++)
+    {
+      // Just skip abstract methods.  This is particularly important
+      // because we don't resize the interpreted_methods array when
+      // miranda methods are added to it.
+      if ((klass->methods[i].accflags
+          & java::lang::reflect::Modifier::ABSTRACT)
+         != 0)
+       continue;
+      // Miranda method additions mean that the `methods' array moves.
+      // We cache a pointer into this array, so we have to update.
+      iclass->interpreted_methods[i]->self = &klass->methods[i];
+    }
+}
+
+#ifdef DIRECT_THREADED
+void
+_Jv_CompileMethod (_Jv_InterpMethod* method)
+{
+  if (method->prepared == NULL)
+    _Jv_InterpMethod::run (NULL, NULL, method);
+}
+#endif // DIRECT_THREADED
+
 #endif // INTERPRETER