need little help for class loading & invokeDynamics
Marvin Hansen
marvin.hansen at gmail.com
Fri Jan 14 13:54:32 PST 2011
Thank you Rémi, you've saved my day,
and sorry for the typo...
yes it was the signature mis-match and finally,
Object alg = loadedClaZZ.newInstance();
Object o = methodHandle.invokeWithArguments(alg, 21, "+", 21);
is doing the job for me, so it's working now:-)
again, thanks for all your help.
marvin
http://www.marvin-hansen.tel
On 14 January 2011 22:37, Rémi Forax <forax at univ-mlv.fr> wrote:
> On 01/14/2011 09:59 AM, Marvin Hansen wrote:
>> Thansk you Rene,
>
> I think i prefer Rémi or Rémy.
>
> run is declared (int,int,String) and you lookup (int,String,int).
>
> Also the line:
> methodHandle.invokeWithArguments(21, "+", 21);
> will raise a runtime exception because you forget to pass an instance of
> SimpleMath
> as first argument (run is not static).
>
> Rémi
>
>> visibility is not an issue, since both class& method are declared
>> public and a normal static call works just fine. I'm sorry
>> I've forgotten to add the simpleMath source but for the sake of
>> completeness I've copied the class
>> at the bottom of the mail.
>>
>> However, it looks much more that I've run into the problem that java
>> cannot directly emit invokedynamic.
>> I understant that the main purpose for invokedynamic was and still is
>> the support of dynamic languages but
>> this limitation seams arbitrary for me. Is there any intention to
>> change it or is that the way invokedynamic should
>> be released?
>>
>> Anyway, thanks for the link I will read it carefully and hopefully I
>> will find a work-around to do an
>> invokedynamic call from my loaded class.
>>
>> Thanks for your helpful advice;
>>
>>
>>
>>
>>
>> public class SimpleMath {
>>
>> public SimpleMath() {
>> }
>>
>> /**
>> * @param a
>> * @param b
>> * @param op
>> * @return int
>> */
>> public int run(int a, int b, String op) {
>>
>> int returnvalue = calculate(a, b, op);
>>
>> return returnvalue;
>> }
>>
>>
>> private int calculate(int a, int b, String op) {
>>
>> int ret = null;
>>
>> switch (op) {
>> case "+":
>> ret = a + b;
>> break;
>> case "-":
>> ret = a - b;
>> break;
>> case "/":
>> ret = a / b;
>> break;
>> case "*":
>> ret = a * b;
>> break;
>> default:
>> System.err.println("No valid paramter given. Use
>> only : '+' ; '-' ; '/' ; '*' (String)
>> as operator and
>> interger as numbers");
>> break;
>> }
>> }
>>
>>
>>
>> http://www.marvin-hansen.tel
>>
>>
>>
>>
>> On 14 January 2011 21:04, Rémi Forax<forax at univ-mlv.fr> wrote:
>>> On 01/14/2011 06:15 AM, Marvin Hansen wrote:
>>>> Hi Folks,
>>>>
>>>> I've started to work on invokeDynamics but I need a little help to
>>>> understand how to use it right. For learning purpose, I've written a
>>>> little class, that loads another class, does the method look-up and
>>>> (should) execute the located method. The example in the methodHandle
>>>> JavaDoc was my starting point but as usual it's not that easy since it
>>>> works well for JDK classes but not with loading my own class which
>>>> causes a “NoAccessException”.
>>>>
>>>> I suppose that I need to deal with CallSite& Bootstraping but I've
>>>> not yet figured out how to patch class-loading, methodHandle,
>>>> Bootstraping& invocation together in order to make it work. The
>>>> JavaDoc says, that before an invokedynamic instruction can be executed
>>>> a CallSite must be linked via boostrap method that produces a
>>>> methodHandle. That makes sense for me.
>>>>
>>>> However, the CallSite JavaDoc is a little bit short on illustrating
>>>> how to use it together with class-loading.
>>>> The given example bootstrap Method:
>>>>
>>>> private static CallSite bootstrapDynamic(MethodHandles.Lookup caller,
>>>> String name, MethodType type) {
>>>> // ignore caller and name, but match the type:
>>>> return new ConstantCallSite(MethodHandles.collectArguments(printArgs, type));
>>>> }
>>>>
>>>> looks fine but this method is neither used nor linked or registered
>>>> in the sample code of the JavaDoc so here are my related questions:
>>>>
>>>> 1) What is needed in a bootstrap method to produce a working callSite
>>>> for a loaded class?
>>>>
>>>> 2) How is the bootstrap method linked to an invokedynamic instruction?
>>>> The spec does not have the @BootstrapMethod anymore so what's the
>>>> current way of linking?
>>> The bootstrap method is know encoded as argument of the invokedynamic
>>> instruction.
>>> So each invokedynamic can have its own bootstrap method.
>>>
>>> The main problem is that there is no way currently to emit an
>>> invokedynamic in Java,
>>> see
>>> http://weblogs.java.net/blog/forax/archive/2011/01/07/call-invokedynamic-java
>>>
>>>> 3) Should the class-loading be done by the bootstrap method or is it
>>>> fine to do it before?
>>> Fine to do it before.
>>>
>>>> I really appriciate any input, since I'm new to InvokeDynamics and not
>>>> familiar with all concepts.
>>>>
>>>> marvin
>>> Rémi
>>> _______________________________________________
>>> mlvm-dev mailing list
>>> mlvm-dev at openjdk.java.net
>>> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>>>
>> _______________________________________________
>> mlvm-dev mailing list
>> mlvm-dev at openjdk.java.net
>> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
More information about the mlvm-dev
mailing list