This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: libjava gcc-3_0-branch, klass timing out in testsuite again


Fergus Henderson wrote:

> If you're going to be making assumptions about how vtables are layed out,
> then I think it's safe to also assume that `char *' and `void *' have
> the same representation, in which case you can write that a little more
> readably using type `char *' for the vtable_ptr:
>
>     union Self {
>         char *vtable_ptr;
>         typeof(*this) self;
>     };
>     ((Self *)this)->vtable_ptr -= 2 * sizeof (void *);
>
> However, this is a matter of taste.  You may prefer the other way.
>
> You may also prefer hard-coding the class name instead of using
> `typeof(*this)', especially since typeof is only supported in GNU C,
> not GNU C++, I think.  As you can see I haven't tested this code ;-)

Thanks for tracking this down Jeff (and thanks Fergus for suggesting the fix). I'm
checking this patch in to the trunk and branch. I've verified that it doesn't cause
any regressions on i686-pc-linux-gnu, but I don't know if it actually fixes the
original problem as I have not seen it. Could someone check?  In any case, its a
damn good cleanup.

regards

  [ bryce ]


2001-05-06  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/lang/Class.h (_Jv_Self): New union type.
	(Class): Manipulate vtable pointer via _Jv_Self union. Thanks to
	Jeff Sturm and Fergus Henderson.

Index: Class.h
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Class.h,v
retrieving revision 1.32
diff -u -r1.32 Class.h
--- Class.h	2001/04/25 15:45:12	1.32
+++ Class.h	2001/05/06 07:38:18
@@ -99,6 +99,13 @@
   jshort count;
 };
 
+// Used for vtable pointer manipulation.
+union _Jv_Self
+{
+  char *vtable_ptr;
+  jclass self;
+};
+
 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
 
 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
@@ -211,9 +218,8 @@
 
     // 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.
-    void *p =  ((void **)this)[0];
-    ((void **)this)[0] = (void *)((char *)p-2*sizeof (void *));
-
+    ((_Jv_Self *)this)->vtable_ptr -= 2 * sizeof (void *);
+    
     // 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.

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