5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.core.test;
24
25 import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID;
26 import static org.graalvm.compiler.debug.DelegatingDebugConfig.Feature.INTERCEPT;
27
28 import java.lang.reflect.Method;
29
30 import jdk.vm.ci.meta.MetaAccessProvider;
31 import jdk.vm.ci.meta.ResolvedJavaMethod;
32
33 import org.junit.Assume;
34 import org.junit.Test;
35
36 import org.graalvm.compiler.api.test.Graal;
37 import org.graalvm.compiler.debug.Debug;
38 import org.graalvm.compiler.debug.DebugConfigScope;
39 import org.graalvm.compiler.debug.DelegatingDebugConfig;
40 import org.graalvm.compiler.java.GraphBuilderPhase;
41 import org.graalvm.compiler.nodes.StructuredGraph;
42 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
43 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
44 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
45 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
46 import org.graalvm.compiler.phases.OptimisticOptimizations;
47 import org.graalvm.compiler.phases.PhaseSuite;
48 import org.graalvm.compiler.phases.VerifyPhase;
49 import org.graalvm.compiler.phases.tiers.HighTierContext;
50 import org.graalvm.compiler.phases.util.Providers;
51 import org.graalvm.compiler.runtime.RuntimeProvider;
52 import org.graalvm.compiler.test.GraalTest;
53
54 /**
55 * Test that interfaces are correctly initialized by a static field resolution during eager graph
56 * building.
57 */
58 public class StaticInterfaceFieldTest extends GraalTest {
59
60 private interface I {
61 Object CONST = new Object() {
62 };
63
64 }
65
66 private static final class C implements I {
67 @SuppressWarnings({"static-method", "unused"})
68 public Object test() {
69 return CONST;
70 }
71 }
72
75 eagerlyParseMethod(C.class, "test");
76
77 }
78
79 @SuppressWarnings("try")
80 private void eagerlyParseMethod(Class<C> clazz, String methodName) {
81 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
82 Providers providers = rt.getHostBackend().getProviders();
83 MetaAccessProvider metaAccess = providers.getMetaAccess();
84
85 PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
86 Plugins plugins = new Plugins(new InvocationPlugins(metaAccess));
87 GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
88 graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
89 HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
90
91 Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
92
93 final Method m = getMethod(clazz, methodName);
94 ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
95 StructuredGraph graph = new StructuredGraph(method, AllowAssumptions.NO, INVALID_COMPILATION_ID);
96 try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("GraphBuilding", graph, method)) {
97 graphBuilderSuite.apply(graph, context);
98 } catch (Throwable e) {
99 throw Debug.handle(e);
100 }
101 }
102 }
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.core.test;
24
25 import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
26 import static org.graalvm.compiler.debug.DelegatingDebugConfig.Feature.INTERCEPT;
27
28 import java.lang.reflect.Method;
29
30 import org.graalvm.compiler.api.test.Graal;
31 import org.graalvm.compiler.debug.Debug;
32 import org.graalvm.compiler.debug.DebugConfigScope;
33 import org.graalvm.compiler.debug.DelegatingDebugConfig;
34 import org.graalvm.compiler.java.GraphBuilderPhase;
35 import org.graalvm.compiler.nodes.StructuredGraph;
36 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
37 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
38 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
39 import org.graalvm.compiler.phases.OptimisticOptimizations;
40 import org.graalvm.compiler.phases.PhaseSuite;
41 import org.graalvm.compiler.phases.VerifyPhase;
42 import org.graalvm.compiler.phases.tiers.HighTierContext;
43 import org.graalvm.compiler.phases.util.Providers;
44 import org.graalvm.compiler.runtime.RuntimeProvider;
45 import org.graalvm.compiler.test.GraalTest;
46 import org.junit.Assume;
47 import org.junit.Test;
48
49 import jdk.vm.ci.meta.MetaAccessProvider;
50 import jdk.vm.ci.meta.ResolvedJavaMethod;
51
52 /**
53 * Test that interfaces are correctly initialized by a static field resolution during eager graph
54 * building.
55 */
56 public class StaticInterfaceFieldTest extends GraalTest {
57
58 private interface I {
59 Object CONST = new Object() {
60 };
61
62 }
63
64 private static final class C implements I {
65 @SuppressWarnings({"static-method", "unused"})
66 public Object test() {
67 return CONST;
68 }
69 }
70
73 eagerlyParseMethod(C.class, "test");
74
75 }
76
77 @SuppressWarnings("try")
78 private void eagerlyParseMethod(Class<C> clazz, String methodName) {
79 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
80 Providers providers = rt.getHostBackend().getProviders();
81 MetaAccessProvider metaAccess = providers.getMetaAccess();
82
83 PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
84 Plugins plugins = new Plugins(new InvocationPlugins(metaAccess));
85 GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
86 graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
87 HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
88
89 Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
90
91 final Method m = getMethod(clazz, methodName);
92 ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
93 StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
94 try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("GraphBuilding", graph, method)) {
95 graphBuilderSuite.apply(graph, context);
96 } catch (Throwable e) {
97 throw Debug.handle(e);
98 }
99 }
100 }
|