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

8252685: APIs that require JavaThread should take JavaThread arguments #3877

Closed
wants to merge 6 commits into from

Conversation

dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented May 5, 2021

Our code is littered with API's that take, or manifest, a Thread* and then assert/guarantee that it must be a JavaThread, rather than taking/manifesting a JavaThread in the first place. The main reason for this is that the TRAPS macro, used in relation to exception generation and processing, is declared as "Thread* THREAD". In practice only JavaThreads that can execute Java code can generate arbitrary exceptions, because it requires executing Java code. In other places we can get away with other kinds of threads "throwing" exceptions because they are only pre-allocated instances that require no Java code execution (e.g. OOME), or when executed by a non-JavaThread the code actually by-passes the logic would throw an exception. Such code also eventually clears the exception and reports the OOM by some other means. We have been progressively untangling these code paths and modifying TRAPS/CHECK usage so that only JavaThreads will call TRAPS methods and throw exceptions. Having done that pre-work we are now ready to convert TRAPS to be "JavaThread* THREAD" and that is what this change does. The resulting changes are largely mechanical:

  • declarations of "Thread* THREAD" become "JavaThread* THREAD" (where THREAD is needed for exceptions, otherwise THREAD is renamed to current)
  • methods that took a Thread* parameter that was always THREAD, now take a JavaThread* param
  • Manifestations of Thread::current() become JavaThread::current()
  • THREAD->as_Java_thread() becomes just THREAD
  • THREAD->is_Java_thread() is reworked so that THREAD is "current"

There are still places where a CompilerThread (which is a JavaThread but may not be able to execute Java code) calls a TRAPS function (primarily where OOME is possible). Fixing that would be a future RFE and may not be possible without reworking a lot of the allocation code paths.

Testing:

  • tiers 1-8 on Linux-x64
  • all builds in tiers 1-4
  • tiers 1-3 on all platforms

Thanks,
David


Progress

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

Issue

  • JDK-8252685: APIs that require JavaThread should take JavaThread arguments

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3877

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented May 5, 2021

👋 Welcome back dholmes! 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
Copy link

openjdk bot commented May 5, 2021

@dholmes-ora The following labels will be automatically applied to this pull request:

  • hotspot
  • serviceability

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 serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels May 5, 2021
coleenp
coleenp approved these changes May 8, 2021
Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

I started out thinking that this was too big and should be broken up but then the change is pretty simple to review and mostly mechanical. So ignore my comments to break it up. I think it's fine. Hitting "approve" even though it's a draft.

