This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: class init fixlet
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 14 Dec 2005 15:56:55 -0700
- Subject: [gcjx] Patch: FYI: class init fixlet
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
We shouldn't initialize a class from inside a method of that class.
There are other cases we could avoid but that will require pushing
class init more fully into the ABI class.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* tree.cc (visit_field_ref): Don't annotate variable.
(visit_method): Don't initialize current class.
* abi.cc (build_field_reference): Don't initialize current class.
Index: abi.cc
===================================================================
--- abi.cc (revision 105944)
+++ abi.cc (working copy)
@@ -182,7 +182,7 @@
tree
cxx_abi::build_field_reference (tree_builtins *builtins,
- aot_class *,
+ aot_class *current,
tree obj, model_field *field)
{
builtins->lay_out_class (field->get_declaring_class ());
@@ -191,10 +191,15 @@
{
assert (obj == NULL_TREE);
- result
- = build2 (COMPOUND_EXPR, TREE_TYPE (result),
- builtins->build_class_init (field->get_declaring_class ()),
- result);
+ // Don't initialize the class if the field is declared locally.
+ // FIXME: should be smarter about this, for C++ ABI we could
+ // avoid this for the entire concrete hierarchy.
+ // FIXME: also doesn't work well with generics.
+ if (current->get () != field->get_declaring_class ())
+ result
+ = build2 (COMPOUND_EXPR, TREE_TYPE (result),
+ builtins->build_class_init (field->get_declaring_class ()),
+ result);
}
else
{
Index: tree.cc
===================================================================
--- tree.cc (revision 108442)
+++ tree.cc (working copy)
@@ -155,7 +155,11 @@
tree statements = alloc_stmt_list ();
tree_stmt_iterator out = tsi_start (statements);
- if (meth->static_p () && ! meth->static_initializer_p ())
+ if (meth->static_p () && ! meth->static_initializer_p ()
+ // Don't emit check for methods declared here. FIXME: this
+ // should be an ABI decision. FIXME: also possibly doesn't
+ // work well with generics.
+ && class_wrapper->get () != meth->get_declaring_class ())
{
tree init
= gcc_builtins->build_class_init (meth->get_declaring_class ());
@@ -2027,7 +2031,8 @@
gcc_builtins->lay_out_class (field->get_declaring_class ());
current = gcc_builtins->map_field_ref (class_wrapper, expr_tree, field);
- annotate (current, elt);
+ // FIXME: should annotate here, but we might have a var_decl
+ // annotate (current, elt);
}
}