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

4718400: Many quantities are held as signed that should be unsigned #6100

Closed

Conversation

stefank
Copy link
Member

@stefank stefank commented Oct 25, 2021

The GC code tends to use the size_t type to describe sizes of memory and objects, while the oopDesc class and *Klasses use int. The unit of the object size is in "words" (8 bytes on 64-bits, 4 bytes on 32-bits), and int variables can currently hold the largest object size in words. However, when/if we start to experiment with larger objects, using int could be limiting. I propose that we convert oopDesc::size to return size_t to describe the "objects size"-in-words quantities, and update calling code to also use size_t. Note that there will still be places in the JVM that expects the size to fit in 4 bytes. I've listed a couple of them below.

I'm reusing this old bug, which more or less covers what this patch does. It would probably be good to update the name of the bug if we decide this patch should be integrated, but I given the age of the RFE, I decided to open the PR with its current name. :)

Comments on the patch:

  • There are some JVMCI usages of 'long' (not jlong). It would be good to figure out why that is, and if that's something that should be cleaned out.
  • JFR stores field offsets in bytes in 4 bytes variables. This could be a bug. I added an assert.
  • java_lang_Class::set_oop_size/oop_size uses size_t but the stored field is only 4 bytes. Leaving this for future consideration.
  • I left array object size calculation as-is for now.

I've run this through tier1-3. I'll run more tiers after initial feedback on this proposal


Progress

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

Issue

  • JDK-4718400: Many quantities are held as signed that should be unsigned

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6100

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

Using diff file

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

@stefank
Copy link
Member Author

stefank commented Oct 25, 2021

/label hotspot

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 25, 2021

👋 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 rfr Pull request is ready for review hotspot hotspot-dev@openjdk.org labels Oct 25, 2021
@openjdk
Copy link

openjdk bot commented Oct 25, 2021

@stefank
The hotspot label was successfully added.

@mlbridge
Copy link

mlbridge bot commented Oct 25, 2021

Webrevs

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.

The runtime changes look great!

assert(size > 0, "Oop size must be greater than zero, not %d", size);
*(int*)(((char*)java_class) + _oop_size_offset) = size;
assert(size > 0, "Oop size must be greater than zero, not " SIZE_FORMAT, size);
assert(size <= INT_MAX, "Lossy conversion: " SIZE_FORMAT, size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, can you add a small comment here that the size in the java.lang.Class instance is only 4 bytes? It probably doesn't need to be but not something to change in this change.

@openjdk
Copy link

openjdk bot commented Oct 25, 2021

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

4718400: Many quantities are held as signed that should be unsigned

Reviewed-by: coleenp, rbackman, dholmes

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 the ready Pull request is ready to be integrated label Oct 25, 2021
Copy link

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

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 25, 2021
@dholmes-ora
Copy link
Member

/issue JDK-4718400

@openjdk
Copy link

openjdk bot commented Oct 26, 2021

@dholmes-ora Only the author (@stefank) is allowed to issue the /issue command.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 26, 2021
Copy link
Member

@dholmes-ora dholmes-ora 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! Thanks for taking this on.

David

@stefank
Copy link
Member Author

stefank commented Oct 27, 2021

/issue JDK-4718400

@openjdk
Copy link

openjdk bot commented Oct 27, 2021

@stefank This issue is referenced in the PR title - it will now be updated.

@stefank
Copy link
Member Author

stefank commented Oct 27, 2021

Thanks for reviewing!
I've also verified that this passes with tier4-7

@stefank
Copy link
Member Author

stefank commented Oct 27, 2021

/integrate

@openjdk
Copy link

openjdk bot commented Oct 27, 2021

Going to push as commit 93be099.
Since your change was applied there have been 3 commits pushed to the master branch:

  • 168081e: 8270490: Charset.forName() taking fallback default value
  • a292733: 8275975: Remove dead code in ciInstanceKlass
  • 4060602: 8275800: Redefinition leaks MethodData::_extra_data_lock

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 27, 2021

@stefank Pushed as commit 93be099.

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

@stefank stefank deleted the 4718400_use_size_t_for_object_sizes branch January 12, 2022 09:41
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
4 participants