* src/vm/jit/trap.c: New file.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 24 Apr 2008 14:04:17 +0000 (16:04 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 24 Apr 2008 14:04:17 +0000 (16:04 +0200)
* src/vm/jit/trap.h: Likewise.

* src/vm/jit/Makefile.am [ENABLE_JIT] (TRAP_SOURCES): Added.
(libjit_la_SOURCES): Added TRAP_SOURCES.

* src/vm/exceptions.c (exceptions_init): Removed.
* src/vm/exceptions.h (EXCEPTION_HARDWARE_*): Removed.

* src/vm/signal.c (signal_handle): Removed.
* src/vm/signallocal.h: Likewise.

* src/vm/vm.c (vm_create): Removed exceptions_init call, added
trap_init call.

* src/vm/jit/x86_64/codegen.c: Use new trap stuff.
* src/vm/jit/x86_64/emit.c: Likewise.
* src/vm/jit/x86_64/linux/md-os.c: Likewise.
* src/vm/jit/x86_64/md-trap.h: New file.

--HG--
branch : twisti

12 files changed:
src/vm/exceptions.c
src/vm/exceptions.h
src/vm/jit/Makefile.am
src/vm/jit/trap.c [new file with mode: 0644]
src/vm/jit/trap.h [new file with mode: 0644]
src/vm/jit/x86_64/codegen.c
src/vm/jit/x86_64/emit.c
src/vm/jit/x86_64/linux/md-os.c
src/vm/jit/x86_64/md-trap.h [new file with mode: 0644]
src/vm/signal.c
src/vm/signallocal.h
src/vm/vm.c

index 4bbf7cdb8e334516a32ae21a89355e6266a5834a..d258329c1f8c538ffe476884da8e0f4d2ecfd09a 100644 (file)
@@ -82,37 +82,6 @@ java_object_t *_no_threads_exceptionptr = NULL;
 #endif
 
 
-/* exceptions_init *************************************************************
-
-   Initialize the exceptions subsystem.
-
-*******************************************************************************/
-
-void exceptions_init(void)
-{
-#if !(defined(__ARM__) && defined(__LINUX__))
-       /* On arm-linux the first memory page can't be mmap'ed, as it
-          contains the exception vectors. */
-
-       int pagesize;
-
-       /* mmap a memory page at address 0x0, so our hardware-exceptions
-          work. */
-
-       pagesize = system_getpagesize();
-
-       (void) system_mmap_anonymous(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED);
-#endif
-
-       TRACESUBSYSTEMINITIALIZATION("exceptions_init");
-
-       /* check if we get into trouble with our hardware-exceptions */
-
-       if (OFFSET(java_bytearray_t, data) <= EXCEPTION_HARDWARE_LARGEST)
-               vm_abort("signal_init: array-data offset is less or equal the maximum hardware-exception displacement: %d <= %d", OFFSET(java_bytearray_t, data), EXCEPTION_HARDWARE_LARGEST);
-}
-
-
 /* exceptions_get_exception ****************************************************
 
    Returns the current exception pointer of the current thread.
index 933eb2c33b99989bcde574052f2d63bc1cd9105b..1aea660408cd7c400337435b3106a30d2aa823c7 100644 (file)
 #ifndef _EXCEPTIONS_H
 #define _EXCEPTIONS_H
 
-/* forward typedefs ***********************************************************/
-
 #include "config.h"
 #include "vm/types.h"
 
 #include "vm/global.h"
 
-#include "vm/jit/stacktrace.h"
-
 #include "vmcore/references.h"
 #include "vmcore/method.h"
 
 
-/* hardware-exception defines **************************************************
-
-   These defines define an internal number for the various hardware
-   exceptions.
-
-   ATTENTION: These values are also used as load-displacements on some
-   architectures. Thus, these values must NOT be aligned to 4 or
-   8-byte boundaries, since normal loads could have such offsets with
-   a base of NULL which should result in a NullPointerException.
-
-   NOTE: In exceptions_init() we have a check whether the offset of
-   java_arrayheader.data[0] is greater than the largest displacement
-   defined below.  Otherwise normal array loads/stores could trigger
-   an exception.
-
-*******************************************************************************/
-
-#define EXCEPTION_HARDWARE_NULLPOINTER              0
-#define EXCEPTION_HARDWARE_ARITHMETIC               1
-#define EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS    2
-#define EXCEPTION_HARDWARE_ARRAYSTORE               3
-
-#define EXCEPTION_HARDWARE_CLASSCAST                5
-#define EXCEPTION_HARDWARE_EXCEPTION                6
-#define EXCEPTION_HARDWARE_PATCHER                  7
-
-#define EXCEPTION_HARDWARE_COMPILER                 9
-
-#define EXCEPTION_HARDWARE_LARGEST                  9
-
-
 /* function prototypes ********************************************************/
 
-void           exceptions_init(void);
-
 java_handle_t *exceptions_get_exception(void);
 void           exceptions_set_exception(java_handle_t *o);
 void           exceptions_clear_exception(void);
index c44f0129e57414a011bf69ab01d8158e4242651b..015a917ce6cc392c394ac03c84dfd99e8638e1cd 100644 (file)
@@ -108,6 +108,10 @@ REPLACE_SOURCES += \
 STACK_SOURCES = \
        stack.c \
        stack.h
+
+TRAP_SOURCES = \
+       trap.c \
+       trap.h
 endif
 
 if ENABLE_REPLACEMENT
@@ -173,7 +177,8 @@ libjit_la_SOURCES = \
        stacktrace.c \
        stacktrace.h \
        trace.c \
-       trace.h
+       trace.h \
+       $(TRAP_SOURCES)
 
 libjit_la_SOURCES += \
        cfg.c \
diff --git a/src/vm/jit/trap.c b/src/vm/jit/trap.c
new file mode 100644 (file)
index 0000000..d062952
--- /dev/null
@@ -0,0 +1,237 @@
+/* src/vm/jit/trap.c - hardware traps
+
+   Copyright (C) 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+/* Include machine dependent trap stuff. */
+
+#include "md-trap.h"
+
+#include "native/llni.h"
+
+#include "toolbox/logging.h"
+
+#include "vm/exceptions.h"
+#include "vm/vm.h"
+
+#include "vm/jit/code.h"
+#include "vm/jit/disass.h"
+#include "vm/jit/jit.h"
+#include "vm/jit/methodtree.h"
+#include "vm/jit/patcher-common.h"
+#include "vm/jit/replace.h"
+#include "vm/jit/stacktrace.h"
+
+#include "vmcore/options.h"
+#include "vmcore/system.h"
+
+
+/**
+ * Mmap the first memory page to support hardware exceptions and check
+ * the maximum hardware trap displacement on the architectures where
+ * it is required (TRAP_INSTRUCTION_IS_LOAD defined to 1).
+ */
+void trap_init(void)
+{
+#if !(defined(__ARM__) && defined(__LINUX__))
+       /* On arm-linux the first memory page can't be mmap'ed, as it
+          contains the exception vectors. */
+
+       int pagesize;
+
+       /* mmap a memory page at address 0x0, so our hardware-exceptions
+          work. */
+
+       pagesize = system_getpagesize();
+
+       (void) system_mmap_anonymous(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED);
+#endif
+
+       TRACESUBSYSTEMINITIALIZATION("trap_init");
+
+#if !defined(TRAP_INSTRUCTION_IS_LOAD)
+# error TRAP_INSTRUCTION_IS_LOAD is not defined in your md-trap.h
+#endif
+
+#if TRAP_INSTRUCTION_IS_LOAD == 1
+       /* Check if we get into trouble with our hardware-exceptions. */
+
+       if (TRAP_END > OFFSET(java_bytearray_t, data))
+               vm_abort("trap_init: maximum hardware trap displacement is greater than the array-data offset: %d > %d", TRAP_END, OFFSET(java_bytearray_t, data));
+#endif
+}
+
+
+/**
+ * Handles the signal which is generated by trap instructions, caught
+ * by a signal handler and calls the correct function.
+ *
+ * @param type trap number
+ * @param 
+ */
+void* trap_handle(int type, intptr_t val, void *pv, void *sp, void *ra, void *xpc, void *context)
+{
+       stackframeinfo_t  sfi;
+       int32_t           index;
+       java_handle_t    *o;
+       methodinfo       *m;
+       java_handle_t    *p;
+
+#if !defined(NDEBUG)
+       if (opt_TraceTraps)
+               log_println("[signal_handle: trap %d]", type);
+#endif
+       
+#if defined(ENABLE_VMLOG)
+       vmlog_cacao_signl_type(type);
+#endif
+
+       /* Prevent compiler warnings. */
+
+       o = NULL;
+       m = NULL;
+
+       /* wrap the value into a handle if it is a reference */
+       /* BEFORE: creating stackframeinfo */
+
+       switch (type) {
+       case TRAP_ClassCastException:
+               o = LLNI_WRAP((java_object_t *) val);
+               break;
+
+       case TRAP_COMPILER:
+               /* In this case the passed PV points to the compiler stub.  We
+                  get the methodinfo pointer here and set PV to NULL so
+                  stacktrace_stackframeinfo_add determines the PV for the
+                  parent Java method. */
+
+               m  = code_get_methodinfo_for_pv(pv);
+               pv = NULL;
+               break;
+
+       default:
+               /* do nothing */
+               break;
+       }
+
+       /* Fill and add a stackframeinfo. */
+
+       stacktrace_stackframeinfo_add(&sfi, pv, sp, ra, xpc);
+
+       switch (type) {
+       case TRAP_NullPointerException:
+               p = exceptions_new_nullpointerexception();
+               break;
+
+       case TRAP_ArithmeticException:
+               p = exceptions_new_arithmeticexception();
+               break;
+
+       case TRAP_ArrayIndexOutOfBoundsException:
+               index = (s4) val;
+               p = exceptions_new_arrayindexoutofboundsexception(index);
+               break;
+
+       case TRAP_ArrayStoreException:
+               p = exceptions_new_arraystoreexception();
+               break;
+
+       case TRAP_ClassCastException:
+               p = exceptions_new_classcastexception(o);
+               break;
+
+       case TRAP_CHECK_EXCEPTION:
+               p = exceptions_fillinstacktrace();
+               break;
+
+       case TRAP_PATCHER:
+#if defined(ENABLE_REPLACEMENT)
+               if (replace_me_wrapper(xpc, context)) {
+                       p = NULL;
+                       break;
+               }
+#endif
+               p = patcher_handler(xpc);
+               break;
+
+       case TRAP_COMPILER:
+               p = jit_compile_handle(m, sfi.pv, ra, (void *) val);
+               break;
+
+       default:
+               /* Let's try to get a backtrace. */
+
+               (void) methodtree_find(xpc);
+
+               /* If that does not work, print more debug info. */
+
+               log_println("signal_handle: unknown hardware exception type %d", type);
+
+#if SIZEOF_VOID_P == 8
+               log_println("PC=0x%016lx", xpc);
+#else
+               log_println("PC=0x%08x", xpc);
+#endif
+
+#if defined(ENABLE_DISASSEMBLER)
+               log_println("machine instruction at PC:");
+               disassinstr(xpc);
+#endif
+
+               vm_abort("Exiting...");
+
+               /* keep compiler happy */
+
+               p = NULL;
+       }
+
+       /* Remove stackframeinfo. */
+
+       stacktrace_stackframeinfo_remove(&sfi);
+
+       /* unwrap and return the exception object */
+       /* AFTER: removing stackframeinfo */
+
+       if (type == TRAP_COMPILER)
+               return p;
+       else
+               return LLNI_UNWRAP(p);
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
diff --git a/src/vm/jit/trap.h b/src/vm/jit/trap.h
new file mode 100644 (file)
index 0000000..8eb295b
--- /dev/null
@@ -0,0 +1,58 @@
+/* src/vm/jit/trap.h - hardware traps
+
+   Copyright (C) 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#ifndef _TRAP_H
+#define _TRAP_H
+
+#include "config.h"
+
+#include <stdint.h>
+
+/* Include machine dependent trap stuff. */
+
+#include "md-trap.h"
+
+
+/* function prototypes ********************************************************/
+
+void  trap_init(void);
+void* trap_handle(int type, intptr_t val, void *pv, void *sp, void *ra, void *xpc, void *context);
+
+#endif /* _TRAP_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
index 9d238bddaeb8b08a0622c24971fc0c2a5c56d2b2..a93f42b5234c24d7bb0165d0663931ecb6419925 100644 (file)
@@ -67,6 +67,7 @@
 #include "vm/jit/reg.h"
 #include "vm/jit/replace.h"
 #include "vm/jit/stacktrace.h"
+#include "vm/jit/trap.h"
 
 #if defined(ENABLE_LSRA)
 # include "vm/jit/allocator/lsra.h"
@@ -269,7 +270,7 @@ bool codegen_emit(jitdata *jd)
                else {
                        M_TEST(REG_A0);
                        M_BNE(8);
-                       M_ALD_MEM(REG_A0, EXCEPTION_HARDWARE_NULLPOINTER);
+                       M_ALD_MEM(REG_A0, TRAP_NullPointerException);
                }
 
                M_AST(REG_A0, REG_SP, s1 * 8);
index 46c21d26d0c85a18016cd862d98c433a811b127a..60e5f342d83933740c4e97524b90ef24aaf7622d 100644 (file)
@@ -39,8 +39,6 @@
 
 #include "threads/lock-common.h"
 
-#include "vm/exceptions.h"
-
 #include "vm/jit/abi.h"
 #include "vm/jit/abi-asm.h"
 #include "vm/jit/asmpart.h"
@@ -50,6 +48,7 @@
 #include "vm/jit/patcher-common.h"
 #include "vm/jit/replace.h"
 #include "vm/jit/trace.h"
+#include "vm/jit/trap.h"
 
 #include "vmcore/options.h"
 
@@ -311,7 +310,7 @@ void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TEST(reg);
                M_BNE(8);
-               M_ALD_MEM(reg, EXCEPTION_HARDWARE_ARITHMETIC);
+               M_ALD_MEM(reg, TRAP_ArithmeticException);
        }
 }
 
