This is the mail archive of the java-patches@sourceware.cygnus.com 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]

Patch: static array runtime patch


I'm checking this in.  This is the runtime support for the static
array initialization optimization.

2000-05-31  Tom Tromey  <tromey@cygnus.com>

	* prims.cc (DECLARE_PRIM_TYPE): Define a vtable as well.
	(_Jv_PrimClass): Set `methods' by calling _Jv_FindArrayClass.
	* include/jvm.h (struct _Jv_ArrayVTable): Declare.
	(NUM_OBJECT_METHODS): New define.
	* java/lang/natClassLoader.cc (_Jv_FindArrayClass): Added
	`array_vtable' parameter.  Added assertion.
	* java/lang/Class.h (_Jv_FindArrayClass): Added `array_vtable'
	parameter.

Tom

Index: prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.29
diff -u -r1.29 prims.cc
--- prims.cc	2000/05/05 02:56:14	1.29
+++ prims.cc	2000/05/18 17:20:31
@@ -507,7 +507,7 @@
 public:
   // FIXME: calling convention is weird.  If we use the natural types
   // then the compiler will complain because they aren't Java types.
-  _Jv_PrimClass (jobject cname, jbyte sig, jint len)
+  _Jv_PrimClass (jobject cname, jbyte sig, jint len, jobject array_vtable)
     {
       using namespace java::lang::reflect;
 
@@ -533,11 +533,21 @@
       interface_count = 0;
       state = JV_STATE_NOTHING;
       thread = NULL;
+
+      // Note that we have to set `methods' to NULL.
+      if (sig != 'V')
+	_Jv_FindArrayClass (this, NULL, (_Jv_VTable *) array_vtable);
     }
 };
 
+// We use this to define both primitive classes and the vtables for
+// arrays of primitive classes.  The latter are given names so that we
+// can refer to them from the compiler, allowing us to construct
+// arrays of primitives statically.
 #define DECLARE_PRIM_TYPE(NAME, SIG, LEN) \
-  _Jv_PrimClass _Jv_##NAME##Class((jobject) #NAME, (jbyte) SIG, (jint) LEN)
+  _Jv_ArrayVTable _Jv_##NAME##VTable; \
+  _Jv_PrimClass _Jv_##NAME##Class((jobject) #NAME, (jbyte) SIG, (jint) LEN, \
+                                  (jobject) &_Jv_##NAME##VTable)
 
 DECLARE_PRIM_TYPE(byte, 'B', 1);
 DECLARE_PRIM_TYPE(short, 'S', 2);
Index: include/jvm.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/jvm.h,v
retrieving revision 1.24
diff -u -r1.24 jvm.h
--- jvm.h	2000/04/27 23:13:31	1.24
+++ jvm.h	2000/05/18 17:20:34
@@ -34,6 +34,18 @@
   void *method[1];
 };
 
+// Number of virtual methods on object.  FIXME: it sucks that we have
+// to keep this up to date by hand.
+#define NUM_OBJECT_METHODS 5
+
+// This structure is the type of an array's vtable.
+struct _Jv_ArrayVTable
+{
+  jclass clas;
+  // `+1' because there is an extra slot for C++ RTTI compatibility.
+  void *method[NUM_OBJECT_METHODS + 1];
+};
+
 union _Jv_word
 {
   jobject o;
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Class.h,v
retrieving revision 1.20
diff -u -r1.20 Class.h
--- Class.h	2000/05/05 02:56:14	1.20
+++ Class.h	2000/05/18 17:20:35
@@ -243,7 +243,8 @@
   friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
 				      java::lang::ClassLoader *loader);
   friend jclass _Jv_FindArrayClass (jclass element,
-				    java::lang::ClassLoader *loader);
+				    java::lang::ClassLoader *loader,
+				    _Jv_VTable *array_vtable = 0);
   friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
 			      java::lang::ClassLoader *loader);
 
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.21
diff -u -r1.21 natClassLoader.cc
--- natClassLoader.cc	2000/03/09 09:22:36	1.21
+++ natClassLoader.cc	2000/05/18 17:20:37
@@ -513,7 +513,8 @@
 }
 
 jclass
-_Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader)
+_Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader,
+		    _Jv_VTable *array_vtable)
 {
   _Jv_Utf8Const *array_name;
   int len;
@@ -560,6 +561,7 @@
 
       // Note that `vtable_method_count' doesn't include the initial
       // NULL slot.
+      JvAssert (ObjectClass.vtable_method_count == NUM_OBJECT_METHODS);
       int dm_count = ObjectClass.vtable_method_count + 1;
 
       // Create a new vtable by copying Object's vtable (except the
@@ -568,7 +570,11 @@
       // GC.
       int size = (sizeof (_Jv_VTable) +
 		  ((dm_count - 1) * sizeof (void *)));
-      _Jv_VTable *vtable = (_Jv_VTable *) _Jv_AllocBytes (size);
+      _Jv_VTable *vtable;
+      if (array_vtable)
+	vtable = array_vtable;
+      else
+	vtable = (_Jv_VTable *) _Jv_AllocBytes (size);
       vtable->clas = array_class;
       memcpy (vtable->method, ObjectClass.vtable->method,
 	      dm_count * sizeof (void *));
@@ -607,5 +613,3 @@
 
   return array_class;
 }
-
-

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