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

8340824: C2: Memory for TypeInterfaces not reclaimed by hashcons() #21163

Closed
wants to merge 9 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Sep 24, 2024

The list of interfaces for a TypeInterfaces is contained in a GrowableArray that's allocated in the type arena. When hashcons() deletes a TypeInterfaces object because an identical one exists, it can't reclaim memory for the object because it can only free the last thing that was allocated and that's the backing store for the GrowableArray, not the TypeInterfaces object.

This patch changes the array of interfaces stored in TypeInterfaces into a pointer to a GrowableArray. TypeInterfaces::make calls hashcons with a temporary copy of the array of interfaces allocated in the current thread's resource area. This way if hascons deletes the TypeInterfaces, it is the last thing allocated in the type arena and memory can be reclaimed. Memory for the GrowableArray is freed as well on return from TypeInterfaces::make. If the newly allocated TypeInterfaces survives hashcons then a permanent array of interfaces is allocated in the type arena and linked from the TypeInterfaces object.

I ran into this issue while working on a fix for a separate issue that causes more Type objects to be created. With that prototype fix, TestScalarReplacementMaxLiveNodes uses 1.4GB of memory at peak. With the patch I propose here on top, memory usage goes down to 150-200 MB which is in line with the peak memory usage for TestScalarReplacementMaxLiveNodes when run with current master.

When I opened the PR initially, the fix I proposed was to let GrowableArray try to reclaim memory from an arena when destroyed. With that patch, some gtests failed when a GrowableArray is created by a copy constructor and the backing store for the array is shared. As a consequence, I reconsidered the fix and thought it was safer to go with a fix that only affects TypeInterfaces.


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-8340824: C2: Memory for TypeInterfaces not reclaimed by hashcons() (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 21163

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 24, 2024

👋 Welcome back roland! 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 Sep 24, 2024

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

8340824: C2: Memory for TypeInterfaces not reclaimed by hashcons()

Reviewed-by: vlivanov, qamai

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

  • 0f38113: 8341243: Use ArraySupport.SOFT_MAX_ARRAY_LENGTH for max array size in java.base
  • 8d6d37f: 8320308: C2 compilation crashes in LibraryCallKit::inline_unsafe_access
  • 83dcb02: 8340079: Modify rearrange/selectFrom Vector API methods to perform wrapIndexes instead of checkIndexes
  • d2e7708: 8341367: Problemlist ShapeNotSetSometimes.java on macOS
  • 0314973: 8341060: Cleanup statics in HeapDumper
  • 021bf63: 8340458: Open source additional Component tests (part 2)
  • 9a7817b: 8340988: Update jdk/jfr/event/gc/collection tests to accept "CodeCache GC Threshold" as valid GC reason
  • f2a767f: 8340907: Open source closed frame tests # 2
  • 7b1e6f8: 8337389: Parallel: Remove unnecessary forward declarations in psScavenge.hpp
  • 2120a84: 8341333: [JVMCI] Export JavaThread::_unlocked_inflated_monitor to JVMCI
  • ... and 4 more: https://git.openjdk.org/jdk/compare/ad5ffccffa89359dac6ad44b9e43242e5bf3e398...master

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 rfr Pull request is ready for review label Sep 24, 2024
@openjdk
Copy link

openjdk bot commented Sep 24, 2024

@rwestrel The following label will be automatically applied to this pull request:

  • hotspot

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

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Sep 24, 2024
@mlbridge
Copy link

mlbridge bot commented Sep 24, 2024

Webrevs

@rwestrel rwestrel marked this pull request as draft September 25, 2024 12:09
@rwestrel
Copy link
Contributor Author

Converted back to draft while I investigate gtest failures.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Sep 25, 2024
@rwestrel
Copy link
Contributor Author

/label remove hotspot
/label add hotspot-compiler

@openjdk openjdk bot removed the hotspot hotspot-dev@openjdk.org label Sep 27, 2024
@openjdk
Copy link

openjdk bot commented Sep 27, 2024

@rwestrel
The hotspot label was successfully removed.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Sep 27, 2024
@openjdk
Copy link

openjdk bot commented Sep 27, 2024

@rwestrel
The hotspot-compiler label was successfully added.

@rwestrel rwestrel marked this pull request as ready for review September 27, 2024 13:41
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 27, 2024
const TypeInterfaces* TypeInterfaces::make(GrowableArray<ciInstanceKlass*>* interfaces) {
TypeInterfaces* result = (interfaces == nullptr) ? new TypeInterfaces() : new TypeInterfaces(interfaces);
return (const TypeInterfaces*)result->hashcons();
const TypeInterfaces* TypeInterfaces::make(const GrowableArray<ciInstanceKlass*>* interfaces) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can make _interface a ciInstanceKlass** and do this:

void* ptr = Type::operator new(sizeof(TypeInterfaces) + sizeof(ciInstanceKlass*) * interfaces->length())

Then delete ptr should drop the whole thing.

Copy link
Member

Choose a reason for hiding this comment

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

A GrowableArrayFromArray would be mostly compatible with the interface of GrowableArray, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! nice. I wasn't aware of GrowableArrayFromArray. Updated change follows your suggestion.

Copy link
Contributor

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

It feels a bit weird to see GrowableArray used to represent a read-only data structure, but I understand that you still benefit from some helper methods it provides.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 1, 2024
@rwestrel
Copy link
Contributor Author

rwestrel commented Oct 2, 2024

@iwanowww @merykitty thanks for the reviews

@rwestrel
Copy link
Contributor Author

rwestrel commented Oct 2, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Oct 2, 2024

Going to push as commit 90c944f.
Since your change was applied there have been 15 commits pushed to the master branch:

  • 39c17b3: 8341277: Validate slot argument for instruction factories
  • 0f38113: 8341243: Use ArraySupport.SOFT_MAX_ARRAY_LENGTH for max array size in java.base
  • 8d6d37f: 8320308: C2 compilation crashes in LibraryCallKit::inline_unsafe_access
  • 83dcb02: 8340079: Modify rearrange/selectFrom Vector API methods to perform wrapIndexes instead of checkIndexes
  • d2e7708: 8341367: Problemlist ShapeNotSetSometimes.java on macOS
  • 0314973: 8341060: Cleanup statics in HeapDumper
  • 021bf63: 8340458: Open source additional Component tests (part 2)
  • 9a7817b: 8340988: Update jdk/jfr/event/gc/collection tests to accept "CodeCache GC Threshold" as valid GC reason
  • f2a767f: 8340907: Open source closed frame tests # 2
  • 7b1e6f8: 8337389: Parallel: Remove unnecessary forward declarations in psScavenge.hpp
  • ... and 5 more: https://git.openjdk.org/jdk/compare/ad5ffccffa89359dac6ad44b9e43242e5bf3e398...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 2, 2024

@rwestrel Pushed as commit 90c944f.

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

@rwestrel
Copy link
Contributor Author

rwestrel commented Nov 4, 2024

/backport jdk21u-dev

@openjdk
Copy link

openjdk bot commented Nov 4, 2024

@rwestrel the backport was successfully created on the branch backport-rwestrel-90c944fe-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 90c944fe from the openjdk/jdk repository.

The commit being backported was authored by Roland Westrelin on 2 Oct 2024 and was reviewed by Vladimir Ivanov and Quan Anh Mai.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-rwestrel-90c944fe-master:backport-rwestrel-90c944fe-master
$ git checkout backport-rwestrel-90c944fe-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-rwestrel-90c944fe-master

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

Successfully merging this pull request may close these issues.

3 participants