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

Example in JEP 193 spec with Foo and Bar worked at build 138 now fails build 157

    Details

      Description

      FULL PRODUCT VERSION :
      Jdk9-ea build 157

      FULL OS VERSION :
      10.12.3 (16D32)

      A DESCRIPTION OF THE PROBLEM :
      Example program fails at run time with error message that it cannot transform compareAndSet(Varhandle, DSStore, DSObject, DSObject): boolean into compareAndSet(VarHandle, Object[]) : boolean.

      For Foo/Bar example, (VarHandle, 0, 1) to (VarHandle, Object[])

      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Build Foo and Bar from JEP 193 example
      try exercising the VarHandle method

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected compareAndSet functions according to spec as it did at Build 138
      Actual: Error message as indicated.
      REPRODUCIBILITY :
      This bug can be reproduced always.

        Activity

        Hide
        psonal Pallavi Sonal added a comment -
        From submitter
        ---------------------
        The test is run under NetBeans 8.2 recently updated.

        package au.com.wcc.vectors;

        public class Foo {
           int i;
           
            /**
             * @param args the command line arguments
             */
            public static void main(String[] args) {
                  Foo f = new Foo();
                  Bar.VH_FOO_FIELD_I.compareAndSet(f, 0, 1);
            }
            
        }

        package au.com.wcc.vectors;

        import java.lang.invoke.MethodHandles;
        import java.lang.invoke.VarHandle;

        public class Bar {
             public static final VarHandle VH_FOO_FIELD_I;

            static {
                try {
                    VH_FOO_FIELD_I = MethodHandles.lookup().
                        in(Foo.class).
                        findVarHandle(Foo.class, "i", int.class);
                } catch (Exception e) {
                    throw new Error(e);
                }
            }
        }

        Exception in thread "main" java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(VarHandle,Foo,int,int)boolean to (VarHandle,Object[])boolean
        at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:785)
        at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:771)
        at java.base/java.lang.invoke.Invokers.checkVarHandleGenericType(Invokers.java:450)
        at au.com.wcc.vectors.Foo.main(Foo.java:20)

        Show
        psonal Pallavi Sonal added a comment - From submitter --------------------- The test is run under NetBeans 8.2 recently updated. package au.com.wcc.vectors; public class Foo {    int i;         /**      * @param args the command line arguments      */     public static void main(String[] args) {           Foo f = new Foo();           Bar.VH_FOO_FIELD_I.compareAndSet(f, 0, 1);     }      } package au.com.wcc.vectors; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; public class Bar {      public static final VarHandle VH_FOO_FIELD_I;     static {         try {             VH_FOO_FIELD_I = MethodHandles.lookup().                 in(Foo.class).                 findVarHandle(Foo.class, "i", int.class);         } catch (Exception e) {             throw new Error(e);         }     } } Exception in thread "main" java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(VarHandle,Foo,int,int)boolean to (VarHandle,Object[])boolean at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:785) at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:771) at java.base/java.lang.invoke.Invokers.checkVarHandleGenericType(Invokers.java:450) at au.com.wcc.vectors.Foo.main(Foo.java:20)
        Hide
        psonal Pallavi Sonal added a comment -
        To submitter:
        ----------------
        Thank you for providing the details.
        Can you try running this on command line with the javac compiler. I guess this was the difference in our approach due to which I wasn’t able to reproduce the issue.
        Show
        psonal Pallavi Sonal added a comment - To submitter: ---------------- Thank you for providing the details. Can you try running this on command line with the javac compiler. I guess this was the difference in our approach due to which I wasn’t able to reproduce the issue.
        Hide
        psandoz Paul Sandoz added a comment -
        The test case is not reproducible with javac. The compareAndSet call should compile to something like the following (as shown via javap):

          14: invokevirtual #5 // Method java/lang/invoke/VarHandle.compareAndSet:(LFoo;II)Z

        The compiler used by the submitter is not processing signature polymorphic methods correctly and generating a call as if the parameter type was Object[], such as:

          // Method java/lang/invoke/VarHandle.compareAndSet:([Ljava/lang/Object;)Z
        Show
        psandoz Paul Sandoz added a comment - The test case is not reproducible with javac. The compareAndSet call should compile to something like the following (as shown via javap):   14: invokevirtual #5 // Method java/lang/invoke/VarHandle.compareAndSet:(LFoo;II)Z The compiler used by the submitter is not processing signature polymorphic methods correctly and generating a call as if the parameter type was Object[], such as:   // Method java/lang/invoke/VarHandle.compareAndSet:([Ljava/lang/Object;)Z
        Hide
        psonal Pallavi Sonal added a comment -
        From submitter:
        I have modified Foo as follows

        public class Foo {
           int i;
           
           public void body(){
               System.out.println("i=" + i);
               Bar.VH_FOO_FIELD_I.compareAndSet(this, 0, 1);
               System.out.println("i=" + i);
           }
           
            /**
             * @param args the command line arguments
             */
            public static void main(String[] args) {
                Foo f = new Foo();
                f.body();
            }
            
        }

        and put both Foo and Bar in the default package (‘cos I am not very good with the command line - that’s what IDE’s are for).

        Under NetBeans it still gives that same error message. But, modified rapture, on the command line I get
        i=0
        i=1

        So, no bug in Java 9, but some fault in the configuration of NetBeans.
        Do I continue to talk to you or will you transfer me to someone else?

        What should I look at where in NetBeans?
        Show
        psonal Pallavi Sonal added a comment - From submitter: I have modified Foo as follows public class Foo {    int i;        public void body(){        System.out.println("i=" + i);        Bar.VH_FOO_FIELD_I.compareAndSet(this, 0, 1);        System.out.println("i=" + i);    }         /**      * @param args the command line arguments      */     public static void main(String[] args) {         Foo f = new Foo();         f.body();     }      } and put both Foo and Bar in the default package (‘cos I am not very good with the command line - that’s what IDE’s are for). Under NetBeans it still gives that same error message. But, modified rapture, on the command line I get i=0 i=1 So, no bug in Java 9, but some fault in the configuration of NetBeans. Do I continue to talk to you or will you transfer me to someone else? What should I look at where in NetBeans?
        Hide
        psonal Pallavi Sonal added a comment -
        To submitter:
        The bugs for Netbeans can be logged at https://netbeans.org/bugzilla/ . As this is not a JDK issue, I will be closing it at our end.
        Show
        psonal Pallavi Sonal added a comment - To submitter: The bugs for Netbeans can be logged at https://netbeans.org/bugzilla/ . As this is not a JDK issue, I will be closing it at our end.

          People

          • Assignee:
            psonal Pallavi Sonal
            Reporter:
            webbuggrp Webbug Group
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: