bootstrap method registration is enabled AFTER class initialization
Rémi Forax
forax at univ-mlv.fr
Fri Jun 5 12:33:32 PDT 2009
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