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

8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray #11086

Closed

Conversation

stefank
Copy link
Member

@stefank stefank commented Nov 10, 2022

Today we use mtNone to denote that a GrowableArray should NOT be backed by a CHeap allocated array.

I've gotten feedback that it would probably be good to limit the usage of mtNone, and at some point maybe completely remove it.

This patch takes a small step to remove mtNone from the GrowableArray. What's left is only asserts to forbid that value. Those asserts will be trivial to remove when/if mtNone is removed.

Just like in the proposed patch to make MEMFLAGS non-optional in CHeapBitMap (see JDK-JDK-8296774), I have thrown around the parameter order for GrowableArray. When looking at the changes to the usages of CHeap-backed GrowableArrays it becomes apparent that all of these usages where forced to provide a value for the initial capacity. When MEMFLAGS move to the front, we can now skip having to figure an initial capacity.


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-8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11086

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 10, 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.

@stefank stefank marked this pull request as draft November 10, 2022 09:42
@openjdk
Copy link

openjdk bot commented Nov 10, 2022

@stefank 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 8296776_growablearray_mtnone_cleanout
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 merge-conflict Pull request has merge conflict with target branch rfr Pull request is ready for review labels Nov 10, 2022
@openjdk
Copy link

openjdk bot commented Nov 10, 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 and removed rfr Pull request is ready for review labels Nov 10, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 10, 2022

@stefank stefank force-pushed the 8296776_growablearray_mtnone_cleanout branch from ba3508f to 9e39835 Compare November 10, 2022 10:09
@stefank stefank marked this pull request as ready for review November 10, 2022 10:09
@stefank
Copy link
Member Author

stefank commented Nov 10, 2022

/label remove serviceability

@openjdk openjdk bot removed merge-conflict Pull request has merge conflict with target branch serviceability serviceability-dev@openjdk.org labels Nov 10, 2022
@openjdk
Copy link

openjdk bot commented Nov 10, 2022

@stefank
The serviceability label was successfully removed.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 10, 2022
@sspitsyn
Copy link
Contributor

All the serviceability files look okay to me.
Thanks,
Serguei

@openjdk
Copy link

openjdk bot commented Nov 10, 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:

8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray

Reviewed-by: sspitsyn, xliu, stuefe

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

  • d0fae43: 8294947: Use 64bit atomics in patch_verified_entry on x86_64
  • 6f467cd: 8295934: IGV: keep node selection when changing view or graph
  • 9adb728: 8295070: Introduce more target combinations for compiler flags
  • 8ab70d3: 8294775: Shenandoah: reduce contention on _threads_in_evac

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 Nov 10, 2022
Copy link
Member

@navyxliu navyxliu left a comment

Choose a reason for hiding this comment

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

It looks like no one is using mtNone for GrowableArray, but memReporter.cpp and virtualMemoryTracker still accept it. Shall we eliminate mtNone completely?

init_checks();
}

GrowableArray(MEMFLAGS memflags, int initial_capacity = 2) :
Copy link
Member

Choose a reason for hiding this comment

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

I feel it's too dangerous to have two constructors with convertible parameters.
eg. GrowableArray(int initial_capacity) and GrowableArray(MEMFLAGS memflags, int initial_capacity = 2) are very close. what if someone has code like this:

short t = 2;
GrowableArray(2); // it's very vague to me which ctor will be selected.

I think it's a good idea to use 'explicit constructor' for one of them. in case implicit conversation takes place unconsciously.

Copy link
Member Author

@stefank stefank Nov 11, 2022

Choose a reason for hiding this comment

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

MEMFLAGS is defined as a class enum, so integers will not be automatically converted to MEMFLAGS. I'll add explicit to the constructors.

@openjdk-notifier
Copy link

@stefank Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information.

@stefank
Copy link
Member Author

stefank commented Nov 11, 2022

It looks like no one is using mtNone for GrowableArray, but memReporter.cpp and virtualMemoryTracker still accept it. Shall we eliminate mtNone completely?

Eliminating mtNone completely is out of scope for this PR.

Copy link
Member

@navyxliu navyxliu left a comment

Choose a reason for hiding this comment

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

LGTM. I am not a reviewer.

@stefank
Copy link
Member Author

stefank commented Nov 11, 2022

Thanks for reviewing!

@dholmes-ora
Copy link
Member

When looking at the changes to the usages of CHeap-backed GrowableArrays it becomes apparent that all of these usages where forced to provide a value for the initial capacity. When MEMFLAGS move to the front, we can now skip having to figure an initial capacity.

The default initial capacity is 2, the explicit initial capacities are not 2 and in many case >>>2. So without an explicit capacity passed in these GrowableArrays would likely waste a lot of time unnecessarily growing. I don't think either of these parameters should really have a default value - in which case the order could have remained as it was.

@stefank
Copy link
Member Author

stefank commented Nov 14, 2022

When looking at the changes to the usages of CHeap-backed GrowableArrays it becomes apparent that all of these usages where forced to provide a value for the initial capacity. When MEMFLAGS move to the front, we can now skip having to figure an initial capacity.

The default initial capacity is 2, the explicit initial capacities are not 2 and in many case >>>2. So without an explicit capacity passed in these GrowableArrays would likely waste a lot of time unnecessarily growing. I don't think either of these parameters should really have a default value - in which case the order could have remained as it was.

Sure, that's an alternative. Before committing to doing that, could you take a look at the similar change to CHeap allocated BitMaps #11084? I want the two classes to be similar in where we put the "allocation strategy". With both these changes I've pushed them to the beginning of the parameter list. With your suggestion I either have to make GrowableArray and CHeapBitMap inconsistent, or I need to change CHeapBitMap to also have the MEMFLAGS at the end, which would force all users to set the clear parameter. I'm fine with either approach, but I'd like to get feedback on that before moving ahead with this PR.

@stefank
Copy link
Member Author

stefank commented Nov 15, 2022

I'm going to go with @dholmes-ora suggestion here, and do a similar change to the CHeapBitMap PR.

Copy link
Member

@tstuefe tstuefe 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. I like this version better. Thanks for doing this.

Small nits remain, nothing big.

src/hotspot/share/utilities/growableArray.hpp Outdated Show resolved Hide resolved
src/hotspot/share/utilities/growableArray.hpp Show resolved Hide resolved
src/hotspot/share/utilities/growableArray.hpp Show resolved Hide resolved
Copy link
Member Author

@stefank stefank left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this, Thomas.

I'm fixing most of your suggestions but left bits() alone, since I like it.

src/hotspot/share/utilities/growableArray.hpp Outdated Show resolved Hide resolved
src/hotspot/share/utilities/growableArray.hpp Show resolved Hide resolved
@tstuefe
Copy link
Member

tstuefe commented Nov 15, 2022

All good Stefan! I already approved.

Cheers, Thomas

@openjdk openjdk bot mentioned this pull request Nov 15, 2022
3 tasks
@stefank
Copy link
Member Author

stefank commented Nov 16, 2022

Thanks for the reviews!

@stefank
Copy link
Member Author

stefank commented Nov 16, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Nov 16, 2022

Going to push as commit 5f51dff.
Since your change was applied there have been 24 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 16, 2022

@stefank Pushed as commit 5f51dff.

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

@dholmes-ora
Copy link
Member

Sorry @stefank this one slipped through the cracks. This simplified version looks better to me. Sorry for not responding to your query sooner.

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
5 participants