On Jan 6, 2011, at 1:12 AM, Helmut Eller wrote:

> * John Rose [2011-01-06 02:37] writes:
> 
>> "Live constants" are definitely one of the use cases that
>> invokedynamic is designed for.
> 
> Are/will there be any means to link invokedynamic call sites eagerly
> instead of the lazy linking scheme?  
> 
> E.g. in Lisp there is this form
> 
>  (load-time-value <exp> t) 
> 
> that is essentially a constant but <exp> must be evaluated at load time
> and not later (as would be done with lazy linking).

This is an unusual pattern for the JVM, but it can be done with invokedynamic 
by pre-executing the constant-load instruction, as follows:

1. Translate the LTV form into an invokedynamic instruction.
2. Emit the invokedynamic instruction into a private static helper method.
3. Call the helper method from two places:  The intended use point, and the 
<clinit> method.

That way, class loading executes <clinit>, which then "warms up" (links) the 
invokedynamic instruction.

If you have many LTV forms in a compilation unit, this leads to many small 
helper methods, which may be inconvenient.  If that is the case, consider a 
more complex scheme where all LTV forms in a compilation unit are collected, 
and their evaluation results collected into a private static final object 
array.  Then, individual lazy-linked invokedynamic instructions can pick from 
the array..  With such a population of similar invokedynamic instructions, it 
can help (as Mark discovered) to share a common BSM and use the name field to 
send in a single simple parameter.

The most direct way to specify a parameter to a BSM for a single invokedynamic 
instruction is to specify a static argument in the BootstrapMethods attribute.  
This is a relatively new feature:

http://cr.openjdk.java.net/~jrose/pres/indy-javadoc-mlvm/java/dyn/package-summary.html#args

If the parameter is a name-string or if you don't mind decoding strings, you 
can also specify it as the name of the relevant NameAndType.

-- John
_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to