When exception occures during exception allocation then
signal_new_exception() functions will return a negative value. If
exception occurres after new exception was allocated then new
exception is not signalled.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/jit/exception.h |    8 ++++----
 jit/exception.c         |   39 ++++++++++++++++++++++++---------------
 vm/object.c             |   14 ++++++++++++--
 3 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/include/jit/exception.h b/include/jit/exception.h
index af34041..813866b 100644
--- a/include/jit/exception.h
+++ b/include/jit/exception.h
@@ -55,10 +55,10 @@ void throw_exception_from_signal(void *ctx, struct 
vm_object *exception);
 void throw_exception_from_trampoline(void *ctx, struct vm_object *exception);
 void unwind(void);
 void signal_exception(struct vm_object *obj);
-void signal_new_exception(struct vm_class *vmc, const char *msg);
-void signal_new_exception_with_cause(struct vm_class *vmc,
-                                    struct vm_object *cause,
-                                    const char *msg);
+int signal_new_exception(struct vm_class *vmc, const char *msg);
+int signal_new_exception_with_cause(struct vm_class *vmc,
+                                   struct vm_object *cause,
+                                   const char *msg);
 void clear_exception(void);
 void init_exceptions(void);
 void thread_init_exceptions(void);
diff --git a/jit/exception.c b/jit/exception.c
index 709559c..649bedf 100644
--- a/jit/exception.c
+++ b/jit/exception.c
@@ -87,40 +87,49 @@ void signal_exception(struct vm_object *exception)
        if (exception_holder)
                return;
 
-       if (exception == NULL)
-               die("exception is NULL");
+       assert(exception);
 
        trampoline_exception_guard = trampoline_exceptions_guard_page;
        exception_guard  = exceptions_guard_page;
        exception_holder = exception;
 }
 
-void signal_new_exception(struct vm_class *vmc, const char *msg)
+int signal_new_exception(struct vm_class *vmc, const char *msg)
 {
-       struct vm_object *e;
+       struct vm_object *exception;
+
+       exception = new_exception(vmc, msg);
+       if (!exception) {
+               NOT_IMPLEMENTED;
+               return -1;
+       }
 
-       e = new_exception(vmc, msg);
-       signal_exception(e);
+       signal_exception(exception);
+       return 0;
 }
 
 typedef struct vm_object * (*vm_throwable_init_cause_fn)(struct vm_object *,
                                                         struct vm_object *);
 
-void signal_new_exception_with_cause(struct vm_class *vmc,
-                                    struct vm_object *cause,
-                                    const char *msg)
+int signal_new_exception_with_cause(struct vm_class *vmc,
+                                   struct vm_object *cause,
+                                   const char *msg)
 {
-       struct vm_object *e;
+       struct vm_object *exception;
        vm_throwable_init_cause_fn init_cause;
 
        init_cause = vm_method_trampoline_ptr(vm_java_lang_Throwable_initCause);
 
-       e = new_exception(vmc, msg);
-       if (!e || exception_occurred())
-               return;
+       exception = new_exception(vmc, msg);
+       if (!exception)
+               return -1;
 
-       init_cause(e, cause);
-       signal_exception(e);
+       init_cause(exception, cause);
+       if (exception_occurred())
+               return -1;
+
+       signal_exception(exception);
+       return 0;
 }
 
 void clear_exception(void)
diff --git a/vm/object.c b/vm/object.c
index 9be492e..78ec3b8 100644
--- a/vm/object.c
+++ b/vm/object.c
@@ -335,13 +335,20 @@ struct vm_object *new_exception(struct vm_class *vmc, 
const char *message)
        struct vm_object *obj;
 
        obj = vm_object_alloc(vmc);
-       if (!obj)
+       if (!obj) {
+               NOT_IMPLEMENTED;
                return NULL;
+       }
 
        if (message == NULL)
                message_str = NULL;
-       else
+       else {
                message_str = vm_object_alloc_string_from_c(message);
+               if (!message_str) {
+                       NOT_IMPLEMENTED;
+                       return NULL;
+               }
+       }
 
        mb = vm_class_get_method(vmc,
                "<init>", "(Ljava/lang/String;)V");
@@ -351,6 +358,9 @@ struct vm_object *new_exception(struct vm_class *vmc, const 
char *message)
        init = vm_method_trampoline_ptr(mb);
        init(obj, message_str);
 
+       if (exception_occurred())
+               return NULL;
+
        return obj;
 }
 
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to