@@ -328,7 +327,7 @@ void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1,
         M_ILD(REG_ITMP3, s1, OFFSET(java_array_t, size));
         M_ICMP(REG_ITMP3, s2);
                M_BULT(8);
-               M_ALD_MEM(s2, EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS);
+               M_ALD_MEM(s2, TRAP_ArrayIndexOutOfBoundsException);
        }
 }
 
@@ -344,7 +343,7 @@ void emit_arraystore_check(codegendata *cd, instruction *iptr)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TEST(REG_RESULT);
                M_BNE(8);
-               M_ALD_MEM(REG_RESULT, EXCEPTION_HARDWARE_ARRAYSTORE);
+               M_ALD_MEM(REG_RESULT, TRAP_ArrayStoreException);
        }
 }
 
@@ -371,7 +370,7 @@ void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 r
                default:
                        vm_abort("emit_classcast_check: unknown condition %d", condition);
                }
-               M_ALD_MEM(s1, EXCEPTION_HARDWARE_CLASSCAST);
+               M_ALD_MEM(s1, TRAP_ClassCastException);
        }
 }
 
@@ -387,7 +386,7 @@ void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TEST(reg);
                M_BNE(8);
-               M_ALD_MEM(reg, EXCEPTION_HARDWARE_NULLPOINTER);
+               M_ALD_MEM(reg, TRAP_NullPointerException);
        }
 }
 
