This isn't a bad rule of thumb, but I'd add a caveat:

* If you know one concrete shape will always fit the execution, emit
the bytecode IFF it's of a reasonable size

Because method handles can blur the lines between methods and dodge
some JVM inlining/optimization thresholds, they're often useful for
encapsulating nontrivial logic that would bloat up a method body. For
example, if you have a lot of pre/post setup for a given call or you
have a more complicated expression you want to run as a unit
repeatedly, you might be better off shoving that into handles and
letting the JVM decide what to inline. Emitting the bytecode in-place
is basically like hand inlining...to be used with caution.

- Charlie

On Mon, May 28, 2012 at 12:45 PM, Attila Szegedi <szege...@gmail.com> wrote:
> My rule of thumb is: if you know that one concrete code shape will
> always fit the execution, I'd just emit the bytecode. Invokedynamic is
> great for cases where the executed code needs to change from time to
> time. You can also combine it - the invocation of actual property
> getters "getA()", "getB()" etc. are invokeDynamic linked, and the
> branching is in bytecode; i.e. if you know that the sequence at that
> point in the code will always be "a.b.c.d".
>
> Attila.
>
> On Sun, May 27, 2012 at 11:12 AM, Dain Sundstrom <d...@iq80.com> wrote:
>> Hi all,
>>
>> I have a general strategy question about using invoke dynamic.  Say I have a 
>> dynamic language that has null safe property chaining where "a.b.c.d" 
>> results in null if a null is encountered anywhere in the chain.  I could 
>> implement this two ways, 1) generate byte code that checks for nulls or 2) 
>> use a guarded method handle at each step that takes care of the nulls.  
>> Either option is ok with me, but I'd rather not write both versions to and 
>> then try to figure out which one will make the JVM angry.
>>
>> As a broader question, there are lots of places where I can make this type 
>> of decision (e.g., pass by value parameters, copy on assignment value 
>> classes), is there a rule of thumb for going with traditional byte code over 
>> branching method handles?
>>
>> Thanks,
>>
>> -dain
>> _______________________________________________
>> mlvm-dev mailing list
>> mlvm-dev@openjdk.java.net
>> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev@openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to