Steps to reproduce
1. Start Java program by non-root user ( pasc in my case )
pasc@pasc-mac /Users/pasc/workspace % java PascUserJavaPid
pasc@pasc-mac /Users/pasc % jcmd
97931 PascUserJavaPid -----> we are interested in this pid
2. Now use jcmd to attach from root
pasc-mac:T root# jcmd 97931 help
97931:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.BsdVirtualMachine.<init>(BsdVirtualMachine.java:90)
at sun.tools.attach.BsdAttachProvider.attachVirtualMachine(BsdAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
at sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:147)
at sun.tools.jcmd.JCmd.main(JCmd.java:131)
3. And user java process throws thread dump in the console
pasc@pasc-mac /Users/pasc/workspace % java PascUserJavaPid
2023-11-06 15:06:37Full thread dump Java HotSpot(TM) 64-Bit Server VM (11.0.16+11-LTS-199 mixed mode):
Threads class SMR info:_java_thread_list=0x0000600003009d60, length=9, elements={0x000000014c80b800, 0x000000013280f800, 0x0000000132814800, 0x000000014c980000,0x000000014c983000, 0x000000014e057800, 0x000000014e058800, 0x000000014d812000,0x0000000132811800}
"main" #1 prio=5 os_prio=31 cpu=117725.73ms elapsed=118.56s tid=0x000000014c80b800 nid=0x2803 runnable [0x000000016b322000] java.lang.Thread.State: RUNNABLE at PascUserJavaPid.main(PascUserJavaPid.java:4)
"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=0.08ms elapsed=118.55s tid=0x000000013280f800 nid=0x4103 waiting on condition [0x000000016c176000] java.lang.Thread.State: RUNNABLE at java.lang.ref.Reference.waitForReferencePendingList(java.base@11.0.16/Native Method) at java.lang.ref.Reference.processPendingReferences(java.base@11.0.16/Reference.java:241) at java.lang.ref.Reference$ReferenceHandler.run(java.base@11.0.16/Reference.java:213)
"Finalizer" #3 daemon prio=8 os_prio=31 cpu=0.21ms elapsed=118.55s tid=0x0000000132814800 nid=0x4303 in Object.wait() [0x000000016c382000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(java.base@11.0.16/Native Method) - waiting on <0x00000005dfe09018> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(java.base@11.0.16/ReferenceQueue.java:155) - waiting to re-lock in wait() <0x00000005dfe09018> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(java.base@11.0.16/ReferenceQueue.java:176) at java.lang.ref.Finalizer$FinalizerThread.run(java.base@11.0.16/Finalizer.java:170)
"Signal Dispatcher" #4 daemon prio=9 os_prio=31 cpu=0.08ms elapsed=118.54s tid=0x000000014c980000 nid=0x5503 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE
"Service Thread" #5 daemon prio=9 os_prio=31 cpu=0.02ms elapsed=118.54s tid=0x000000014c983000 nid=0x7f03 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #6 daemon prio=9 os_prio=31 cpu=7.99ms elapsed=118.54s tid=0x000000014e057800 nid=0x5a03 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE No compile task
"C1 CompilerThread0" #9 daemon prio=9 os_prio=31 cpu=21.69ms elapsed=118.54s tid=0x000000014e058800 nid=0x5c03 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE No compile task
"Sweeper thread" #10 daemon prio=9 os_prio=31 cpu=0.02ms elapsed=118.54s tid=0x000000014d812000 nid=0x5d03 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE
"Common-Cleaner" #11 daemon prio=8 os_prio=31 cpu=0.18ms elapsed=118.52s tid=0x0000000132811800 nid=0x5f03 in Object.wait() [0x000000016d0e2000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(java.base@11.0.16/Native Method) - waiting on <0x00000005dff87fc0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(java.base@11.0.16/ReferenceQueue.java:155) - waiting to re-lock in wait() <0x00000005dff87fc0> (a java.lang.ref.ReferenceQueue$Lock) at jdk.internal.ref.CleanerImpl.run(java.base@11.0.16/CleanerImpl.java:148) at java.lang.Thread.run(java.base@11.0.16/Thread.java:834) at jdk.internal.misc.InnocuousThread.run(java.base@11.0.16/InnocuousThread.java:134)
"VM Thread" os_prio=31 cpu=2.31ms elapsed=118.56s tid=0x000000014d811800 nid=0x5403 runnable
"GC Thread#0" os_prio=31 cpu=0.15ms elapsed=118.57s tid=0x000000014d80b000 nid=0x3c03 runnable
"G1 Main Marker" os_prio=31 cpu=0.16ms elapsed=118.57s tid=0x000000014c84b800 nid=0x3b03 runnable
"G1 Conc#0" os_prio=31 cpu=0.02ms elapsed=118.57s tid=0x000000014c84c000 nid=0x3903 runnable
"G1 Refine#0" os_prio=31 cpu=0.17ms elapsed=118.56s tid=0x000000014c96d000 nid=0x3203 runnable
"G1 Young RemSet Sampling" os_prio=31 cpu=6.72ms elapsed=118.56s tid=0x000000014e008800 nid=0x3803 runnable"VM Periodic Task Thread" os_prio=31 cpu=34.05ms elapsed=118.52s tid=0x000000014c9e1800 nid=0x7603 waiting on condition
JNI global refs: 15, weak refs: 0
Heap garbage-first heap total 524288K, used 2048K [0x00000005c0000000, 0x00000007c0000000) region size 2048K, 2 young (4096K), 0 survivors (0K) Metaspace used 6858K, capacity 6934K, committed 7168K, reserved 1056768K class space used 620K, capacity 657K, committed 768K, reserved 1048576K
This issue occurrence verified in all major JDK versions:
1.8.0_381, 11.0.16, 17 and 21
A similar issue was found and fixed in -JDK-8197387
But the fix seems to be working only for Linux and not for Mac.
1. Start Java program by non-root user ( pasc in my case )
pasc@pasc-mac /Users/pasc/workspace % java PascUserJavaPid
pasc@pasc-mac /Users/pasc % jcmd
97931 PascUserJavaPid -----> we are interested in this pid
2. Now use jcmd to attach from root
pasc-mac:T root# jcmd 97931 help
97931:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.BsdVirtualMachine.<init>(BsdVirtualMachine.java:90)
at sun.tools.attach.BsdAttachProvider.attachVirtualMachine(BsdAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
at sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:147)
at sun.tools.jcmd.JCmd.main(JCmd.java:131)
3. And user java process throws thread dump in the console
pasc@pasc-mac /Users/pasc/workspace % java PascUserJavaPid
2023-11-06 15:06:37Full thread dump Java HotSpot(TM) 64-Bit Server VM (11.0.16+11-LTS-199 mixed mode):
Threads class SMR info:_java_thread_list=0x0000600003009d60, length=9, elements={0x000000014c80b800, 0x000000013280f800, 0x0000000132814800, 0x000000014c980000,0x000000014c983000, 0x000000014e057800, 0x000000014e058800, 0x000000014d812000,0x0000000132811800}
"main" #1 prio=5 os_prio=31 cpu=117725.73ms elapsed=118.56s tid=0x000000014c80b800 nid=0x2803 runnable [0x000000016b322000] java.lang.Thread.State: RUNNABLE at PascUserJavaPid.main(PascUserJavaPid.java:4)
"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=0.08ms elapsed=118.55s tid=0x000000013280f800 nid=0x4103 waiting on condition [0x000000016c176000] java.lang.Thread.State: RUNNABLE at java.lang.ref.Reference.waitForReferencePendingList(java.base@11.0.16/Native Method) at java.lang.ref.Reference.processPendingReferences(java.base@11.0.16/Reference.java:241) at java.lang.ref.Reference$ReferenceHandler.run(java.base@11.0.16/Reference.java:213)
"Finalizer" #3 daemon prio=8 os_prio=31 cpu=0.21ms elapsed=118.55s tid=0x0000000132814800 nid=0x4303 in Object.wait() [0x000000016c382000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(java.base@11.0.16/Native Method) - waiting on <0x00000005dfe09018> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(java.base@11.0.16/ReferenceQueue.java:155) - waiting to re-lock in wait() <0x00000005dfe09018> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(java.base@11.0.16/ReferenceQueue.java:176) at java.lang.ref.Finalizer$FinalizerThread.run(java.base@11.0.16/Finalizer.java:170)
"Signal Dispatcher" #4 daemon prio=9 os_prio=31 cpu=0.08ms elapsed=118.54s tid=0x000000014c980000 nid=0x5503 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE
"Service Thread" #5 daemon prio=9 os_prio=31 cpu=0.02ms elapsed=118.54s tid=0x000000014c983000 nid=0x7f03 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #6 daemon prio=9 os_prio=31 cpu=7.99ms elapsed=118.54s tid=0x000000014e057800 nid=0x5a03 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE No compile task
"C1 CompilerThread0" #9 daemon prio=9 os_prio=31 cpu=21.69ms elapsed=118.54s tid=0x000000014e058800 nid=0x5c03 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE No compile task
"Sweeper thread" #10 daemon prio=9 os_prio=31 cpu=0.02ms elapsed=118.54s tid=0x000000014d812000 nid=0x5d03 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE
"Common-Cleaner" #11 daemon prio=8 os_prio=31 cpu=0.18ms elapsed=118.52s tid=0x0000000132811800 nid=0x5f03 in Object.wait() [0x000000016d0e2000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(java.base@11.0.16/Native Method) - waiting on <0x00000005dff87fc0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(java.base@11.0.16/ReferenceQueue.java:155) - waiting to re-lock in wait() <0x00000005dff87fc0> (a java.lang.ref.ReferenceQueue$Lock) at jdk.internal.ref.CleanerImpl.run(java.base@11.0.16/CleanerImpl.java:148) at java.lang.Thread.run(java.base@11.0.16/Thread.java:834) at jdk.internal.misc.InnocuousThread.run(java.base@11.0.16/InnocuousThread.java:134)
"VM Thread" os_prio=31 cpu=2.31ms elapsed=118.56s tid=0x000000014d811800 nid=0x5403 runnable
"GC Thread#0" os_prio=31 cpu=0.15ms elapsed=118.57s tid=0x000000014d80b000 nid=0x3c03 runnable
"G1 Main Marker" os_prio=31 cpu=0.16ms elapsed=118.57s tid=0x000000014c84b800 nid=0x3b03 runnable
"G1 Conc#0" os_prio=31 cpu=0.02ms elapsed=118.57s tid=0x000000014c84c000 nid=0x3903 runnable
"G1 Refine#0" os_prio=31 cpu=0.17ms elapsed=118.56s tid=0x000000014c96d000 nid=0x3203 runnable
"G1 Young RemSet Sampling" os_prio=31 cpu=6.72ms elapsed=118.56s tid=0x000000014e008800 nid=0x3803 runnable"VM Periodic Task Thread" os_prio=31 cpu=34.05ms elapsed=118.52s tid=0x000000014c9e1800 nid=0x7603 waiting on condition
JNI global refs: 15, weak refs: 0
Heap garbage-first heap total 524288K, used 2048K [0x00000005c0000000, 0x00000007c0000000) region size 2048K, 2 young (4096K), 0 survivors (0K) Metaspace used 6858K, capacity 6934K, committed 7168K, reserved 1056768K class space used 620K, capacity 657K, committed 768K, reserved 1048576K
This issue occurrence verified in all major JDK versions:
1.8.0_381, 11.0.16, 17 and 21
A similar issue was found and fixed in -
But the fix seems to be working only for Linux and not for Mac.