src/hotspot/share/cds/archiveBuilder.cpp Show resolved Hide resolved
src/hotspot/share/cds/dynamicArchive.cpp Outdated Show resolved Hide resolved
@@ -1074,7 +1074,7 @@ ClassPathEntry* find_first_module_cpe(ModuleEntry* mod_entry,


// Search either the patch-module or exploded build entries for class.
ClassFileStream* ClassLoader::search_module_entries(Thread* current,
ClassFileStream* ClassLoader::search_module_entries(JavaThread* current,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if these CDS and classLoader.hpp/cpp changes can be done first? Just change the caller to pass ->as_Java_thread() until TRAPS is changed.

src/hotspot/share/runtime/sharedRuntime.cpp Show resolved Hide resolved
@openjdk
Copy link

openjdk bot commented May 8, 2021

@dholmes-ora 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 8252685
git fetch https://git.openjdk.java.net/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 May 8, 2021
@dholmes-ora
Copy link
Member Author

Thanks for the pre-review comments Coleen! I started responding to your various comments then realized they were the ones about breaking things up that you said I could now ignore :)

@dholmes-ora dholmes-ora marked this pull request as ready for review May 9, 2021 22:45
@openjdk
Copy link

openjdk bot commented May 9, 2021

@dholmes-ora 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:

8252685: APIs that require JavaThread should take JavaThread arguments

Reviewed-by: coleenp, sspitsyn, kvn, iklam

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 rfr Pull request is ready for review and removed merge-conflict Pull request has merge conflict with target branch labels May 9, 2021
@mlbridge
Copy link

mlbridge bot commented May 9, 2021

Webrevs

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

David,
This looks pretty good. At least, I do not see real problems.
It is really nice to make it more consistent.
Thanks,
Serguei

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Compiler related changes seems fine.
@dougxc, note that jvmci is affected. It looks reasonable for me but you may need to check if it is correct from libgraal POV.

@dougxc
Copy link
Member

dougxc commented May 13, 2021

Compiler related changes seems fine.
@dougxc, note that jvmci is affected. It looks reasonable for me but you may need to check if it is correct from libgraal POV.

I tried to test this patch against GraalVM but am blocked due to jdk.internal.vm.compiler no longer being upgradeable.

iklam
iklam approved these changes May 13, 2021
Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

LGTM

@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

On 11/05/2021 9:14 am, Serguei Spitsyn wrote:

On Wed, 5 May 2021 10:16:29 GMT, David Holmes <dholmes at openjdk.org> wrote:

David,
This looks pretty good. At least, I do not see real problems.
It is really nice to make it more consistent.
Thanks,
Serguei

Thanks for the review Serguei!

David

1 similar comment
@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

On 11/05/2021 9:14 am, Serguei Spitsyn wrote:

On Wed, 5 May 2021 10:16:29 GMT, David Holmes <dholmes at openjdk.org> wrote:

David,
This looks pretty good. At least, I do not see real problems.
It is really nice to make it more consistent.
Thanks,
Serguei

Thanks for the review Serguei!

David

@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

On 11/05/2021 9:00 am, Serguei Spitsyn wrote:

On Wed, 5 May 2021 10:16:29 GMT, David Holmes <dholmes at openjdk.org> wrote:

src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp line 108:

106:
107: // caller needs ResourceMark
108: const char* get_java_thread_name(const JavaThread* t) {

Nit: Better to rename it: t => jt

Changed.

1 similar comment
@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

On 11/05/2021 9:00 am, Serguei Spitsyn wrote:

On Wed, 5 May 2021 10:16:29 GMT, David Holmes <dholmes at openjdk.org> wrote:

src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp line 108:

106:
107: // caller needs ResourceMark
108: const char* get_java_thread_name(const JavaThread* t) {

Nit: Better to rename it: t => jt

Changed.

@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

On 13/05/2021 1:29 pm, Vladimir Kozlov wrote:

On Tue, 11 May 2021 01:56:21 GMT, David Holmes <dholmes at openjdk.org> wrote:

David Holmes has updated the pull request incrementally with one additional commit since the last revision:

Review feedback from Serguei

Compiler related changes seems fine.
@dougxc, note that jvmci is affected. It looks reasonable for me but you may need to check if it is correct from libgraal POV.

Thanks for the review Vladimir!

cc'ing Doug in case the @-notification doesn't work.

David

1 similar comment
@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

On 13/05/2021 1:29 pm, Vladimir Kozlov wrote:

On Tue, 11 May 2021 01:56:21 GMT, David Holmes <dholmes at openjdk.org> wrote:

David Holmes has updated the pull request incrementally with one additional commit since the last revision:

Review feedback from Serguei

Compiler related changes seems fine.
@dougxc, note that jvmci is affected. It looks reasonable for me but you may need to check if it is correct from libgraal POV.

Thanks for the review Vladimir!

cc'ing Doug in case the @-notification doesn't work.

David

@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

Thanks for the review Ioi!

David

On 14/05/2021 3:03 am, Ioi Lam wrote:

1 similar comment
@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from David Holmes on hotspot-dev:

Thanks for the review Ioi!

David

On 14/05/2021 3:03 am, Ioi Lam wrote:

@dholmes-ora
Copy link
Member Author

/integrate

@openjdk openjdk bot closed this May 17, 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 17, 2021
@openjdk
Copy link

openjdk bot commented May 17, 2021

@dholmes-ora Pushed as commit 02f895c.

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

@dholmes-ora dholmes-ora deleted the 8252685 branch May 17, 2021 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
6 participants