jdk icon indicating copy to clipboard operation
jdk copied to clipboard

8331572: Allow using OopMapCache outside of STW GC phases

Open shipilev opened this issue 9 months ago • 11 comments

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:

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

Progress

  • [x] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • [x] Change must not contain extraneous whitespace
  • [x] Commit message must refer to an issue

Issue

  • JDK-8331572: Allow using OopMapCache outside of STW GC phases (Enhancement - P4)

Reviewers

Contributors

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 avatar May 14 '24 12:05 shipilev

/contributor add @zhengyu123

shipilev avatar May 14 '24 12:05 shipilev

:wave: 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.

bridgekeeper[bot] avatar May 14 '24 12:05 bridgekeeper[bot]

@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 <[email protected]>
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:

  • 39a55e97799b5328da85aaa66c8d23175b305691: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint
  • b7ae0ae1d7481e66a07f40bf01c5614fdf44c2ed: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151796d71c40a9395cb6fbe734f36d4c1b55: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf9964eb2dd0eb4034576e1f903a27c410286: 8332239: Improve CSS for block tags
  • 9bb6169a1cba900fa79d63119696efe265762083: 8317621: --add-script should support JavaScript modules
  • 4eb1eaf04477b9a8947a57655cf36380b5b88b5c: 8329617: Update stylesheet for specs and tool documentation
  • d4c2edf2c91a790874c80f1a7bea5bfd4f438bde: 8331855: Convert jdk.jdeps jdeprscan and jdeps to use the Classfile API
  • beeffd4671649e5d8f9c96f0455ac90a82917234: 8332109: Convert remaining tests using com.sun.tools.classfile to ClassFile API
  • e0d1c4b38c7ad2dc67f3d14b0b179b313c85fc0a: 8321428: Deprecate for removal the package java.beans.beancontext
  • 0b0445be2833286b4eace698b91a658de3e7608b: 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[bot] avatar May 14 '24 12:05 openjdk[bot]

@shipilev Contributor Zhengyu Gu <[email protected]> successfully added.

openjdk[bot] avatar May 14 '24 12:05 openjdk[bot]

@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[bot] avatar May 14 '24 12:05 openjdk[bot]

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 https://github.com/openjdk/jdk/blob/5a4415a6bddb25cbd5b87ff8ad1a06179c2e452e/src/hotspot/share/utilities/globalCounter.inline.hpp#L43

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: https://github.com/openjdk/jdk/pull/19229/commits/455687addeba55dc998dbf9ab4b8ec58f0b69ee4. This also improves Shenandoah times further (6.1 -> 5.6 ms).

shipilev avatar May 14 '24 14:05 shipilev

Webrevs

mlbridge[bot] avatar May 14 '24 18:05 mlbridge[bot]

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?

zhengyu123 avatar May 15 '24 22:05 zhengyu123

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.

shipilev avatar May 16 '24 07:05 shipilev

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()

zhengyu123 avatar May 17 '24 15:05 zhengyu123

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.

shipilev avatar May 17 '24 15:05 shipilev

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

shipilev avatar May 21 '24 07:05 shipilev

Yes, ZGC code looks fine. Thanks!

stefank avatar May 21 '24 08:05 stefank

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

/integrate

shipilev avatar May 21 '24 14:05 shipilev

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

  • 8291c94bcdbb01beddc94f290f2749841404cc0c: 8331224: ClassCastException in ObjectInputStream hides ClassNotFoundException
  • 42e3c842ae2684265c794868fc76eb0ff2dea3d9: 8332086: Remove the usage of ServiceLoader in j.u.r.RandomGeneratorFactory
  • 5cf8288b8071bdcf0c923dd7ba36f91bc7594ef3: 8332153: RISC-V: enable tests and add comment for vector shift instruct (shared by vectorization and Vector API)
  • ae9ad862ee54e119553efec919f1061dca36b954: 8331934: [s390x] Add support for primitive array C1 clone intrinsic
  • 3479b46c5bea3afd92b6ab4acd2fe7f274df38aa: 8332595: Serial: Remove unused TenuredGeneration::should_collect
  • 9bfae8891e6efa58c557bd6dac61de111a16f71e: 8332297: annotation processor that generates records sometimes fails due to NPE in javac
  • 4e169d1ed7501d1de8fd4ea326f84b6c1a34270d: 8332401: G1: TestFromCardCacheIndex.java with -XX:GCCardSizeInBytes=128 triggers underflow assertion
  • 7ffc9997bd4a93cefe30f672a5f0e9c49215d2c7: 8332498: [aarch64, x86] improving OpToAssembly output for partialSubtypeCheckConstSuper Instruct
  • e529101ea30b49a6601088ce5ab81df590fc52f0: 8332473: ubsan: growableArray.hpp:290:10: runtime error: null pointer passed as argument 1, which is declared to never be null
  • 414a7fdc5e4aae4cec25b0847bb7c163f271b4e0: 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[bot] avatar May 21 '24 14:05 openjdk[bot]

@shipilev Pushed as commit d999b81e7110751be402012e1ed41b3256f5895e.

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

openjdk[bot] avatar May 21 '24 14:05 openjdk[bot]