Skip to content

8263452: Javac slow compilation due to algorithmic complexity #3523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Apr 15, 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.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263452: Javac slow compilation due to algorithmic complexity

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3523/head:pull/3523
$ git checkout pull/3523

Update a local copy of the PR:
$ git checkout pull/3523
$ git pull https://git.openjdk.java.net/jdk pull/3523/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3523

View PR using the GUI difftool:
$ git pr show -t 3523

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3523.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 15, 2021

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 15, 2021
@openjdk
Copy link

openjdk bot commented Apr 15, 2021

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Apr 15, 2021
@mlbridge
Copy link

mlbridge bot commented Apr 15, 2021

Webrevs

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks sensible

@openjdk
Copy link

openjdk bot commented Apr 15, 2021

@lahodaj This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8263452: Javac slow compilation due to algorithmic complexity

Reviewed-by: vromero, jfranck

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 442 new commits pushed to the master branch:

  • 6018336: 8259316: [REDO] C1/C2 compiler support for blackholes
  • f07bb2f: 8250766: javadoc adds redundant spaces when @see program element is wrapped
  • 61bb6ec: 8266453: Shenandoah: Disable write protections before patching nmethod in nmethod_barrier on MacOSX/AArch64
  • a05e8e2: 8266497: Remove unnecessary EMCP liveness indication
  • 6ba911d: 8266498: Make debug ps() call print_stack
  • ef0f693: 8266499: Delete dead code in aarch64.ad
  • 71d0858: 8266522: Shenandoah: Shenandoah LRB calls wrong runtime barrier on aarch64
  • 0ac84d1: 8266506: [aix] Treat mapping attempt too close to BRK as a mapping error
  • 02cdd6e: 8266419: [aix] in mmap mode, os::attempt_reserve_memory_at() fails to handle wrong mapping address
  • 250b45a: 8266222: [aix] In mmap-mode, partial releases with os::release_memory may trash internal bookkeeping
  • ... and 432 more: https://git.openjdk.java.net/jdk/compare/ec31b3a13734a6c4fbe14afcef84b9e1768226db...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 15, 2021
@@ -5089,14 +5089,17 @@ void attribClass(ClassSymbol c) throws CompletionFailure {
chk.checkNonCyclic(null, c.type);

Type st = types.supertype(c.type);
if ((c.flags_field & Flags.COMPOUND) == 0) {
if ((c.flags_field & Flags.COMPOUND) == 0 &&
(c.flags_field & Flags.SUPER_OWNER_ATTRIBUTED) == 0) {
// First, attribute superclass.
if (st.hasTag(CLASS))
attribClass((ClassSymbol)st.tsym);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a guarding against a special case of attributing something twice. Did you consider pushing this into attribClass instead so that calling it a second time is a no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbf, sorry, I missed you comment.

I was thinking of using Flags.UNATTRIBUTED and skipping this whole method. I was a bit worried about a case where a class from source has a supertype from classfile (which never has UNATTRIBUTED), which has a supertype from source - by using UNATTRIBUTED, we could get to a state where this supertype attribution wouldn't attribute the super-supertype from source. Using another flag is an attempt to avoid this issue completely - the cost is using one more flag out of a limited pool of flags, of course.

Copy link
Member

@jbf jbf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, though you should probably get a second reviewer.

@lahodaj
Copy link
Contributor Author

lahodaj commented May 11, 2021

/integrate

@openjdk openjdk bot closed this May 11, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 11, 2021
@openjdk
Copy link

openjdk bot commented May 11, 2021

@lahodaj Since your change was applied there have been 512 commits pushed to the master branch:

  • 67cb22a: 8266601: Fix bugs in AddLNode::Ideal transformations
  • 18e9d28: 8266676: G1: Remove dead code init_node_id_to_index_map()
  • 0e7bdae: 8265062: Remove duplication constant MaxTextureSize
  • 10a049e: 8265956: JVM crashes when matching LShiftVB Node
  • 9713152: 8262092: vmTestbase/nsk/jvmti/scenarios/hotswap/HS102/hs102t001/TestDescription.java SIGSEGV in memmove_ssse3
  • 23446f1: 8265128: [REDO] Optimize Vector API slice and unslice operations
  • e5d3ee3: 8266802: Shenandoah: Round up region size to page size unconditionally
  • 8851cb6: 8266779: Use instead of ZERO_WIDTH_SPACE
  • 0cc7833: 8265208: [JEP-356] : SplittableRandom and SplittableGenerators - splits() methods does not throw NullPointerException when source is null
  • f78440a: 8266440: Shenandoah: TestReferenceShortcutCycle.java test failed on AArch64
  • ... and 502 more: https://git.openjdk.java.net/jdk/compare/ec31b3a13734a6c4fbe14afcef84b9e1768226db...master

Your commit was automatically rebased without conflicts.

Pushed as commit 8468001.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants