bootstrap method registration is enabled AFTER class initialization

John Rose John.Rose at Sun.COM
Fri Jun 5 12:54:05 PDT 2009


Thanks, Yuri; that's a good negative test.

The problem with allowing that BSM registration is that racing threads  
can attempt to use indy sites before a BSM is installed.  It's minor  
problem, arguably the user's fault not ours, but I think it's both  
harmless and helpful to require the BSM to be present by the end of  
initialization.

It does mean that an external class B cannot easily assign a method of  
a class A as A's own BSM, unless the action is somehow taken during  
the course of A's <clinit> execution.  (This can be worked around.   
The problem is probably typical of coding with <clinit> effects.)

Remi, the issue of when CallSites is built is separable; a given call  
site can be built (logically) any time >= BSM installation and <= its  
first execution.  I'll make an issue for this:

ISSUE CALL-SITE-CONSTRUCTION-PHASE: A call site can (with logical  
consistency) be built any time after registration of the BSM and  
before the first execution of its instruction.  Shall the  
specification (a) require that call sites are created as late as  
possible, or (b) make no guarantee about when they are created?


-- John

On Jun 5, 2009, at 12:33 PM, Rémi Forax wrote:

> Yuri Gaevsky a écrit :
>> Hi John,
>>
> Hi, Yuri,
> the current implementation of invokedynamic is really dynamic :)
> And as far as I know, the expert group has not decided
> if this program is legal or not.
>
> For the record, the problem with this kind of program is that
> bsm() can be called more that once by  mutiple threads
> and there is no way to know which CallSite object
> will be chosen by the VM among the multiple created
> for one call site.
>
> If Linkage.registerBootstrapMethod is called before
> the end of the static init, the creation of the CallSite objects
> can be done  under the lock used to execute the static init method.
>
> Rémi
>
>> The following program:
>>
>> --- LinkageTest.java ---
>> import java.dyn.*;
>> import java.io.*;
>>
>>
>> public class LinkageTest {
>>     public static void main(String[] argv) {
>>         System.exit(run(argv, System.out));
>>     }
>>
>>     public static int run(String[] argv, PrintStream out) {
>>         Linkage.registerBootstrapMethod("bsm");
>>         InvokeDynamic.<void>dm();
>>         out.println("OKAY");
>>         return 0;
>>     }
>>
>>     public static void m() {
>>         System.out.print("m() ");
>>         return;
>>     }
>>
>>     private static CallSite bsm(Class caller, String name,  
>> MethodType type) {
>>         MethodHandle target = MethodHandles.lookup().findStatic(
>>                 LinkageTest.class, "m", MethodType.make(void.class));
>>         CallSite site = new CallSite(caller, name, type);
>>         site.setTarget(target);
>>         return site;
>>     }
>> }
>> --- LinkageTest.java ---
>>
>> doesn't throw any exceptions under jdk7-b59:
>>
>> $ java -XX:+EnableInvokeDynamic -XX:+EnableMethodHandles LinkageTest
>> m() OKAY
>>
>> That looks like a bug.
>>
>> Regards,
>> -Yuri
>> _______________________________________________
>> 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