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

8331572: Allow using OopMapCache outside of STW GC phases #19229

Closed

Conversation

shipilev
Copy link
Member

@shipilev shipilev commented May 14, 2024

As the reproducer in the issue shows, we would also like to use the OopMapCache during the concurrent GC phases. Zhengyu mentions there is also a production problem for stack walking that would benefit from letting OopMapCache be used without looking at GC at all.

This PR unblocks OopMapCache uses for everything. Cleanups are nominally done by service thread. But, still appreciating that majority of use cases would be from GCs, we leave the proactive cleanups from the GC ops here as well. It requires the synchronization between readers that might be copying out the entries out of the hashmap and the concurrent reclamation. Handily, GlobalCounter can be used for that purpose.

After this lands, I think we can go over OopMapCache::compute_one_oop_map uses and see if they would instead like to use the cached lookup to benefit from this cache too. I think those paths are for OSR and deopts, so their performance is unlikely to be critical. This PR already covers the concurrent GC paths well.

Additional testing:

  • Performance test reproducer from the bug improves significantly
  • Linux AArch64 server fastdebug, hotspot_gc_shenandoah (10x)
  • Linux AArch64 server fastdebug, all
  • Linux x86_64 server fastdebug, all

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-8331572: Allow using OopMapCache outside of STW GC phases (Enhancement - P4)

Reviewers

Contributors

  • Zhengyu Gu <zgu@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19229

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

Using diff file

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

Webrev

Link to Webrev Comment

@shipilev
Copy link
Member Author

/contributor add @zhengyu123

@bridgekeeper
Copy link

bridgekeeper bot commented May 14, 2024

👋 Welcome back shade! 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 May 14, 2024

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

8331572: Allow using OopMapCache outside of STW GC phases

Co-authored-by: Zhengyu Gu <zgu@openjdk.org>
Reviewed-by: coleenp, zgu

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

  • 39a55e9: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint
  • b7ae0ae: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf99: 8332239: Improve CSS for block tags
  • 9bb6169: 8317621: --add-script should support JavaScript modules
  • 4eb1eaf: 8329617: Update stylesheet for specs and tool documentation
  • d4c2edf: 8331855: Convert jdk.jdeps jdeprscan and jdeps to use the Classfile API
  • beeffd4: 8332109: Convert remaining tests using com.sun.tools.classfile to ClassFile API
  • e0d1c4b: 8321428: Deprecate for removal the package java.beans.beancontext
  • 0b0445b: 8331724: Refactor j.l.constant implementation to internal package
  • ... and 50 more: https://git.openjdk.org/jdk/compare/ea5eb74a65f20ce28fa0a94ea851915d4a6f83da...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 May 14, 2024

@shipilev
Contributor Zhengyu Gu <zgu@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented May 14, 2024

@shipilev The following labels will be automatically applied to this pull request:

  • hotspot
  • shenandoah

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 hotspot hotspot-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels May 14, 2024
@shipilev shipilev force-pushed the JDK-8331572-oopmap-cache-concgc branch from eac6783 to 62eda44 Compare May 14, 2024 12:42
@shipilev
Copy link
Member Author

shipilev commented May 14, 2024

Performance note: there is an intrinsic tradeoff here between the cost of acquiring the critical section vs the concurrency it unblocks for non-STW GCs and the cache improvements on non-GC paths. The critical section overhead is mostly due to the fence in

Atomic::release_store_fence(thread->get_rcu_counter(), new_cnt);

So, the original reproducer (very stressy, with lots of interpreter frames) improves dramatically (73 -> 6ms) with Shenandoah GC, but run with Serial GC reveals there is a slight regression in GC times (74 -> 79 ms). I have not been able to replicate this regression in larger benchmarks.

Anyhow, this very fine-grained regression nearly disappears (74.1 -> 74.3 ms on Serial) if we optimize the other part of this whole path a bit, done as part of this PR: 455687a. This also improves Shenandoah times further (6.1 -> 5.6 ms).

@shipilev shipilev marked this pull request as ready for review May 14, 2024 18:20
@openjdk openjdk bot added the rfr Pull request is ready for review label May 14, 2024
@mlbridge
Copy link

mlbridge bot commented May 14, 2024

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.

