On Jul 19, 2012, at 7:04 PM, Dain Sundstrom wrote:
> I have some code that tries to get the value of a static final field using a
> MethodHandle, and I find that the field is null because the class isn't
> initialized. Is calling a method handle supposed to cause a class to
> initialize (run the <clinit> method)?
Yes, the behavior of findStaticGetter is based on the getstatic bytecode, which
includes (as you expected) the initialization barrier. Same point for
putstatic and invokestatic, and REF_newInvokeSpecial (combination of new +
<init>).
The JDK 7 implementation has bugs regarding some of these guys. The upcoming
integration of "lazy method handles" includes complete coverage for these
initialization paths.
> In a related question, what is the best way to force initialization and when
> do you do the initialization? in the bootstrap method?
The best way to force initialization of a class is to fetch a static field or
call a static method. You can do this with reflection, or (if the above bugs
are fixed) via method handles. You can also allocate an instance of the class.
— John
_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev