ART: Additional initialization for MethodHandle accessors.
Ensure classes are initialized before static fields are touched by
MethodHandle setters and getters.
Bug: 30550796
Test: m test-art-host-run-test-979-invoke-polymorphic-accessors
Change-Id: Ibac4372607ecbb4e6f7347b89cef6d280632c835
diff --git a/test/979-invoke-polymorphic-accessors/src/Main.java b/test/979-invoke-polymorphic-accessors/src/Main.java
index 6cdcd10..8f1e361 100644
--- a/test/979-invoke-polymorphic-accessors/src/Main.java
+++ b/test/979-invoke-polymorphic-accessors/src/Main.java
@@ -683,10 +683,20 @@
public static class FindAccessorTester {
public static void main() throws Throwable {
- ValueHolder valueHolder = new ValueHolder();
+ // NB having a static field test here is essential for
+ // this test. MethodHandles need to ensure the class
+ // (ValueHolder) is initialized. This happens in the
+ // invoke-polymorphic dispatch.
MethodHandles.Lookup lookup = MethodHandles.lookup();
-
- lookup.findStaticGetter(ValueHolder.class, "s_fi", int.class);
+ try {
+ MethodHandle mh = lookup.findStaticGetter(ValueHolder.class, "s_fi", int.class);
+ int initialValue = (int)mh.invokeExact();
+ System.out.println(initialValue);
+ } catch (NoSuchFieldException e) { unreachable(); }
+ try {
+ MethodHandle mh = lookup.findStaticSetter(ValueHolder.class, "s_i", int.class);
+ mh.invokeExact(0);
+ } catch (NoSuchFieldException e) { unreachable(); }
try {
lookup.findStaticGetter(ValueHolder.class, "s_fi", byte.class);
unreachable();
@@ -721,6 +731,8 @@
}
public static void main(String[] args) throws Throwable {
+ // FindAccessor test should be the first test class in this
+ // file to ensure class initialization test is run.
FindAccessorTester.main();
InvokeExactTester.main();
}