RFR: 8263452: Javac slow compilation due to algorithmic complexity
Jan Lahoda
jlahoda at openjdk.java.net
Thu Apr 15 16:39:00 UTC 2021
Consider a class that extends its enclosing class. There are a few places in javac where javac does some actions for the supertype and enclosing class, doing these actions twice in this scenario. If the enclosing class also extends its enclosing class, and its enclosing type does as well, etc., these checks are done for the enclosing classes, and the number of actions grows exponentially.
Even though this seems like a rare case, we can improve javac by avoiding redoing the checks that were already done. There are two parts:
-`Check.checkNonCyclicDecl` will not record the hierarchy is acyclic if a supertype uses a full-qualified name, as it considers the hierarchy to be "partial", as it only considers hierarchies non-partial if all super AST nodes are filled with class symbols. The proposed solution is to not mark the hierarchy as partial if a part of the FQN is attributed as a package symbol. As a side tweak, the cycle detector is now proposed to be a Set rather than a List, to improve lookup times.
-in `attribClass`, first the superclass and enclosing class of the current class are attributed, but these are done even if already done, and in the case of the class hierarchy described here these no-op attributions can be done very many times. The proposed fix is to do the attribution of super/enclosing only once.
-------------
Commit messages:
- Improving order of Flag constants.
- 8263452: Javac slow compilation due to algorithmic complexity
Changes: https://git.openjdk.java.net/jdk/pull/3523/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3523&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8263452
Stats: 107 lines in 4 files changed: 101 ins; 0 del; 6 mod
Patch: https://git.openjdk.java.net/jdk/pull/3523.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/3523/head:pull/3523
PR: https://git.openjdk.java.net/jdk/pull/3523
More information about the compiler-dev
mailing list