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]
Other format: [Raw text]

Patch: FYI: Class constructor


I'm checking this in.

This is a prerequisite for my PR 5088 patch.
It also fixes an oddity Adam Megacz noted: we have two no-arg Class
constructors.

For reasons outlined on the main list, I've removed the C++
constructor.

Tom

Index: ChangeLog
from  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.

Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.65
diff -u -r1.65 prims.cc
--- prims.cc 2001/12/14 18:43:51 1.65
+++ prims.cc 2001/12/16 22:26:25
@@ -56,6 +56,7 @@
 #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 @@
       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 @@
 {    
   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;
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.41
diff -u -r1.41 Class.h
--- java/lang/Class.h 2001/12/15 08:31:48 1.41
+++ java/lang/Class.h 2001/12/16 22:26:26
@@ -109,13 +109,6 @@
   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 @@
 
   // 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 @@
 				 _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: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.45
diff -u -r1.45 natClassLoader.cc
--- java/lang/natClassLoader.cc 2001/12/15 08:31:48 1.45
+++ java/lang/natClassLoader.cc 2001/12/16 22:26:26
@@ -61,6 +61,7 @@
 #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 @@
   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 @@
   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 @@
   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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]