This looks good but one question for ZGC, does ZGC need an OopMapCache::cleanup_old_entries() ?

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

I did have questions (sorry hit approve too soon).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 15, 2024
@zhengyu123
Copy link
Contributor

This looks good but one question for ZGC, does ZGC need an OopMapCache::cleanup_old_entries() ?

We still call OopMapCache::cleanup_old_entries() after STW pause, but now concurrent phase also can accumulate old entries, should we unify them? e.g. all depend on service thread to clean up old entries?

@shipilev
Copy link
Member Author

This looks good but one question for ZGC, does ZGC need an OopMapCache::cleanup_old_entries() ?

We still call OopMapCache::cleanup_old_entries() after STW pause, but now concurrent phase also can accumulate old entries, should we unify them? e.g. all depend on service thread to clean up old entries?

Yes. I think the post-GC cleanup is opportunistic after this patch: it is not necessary, since service thread is supposed to catch up with cleanups, but we might still do it after the phases that we know might generate lots of old entries. This is why I left current calls to cleanup_old_entries() in current paths, and we might consider adding those for ZGC paths as well. I don't see a strong pressure to do it here, though.

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.

This looks good.

src/hotspot/share/interpreter/oopMapCache.cpp Show resolved Hide resolved
src/hotspot/share/interpreter/oopMapCache.cpp Outdated Show resolved Hide resolved
@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 16, 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.

This looks safe. You still get some trigger for cleanup, plus the ServiceThread timeout. The timer comment is vague enough to cover this case also.

@zhengyu123
Copy link
Contributor

I would suggest to move OopMapCache::trigger_cleanup(); from VM_ShenandoahReferenceOperation::doit_epilogue() to VM_ShenandoahOperation::doit_prologue() and add the call to VM_ZOperation and VM_XOperation's doit_epilogue()

@shipilev
Copy link
Member Author

I would suggest to move OopMapCache::trigger_cleanup(); from VM_ShenandoahReferenceOperation::doit_epilogue() to VM_ShenandoahOperation::doit_prologue() and add the call to VM_ZOperation and VM_XOperation's doit_epilogue()

Right. Surely, it would be better to move it to VM_ShenandoahOperation::doit_epilogue() as well? This way we don't risk Service thread waking up during the short GC pause.

Copy link
Contributor

@zhengyu123 zhengyu123 left a comment

Choose a reason for hiding this comment

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

LGTM

@shipilev
Copy link
Member Author

Thanks for reviews! @stefank, I assume you are fine with the way we (lightly) touched ZGC code?

@stefank
Copy link
Member

stefank commented May 21, 2024

Yes, ZGC code looks fine. Thanks!

@shipilev
Copy link
Member Author

All right, thank you all. Test re-run passes, so I am integrating.

/integrate

@openjdk
Copy link

openjdk bot commented May 21, 2024

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

  • 8291c94: 8331224: ClassCastException in ObjectInputStream hides ClassNotFoundException
  • 42e3c84: 8332086: Remove the usage of ServiceLoader in j.u.r.RandomGeneratorFactory
  • 5cf8288: 8332153: RISC-V: enable tests and add comment for vector shift instruct (shared by vectorization and Vector API)
  • ae9ad86: 8331934: [s390x] Add support for primitive array C1 clone intrinsic
  • 3479b46: 8332595: Serial: Remove unused TenuredGeneration::should_collect
  • 9bfae88: 8332297: annotation processor that generates records sometimes fails due to NPE in javac
  • 4e169d1: 8332401: G1: TestFromCardCacheIndex.java with -XX:GCCardSizeInBytes=128 triggers underflow assertion
  • 7ffc999: 8332498: [aarch64, x86] improving OpToAssembly output for partialSubtypeCheckConstSuper Instruct
  • e529101: 8332473: ubsan: growableArray.hpp:290:10: runtime error: null pointer passed as argument 1, which is declared to never be null
  • 414a7fd: 8311175: Move BufWriter::asByteBuffer to BufWriterImpl
  • ... and 74 more: https://git.openjdk.org/jdk/compare/ea5eb74a65f20ce28fa0a94ea851915d4a6f83da...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 21, 2024

@shipilev Pushed as commit d999b81.

💡 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 shenandoah shenandoah-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

4 participants