Error in sequence initialisation of Lookup

Rémi Forax forax at univ-mlv.fr
Fri Jun 5 01:31:15 PDT 2009


This program throw an Internal Error

import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;

public class MethodHandleInvocationTest {
  public static void sayHello(String message) {
      System.out.println("hello " + message);
  }
    
  public static void main(String[] args) {
    MethodHandle mh = 
MethodHandles.Lookup.PUBLIC_LOOKUP.findStatic(MethodHandleInvocationTest.class,
            "sayHello", MethodType.make(void.class, String.class));
    
    mh.<void>invoke("jsr 292 backport");
  }
}

Exception in thread "main" java.lang.InternalError
    at sun.dyn.MethodHandleImpl.<clinit>(MethodHandleImpl.java:112)
    at java.dyn.MethodHandles.<clinit>(MethodHandles.java:66)
    at java.dyn.MethodHandles$Lookup.<clinit>(MethodHandles.java:158)
    at MethodHandleInvocationTest.main(MethodHandleInvocationTest.java:11)

I use the jdkb59 here,
but the current mlvm repository patch seems to exhibit the same problem.

MethodHandles$Lookup static init calls MethodHandles.<clinit>
but *before* the call to initLookup(), the class MethodHandleImpl need 
to be initialized,
so its <clinit> is called and raise the InternalError.

static final Lookup IMPL_LOOKUP = new Lookup(null);
static { MethodHandleImpl.initLookup(IMPL_TOKEN, IMPL_LOOKUP);

A simple patch, even if it doesn't solve the real problem is to
change the visibility of the constant PUBLIC_LOOKUP in Lookup
and to provide an access through a method in MethodHandles

public static Lookup lookup() {
  return new Lookup();
}

public static Lookup publicLookup() {
  return Lookup.PUBLIC_LOOKUP;
}

cheers,
Rémi





More information about the mlvm-dev mailing list