[PATCH] Speedup java front-end when compiling from source

Andrew Pinski pinskia@physics.uc.edu
Sun May 9 14:23:00 GMT 2004


With the recent complaint that compiling libjava is slow.  I decided to 
see if I
could speed up the java front-end and I found that it was calling getc 
a huge
amount even though the warnings or errors were being outputted.  The 
problem
is that parser_check_super_interface was calling lookup_cl which 
generates the
huge amount of calls to getc (indirectly via java_get_line_col).  This 
patches
causes lookup_cl not be called unless the error is going to be 
outputted.
This saves about 10% when compiling  "java{,x}/sql/*.java" at -O0.

Bootstrapped and tested on powerpc-apple-darwin with no regressions and 
it felt
to compile faster.

Thanks,
Andrew Pinski

ChangeLog:

	* parse.y (check_pkg_class_access): Add new argument
	and use it when cl is NULL to call lookup_cl on it.
	(parser_check_super_interface): Do not call lookup_cl.
	Pass this_decl to check_pkg_class_access and NULL
	instead of lookup_cl.
	(parser_check_super): Update for change in
	check_pkg_class_access.
	(do_resolve_class): Likewise.
	(process_imports): Likewise.
	(find_in_imports_on_demand): Likewise.


Patch:
--- /Users/pinskia/src/gcc-tree-ssa/gcc/gcc/java/parse.y	Thu Apr 29 
16:09:46 2004
+++ ./parse.y	Sat May  8 21:51:26 2004
@@ -106,7 +106,7 @@ static void read_import_dir (tree);
  static int find_in_imports_on_demand (tree, tree);
  static void find_in_imports (tree, tree);
  static void check_inner_class_access (tree, tree, tree);
-static int check_pkg_class_access (tree, tree, bool);
+static int check_pkg_class_access (tree, tree, bool, tree);
  static void register_package (tree);
  static tree resolve_package (tree, tree *, tree *);
  static tree resolve_class (tree, tree, tree, tree);
@@ -5062,7 +5062,7 @@ parser_check_super_interface (tree super
       access rules (6.6.1). */
    if (! INNER_CLASS_P (super_type)
        && check_pkg_class_access (DECL_NAME (super_decl),
-				 lookup_cl (this_decl), true))
+				 NULL_TREE, true, this_decl))
      return 1;

    SOURCE_FRONTEND_DEBUG (("Completing interface %s with %s",
@@ -5100,7 +5100,7 @@ parser_check_super (tree super_decl, tre
    /* Check top-level class scope. Inner classes are subject to member 
access
       rules (6.6.1). */
    if (! INNER_CLASS_P (super_type)
-      && (check_pkg_class_access (DECL_NAME (super_decl), wfl, true)))
+      && (check_pkg_class_access (DECL_NAME (super_decl), wfl, true, 
NULL_TREE)))
      return 1;

    SOURCE_FRONTEND_DEBUG (("Completing class %s with %s",
@@ -5840,7 +5840,7 @@ do_resolve_class (tree enclosing, tree c
       by the caller. */
    if (cl)
      {
-      if (check_pkg_class_access (TYPE_NAME (class_type), cl, true))
+      if (check_pkg_class_access (TYPE_NAME (class_type), cl, true, 
NULL_TREE))
          return NULL_TREE;
      }

@@ -6800,7 +6800,7 @@ process_imports (void)
  	  QUALIFIED_P (to_be_found) = 1;
  	  load_class (to_be_found, 0);
  	  error_found =
-	    check_pkg_class_access (to_be_found, TREE_PURPOSE (import), true);
+	    check_pkg_class_access (to_be_found, TREE_PURPOSE (import), true, 
NULL_TREE);

  	  /* We found it, we can bail out */
  	  if (IDENTIFIER_CLASS_VALUE (to_be_found))
@@ -7044,7 +7044,7 @@ find_in_imports_on_demand (tree enclosin
  	}
        if (decl && ! INNER_CLASS_P (TREE_TYPE (decl)))
  	access_check = check_pkg_class_access (node, TREE_PURPOSE (import),
-					       false);
+					       false, NULL_TREE);
        else
  	/* 6.6.1: Inner classes are subject to member access rules. */
  	access_check = 0;
@@ -7230,10 +7230,11 @@ check_inner_class_access (tree decl, tre
  /* Accessibility check for top-level classes. If CLASS_NAME is in a
     foreign package, it must be PUBLIC. Return 0 if no access
     violations were found, 1 otherwise. If VERBOSE is true and an error
-   was found, it is reported and accounted for.  */
+   was found, it is reported and accounted for.  If cl is NULL then
+   lookup it up with THIS_DECL.  */

  static int
-check_pkg_class_access (tree class_name, tree cl, bool verbose)
+check_pkg_class_access (tree class_name, tree cl, bool verbose, tree 
this_decl)
  {
    tree type;

@@ -7258,7 +7259,8 @@ check_pkg_class_access (tree class_name,

        if (verbose)
  	parse_error_context
-	  (cl, "Can't access %s `%s'. Only public classes and interfaces in 
other packages can be accessed",
+	  (cl == NULL ? lookup_cl (this_decl): cl,
+           "Can't access %s `%s'. Only public classes and interfaces 
in other packages can be accessed",
  	   (CLASS_INTERFACE (TYPE_NAME (type)) ? "interface" : "class"),
  	   IDENTIFIER_POINTER (class_name));
        return 1;

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: makejava-fast.diff.txt
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040509/f1eb86ee/attachment.txt>
-------------- next part --------------



More information about the Java-patches mailing list