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

8293304: Replace some usages of INTPTR_FORMAT with PTR_FORMAT #10141

Closed
wants to merge 8 commits into from

Conversation

stefank
Copy link
Member

@stefank stefank commented Sep 2, 2022

During the discussion of JDK-8292981 an opinion was voiced that we should stop using INTPTR_FORMAT when printing pointers.

Some background that could explain why some tend to use INTPTR_FORMAT instead of PTR_FORMAT:

Both those format specifiers require an integer and the compiler barfs if you send in a pointer. We therefore have a utility function named p2i, which converts the pointer to an integer. So, everywhere we have to write print line like this: print("my pointer: " PTR_FORMAT, p2i(my_pointer));. Now, p2i returns an intptr_t, and it becomes natural for some to consider the type of the converted value (that we need because of the mentioned workaround), instead of the original type of the value.

With this enhancement I'd like to clean up the code that I often work in, so that it uses PTR_FORMAT when printing pointers. I'm leaving the rest of the code base for others to consider cleaning up.

Cleanups have been done in directories gc/, utilities/, memory/, and oops/.


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-8293304: Replace some usages of INTPTR_FORMAT with PTR_FORMAT

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10141

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 2, 2022

👋 Welcome back stefank! 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 Sep 2, 2022
@openjdk
Copy link

openjdk bot commented Sep 2, 2022

@stefank 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 Sep 2, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 2, 2022

Webrevs

@stefank
Copy link
Member Author

stefank commented Sep 7, 2022

@kimbarrett You commented on the "incorrect" usages of INTPTR_FORMAT in JDK-8292981. Do you think this PR moves the code in the right direction?

Copy link

@kimbarrett kimbarrett 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.

I did notice a couple INTPTR_FORMAT => (new) SIZE_FORMAT_X_0. Good change.

I also noticed a place where there are sequential asserts, one (previously)
using INTPTR_FORMAT and the next PTR_FORMAT, for the same value. Seems like
somebody wasn't paying attention. Again good change.

Also noticed some pre-existing unnecessary (void*) casts of the pointer
argument to p2i. Not your problem, and not really appropriate for this change
to do anything about them, but I really hate eye-catching cast junk like that.

There were also a few INTPTR_FORMAT uses that were left in place. All that I
recall looked like they could/should instead be SIZE_FORMAT_X_0 or maybe even
SIZE_FORMAT_X if the zero padding isn't useful. Leaving those for a later pass
seems fine. I wonder how many INTPTR_FORMATs are left in the areas you worked
on?

@openjdk
Copy link

openjdk bot commented Sep 7, 2022

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

8293304: Replace some usages of INTPTR_FORMAT with PTR_FORMAT

Reviewed-by: kbarrett, coleenp

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 2 new commits pushed to the master branch:

  • 98da03a: 8293432: Use diamond operator in java.management
  • ffc249a: 8289613: Drop use of Thread.stop in jshell

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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 Sep 7, 2022
@stefank
Copy link
Member Author

stefank commented Sep 8, 2022

Looks good.

Thanks.

Also noticed some pre-existing unnecessary (void*) casts of the pointer argument to p2i. Not your problem, and not really appropriate for this change to do anything about them, but I really hate eye-catching cast junk like that.

I agree. I cleaned out some of that. There's a lot of casts from oop to void* that are unnecessary after we rewrote the fastdebug oop class and/or p2i.

There were also a few INTPTR_FORMAT uses that were left in place. All that I recall looked like they could/should instead be SIZE_FORMAT_X_0 or maybe even SIZE_FORMAT_X if the zero padding isn't useful. Leaving those for a later pass seems fine. I wonder how many INTPTR_FORMATs are left in the areas you worked on?

I saw a lot of intptr_t/uintptr_t being printed with INTPRT_FORMAT, I don't think those should be changed to use SIZE_FORMAT_.

I found and converted three more lingering INTPTR_FORMAT usages. We are now down to a little bit less then 30 usages of INTPTR_FORMAT in the directories relevant to this PR. Most in:
g1HeapRegionAttr.hpp to print an index
elfFile.hpp to print a integer typed address
markWord.cpp to print the mark word
stackChunk/instanceStackChunk files to print relative stack pointers

@stefank
Copy link
Member Author

stefank commented Sep 8, 2022

Thanks for reviewing!
/integrate

@openjdk
Copy link

openjdk bot commented Sep 8, 2022

Going to push as commit 6bd2794.
Since your change was applied there have been 2 commits pushed to the master branch:

  • 98da03a: 8293432: Use diamond operator in java.management
  • ffc249a: 8289613: Drop use of Thread.stop in jshell

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 8, 2022

@stefank Pushed as commit 6bd2794.

💡 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
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
3 participants