/* src/vm/initialize.c - static class initializer functions
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ 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
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 4552 2006-03-04 17:15:44Z twisti $
-
*/
#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 **********************************************************/
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 (CLASS_IS_OR_ALMOST_INITIALIZED(c)) {
-#if defined(USE_THREADS)
- builtin_monitorexit((java_objectheader *) c);
-#endif
+ LOCK_MONITOR_EXIT(c);
return true;
}
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) */
c->state &= ~CLASS_INITIALIZING;
-#if defined(USE_THREADS)
- /* leave the monitor */
-
- builtin_monitorexit((java_objectheader *) c);
-#endif
+ LOCK_MONITOR_EXIT(c);
return r;
}
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 *cause;
+ classinfo *class;
/* maybe the class is not already linked */
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;
}
}
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);
log_message_class("Starting static class initializer for class: ", c);
#endif
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
- b = blockInts;
- blockInts = 0;
-#endif
-
/* now call the initializer */
- (void) vm_call_method_intern(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;
+ 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;