1 /*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
24
25 package org.graalvm.compiler.hotspot.test;
26
27 import org.graalvm.compiler.core.test.GraalCompilerTest;
28 import org.graalvm.compiler.hotspot.meta.HotSpotClassInitializationPlugin;
29 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
30 import org.graalvm.compiler.hotspot.phases.aot.EliminateRedundantInitializationPhase;
31 import org.graalvm.compiler.nodes.StructuredGraph;
32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
34 import org.graalvm.compiler.phases.tiers.HighTierContext;
35 import org.junit.Assert;
36 import org.junit.Test;
37
38 public class EliminateRedundantInitializationPhaseTest extends GraalCompilerTest {
39 @Override
40 protected Plugins getDefaultGraphBuilderPlugins() {
41 Plugins plugins = super.getDefaultGraphBuilderPlugins();
42 plugins.setClassInitializationPlugin(new HotSpotClassInitializationPlugin());
43 return plugins;
44 }
45
46 public static class X {
47 public static int x;
48 public static int y;
49 public static int z;
50 }
51
52 public static class Y extends X {
53 public static int a;
54 public static int b;
55 }
56
57 public static void assignFields() {
58 X.x = 1;
59 X.y = 2;
60 X.z = 3;
61 }
62
202 test("assignFieldsInLoop", 4, 1);
203 }
204
205 @Test
206 public void test9() {
207 test("assignFieldsInBranches", 3, 2);
208 }
209
210 @Test
211 public void test10() {
212 test("assignFieldsInBranchesMixed", 3, 2);
213 }
214
215 @Test
216 public void test11() {
217 test("invokestatic", 1, 0);
218 }
219
220 @Test
221 public void test12() {
222 test("invokestaticInlined", 1, 1);
223 }
224 }
|
1 /*
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
24
25 package org.graalvm.compiler.hotspot.test;
26
27 import org.graalvm.compiler.core.test.GraalCompilerTest;
28 import org.graalvm.compiler.hotspot.meta.HotSpotAOTClassInitializationPlugin;
29 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
30 import org.graalvm.compiler.hotspot.phases.aot.EliminateRedundantInitializationPhase;
31 import org.graalvm.compiler.nodes.StructuredGraph;
32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
34 import org.graalvm.compiler.phases.tiers.HighTierContext;
35 import org.junit.Assert;
36 import org.junit.Test;
37
38 public class EliminateRedundantInitializationPhaseTest extends GraalCompilerTest {
39 @Override
40 protected Plugins getDefaultGraphBuilderPlugins() {
41 Plugins plugins = super.getDefaultGraphBuilderPlugins();
42 plugins.setClassInitializationPlugin(new HotSpotAOTClassInitializationPlugin());
43 return plugins;
44 }
45
46 public static class X {
47 public static int x;
48 public static int y;
49 public static int z;
50 }
51
52 public static class Y extends X {
53 public static int a;
54 public static int b;
55 }
56
57 public static void assignFields() {
58 X.x = 1;
59 X.y = 2;
60 X.z = 3;
61 }
62
202 test("assignFieldsInLoop", 4, 1);
203 }
204
205 @Test
206 public void test9() {
207 test("assignFieldsInBranches", 3, 2);
208 }
209
210 @Test
211 public void test10() {
212 test("assignFieldsInBranchesMixed", 3, 2);
213 }
214
215 @Test
216 public void test11() {
217 test("invokestatic", 1, 0);
218 }
219
220 @Test
221 public void test12() {
222 // Force initialization of SomeClass
223 SomeClass.inlinedMethod();
224 test("invokestaticInlined", 1, 1);
225 }
226 }
|