From 107abb2f61f6e53ebb7aa05b78fdd9234ee7877c Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Tue, 16 Oct 2001 08:35:17 +0000 Subject: Eliminate use of C++ static constructors. * interpret.cc: Remove static Utf8Consts. Use namespace gcj. * jni.cc: Likewise. * resolve.cc: Likewise. * defineclass.cc: Likewise. (_Jv_ClassReader::handleClassBegin): Synchronize call to _Jv_RegisterClass. * include/jvm.h (void_signature, clinit_name, init_name, finit_name): Declare in namespace gcj. * java/lang/Class.h (Class): Remove initialization for primitive types. (friend void _Jv_InitPrimClass): This is in prims.cc. * prims.cc (_Jv_InitPrimClass): Do primitive type initialization here instead. (void_signature, clinit_name, init_name, finit_name): Define in namespace gcj. (_Jv_CreateJavaVM): Call _Jv_InitThreads, _Jv_InitGC, and _Jv_InitializeSyncMutex from here. Initialize Utf8 constants. Initialize primitive types. * java/lang/natClassLoader.cc (_Jv_RegisterClasses): Don't call initialization routines. Don't synchronize. * java/lang/natRuntime.cc (_load): Synchronize on java.lang.Class across dlopen call. From-SVN: r46282 --- libjava/java/lang/natClass.cc | 23 +++++------------------ libjava/java/lang/natClassLoader.cc | 20 ++++---------------- libjava/java/lang/natRuntime.cc | 9 ++++++++- 3 files changed, 17 insertions(+), 35 deletions(-) (limited to 'libjava/java') diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index 7b6b8b5..2ca7960 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -60,17 +60,10 @@ details. */ #define FieldClass java::lang::reflect::Field::class$ #define ConstructorClass java::lang::reflect::Constructor::class$ -// Some constants we use to look up the class initializer. -static _Jv_Utf8Const *void_signature = _Jv_makeUtf8Const ("()V", 3); -static _Jv_Utf8Const *clinit_name = _Jv_makeUtf8Const ("", 8); -static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("", 6); -static _Jv_Utf8Const *finit_name = _Jv_makeUtf8Const ("finit$", 6); -// The legacy `$finit$' method name, which still needs to be -// recognized as equivalent to the now prefered `finit$' name. -static _Jv_Utf8Const *finit_leg_name = _Jv_makeUtf8Const ("$finit$", 7); - +using namespace gcj; + jclass java::lang::Class::forName (jstring className, jboolean initialize, java::lang::ClassLoader *loader) @@ -341,9 +334,7 @@ java::lang::Class::getDeclaredMethods (void) if (method->name == NULL || _Jv_equalUtf8Consts (method->name, clinit_name) || _Jv_equalUtf8Consts (method->name, init_name) - || _Jv_equalUtf8Consts (method->name, finit_name) - // Backward compatibility hack: match the legacy `$finit$' name - || _Jv_equalUtf8Consts (method->name, finit_leg_name)) + || _Jv_equalUtf8Consts (method->name, finit_name)) continue; numMethods++; } @@ -357,9 +348,7 @@ java::lang::Class::getDeclaredMethods (void) if (method->name == NULL || _Jv_equalUtf8Consts (method->name, clinit_name) || _Jv_equalUtf8Consts (method->name, init_name) - || _Jv_equalUtf8Consts (method->name, finit_name) - // Backward compatibility hack: match the legacy `$finit$' name - || _Jv_equalUtf8Consts (method->name, finit_leg_name)) + || _Jv_equalUtf8Consts (method->name, finit_name)) continue; java::lang::reflect::Method* rmethod = new java::lang::reflect::Method (); @@ -522,9 +511,7 @@ java::lang::Class::_getMethods (JArray *result, if (method->name == NULL || _Jv_equalUtf8Consts (method->name, clinit_name) || _Jv_equalUtf8Consts (method->name, init_name) - || _Jv_equalUtf8Consts (method->name, finit_name) - // Backward compatibility hack: match the legacy `$finit$' name - || _Jv_equalUtf8Consts (method->name, finit_leg_name)) + || _Jv_equalUtf8Consts (method->name, finit_name)) continue; // Only want public methods. if (! java::lang::reflect::Modifier::isPublic (method->accflags)) diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc index 004b9d1..3c2679b 100644 --- a/libjava/java/lang/natClassLoader.cc +++ b/libjava/java/lang/natClassLoader.cc @@ -175,7 +175,6 @@ java::lang::ClassLoader::markClassErrorState0 (java::lang::Class *klass) klass->notifyAll (); } - // This is the findClass() implementation for the System classloader. It is // the only native method in VMClassLoader, so we define it here. jclass @@ -419,24 +418,13 @@ _Jv_RegisterInitiatingLoader (jclass klass, java::lang::ClassLoader *loader) } // This function is called many times during startup, before main() is -// run. We do our runtime initialization here the very first time we -// are called. At that point in time we know for certain we are -// running single-threaded, so we don't need to lock when modifying -// `init'. CLASSES is NULL-terminated. +// run. At that point in time we know for certain we are running +// single-threaded, so we don't need to lock when adding classes to the +// class chain. At all other times, the caller should synchronize on +// Class::class$. void _Jv_RegisterClasses (jclass *classes) { - static bool init = false; - - if (! init) - { - init = true; - _Jv_InitThreads (); - _Jv_InitGC (); - _Jv_InitializeSyncMutex (); - } - - JvSynchronize sync (&ClassClass); for (; *classes; ++classes) { jclass klass = *classes; diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index 0551ba6..18bc3cb 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -138,8 +138,15 @@ java::lang::Runtime::_load (jstring path, jboolean do_search) #endif jsize total = JvGetStringUTFRegion (path, 0, path->length(), &buf[offset]); buf[offset + total] = '\0'; + lt_dlhandle h; // FIXME: make sure path is absolute. - lt_dlhandle h = do_search ? lt_dlopenext (buf) : lt_dlopen (buf); + { + // Synchronize on java.lang.Class. This is to protect the class chain from + // concurrent modification by class registration calls which may be run + // during the dlopen(). + JvSynchronize sync (&java::lang::Class::class$); + h = do_search ? lt_dlopenext (buf) : lt_dlopen (buf); + } if (h == NULL) { const char *msg = lt_dlerror (); -- cgit v1.1