Skip to content
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

8297455: Use the official ToolProvider API to call javac #11299

Closed

Conversation

magicus
Copy link
Member

@magicus magicus commented Nov 22, 2022

In JDK-8297041, the javacserver was moved out of the JDK itself, and lifted out as a separate buildtool. Due to this, internal classes in jdk.compiler were no longer available. Therefore, the closest way to calling javac as before were to use com.sun.tools.javac.Main.compile(). This method is however deprecated for removal, and relying on that was only needed as a temporary measure during the transition.

After the major refactoring of the javacserver tool in JDK-8297444, it will be easy to replace the Main.compile API with the official ToolProvider API instead.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8297455: Use the official ToolProvider API to call javac

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11299/head:pull/11299
$ git checkout pull/11299

Update a local copy of the PR:
$ git checkout pull/11299
$ git pull https://git.openjdk.org/jdk pull/11299/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11299

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11299.diff

@magicus
Copy link
Member Author

magicus commented Nov 22, 2022

Note that this PR is dependent on JDK-8297444 (PR: #11298)

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 22, 2022

👋 Welcome back ihse! A progress list of the required criteria for merging this PR into pr/11298 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 Nov 22, 2022
@openjdk
Copy link

openjdk bot commented Nov 22, 2022

@magicus The following labels will be automatically applied to this pull request:

  • build
  • compiler

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

@openjdk openjdk bot added build build-dev@openjdk.org compiler compiler-dev@openjdk.org labels Nov 22, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 22, 2022

Webrevs

@erikj79
Copy link
Member

erikj79 commented Nov 22, 2022

Just to make sure, will this find the interim javac before the bootjdk javac? How is this enforced?

@magicus
Copy link
Member Author

magicus commented Nov 22, 2022

Well, I assume so. If this does not work properly, the problem will most likely be already in JDK-8297444; this patch is just choosing a different path to end up in the same class, as far as I can understand.

The thing that makes (or should make) us chose the interim javac is the $(INTERIM_LANGTOOLS_ARGS) which is passed to java when launching the server. (This is since these flags are passed in the config file to the client as javacmd).

I'll add some test output code to the interim compiler to verify that it is actually executed, both in JDK-8297444 and in this PR.

@magicus
Copy link
Member Author

magicus commented Dec 1, 2022

I have now verified that the interim compiler is indeed used (made it say bad words and fail at startup, so there is no doubt about it :)). As to the reason why this is so, here is the magic incantation from $(INTERIM_LANGTOOLS_ARGS):

    --limit-modules java.base,jdk.zipfs,$(INTERIM_LANGTOOLS_MODULES_COMMA) \
    --add-modules $(INTERIM_LANGTOOLS_MODULES_COMMA) \
    --module-path $(BUILDTOOLS_OUTPUTDIR)/interim_langtools_modules \
    --patch-module java.base=$(BUILDTOOLS_OUTPUTDIR)/gensrc/java.base.interim \
    --add-exports java.base/sun.reflect.annotation=jdk.compiler.interim \
    --add-exports java.base/jdk.internal.jmod=jdk.compiler.interim \
    --add-exports java.base/jdk.internal.misc=jdk.compiler.interim \
    --add-exports java.base/sun.invoke.util=jdk.compiler.interim \
    --add-exports java.base/jdk.internal.javac=java.compiler.interim \
    --add-exports java.base/jdk.internal.javac=jdk.compiler.interim \

I hope you are not asking me to explain in detail how or why this works. :-)

@openjdk-notifier openjdk-notifier bot changed the base branch from pr/11298 to master December 1, 2022 23:51
@openjdk-notifier
Copy link

The parent pull request that this pull request depends on has now been integrated and the target branch of this pull request has been updated. This means that changes from the dependent pull request can start to show up as belonging to this pull request, which may be confusing for reviewers. To remedy this situation, simply merge the latest changes from the new target branch into this pull request by running commands similar to these in the local repository for your personal fork:

git checkout use-toolprovider-in-javacserver
git fetch https://git.openjdk.org/jdk master
git merge FETCH_HEAD
# if there are conflicts, follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk
Copy link

openjdk bot commented Dec 1, 2022

@magicus this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout use-toolprovider-in-javacserver
git fetch https://git.openjdk.org/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Dec 1, 2022
@openjdk
Copy link

openjdk bot commented Dec 2, 2022

@magicus 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:

8297455: Use the official ToolProvider API to call javac

Reviewed-by: erikj

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 ready Pull request is ready to be integrated and removed merge-conflict Pull request has merge conflict with target branch labels Dec 2, 2022
@magicus
Copy link
Member Author

magicus commented Dec 2, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Dec 2, 2022

Going to push as commit b035056.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 2, 2022
@openjdk openjdk bot closed this Dec 2, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 2, 2022
@openjdk
Copy link

openjdk bot commented Dec 2, 2022

@magicus Pushed as commit b035056.

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

@magicus magicus deleted the use-toolprovider-in-javacserver branch December 2, 2022 00:12
@erikj79
Copy link
Member

erikj79 commented Dec 2, 2022

I have now verified that the interim compiler is indeed used (made it say bad words and fail at startup, so there is no doubt about it :)). As to the reason why this is so, here is the magic incantation from $(INTERIM_LANGTOOLS_ARGS):

    --limit-modules java.base,jdk.zipfs,$(INTERIM_LANGTOOLS_MODULES_COMMA) \
    --add-modules $(INTERIM_LANGTOOLS_MODULES_COMMA) \
    --module-path $(BUILDTOOLS_OUTPUTDIR)/interim_langtools_modules \
    --patch-module java.base=$(BUILDTOOLS_OUTPUTDIR)/gensrc/java.base.interim \
    --add-exports java.base/sun.reflect.annotation=jdk.compiler.interim \
    --add-exports java.base/jdk.internal.jmod=jdk.compiler.interim \
    --add-exports java.base/jdk.internal.misc=jdk.compiler.interim \
    --add-exports java.base/sun.invoke.util=jdk.compiler.interim \
    --add-exports java.base/jdk.internal.javac=java.compiler.interim \
    --add-exports java.base/jdk.internal.javac=jdk.compiler.interim \

I hope you are not asking me to explain in detail how or why this works. :-)

Thanks! Yeah, that rings a bell and I think I understand how it works, but I surely wouldn't be able to replicate this from memory.

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