JDK-6736095 : Incorrect optimized code leads to NPE with J2SE 6.0 Hotspot server VM
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2008-08-12
  • Updated: 2010-04-02
  • Resolved: 2008-08-12
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

FULL OS VERSION :
Observed on Linux and Windows:
Linux 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux
Windows Server 2003 x64 R2 SP 2 Version 5.2.3790

A DESCRIPTION OF THE PROBLEM :
When running certain code multiple times (in a loop) with the J2SE 1.6 hotspot server vm, then a NullPointerException occurs at this line:

super.put(localKeys[j], localValues[j]);

It seems that super is null.

The same code does work properly with 1.6 client vm, 1.5 client or 1.5 server vm.

The attached source code is not complete. Complete small testcase is available. Please let me know where to upload.

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Extract zip file with testcase.
It contains a small eclipse 3.3 project.

Starting the testcase commandline (not from eclipse):
Set classpath to current directory and jdo.jar:
> set classpath=.;..\lib\jdo.jar
Change to the bin directory of the testcase directory
> cd bin
Start server vm with class test.Main
> java -server test.Main
Exception in thread "main" java.lang.NullPointerException
        at com.poet.rt.db.tracked.TrackedHashMap.preRead(TrackedHashMap.java:52)
        at com.poet.rt.db.tracked.TrackedHashMap.size(TrackedHashMap.java:119)
        at test.Main.main(Main.java:15)



EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected result:
30000000

Actual result:

[U:\NPETestcase\bin]java -server test.Main
Exception in thread "main" java.lang.NullPointerException
        at com.poet.rt.db.tracked.TrackedHashMap.preRead(TrackedHashMap.java:52)
        at com.poet.rt.db.tracked.TrackedHashMap.size(TrackedHashMap.java:119)
        at test.Main.main(Main.java:15)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
        at com.poet.rt.db.tracked.TrackedHashMap.preRead(TrackedHashMap.java:52)
        at com.poet.rt.db.tracked.TrackedHashMap.size(TrackedHashMap.java:119)
        at test.Main.main(Main.java:15)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
All classes required are available in a seperate small testcase.


Main.java:

package test;

import com.poet.rt.db.tracked.*;

public class Main {
	public static void main(String[] args) {
		TrackedHashMap map = new TrackedHashMap();
		long l=0;
		for( int i=0; i<10000000; i++) {
			map.tempSet(new Object[]{"a", "b", "c"}, new Object[]{"d", "e", "f"});
			l += map.size();
		}
		System.out.println(l);
	}
}


Excerpt from TrackedHashMap:

	private synchronized final void preRead() {
		if (_tempKeys!=null) {
			Object [] localKeys = _tempKeys;
			Object [] localValues = _tempValues;
			_tempKeys = _tempValues = null;

			for (int j=0; j<localKeys.length; ++j)
			{

				super.put(localKeys[j], localValues[j]);
			}
		}
	}



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

CUSTOMER SUBMITTED WORKAROUND :
Adding code to to the method where the NPE occurs (TrackedHashMap.preRead()) seem to prevent the error.

Using 1.6 client VM.
Using 1.6 server VM with -Xint
Using 1.5 VM (client or server)

Release Regression From : 5
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.
It is not super that is null, but localValues.

Comments
EVALUATION When inserting anti-dependencies, GCM fails to correctly negotiate the cfg, and fails to insert the anti-dep that keeps Object [] localValues = _tempValues; before: _tempValues = null; Although it has different symptoms, this bug is fixed by the change for 6714694.
12-08-2008

WORK AROUND 1) Run with '-client' or '-Xint' 2) exclude the preRead method from compilation by creating a .hotspot_compiler file in your run directory. The contents should be: % cat .hotspot_compiler exclude com/poet/rt/db/tracked/TrackedHashMap preRead
12-08-2008