* src/mm/memory.cpp,
[cacao.git] / src / vm / jit / intrp / engine.c
index 66324bdf14fab6bf4712da18554dd2323331c192..118883f720c09c21215ae8d55979395389073968 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/intrp/engine.c - #included by engine1.c and engine2.c
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Christian Thalinger
-            Anton Ertl
-
-   Changes:
-
-   $Id: engine.c 4139 2006-01-11 12:16:57Z twisti $
 */
 
 
 /* #define VM_DEBUG */
-#define USE_spTOS
 
 #include "config.h"
 
 #include <assert.h>
 
+#include "vm/types.h"
+
 #include "arch.h"
+
 #include "vm/jit/intrp/intrp.h"
 
 #include "md-abi.h"                           /* required for TRACE_ARGS_NUM */
 
-#include "cacao/cacao.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/loader.h"
+#include "mm/memory.hpp"
+
+#include "threads/thread.hpp"
+
+#include "vm/jit/builtin.hpp"
+#include "vm/loader.hpp"
 #include "vm/options.h"
+
 #include "vm/jit/methodheader.h"
 #include "vm/jit/patcher.h"
+#include "vm/jit/stacktrace.hpp"
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-# ifndef USE_MD_THREAD_STUFF
-#  include "machine-instr.h"
-# else
-#  include "threads/native/generic-primitives.h"
-# endif
+
+#if defined(ENABLE_THREADS)
+# include "threads/atomic.hpp"
 #endif
 
-#if !defined(STORE_ORDER_BARRIER) && !defined(USE_THREADS)
+#if !defined(STORE_ORDER_BARRIER) && !defined(ENABLE_THREADS)
 #define STORE_ORDER_BARRIER() /* nothing */
 #endif
 
 #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;})
 #define IPTOS NEXT_INST
 
+#if defined(__POWERPC__) || defined(__POWERPC64__) || defined(__SPARC__)
+# define USE_spTOS
+#endif
+
 #if defined(USE_spTOS)
 #define IF_spTOS(x) x
 #else
            } \
        }
 
+#define THROW_CLASSCASTEXCEPTION(o) \
+    { \
+               classcastexception_object = o; \
+        THROW(classcastexception); \
+       }
+
 #define CHECK_OUT_OF_BOUNDS(_array, _idx)              \
         {                                            \
           if (length_array(_array) <= (u4) (_idx)) { \
 #define access_array_addr(array, index)               \
         ((((java_objectarray*)(array))->data)[index])
 
-#define MAXLOCALS(stub) (((Cell *)stub)[1])
+#define access_array_float(array, index)               \
+        ((((java_floatarray*)(array))->data)[index])
+
+/* (see createcompilerstub in codegen.c) */
+#define FRAMESIZE(stub) (((Cell *)stub)[1])
 
 #if 0
 #define CLEARSTACK(_start, _end) \
@@ -210,24 +217,24 @@ engine(Inst *ip0, Cell * sp0, Cell * fp)
 {
   Inst *ip;
   register Cell *sp SPREG = sp0;
-  Inst ca1; /* code address; this is the next dispatched instruction */
-  IF_spTOS(register Cell spTOS TOSREG);
+  /* Inst ca1; XXX unused? */ /* code address; this is the next dispatched instruction */
+  IF_spTOS(register Cell spTOS TOSREG;)
   static Inst   labels[] = {
 #define INST_ADDR(_inst) (&&I_##_inst)
-#include "java-labels.i"
+#include <java-labels.i>
 #undef INST_ADDR
          NULL,
 #define INST_ADDR(_inst) (&&J_##_inst)
-#include "java-labels.i"
+#include <java-labels.i>
 #undef INST_ADDR
 #define INST_ADDR(_inst) (&&K_##_inst)
-#include "java-labels.i"
+#include <java-labels.i>
 #undef INST_ADDR
     (Label)&&after_last,
     (Label)&&before_goto,
     (Label)&&after_goto,
 #define INST_ADDR(_inst) (&&H_##_inst)
-#include "java-labels.i"
+#include <java-labels.i>
 #undef INST_ADDR
   };
   /* local variables for the various throw codes; this helps make
@@ -238,7 +245,8 @@ engine(Inst *ip0, Cell * sp0, Cell * fp)
   Label throw_classcastexception                        = &&throw_classcastexception1;  
   Label throw_nullpointerexception                  = &&throw_nullpointerexception1;
   Label throw_arraystoreexception            = &&throw_arraystoreexception1;
-  s4 arrayindexoutofbounds_index; /* pass the index to the throw code */
+  java_objectheader *classcastexception_object = NULL;
+  s4 arrayindexoutofbounds_index = 0; /* pass the index to the throw code */
 
   if (vm_debug)
       fprintf(vm_out,"entering engine(%p,%p,%p)\n",ip0,sp,fp);
@@ -260,10 +268,15 @@ engine(Inst *ip0, Cell * sp0, Cell * fp)
 
       /* the actual codes jumped to through the ...exception variables */
          THROWCODE(arithmeticexception);
-         THROWCODE(classcastexception);
          THROWCODE(nullpointerexception);
          THROWCODE(arraystoreexception);
 
+  throw_classcastexception1:
+         global_sp = sp;
+         *exceptionptr = stacktrace_inline_classcastexception(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP, classcastexception_object);
+         CLEAR_global_sp;
+         THROW0;
+
   throw_arrayindexoutofboundsexception1:
          global_sp = sp;
          *exceptionptr = stacktrace_inline_arrayindexoutofboundsexception(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP, arrayindexoutofbounds_index);
@@ -279,7 +292,7 @@ engine(Inst *ip0, Cell * sp0, Cell * fp)
   NEXT;
 
 #define INST_ADDR(_inst) (&&I_##_inst)
-#include "java-vm.i"
+#include <java-vm.i>
 #undef NAME
  after_last: return NULL;
 }
@@ -296,4 +309,5 @@ engine(Inst *ip0, Cell * sp0, Cell * fp)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */