On Dec 28, 2010, at 1:53 PM, Rémi Forax wrote:

> We, the JSR292 EG, think that most of the VMs will be able to optimize this.

Thanks for answering Mark's question so fully, Remi.

"Live constants" are definitely one of the use cases that invokedynamic is 
designed for.

The design is a little indirect:  You bind a call site permanently to a K 
combinator, which always returns your desired value.

(The K combinator is K(x) := lambda(){x}.  See 
http://en.wikipedia.org/wiki/SKI_combinator_calculus .)

But the design is also general:  An invokedynamic call site can take arguments.

This opens the door to "almost constant" values.  Many languages feature 
templated value constructors, in which most of the constructor expression is a 
constant template, with little bits of inserted data.

   Shell:  "foo $x bar 12"
   Lisp:  `(foo ,x bar 12)
   JavaScript:  {foo: x, bar: 12}
   Java+Lambda: {PrintStream out -> out.println("foo "+x+" bar 12")}

In all the above cases, a variable value x is stuffed into the middle of a 
mostly-constant value (string, quasiquoted list, object literal, closure, 
respectively).

Invokedynamic allows you a hook to pass the constant parts of the template as 
bootstrap method parameters, and the non-constant parts as normal stacked 
invocation parameters.  The bootstrap method is responsible for spinning a 
factor method which will take the non-constant parts and build the requested 
patterned value.  There are lots of interesting language-specific optimizations 
possible here.

>From this viewpoint, a "live constant" is simply a zero-argument templated 
>value, and the K combinator is its constructor.

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

Reply via email to