@@ -403,7 +402,7 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TEST(REG_RESULT);
                M_BNE(8);
-               M_ALD_MEM(REG_RESULT, EXCEPTION_HARDWARE_EXCEPTION);
+               M_ALD_MEM(REG_RESULT, TRAP_CHECK_EXCEPTION);
        }
 }
 
@@ -416,7 +415,7 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
 
 void emit_trap_compiler(codegendata *cd)
 {
-       M_ALD_MEM(REG_METHODPTR, EXCEPTION_HARDWARE_COMPILER);
+       M_ALD_MEM(REG_METHODPTR, TRAP_COMPILER);
 }
 
 
index aa81679c819f0efe948371c6c05d4665e8040fa3..8b8bf32d51f1a44dc0e920b70370ba58d2dd31b5 100644 (file)
 #include "threads/thread.h"
 
 #include "vm/builtin.h"
-#include "vm/exceptions.h"
 #include "vm/signallocal.h"
 
 #include "vm/jit/asmpart.h"
 #include "vm/jit/executionstate.h"
+#include "vm/jit/trap.h"
 #include "vm/jit/stacktrace.h"
 
 
@@ -152,7 +152,7 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
                val = _mc->gregs[d];
 
-               if (type == EXCEPTION_HARDWARE_COMPILER) {
+               if (type == TRAP_COMPILER) {
                        /* The PV from the compiler stub is equal to the XPC. */
 
                        pv = xpc;
@@ -175,17 +175,17 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        else {
                /* this was a normal NPE */
 
-               type = EXCEPTION_HARDWARE_NULLPOINTER;
+               type = TRAP_NullPointerException;
                val  = 0;
        }
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* Set registers. */
 
-       if (type == EXCEPTION_HARDWARE_COMPILER) {
+       if (type == TRAP_COMPILER) {
                if (p == NULL) {
                        o = builtin_retrieve_exception();
 
@@ -237,14 +237,14 @@ void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
        xpc = (u1 *) _mc->gregs[REG_RIP];
        ra  = xpc;                          /* return address is equal to xpc     */
 
-       /* this is an ArithmeticException */
+       /* This is an ArithmeticException. */
 
-       type = EXCEPTION_HARDWARE_ARITHMETIC;
+       type = TRAP_ArithmeticException;
        val  = 0;
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* set registers */
 
@@ -285,12 +285,12 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 
        /* This is a patcher. */
 
-       type = EXCEPTION_HARDWARE_PATCHER;
+       type = TRAP_PATCHER;
        val  = 0;
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* set registers */
 
diff --git a/src/vm/jit/x86_64/md-trap.h b/src/vm/jit/x86_64/md-trap.h
new file mode 100644 (file)
index 0000000..6493e35
--- /dev/null
@@ -0,0 +1,79 @@
+/* src/vm/jit/x86_64/md-trap.h - x86_64 hardware traps
+
+   Copyright (C) 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#ifndef _MD_TRAP_H
+#define _MD_TRAP_H
+
+#include "config.h"
+
+
+/**
+ * Trap number defines.
+ *
+ * On this architecture (x86_64) the trap numbers are used as load
+ * displacements and thus must not be 4- or 8-byte aligned.
+ *
+ * NOTE: In trap_init() we have a check whether the offset of
+ * java_arrayheader.data[0] is greater than the largest displacement
+ * defined below.  Otherwise normal array loads/stores could trigger
+ * an exception.
+ */
+
+#define TRAP_INSTRUCTION_IS_LOAD    1
+
+enum {
+       TRAP_NullPointerException           = 0,
+       TRAP_ArithmeticException            = 1,
+       TRAP_ArrayIndexOutOfBoundsException = 2,
+       TRAP_ArrayStoreException            = 3,
+
+       /* Don't use 4 (could be a normal load offset). */
+
+       TRAP_ClassCastException             = 5,
+       TRAP_CHECK_EXCEPTION                = 6,
+       TRAP_PATCHER                        = 7,
+
+       /* Don't use 8 (could be a normal load offset). */
+
+       TRAP_COMPILER                       = 9,
+       TRAP_END
+};
+
+#endif /* _MD_TRAP_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
index fe16b57086a2f0ea38c155586e183c70b8da716d..39e1c6b22455211b34828b3d7cf93159b7736b32 100644 (file)
 
 #include "arch.h"
 
-#include "mm/memory.h"
-
-#include "native/llni.h"
-
 #include "threads/thread.h"
 
-#include "toolbox/logging.h"
-
 #include "vm/exceptions.h"
 #include "vm/signallocal.h"
 #include "vm/vm.h"
 
-#include "vm/jit/codegen-common.h"
-#include "vm/jit/disass.h"
-#include "vm/jit/methodtree.h"
-#include "vm/jit/patcher-common.h"
-
 #include "vmcore/options.h"
 
 #if defined(ENABLE_STATISTICS)
@@ -244,144 +233,6 @@ void signal_register_signal(int signum, functionptr handler, int flags)
 }
 
 
-/* signal_handle ***************************************************************
-
-   Handles the signal caught by a signal handler and calls the correct
-   function.
-
-*******************************************************************************/
-
-void *signal_handle(int type, intptr_t val,
-                                       void *pv, void *sp, void *ra, void *xpc, void *context)
-{
-       stackframeinfo_t  sfi;
-       int32_t           index;
-       java_handle_t    *o;
-       methodinfo       *m;
-       java_handle_t    *p;
-
-#if !defined(NDEBUG)
-       if (opt_TraceTraps)
-               log_println("[signal_handle: trap %d]", type);
-#endif
-       
-#if defined(ENABLE_VMLOG)
-       vmlog_cacao_signl_type(type);
-#endif
-
-       /* Prevent compiler warnings. */
-
-       o = NULL;
-       m = NULL;
-
-       /* wrap the value into a handle if it is a reference */
-       /* BEFORE: creating stackframeinfo */
-
-       switch (type) {
-       case EXCEPTION_HARDWARE_CLASSCAST:
-               o = LLNI_WRAP((java_object_t *) val);
-               break;
-
-       case EXCEPTION_HARDWARE_COMPILER:
-               /* In this case the passed PV points to the compiler stub.  We
-                  get the methodinfo pointer here and set PV to NULL so
-                  stacktrace_stackframeinfo_add determines the PV for the
-                  parent Java method. */
-
-               m  = code_get_methodinfo_for_pv(pv);
-               pv = NULL;
-               break;
-
-       default:
-               /* do nothing */
-               break;
-       }
-
-       /* Fill and add a stackframeinfo. */
-
-       stacktrace_stackframeinfo_add(&sfi, pv, sp, ra, xpc);
-
-       switch (type) {
-       case EXCEPTION_HARDWARE_NULLPOINTER:
-               p = exceptions_new_nullpointerexception();
-               break;
-
-       case EXCEPTION_HARDWARE_ARITHMETIC:
-               p = exceptions_new_arithmeticexception();
-               break;
-
-       case EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS:
-               index = (s4) val;
-               p = exceptions_new_arrayindexoutofboundsexception(index);
-               break;
-
-       case EXCEPTION_HARDWARE_ARRAYSTORE:
-               p = exceptions_new_arraystoreexception();
-               break;
-
-       case EXCEPTION_HARDWARE_CLASSCAST:
-               p = exceptions_new_classcastexception(o);
-               break;
-
-       case EXCEPTION_HARDWARE_EXCEPTION:
-               p = exceptions_fillinstacktrace();
-               break;
-
-       case EXCEPTION_HARDWARE_PATCHER:
-#if defined(ENABLE_REPLACEMENT)
-               if (replace_me_wrapper(xpc, context)) {
-                       p = NULL;
-                       break;
-               }
-#endif
-               p = patcher_handler(xpc);
-               break;
-
-       case EXCEPTION_HARDWARE_COMPILER:
-               p = jit_compile_handle(m, sfi.pv, ra, (void *) val);
-               break;
-
-       default:
-               /* Let's try to get a backtrace. */
-
-               (void) methodtree_find(xpc);
-
-               /* If that does not work, print more debug info. */
-
-               log_println("signal_handle: unknown hardware exception type %d", type);
-
-#if SIZEOF_VOID_P == 8
-               log_println("PC=0x%016lx", xpc);
-#else
-               log_println("PC=0x%08x", xpc);
-#endif
-
-#if defined(ENABLE_DISASSEMBLER)
-               log_println("machine instruction at PC:");
-               disassinstr(xpc);
-#endif
-
-               vm_abort("Exiting...");
-
-               /* keep compiler happy */
-
-               p = NULL;
-       }
-
-       /* Remove stackframeinfo. */
-
-       stacktrace_stackframeinfo_remove(&sfi);
-
-       /* unwrap and return the exception object */
-       /* AFTER: removing stackframeinfo */
-
-       if (type == EXCEPTION_HARDWARE_COMPILER)
-               return p;
-       else
-               return LLNI_UNWRAP(p);
-}
-
-
 /* signal_thread ************************************************************
 
    This thread sets the signal mask to catch the user input signals
index 2c9450e547e351f3c94210397f94a0b8d4944949..7d4e70e38944a5f12f940842618ddd10b22e9be1 100644 (file)
@@ -40,9 +40,6 @@
 bool  signal_init(void);
 void  signal_register_signal(int signum, functionptr handler, int flags);
 
-void *signal_handle(int type, intptr_t val,
-                                       void *pv, void *sp, void *ra, void *xpc, void *context);
-
 void  signal_thread_handler(int sig);
 bool  signal_start_thread(void);
 
index 4888eb3a3d1666035a8e54067bd8026941368ae1..3a44d2daec65ab4e5df0f31bcdf3547413e1c943 100644 (file)
 # include "vm/jit/python.h"
 #endif
 
+#include "vm/jit/trap.h"
+
 #include "vmcore/classcache.h"
 #include "vmcore/options.h"
 #include "vmcore/statistics.h"
@@ -1516,7 +1518,9 @@ bool vm_create(JavaVMInitArgs *vm_args)
        primitive_postinit();
        method_init();
 
-       exceptions_init();
+#if defined(ENABLE_JIT)
+       trap_init();
+#endif
 
        if (!builtin_init())
                vm_abort("vm_create: builtin_init failed");