JDK-7018378 : JSR 292: _bound_int_mh produces wrong result on 64-bit SPARC
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: hs20
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-02-09
  • Updated: 2012-02-01
  • Resolved: 2011-03-08
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 Other
7Fixed hs21Fixed
Related Reports
Relates :  
Description
The test below computes long sum using different methods. On solaris-sparcv9 it produced different sums:

Sum computed using MH 1=50001375000000 
Sum computed using MH 2=50000955000000 
Sum using direct calls =50001375000000

The test:

...
public class Test {
	
	private static final int ITERATIONS = 10000000;
	private static final int THE_CONSTANT = 42;

	static int i(int i) {
		return i;
	}
	
	static int k(int i) {
		return THE_CONSTANT;
	}
	
	private int _field = 96;
	int getter() {
		return _field;
	}
	
	int iplusk(int i) {
		return i(i) + k(i) + getter();
	}
	
	static int mhplusmh(MethodHandle a, MethodHandle b, MethodHandle c, int i) throws Throwable {
		return (int) a.invokeExact(i) + (int) b.invokeExact(i) + (int) c.invokeExact();
	}
	
	public boolean run() throws Throwable {
		Lookup l = MethodHandles.lookup();
		MethodHandle ipluskh = l.findVirtual(Test.class, "iplusk", MethodType.methodType(int.class, int.class)).bindTo(this);
		
		MethodHandle ich = MethodHandles.identity(int.class);
		MethodHandle kch = MethodHandles.dropArguments(MethodHandles.constant(int.class, THE_CONSTANT), 0, int.class);
		MethodHandle gch = l.findGetter(Test.class, "_field", int.class).bindTo(this);
		MethodHandle ipluskch = MethodHandles.insertArguments(
				l.findStatic(Test.class, "mhplusmh", 
						MethodType.methodType(int.class, MethodHandle.class, MethodHandle.class, MethodHandle.class, int.class)),
				0, ich, kch, gch);
		
		long mh1Result = 0, mh2Result = 0, directResult = 0;
		for ( int i = 0; i < ITERATIONS; i++ ) {
			mh1Result += (int) ipluskh.invokeExact(i);
			mh2Result += (int) ipluskch.invokeExact(i);
			directResult += iplusk(i);
		}

		if ( mh1Result != directResult || mh2Result != directResult ) {
			System.out.println(
					"Sum computed using MH 1=" + mh1Result 
				  + "; Sum computed using MH 2=" + mh2Result 
				  + "; using direct calls=" + directResult
			);
			return false;
		}
			
		return true;
	}
...
}

Comments
EVALUATION http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/28bf941f445e
14-02-2011

SUGGESTED FIX Replace the existing code with a ld_long/st_long sequence.
10-02-2011

EVALUATION The bug is in the implementation of SPARC's _bound_int_direct_mh. The current code reads a 64-bit integer value with ldx and tries to sign-extend it properly for st_long. But that sign-extension code is wrong.
10-02-2011

EVALUATION It also fails with the interpreter so I guess there is a bug in one of the hand-written method handle adapters. Reproducible with: $ gamma -Xint -XX:+UseSerialGC -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining Test
10-02-2011