This is the mail archive of the
java-prs@sourceware.cygnus.com
mailing list for the Java project.
Re: gcj/131
- To: apbianco at cygnus dot com
- Subject: Re: gcj/131
- From: Alexandre Petit-Bianco <apbianco at cygnus dot com>
- Date: 30 Mar 2000 23:16:00 -0000
- Cc: java-prs at sourceware dot cygnus dot com,
- Reply-To: Alexandre Petit-Bianco <apbianco at cygnus dot com>
The following reply was made to PR gcj/131; it has been noted by GNATS.
From: Alexandre Petit-Bianco <apbianco@cygnus.com>
To: Pekka Nikander <Pekka.Nikander@hut.fi>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/131
Date: Thu, 30 Mar 2000 15:10:48 -0800 (PST)
Pekka Nikander writes:
> I've been running with the test disabled for about a week now,
> without any apparent problems. Thus, I wholly agree with you.
And it looks like with the attached patch, we can get rid of <clinit>
when it turns out to be unnecessary. I'm testing it at the moment and
so far it looks OK.
./A
Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.146
diff -u -p -r1.146 parse.y
--- parse.y 2000/03/23 07:01:24 1.146
+++ parse.y 2000/03/30 23:08:25
@@ -136,6 +136,7 @@ static tree obtain_incomplete_type PARAM
static tree java_complete_lhs PARAMS ((tree));
static tree java_complete_tree PARAMS ((tree));
static tree maybe_generate_pre_expand_clinit PARAMS ((tree));
+static int maybe_yank_clinit PARAMS ((tree));
static void java_complete_expand_method PARAMS ((tree));
static int unresolved_type_p PARAMS ((tree, tree *));
static void create_jdep_list PARAMS ((struct parser_ctxt *));
@@ -7332,17 +7333,17 @@ maybe_generate_pre_expand_clinit (class_
end_artificial_method_body (mdecl);
- /* Now we want to place <clinit> as the last method for interface so
- that it doesn't interfere with the dispatch table based
- lookup. */
- if (CLASS_INTERFACE (TYPE_NAME (class_type))
- && TREE_CHAIN (TYPE_METHODS (class_type)))
+ /* Now we want to place <clinit> as the last method (because we need
+ it at least for interface so that it doesn't interfere with the
+ dispatch table based lookup. */
+ if (TREE_CHAIN (TYPE_METHODS (class_type)))
{
- tree current =
- TYPE_METHODS (class_type) = TREE_CHAIN (TYPE_METHODS (class_type));
+ current = TREE_CHAIN (TYPE_METHODS (class_type));
+ TYPE_METHODS (class_type) = current;
while (TREE_CHAIN (current))
current = TREE_CHAIN (current);
+
TREE_CHAIN (current) = mdecl;
TREE_CHAIN (mdecl) = NULL_TREE;
}
@@ -7350,6 +7351,47 @@ maybe_generate_pre_expand_clinit (class_
return mdecl;
}
+/* See whether we could get rid of <clinit>. Criteria are: all static
+ final fields have constant initial values. Return 1 if <clinit> was
+ discarded, 0 otherwise. */
+
+static int
+maybe_yank_clinit (mdecl)
+ tree mdecl;
+{
+ tree type, current;
+
+ if (!DECL_CLINIT_P (mdecl))
+ return 0;
+
+ type = DECL_CONTEXT (mdecl);
+ current = TYPE_FIELDS (type);
+
+ for (current = (current ? TREE_CHAIN (current) : current);
+ current; current = TREE_CHAIN (current))
+ if (!(FIELD_STATIC (current) && FIELD_FINAL (current)
+ && DECL_INITIAL (current) && TREE_CONSTANT (DECL_INITIAL (current))))
+ break;
+
+ if (current)
+ return 0;
+
+ /* Get rid of <clinit> in the class' list of methods */
+ if (TYPE_METHODS (type) == mdecl)
+ TYPE_METHODS (type) = TREE_CHAIN (mdecl);
+ else
+ for (current = TYPE_METHODS (type); current;
+ current = TREE_CHAIN (current))
+ if (TREE_CHAIN (current) == mdecl)
+ {
+ TREE_CHAIN (current) = TREE_CHAIN (mdecl);
+ break;
+ }
+
+ return 1;
+}
+
+
/* Complete and expand a method. */
static void
@@ -7403,16 +7445,21 @@ java_complete_expand_method (mdecl)
&& !flag_emit_xref)
missing_return_error (current_function_decl);
- complete_start_java_method (mdecl);
-
- /* Don't go any further if we've found error(s) during the
- expansion */
- if (!java_error_count)
- source_end_java_method ();
- else
- {
- pushdecl_force_head (DECL_ARGUMENTS (mdecl));
- poplevel (1, 0, 1);
+ /* Check wether we could just get rid of clinit, now the picture
+ is complete. */
+ if (!maybe_yank_clinit (mdecl))
+ {
+ complete_start_java_method (mdecl);
+
+ /* Don't go any further if we've found error(s) during the
+ expansion */
+ if (!java_error_count)
+ source_end_java_method ();
+ else
+ {
+ pushdecl_force_head (DECL_ARGUMENTS (mdecl));
+ poplevel (1, 0, 1);
+ }
}
/* Pop the exceptions and sanity check */
@@ -14488,8 +14535,6 @@ fold_constant_for_init (node, context)
if (code == INTEGER_CST || code == REAL_CST)
return convert (TREE_TYPE (context), node);
- if (TREE_TYPE (node) != NULL_TREE && code != VAR_DECL && code != FIELD_DECL)
- return NULL_TREE;
switch (code)
{