Bootstrap method question

Rémi Forax forax at univ-mlv.fr
Sat Jun 19 04:00:38 PDT 2010


Le 19/06/2010 08:40, Howard Lovatt a écrit :
> @Rémi,
>
> Thanks for the advise about using a "slowPath" method to discover the
> runtime types. I have coded up something along the lines you
> suggested:
>
>    private static double slowPath( final CallSite callSite, final
> CostCalculator cC, final Item i ) throws Throwable {
>      System.out.println("callSite = " + callSite + ", CostCalculator =
> " + cC + ", i = " + i );
>      final MethodHandle nearest = Dispatchers.nearest( mhs.values(),
> double.class, cC, i );
>      System.out.println( "nearest = " + Dispatchers.toString( nearest ) );
>      final MethodHandle converted = MethodHandles.collectArguments(
> nearest, callSite.getTarget().type() );
>      System.out.println( "converted = " + Dispatchers.toString( converted ) );
>      callSite.setTarget( converted );
>      return converted.<double>invokeExact( cC, i );
>    }
>
> When run I get the following:
>
> callSite = CallSite#29596205[from invokedynamicmultipledispatch.Cost :
> (invokedynamicmultipledispatch.CostCalculator,invokedynamicmultipledispatch.Item)double
> =>  slowPath], CostCalculator =
> invokedynamicmultipledispatch.Price at bf2d5e, i =
> [Ljava.lang.Object;@13bad12
> Exception in thread "main"
> invokedynamicmultipledispatch.MultipleDispatchException
>          at invokedynamicmultipledispatch.Cost.cost(Cost.java:62)
>          at invokedynamicmultipledispatch.Cost.main(Cost.java:51)
> Caused by: invokedynamicmultipledispatch.MultipleDispatchException:
> Cannot find type,
> (invokedynamicmultipledispatch.Price,java.lang.Object[])double,
> compatible method in,
> [cost(invokedynamicmultipledispatch.Postage,invokedynamicmultipledispatch.CD)double,
> cost(invokedynamicmultipledispatch.CostCalculator,invokedynamicmultipledispatch.Item)double,
> cost(invokedynamicmultipledispatch.Price,invokedynamicmultipledispatch.Book)double,
> cost(invokedynamicmultipledispatch.Price,invokedynamicmultipledispatch.CD)double,
> cost(invokedynamicmultipledispatch.Postage,invokedynamicmultipledispatch.Book)double]
>          at invokedynamicmultipledispatch.Dispatchers.nearest(Dispatchers.java:182)
>          at invokedynamicmultipledispatch.Dispatchers.nearest(Dispatchers.java:145)
>          at invokedynamicmultipledispatch.CostCalculatorDispatcher.slowPath(CostCalculatorDispatcher.java:35)
>          at sun.dyn.FromGeneric$A2.invoke_D2(FromGeneric.java:534)
>          at sun.dyn.FilterGeneric$F2.invoke_C1(FilterGeneric.java:550)
>          at sun.dyn.ToGeneric$A2.target(ToGeneric.java:661)
>          at sun.dyn.ToGeneric$A2.targetA2(ToGeneric.java:662)
>          at sun.dyn.ToGeneric$A2.invoke_D(ToGeneric.java:671)
>          at invokedynamicmultipledispatch.Cost.cost(Cost.java:60)
>          ... 1 more
>
> The interesting bit is "i = [Ljava.lang.Object;@13bad12" on the first
> line of the printout (ignoring wrapping). This Object[] contains 1
> element, the expected Item. What is not expected is wrapping this in
> an array. Also this is a type unsafe at runtime since an array is
> passed into a method in a position where an Item is coded.
>
> Any idea what is going on?
>
>    -- Howard.
>    

And what is the code of the bootstrap method ?

Rémi


More information about the mlvm-dev mailing list