This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Java: Avoid multiple warnings for source files newer thanclass files


Hi,

  GCJ currently warns if while finding a class it finds both
a class file as well as a Java source file for the class
and the source file is more recent than the class file.

In some cases - for example, while compiling a JAR file - this
warning can unnecessarily be issued quite a few times for the
*same* class and become quite irritating. Consider a simple
test case:
----------------------------- 8< -----------------------------
$ cat X.java
public class X { }

$ cat Y1.java Y2.java
public class Y1 extends X {}
public class Y2 extends X {}

$ $MYGCJ -C X.java
$ touch X.java
----------------------------- 8< -----------------------------

If you now try to compile Y1.java and Y2.java on the same
command line, you'll see the warning about X *four* times.

With the appended patch, you'll see the warning only two
times while compiling the "normal way" and only once if
you compile using the "@filelist" syntax. (This is because
the GCC driver passes files individually to jc1 even though
it is quite capable of handling multiple files at the same
time - this is possibly fodder for another patch.)

This patch also helps avoid unnecessarily calling
find_class(), which can be quite expensive, if we've
already parsed a source file.

I've tested this on i686-pc-linux-gnu with the libjava
and Jacks testsuites and this produced no regressions.

OK for mainline?

Ranjit.

Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

        * jcf-parse.c (read_class): Create jcf for a class that has already
        been read from a source file. Avoids unnecessary call to find_class
        for this case.

Index: jcf-parse.c
===================================================================
--- jcf-parse.c 2004-06-19 17:10:37.000000000 +0530
+++ jcf-parse.c 2004-06-19 20:27:46.000000000 +0530
@@ -475,7 +475,19 @@ read_class (tree name)
   if ((icv = IDENTIFIER_CLASS_VALUE (name)) != NULL_TREE)
     {
       class = TREE_TYPE (icv);
-      jcf = TYPE_JCF (class);
+
+      if (CLASS_FROM_SOURCE_P (class))
+        {
+          JCF_ZERO (&this_jcf);
+
+          this_jcf.java_source = 1;
+          this_jcf.classname = xstrdup (IDENTIFIER_POINTER (name));
+          this_jcf.filename = xstrdup (DECL_SOURCE_FILE (icv));
+
+          jcf = &this_jcf;
+        }
+      else
+        jcf = TYPE_JCF (class);
     }
   else
     jcf = NULL;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]