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

8335409: Can't allocate and retain memory from resource area in frame::oops_interpreted_do oop closure after 8329665 #20012

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pchilano
Copy link
Contributor

@pchilano pchilano commented Jul 3, 2024

The ResourceMark added in 8329665 to address the case of having to allocate extra memory for the _bit_mask, prevents code in the closure from allocating and retaining memory from the resource area across the closure, relying on some ResourceMark in scope further up the stack from frame::oops_interpreted_do(). There is in fact one case today in JFR code where this kind of allocation happens.

The amount of locals and expression stack entries a method can have before having to allocate extra memory for the _bit_mask is 4*64/2 = 128. This is already big enough that we almost never have to allocate. A test run through mach5 tiers1-6 shows only a handful of methods that fall into this case, and most are artificial ones created to trigger this condition. So moving the allocation to the C heap shouldn't have any performance penalty as the comment otherwise says. This comment dates back from 2002 where instead of 128 entries we could have only 32, considering 32 bits cpus as still in main use (see bug for more history details).

The current code in InterpreterOopMap::resource_copy() has a comment expecting the InterpreterOopMap object to be recently created and empty, but it also has an assert in the allocation case path where it considers the entry might be in use already. This assert actually looks wrong since a used InterpreterOopMap object will not necessarily contain a pointer to resource area memory in _bit_mask[0]. I added an example case in the bug details. In any case, since we don't have any such cases in the codebase I added an explicit assert to verify each InterpreterOopMap is only used one.

I tested the patch by running it through mach5 tiers 1-6.

Thanks,
Patricio


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-8335409: Can't allocate and retain memory from resource area in frame::oops_interpreted_do oop closure after 8329665 (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20012

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 3, 2024

👋 Welcome back pchilanomate! 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 Jul 3, 2024

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

8335409: Can't allocate and retain memory from resource area in frame::oops_interpreted_do oop closure after 8329665

Reviewed-by: coleenp, 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 45 new commits pushed to the master branch:

  • ff49f67: 8335775: Remove extraneous 's' in comment of rawmonitor.cpp test file
  • 194425d: 8335645: j.u.Formatter#trailingZeros improved with String repeat
  • c8acea8: 8335706: G1: Remove unused G1ConcurrentRefine::RemSetSamplingClosure::_cset
  • bdf470b: 8335742: Problemlist gc/g1/TestMixedGCLiveThreshold.java#25percent with virtual threads
  • 6409ec3: 8335711: G1: Remove unused bot_updates argument in G1AllocRegion constructor
  • 4ec1ae1: 8331385: G1: Prefix HeapRegion helper classes with G1
  • b9d8056: 8332124: Jcmd should recognise options that look like requests for help
  • cff9e24: 8335493: check_gc_overhead_limit should reset SoftRefPolicy::_should_clear_all_soft_refs
  • f4fa35e: 8330954: since-checker - Fix remaining @ since tags in java.base
  • 3050ba0: 8335654: Remove stale hyperlink in divnode.cpp
  • ... and 35 more: https://git.openjdk.org/jdk/compare/fac74b118f5fda4ec297e46238d34ce5b9be1e21...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
Copy link

openjdk bot commented Jul 3, 2024

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

@pchilano pchilano marked this pull request as ready for review July 3, 2024 16:39
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 3, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 3, 2024

Webrevs

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.

Thanks for the detailed explanations. A couple of minor (pre-existing) nits but changes are good.

Thanks

"Should not resource allocate the _bit_mask");
assert(from->has_valid_mask(),
"Cannot copy entry with an invalid mask");
// The expectation is that this InterpreterOopMap is a recently created
Copy link
Member

Choose a reason for hiding this comment

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

s/is a recently/is recently/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 177 to 179
#ifdef ASSERT
_resource_allocate_bit_mask = true;
_used = false;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Nit pre-existing: use of DEBUG_ONLY would be more consistent with later setting of _used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -128,11 +129,12 @@ class InterpreterOopMap: ResourceObj {

public:
InterpreterOopMap();
~InterpreterOopMap();

// Copy the OopMapCacheEntry in parameter "from" into this
// InterpreterOopMap. If the _bit_mask[0] in "from" points to
// allocated space (i.e., the bit mask was to large to hold
Copy link
Member

Choose a reason for hiding this comment

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

Nit pre-existing: s/to/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.

Fixed.

Comment on lines 135 to 138
// in-line), allocate the space from a Resource area.
// in-line), allocate the space from the C heap.
void resource_copy(OopMapCacheEntry* from);
Copy link
Member

Choose a reason for hiding this comment

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

The name resource_copy seems somewhat of a misnomer given it may be C heap. Is it worth changing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, this should probably be copy_from, and rename the parameter src. Or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also thought about renaming it but ended up leaving it as is in v1. I changed it to Coleen's suggestion.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 4, 2024
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.

Also a couple of nits, but this looks good. Thanks for tracking down the history and verifying that its an unusual situation that we were optimizing for.

// a resource area for better performance. InterpreterOopMap
// For InterpreterOopMap the bit_mask is allocated in the C heap
// to avoid issues with allocations from the resource area that have
// to live accross the oop closure (see 8335409). InterpreterOopMap
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't usually put bug numbers in the code and after this change nobody will want to move this back to resource area, so putting the bug number as a caution shouldn't be needed. If one wants to know the details, they can git blame this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

// a resource area for better performance. InterpreterOopMap
// For InterpreterOopMap the bit_mask is allocated in the C heap
// to avoid issues with allocations from the resource area that have
// to live accross the oop closure (see 8335409). InterpreterOopMap
// should only be created and deleted during same garbage collection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add 'the' to "during the same garbage collection."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 135 to 138
// in-line), allocate the space from a Resource area.
// in-line), allocate the space from the C heap.
void resource_copy(OopMapCacheEntry* from);
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, this should probably be copy_from, and rename the parameter src. Or something like that.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 5, 2024
@@ -89,7 +90,7 @@ class InterpreterOopMap: ResourceObj {

protected:
#ifdef ASSERT
bool _resource_allocate_bit_mask;
bool _used;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this a DEBUG_ONLY() 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.

Fixed.

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.

One tiny nit.

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.

Perfect, thanks!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review
3 participants