United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7093328 JVMTI: jvmtiPrimitiveFieldCallback always report 0's for static primitives
JDK-7093328 : JVMTI: jvmtiPrimitiveFieldCallback always report 0's for static primitives

Details
Type:
Bug
Submit Date:
2011-09-21
Status:
Closed
Updated Date:
2013-06-26
Project Name:
JDK
Resolved Date:
2012-11-07
Component:
hotspot
OS:
windows_7
Sub-Component:
jvmti
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u40 (b01)

Related Reports
Backport:
Backport:
Backport:
Backport:
Relates:

Sub Tasks

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
EVALUATION

The agent code is missing from the example test.
                                     
2011-09-21
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;
                                     
2012-08-30
URL:   http://hg.openjdk.java.net/jdk7u/jdk7u-dev/hotspot/rev/16f3116e792d
User:  amurillo
Date:  2012-11-07 19:08:46 +0000

                                     
2012-11-07
URL:   http://hg.openjdk.java.net/jdk7u/jdk7u/hotspot/rev/16f3116e792d
User:  amurillo
Date:  2012-11-07 19:33:34 +0000

                                     
2012-11-07
URL:   http://hg.openjdk.java.net/jdk7u/jdk7u/hotspot/rev/16f3116e792d
User:  amurillo
Date:  2012-11-07 19:33:34 +0000

                                     
2012-11-07
Verified with attached testcase in 7u12-b01
                                     
2013-01-17



Hardware and Software, Engineered to Work Together