Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7018378

JSR 292: _bound_int_mh produces wrong result on 64-bit SPARC

XMLWordPrintable

    • b03
    • generic
    • generic
    • Verified

        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;
        }
        ...
        }

              twisti Christian Thalinger (Inactive)
              kshiroko Kirill Shirokov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: