/* 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 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
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:
+/* #define VM_DEBUG */
- $Id: engine.c 3895 2005-12-07 16:03:37Z anton $
-*/
+#include "config.h"
#include <assert.h>
-/* #define VM_DEBUG */
-#define USE_spTOS
+#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 "mm/memory.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
+#else
+# include "threads/none/threads.h"
+#endif
+
#include "vm/builtin.h"
#include "vm/exceptions.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/jit/codegen.inc.h"
+
#include "vm/jit/methodheader.h"
#include "vm/jit/patcher.h"
+#include "vm/jit/stacktrace.h"
-#define FFCALL 0
+#include "vmcore/loader.h"
+#include "vmcore/options.h"
-#if FFCALL
-# include "ffcall/avcall/avcall.h"
-#else
-# include "libffi/include/ffi.h"
-#endif
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-# ifndef USE_MD_THREAD_STUFF
+#if defined(ENABLE_THREADS)
+# ifndef USE_FAKE_ATOMIC_INSTRUCTIONS
# include "machine-instr.h"
# else
# include "threads/native/generic-primitives.h"
# endif
#endif
-#if !defined(STORE_ORDER_BARRIER) && !defined(USE_THREADS)
+#if !defined(STORE_ORDER_BARRIER) && !defined(ENABLE_THREADS)
#define STORE_ORDER_BARRIER() /* nothing */
#endif
/* threading macros */
#define GCC_PR15242_WORKAROUND
#ifdef GCC_PR15242_WORKAROUND
-#define DO_GOTO goto before_goto
+# define NEXT_P1_5
+# define DO_GOTO goto before_goto
#else
-#define DO_GOTO goto *ca
+# define NEXT_P1_5
+# define DO_GOTO goto *ip[-1]
#endif
# define NEXT_P0
# define INC_IP(const_inc) do { ip+=(const_inc);} while (0)
# define DEF_CA
# define NEXT_P1 (ip++)
-# define NEXT_P1_5 do {ca=ip[-1];} while(0)
# define NEXT_P2 do {NEXT_P1_5; DO_GOTO;} while(0)
#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 spTOS (sp[0])
#endif
+#if defined(__I386__)
+/* works with gcc-2.95.4 20011002 (Debian prerelease) without static supers */
+#define SPREG /* __asm__("%esi") */
+#define TOSREG /* __asm__("%ecx") */
+#elif defined(__X86_64__)
+/* works with gcc-4.0.2 (Debian 4.0.2-2) */
+#define SPREG /* __asm__("%r15") */
+#define TOSREG
+#else
+#define SPREG
+#define TOSREG
+#endif
+
+
/* conversion on fetch */
#ifdef VM_PROFILING
#define THROW0 goto throw
+#if 1
#define THROW(_ball) do { \
__asm__(""); /* work around gcc PR 25285 */ \
goto *throw_##_ball; \
} while (0)
+#else
+#define THROW(_ball) do { \
+ goto throw_##_ball##1; \
+ } while (0)
+#endif
#define THROWCODE(_ball) \
throw_##_ball##1: \
global_sp = sp; \
- *exceptionptr = (stacktrace_inline_##_ball(NULL, (u1 *) fp, (functionptr) IP, (functionptr) IP)); \
+ *exceptionptr = (stacktrace_inline_##_ball(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP)); \
CLEAR_global_sp; \
THROW0;
} \
}
+#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) \
java_objectheader *
-engine(Inst *ip0, Cell * sp, Cell * fp)
+engine(Inst *ip0, Cell * sp0, Cell * fp)
{
Inst *ip;
- Inst ca; /* code address; this is the next dispatched instruction */
- IF_spTOS(Cell spTOS);
+ register Cell *sp SPREG = sp0;
+ /* 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
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);
if (0) {
before_goto:
- goto *ca;
+ goto *ip[-1];
after_goto:
/* ensure that gcc does not constant-propagate the contents of
these variables and thus undo our relocatability work */
/* 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, (functionptr) IP, (functionptr) IP, arrayindexoutofbounds_index);
+ *exceptionptr = stacktrace_inline_arrayindexoutofboundsexception(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP, arrayindexoutofbounds_index);
CLEAR_global_sp;
THROW0;
}
NEXT;
#define INST_ADDR(_inst) (&&I_##_inst)
-#include "java-vm.i"
+#include <java-vm.i>
#undef NAME
after_last: return NULL;
}
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/