[BC] Patch: FYI: API tweaks, class layout fixlet

Tom Tromey tromey@redhat.com
Fri Aug 13 22:39:00 GMT 2004


I'm checking this in on the BC branch.

This changes the interface to a couple helper methods.  In the process
I also fixed a buglet in _Jv_LayoutClass; the old code would allocate
too much memory for an interpreted class' static fields.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* java/lang/natClassLoader.cc (_Jv_WaitForState): Updated.
	* java/lang/Class.h (_Jv_ResolveClassRef): Updated declaration.
	(Class::getSuperclass): Updated.
	(Class::getInterfaces): Likewise.
	(Class::size): Updated.
	(_Jv_LayoutClass): Updated declaration.
	* java/lang/natClass.cc (_Jv_ResolveClassRef): Changed interface.
	Synchronize on class.
	(_Jv_LayoutClass): Changed interface.
	(initializeClass): Updated.
	(_Jv_LinkSymbolTable): Likewise.

Index: resolve.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/resolve.cc,v
retrieving revision 1.44.2.3
diff -u -r1.44.2.3 resolve.cc
--- resolve.cc 20 May 2004 23:33:45 -0000 1.44.2.3
+++ resolve.cc 12 Aug 2004 23:06:14 -0000
@@ -475,8 +475,7 @@
     java::lang::VMClassLoader::resolveClass (klass->getSuperclass());
 
   /************ PART ONE: OBJECT LAYOUT ***************/
-  int static_size = 0;
-  _Jv_LayoutClass(klass, &static_size);
+  int static_size = _Jv_LayoutClass(klass);
 
   _Jv_InterpClass *iclass = (_Jv_InterpClass*)klass->aux_info;
 
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.63.12.5
diff -u -r1.63.12.5 Class.h
--- java/lang/Class.h 12 Aug 2004 19:29:29 -0000 1.63.12.5
+++ java/lang/Class.h 12 Aug 2004 23:06:17 -0000
@@ -207,20 +207,18 @@
   void setSigners(JArray<jobject> *);
 
   inline jclass getSuperclass (void)
-    {
-      if (state < JV_STATE_LINKED)
-	superclass =_Jv_ResolveClassRef (this, superclass);
-      
-      return superclass;
-    }
+  {
+    if (state < JV_STATE_LINKED)
+      _Jv_ResolveClassRef (this, &superclass);
+    return superclass;
+  }
 
   inline jclass getInterface (jint n)
-    {
-      if (state < JV_STATE_LINKED)
-	interfaces[n] =_Jv_ResolveClassRef (this, interfaces[n]);
-      
-      return interfaces[n];
-    }
+  {
+    if (state < JV_STATE_LINKED)
+      _Jv_ResolveClassRef (this, &interfaces[n]);
+    return interfaces[n];
+  }
 
   inline jboolean isArray (void)
     {
@@ -257,10 +255,7 @@
       // FIXME: ugly implementation.
       // FIXME: can't use _Jv_isBinaryCompatible here.
       if (size_in_bytes == -1)
-	{
-	  int static_size;
-	  _Jv_LayoutClass(this, &static_size);
-	}
+	_Jv_LayoutClass(this);
 
       return size_in_bytes;
     }
@@ -297,7 +292,7 @@
   friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, 
 					     int method_idx);
 
-  friend jclass _Jv_ResolveClassRef (jclass, jclass);
+  friend void _Jv_ResolveClassRef (jclass, jclass *);
 
   inline friend void 
   _Jv_InitClass (jclass klass)
@@ -307,7 +302,7 @@
     klass->initializeClass ();  
   }
   
-  friend void _Jv_LayoutClass(jclass, int*);
+  friend int _Jv_LayoutClass(jclass);
 
   friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *, 
 					       _Jv_Utf8Const*);
@@ -482,8 +477,8 @@
   JArray<jobject> *hack_signers;
   // Used by Jv_PopClass and _Jv_PushClass to communicate with StackTrace.
   jclass chain;
-  // Additional data, specific to the generator (JIT, native, interpreter) of this 
-  // class.
+  // Additional data, specific to the generator (JIT, native,
+  // interpreter) of this class.
   void *aux_info;
 };
 
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.75.2.7
diff -u -r1.75.2.7 natClass.cc
--- java/lang/natClass.cc 12 Aug 2004 19:29:29 -0000 1.75.2.7
+++ java/lang/natClass.cc 12 Aug 2004 23:06:18 -0000
@@ -101,20 +101,22 @@
     return ALIGNOF (jobject);
 }
 
