* src/vm/vm.c (vm_abort): New method.
authortwisti <none@none>
Mon, 22 May 2006 09:06:44 +0000 (09:06 +0000)
committertwisti <none@none>
Mon, 22 May 2006 09:06:44 +0000 (09:06 +0000)
* src/vm/vm.h: Likewise.
* src/cacaoh/headers.c: Likewise.

* src/toolbox/logging.c (log_vprint): Made non-static.
* src/toolbox/logging.h (log_vprint): Added.

* src/threads/native/threads.c (threads_sem_init): Use vm_abort.
(threads_sem_wait): Likewise.
(threads_sem_post): Likewise.
(threads_current_time_is_earlier_than): Likewise.
(threads_init): Check for pthread_attr_init error.
(threads_start_thread): Check for errors of pthread calls. Set the
threads stack size.

src/cacaoh/headers.c
src/threads/native/threads.c
src/toolbox/logging.c
src/toolbox/logging.h
src/vm/vm.c
src/vm/vm.h

index f25c4ac2a02258afde966ced70386ceb74fd0de4..817eddccb66665e0cf62b376e78e93202fb29ed0 100644 (file)
@@ -31,7 +31,7 @@
             Christian Thalinger
                        Edwin Steiner
 
-   $Id: headers.c 4921 2006-05-15 14:24:36Z twisti $
+   $Id: headers.c 4938 2006-05-22 09:06:44Z twisti $
 
 */
 
@@ -102,6 +102,10 @@ java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwab
 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
 { return NULL; }
 
+void vm_abort(const char *text, ...)
+{
+       abort();
+}
 
 /* code patching functions */
 void patcher_builtin_arraycheckcast(u1 *sp) {}
index c9946172549c4948ce21117b3e01f921aee57f03..55aa25d8ba21e26ef2ab78b05bc47e66fd5d65e5 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: threads.c 4921 2006-05-15 14:24:36Z twisti $
+   $Id: threads.c 4938 2006-05-22 09:06:44Z twisti $
 
 */
 
@@ -324,9 +324,7 @@ void threads_sem_init(sem_t *sem, bool shared, int value)
                        return;
        } while (errno == EINTR);
 
-       fprintf(stderr,"error: sem_init returned unexpected error %d: %s\n",
-                       errno, strerror(errno));
-       abort();
+       vm_abort("sem_init failed: %s", strerror(errno));
 }
 
 
@@ -354,9 +352,7 @@ void threads_sem_wait(sem_t *sem)
                        return;
        } while (errno == EINTR);
 
-       fprintf(stderr,"error: sem_wait returned unexpected error %d: %s\n",
-                       errno, strerror(errno));
-       abort();
+       vm_abort("sem_wait failed: %s", strerror(errno));
 }
 
 
@@ -381,9 +377,7 @@ void threads_sem_post(sem_t *sem)
        if (r == 0)
                return;
 
-       fprintf(stderr,"error: sem_post returned unexpected error %d: %s\n",
-                       errno, strerror(errno));
-       abort();
+       vm_abort("sem_post failed: %s", strerror(errno));
 }
 
 
@@ -748,7 +742,7 @@ bool threads_init(void)
 
        mainthreadobj = (threadobject *) builtin_new(class_java_lang_VMThread);
 
-       if (!mainthreadobj)
+       if (mainthreadobj == NULL)
                return false;
 
        FREE(tempthread, threadobject);
@@ -787,7 +781,7 @@ bool threads_init(void)
 
        mainthread = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
 
-       if (!mainthread)
+       if (mainthread == NULL)
                throw_exception_exit();
 
        mainthreadobj->o.thread = mainthread;
@@ -800,7 +794,7 @@ bool threads_init(void)
                                                                          class_java_lang_Thread,
                                                                          true);
 
-       if (!method)
+       if (method == NULL)
                return false;
 
        (void) vm_call_method(method, (java_objectheader *) mainthread,
@@ -819,7 +813,7 @@ bool threads_init(void)
                                                                          class_java_lang_ThreadGroup,
                                                                          true);
 
-       if (!method)
+       if (method == NULL)
                return false;
 
        (void) vm_call_method(method, (java_objectheader *) threadgroup,
@@ -830,7 +824,13 @@ bool threads_init(void)
 
        threads_set_thread_priority(pthread_self(), 5);
 
-       pthread_attr_init(&threadattr);
+       /* initialize the thread attribute object */
+
+       if (pthread_attr_init(&threadattr)) {
+               log_println("pthread_attr_init failed: %s", strerror(errno));
+               return false;
+       }
+
        pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED);
 
        /* everything's ok */
