This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: make vtable layout abi-dependent
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 07 Mar 2005 17:31:44 -0700
- Subject: [gcjx] Patch: FYI: make vtable layout abi-dependent
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
This patch changes Class creation so that the generated vtable is
abi-dependent. In particular for the BC ABI we don't generate a
vtable.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* classobj.hh (class_object_creator::fill_in_vtable): Declare.
* abi.cc (get_vtable): Updated.
* abi.hh (gcj_abi::get_vtable): Removed 'lay_out' argument.
(cxx_abi::get_vtable): Updated.
(bc_abi::get_vtable): Updated.
* classobj.cc (fill_in_vtable): New method.
(create_class_instance): Use it.
* builtins.hh (tree_builtins::get_vtable_decl): Declare.
* builtins.cc (get_vtable_decl): Removed 'lay_out' argument.
Index: abi.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.cc,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 abi.cc
--- abi.cc 8 Mar 2005 00:29:19 -0000 1.1.2.7
+++ abi.cc 8 Mar 2005 00:33:28 -0000
@@ -195,10 +195,9 @@
}
tree
-cxx_abi::get_vtable (tree_builtins *builtins, model_class *klass,
- bool lay_out)
+cxx_abi::get_vtable (tree_builtins *builtins, model_class *klass)
{
- return build_address_of (builtins->get_vtable_decl (klass, lay_out));
+ return build_address_of (builtins->get_vtable_decl (klass));
}
tree
Index: abi.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.hh,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 abi.hh
--- abi.hh 8 Mar 2005 00:29:19 -0000 1.1.2.5
+++ abi.hh 8 Mar 2005 00:33:28 -0000
@@ -111,8 +111,7 @@
/// Return a pointer to the vtable for the indicated class. If the
/// bool argument is true, we are creating the Class object for
/// KLASS and need a fully-filled-in vtable, not just a decl.
- virtual tree get_vtable (tree_builtins *builtins, model_class *klass,
- bool lay_out = false) = 0;
+ virtual tree get_vtable (tree_builtins *builtins, model_class *klass) = 0;
/// Return tree representing index into vtable where this method can
/// be found. Should return -1 for a static method or constructor.
@@ -154,7 +153,7 @@
return JV_STATE_COMPILED;
}
- tree get_vtable (tree_builtins *, model_class *, bool);
+ tree get_vtable (tree_builtins *, model_class *);
tree get_vtable_index (aot_class *klass, model_method *method);
};
@@ -194,7 +193,7 @@
return JV_STATE_PRELOADING;
}
- tree get_vtable (tree_builtins *, model_class *, bool)
+ tree get_vtable (tree_builtins *, model_class *)
{
// The BC ABI lays out all vtables at runtime.
return null_pointer_node;
Index: builtins.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.cc,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 builtins.cc
--- builtins.cc 8 Mar 2005 00:22:45 -0000 1.1.2.11
+++ builtins.cc 8 Mar 2005 00:33:28 -0000
@@ -473,7 +473,7 @@
}
tree
-tree_builtins::get_vtable_decl (model_class *klass, bool lay_out)
+tree_builtins::get_vtable_decl (model_class *klass)
{
if (vtable_map.find (klass) == vtable_map.end ())
{
@@ -485,37 +485,6 @@
SET_DECL_ASSEMBLER_NAME (decl,
get_identifier (m.get ().c_str ()));
- if (lay_out)
- {
- lay_out_class (klass);
-
- tree klass_ptr_type = map_type (klass);
- tree vtable = BINFO_VTABLE (TYPE_BINFO (TREE_TYPE (klass_ptr_type)));
-
- // FIXME: this isn't really correct.
- // it fails where a pointer-to-function is wider.
- tree vtype
- = build_array_type (type_nativecode_ptr,
- build_index_type (build_int_cst (type_jint,
- TREE_VEC_LENGTH (vtable))));
- tree cons = NULL_TREE;
-
- TREE_TYPE (decl) = vtype;
-
- // FIXME: set these on the initializer when we make it.
- // Also set them on the decl?
- // TREE_CONSTANT (init) = 1;
- // TREE_INVARIANT (init) = 1;
- // TREE_READONLY (init) = 1;
-
- // FIXME: make a helper method for this sequence.
- // Is it even correct? We do something with cgraph in
- // treegen.cc.
- layout_decl (decl, 0);
- rest_of_decl_compilation (decl, 1, 0);
- make_decl_rtl (decl);
- }
-
vtable_map[klass] = decl;
}
return vtable_map[klass];
@@ -533,13 +502,14 @@
// Create a new tree vector to represent the vtable, and fill it in.
// Note that we have two empty slots at the beginning; this is kept
// in sync with aot_class. FIXME: define a constant.
+ // FIXME: should move into aotclass.
tree vtable_tree = make_tree_vec (2 + vtable.size ());
int index = 2;
for (std::vector<model_method *>::const_iterator i = vtable.begin ();
i != vtable.end ();
++i)
{
- TREE_VEC_ELT (vtable_tree, index) = map_method (*i);
+ TREE_VEC_ELT (vtable_tree, index) = build_address_of (map_method (*i));
++index;
}
Index: builtins.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.hh,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 builtins.hh
--- builtins.hh 8 Mar 2005 00:22:45 -0000 1.1.2.8
+++ builtins.hh 8 Mar 2005 00:33:28 -0000
@@ -120,10 +120,8 @@
/// Return a new unique symbol name.
tree get_symbol ();
- /// Return the decl for a given class' vtable. If the second
- /// argument is true, assume we are laying out the vtable, so go
- /// ahead and fill it in.
- tree get_vtable_decl (model_class *, bool = false);
+ /// Return the decl for a given class' vtable.
+ tree get_vtable_decl (model_class *);
};
#endif // GCC_TREE_BUILTINS_HH
Index: classobj.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/classobj.cc,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 classobj.cc
--- classobj.cc 8 Mar 2005 00:29:19 -0000 1.1.2.13
+++ classobj.cc 8 Mar 2005 00:33:32 -0000
@@ -378,6 +378,48 @@
}
void
+class_object_creator::fill_in_vtable (tree decl)
+{
+ // We are passed the address of the actual decl.
+ assert (TREE_CODE (decl) == ADDR_EXPR);
+ decl = TREE_OPERAND (decl, 0);
+
+ tree klass_ptr_type = builtins->lay_out_class (klass->get ());
+ tree klass_record = TREE_TYPE (klass_record);
+
+ tree vtable = BINFO_VTABLE (TYPE_BINFO (TREE_TYPE (klass_ptr_type)));
+
+ // FIXME: this isn't really correct.
+ // it fails where a pointer-to-function is wider.
+ tree vtype
+ = build_array_type (type_nativecode_ptr,
+ build_index_type (build_int_cst (type_jint,
+ TREE_VEC_LENGTH (vtable))));
+
+ tree cons = NULL_TREE;
+ for (int i = 0; i < TREE_VEC_LENGTH (vtable); ++i)
+ cons = tree_cons (build_int_cst (type_jint, i), TREE_VEC_ELT (vtable, i),
+ cons);
+ cons = nreverse (cons);
+
+ tree init = build_constructor (vtype, cons);
+ // Also set these on the decl?
+ TREE_CONSTANT (init) = 1;
+ TREE_INVARIANT (init) = 1;
+ TREE_READONLY (init) = 1;
+
+ DECL_INITIAL (decl) = init;
+
+ // FIXME: make a helper method for this sequence.
+ // Is it even correct? We do something with cgraph in
+ // treegen.cc.
+ layout_decl (decl, 0);
+ rest_of_decl_compilation (decl, 1, 0);
+ make_decl_rtl (decl);
+
+}
+
+void
class_object_creator::create_class_instance (tree class_tree)
{
assert (TREE_CODE (class_tree) == RECORD_TYPE);
@@ -433,7 +475,10 @@
inst.set_field ("static_field_count",
build_int_cst (type_jshort, num_static_fields));
- inst.set_field ("dtable", abi->get_vtable (builtins, klass->get (), true));
+ tree dtable = abi->get_vtable (builtins, klass->get ());
+ if (dtable != null_pointer_node)
+ fill_in_vtable (dtable);
+ inst.set_field ("dtable", dtable);
tree table, syms;
create_index_table (klass->get_otable (), table, syms);
Index: classobj.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/classobj.hh,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 classobj.hh
--- classobj.hh 8 Mar 2005 00:22:45 -0000 1.1.2.5
+++ classobj.hh 8 Mar 2005 00:33:32 -0000
@@ -74,6 +74,7 @@
tree &, tree &);
void create_class_instance (tree);
tree create_constants ();
+ void fill_in_vtable (tree);
public: