JDK-8228850 : jhsdb jinfo fails with ClassCastException: s.j.h.oops.TypeArray cannot be cast to s.j.h.oops.Instance
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 14
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2019-07-30
  • Updated: 2023-07-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Test that failed: test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java
This can be container related, or not.

Frequency: Somewhat intermittent, fails about 1 in 4 times in CI

Scenario:
  The observed JVM (target of jhsdb jinfo command) runs in container A (pid=1, normal when running in container), while the 'jhsdb jinfo' runs in a 'sidecar' container B. The containers are 'friendly' to each other, sharing process namespace, /tmp directories and signals. The PTRACE capability is enabled on the target container. It usually works, but in this instance it fails.

See the relevant log section in the comments below:
Comments
From this (abbreviated) stack trace, it looks like SA is trying to get the java mirror (java.lang.Class instance) from the native Klass object, but is ending up with a java instace of type array rather than type java.lang.Class. I don't see how using a sidecar might be causing this. Exception in thread "main" java.lang.ClassCastException: class sun.jvm.hotspot.oops.TypeArray cannot be cast to class sun.jvm.hotspot.oops.Instance (sun.jvm.hotspot.oops.TypeArray and sun.jvm.hotspot.oops.Instance are in module jdk.hotspot.agent of loader 'app') at jdk.hotspot.agent/sun.jvm.hotspot.oops.VMOopHandle.resolve(VMOopHandle.java:61) at jdk.hotspot.agent/sun.jvm.hotspot.oops.Klass.getJavaMirror(Klass.java:112) at jdk.hotspot.agent/sun.jvm.hotspot.oops.InstanceKlass.iterateStaticFields(InstanceKlass.java:649)
26-07-2023

This test is misnamed, as it also tests SA, not just jcmd: // run jhsdb jinfo <PID> (jhsdb uses PTRACE) private static void testCase02(long pid) throws Exception { runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jhsdb", "jinfo", "--pid", "" + pid) .shouldHaveExitValue(0) .shouldContain("Java System Properties") .shouldContain("VM Flags"); }
26-07-2023

To reproduce, comment out testcase02() in test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java. When fixed, please uncomment the mentioned test case.
07-08-2019

[COMMAND] docker run --tty=true --rm --cap-add=SYS_PTRACE --sig-proxy=true --pid=container:test-container-main --volumes-from test-container-main jdk-internal:test-jfr-jcmd /jdk/bin/jhsdb jinfo --pid 1 [2019-07-30T19:44:36.960618Z] Gathering output for process 6943 [ELAPSED: 2 ms] [STDERR] [STDOUT] Attaching to process ID 1, please wait... Debugger attached successfully. Server compiler detected. JVM version is 14-ea+8-241 Java System Properties: Exception in thread "main" java.lang.ClassCastException: class sun.jvm.hotspot.oops.TypeArray cannot be cast to class sun.jvm.hotspot.oops.Instance (sun.jvm.hotspot.oops.TypeArray and sun.jvm.hotspot.oops.Instance are in module jdk.hotspot.agent of loader 'app') at jdk.hotspot.agent/sun.jvm.hotspot.oops.VMOopHandle.resolve(VMOopHandle.java:61) at jdk.hotspot.agent/sun.jvm.hotspot.oops.Klass.getJavaMirror(Klass.java:112) at jdk.hotspot.agent/sun.jvm.hotspot.oops.InstanceKlass.iterateStaticFields(InstanceKlass.java:649) at jdk.hotspot.agent/sun.jvm.hotspot.runtime.VM.readSystemProperties(VM.java:1063) at jdk.hotspot.agent/sun.jvm.hotspot.runtime.VM.getSystemProperties(VM.java:1056) at jdk.hotspot.agent/sun.jvm.hotspot.tools.SysPropsDumper.run(SysPropsDumper.java:44) at jdk.hotspot.agent/sun.jvm.hotspot.tools.JInfo$1.run(JInfo.java:80) at jdk.hotspot.agent/sun.jvm.hotspot.tools.JInfo.run(JInfo.java:95) at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260) at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.start(Tool.java:223) at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.execute(Tool.java:118) at jdk.hotspot.agent/sun.jvm.hotspot.tools.JInfo.runWithArgs(JInfo.java:139) at jdk.hotspot.agent/sun.jvm.hotspot.tools.JInfo.main(JInfo.java:144) at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runJINFO(SALauncher.java:412) at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:543)
30-07-2019