Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak module initialization to comply with JVM spec
Dmitry learned that we've been relying on a bug in the verifier that will be fixed in JDK 9 under the new classfile format. Assignment to a static final must occur lexically within the <clinit>. We were performing this assignment from the constructor of the module class. This commit moves the assignment to <clinit>. Before: ``` public final class O$ { public static final O$ MODULE$; public static {}; Code: 0: new #2 // class O$ 3: invokespecial #12 // Method "<init>":()V 6: return private O$(); Code: 0: aload_0 1: invokespecial #13 // Method java/lang/Object."<init>":()V 4: aload_0 5: putstatic #15 // Field MODULE$:LO$; 8: return } ``` After: ``` public final class O$ { public static final O$ MODULE$; public static {}; Code: 0: new #2 // class O$ 3: dup 4: invokespecial #12 // Method "<init>":()V 7: putstatic #14 // Field MODULE$:LO$; 10: return private O$(); Code: 0: aload_0 1: invokespecial #15 // Method java/lang/Object."<init>":()V 4: return } ``` The difference is observable is the constructor is called a second time with reflection/setAccessible. That used to overwrite the `MODULE$` field. I think few would argue that the new semantics are a clear improvement.
- Loading branch information