Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8263452

Javac slow compilation due to algorithmic complexity

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 17
    • 15.0.2
    • tools
    • None
    • b22

    Description

      When compiling nested inner classes, there is a certain threshold where compilation times with become exponential with each additional nesting level. This can become a problem in learning environments where the Java Compiler API could be used to compile students scripts in a contained scenario.

      The following source can be created with the attached generator class GenOuterJava . The generator expects an outer class name and a maximum nesting level. It then generates a source file with all the nested classes.

      java GenOuterLevel JavacStalls 20

      The resulting JavacStalls.java can then be processed with Javac or the Compiler API.

      Levels from 30 above expose notable compilation times, especially for the relatively small file size of the originating (generated) source file.


      public class JavacStalls {
              public JavacStalls() {};

         private void outerPrivate(String z) {
         }
      class aa_ extends java.util.ArrayList<Void> {
              @Deprecated
              public aa_() {};
      class ab_ extends aa_ {
              @Deprecated
              public ab_() {};
      class ac_ extends ab_ {
              @Deprecated
              public ac_() {};

      [..]
      class as_ extends ar_ {
              @Deprecated
              public as_() {};
      class at_ extends as_ {
              @Deprecated
              public at_() {};
      class Inner {
              //A a;
              public void innerPublic() {
              outerPrivate(Inner.class.toString());
              }
      }
      }}}}}}}}}}}}}}}}}}}} public void outerPublic() {
                              System.out.println();
              }

      };

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              mschoene Marc Schönefeld
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: