/* src/vmcore/loader.c - class loader functions
- 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
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
+#include "vm/package.h"
#include "vm/primitive.h"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
Initializes the classpath list and loads classes required for the
primitive table.
+ NOTE: Exceptions thrown during VM initialization are caught in the
+ exception functions themselves.
+
*******************************************************************************/
void loader_preinit(void)
{
#if defined(ENABLE_THREADS)
list_classpath_entry *lce;
+#endif
+
+ TRACESUBSYSTEMINITIALIZATION("loader_preinit");
+#if defined(ENABLE_THREADS)
/* Initialize the monitor pointer for zip/jar file locking. */
for (lce = list_first(list_classpath_entries); lce != NULL;
hashtable_classloader = NEW(hashtable);
hashtable_create(hashtable_classloader, 10);
- /* Load the most basic class. */
+ /* Load the most basic classes. */
- if (!(class_java_lang_Object = load_class_bootstrap(utf_java_lang_Object)))
- vm_abort("loader_preinit: loading java/lang/Object failed");
+ assert(vm_initializing == true);
-#if defined(ENABLE_JAVASE)
- if (!(class_java_lang_Cloneable =
- load_class_bootstrap(utf_java_lang_Cloneable)))
- vm_abort("loader_preinit: loading java/lang/Cloneable failed");
+ class_java_lang_Object = load_class_bootstrap(utf_java_lang_Object);
- if (!(class_java_io_Serializable =
- load_class_bootstrap(utf_java_io_Serializable)))
- vm_abort("loader_preinit: loading java/io/Serializable failed");
+#if defined(ENABLE_JAVASE)
+ class_java_lang_Cloneable = load_class_bootstrap(utf_java_lang_Cloneable);
+ class_java_io_Serializable = load_class_bootstrap(utf_java_io_Serializable);
#endif
}
Loads all classes required in the VM.
+ NOTE: Exceptions thrown during VM initialization are caught in the
+ exception functions themselves.
+
*******************************************************************************/
void loader_init(void)
{
+ TRACESUBSYSTEMINITIALIZATION("loader_init");
+
/* Load primitive-type wrapping classes. */
+ assert(vm_initializing == true);
+
#if defined(ENABLE_JAVASE)
- if (!(class_java_lang_Void = load_class_bootstrap(utf_java_lang_Void)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_Void = load_class_bootstrap(utf_java_lang_Void);
#endif
- if (!(class_java_lang_Boolean =
- load_class_bootstrap(utf_java_lang_Boolean)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Byte = load_class_bootstrap(utf_java_lang_Byte)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Character =
- load_class_bootstrap(utf_java_lang_Character)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Short = load_class_bootstrap(utf_java_lang_Short)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Integer =
- load_class_bootstrap(utf_java_lang_Integer)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Long = load_class_bootstrap(utf_java_lang_Long)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Float = load_class_bootstrap(utf_java_lang_Float)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_Double = load_class_bootstrap(utf_java_lang_Double)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_Boolean = load_class_bootstrap(utf_java_lang_Boolean);
+ class_java_lang_Byte = load_class_bootstrap(utf_java_lang_Byte);
+ class_java_lang_Character = load_class_bootstrap(utf_java_lang_Character);
+ class_java_lang_Short = load_class_bootstrap(utf_java_lang_Short);
+ class_java_lang_Integer = load_class_bootstrap(utf_java_lang_Integer);
+ class_java_lang_Long = load_class_bootstrap(utf_java_lang_Long);
+ class_java_lang_Float = load_class_bootstrap(utf_java_lang_Float);
+ class_java_lang_Double = load_class_bootstrap(utf_java_lang_Double);
/* Load important system classes. */
- if (!(class_java_lang_Class = load_class_bootstrap(utf_java_lang_Class)))
- vm_abort("loader_init: loading failed");
-
- if (!(class_java_lang_String = load_class_bootstrap(utf_java_lang_String)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_Class = load_class_bootstrap(utf_java_lang_Class);
+ class_java_lang_String = load_class_bootstrap(utf_java_lang_String);
#if defined(ENABLE_JAVASE)
- if (!(class_java_lang_ClassLoader =
- load_class_bootstrap(utf_java_lang_ClassLoader)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_ClassLoader =
+ load_class_bootstrap(utf_java_lang_ClassLoader);
- if (!(class_java_lang_SecurityManager =
- load_class_bootstrap(utf_java_lang_SecurityManager)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_SecurityManager =
+ load_class_bootstrap(utf_java_lang_SecurityManager);
#endif
- if (!(class_java_lang_System = load_class_bootstrap(utf_java_lang_System)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_System =
+ load_class_bootstrap(utf_new_char("java/lang/System"));
- if (!(class_java_lang_Thread =
- load_class_bootstrap(utf_new_char("java/lang/Thread"))))
- vm_abort("loader_init: loading failed");
+ class_java_lang_Thread =
+ load_class_bootstrap(utf_new_char("java/lang/Thread"));
#if defined(ENABLE_JAVASE)
- if (!(class_java_lang_ThreadGroup =
- load_class_bootstrap(utf_java_lang_ThreadGroup)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_ThreadGroup =
+ load_class_bootstrap(utf_java_lang_ThreadGroup);
#endif
+ class_java_lang_Throwable = load_class_bootstrap(utf_java_lang_Throwable);
+
#if defined(WITH_CLASSPATH_GNU)
- if (!(class_java_lang_VMSystem =
- load_class_bootstrap(utf_new_char("java/lang/VMSystem"))))
- vm_abort("loader_init: loading failed");
+ class_java_lang_VMSystem =
+ load_class_bootstrap(utf_new_char("java/lang/VMSystem"));
+
+ class_java_lang_VMThread =
+ load_class_bootstrap(utf_new_char("java/lang/VMThread"));
- if (!(class_java_lang_VMThread =
- load_class_bootstrap(utf_new_char("java/lang/VMThread"))))
- vm_abort("loader_init: loading failed");
+ class_java_lang_VMThrowable =
+ load_class_bootstrap(utf_new_char("java/lang/VMThrowable"));
#endif
+ /* Important system exceptions. */
+
+ class_java_lang_Exception = load_class_bootstrap(utf_java_lang_Exception);
+
+ class_java_lang_ClassNotFoundException =
+ load_class_bootstrap(utf_java_lang_ClassNotFoundException);
- /* some classes which may be used more often */
+ class_java_lang_RuntimeException =
+ load_class_bootstrap(utf_java_lang_RuntimeException);
+
+ /* Some classes which may be used often. */
#if defined(ENABLE_JAVASE)
- if (!(class_java_lang_StackTraceElement =
- load_class_bootstrap(utf_java_lang_StackTraceElement)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_StackTraceElement =
+ load_class_bootstrap(utf_java_lang_StackTraceElement);
+
+ class_java_lang_reflect_Constructor =
+ load_class_bootstrap(utf_java_lang_reflect_Constructor);
- if (!(class_java_lang_reflect_Constructor =
- load_class_bootstrap(utf_java_lang_reflect_Constructor)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_reflect_Field =
+ load_class_bootstrap(utf_java_lang_reflect_Field);
- if (!(class_java_lang_reflect_Field =
- load_class_bootstrap(utf_java_lang_reflect_Field)))
- vm_abort("loader_init: loading failed");
+ class_java_lang_reflect_Method =
+ load_class_bootstrap(utf_java_lang_reflect_Method);
- if (!(class_java_lang_reflect_Method =
- load_class_bootstrap(utf_java_lang_reflect_Method)))
- vm_abort("loader_init: loading failed");
+ class_java_security_PrivilegedAction =
+ load_class_bootstrap(utf_new_char("java/security/PrivilegedAction"));
- if (!(class_java_security_PrivilegedAction =
- load_class_bootstrap(utf_new_char("java/security/PrivilegedAction"))))
- vm_abort("loader_init: loading failed");
+ class_java_util_HashMap =
+ load_class_bootstrap(utf_new_char("java/util/HashMap"));
- if (!(class_java_util_Vector = load_class_bootstrap(utf_java_util_Vector)))
- vm_abort("loader_init: loading failed");
+ class_java_util_Vector = load_class_bootstrap(utf_java_util_Vector);
# if defined(WITH_CLASSPATH_SUN)
- if (!(class_sun_reflect_MagicAccessorImpl =
- load_class_bootstrap(utf_new_char("sun/reflect/MagicAccessorImpl"))))
- vm_abort("loader_init: loading failed");
+ class_sun_reflect_MagicAccessorImpl =
+ load_class_bootstrap(utf_new_char("sun/reflect/MagicAccessorImpl"));
# endif
- if (!(arrayclass_java_lang_Object =
- load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"))))
- vm_abort("loader_init: loading failed");
+ arrayclass_java_lang_Object =
+ load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"));
# if defined(ENABLE_ANNOTATIONS)
/* needed by annotation support */
- if (!(class_sun_reflect_ConstantPool =
- load_class_bootstrap(utf_new_char("sun/reflect/ConstantPool"))))
- vm_abort("loader_init: loading failed");
+ class_sun_reflect_ConstantPool =
+ load_class_bootstrap(utf_new_char("sun/reflect/ConstantPool"));
# if defined(WITH_CLASSPATH_GNU)
/* needed by GNU Classpaths annotation support */
- if (!(class_sun_reflect_annotation_AnnotationParser =
- load_class_bootstrap(utf_new_char("sun/reflect/annotation/AnnotationParser"))))
- vm_abort("loader_init: loading failed");
+ class_sun_reflect_annotation_AnnotationParser =
+ load_class_bootstrap(utf_new_char("sun/reflect/annotation/AnnotationParser"));
# endif
# endif
#endif
/* key for entry is the hashcode of the classloader;
aligned to 16-byte boundaries */
-#if defined(ENABLE_GC_CACAO)
- key = heap_get_hashcode(LLNI_DIRECT(cl)) >> 4;
-#else
- key = ((u4) (ptrint) cl) >> 4;
-#endif
-
+ key = heap_hashcode(LLNI_DIRECT(cl)) >> 4;
slot = key & (hashtable_classloader->size - 1);
cle = hashtable_classloader->ptr[slot];
/* key for entry is the hashcode of the classloader;
aligned to 16-byte boundaries */
-#if defined(ENABLE_GC_CACAO)
- key = heap_get_hashcode(LLNI_DIRECT(cl)) >> 4;
-#else
- key = ((u4) (ptrint) cl) >> 4;
-#endif
-
+ key = heap_hashcode(LLNI_DIRECT(cl)) >> 4;
slot = key & (hashtable_classloader->size - 1);
cle = hashtable_classloader->ptr[slot];
cb = suck_start(c);
if (cb == NULL) {
- /* this normally means, the classpath was not set properly */
-
- if (name == utf_java_lang_Object)
- vm_abort("java/lang/NoClassDefFoundError: java/lang/Object");
-
exceptions_throw_classnotfoundexception(name);
-
return NULL;
}
RT_TIMING_GET_TIME(time_load);
- if (!r) {
+ if (r == NULL) {
/* the class could not be loaded, free the classinfo struct */
class_free(c);
-
- } else {
+ }
+ else {
/* Store this class in the loaded class cache this step also
- checks the loading constraints. If the class has been loaded
- before, the earlier loaded class is returned. */
+ checks the loading constraints. If the class has been
+ loaded before, the earlier loaded class is returned. */
classinfo *res = classcache_store(NULL, c, true);
- if (!res) {
+ if (res == NULL) {
/* exception */
class_free(c);
}
+ else {
+ /* Add the package name to the boot packages. */
+
+ package_add(c->packagename);
+ }
r = res;
}
/* XXX This should be done better. */
tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
- if (tc == NULL)
+ if (tc == NULL) {
+ resolve_handle_pending_exception(true);
return false;
+ }
/* Interfaces are not allowed as super classes. */
/* XXX This should be done better. */
tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
- if (tc == NULL)
+ if (tc == NULL) {
+ resolve_handle_pending_exception(true);
return false;
+ }
/* Detect circularity. */
classinfo *load_class_from_classbuffer(classbuffer *cb)
{
classinfo *c;
- int32_t dumpsize;
bool result;
+ int32_t dumpmarker;
/* Get the classbuffer's class. */
/* Mark start of dump memory area. */
- dumpsize = dump_size();
+ DMARKER;
/* Class is currently loading. */
/* Release dump area. */
- dump_release(dumpsize);
+ DRELEASE;
/* An error occurred. */