JDK-7143353 : -Xrunhprof fails in Java 7 due to bad switch
  • Type: Bug
  • Component: tools
  • Sub-Component: hprof
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,solaris_10
  • CPU: x86
  • Submitted: 2012-02-07
  • Updated: 2019-08-16
  • Resolved: 2012-07-16
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.
JDK 7
7u6 b13Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux headius-Server 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

Darwin Charles-Oliver-Nutters-MacBook-Pro.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
In all builds of OpenJDK 7 I have tried, the -Xrunhprof switch (for the "demo" JVMTI profiler) fails to work with the following error when run against code that uses invokedynamic or methodhandle/methodtype references:

HPROF ERROR: Unknown constant
[../../../src/share/demo/jvmti/java_crw_demo/java_crw_demo.c:693]
[hprof_init.c:210]
HPROF TERMINATED PROCESS

The problem lies in the file listed here. A switch statement (at
java_crw_demo.c:662 in my copy) is not handling the two new constant types JVM_CONSTANT_MethodHandle and JVM_CONSTANT_MethodType.

I'm not sure the right way to handle them, but because they are missing the switch falls off the end and produces this error.

I understand that "hprof" is demonstration code, but there are folks like
myself that actually use its output.

Note that the switch in question is missing *at least* the constants I
reported. There may be others.

I also did a quick audit of other places where these constants are used and found the following files that might be worth examining...

hotspot/src/share/vm/oops/constantPoolOop.cpp in
constantPoolOopDesc::shared_symbols_iterate,
constantPoolOopDesc::shared_strings_iterate, print_cpool_bytes (some of these may be filtered out elsewhere)

hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp in
VM_RedefineClasses::append_entry

This is not a complete list, but they were at least suspicious.

REGRESSION.  Last worked in version 6u29

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run any program that uses invokedynamic, methodhandle, or methodtype constant pool entries with the -Xrunhprof flag passed to the JVM.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The "hprof" JVMTI profiler should profile the program.
ACTUAL -
The error mentioned in the description is produced.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
HPROF ERROR: Unknown constant
[../../../src/share/demo/jvmti/java_crw_demo/java_crw_demo.c:693]
[hprof_init.c:210]
HPROF TERMINATED PROCESS

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
It is not possible to produce Java source code that compiles to a .class file with invokedynamic, methodhandle, or methodtype constant pool entries. The invokedynamic-related test code in OpenJDK should work as an example case.
---------- END SOURCE ----------

Comments
Fixed jdk8, http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/5ec5588c733d
06-11-2013

EVALUATION http://hg.openjdk.java.net/jdk7u/jdk7u-dev/jdk/rev/61517f1fe79e
25-05-2012

EVALUATION http://hg.openjdk.java.net/jdk8/tl/jdk/rev/5ec5588c733d
24-05-2012

EVALUATION see comments
22-05-2012