X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Finitialize.c;h=2c6ff024ddad81c18b4997484c477006380cbfe5;hb=8c81647e1c96715f45498a3ada7f795b5c9dfe81;hp=c3a86b719c61bc284c48330000e3761b9b5d82bf;hpb=25eef6ad6910c09c86e930af6e5491e2d2ef0130;p=cacao.git diff --git a/src/vm/initialize.c b/src/vm/initialize.c index c3a86b719..2c6ff024d 100644 --- a/src/vm/initialize.c +++ b/src/vm/initialize.c @@ -1,9 +1,7 @@ /* src/vm/initialize.c - static class initializer functions - Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel, - C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, - E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, - J. Wenninger, Institut f. Computersprachen - TU Wien + Copyright (C) 1996-2005, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -22,16 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Contact: cacao@cacaojvm.org - - Authors: Reinhard Grafl - - Changes: Mark Probst - Andreas Krall - Christian Thalinger - - $Id: initialize.c 5123 2006-07-12 21:45:34Z twisti $ - */ @@ -41,30 +29,73 @@ #include "vm/types.h" -#if defined(ENABLE_THREADS) -# include "threads/native/lock.h" -#else -# include "threads/none/lock.h" -#endif +#include "threads/lock-common.h" #include "vm/global.h" #include "vm/initialize.h" #include "vm/builtin.h" -#include "vm/class.h" -#include "vm/loader.h" #include "vm/exceptions.h" -#include "vm/options.h" -#include "vm/statistics.h" #include "vm/stringlocal.h" #include "vm/vm.h" + #include "vm/jit/asmpart.h" +#include "vmcore/class.h" +#include "vmcore/loader.h" +#include "vmcore/options.h" + +#if defined(ENABLE_STATISTICS) +# include "vmcore/statistics.h" +#endif + /* private functions **********************************************************/ static bool initialize_class_intern(classinfo *c); +/* initialize_init ************************************************************* + + Initialize important system classes. + +*******************************************************************************/ + +void initialize_init(void) +{ + TRACESUBSYSTEMINITIALIZATION("initialize_init"); + +#if defined(ENABLE_JAVASE) +# if defined(WITH_CLASSPATH_GNU) + + /* Nothing. */ + +# elif defined(WITH_CLASSPATH_SUN) + + if (!initialize_class(class_java_lang_String)) + vm_abort("initialize_init: Initialization failed: java.lang.String"); + + if (!initialize_class(class_java_lang_System)) + vm_abort("initialize_init: Initialization failed: java.lang.System"); + + if (!initialize_class(class_java_lang_ThreadGroup)) + vm_abort("initialize_init: Initialization failed: java.lang.ThreadGroup"); + + if (!initialize_class(class_java_lang_Thread)) + vm_abort("initialize_init: Initialization failed: java.lang.Thread"); + +# else +# error unknown classpath configuration +# endif + +#elif defined(ENABLE_JAVAME_CLDC1_1) + + /* Nothing. */ + +#else +# error unknown Java configuration +#endif +} + /* initialize_class ************************************************************ In Java, every class can have a static initialization @@ -95,7 +126,7 @@ bool initialize_class(classinfo *c) error and we have to throw a NoClassDefFoundError */ if (c->state & CLASS_ERROR) { - *exceptionptr = new_noclassdeffounderror(c->name); + exceptions_throw_noclassdeffounderror(c->name); LOCK_MONITOR_EXIT(c); @@ -137,8 +168,9 @@ bool initialize_class(classinfo *c) static bool initialize_class_intern(classinfo *c) { - methodinfo *m; - java_objectheader *xptr; + methodinfo *m; + java_handle_t *cause; + classinfo *class; /* maybe the class is not already linked */ @@ -151,19 +183,19 @@ static bool initialize_class_intern(classinfo *c) count_class_inits++; #endif - /* initialize super class */ + /* Initialize super class. */ - if (c->super.cls) { - if (!(c->super.cls->state & CLASS_INITIALIZED)) { + if (c->super != NULL) { + if (!(c->super->state & CLASS_INITIALIZED)) { #if !defined(NDEBUG) if (initverbose) log_message_class_message_class("Initialize super class ", - c->super.cls, + c->super, " from ", c); #endif - if (!initialize_class(c->super.cls)) + if (!initialize_class(c->super)) return false; } } @@ -172,7 +204,7 @@ static bool initialize_class_intern(classinfo *c) m = class_findmethod(c, utf_clinit, utf_void__void); - if (!m) { + if (m == NULL) { #if !defined(NDEBUG) if (initverbose) log_message_class("Class has no static class initializer: ", c); @@ -196,25 +228,30 @@ static bool initialize_class_intern(classinfo *c) /* we have an exception or error */ - xptr = *exceptionptr; + cause = exceptions_get_exception(); - if (xptr) { + if (cause != NULL) { /* class is NOT initialized and is marked with error */ c->state |= CLASS_ERROR; - /* is this an exception, than wrap it */ + /* Load java/lang/Exception for the instanceof check. */ + + class = load_class_bootstrap(utf_java_lang_Exception); + + if (class == NULL) + return false; + + /* Is this an exception? Yes, than wrap it. */ - if (builtin_instanceof(xptr, class_java_lang_Exception)) { + if (builtin_instanceof(cause, class)) { /* clear exception, because we are calling jit code again */ - *exceptionptr = NULL; + exceptions_clear_exception(); /* wrap the exception */ - *exceptionptr = - new_exception_throwable(string_java_lang_ExceptionInInitializerError, - (java_lang_Throwable *) xptr); + exceptions_throw_exceptionininitializererror(cause); } return false;