// natClassLoader.cc - Implementation of java.lang.ClassLoader native methods.
-/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of libgcj.
#include <java/lang/Cloneable.h>
#include <java/util/HashMap.h>
#include <gnu/gcj/runtime/BootClassLoader.h>
+#include <gnu/gcj/runtime/SystemClassLoader.h>
// Size of local hash table.
#define HASH_LEN 1013
// Hash function for Utf8Consts.
#define HASH_UTF(Utf) ((Utf)->hash16() % HASH_LEN)
-static jclass loaded_classes[HASH_LEN];
-
// This records classes which will be registered with the system class
// loader when it is initialized.
static jclass system_class_list;
// no longer pay attention to the system abi flag.
#define SYSTEM_LOADER_INITIALIZED ((jclass) -1)
+static jclass loaded_classes[HASH_LEN];
+
// This is the root of a linked list of classes
static jclass stack_head;
int len = _Jv_GetStringUTFLength (name);
char sig[len + 1];
_Jv_GetStringUTFRegion (name, 0, name->length(), sig);
- return _Jv_FindClassFromSignature(sig, this);
+ jclass result = _Jv_FindClassFromSignature(sig, this);
+ if (result == NULL)
+ throw new ClassNotFoundException(name);
+ return result;
}
\f
void
_Jv_RegisterClasses (const jclass *classes)
{
+ _Jv_RegisterLibForGc (classes);
+
for (; *classes; ++classes)
{
jclass klass = *classes;
_Jv_RegisterClasses_Counted (const jclass * classes, size_t count)
{
size_t i;
+
+ _Jv_RegisterLibForGc (classes);
+
for (i = 0; i < count; i++)
{
jclass klass = classes[i];
}
}
+// Create a class on the heap from an initializer struct.
+jclass
+_Jv_NewClassFromInitializer (const jclass class_initializer)
+{
+ jclass new_class = (jclass)_Jv_AllocObj (sizeof *new_class,
+ &java::lang::Class::class$);
+ memcpy ((void*)new_class, (void*)class_initializer, sizeof *new_class);
+
+ if (_Jv_CheckABIVersion ((unsigned long) new_class->next_or_version))
+ (*_Jv_RegisterClassHook) (new_class);
+
+ return new_class;
+}
+
+// Called by compiler-generated code at DSO initialization. CLASSES
+// is an array of pairs: the first item of each pair is a pointer to
+// the initialized data that is a class initializer in a DSO, and the
+// second is a pointer to a class reference.
+// _Jv_NewClassFromInitializer() creates the new class (on the Java
+// heap) and we write the address of the new class into the address
+// pointed to by the second word.
+void
+_Jv_RegisterNewClasses (void **classes)
+{
+ _Jv_InitGC ();
+
+ jclass initializer;
+
+ while ((initializer = (jclass)*classes++))
+ {
+ jclass *class_ptr = (jclass *)*classes++;
+ *class_ptr = _Jv_NewClassFromInitializer (initializer);
+ }
+}
+
void
_Jv_RegisterClassHookDefault (jclass klass)
{
// This is used during initialization to register all compiled-in
// classes that are not part of the core with the system class loader.
void
-_Jv_CopyClassesToSystemLoader (java::lang::ClassLoader *loader)
+_Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::SystemClassLoader *loader)
{
for (jclass klass = system_class_list;
klass;
klass = klass->next_or_version)
{
klass->loader = loader;
- loader->loadedClasses->put(klass->name->toString(), klass);
+ loader->addClass(klass);
}
system_class_list = SYSTEM_LOADER_INITIALIZED;
}
+// An internal variant of _Jv_FindClass which simply swallows a
+// NoClassDefFoundError or a ClassNotFoundException. This gives the
+// caller a chance to evaluate the situation and behave accordingly.
+jclass
+_Jv_FindClassNoException (_Jv_Utf8Const *name, java::lang::ClassLoader *loader)
+{
+ jclass klass;
+
+ try
+ {
+ klass = _Jv_FindClass(name, loader);
+ }
+ catch ( java::lang::NoClassDefFoundError *ncdfe )
+ {
+ return NULL;
+ }
+ catch ( java::lang::ClassNotFoundException *cnfe )
+ {
+ return NULL;
+ }
+
+ return klass;
+}
+
jclass
_Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader)
{
static jshort array_depth = 0;
static jclass *array_ancestors = NULL;
+static jclass interfaces[] =
+{
+ &java::lang::Cloneable::class$,
+ &java::io::Serializable::class$
+};
+
// Create a class representing an array of ELEMENT and store a pointer to it
// in element->arrayclass. LOADER is the ClassLoader which _initiated_ the
// instantiation of this array. ARRAY_VTABLE is the vtable to use for the new
= java::lang::Object::class$.vtable_method_count;
// Stash the pointer to the element type.
- array_class->methods = (_Jv_Method *) element;
+ array_class->element_type = element;
// Register our interfaces.
- static jclass interfaces[] =
- {
- &java::lang::Cloneable::class$,
- &java::io::Serializable::class$
- };
array_class->interfaces = interfaces;
array_class->interface_count = sizeof interfaces / sizeof interfaces[0];