@@ -1150,10 +1150,11 @@ static void *threads_startup_thread(void *t)
 
 void threads_start_thread(java_lang_Thread *t, functionptr function)
 {
-       sem_t         sem;
-       sem_t         sem_first;
-       startupinfo   startup;
-       threadobject *thread;
+       sem_t          sem;
+       sem_t          sem_first;
+       pthread_attr_t attr;
+       startupinfo    startup;
+       threadobject  *thread;
 
        thread = (threadobject *) t->vmThread;
 
@@ -1168,13 +1169,20 @@ void threads_start_thread(java_lang_Thread *t, functionptr function)
        threads_sem_init(&sem, 0, 0);
        threads_sem_init(&sem_first, 0, 0);
 
+       /* initialize thread attribute object */
+
+       if (pthread_attr_init(&attr))
+               vm_abort("pthread_attr_init failed: %s", strerror(errno));
+
+       /* initialize thread stacksize */
+
+       if (pthread_attr_setstacksize(&attr, opt_stacksize))
+               vm_abort("pthread_attr_setstacksize failed: %s", strerror(errno));
+
        /* create the thread */
 
-       if (pthread_create(&thread->tid, &threadattr, threads_startup_thread,
-                                          &startup)) {
-               log_text("pthread_create failed");
-               assert(0);
-       }
+       if (pthread_create(&thread->tid, &attr, threads_startup_thread, &startup))
+               vm_abort("pthread_create failed: %s", strerror(errno));
 
        /* signal that pthread_create has returned, so thread->tid is valid */
 
@@ -1284,11 +1292,8 @@ static bool threads_current_time_is_earlier_than(const struct timespec *tv)
 
        /* get current time */
 
-       if (gettimeofday(&tvnow, NULL) != 0) {
-               fprintf(stderr,"error: gettimeofday returned unexpected error %d: %s\n",
-                               errno, strerror(errno));
-               abort();
-       }
+       if (gettimeofday(&tvnow, NULL) != 0)
+               vm_abort("gettimeofday failed: %s\n", strerror(errno));
 
        /* convert it to a timespec */
 
index 6c9b411da9e65920b1578a8cfdd43cd4999c517c..d6d87cd05cfa14b6a6e9916fe83c75b90305b001 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: logging.c 4921 2006-05-15 14:24:36Z twisti $
+   $Id: logging.c 4938 2006-05-22 09:06:44Z twisti $
 
 */
 
@@ -101,7 +101,7 @@ void log_start(void)
 
 *******************************************************************************/
 
-static void log_vprint(const char *text, va_list ap)
+void log_vprint(const char *text, va_list ap)
 {
        if (logfile)
                vfprintf(logfile, text, ap);
index c14f6ddf22b66f2d11df9689104f858ece56f7bf..188f5e31c4145ddbdd8ea452fe2063eb0f31de81 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christan Thalinger
 
-   $Id: logging.h 4375 2006-01-27 17:35:13Z twisti $
+   $Id: logging.h 4938 2006-05-22 09:06:44Z twisti $
 
 */
 
@@ -57,6 +57,7 @@ void log_init(const char *fname);
 
 void log_start(void);
 
+void log_vprint(const char *text, va_list ap);
 void log_print(const char *text, ...);
 void log_println(const char *text, ...);
 
index 3685969a33a7f56ac5bd8d86244919281c23096b..b584720f1afe4f1e4a5fd3decba7759a9541c312 100644 (file)
@@ -1388,6 +1388,32 @@ void vm_exit_handler(void)
 }
 
 
+/* vm_abort ********************************************************************
+
+   Prints an error message and aborts the VM.
+
+*******************************************************************************/
+
+void vm_abort(const char *text, ...)
+{
+       va_list ap;
+
+       /* print the log message */
+
+       log_start();
+
+       va_start(ap, text);
+       log_vprint(text, ap);
+       va_end(ap);
+
+       log_finish();
+
+       /* now abort the VM */
+
+       abort();
+}
+
+
 /* vm_vmargs_from_valist *******************************************************
 
    XXX
index c06ffb572c5b5997e1c23d8fa83af396d27ac33c..bc3deb12c27736b61e64f31d167b5e8bd9149f8e 100644 (file)
@@ -90,6 +90,8 @@ void vm_shutdown(s4 status);
 
 void vm_exit_handler(void);
 
+void vm_abort(const char *text, ...);
+
 /* Java method calling functions */
 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...);
 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,