From: Michael Starzinger Date: Sun, 28 Dec 2008 14:32:21 +0000 (+0100) Subject: * src/vm/jit/trap.c: Moved to C++ X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=cacao.git;a=commitdiff_plain;h=23a3859cc1442012273e1a77e44ca2ac985aac5e * src/vm/jit/trap.c: Moved to C++ * src/vm/jit/trap.h: Likewise. * src/vm/jit/trap.cpp: See above. * src/vm/jit/trap.hpp: Likeiwse. Adapted includes in the following files: * src/vm/jit/alpha/codegen.c * src/vm/jit/alpha/emit.c * src/vm/jit/alpha/linux/md-os.c * src/vm/jit/alpha/md.c * src/vm/jit/arm/emit.c * src/vm/jit/arm/linux/md-os.c * src/vm/jit/i386/codegen.c * src/vm/jit/i386/darwin/md-os.c * src/vm/jit/i386/emit.c * src/vm/jit/i386/freebsd/md-os.c * src/vm/jit/i386/linux/md-os.c * src/vm/jit/i386/solaris/md-os.c * src/vm/jit/m68k/codegen.c * src/vm/jit/m68k/emit.c * src/vm/jit/m68k/linux/md-os.c * src/vm/jit/mips/codegen.c * src/vm/jit/mips/emit.c * src/vm/jit/mips/linux/md-os.c * src/vm/jit/powerpc/codegen.c * src/vm/jit/powerpc/emit.c * src/vm/jit/powerpc/linux/md-os.c * src/vm/jit/powerpc64/codegen.c * src/vm/jit/powerpc64/emit.c * src/vm/jit/powerpc64/linux/md-os.c * src/vm/jit/powerpc64/md.c * src/vm/jit/s390/codegen.c * src/vm/jit/s390/emit.c * src/vm/jit/s390/md.c * src/vm/jit/sparc64/linux/md-os.c * src/vm/jit/sparc64/solaris/md-os.c * 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/solaris/md-os.c * src/vm/vm.cpp --HG-- rename : src/vm/jit/trap.c => src/vm/jit/trap.cpp rename : src/vm/jit/trap.h => src/vm/jit/trap.hpp --- diff --git a/src/vm/jit/alpha/codegen.c b/src/vm/jit/alpha/codegen.c index bb4c1fcb9..21e536f7c 100644 --- a/src/vm/jit/alpha/codegen.c +++ b/src/vm/jit/alpha/codegen.c @@ -62,7 +62,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_SSA) # include "vm/jit/optimizing/lsra.h" diff --git a/src/vm/jit/alpha/emit.c b/src/vm/jit/alpha/emit.c index 96fb6f0be..ac5d0ba12 100644 --- a/src/vm/jit/alpha/emit.c +++ b/src/vm/jit/alpha/emit.c @@ -48,7 +48,7 @@ #include "vm/jit/patcher-common.hpp" #include "vm/jit/replace.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ******************************************************************* diff --git a/src/vm/jit/alpha/linux/md-os.c b/src/vm/jit/alpha/linux/md-os.c index 1fe5e8086..b81ff2bc7 100644 --- a/src/vm/jit/alpha/linux/md-os.c +++ b/src/vm/jit/alpha/linux/md-os.c @@ -45,7 +45,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/disass.h" #include "vm/jit/executionstate.h" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/alpha/md.c b/src/vm/jit/alpha/md.c index 9ad99b747..f769b3f78 100644 --- a/src/vm/jit/alpha/md.c +++ b/src/vm/jit/alpha/md.c @@ -40,7 +40,7 @@ extern void ieee_set_fp_control(unsigned long fp_control); #include "vm/jit/asmpart.h" #include "vm/jit/jit.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* global variables ***********************************************************/ diff --git a/src/vm/jit/arm/emit.c b/src/vm/jit/arm/emit.c index c6c922c21..a9793ce7b 100644 --- a/src/vm/jit/arm/emit.c +++ b/src/vm/jit/arm/emit.c @@ -47,7 +47,7 @@ #include "vm/jit/patcher-common.hpp" #include "vm/jit/replace.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #include "toolbox/logging.hpp" /* XXX for debugging only */ diff --git a/src/vm/jit/arm/linux/md-os.c b/src/vm/jit/arm/linux/md-os.c index 10e7c13a2..0788aa26a 100644 --- a/src/vm/jit/arm/linux/md-os.c +++ b/src/vm/jit/arm/linux/md-os.c @@ -59,7 +59,7 @@ typedef struct ucontext { #include "vm/jit/disass.h" #include "vm/jit/executionstate.h" #include "vm/jit/patcher-common.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/i386/codegen.c b/src/vm/jit/i386/codegen.c index 8eab0fbf0..0b2ae4671 100644 --- a/src/vm/jit/i386/codegen.c +++ b/src/vm/jit/i386/codegen.c @@ -64,7 +64,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_SSA) # include "vm/jit/optimizing/lsra.h" diff --git a/src/vm/jit/i386/darwin/md-os.c b/src/vm/jit/i386/darwin/md-os.c index b9f3afd9d..b18a66a27 100644 --- a/src/vm/jit/i386/darwin/md-os.c +++ b/src/vm/jit/i386/darwin/md-os.c @@ -44,7 +44,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #include "vm/jit/i386/codegen.h" diff --git a/src/vm/jit/i386/emit.c b/src/vm/jit/i386/emit.c index 3a264f162..27c60f5ca 100644 --- a/src/vm/jit/i386/emit.c +++ b/src/vm/jit/i386/emit.c @@ -48,7 +48,7 @@ #include "vm/jit/patcher-common.hpp" #include "vm/jit/replace.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ****************************************************************** diff --git a/src/vm/jit/i386/freebsd/md-os.c b/src/vm/jit/i386/freebsd/md-os.c index 9a1883147..43800e6b1 100644 --- a/src/vm/jit/i386/freebsd/md-os.c +++ b/src/vm/jit/i386/freebsd/md-os.c @@ -41,7 +41,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/i386/linux/md-os.c b/src/vm/jit/i386/linux/md-os.c index 19be0e4b7..754b32124 100644 --- a/src/vm/jit/i386/linux/md-os.c +++ b/src/vm/jit/i386/linux/md-os.c @@ -43,7 +43,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/i386/solaris/md-os.c b/src/vm/jit/i386/solaris/md-os.c index 16e649d6d..e39705063 100644 --- a/src/vm/jit/i386/solaris/md-os.c +++ b/src/vm/jit/i386/solaris/md-os.c @@ -41,7 +41,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/m68k/codegen.c b/src/vm/jit/m68k/codegen.c index 5c4689403..12fd51840 100644 --- a/src/vm/jit/m68k/codegen.c +++ b/src/vm/jit/m68k/codegen.c @@ -61,7 +61,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" bool codegen_emit(jitdata *jd) diff --git a/src/vm/jit/m68k/emit.c b/src/vm/jit/m68k/emit.c index 63d74a8e6..f0e3e5fbe 100644 --- a/src/vm/jit/m68k/emit.c +++ b/src/vm/jit/m68k/emit.c @@ -37,7 +37,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/emit-common.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_mov_imm_reg ************************************************************************** diff --git a/src/vm/jit/m68k/linux/md-os.c b/src/vm/jit/m68k/linux/md-os.c index 36e85035d..45e1a34ff 100644 --- a/src/vm/jit/m68k/linux/md-os.c +++ b/src/vm/jit/m68k/linux/md-os.c @@ -32,7 +32,7 @@ #include "vm/vm.hpp" #include "vm/jit/asmpart.h" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #include #include diff --git a/src/vm/jit/mips/codegen.c b/src/vm/jit/mips/codegen.c index 7fac72391..3d98fce85 100644 --- a/src/vm/jit/mips/codegen.c +++ b/src/vm/jit/mips/codegen.c @@ -58,7 +58,7 @@ #include "vm/jit/patcher-common.hpp" #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_LSRA) # include "vm/jit/allocator/lsra.h" diff --git a/src/vm/jit/mips/emit.c b/src/vm/jit/mips/emit.c index 98e9b451f..60e4ceb75 100644 --- a/src/vm/jit/mips/emit.c +++ b/src/vm/jit/mips/emit.c @@ -47,7 +47,7 @@ #include "vm/jit/jit.hpp" #include "vm/jit/patcher-common.hpp" #include "vm/jit/replace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ******************************************************************* diff --git a/src/vm/jit/mips/linux/md-os.c b/src/vm/jit/mips/linux/md-os.c index e707d6ee2..eef2a2dc6 100644 --- a/src/vm/jit/mips/linux/md-os.c +++ b/src/vm/jit/mips/linux/md-os.c @@ -45,7 +45,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_init ********************************************************************* diff --git a/src/vm/jit/powerpc/codegen.c b/src/vm/jit/powerpc/codegen.c index 555f0cf83..832958f6b 100644 --- a/src/vm/jit/powerpc/codegen.c +++ b/src/vm/jit/powerpc/codegen.c @@ -64,7 +64,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_LSRA) # include "vm/jit/allocator/lsra.h" diff --git a/src/vm/jit/powerpc/emit.c b/src/vm/jit/powerpc/emit.c index 9569377aa..6065246b9 100644 --- a/src/vm/jit/powerpc/emit.c +++ b/src/vm/jit/powerpc/emit.c @@ -48,7 +48,7 @@ #include "vm/jit/jit.hpp" #include "vm/jit/replace.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ******************************************************************* diff --git a/src/vm/jit/powerpc/linux/md-os.c b/src/vm/jit/powerpc/linux/md-os.c index 5d2bf98e4..3980348db 100644 --- a/src/vm/jit/powerpc/linux/md-os.c +++ b/src/vm/jit/powerpc/linux/md-os.c @@ -51,7 +51,7 @@ #endif #include "vm/jit/patcher-common.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/powerpc64/codegen.c b/src/vm/jit/powerpc64/codegen.c index 7c609638f..4bfc71206 100644 --- a/src/vm/jit/powerpc64/codegen.c +++ b/src/vm/jit/powerpc64/codegen.c @@ -64,7 +64,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_LSRA) # include "vm/jit/allocator/lsra.h" diff --git a/src/vm/jit/powerpc64/emit.c b/src/vm/jit/powerpc64/emit.c index 0888baefe..3009eac98 100644 --- a/src/vm/jit/powerpc64/emit.c +++ b/src/vm/jit/powerpc64/emit.c @@ -44,7 +44,7 @@ #include "vm/jit/emit-common.hpp" #include "vm/jit/jit.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ******************************************************************* diff --git a/src/vm/jit/powerpc64/linux/md-os.c b/src/vm/jit/powerpc64/linux/md-os.c index 203cb007c..25d0b1bf4 100644 --- a/src/vm/jit/powerpc64/linux/md-os.c +++ b/src/vm/jit/powerpc64/linux/md-os.c @@ -50,7 +50,7 @@ #endif #include "vm/jit/disass.h" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_signal_handler_sigsegv *************************************************** diff --git a/src/vm/jit/powerpc64/md.c b/src/vm/jit/powerpc64/md.c index 15b564227..fd1019400 100644 --- a/src/vm/jit/powerpc64/md.c +++ b/src/vm/jit/powerpc64/md.c @@ -40,7 +40,7 @@ #include "vm/global.h" #include "vm/jit/jit.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* md_init ********************************************************************* diff --git a/src/vm/jit/s390/codegen.c b/src/vm/jit/s390/codegen.c index b2780c05b..05055ba81 100644 --- a/src/vm/jit/s390/codegen.c +++ b/src/vm/jit/s390/codegen.c @@ -66,7 +66,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* DO__LOG generates a call to do__log. No registers are destroyed, diff --git a/src/vm/jit/s390/emit.c b/src/vm/jit/s390/emit.c index f4ed94218..0720e1387 100644 --- a/src/vm/jit/s390/emit.c +++ b/src/vm/jit/s390/emit.c @@ -49,7 +49,7 @@ #include "vm/jit/patcher-common.hpp" #include "vm/jit/replace.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ******************************************************************* diff --git a/src/vm/jit/s390/md.c b/src/vm/jit/s390/md.c index 0788e45a1..bee38bb7d 100644 --- a/src/vm/jit/s390/md.c +++ b/src/vm/jit/s390/md.c @@ -45,7 +45,7 @@ #include "vm/jit/methodheader.h" #include "vm/jit/methodtree.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) #include "vm/options.h" /* XXX debug */ diff --git a/src/vm/jit/sparc64/linux/md-os.c b/src/vm/jit/sparc64/linux/md-os.c index 97c10e3f6..5f38666e8 100644 --- a/src/vm/jit/sparc64/linux/md-os.c +++ b/src/vm/jit/sparc64/linux/md-os.c @@ -38,7 +38,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" typedef struct sigcontext sigcontext; diff --git a/src/vm/jit/sparc64/solaris/md-os.c b/src/vm/jit/sparc64/solaris/md-os.c index 8b13aa3f8..f6911f670 100644 --- a/src/vm/jit/sparc64/solaris/md-os.c +++ b/src/vm/jit/sparc64/solaris/md-os.c @@ -41,7 +41,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" ptrint md_get_reg_from_context(mcontext_t *_mc, u4 rindex) diff --git a/src/vm/jit/trap.c b/src/vm/jit/trap.c deleted file mode 100644 index a5ab45182..000000000 --- a/src/vm/jit/trap.c +++ /dev/null @@ -1,321 +0,0 @@ -/* 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 - -/* Include machine dependent trap stuff. */ - -#include "md.h" -#include "md-trap.h" - -#include "mm/memory.hpp" - -#include "native/llni.h" - -#include "toolbox/logging.hpp" - -#include "vm/exceptions.hpp" -#include "vm/options.h" -#include "vm/os.hpp" -#include "vm/vm.hpp" - -#include "vm/jit/asmpart.h" -#include "vm/jit/code.hpp" -#include "vm/jit/disass.h" -#include "vm/jit/executionstate.h" -#include "vm/jit/jit.hpp" -#include "vm/jit/methodtree.h" -#include "vm/jit/patcher-common.hpp" -#include "vm/jit/replace.hpp" -#include "vm/jit/stacktrace.hpp" - - -/** - * 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 = os_getpagesize(); - - (void) os_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) -{ - executionstate_t es; - 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; - -#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) -# if !defined(NDEBUG) - /* Perform a sanity check on our execution state functions. */ - - executionstate_sanity_check(context); -# endif - - /* Read execution state from current context. */ - - es.code = NULL; - md_executionstate_read(&es, context); -#endif - - /* 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; - -#if defined(ENABLE_REPLACEMENT) - case TRAP_COUNTDOWN: -#if defined(__I386__) - replace_me_wrapper((char*)xpc - 13, context); -#endif - p = NULL; - break; -#endif - - 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); - -#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) - /* Update execution state and set registers. */ - /* AFTER: removing stackframeinfo */ - - switch (type) { - case TRAP_COMPILER: - // The normal case for a compiler trap is to jump directly to - // the newly compiled method. - - if (p != NULL) { - es.pc = (uint8_t *) (uintptr_t) p; - es.pv = (uint8_t *) (uintptr_t) p; - break; - } - - // In case of an exception during JIT compilation, we fetch - // the exception here and proceed with exception handling. - - java_handle_t *e = exceptions_get_and_clear_exception(); - assert(e != NULL); - - // Get and set the PV from the parent Java method. - - es.pv = md_codegen_get_pv_from_pc(ra); - - // XXX: Make the code below a fall-through to default case! - - es.intregs[REG_ITMP1_XPTR] = (uintptr_t) LLNI_DIRECT(e); - es.intregs[REG_ITMP2_XPC] = (uintptr_t) xpc; - es.pc = (uint8_t *) (uintptr_t) asm_handle_exception; - break; - - case TRAP_PATCHER: - // The normal case for a patcher trap is to continue execution at - // the trap instruction. On some archs the PC may point after the - // trap instruction, so we reset it here. - - if (p == NULL) { - es.pc = (uint8_t *) (uintptr_t) xpc; - break; - } - - /* fall-through */ - - default: - if (p != NULL) { - es.intregs[REG_ITMP1_XPTR] = (uintptr_t) LLNI_DIRECT(p); - es.intregs[REG_ITMP2_XPC] = (uintptr_t) xpc; - es.pc = (uint8_t *) (uintptr_t) asm_handle_exception; - } - } - - /* Write back execution state to current context. */ - - md_executionstate_write(&es, context); -#endif - - /* 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.cpp b/src/vm/jit/trap.cpp new file mode 100644 index 000000000..c1dc16295 --- /dev/null +++ b/src/vm/jit/trap.cpp @@ -0,0 +1,329 @@ +/* src/vm/jit/trap.cpp - 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 + +/* Include machine dependent trap stuff. */ + +#include "md.h" +#include "md-trap.h" + +#include "mm/memory.hpp" + +#include "native/llni.h" + +#include "toolbox/logging.hpp" + +#include "vm/exceptions.hpp" +#include "vm/options.h" +#include "vm/os.hpp" +#include "vm/vm.hpp" + +#include "vm/jit/asmpart.h" +#include "vm/jit/code.hpp" +#include "vm/jit/disass.h" +#include "vm/jit/executionstate.h" +#include "vm/jit/jit.hpp" +#include "vm/jit/methodtree.h" +#include "vm/jit/patcher-common.hpp" +#include "vm/jit/replace.hpp" +#include "vm/jit/stacktrace.hpp" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * 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 = os::getpagesize(); + + (void) os::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) +{ + executionstate_t es; + stackframeinfo_t sfi; + +#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. */ + + java_handle_t* o = NULL; + methodinfo* m = NULL; + +#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) +# if !defined(NDEBUG) + /* Perform a sanity check on our execution state functions. */ + + executionstate_sanity_check(context); +# endif + + /* Read execution state from current context. */ + + es.code = NULL; + md_executionstate_read(&es, context); +#endif + + /* Do some preparations before we enter the nativeworld. */ + /* BEFORE: creating stackframeinfo */ + + switch (type) { + case TRAP_ClassCastException: + /* Wrap the value into a handle, as it is a reference. */ + + 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); + + /* Get resulting exception (or pointer to compiled method). */ + + int32_t index; + java_handle_t* p; + + switch (type) { + case TRAP_NullPointerException: + p = exceptions_new_nullpointerexception(); + break; + + case TRAP_ArithmeticException: + p = exceptions_new_arithmeticexception(); + break; + + case TRAP_ArrayIndexOutOfBoundsException: + index = (int32_t) 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((uint8_t*) xpc, context)) { + p = NULL; + break; + } +#endif + p = patcher_handler((uint8_t*) xpc); + break; + + case TRAP_COMPILER: + p = (java_handle_t*) jit_compile_handle(m, sfi.pv, ra, (void*) val); + break; + +#if defined(ENABLE_REPLACEMENT) + case TRAP_COUNTDOWN: +# if defined(__I386__) + replace_me_wrapper((char*)xpc - 13, context); +# endif + p = NULL; + break; +#endif + + 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((uint8_t*) xpc); +#endif + + vm_abort("Exiting..."); + + /* keep compiler happy */ + + p = NULL; + } + + /* Remove stackframeinfo. */ + + stacktrace_stackframeinfo_remove(&sfi); + +#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) + /* Update execution state and set registers. */ + /* AFTER: removing stackframeinfo */ + + switch (type) { + case TRAP_COMPILER: + // The normal case for a compiler trap is to jump directly to + // the newly compiled method. + + if (p != NULL) { + es.pc = (uint8_t *) (uintptr_t) p; + es.pv = (uint8_t *) (uintptr_t) p; + break; + } + + // In case of an exception during JIT compilation, we fetch + // the exception here and proceed with exception handling. + + p = exceptions_get_and_clear_exception(); + assert(p != NULL); + + // Get and set the PV from the parent Java method. + + es.pv = (uint8_t *) md_codegen_get_pv_from_pc(ra); + + // Now fall-through to default exception handling. + + goto trap_handle_exception; + + case TRAP_PATCHER: + // The normal case for a patcher trap is to continue execution at + // the trap instruction. On some archs the PC may point after the + // trap instruction, so we reset it here. + + if (p == NULL) { + es.pc = (uint8_t *) (uintptr_t) xpc; + break; + } + + // Fall-through to default exception handling. + + trap_handle_exception: + default: + if (p != NULL) { + es.intregs[REG_ITMP1_XPTR] = (uintptr_t) LLNI_DIRECT(p); + es.intregs[REG_ITMP2_XPC] = (uintptr_t) xpc; + es.pc = (uint8_t *) (uintptr_t) asm_handle_exception; + } + } + + /* Write back execution state to current context. */ + + md_executionstate_write(&es, context); +#endif + + /* Unwrap and return the exception object. */ + /* AFTER: removing stackframeinfo */ + + if (type == TRAP_COMPILER) + return p; + else + return LLNI_UNWRAP(p); +} + +#ifdef __cplusplus +} +#endif + + +/* + * 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 deleted file mode 100644 index 6a18c35dc..000000000 --- a/src/vm/jit/trap.h +++ /dev/null @@ -1,66 +0,0 @@ -/* 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 - -#ifdef __cplusplus -extern "C" { -#endif - -/* 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); - -#ifdef __cplusplus -} -#endif - -#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: - */ diff --git a/src/vm/jit/trap.hpp b/src/vm/jit/trap.hpp new file mode 100644 index 000000000..ce0c044c1 --- /dev/null +++ b/src/vm/jit/trap.hpp @@ -0,0 +1,66 @@ +/* src/vm/jit/trap.hpp - 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_HPP +#define _TRAP_HPP + +#include "config.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* 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); + +#ifdef __cplusplus +} +#endif + +#endif /* _TRAP_HPP */ + + +/* + * 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: + */ diff --git a/src/vm/jit/x86_64/codegen.c b/src/vm/jit/x86_64/codegen.c index 80c81af88..0265db459 100644 --- a/src/vm/jit/x86_64/codegen.c +++ b/src/vm/jit/x86_64/codegen.c @@ -68,7 +68,7 @@ #include "vm/jit/reg.h" #include "vm/jit/replace.hpp" #include "vm/jit/stacktrace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_LSRA) # include "vm/jit/allocator/lsra.h" diff --git a/src/vm/jit/x86_64/emit.c b/src/vm/jit/x86_64/emit.c index 5f6f0d87a..778f74916 100644 --- a/src/vm/jit/x86_64/emit.c +++ b/src/vm/jit/x86_64/emit.c @@ -48,7 +48,7 @@ #include "vm/jit/patcher-common.hpp" #include "vm/jit/replace.hpp" #include "vm/jit/trace.hpp" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" /* emit_load ******************************************************************* diff --git a/src/vm/jit/x86_64/linux/md-os.c b/src/vm/jit/x86_64/linux/md-os.c index 1c30b8bbf..ca42a1926 100644 --- a/src/vm/jit/x86_64/linux/md-os.c +++ b/src/vm/jit/x86_64/linux/md-os.c @@ -44,7 +44,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #include "vm/jit/stacktrace.hpp" diff --git a/src/vm/jit/x86_64/solaris/md-os.c b/src/vm/jit/x86_64/solaris/md-os.c index cce569be9..e9f7b838f 100644 --- a/src/vm/jit/x86_64/solaris/md-os.c +++ b/src/vm/jit/x86_64/solaris/md-os.c @@ -42,7 +42,7 @@ #include "vm/jit/asmpart.h" #include "vm/jit/executionstate.h" -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #include "vm/jit/stacktrace.hpp" diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index 448e4a7e9..43fb31c9a 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -101,7 +101,7 @@ # include "vm/jit/python.h" #endif -#include "vm/jit/trap.h" +#include "vm/jit/trap.hpp" #if defined(ENABLE_JVMTI) # include "native/jvmti/cacaodbg.h"