This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

[BC] Patch: RFA: itable fix


I found the interface dispatch bug.  In build_invokeinterface, we
compute both `interface' and `idx' using the same index.  Patch
appended.

I'm asking for approval rather than just committing it since the code
here is weird and it would be nice to have someone else take a quick
look.

The oddity is that the data type declarations in the compiler don't
match what I see in Class.h.

In the compiler:

  itable_type = build_array_type (ptr_type_node, 
				  one_elt_array_domain_type);
  TYPE_NONALIASED_COMPONENT (itable_type) = 1;
  itable_ptr_type = build_pointer_type (itable_type);

  PUSH_FIELD (class_type_node, field, "itable", itable_ptr_type);

So it looks like an itable is a `void *[]'.

In Class.h:

    struct _Jv_AddressTable
    {
      jint state;
      void *addresses[];
    };

    _Jv_AddressTable *itable;

Are we relying on padding to ensure that these are compatible?
Why not just declare things the same in both places?  That is both
more understandable and safer.

Anyway, on that theory I think my patch is ok.  The first interface
method is given index 1 by the compiler (so "slots" 1 and 2), which is
really index 0 to the runtime (same slots).

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* expr.c (build_invokeinterface): Compute correct offset for
	index into interface methods.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.185.2.15
diff -u -r1.185.2.15 expr.c
--- expr.c 18 Oct 2004 22:06:00 -0000 1.185.2.15
+++ expr.c 22 Oct 2004 00:39:13 -0000
@@ -2207,7 +2207,7 @@
 	= build4 (ARRAY_REF, 
 		 TREE_TYPE (TREE_TYPE (TYPE_ITABLE_DECL (output_class))),
 		 TYPE_ITABLE_DECL (output_class), 
-		  build_int_cst (NULL_TREE, itable_index-1),
+		  build_int_cst (NULL_TREE, itable_index),
 		  NULL_TREE, NULL_TREE);
       interface = convert (class_ptr_type, interface);
       idx = convert (integer_type_node, idx);


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