This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[java] ia64 c++ abi vtable changes
- To: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Subject: [java] ia64 c++ abi vtable changes
- From: Richard Henderson <rth at redhat dot com>
- Date: Thu, 20 Sep 2001 15:34:55 -0700
It appears that I don't need to do anything for interfaces.
That is, a call through an interface won't directly compute
an offset into the vtable. Is that true?
r~
* class.c (get_dispatch_table): Handle function descriptors.
(build_dtable_decl): Likewise.
* expr.c (build_invokevirtual): Likewise.
Index: gcc/java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.114
diff -c -p -d -r1.114 class.c
*** class.c 2001/09/10 08:52:54 1.114
--- class.c 2001/09/20 22:19:17
*************** get_dispatch_table (type, this_class_add
*** 1372,1380 ****
{
int abstract_p = CLASS_ABSTRACT (TYPE_NAME (type));
tree vtable = get_dispatch_vector (type);
! int i;
tree list = NULL_TREE;
int nvirtuals = TREE_VEC_LENGTH (vtable);
for (i = nvirtuals; --i >= 0; )
{
tree method = TREE_VEC_ELT (vtable, i);
--- 1372,1382 ----
{
int abstract_p = CLASS_ABSTRACT (TYPE_NAME (type));
tree vtable = get_dispatch_vector (type);
! int i, j;
tree list = NULL_TREE;
int nvirtuals = TREE_VEC_LENGTH (vtable);
+ int arraysize;
+
for (i = nvirtuals; --i >= 0; )
{
tree method = TREE_VEC_ELT (vtable, i);
*************** get_dispatch_table (type, this_class_add
*** 1383,1409 ****
if (! abstract_p)
warning_with_decl (method,
"abstract method in non-abstract class");
! method = null_pointer_node;
}
else
{
if (!DECL_RTL_SET_P (method))
make_decl_rtl (method, NULL);
! method = build1 (ADDR_EXPR, nativecode_ptr_type_node, method);
}
- list = tree_cons (NULL_TREE /*DECL_VINDEX (method) + 2*/,
- method, list);
}
/* Dummy entry for compatibility with G++ -fvtable-thunks. When
using the Boehm GC we sometimes stash a GC type descriptor
there. We set the PURPOSE to NULL_TREE not to interfere (reset)
the emitted byte count during the output to the assembly file. */
! list = tree_cons (NULL_TREE, get_boehm_type_descriptor (type),
! list);
list = tree_cons (integer_zero_node, this_class_addr, list);
! return build (CONSTRUCTOR, build_prim_array_type (nativecode_ptr_type_node,
! nvirtuals + 2),
! NULL_TREE, list);
}
void
--- 1385,1436 ----
if (! abstract_p)
warning_with_decl (method,
"abstract method in non-abstract class");
!
! if (TARGET_VTABLE_USES_DESCRIPTORS)
! for (j = 0; j < TARGET_VTABLE_USES_DESCRIPTORS; ++j)
! list = tree_cons (NULL_TREE, null_pointer_node, list);
! else
! list = tree_cons (NULL_TREE, null_pointer_node, list);
}
else
{
if (!DECL_RTL_SET_P (method))
make_decl_rtl (method, NULL);
!
! if (TARGET_VTABLE_USES_DESCRIPTORS)
! for (j = 0; j < TARGET_VTABLE_USES_DESCRIPTORS; ++j)
! {
! tree fdesc = build (FDESC_EXPR, nativecode_ptr_type_node,
! method, build_int_2 (j, 0));
! TREE_CONSTANT (fdesc) = 1;
! list = tree_cons (NULL_TREE, fdesc, list);
! }
! else
! list = tree_cons (NULL_TREE,
! build1 (ADDR_EXPR, nativecode_ptr_type_node,
! method),
! list);
}
}
+
/* Dummy entry for compatibility with G++ -fvtable-thunks. When
using the Boehm GC we sometimes stash a GC type descriptor
there. We set the PURPOSE to NULL_TREE not to interfere (reset)
the emitted byte count during the output to the assembly file. */
! for (j = 1; j < TARGET_VTABLE_USES_DESCRIPTORS; ++j)
! list = tree_cons (NULL_TREE, null_pointer_node, list);
! list = tree_cons (NULL_TREE, get_boehm_type_descriptor (type), list);
!
! for (j = 1; j < TARGET_VTABLE_USES_DESCRIPTORS; ++j)
! list = tree_cons (NULL_TREE, null_pointer_node, list);
list = tree_cons (integer_zero_node, this_class_addr, list);
!
! arraysize = nvirtuals + 2;
! if (TARGET_VTABLE_USES_DESCRIPTORS)
! arraysize *= TARGET_VTABLE_USES_DESCRIPTORS;
! return build (CONSTRUCTOR,
! build_prim_array_type (nativecode_ptr_type_node, arraysize),
! NULL_TREE, list);
}
void
*************** build_dtable_decl (type)
*** 1733,1745 ****
TYPE. */
if (current_class == type)
{
! tree dummy = NULL_TREE, aomt, n;
dtype = make_node (RECORD_TYPE);
PUSH_FIELD (dtype, dummy, "class", class_ptr_type);
! n = build_int_2 (TREE_VEC_LENGTH (get_dispatch_vector (type)), 0);
! aomt = build_array_type (ptr_type_node, build_index_type (n));
! PUSH_FIELD (dtype, dummy, "methods", aomt);
layout_type (dtype);
}
else
--- 1760,1796 ----
TYPE. */
if (current_class == type)
{
! tree dummy = NULL_TREE;
! int n;
dtype = make_node (RECORD_TYPE);
+
PUSH_FIELD (dtype, dummy, "class", class_ptr_type);
! for (n = 1; n < TARGET_VTABLE_USES_DESCRIPTORS; ++n)
! {
! tree tmp_field = build_decl (FIELD_DECL, NULL_TREE, ptr_type_node);
! TREE_CHAIN (dummy) = tmp_field;
! DECL_CONTEXT (tmp_field) = dtype;
! DECL_ARTIFICIAL (tmp_field) = 1;
! dummy = tmp_field;
! }
!
! PUSH_FIELD (dtype, dummy, "gc_descr", ptr_type_node);
! for (n = 1; n < TARGET_VTABLE_USES_DESCRIPTORS; ++n)
! {
! tree tmp_field = build_decl (FIELD_DECL, NULL_TREE, ptr_type_node);
! TREE_CHAIN (dummy) = tmp_field;
! DECL_CONTEXT (tmp_field) = dtype;
! DECL_ARTIFICIAL (tmp_field) = 1;
! dummy = tmp_field;
! }
!
! n = TREE_VEC_LENGTH (get_dispatch_vector (type));
! if (TARGET_VTABLE_USES_DESCRIPTORS)
! n *= TARGET_VTABLE_USES_DESCRIPTORS;
!
! PUSH_FIELD (dtype, dummy, "methods",
! build_prim_array_type (nativecode_ptr_type_node, n));
layout_type (dtype);
}
else
Index: gcc/java/expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.116
diff -c -p -d -r1.116 expr.c
*** expr.c 2001/09/13 14:37:24 1.116
--- expr.c 2001/09/20 22:19:17
*************** build_invokevirtual (dtable, method)
*** 1845,1853 ****
method_index = size_binop (PLUS_EXPR, method_index, size_int (2));
method_index = size_binop (MULT_EXPR, method_index,
TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node));
func = fold (build (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
convert (nativecode_ptr_ptr_type_node, method_index)));
! func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func);
return func;
}
--- 1845,1862 ----
method_index = size_binop (PLUS_EXPR, method_index, size_int (2));
method_index = size_binop (MULT_EXPR, method_index,
TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node));
+
+ if (TARGET_VTABLE_USES_DESCRIPTORS)
+ method_index = size_binop (MULT_EXPR, method_index,
+ size_int (TARGET_VTABLE_USES_DESCRIPTORS));
+
func = fold (build (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
convert (nativecode_ptr_ptr_type_node, method_index)));
!
! if (TARGET_VTABLE_USES_DESCRIPTORS)
! func = build1 (NOP_EXPR, nativecode_ptr_type_node, func);
! else
! func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func);
return func;
}