From: twisti Date: Tue, 5 Dec 2006 21:10:54 +0000 (+0000) Subject: * src/vm/exceptions.h (EXCEPTION_LOAD_DISP_NULLPOINTER) X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=00a0869f40b65c869faa0c3d14b65902018fbaf1;p=cacao.git * src/vm/exceptions.h (EXCEPTION_LOAD_DISP_NULLPOINTER) (EXCEPTION_LOAD_DISP_ARITHMETIC) (EXCEPTION_LOAD_DISP_ARRAYINDEXOUTOFBOUNDS) (EXCEPTION_LOAD_DISP_CLASSCAST, EXCEPTION_LOAD_DISP_PATCHER): Defined. * src/vm/signal.c (signal_init): Removed checknull-check. * src/vm/jit/powerpc/emit.c (vm/exceptions.h): Added. (emit_arrayindexoutofbounds_check): Added hardware-exception version. * src/vm/jit/powerpc/darwin/md-os.c (md_signal_handler_sigsegv): Started to handle other hardware-exceptions. --- diff --git a/src/vm/exceptions.h b/src/vm/exceptions.h index db01a530f..e3e1d2c9f 100644 --- a/src/vm/exceptions.h +++ b/src/vm/exceptions.h @@ -28,7 +28,7 @@ Changes: Edwin Steiner - $Id: exceptions.h 5935 2006-11-08 20:27:37Z twisti $ + $Id: exceptions.h 6123 2006-12-05 21:10:54Z twisti $ */ @@ -49,6 +49,27 @@ #include "vm/method.h" +/* hardware-exception defines ************************************************** + + These defines define the load-offset which indicates the given + exception. + + ATTENTION: These offsets need NOT to 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. + +*******************************************************************************/ + +#define EXCEPTION_LOAD_DISP_NULLPOINTER 0 +#define EXCEPTION_LOAD_DISP_ARITHMETIC 1 +#define EXCEPTION_LOAD_DISP_ARRAYINDEXOUTOFBOUNDS 2 +#define EXCEPTION_LOAD_DISP_CLASSCAST 3 + +#define EXCEPTION_LOAD_DISP_PATCHER 5 + + +/* exception pointer **********************************************************/ + #if defined(ENABLE_THREADS) #define exceptionptr &(THREADOBJECT->_exceptionptr) #else diff --git a/src/vm/jit/powerpc/darwin/md-os.c b/src/vm/jit/powerpc/darwin/md-os.c index 837624659..c90f8d8be 100644 --- a/src/vm/jit/powerpc/darwin/md-os.c +++ b/src/vm/jit/powerpc/darwin/md-os.c @@ -28,7 +28,7 @@ Changes: - $Id: md-os.c 5074 2006-07-04 16:05:35Z twisti $ + $Id: md-os.c 6123 2006-12-05 21:10:54Z twisti $ */ @@ -66,11 +66,14 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p) ptrint *gregs; u4 instr; s4 reg; + s4 disp; ptrint addr; u1 *pv; u1 *sp; u1 *ra; u1 *xpc; + stackframeinfo sfi; + java_objectheader *o; _uc = (ucontext_t *) _p; _mc = _uc->uc_mcontext; @@ -81,26 +84,53 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p) gregs = &_ss->r0; instr = *((u4 *) _ss->srr0); - reg = (instr >> 16) & 31; - addr = gregs[reg]; + reg = (instr >> 16) & 31; + disp = (instr & 0xffff); + addr = gregs[reg]; + + pv = (u1 *) _ss->r13; + sp = (u1 *) _ss->r1; + ra = (u1 *) _ss->lr; /* this is correct for leafs */ + xpc = (u1 *) _ss->srr0; + + /* create stackframeinfo */ + + stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc); + + if (reg == REG_ZERO) { + switch (disp) { + case EXCEPTION_LOAD_DISP_ARITHMETIC: + vm_abort("ArithmeticException"); + break; + case EXCEPTION_LOAD_DISP_ARRAYINDEXOUTOFBOUNDS: + log_println("ArrayIndexOutOfBoundsException"); + o = new_arrayindexoutofboundsexception(0); + break; + case EXCEPTION_LOAD_DISP_CLASSCAST: + vm_abort("ClassCastException"); + break; + default: + vm_abort("unknown exception %d", disp); + } + } + else if (addr == 0) { + o = exceptions_new_nullpointerexception(); + } + else { + codegen_get_pv_from_pc(xpc); - if (addr == 0) { - pv = (u1 *) _ss->r13; - sp = (u1 *) _ss->r1; - ra = (u1 *) _ss->lr; /* this is correct for leafs */ - xpc = (u1 *) _ss->srr0; + /* this should not happen */ - _ss->r11 = - (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc); + assert(0); + } - _ss->r12 = (ptrint) xpc; - _ss->srr0 = (ptrint) asm_handle_exception; + /* remove stackframeinfo */ - } else { - throw_cacao_exception_exit(string_java_lang_InternalError, - "Segmentation fault: 0x%08lx at 0x%08lx", - addr, _ss->srr0); - } + stacktrace_remove_stackframeinfo(&sfi); + + _ss->r11 = (ptrint) o; + _ss->r12 = (ptrint) xpc; + _ss->srr0 = (ptrint) asm_handle_exception; } diff --git a/src/vm/jit/powerpc/emit.c b/src/vm/jit/powerpc/emit.c index 64f46ba9d..db8d3240d 100644 --- a/src/vm/jit/powerpc/emit.c +++ b/src/vm/jit/powerpc/emit.c @@ -43,6 +43,7 @@ #include "mm/memory.h" #include "vm/builtin.h" +#include "vm/exceptions.h" #include "vm/options.h" #include "vm/jit/asmpart.h" #include "vm/jit/dseg.h" @@ -295,12 +296,19 @@ void emit_nullpointer_check(codegendata *cd, s4 reg) void emit_arrayindexoutofbounds_check(codegendata *cd, s4 s1, s4 s2) { +#if 0 if (checkbounds) { M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size)); M_CMPU(s2, REG_ITMP3); M_BGE(0); codegen_add_arrayindexoutofboundsexception_ref(cd, s2); } +#else + M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size)); + M_CMPU(s2, REG_ITMP3); + M_BLT(1); + M_ALD_INTERN(s2, REG_ZERO, EXCEPTION_LOAD_DISP_ARRAYINDEXOUTOFBOUNDS); +#endif } diff --git a/src/vm/signal.c b/src/vm/signal.c index 89e0ee04e..f8f4d33f4 100644 --- a/src/vm/signal.c +++ b/src/vm/signal.c @@ -26,7 +26,7 @@ Authors: Christian Thalinger - $Id: signal.c 5979 2006-11-14 21:56:17Z twisti $ + $Id: signal.c 6123 2006-12-05 21:10:54Z twisti $ */ @@ -84,18 +84,16 @@ void signal_init(void) # endif /* catch NullPointerException/StackOverFlowException */ - if (!checknull) { - act.sa_sigaction = md_signal_handler_sigsegv; - act.sa_flags = SA_NODEFER | SA_SIGINFO; + act.sa_sigaction = md_signal_handler_sigsegv; + act.sa_flags = SA_NODEFER | SA_SIGINFO; #if defined(SIGSEGV) - sigaction(SIGSEGV, &act, NULL); + sigaction(SIGSEGV, &act, NULL); #endif #if defined(SIGBUS) - sigaction(SIGBUS, &act, NULL); + sigaction(SIGBUS, &act, NULL); #endif - } /* catch ArithmeticException */