Adopting JEP 303 (Intrinsics for LDC and INVOKEDYNAMIC) into Amber
Vicente Romero
vicente.romero at oracle.com
Tue Apr 18 13:26:41 UTC 2017
Hi Tagir,
I think that you just hit some bogus behavior. I will work on it and get
back to you.
Thanks for the report.
Vicente
On 04/18/2017 02:17 AM, Tagir Valeev wrote:
> Hello!
>
> I tried to play with this, but still no success. Fresh build from
> constant-folding branch. I tried to compile the following files:
>
> // MH.java
> import java.lang.invoke.*; import java.lang.invoke.Constables.*;
> import java.lang.reflect.*; public class MH { private static void
> test() { System.out.println("Hello"); } public static void
> main(String[] args) throws Throwable { final MethodHandle handle =
> Intrinsics.ldc(
> MethodHandleConstant.ofStatic(ClassConstant.of(MH.class), "test",
> MethodTypeConstant.of(Constables.VOID))); handle.invokeExact(); }
> }
>
> // VH.java
> import java.lang.invoke.*;
> import java.lang.invoke.Constables.*;
> import java.lang.reflect.*;
>
> public class VH {
> private static volatile int counter;
>
> private static final VarHandle COUNTER = Intrinsics.ldc(
> VarHandleConstant.ofStaticField(ClassConstant.of(VH.class),
> "counter", Constables.INT));
>
> public static void main(String[] args) {
> System.out.println(COUNTER.getAndAdd(1));
> System.out.println(COUNTER.getAndAdd(1));
> }
> }
>
> Building with "javac -XDdoConstantFold=true MH.java" or "javac
> -XDdoConstantFold=true VH.java",
> javac silently exists without producing .class file or reporting any
> error. Tried with -verbose, the output ends like this:
>
> [loading /modules/java.base/java/lang/annotation/RetentionPolicy.class]
> [loading /modules/java.base/java/lang/annotation/Target.class]
> [loading /modules/java.base/java/lang/annotation/ElementType.class]
> [checking VH]
> [loading /modules/java.base/java/io/Serializable.class]
> [loading /modules/java.base/java/lang/AutoCloseable.class]
> [loading /modules/java.base/java/lang/Class.class]
> [loading /modules/java.base/java/lang/invoke/Constable.class]
> [loading /modules/java.base/java/lang/invoke/Intrinsics.class]
> [total 1484ms]
>
> Without -XDdoConstantFold=true the class file is produced and dies like
>
> Exception in thread "main" java.lang.UnsupportedOperationException: no
> reflective access
> at java.base/java.lang.invoke.Intrinsics.ldc(Intrinsics.java:42)
> at MH.main(MH.java:12)
>
> Which is expected behavior, I guess.
>
> Am I doing something wrong? Could you compile these files on your
> side? Sorry if my tries look lame: I'm very new to this.
>
> With best regards,
> Tagir Valeev.
>
> On Tue, Apr 18, 2017 at 9:07 AM, Vicente Romero
> <vicente.romero at oracle.com <mailto:vicente.romero at oracle.com>> wrote:
>
> Hi,
>
> Support for JEP 303 has been pushed in the amber repo [1, 2]
> (branch name is 'constant-folding'). The development is mature
> although there are some fresh areas like using reflection for
> accessing the API methods. Reflection is needed as the classes
> defined in the API see [1] are not available in the boot JDK.
> There is still some ongoing research so some changes to the API
> and the code are to be expected in the near future,
>
> Thanks,
> Vicente
>
>
> [1] http://hg.openjdk.java.net/amber/amber/jdk/rev/2eeb80b82c9c
> <http://hg.openjdk.java.net/amber/amber/jdk/rev/2eeb80b82c9c>
> [2]
> http://hg.openjdk.java.net/amber/amber/langtools/rev/7be70b52c760
> <http://hg.openjdk.java.net/amber/amber/langtools/rev/7be70b52c760>
>
>
> On 04/17/2017 04:22 PM, Brian Goetz wrote:
>
> JEP 303 (Intrinsics for LDC and INVOKEDYNAMIC) is hereby
> adopted into Project Amber.
>
> A first draft of the API can be found at:
>
> http://cr.openjdk.java.net/~briangoetz/JDK-8178320/webrev/
> <http://cr.openjdk.java.net/%7Ebriangoetz/JDK-8178320/webrev/>
>
> Prototype implementation coming soon.
>
>
>
>
More information about the amber-dev
mailing list