X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Finitialize.c;h=cc847933a6c921c2124d993f1508da4bc74dce61;hb=9f859ad50d3d5d98c185d40b86b2179bc4dc9aeb;hp=90c5b5a4c0133cf2095e008001aa50f783863d01;hpb=9e0227a70ac3c065033903eab85c9ca29e12d3dc;p=cacao.git diff --git a/src/vm/initialize.c b/src/vm/initialize.c index 90c5b5a4c..cc847933a 100644 --- a/src/vm/initialize.c +++ b/src/vm/initialize.c @@ -1,9 +1,9 @@ /* src/vm/initialize.c - static class initializer functions - Copyright (C) 1996-2005 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 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 This file is part of CACAO. @@ -19,38 +19,37 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. - - Contact: cacao@complang.tuwien.ac.at - - Authors: Reinhard Grafl - - Changes: Mark Probst - Andreas Krall - Christian Thalinger - - $Id: initialize.c 3888 2005-12-05 22:08:45Z twisti $ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ +#include "config.h" + #include -#include "config.h" #include "vm/types.h" +#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 **********************************************************/ @@ -72,19 +71,13 @@ bool initialize_class(classinfo *c) if (!makeinitializations) return true; -#if defined(USE_THREADS) - /* enter a monitor on the class */ - - builtin_monitorenter((java_objectheader *) c); -#endif + LOCK_MONITOR_ENTER(c); /* maybe the class is already initalized or the current thread, which can pass the monitor, is currently initalizing this class */ - if ((c->state & CLASS_INITIALIZING) || (c->state & CLASS_INITIALIZED)) { -#if defined(USE_THREADS) - builtin_monitorexit((java_objectheader *) c); -#endif + if (CLASS_IS_OR_ALMOST_INITIALIZED(c)) { + LOCK_MONITOR_EXIT(c); return true; } @@ -93,11 +86,9 @@ 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); -#if defined(USE_THREADS) - builtin_monitorexit((java_objectheader *) c); -#endif + LOCK_MONITOR_EXIT(c); /* ...but return true, this is ok (mauve test) */ @@ -122,11 +113,7 @@ bool initialize_class(classinfo *c) c->state &= ~CLASS_INITIALIZING; -#if defined(USE_THREADS) - /* leave the monitor */ - - builtin_monitorexit((java_objectheader *) c); -#endif + LOCK_MONITOR_EXIT(c); return r; } @@ -141,11 +128,8 @@ bool initialize_class(classinfo *c) static bool initialize_class_intern(classinfo *c) { - methodinfo *m; - java_objectheader *xptr; -#if defined(USE_THREADS) && !defined(NATIVE_THREADS) - int b; -#endif + methodinfo *m; + java_handle_t *xptr; /* maybe the class is not already linked */ @@ -153,7 +137,7 @@ static bool initialize_class_intern(classinfo *c) if (!link_class(c)) return false; -#if defined(STATISTICS) +#if defined(ENABLE_STATISTICS) if (opt_stat) count_class_inits++; #endif @@ -162,11 +146,13 @@ static bool initialize_class_intern(classinfo *c) if (c->super.cls) { if (!(c->super.cls->state & CLASS_INITIALIZED)) { +#if !defined(NDEBUG) if (initverbose) log_message_class_message_class("Initialize super class ", c->super.cls, " from ", c); +#endif if (!initialize_class(c->super.cls)) return false; @@ -178,8 +164,10 @@ static bool initialize_class_intern(classinfo *c) m = class_findmethod(c, utf_clinit, utf_void__void); if (!m) { +#if !defined(NDEBUG) if (initverbose) log_message_class("Class has no static class initializer: ", c); +#endif return true; } @@ -188,28 +176,20 @@ static bool initialize_class_intern(classinfo *c) /* if (!(m->flags & ACC_STATIC)) { */ /* log_text("Class initializer is not static!"); */ +#if !defined(NDEBUG) if (initverbose) log_message_class("Starting static class initializer for class: ", c); - -#if defined(USE_THREADS) && !defined(NATIVE_THREADS) - b = blockInts; - blockInts = 0; #endif /* now call the initializer */ - asm_calljavafunction(m, NULL, NULL, NULL, NULL); - -#if defined(USE_THREADS) && !defined(NATIVE_THREADS) - assert(blockInts == 0); - blockInts = b; -#endif + (void) vm_call_method(m, NULL); /* we have an exception or error */ - xptr = *exceptionptr; + xptr = exceptions_get_exception(); - if (xptr) { + if (xptr != NULL) { /* class is NOT initialized and is marked with error */ c->state |= CLASS_ERROR; @@ -219,20 +199,20 @@ static bool initialize_class_intern(classinfo *c) if (builtin_instanceof(xptr, class_java_lang_Exception)) { /* 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(xptr); } return false; } +#if !defined(NDEBUG) if (initverbose) log_message_class("Finished static class initializer for class: ", c); +#endif return true; }