Skip to content

8354555: Add generic JFR events for TaskTerminator #24676

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

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

Conversation

pengxiaolong
Copy link

@pengxiaolong pengxiaolong commented Apr 16, 2025

The purpose of the PR is to add generic JFR events for TaskTerminator to track the attempts and timings that GC threads have tried to terminate GC tasks.

Today only G1 emits JFR event with name Termination from G1ParEvacuateFollowersClosure, all other garbage collectors don't emit any JFR event for the termination attempt at all.

By adding this, it gives performance engineers the visibility to the termination attempts and termination time when GC threads trying to finish GC tasks, we could build tool to analyze the jfr events to determine if there is potential data structure issue in application code, e.g. very large LinkedList or LinkedBlockingQueue.

For the test, I have manually tested different GCs with Flight Recording enabled and verified the events:
G1:

jdk.GCPhaseParallel {
  startTime = 23:09:34.124 (2025-05-22)
  duration = 0.0108 ms
  gcId = 0
  gcWorkerId = 8
  name = "Termination"
  eventThread = "GC Thread#4" (osThreadId = 20483)
}

jdk.GCPhaseParallel {
  startTime = 23:09:34.124 (2025-05-22)
  duration = 0.0467 ms
  gcId = 0
  gcWorkerId = 2
  name = "Termination"
  eventThread = "GC Thread#2" (osThreadId = 21251)
}

jdk.GCPhaseParallel {
  startTime = 23:09:34.124 (2025-05-22)
  duration = 0.0474 ms
  gcId = 0
  gcWorkerId = 1
  name = "Termination"
  eventThread = "GC Thread#8" (osThreadId = 36359)
}
jdk.GCPhaseParallel {
  startTime = 23:09:41.925 (2025-05-22)
  duration = 0.000834 ms
  gcId = 14
  gcWorkerId = 7
  name = "Termination: Parallel Marking"
  eventThread = "GC Thread#1" (osThreadId = 21507)
}

jdk.GCPhaseParallel {
  startTime = 23:09:41.925 (2025-05-22)
  duration = 0.000166 ms
  gcId = 14
  gcWorkerId = 7
  name = "Termination: Parallel Marking"
  eventThread = "GC Thread#1" (osThreadId = 21507)
}

Shenandoah:

jdk.GCPhaseParallel {
  startTime = 23:39:58.890 (2025-05-22)
  duration = 0.0202 ms
  gcId = 0
  gcWorkerId = 0
  name = "Termination: Concurrent Mark"
  eventThread = "Shenandoah GC Threads#3" (osThreadId = 13827)
}

jdk.GCPhaseParallel {
  startTime = 23:39:58.890 (2025-05-22)
  duration = 0.0205 ms
  gcId = 0
  gcWorkerId = 1
  name = "Termination: Concurrent Mark"
  eventThread = "Shenandoah GC Threads#1" (osThreadId = 14339)
}

jdk.GCPhaseParallel {
  startTime = 23:39:58.890 (2025-05-22)
  duration = 0.0127 ms
  gcId = 0
  gcWorkerId = 5
  name = "Termination: Final Mark"
  eventThread = "Shenandoah GC Threads#1" (osThreadId = 14339)
}

jdk.GCPhaseParallel {
  startTime = 23:39:58.890 (2025-05-22)
  duration = 0.0377 ms
  gcId = 0
  gcWorkerId = 3
  name = "Termination: Final Mark"
  eventThread = "Shenandoah GC Threads#3" (osThreadId = 13827)
}

Parallel GC:

jdk.GCPhaseParallel {
  startTime = 23:31:25.009 (2025-05-22)
  duration = 0.0168 ms
  gcId = 0
  gcWorkerId = 4
  name = "Termination: Scavenge"
  eventThread = "GC Thread#1" (osThreadId = 14339)
}

jdk.GCPhaseParallel {
  startTime = 23:31:25.009 (2025-05-22)
  duration = 0.325 ms
  gcId = 0
  gcWorkerId = 5
  name = "Termination: Scavenge"
  eventThread = "GC Thread#5" (osThreadId = 21507)
}

jdk.GCPhaseParallel {
  startTime = 23:31:25.009 (2025-05-22)
  duration = 0.338 ms
  gcId = 0
  gcWorkerId = 8
  name = "Termination: Scavenge"
  eventThread = "GC Thread#7" (osThreadId = 33799)
}

Test

  • Test and verify the termination events in jfr for G1, Shenandoah and Parallel GC.
  • Tier 1
  • Tier 2
  • all tests in jdk/jfr

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-8354555: Add generic JFR events for TaskTerminator (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24676

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 16, 2025

👋 Welcome back xpeng! 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 Apr 16, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Apr 16, 2025

@pengxiaolong 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 Apr 16, 2025
Copy link
Member

@shipilev shipilev 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 compelling, but we need to fix a few issues:


~TaskTerminationTracker() {
if (_terminator->_task_name != nullptr && _event.should_commit()) {
char* event_name = NEW_C_HEAP_ARRAY(char, strlen(TaskTerminator::termination_event_name_prefix) + strlen(_terminator->_task_name) + 1, mtGC);
Copy link
Member

Choose a reason for hiding this comment

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

Well, NEW_C_HEAP_ARRAY without a matching FREE_C_HEAP_ARRAY is a memory leak.

We do this to prepend Termination: , right? Can we just pass the constant strings to TaskTerminator, and avoid all this dynamicity? It would be a bit tedious, but I think you can do the compile-time concatenation with a few macros.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I have replaced it with macro for the string concatenation here, now it doesn't use NEW_C_HEAP_ARRAY at all.

_terminator(num_workers, _task_queues),
_pinned_regions_recorded(false)
{ }
_terminator(num_workers, _task_queues, G1GCPhaseTimes::phase_name(G1GCPhaseTimes::Termination)),
Copy link
Author

Choose a reason for hiding this comment

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

G1EvacuateRegionsBaseTask emits Termination event from G1ParEvacuateFollowersClosure:: offer_termination(), I am trying to keep it same.

@@ -949,7 +946,7 @@ class G1STWRefProcProxyTask : public RefProcProxyTask {
: RefProcProxyTask("G1STWRefProcProxyTask", max_workers),
_g1h(g1h),
_pss(pss),
_terminator(max_workers, &task_queues),
_terminator(max_workers, &task_queues, G1GCPhaseTimes::phase_name(G1GCPhaseTimes::Termination)),
Copy link
Author

Choose a reason for hiding this comment

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

RefProcProxyTask emits Termination event from G1ParEvacuateFollowersClosure:: offer_termination(), I am trying to keep it same as it is today.

@pengxiaolong pengxiaolong marked this pull request as ready for review May 14, 2025 05:56
@openjdk openjdk bot added the rfr Pull request is ready for review label May 14, 2025
@mlbridge
Copy link

mlbridge bot commented May 14, 2025

Webrevs

@openjdk
Copy link

openjdk bot commented May 23, 2025

@pengxiaolong 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 JDK-8354555
git fetch https://git.openjdk.org/jdk.git 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 the merge-conflict Pull request has merge conflict with target branch label May 23, 2025
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label May 23, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Jun 10, 2025

@pengxiaolong This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@pengxiaolong
Copy link
Author

/keepalive

@openjdk
Copy link

openjdk bot commented Jun 24, 2025

@pengxiaolong The pull request is being re-evaluated and the inactivity timeout has been reset.

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 23, 2025

@pengxiaolong This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review shenandoah shenandoah-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

2 participants