7061125: Proposed javac argument processing performance improvement

Thu, 07 Jul 2011 13:29:31 -0700

author
jjg
date
Thu, 07 Jul 2011 13:29:31 -0700
changeset 1055
7337295434b6
parent 1054
111bbf1ad913
child 1056
025a370b9fc3

7061125: Proposed javac argument processing performance improvement
Reviewed-by: jjg, dlsmith, mcimadamore, forax
Contributed-by: schlosna@gmail.com

src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/Main.java file | annotate | diff | comparison | revisions
test/tools/javac/T6358166.java file | annotate | diff | comparison | revisions
test/tools/javac/T6358168.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Tue Jul 05 16:37:24 2011 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Thu Jul 07 13:29:31 2011 -0700
     1.3 @@ -158,10 +158,10 @@
     1.4          } else {
     1.5              initContext();
     1.6              compilerMain.setOptions(Options.instance(context));
     1.7 -            compilerMain.filenames = new ListBuffer<File>();
     1.8 -            List<File> filenames = compilerMain.processArgs(CommandLine.parse(args));
     1.9 +            compilerMain.filenames = new LinkedHashSet<File>();
    1.10 +            Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args));
    1.11              if (!filenames.isEmpty())
    1.12 -                throw new IllegalArgumentException("Malformed arguments " + filenames.toString(" "));
    1.13 +                throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " "));
    1.14              compiler = JavaCompiler.instance(context);
    1.15              compiler.keepComments = true;
    1.16              compiler.genEndPos = true;
    1.17 @@ -177,6 +177,17 @@
    1.18          }
    1.19      }
    1.20  
    1.21 +    <T> String toString(Iterable<T> items, String sep) {
    1.22 +        String currSep = "";
    1.23 +        StringBuilder sb = new StringBuilder();
    1.24 +        for (T item: items) {
    1.25 +            sb.append(currSep);
    1.26 +            sb.append(item.toString());
    1.27 +            currSep = sep;
    1.28 +        }
    1.29 +        return sb.toString();
    1.30 +    }
    1.31 +
    1.32      private void initContext() {
    1.33          context.put(JavacTaskImpl.class, this);
    1.34          if (context.get(TaskListener.class) != null)
     2.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java	Tue Jul 05 16:37:24 2011 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Thu Jul 07 13:29:31 2011 -0700
     2.3 @@ -31,7 +31,10 @@
     2.4  import java.net.URL;
     2.5  import java.security.DigestInputStream;
     2.6  import java.security.MessageDigest;
     2.7 +import java.util.Collection;
     2.8 +import java.util.LinkedHashSet;
     2.9  import java.util.MissingResourceException;
    2.10 +import java.util.Set;
    2.11  import javax.tools.JavaFileManager;
    2.12  import javax.tools.JavaFileObject;
    2.13  import javax.annotation.processing.Processor;
    2.14 @@ -107,8 +110,7 @@
    2.15          }
    2.16  
    2.17          public void addFile(File f) {
    2.18 -            if (!filenames.contains(f))
    2.19 -                filenames.append(f);
    2.20 +            filenames.add(f);
    2.21          }
    2.22  
    2.23          public void addClassName(String s) {
    2.24 @@ -136,7 +138,7 @@
    2.25  
    2.26      /** The list of source files to process
    2.27       */
    2.28 -    public ListBuffer<File> filenames = null; // XXX sb protected
    2.29 +    public Set<File> filenames = null; // XXX sb protected
    2.30  
    2.31      /** List of class files names passed on the command line
    2.32       */
    2.33 @@ -202,7 +204,7 @@
    2.34       *  in `options' table and return all source filenames.
    2.35       *  @param flags    The array of command line arguments.
    2.36       */
    2.37 -    public List<File> processArgs(String[] flags) { // XXX sb protected
    2.38 +    public Collection<File> processArgs(String[] flags) { // XXX sb protected
    2.39          int ac = 0;
    2.40          while (ac < flags.length) {
    2.41              String flag = flags[ac];
    2.42 @@ -294,7 +296,7 @@
    2.43              showClass(showClass);
    2.44          }
    2.45  
    2.46 -        return filenames.toList();
    2.47 +        return filenames;
    2.48      }
    2.49      // where
    2.50          private boolean checkDirectory(OptionName optName) {
    2.51 @@ -342,7 +344,7 @@
    2.52          if (options == null)
    2.53              options = Options.instance(context); // creates a new one
    2.54  
    2.55 -        filenames = new ListBuffer<File>();
    2.56 +        filenames = new LinkedHashSet<File>();
    2.57          classnames = new ListBuffer<String>();
    2.58          JavaCompiler comp = null;
    2.59          /*
    2.60 @@ -356,7 +358,7 @@
    2.61                  return EXIT_CMDERR;
    2.62              }
    2.63  
    2.64 -            List<File> files;
    2.65 +            Collection<File> files;
    2.66              try {
    2.67                  files = processArgs(CommandLine.parse(args));
    2.68                  if (files == null) {
     3.1 --- a/test/tools/javac/T6358166.java	Tue Jul 05 16:37:24 2011 -0700
     3.2 +++ b/test/tools/javac/T6358166.java	Thu Jul 07 13:29:31 2011 -0700
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -61,7 +61,7 @@
    3.11  
    3.12          Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    3.13          compilerMain.setOptions(Options.instance(context));
    3.14 -        compilerMain.filenames = new ListBuffer<File>();
    3.15 +        compilerMain.filenames = new LinkedHashSet<File>();
    3.16          compilerMain.processArgs(args);
    3.17  
    3.18          JavaCompiler c = JavaCompiler.instance(context);
     4.1 --- a/test/tools/javac/T6358168.java	Tue Jul 05 16:37:24 2011 -0700
     4.2 +++ b/test/tools/javac/T6358168.java	Thu Jul 07 13:29:31 2011 -0700
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -72,7 +72,7 @@
    4.11  
    4.12          Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    4.13          compilerMain.setOptions(Options.instance(context));
    4.14 -        compilerMain.filenames = new ListBuffer<File>();
    4.15 +        compilerMain.filenames = new LinkedHashSet<File>();
    4.16          compilerMain.processArgs(new String[] { "-d", "." });
    4.17  
    4.18          JavaCompiler compiler = JavaCompiler.instance(context);
    4.19 @@ -91,7 +91,7 @@
    4.20  
    4.21          Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    4.22          compilerMain.setOptions(Options.instance(context));
    4.23 -        compilerMain.filenames = new ListBuffer<File>();
    4.24 +        compilerMain.filenames = new LinkedHashSet<File>();
    4.25          compilerMain.processArgs(new String[] {
    4.26                                       "-XprintRounds",
    4.27                                       "-processorpath", testClasses,

mercurial