compiler accepts incompatible method reference for Sam conversion
maurizio cimadamore
maurizio.cimadamore at oracle.com
Sat Jul 16 04:26:13 PDT 2011
On 16/07/2011 08:59, Ali Ebrahimi wrote:
> Hi,
> for me this still crash with full lambda repo build.
> The main reason for this, i think, is that hotspot sub-repo of lambda
> repository is not sync with jdkb147(currently, latest tag is jdkb143).
Yeah - I noticed the weird tag in hotspot - I merged it against the JDK
8 repo, which seems to have the same problem (all subrepos have b147 tag
but hotspot, which has b143).
I will investigate about this.
Maurizio
>
> Best Regards,
> Ali Ebrahimi
>
> On Wed, Jul 13, 2011 at 1:22 PM, Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>
> Ali,
> this works for me (using b147 - or the VM bundled in the lambda
> repo). There have been tons of fixes in the MH area lately, so
> make sure you grab a more recent JDK 7 snapshot (I used to see
> those problems too before the latest lambda merge, but now ost of
> them went away).
>
> Note also that, in cases in which 292 code is still unstable, you
> can switch back to the old generation logic using the -XDuseProxy
> flag, which should remove all 292-related problems (as, by doing
> so, java.lang.reflect.Proxy will be used instead).
>
> I will be pushing a fix for the other issue (incompatible method
> ref erroneously accepted by javac) shortly.
>
> Thanks
> Maurizio
>
>
> On 13/07/11 10:36, Ali Ebrahimi wrote:
>
> Hi Remi,
>
> On 7/13/11, Rémi Forax<forax at univ-mlv.fr
> <mailto:forax at univ-mlv.fr>> wrote:
>
> On 07/13/2011 06:01 AM, Ali Ebrahimi wrote:
>
> Hi Ali,
>
> ...
>
> MethodHandle mh =
> MethodHandles.lookup().findStatic(MethodHandleTest.class,
> "sTest",
> MethodType.methodType(void.class,int.class,int.class));
> MethodHandle smh = mh.asSpreader(Object[].class,
> mh.type().parameterCount());
>
> smh.invoke(new Object[]{i,i});<===============crash
>
> main cause: mh.asSpreader
>
> I don't known this crash appears in jdkb147.
>
> What you want here is to use asCollector, not asSpreader.
> asSpreader requires that the method as already an object array
> and extract the value from it.
>
> May be i'm wrong. but this code picked from
> MethodHandleProxies class
>
> public static
> <T> T asInterfaceInstance(final Class<T> intfc, final
> MethodHandle target) {
> final Method sm = getSingleMethod(intfc);
> if (sm == null)
> throw new IllegalArgumentException("not a
> single-method
> interface: "+intfc.getName());
> MethodType smMT =
> MethodType.methodType(sm.getReturnType(),
> sm.getParameterTypes());
> MethodHandle checkTarget = target.asType(smMT); //
> make throw WMT
> checkTarget =
> checkTarget.asType(checkTarget.type().changeReturnType(Object.class));
> final MethodHandle vaTarget =
> checkTarget.asSpreader(Object[].class, smMT.parameterCount());
> return intfc.cast(Proxy.newProxyInstance(
> intfc.getClassLoader(),
> new Class[]{ intfc, WrapperInstance.class },
> new InvocationHandler() {
> private Object getArg(String name) {
> if ((Object)name ==
> "getWrapperInstanceTarget") return target;
> if ((Object)name ==
> "getWrapperInstanceType")
> return intfc;
> throw new AssertionError();
> }
> public Object invoke(Object proxy, Method
> method,
> Object[] args) throws Throwable {
> if (method.getDeclaringClass() ==
> WrapperInstance.class)
> return getArg(method.getName());
> if (method.equals(sm))
> return vaTarget.invokeExact(args);
> if (isObjectMethod(method))
> return callObjectMethod(this,
> method, args);
> throw new InternalError();
> }
> }));
> }
>
> and this results in this crash:
> class MethodHandleTest{
> ...
> public static void sTest(int x,int y){
> // System.out.println("stest");
> }
>
> static interface Sam{
> void m(int x,int y);
> }
> ..
> Sam sam = MethodHandleTest#sTest;
> sam.m(1,1);<==========
>
> In your example, the call to mh.asSpreader should return a
> runtime
> exception,
> I will investigate why it's not the case when I will be at
> my office :)
>
> Best Regards,
> Ali Ebrahimi
>
> regards,
> Rémi
>
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net <mailto:mlvm-dev at openjdk.java.net>
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
> Best Regards,
> Ali Ebrahimi
>
>
>
More information about the lambda-dev
mailing list