United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7018378 JSR 292: _bound_int_mh produces wrong result on 64-bit SPARC
JDK-7018378 : JSR 292: _bound_int_mh produces wrong result on 64-bit SPARC

Details
Type:
Bug
Submit Date:
2011-02-09
Status:
Closed
Updated Date:
2012-02-01
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
hs20
Fixed Versions:
hs21 (b03)

Related Reports
Backport:
Relates:

Sub Tasks

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

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
                                     
2011-02-10
SUGGESTED FIX

Replace the existing code with a ld_long/st_long sequence.
                                     
2011-02-10
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.
                                     
2011-02-10
EVALUATION

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



Hardware and Software, Engineered to Work Together