Authors: Christian Thalinger
- $Id: exceptions.c 1845 2005-01-04 11:28:16Z twisti $
+ $Id: exceptions.c 1935 2005-02-10 11:01:26Z twisti $
*/
#include <stdarg.h>
#include <stdlib.h>
+#include "config.h"
+
#include "mm/memory.h"
#include "native/native.h"
#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Throwable.h"
#include "toolbox/logging.h"
+#include "vm/class.h"
+#include "vm/exceptions.h"
#include "vm/global.h"
#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/stringlocal.h"
#include "vm/tables.h"
#include "vm/jit/asmpart.h"
#include "vm/jit/jit.h"
-#include "vm/options.h"
-/* system exception classes required in cacao */
+/* for raising exceptions from native methods */
-classinfo *class_java_lang_Throwable;
-classinfo *class_java_lang_Exception;
-classinfo *class_java_lang_Error;
-classinfo *class_java_lang_OutOfMemoryError;
+#if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
+java_objectheader* _exceptionptr = NULL;
+#endif
/* exception/error super class */
const char *string_java_lang_IndexOutOfBoundsException =
"java/lang/IndexOutOfBoundsException";
+const char *string_java_lang_InstantiationException =
+ "java/lang/InstantiationException";
+
const char *string_java_lang_InterruptedException =
"java/lang/InterruptedException";
"java/lang/VirtualMachineError";
-/* init_system_exceptions *****************************************************
+/* init_system_exceptions ******************************************************
- load, link and compile exceptions used in the system
+ Load and link exceptions used in the system.
*******************************************************************************/
-bool init_system_exceptions(void)
+bool exceptions_init(void)
{
/* java/lang/Throwable */
- class_java_lang_Throwable =
- class_new(utf_new_char(string_java_lang_Throwable));
-
- if (!class_load(class_java_lang_Throwable))
- return false;
-
- if (!class_link(class_java_lang_Throwable))
+ if (!class_load(class_java_lang_Throwable) ||
+ !class_link(class_java_lang_Throwable))
return false;
/* java/lang/Exception */
- class_java_lang_Exception =
- class_new(utf_new_char(string_java_lang_Exception));
-
- if (!class_load(class_java_lang_Exception))
- return false;
-
- if (!class_link(class_java_lang_Exception))
+ if (!class_load(class_java_lang_Exception) ||
+ !class_link(class_java_lang_Exception))
return false;
/* java/lang/Error */
- class_java_lang_Error =
- class_new(utf_new_char(string_java_lang_Error));
-
- if (!class_load(class_java_lang_Error))
- return false;
-
- if (!class_link(class_java_lang_Error))
+ if (!class_load(class_java_lang_Error) ||
+ !class_link(class_java_lang_Error))
return false;
/* java/lang/OutOfMemoryError */
- class_java_lang_OutOfMemoryError =
- class_new(utf_new_char(string_java_lang_OutOfMemoryError));
-
- if (!class_load(class_java_lang_OutOfMemoryError))
- return false;
-
- if (!class_link(class_java_lang_OutOfMemoryError))
+ if (!class_load(class_java_lang_OutOfMemoryError) ||
+ !class_link(class_java_lang_OutOfMemoryError))
return false;
return true;
c = xptr->vftbl->class;
pss = class_resolveclassmethod(c,
- utf_new_char("printStackTrace"),
- utf_new_char("()V"),
+ utf_printStackTrace,
+ utf_void__void,
class_java_lang_Object,
false);
fflush(stderr);
/* good bye! */
- if (doexit) {
+
+ if (doexit)
exit(1);
- }
}
}
/* convert to classname */
- for (i = len - 1; i >= 0; i--) {
+ for (i = len - 1; i >= 0; i--)
if (tmp[i] == '/') tmp[i] = '.';
- }
fprintf(stderr, "Exception in thread \"main\" %s", tmp);
fflush(stderr);
/* good bye! */
+
exit(1);
}
Authors: Christian Thalinger
- $Id: exceptions.h 1846 2005-01-04 11:28:46Z twisti $
+ $Id: exceptions.h 1935 2005-02-10 11:01:26Z twisti $
*/
#define _EXCEPTIONS_H
+#include "config.h"
+
#include "vm/global.h"
#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Throwable.h"
+#include "vm/builtin.h"
+#include "vm/class.h"
+
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+
+#define exceptionptr builtin_get_exceptionptrptr()
+#define threadrootmethod builtin_get_threadrootmethod()
+
+#else /* defined(USE_THREADS) && defined(NATIVE_THREADS) */
+#define exceptionptr (&_exceptionptr)
+#define threadrootmethod (&_threadrootmethod)
-/* system exception classes required in cacao */
+#endif /* defined(USE_THREADS) && defined(NATIVE_THREADS) */
-extern classinfo *class_java_lang_Throwable;
-extern classinfo *class_java_lang_Exception;
-extern classinfo *class_java_lang_Error;
-extern classinfo *class_java_lang_OutOfMemoryError;
+#if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
+extern java_objectheader *_exceptionptr;
+extern methodinfo* _threadrootmethod;
+#endif /* !defined(USE_THREADS) || !defined(NATIVE_THREADS) */
/* exception/error super class */
extern const char *string_java_lang_IllegalArgumentException;
extern const char *string_java_lang_IllegalMonitorStateException;
extern const char *string_java_lang_IndexOutOfBoundsException;
+extern const char *string_java_lang_InstantiationException;
extern const char *string_java_lang_InterruptedException;
extern const char *string_java_lang_NegativeArraySizeException;
extern const char *string_java_lang_NoSuchFieldException;
extern const char *string_java_lang_VirtualMachineError;
-/* function prototypes */
+/* function prototypes ********************************************************/
-/* load, link and compile exceptions used in the system */
+/* load and link exceptions used in the system */
-bool init_system_exceptions(void);
+bool exceptions_init(void);
/* exception throwing functions */