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

JDK-8316691: Heap dump: separate stack traces for mounted virtual threads #15869

Closed
wants to merge 8 commits into from

Conversation

alexmenkov
Copy link

@alexmenkov alexmenkov commented Sep 21, 2023

This is subtask of JDK-8299426: Heap dump does not contain virtual Thread stack references
The change:

  • reorganize thread-related code/prepare it to use for unmounted vthreads:
    • new ThreadDumper class caches stack frames, thread serial num, frame serial number (trace serial number is calculated from thread serial);
      ThreadDumper objects for all platform/carrier and mounted virtual threads are cached instead of ThreadStackTrace objects (they are created during HPROF_FRAME/HPROF_TRACE dumping, used lated for writing HPROF_GC_ROOT_THREAD_OBJ/HPROF_GC_ROOT_JAVA_FRAME/HPROF_GC_ROOT_JNI_LOCAL subrecords);
    • new helper class JavaStackRefDumper to dump references from threadf stack;
  • separate track traces for mounted virtual threads:
    • separate HPROF_FRAME/HPROF_TRACE records for mounted vthreads and carrier threads;
    • separate HPROF_GC_ROOT_THREAD_OBJ/HPROF_GC_ROOT_JAVA_FRAME/HPROF_GC_ROOT_JNI_LOCAL subrecords;
  • updated hprof parser test lib to collect data about threads (HPROF_GC_ROOT_THREAD_OBJ subrecords) and corresponding stack traces and stack references.

Testing - tier1-tier3, new test

Output of the test for VtreadInHeapDumpTarg$VthreadMounted thread
without the fix:
`thread 0x8101be90, 16 frames

  • [0] VtreadInHeapDumpTarg$VthreadMounted.run()V (VtreadInHeapDump.java:127)
    Java Local Reference: VtreadInHeapDumpTarg$VthreadMounted
    Java Local Reference: VtreadInHeapDumpTarg$VThreadMountedReferenced
  • [1] java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V (Thread.java:1583)
    Java Local Reference: java.lang.VirtualThread
    Java Local Reference: java.lang.Class
    Java Local Reference: VtreadInHeapDumpTarg$VthreadMounted
  • [2] java.lang.VirtualThread.run(Ljava/lang/Runnable;)V (VirtualThread.java:309)
    Java Local Reference: java.lang.VirtualThread
    Java Local Reference: VtreadInHeapDumpTarg$VthreadMounted
    Java Local Reference: java.lang.Class
  • [3] java.lang.VirtualThread$VThreadContinuation$1.run()V (VirtualThread.java:190)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation$1
  • [4] jdk.internal.vm.Continuation.enter0()V (Continuation.java:320)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation
  • [5] jdk.internal.vm.Continuation.enter(Ljdk/internal/vm/Continuation;Z)V (Continuation.java:312)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation
  • [6] jdk.internal.vm.Continuation.enterSpecial(Ljdk/internal/vm/Continuation;ZZ)V (Continuation.java:(native method))
  • [7] jdk.internal.vm.Continuation.run()V (Continuation.java:248)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation
    Java Local Reference: jdk.internal.misc.CarrierThread
  • [8] java.lang.VirtualThread.runContinuation()V (VirtualThread.java:221)
    Java Local Reference: java.lang.VirtualThread
  • [9] java.lang.VirtualThread$$Lambda+0x0000023001057a58.run()V (:(unknown))
    Java Local Reference: java.lang.VirtualThread$$Lambda+0x0000023001057a58
  • [10] java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec()Z (ForkJoinTask.java:1423)
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
  • [11] java.util.concurrent.ForkJoinTask.doExec()I (ForkJoinTask.java:387)
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
  • [12] java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Ljava/util/concurrent/ForkJoinTask;Ljava/util/concurrent/ForkJoinPool$WorkQueue;)V (ForkJoinPool.java:1312)
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
  • [13] java.util.concurrent.ForkJoinPool.scan(Ljava/util/concurrent/ForkJoinPool$WorkQueue;II)I (ForkJoinPool.java:1843)
    Java Local Reference: java.util.concurrent.ForkJoinPool
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
    Java Local Reference: [Ljava.util.concurrent.ForkJoinPool$WorkQueue;
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
    Java Local Reference: [Ljava.util.concurrent.ForkJoinTask;
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
  • [14] java.util.concurrent.ForkJoinPool.runWorker(Ljava/util/concurrent/ForkJoinPool$WorkQueue;)V (ForkJoinPool.java:1808)
    Java Local Reference: java.util.concurrent.ForkJoinPool
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
  • [15] java.util.concurrent.ForkJoinWorkerThread.run()V (ForkJoinWorkerThread.java:188)
    Java Local Reference: jdk.internal.misc.CarrierThread
    Java Local Reference: java.util.concurrent.ForkJoinPool
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue`

