* src/vm/exceptions.h (EXCEPTION_LOAD_DISP_NULLPOINTER)
authortwisti <none@none>
Tue, 5 Dec 2006 21:10:54 +0000 (21:10 +0000)
committertwisti <none@none>
Tue, 5 Dec 2006 21:10:54 +0000 (21:10 +0000)
(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.

src/vm/exceptions.h
src/vm/jit/powerpc/darwin/md-os.c
src/vm/jit/powerpc/emit.c
src/vm/signal.c

index db01a530f39fd4ed625540355328370cebb932f8..e3e1d2c9f5c65b2260ede0c487c66403dd564153 100644 (file)
@@ -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 $
 
 */
 
 #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
index 837624659f4fcc0fb1b95323d90225fba33b6b2e..c90f8d8bea1c947be76cf63d39f6929fecb51b9d 100644 (file)
@@ -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;
 }
 
 
index 64f46ba9d2c93e2d9edcf54702d11b752e695794..db8d3240ddc62f3ecbab46eef0b5b84af89c9f86 100644 (file)
@@ -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
 }
 
 
index 89e0ee04e1982b341ca3ee91a89d7e65076637b1..f8f4d33f403857ecc03dc9e46ddf8bb7e79dcef0 100644 (file)
@@ -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 */