Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/preload.h |    1 +
 vm/jato.c            |   15 ++++++++++++++-
 vm/preload.c         |    9 +++++++++
 3 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/include/vm/preload.h b/include/vm/preload.h
index d2571e0..2a739f0 100644
--- a/include/vm/preload.h
+++ b/include/vm/preload.h
@@ -68,6 +68,7 @@ extern struct vm_method *vm_java_lang_ThreadGroup_init;
 extern struct vm_method *vm_java_lang_ThreadGroup_addThread;
 extern struct vm_method *vm_java_lang_VMThread_init;
 extern struct vm_method *vm_java_lang_VMThread_run;
+extern struct vm_method *vm_java_lang_System_exit;
 
 int preload_vm_classes(void);
 
diff --git a/vm/jato.c b/vm/jato.c
index bc81864..1319ba6 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -75,6 +75,16 @@
 static bool perf_enabled;
 char *exe_name;
 
+static void __attribute__((noreturn)) vm_exit(int status)
+{
+       clear_exception();
+       vm_call_method(vm_java_lang_System_exit, status);
+       if (exception_occurred())
+               vm_print_exception(exception_occurred());
+
+       error("System.exit() returned");
+}
+
 static struct vm_object *native_vmstackwalker_getclasscontext(void)
 {
        struct stack_trace_elem st_elem;
@@ -956,5 +966,8 @@ out_check_exception:
 
        vm_thread_wait_for_non_daemons();
 out:
-       return status;
+       vm_exit(status);
+
+       /* XXX: We should not get there */
+       return EXIT_FAILURE;
 }
diff --git a/vm/preload.c b/vm/preload.c
index de2922d..7ea4902 100644
--- a/vm/preload.c
+++ b/vm/preload.c
@@ -65,6 +65,7 @@ struct vm_class *vm_java_lang_Thread;
 struct vm_class *vm_java_lang_ThreadGroup;
 struct vm_class *vm_java_lang_VMThread;
 struct vm_class *vm_java_lang_IllegalMonitorStateException;
+struct vm_class *vm_java_lang_System;
 struct vm_class *vm_boolean_class;
 struct vm_class *vm_char_class;
 struct vm_class *vm_float_class;
@@ -103,6 +104,7 @@ static const struct preload_entry preload_entries[] = {
        { "java/lang/ThreadGroup", &vm_java_lang_ThreadGroup },
        { "java/lang/VMThread", &vm_java_lang_VMThread },
        { "java/lang/IllegalMonitorStateException", 
&vm_java_lang_IllegalMonitorStateException },
+       { "java/lang/System",   &vm_java_lang_System },
 };
 
 static const struct preload_entry primitive_preload_entries[] = {
@@ -178,6 +180,7 @@ struct vm_method *vm_java_lang_ThreadGroup_init;
 struct vm_method *vm_java_lang_ThreadGroup_addThread;
 struct vm_method *vm_java_lang_VMThread_init;
 struct vm_method *vm_java_lang_VMThread_run;
+struct vm_method *vm_java_lang_System_exit;
 
 static const struct method_preload_entry method_preload_entries[] = {
        {
@@ -264,6 +267,12 @@ static const struct method_preload_entry 
method_preload_entries[] = {
                "()V",
                &vm_java_lang_VMThread_run,
        },
+       {
+               &vm_java_lang_System,
+               "exit",
+               "(I)V",
+               &vm_java_lang_System_exit,
+       },
 };
 
 int preload_vm_classes(void)
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to