Difference between revisions of "DinnerAtPiatti"

From JVMLangSummit
Jump to navigationJump to search
m (New page: Friday night after the Summit, some of us who hadn't had enough yet went across the street to Piatti for dinner. Emboldened by good food and drink, some of the JSR 292 EG members (Forax, ...)
 
Line 3: Line 3:
 
Emboldened by good food and drink, some of the JSR 292 EG members (Forax, Ohrstrom, Rose, ...) worked on some hard remaining issues.  Here are the napkins to prove it.
 
Emboldened by good food and drink, some of the JSR 292 EG members (Forax, Ohrstrom, Rose, ...) worked on some hard remaining issues.  Here are the napkins to prove it.
  
[[Media:FridayDinnerNapkin1.jpg]] [[Media:FridayDinnerNapkin2.jpg]] [[Media:FridayDinnerNapkin3.jpg]] [[Media:FridayDinnerNapkin4.jpg]]
+
{|
 +
|[[Image:FridayDinnerNapkin1.jpg|160px|thumb|frameless]]
 +
|[[Image:FridayDinnerNapkin2.jpg|160px|thumb|frameless]]
 +
|[[Image:FridayDinnerNapkin3.jpg|160px|thumb|frameless]]
 +
|[[Image:FridayDinnerNapkin4.jpg|160px|thumb|frameless]]
 +
|}
 +
 
 +
==== MethodHandle sub-kernel ====
 +
 
 +
<pre>
 +
class MH {
 +
  MT type()
 +
  ? exactInvoke(?)
 +
  ? genericInvoke(?)
 +
 
 +
  MH convertArgs(MT)
 +
  MH bind(x)
 +
  MH spreadArguments()
 +
  MH collectArguments(int n)
 +
 
 +
  MH convertArgments(MT)
 +
 
 +
  "MH collectVarargs()" (maybe?)
 +
 
 +
  toString() ??
 +
  examine() ??
 +
</pre>
 +
 
 +
Change <tt>insertArgument</tt> to <tt>bind</tt> or (per Ola) <tt>prependArgument</tt>.
 +
 
 +
==== What should toString return? ====
 +
Simple answers:
 +
* Implementation-dependent
 +
* Object.toString
 +
* Current RI:  The simple-name of the target method.  (For system-defined combinators, delegates to target.toString; user-defined ones also.)  SImple and useful.
 +
 
 +
==== Calling Sequences ====
 +
 
 +
MH.genericInvoke does autoboxing.  Can result in an OOM error.  The JVM can make the adapter non-blocking, by preallocating all the boxing memory in advance (in thread-local buffer) before advancing into the call.  If the allocation fails, the call site is restarted after GC.
 +
 
 +
<pre>// virtual call through vtable:
 +
mov [obj] -> ecx
 +
call [ecx+off]
 +
</pre>
 +
 
 +
<pre>// mh call through vtable:
 +
mov [obj] -> ecx
 +
mov [obj+6] -> edx
 +
call [ecx+edx]
 +
</pre>
 +
 
 +
==== Java Method Handles ====
 +
 
 +
<pre>
 +
class Foo extends JavaMethodHandle {
 +
  Foo() { super(#myInvoke); }
 +
  void myInvoke() { ... }
 +
}
 +
</pre>
 +
 
 +
==== Constant Pool Constants ====
 +
Should be for MT and four kinds of MH:  virtual/interface, static, special.
 +
 
 +
Idea:  Have the constant pool format for CONSTANT_MethodHandle be parameterized by (a) a member reference, and (b) a bytecode point (invokespecial, etc.).  Makes clear the correspondence between the symbolic reference and the semantics of the resulting method handle.  This also extends naturally to all other symbolic references:
 +
* invokevirtual, CONSTANT_Methodref = findVirtual (must be class)
 +
* invokeinterface, CONSTANT_InterfaceMethodref = findVirtual (must be interface)
 +
* invokestatic, CONSTANT_Methodref = findStatic
 +
* invokespecial, CONSTANT_Methodref = findSpecial
 +
* getfield, CONSTANT_Fieldref = unreflectGetter (must be non-static)
 +
* getstatic, CONSTANT_Fieldref = unreflectGetter (must be static)
 +
* putfield, CONSTANT_Fieldref = unreflectSetter (must be non-static)
 +
* putstatic, CONSTANT_Fieldref = unreflectSetter (must be static)

Revision as of 15:05, 24 September 2009

Friday night after the Summit, some of us who hadn't had enough yet went across the street to Piatti for dinner.

Emboldened by good food and drink, some of the JSR 292 EG members (Forax, Ohrstrom, Rose, ...) worked on some hard remaining issues. Here are the napkins to prove it.

frameless
frameless
frameless
frameless

MethodHandle sub-kernel

class MH {
  MT type()
  ? exactInvoke(?)
  ? genericInvoke(?)
  
  MH convertArgs(MT)
  MH bind(x)
  MH spreadArguments()
  MH collectArguments(int n)

  MH convertArgments(MT)

  "MH collectVarargs()" (maybe?)

  toString() ??
  examine() ??

Change insertArgument to bind or (per Ola) prependArgument.

What should toString return?

Simple answers:

  • Implementation-dependent
  • Object.toString
  • Current RI: The simple-name of the target method. (For system-defined combinators, delegates to target.toString; user-defined ones also.) SImple and useful.

Calling Sequences

MH.genericInvoke does autoboxing. Can result in an OOM error. The JVM can make the adapter non-blocking, by preallocating all the boxing memory in advance (in thread-local buffer) before advancing into the call. If the allocation fails, the call site is restarted after GC.

// virtual call through vtable:
mov [obj] -> ecx
call [ecx+off]
// mh call through vtable:
mov [obj] -> ecx
mov [obj+6] -> edx
call [ecx+edx]

Java Method Handles

class Foo extends JavaMethodHandle {
  Foo() { super(#myInvoke); }
  void myInvoke() { ... }
}

Constant Pool Constants

Should be for MT and four kinds of MH: virtual/interface, static, special.

Idea: Have the constant pool format for CONSTANT_MethodHandle be parameterized by (a) a member reference, and (b) a bytecode point (invokespecial, etc.). Makes clear the correspondence between the symbolic reference and the semantics of the resulting method handle. This also extends naturally to all other symbolic references:

  • invokevirtual, CONSTANT_Methodref = findVirtual (must be class)
  • invokeinterface, CONSTANT_InterfaceMethodref = findVirtual (must be interface)
  • invokestatic, CONSTANT_Methodref = findStatic
  • invokespecial, CONSTANT_Methodref = findSpecial
  • getfield, CONSTANT_Fieldref = unreflectGetter (must be non-static)
  • getstatic, CONSTANT_Fieldref = unreflectGetter (must be static)
  • putfield, CONSTANT_Fieldref = unreflectSetter (must be non-static)
  • putstatic, CONSTANT_Fieldref = unreflectSetter (must be static)