This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: this$<n> initialization -vs- verification
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 08 Dec 2001 20:12:26 -0700
- Subject: Patch: this$<n> initialization -vs- verification
- Reply-to: tromey at redhat dot com
Currently, gcj -C will generate unverifiable bytecode for this class:
public class t
{
public class x
{
}
public static void main (String[] args)
{
}
}
The constructor for x assigns to this$0 before it invokes super(),
which is a violation of the JVM spec. The gij bytecode verifier
catches this (one of a very few actual verification failures it has
correctly detected :-).
This patch attempts to fix the problem. It works on the above test
case. I'm rebuilding libgcj with this. Assuming the rebuild is fine,
is this ok to check in?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* parse.y (fix_constructors): Assign to this$<n> field after
invoking superclass initializer.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.331
diff -u -r1.331 parse.y
--- parse.y 2001/12/06 23:12:55 1.331
+++ parse.y 2001/12/09 03:04:16
@@ -8792,16 +8792,16 @@
CLASSNAME() constructor */
start_artificial_method_body (mdecl);
- /* Insert an assignment to the this$<n> hidden field, if
- necessary */
- if ((thisn_assign = build_thisn_assign ()))
- java_method_add_stmt (mdecl, thisn_assign);
-
/* We don't generate a super constructor invocation if we're
compiling java.lang.Object. build_super_invocation takes care
of that. */
java_method_add_stmt (mdecl, build_super_invocation (mdecl));
+ /* Insert an assignment to the this$<n> hidden field, if
+ necessary */
+ if ((thisn_assign = build_thisn_assign ()))
+ java_method_add_stmt (mdecl, thisn_assign);
+
/* FIXME */
if ((iii = build_instinit_invocation (class_type)))
java_method_add_stmt (mdecl, iii);
@@ -8839,15 +8839,11 @@
body = NULL_TREE;
}
- /* Generate the assignment to this$<n>, if necessary */
- if ((thisn_assign = build_thisn_assign ()))
- compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
-
/* The constructor is missing an invocation of super() */
if (!found)
compound = add_stmt_to_compound (compound, NULL_TREE,
build_super_invocation (mdecl));
- /* Explicit super() invokation should take place before the
+ /* Explicit super() invocation should take place before the
instance initializer blocks. */
else
{
@@ -8855,7 +8851,11 @@
TREE_OPERAND (found_call, 0));
TREE_OPERAND (found_call, 0) = empty_stmt_node;
}
-
+
+ /* Generate the assignment to this$<n>, if necessary */
+ if ((thisn_assign = build_thisn_assign ()))
+ compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
+
DECL_INIT_CALLS_THIS (mdecl) = invokes_this;
/* Insert the instance initializer block right after. */