with the fix:
`thread 0x8101c360, 6 frames

  • [0] VtreadInHeapDumpTarg$VthreadMounted.run()V (VtreadInHeapDump.java:127)
    Java Local Reference: VtreadInHeapDumpTarg$VthreadMounted
    Java Local Reference: VtreadInHeapDumpTarg$VThreadMountedReferenced
  • [1] java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V (Thread.java:1583)
    Java Local Reference: java.lang.VirtualThread
    Java Local Reference: java.lang.Class
    Java Local Reference: VtreadInHeapDumpTarg$VthreadMounted
  • [2] java.lang.VirtualThread.run(Ljava/lang/Runnable;)V (VirtualThread.java:309)
    Java Local Reference: java.lang.VirtualThread
    Java Local Reference: VtreadInHeapDumpTarg$VthreadMounted
    Java Local Reference: java.lang.Class
  • [3] java.lang.VirtualThread$VThreadContinuation$1.run()V (VirtualThread.java:190)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation$1
  • [4] jdk.internal.vm.Continuation.enter0()V (Continuation.java:320)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation
  • [5] jdk.internal.vm.Continuation.enter(Ljdk/internal/vm/Continuation;Z)V (Continuation.java:312)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation

`thread 0x8101be90, 9 frames

  • [0] jdk.internal.vm.Continuation.run()V (Continuation.java:248)
    Java Local Reference: java.lang.VirtualThread$VThreadContinuation
    Java Local Reference: jdk.internal.misc.CarrierThread
  • [1] java.lang.VirtualThread.runContinuation()V (VirtualThread.java:221)
    Java Local Reference: java.lang.VirtualThread
  • [2] java.lang.VirtualThread$$Lambda+0x000001fa96057a58.run()V (:(unknown))
    Java Local Reference: java.lang.VirtualThread$$Lambda+0x000001fa96057a58
  • [3] java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec()Z (ForkJoinTask.java:1423)
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
  • [4] java.util.concurrent.ForkJoinTask.doExec()I (ForkJoinTask.java:387)
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
  • [5] java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Ljava/util/concurrent/ForkJoinTask;Ljava/util/concurrent/ForkJoinPool$WorkQueue;)V (ForkJoinPool.java:1312)
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
  • [6] java.util.concurrent.ForkJoinPool.scan(Ljava/util/concurrent/ForkJoinPool$WorkQueue;II)I (ForkJoinPool.java:1843)
    Java Local Reference: java.util.concurrent.ForkJoinPool
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
    Java Local Reference: [Ljava.util.concurrent.ForkJoinPool$WorkQueue;
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
    Java Local Reference: [Ljava.util.concurrent.ForkJoinTask;
    Java Local Reference: java.util.concurrent.ForkJoinTask$RunnableExecuteAction
  • [7] java.util.concurrent.ForkJoinPool.runWorker(Ljava/util/concurrent/ForkJoinPool$WorkQueue;)V (ForkJoinPool.java:1808)
    Java Local Reference: java.util.concurrent.ForkJoinPool
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue
  • [8] java.util.concurrent.ForkJoinWorkerThread.run()V (ForkJoinWorkerThread.java:188)
    Java Local Reference: jdk.internal.misc.CarrierThread
    Java Local Reference: java.util.concurrent.ForkJoinPool
    Java Local Reference: java.util.concurrent.ForkJoinPool$WorkQueue`

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-8316691: Heap dump: separate stack traces for mounted virtual threads (Sub-task - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15869

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 21, 2023

👋 Welcome back amenkov! 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 openjdk bot added the rfr Pull request is ready for review label Sep 21, 2023
@openjdk
Copy link

openjdk bot commented Sep 21, 2023

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

  • hotspot-runtime
  • serviceability

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 serviceability serviceability-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org labels Sep 21, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 21, 2023

Webrevs

@dholmes-ora
Copy link
Member

Is there anything to tell you which carrier thread is associated with which mounted VThread?

@AlanBateman
Copy link
Contributor

Is there anything to tell you which carrier thread is associated with which mounted VThread?

The carrier and virtual threads are distinct and the HPROF format doesn't have record types to support associations like this. However, your question does make me wonder how it behaves when running with +ShowCarrierFrames.

@alexmenkov
Copy link
Author

Is there anything to tell you which carrier thread is associated with which mounted VThread?
No (at least for now).
I'm not sure if we need this information in heap dump (and if we need a way to differentiate platform(carrier)/virtual threads).
If we need it, we can introduce new record type ((outside of HPROF_HEAP_DUMP record) for this later (new record type should not break existing hprof readers/parsers)

@alexmenkov
Copy link
Author

Is there anything to tell you which carrier thread is associated with which mounted VThread?

The carrier and virtual threads are distinct and the HPROF format doesn't have record types to support associations like this. However, your question does make me wonder how it behaves when running with +ShowCarrierFrames.

IFAIU +ShowCarrierFrames does not makes sense for "general" heap dump (like generated by "jcmd GC.heap_dump").
We can handle it for HeapDumpOnOutOfMemoryError case (when we add fake frame with OOME ctor), but I don't think it'd add a value for diagnostics.

@sspitsyn
Copy link
Contributor

sspitsyn commented Oct 3, 2023

I wonder why the enterSpecial frame is not present in mounted virtual thread stack trace case with the fix:
[6] jdk.internal.vm.Continuation.enterSpecial(Ljdk/internal/vm/Continuation;ZZ)V (Continuation.java:(native method))

@alexmenkov
Copy link
Author

I wonder why the enterSpecial frame is not present in mounted virtual thread stack trace case with the fix: [6] jdk.internal.vm.Continuation.enterSpecial(Ljdk/internal/vm/Continuation;ZZ)V (Continuation.java:(native method))

I used the same logic to split stack traces as ThreadStackTrace::dump_stack_at_safepoint (it was added with VT integration, it's used, for example by VM_ThreadDump).
My understanding that enterSpecial is considered as a special frame which is not belongs to VT stack trace
@AlanBateman could you please comment if my understanding is correct.

@sspitsyn
Copy link
Contributor

sspitsyn commented Oct 5, 2023

used the same logic to split stack traces as ThreadStackTrace::dump_stack_at_safepoint
(it was added with VT integration, it's used, for example by VM_ThreadDump).
My understanding that enterSpecial is considered as a special frame which is not belongs to VT stack trace.

That's right.
I forgot it is not returned by the vframe::java_sender(), so JVMTI GetStackTrace() does not return it as well.

Copy link
Member

@lmesnik lmesnik left a comment

Choose a reason for hiding this comment

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

The fix looks good. (I looked at the test changes mostly.) The only question, if it makes sense to update the test to verify that heapdump works correctly without continuations.

@openjdk
Copy link

openjdk bot commented Oct 6, 2023

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

8316691: Heap dump: separate stack traces for mounted virtual threads

Reviewed-by: lmesnik, sspitsyn

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

  • 33591a3: 8317795: Add an ImmutableBitSetPredicate variant for bitsets <= 128 elements
  • fb4098f: 8317730: Change byte_size to return size_t
  • c2abf12: 8261894: Remove support for UseSHM
  • ad7a8e8: 8315505: CompileTask timestamp printed can overflow
  • fcff222: 8317706: Exclude java/awt/Graphics2D/DrawString/RotTransText.java on linux
  • ef41aa0: 8317711: Exclude gtest/GTestWrapper.java on AIX
  • ad6dce3: 8317705: ProblemList sun/tools/jstat/jstatLineCountsX.sh on linux-ppc64le and aix due to JDK-8248691
  • e882718: 8314199: Initial size PBEKeyFactory#validTypes is not up-to-date
  • d313915: 8316233: VirtualThreadStart events should not be thread-filtered
  • 053f456: 8316447: 8 sun/management/jmxremote tests ignore VM flags
  • ... and 222 more: https://git.openjdk.org/jdk/compare/c04c9ea3615aad875ccb7e103e2d885b34cda7f6...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 ready Pull request is ready to be integrated label Oct 6, 2023
Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

The fix looks pretty good to me.
I've posted several nits though.

src/hotspot/share/services/heapDumper.cpp Outdated Show resolved Hide resolved
src/hotspot/share/services/heapDumper.cpp Outdated Show resolved Hide resolved
src/hotspot/share/services/heapDumper.cpp Outdated Show resolved Hide resolved
@alexmenkov
Copy link
Author

The fix looks good. (I looked at the test changes mostly.) The only question, if it makes sense to update the test to verify that heapdump works correctly without continuations.

good point.
Added testing with -VMContinuations
Also realized that the test itself does not need extra VM options (they are needed only for target process) and the test does not require othervm mode

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Thank you for the update!
Looks good.
Thanks,
Serguei

@alexmenkov
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 10, 2023

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

  • 33591a3: 8317795: Add an ImmutableBitSetPredicate variant for bitsets <= 128 elements
  • fb4098f: 8317730: Change byte_size to return size_t
  • c2abf12: 8261894: Remove support for UseSHM
  • ad7a8e8: 8315505: CompileTask timestamp printed can overflow
  • fcff222: 8317706: Exclude java/awt/Graphics2D/DrawString/RotTransText.java on linux
  • ef41aa0: 8317711: Exclude gtest/GTestWrapper.java on AIX
  • ad6dce3: 8317705: ProblemList sun/tools/jstat/jstatLineCountsX.sh on linux-ppc64le and aix due to JDK-8248691
  • e882718: 8314199: Initial size PBEKeyFactory#validTypes is not up-to-date
  • d313915: 8316233: VirtualThreadStart events should not be thread-filtered
  • 053f456: 8316447: 8 sun/management/jmxremote tests ignore VM flags
  • ... and 222 more: https://git.openjdk.org/jdk/compare/c04c9ea3615aad875ccb7e103e2d885b34cda7f6...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 10, 2023
@openjdk openjdk bot closed this Oct 10, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 10, 2023
@alexmenkov alexmenkov deleted the vt_dump_split branch October 10, 2023 20:13
@openjdk
Copy link

openjdk bot commented Oct 10, 2023

@alexmenkov Pushed as commit 2b8276a.

💡 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-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
5 participants