home *** CD-ROM | disk | FTP | other *** search
- /*
- * exception.c
- * Handle exceptions.
- *
- * Copyright (c) 1996 Systems Architecture Research Centre,
- * City University, London, UK.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
- */
-
- #define DEBUG
-
- #include <stdio.h>
- #include <assert.h>
- #include <signal.h>
- #include "object.h"
- #include "classMethod.h"
- #include "exception.h"
- #include "baseClasses.h"
- #include "lookup.h"
- #include "md.h"
-
- object* ClassFormatError;
- object* ClassFormatError;
- object* LinkageError;
- object* NoClassDefFoundError;
- object* NoSuchFieldError;
- object* NoSuchMethodError;
- object* OutOfMemoryError;
- object* UnsatisfiedLinkError;
- object* VirtualMachineError;
- object* ClassCircularityError;
- object* NegativeArraySizeException;
- object* ClassCastException;
- object* IllegalMonitorStateException;
- object* NullPointerException;
-
- static void nullException(int);
-
- /*
- * Setup the internal exceptions.
- */
- void
- initExceptions(void)
- {
- #define EXCEPTION(s) alloc_object(lookupClass(addString(#s)), true)
-
- ClassFormatError = EXCEPTION(java/lang/ClassFormatError);
- LinkageError = EXCEPTION(java/lang/LinkageError);
- NoClassDefFoundError = EXCEPTION(java/lang/NoClassDefFoundError);
- NoSuchFieldError = EXCEPTION(java/lang/NoSuchFieldError);
- NoSuchMethodError = EXCEPTION(java/lang/NoSuchMethodError);
- OutOfMemoryError = EXCEPTION(java/lang/OutOfMemoryError);
- UnsatisfiedLinkError = EXCEPTION(java/lang/UnsatisfiedLinkError);
- VirtualMachineError = EXCEPTION(java/lang/VirtualMachineError);
- ClassCircularityError = EXCEPTION(java/lang/ClassCircularityError);
- NegativeArraySizeException = EXCEPTION(java/lang/NegativeArraySizeException);
- ClassCastException = EXCEPTION(java/lang/ClassCastException);
- IllegalMonitorStateException = EXCEPTION(java/lang/IllegalMonitorStateException);
- NullPointerException = EXCEPTION(java/lang/NullPointerException);
-
- initClasses();
-
- #if !defined(DEBUG)
- /* Catch signal we need to convert to exceptions */
- #if defined(SIGSEGV)
- signal(SIGSEGV, nullException);
- #endif
- #if defined(SIGBUS)
- signal(SIGBUS, nullException);
- #endif
- #endif
- }
-
- /*
- * Throw an exception.
- */
- void
- throwException(object* eobj, void* fptr)
- {
- exceptionFrame* firstFrame;
- exceptionFrame* frame;
- classes* class;
- exceptionInfo einfo;
-
- if (eobj == 0) {
- fprintf(stderr, "Exception thrown on null object ... aborting\n");
- exit(1);
- }
-
- class = eobj->mtable->class;
-
- firstFrame = FIRSTFRAME(fptr);
- for (frame = firstFrame; frame != 0; frame = NEXTFRAME(frame)) {
- findExceptionInMethod((nativecode*)frame->retpc, class, &einfo);
- if (einfo.handler == 0) {
- continue;
- }
- /* Goto the exception handler */
- CALL_KAFFE_EXCEPTION(frame, einfo, eobj);
- }
-
- fprintf(stderr, "Failed to catch exception ... aborting:\n\t%s\n", class->name);
- fflush(stderr);
- exit(1);
- }
-
- /*
- * Null exception - catches bad memory accesses.
- */
- static
- void
- nullException(int sig)
- {
- /* I really need to check the fault address is null but I dont
- have the info at the moment. */
- throwException(NullPointerException, 0 /* dummy */);
- }
-