Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8299426

Heap dump does not contain virtual Thread stack references

    XMLWordPrintable

Details

    • svc
    • b02
    • generic
    • generic
    • Fix failed

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        Ubunu 22.10 x86_64
        openjdk version "21-ea" 2023-09-19
        OpenJDK Runtime Environment (build 21-ea+3-124)
        OpenJDK 64-Bit Server VM (build 21-ea+3-124, mixed mode, sharing)

        A DESCRIPTION OF THE PROBLEM :
        HPROF files do not contain stack references of unmounted VirtualThreads. This would be necessary for all analyses based on reachability like biggest objects and dominator trees.
        The HPROF file format generally supports variable-length HPROF_GC_INSTANCE_DUMP records so the references could be appended to the StackChunk dump.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        With the attached source, create a HPROF file and open it in a HPROF analyser that can show incoming references.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        There should be a reference to the VThreadReferenced instance.
        ACTUAL -
        There are no references to the VThreadReferenced instance.

        ---------- BEGIN SOURCE ----------
        -- HprofVThreadStackRef.java ---------------------------------------------------------
        import com.sun.management.HotSpotDiagnosticMXBean;

        import java.io.File;
        import java.lang.management.ManagementFactory;
        import java.util.concurrent.CountDownLatch;

        public class HprofVThreadStackRef {
            public static void main(String[] args) throws Exception {
                CountDownLatch dumpedLatch = new CountDownLatch(1);
                Thread vthread = Thread.ofVirtual().start(() -> {
                    Object referenced = new VThreadReferenced();
                    System.out.println(referenced.getClass());
                    await(dumpedLatch);
                    System.out.println(referenced.getClass());
                });
                Thread.sleep(2000); // wait for reference and unmount
                HotSpotDiagnosticMXBean hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
                File hprofFile = new File("vthread_test.hprof");
                hprofFile.delete();
                hotSpotDiagnosticMXBean.dumpHeap(hprofFile.getPath(), true);
                dumpedLatch.countDown();
                vthread.join();
            }

            private static void await(CountDownLatch dumpedLatch) {
                try {
                    dumpedLatch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            public static class VThreadReferenced {
            }
        }
        --------------------------------------------------------------------------------------

        ---------- END SOURCE ----------

        FREQUENCY : always


        Attachments

          Issue Links

            There are no Sub-Tasks for this issue.

            Activity

              People

                amenkov Alex Menkov
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: