For PR java/5088:
authorTom Tromey <tromey@redhat.com>
Sun, 16 Dec 2001 22:28:35 +0000 (22:28 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Sun, 16 Dec 2001 22:28:35 +0000 (22:28 +0000)
* java/lang/natClassLoader.cc (_Jv_InitNewClassFields): New
function.
(_Jv_NewClass): Use it.
(defineClass0): Use it.
* prims.cc (_Jv_InitPrimClass): Adjust vtable here.
(_Jv_InitPrimClass): Use _Jv_InitNewClassFields.
(_Jv_NewArray): Don't abort; just throw exception.
Include InternalError.h.
* java/lang/Class.h (Class::Class): Declare, don't define.
(Class): Declare _Jv_InitNewClassFields as a friend.
(union _Jv_Self): Removed.

From-SVN: r48081

libjava/ChangeLog
libjava/java/lang/Class.h
libjava/java/lang/natClassLoader.cc
libjava/prims.cc

index ff59f96eb6ccabfca4889e601007a76d84c7f1b6..aaebefa25f69f81b3ec9307f6e18f73288d92689 100644 (file)
@@ -1,5 +1,18 @@
 2001-12-16  Tom Tromey  <tromey@redhat.com>
 
+       For PR java/5088:
+       * java/lang/natClassLoader.cc (_Jv_InitNewClassFields): New
+       function.
+       (_Jv_NewClass): Use it.
+       (defineClass0): Use it.
+       * prims.cc (_Jv_InitPrimClass): Adjust vtable here.
+       (_Jv_InitPrimClass): Use _Jv_InitNewClassFields.
+       (_Jv_NewArray): Don't abort; just throw exception.
+       Include InternalError.h.
+       * java/lang/Class.h (Class::Class): Declare, don't define.
+       (Class): Declare _Jv_InitNewClassFields as a friend.
+       (union _Jv_Self): Removed.
+
        * Makefile.in: Rebuilt.
        * Makefile.am (ordinary_java_source_files): Removed old file;
        added new file.
index 20523912e583554b5b27cbbd33e4f43711a86d56..73d81daad165275d26ed8c8265e5e0ed20645bed 100644 (file)
@@ -109,13 +109,6 @@ struct _Jv_ifaces
   jshort count;
 };
 
-// Used for vtable pointer manipulation.
-union _Jv_Self
-{
-  char *vtable_ptr;
-  jclass self;
-};
-
 struct _Jv_MethodSymbol
 {
   _Jv_Utf8Const *class_name;
@@ -232,12 +225,7 @@ public:
 
   // This constructor is used to create Class object for the primitive
   // types. See prims.cc.
-  Class ()
-  {
-    // C++ ctors set the vtbl pointer to point at an offset inside the vtable
-    // object. That doesn't work for Java, so this hack adjusts it back.
-    ((_Jv_Self *)this)->vtable_ptr -= 2 * sizeof (void *);
-  }
+  Class ();
 
   static java::lang::Class class$;
 
@@ -307,6 +295,7 @@ private:
                                 _Jv_VTable *array_vtable = 0);
   friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
                              java::lang::ClassLoader *loader);
+  friend void _Jv_InitNewClassFields (jclass klass);
 
   // in prims.cc
   friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *);
index ffe5b18fbe04f10689b8957ce063a0b2259f7126..a6f7b60e4c588919c910577afe09e8b6c3d0a4b1 100644 (file)
@@ -61,6 +61,7 @@ java::lang::ClassLoader::defineClass0 (jstring name,
 #ifdef INTERPRETER
   jclass klass;
   klass = (jclass) JvAllocObject (&ClassClass, sizeof (_Jv_InterpClass));
+  _Jv_InitNewClassFields (klass);
 
   // synchronize on the class, so that it is not
   // attempted initialized until we're done loading.
@@ -549,16 +550,13 @@ _Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader)
   return klass;
 }
 
-jclass
-_Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
-             java::lang::ClassLoader *loader)
+void
+_Jv_InitNewClassFields (jclass ret)
 {
-  jclass ret = (jclass) JvAllocObject (&ClassClass);
-
   ret->next = NULL;
-  ret->name = name;
+  ret->name = NULL;
   ret->accflags = 0;
-  ret->superclass = superclass;
+  ret->superclass = NULL;
   ret->constants.size = 0;
   ret->constants.tags = NULL;
   ret->constants.data = NULL;
@@ -571,7 +569,7 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
   ret->static_field_count = 0;
   ret->vtable = NULL;
   ret->interfaces = NULL;
-  ret->loader = loader;
+  ret->loader = NULL;
   ret->interface_count = 0;
   ret->state = JV_STATE_NOTHING;
   ret->thread = NULL;
@@ -579,6 +577,17 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
   ret->ancestors = NULL;
   ret->idt = NULL;
   ret->arrayclass = NULL;
+}
+
+jclass
+_Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
+             java::lang::ClassLoader *loader)
+{
+  jclass ret = (jclass) JvAllocObject (&ClassClass);
+  _Jv_InitNewClassFields (ret);
+  ret->name = name;
+  ret->superclass = superclass;
+  ret->loader = loader;
 
   _Jv_RegisterClass (ret);
 
index 40d1bd66f815c920e51f4afdff091f5090d141a5..279e3caad02ad07d29cfe4d31223b52b6da4379b 100644 (file)
@@ -56,6 +56,7 @@ details.  */
 #include <java/lang/ArrayIndexOutOfBoundsException.h>
 #include <java/lang/ArithmeticException.h>
 #include <java/lang/ClassFormatError.h>
+#include <java/lang/InternalError.h>
 #include <java/lang/NegativeArraySizeException.h>
 #include <java/lang/NullPointerException.h>
 #include <java/lang/OutOfMemoryError.h>
@@ -533,8 +534,8 @@ _Jv_NewArray (jint type, jint size)
       case 10:  return JvNewIntArray (size);
       case 11:  return JvNewLongArray (size);
     }
-  JvFail ("newarray - bad type code");
-  return NULL;                 // Placate compiler.
+  throw new java::lang::InternalError
+    (JvNewStringLatin1 ("invalid type code in _Jv_NewArray"));
 }
 
 // Allocate a possibly multi-dimensional array but don't check that
@@ -613,9 +614,14 @@ _Jv_InitPrimClass (jclass cl, char *cname, char sig, int len,
 {    
   using namespace java::lang::reflect;
 
-  // We must initialize every field of the class.  We do this in the
-  // same order they are declared in Class.h, except for fields that
-  // are initialized to NULL.
+  _Jv_InitNewClassFields (cl);
+
+  // We must set the vtable for the class; the Java constructor
+  // doesn't do this.
+  (*(_Jv_VTable **) cl) = java::lang::Class::class$.vtable;
+
+  // Initialize the fields we care about.  We do this in the same
+  // order they are declared in Class.h.
   cl->name = _Jv_makeUtf8Const ((char *) cname, -1);
   cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT;
   cl->method_count = sig;