JDK-7093328 : JVMTI: jvmtiPrimitiveFieldCallback always report 0's for static primitives
  • Type: Bug
  • Component: hotspot
  • Sub-Component: jvmti
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-09-21
  • Updated: 2013-06-26
  • Resolved: 2012-11-07
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 JDK 8 Other
7u40 b01Fixed 8Fixed hs24Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
It seems that with jdk7, the jvmtiPrimitiveFieldCallback used with IterateThroughHeap() always reports 0's for static primitive fields. Non-static primitive fields seem to be reported correctly.

REGRESSION.  Last worked in version 6u26

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java-sample:

class Test {
  private float pi = 3.1415927f;
  private static float pipi = 3.1415927f;
  private static String aString = ���hello���;
}

Write an agent that does an IterateThroughHeap(), the jvmtiPrimitiveFieldCallback always reports 3.415927 for the non-static field "pi" of an instance of this class and 0 for the static field "pipi". This was working in Java6.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd exepcted that (as for java6) jvmtiPrimitiveFieldCallback returns 3.1415927 for "pipi" in the example above
ACTUAL -
0 instead of 3.1415927 for "pipi" in the example above

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;

public class Test {
	private static String aString = "hello";
	private float pi = 3.1415927f;
	private static float pipi = 3.1415927f;
	
	public static void main(String[] args) throws Exception {
		Test test = new Test();
		waitForEnter();
	}
	
	public Test() {
	}
	
	private static void waitForEnter() throws IOException {
		System.out.println("waiting for ENTER, pipi="+pipi);
		System.in.skip(System.in.available());
		System.in.read();
	}
}

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

CUSTOMER SUBMITTED WORKAROUND :
none found
1) To run the reproducer, use runStaticFields.cmd. 

C:\devtools\jdk1.7.0_x64\bin\java -agentpath:".\win64\lib\dtdagent.dll" StaticFields
rem C:\devtools\jdk1.6.0_31_x64\bin\java -agentpath:".\win64\lib\dtdagent.dll" StaticFields

You have to adapt JRE locations in this script first.

2) relevant agent-source is in Agent.cpp, please note that this is a highly stripped-down version of our agent and error-checking is not done. 

3) when run with a JDK1.6.x_64, you will get something similar to waiting for ENTER, pipi=2.1415927 doDump invoked found instance of TestClass found primitiveField of TestClass (instance)
        float-value:3.141593
found primitiveField of TestClass (static)
        float-value:2.141593				( <===== )
VMDeath

4) when running with JDK1.7.0_64, you will get something similar to the following, please note that the float-value of the static-field is 0.00 although it is 2.1415 from java and when running with jdk1.6 waiting for ENTER, pipi=2.1415927 doDump invoked found primitiveField of TestClass (static)
        float-value:0.000000				( <===== )
found instance of TestClass
found primitiveField of TestClass (instance)
        float-value:3.141593
VMDeath

Comments
Verified with attached testcase in 7u12-b01
17-01-2013

EVALUATION The cause is the change for 7017732 where static variables where moved. One use seems to have been missed. The line: address addr = (address)k + offset; should have been changed to: address addr = (address)klass->java_mirror() + offset;
30-08-2012

EVALUATION The agent code is missing from the example test.
21-09-2011