diff options
Diffstat (limited to 'libjava/java/lang')
-rw-r--r-- | libjava/java/lang/Class.h | 7 | ||||
-rw-r--r-- | libjava/java/lang/natClassLoader.cc | 60 |
2 files changed, 59 insertions, 8 deletions
diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h index 787e263..af959f9 100644 --- a/libjava/java/lang/Class.h +++ b/libjava/java/lang/Class.h @@ -39,6 +39,9 @@ extern "Java" // We declare these here to avoid including gcj/cni.h. extern "C" void _Jv_InitClass (jclass klass); +extern "C" jclass _Jv_NewClassFromInitializer + (const jclass class_initializer); +extern "C" void _Jv_RegisterNewClasses (void **classes); extern "C" void _Jv_RegisterClasses (const jclass *classes); extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes, size_t count); @@ -286,7 +289,7 @@ public: JArray<jclass> *getClasses (void); java::lang::ClassLoader *getClassLoader (void); - +public: // This is an internal method that circumvents the usual security // checks when getting the class loader. java::lang::ClassLoader *getClassLoaderInternal (void) @@ -427,6 +430,8 @@ private: int method_idx); friend void ::_Jv_InitClass (jclass klass); + friend java::lang::Class* ::_Jv_NewClassFromInitializer (const jclass class_initializer); + friend void _Jv_RegisterNewClasses (void **classes); friend _Jv_Method* ::_Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *, _Jv_Utf8Const*, jclass *); diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc index d22d6c2..e6cfca2 100644 --- a/libjava/java/lang/natClassLoader.cc +++ b/libjava/java/lang/natClassLoader.cc @@ -45,14 +45,17 @@ details. */ #include <gnu/gcj/runtime/BootClassLoader.h> #include <gnu/gcj/runtime/SystemClassLoader.h> +#undef _GNU_SOURCE +#define _GNU_SOURCE +#include <dlfcn.h> +#include <link.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; @@ -62,6 +65,8 @@ 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; @@ -164,6 +169,8 @@ _Jv_UnregisterInitiatingLoader (jclass klass, java::lang::ClassLoader *loader) void _Jv_RegisterClasses (const jclass *classes) { + _Jv_RegisterLibForGc (classes); + for (; *classes; ++classes) { jclass klass = *classes; @@ -178,6 +185,9 @@ void _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]; @@ -187,6 +197,41 @@ _Jv_RegisterClasses_Counted (const jclass * classes, size_t count) } } +// 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) { @@ -389,6 +434,12 @@ static _Jv_IDispatchTable *array_idt = NULL; 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 @@ -464,11 +515,6 @@ _Jv_NewArrayClass (jclass element, java::lang::ClassLoader *loader, 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]; |