This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Duplicate class registration handling


_Jv_RegisterClassHookDefault tries to throw an exception when duplicate 
class registration is detected. This didn't work if duplicate classes 
were registered before the runtime was initialized because we can't 
allocate at that point. This patch changes it to use JvFail if the 
runtime isn't initialized, but continue to throw an exception otherwise. 
It also changes JvFail to not do any allocation - I think its reasonable 
to assume that if JvFail is called then the runtime is pretty hosed and 
GC allocation might not work anyway.

regards

Bryce.


2001-10-23  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* prims.cc (_Jv_Abort): Always print error message using fprintf,
	don't try to allocate.
	(_Jv_CreateJavaVM): Set gcj::runTimeInitialized.
	* include/jvm.h (gcj::runTimeInitialized): New variable declaration.
	* java/lang/natClassLoader.cc (_Jv_RegisterClassHookDefault): Handle
	duplicate class registration with JvFail if the runtime hasn't been
	initialized yet.

Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.61
diff -u -r1.61 prims.cc
--- prims.cc	2001/10/16 08:35:17	1.61
+++ prims.cc	2001/10/23 05:24:47
@@ -299,10 +299,7 @@
 	   "libgcj failure: %s\n   in function %s, file %s, line %d\n",
 	   message, function, file, line);
 #else
-  java::io::PrintStream *err = java::lang::System::err;
-  err->print(JvNewStringLatin1 ("libgcj failure: "));
-  err->println(JvNewStringLatin1 (message));
-  err->flush();
+  fprintf (stderr, "libgcj failure: %s\n", message);
 #endif
   abort ();
 }
@@ -872,6 +869,8 @@
   _Jv_Utf8Const *clinit_name;
   _Jv_Utf8Const *init_name;
   _Jv_Utf8Const *finit_name;
+  
+  bool runtimeInitialized = false;
 }
 
 jint
@@ -879,12 +878,10 @@
 {
   using namespace gcj;
   
-  static bool init = false;
-
-  if (init)
+  if (runtimeInitialized)
     return -1;
 
-  init = true;
+  runtimeInitialized = true;
 
   PROCESS_GCJ_PROPERTIES;
 
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.38
diff -u -r1.38 natClassLoader.cc
--- natClassLoader.cc	2001/10/16 08:35:17	1.38
+++ natClassLoader.cc	2001/10/23 05:24:48
@@ -14,6 +14,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 #include <gcj/cni.h>
 #include <jvm.h>
@@ -452,7 +453,17 @@
 	{
 	  // If you get this, it means you have the same class in two
 	  // different libraries.
-	  throw new java::lang::VirtualMachineError (JvNewStringLatin1 ("class registered twice"));
+	  char *message;
+	  asprintf (&message, "Duplicate class registration: %s", 
+		    klass->name->data);
+	  if (! gcj::runtimeInitialized)
+	    JvFail (message);
+	  else
+	    {
+	      java::lang::String *str = JvNewStringLatin1 (message);
+	      free (message);
+	      throw new java::lang::VirtualMachineError (str);
+	    }
 	}
 
       check_class = check_class->next;
Index: include/jvm.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.44
diff -u -r1.44 jvm.h
--- jvm.h	2001/10/16 08:35:17	1.44
+++ jvm.h	2001/10/23 05:24:48
@@ -131,6 +131,9 @@
   extern _Jv_Utf8Const *clinit_name;    /* "<clinit>" */
   extern _Jv_Utf8Const *init_name;      /* "<init>" */
   extern _Jv_Utf8Const *finit_name;     /* "finit$", */
+  
+  /* Set to true by _Jv_CreateJavaVM. */
+  extern bool runtimeInitialized;
 };
 
 /* Type of pointer used as finalizer.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]