-jclass
-_Jv_ResolveClassRef (jclass klass, jclass classref)
+// This function is used to lazily locate superclasses and
+// superinterfaces.
+void
+_Jv_ResolveClassRef (jclass klass, jclass *classref)
 {
-  jclass ret = classref;
+  jclass ret = *classref;
 
   typedef unsigned int uaddr __attribute__ ((mode (pointer)));
 
-  // If superclass looks like a constant pool entry,
-  // resolve it now.
-  if (classref && (uaddr)classref < (uaddr)klass->constants.size)
+  // If superclass looks like a constant pool entry, resolve it now.
+  if (ret && (uaddr) ret < (uaddr) klass->constants.size)
     {
+      JvSynchronize sync (klass);
       if (klass->state < JV_STATE_LINKED)
 	{
-	  _Jv_Utf8Const *name = klass->constants.data[(uaddr)classref].utf8;
+	  _Jv_Utf8Const *name = klass->constants.data[(uaddr) *classref].utf8;
 	  ret = _Jv_FindClass (name, klass->loader);
 	  if (! ret)
 	    {
@@ -123,10 +125,9 @@
 	    }
 	}
       else
-	ret = klass->constants.data[(uaddr)classref].clazz;
+	ret = klass->constants.data[(uaddr) classref].clazz;
+      *classref = ret;
     }
-
-  return ret;
 }
 
 jclass
@@ -808,7 +809,8 @@
 
   // Step 2.
   java::lang::Thread *self = java::lang::Thread::currentThread();
-  // FIXME: `self' can be null at startup.  Hence this nasty trick.
+  // Note that `self' can be null at startup (at least this was the
+  // case with the old qthread system).  Hence this nasty trick.
   self = (java::lang::Thread *) ((long) self | 1);
   while (state == JV_STATE_IN_PROGRESS && thread && thread != self)
     wait ();
@@ -869,10 +871,7 @@
   
   // Assign storage to fields
   if (_Jv_isBinaryCompatible (this))
-    {
-      int static_size;
-      _Jv_LayoutClass(this, &static_size);
-    }
+    _Jv_LayoutClass(this);
 
   if (vtable == NULL)
     _Jv_MakeVTable(this);
@@ -1735,10 +1734,7 @@
 // 		  {
 
 		if (_Jv_isBinaryCompatible (cls))
-		  {
-		    int static_size;
-		    _Jv_LayoutClass(cls, &static_size);
-		  }
+		  _Jv_LayoutClass(cls);
 
 		if (!field->isResolved ())
 		  _Jv_ResolveField (field, cls->loader);
@@ -2118,8 +2114,10 @@
     }
 }
 
-void 
-_Jv_LayoutClass(jclass klass, int *static_size)
+// Lay out the class, returning the number of bytes needed for the
+// class' static variables.
+int
+_Jv_LayoutClass(jclass klass)
 {  
   // Compute the alignment for this type by searching through the
   // superclasses and finding the maximum required alignment.  We
@@ -2129,7 +2127,7 @@
   while (super != NULL)
     {
       if (_Jv_isBinaryCompatible (super))
-	_Jv_LayoutClass(super, static_size);
+	_Jv_LayoutClass(super);
       int num = JvNumInstanceFields (super);
       _Jv_Field *field = JvGetFirstInstanceField (super);
       while (num > 0)
@@ -2144,6 +2142,7 @@
     }
 
   int instance_size;
+  int static_size = 0;
 
   // Although java.lang.Object is never interpreted, an interface can
   // have a null superclass.  Note that we have to lay out an
@@ -2183,13 +2182,12 @@
 	{
 	  if (_Jv_IsInterpretedClass (klass))
 	    {
-	      /* this computes an offset into a region we'll allocate
-		 shortly, and then add this offset to the start
-		 address */
-
-	      *static_size       = ROUND (*static_size, field_align);
-	      field->u.boffset   = *static_size;
-	      *static_size       += field_size;
+	      // This computes an offset into a region we'll allocate
+	      // shortly, and then add this offset to the start
+	      // address.
+	      static_size       = ROUND (static_size, field_align);
+	      field->u.boffset   = static_size;
+	      static_size       += field_size;
 	    }
 	}
       else
@@ -2207,5 +2205,6 @@
   // with our current ABI.
   instance_size = ROUND (instance_size, max_align);
   klass->size_in_bytes = instance_size;
-}
 
+  return static_size;
+}
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.64.8.5
diff -u -r1.64.8.5 natClassLoader.cc
--- java/lang/natClassLoader.cc 12 Aug 2004 19:29:29 -0000 1.64.8.5
+++ java/lang/natClassLoader.cc 12 Aug 2004 23:06:18 -0000
@@ -58,12 +58,9 @@
 	_Jv_PrepareClass (klass);
       else
 #endif
-	// Assign storage to fields
+	// Assign storage to fields.
 	if (_Jv_isBinaryCompatible (klass))
-	  {   
-	    int static_size;
-	    _Jv_LayoutClass(klass, &static_size);
-	  }
+	  _Jv_LayoutClass(klass);
       _Jv_PrepareCompiledClass (klass);
       _Jv_MonitorExit (klass);
       return;



More information about the Java-patches mailing list