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.replacements.test;
26
27 import jdk.vm.ci.aarch64.AArch64;
28 import jdk.vm.ci.amd64.AMD64;
29 import jdk.vm.ci.meta.ResolvedJavaMethod;
30 import org.graalvm.compiler.graph.Node;
31 import org.graalvm.compiler.nodes.StructuredGraph;
32 import org.graalvm.compiler.options.OptionValues;
33 import org.graalvm.compiler.replacements.nodes.ArrayCompareToNode;
34 import org.graalvm.compiler.serviceprovider.GraalServices;
35 import org.junit.Assert;
36 import org.junit.Assume;
37 import org.junit.Test;
38
39 import java.util.List;
40
41 import static org.graalvm.compiler.core.common.GraalOptions.RemoveNeverExecutedCode;
42
43 /**
44 * Tests compareTo method intrinsic.
45 */
46 public class StringCompareToTest extends StringSubstitutionTestBase {
47
48 // The compareTo() implementation in java.lang.String has 4 calls to compareTo implementation.
49 private static final int EXPECT_NODE_COUNT = 4;
50 private static final String DISABLE_COMPACTSTRINGS_FLAG = "-XX:-CompactStrings";
51
52 public StringCompareToTest() {
53 initSubstitution(
54 getResolvedJavaMethod(String.class, "compareTo", String.class),
55 getResolvedJavaMethod("stringCompareTo"),
56 ArrayCompareToNode.class);
57 }
58
59 private int countNode(ResolvedJavaMethod method, Class<?> expectedNode, OptionValues options) {
60 StructuredGraph graph = parseForCompile(method, options);
61 applyFrontEnd(graph);
72
73 @Override
74 protected void initSubstitution(ResolvedJavaMethod theRealMethod,
75 ResolvedJavaMethod theTestMethod, Class<?> expectedNode) {
76 Assume.assumeTrue((getTarget().arch instanceof AMD64) || (getTarget().arch instanceof AArch64));
77
78 realMethod = theRealMethod;
79 testMethod = theTestMethod;
80
81 StructuredGraph graph = testGraph(testMethod.getName());
82
83 // Check to see if the resulting graph contains the expected node
84 StructuredGraph replacement = getReplacements().getSubstitution(realMethod, -1, false, null);
85 if (replacement == null) {
86 assertInGraph(graph, expectedNode);
87 }
88
89 OptionValues options;
90 boolean needCheckNode = true;
91
92 if (GraalServices.Java8OrEarlier) {
93 needCheckNode = false;
94 } else {
95 List<String> vmArgs = GraalServices.getInputArguments();
96 Assume.assumeTrue(vmArgs != null);
97 for (String vmArg : vmArgs) {
98 if (vmArg.equals(DISABLE_COMPACTSTRINGS_FLAG)) {
99 needCheckNode = false;
100 }
101 }
102 }
103
104 if (needCheckNode) {
105 options = new OptionValues(getInitialOptions(), RemoveNeverExecutedCode, false);
106 Assert.assertEquals(EXPECT_NODE_COUNT, countNode(testMethod, expectedNode, options));
107 } else {
108 options = getInitialOptions();
109 }
110
111 // Force compilation.
112 testCode = getCode(testMethod, options);
|
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.replacements.test;
26
27 import static org.graalvm.compiler.core.common.GraalOptions.RemoveNeverExecutedCode;
28
29 import java.util.List;
30
31 import org.graalvm.compiler.graph.Node;
32 import org.graalvm.compiler.nodes.StructuredGraph;
33 import org.graalvm.compiler.options.OptionValues;
34 import org.graalvm.compiler.replacements.nodes.ArrayCompareToNode;
35 import org.graalvm.compiler.serviceprovider.GraalServices;
36 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
37 import org.junit.Assert;
38 import org.junit.Assume;
39 import org.junit.Test;
40
41 import jdk.vm.ci.aarch64.AArch64;
42 import jdk.vm.ci.amd64.AMD64;
43 import jdk.vm.ci.meta.ResolvedJavaMethod;
44
45 /**
46 * Tests compareTo method intrinsic.
47 */
48 public class StringCompareToTest extends StringSubstitutionTestBase {
49
50 // The compareTo() implementation in java.lang.String has 4 calls to compareTo implementation.
51 private static final int EXPECT_NODE_COUNT = 4;
52 private static final String DISABLE_COMPACTSTRINGS_FLAG = "-XX:-CompactStrings";
53
54 public StringCompareToTest() {
55 initSubstitution(
56 getResolvedJavaMethod(String.class, "compareTo", String.class),
57 getResolvedJavaMethod("stringCompareTo"),
58 ArrayCompareToNode.class);
59 }
60
61 private int countNode(ResolvedJavaMethod method, Class<?> expectedNode, OptionValues options) {
62 StructuredGraph graph = parseForCompile(method, options);
63 applyFrontEnd(graph);
74
75 @Override
76 protected void initSubstitution(ResolvedJavaMethod theRealMethod,
77 ResolvedJavaMethod theTestMethod, Class<?> expectedNode) {
78 Assume.assumeTrue((getTarget().arch instanceof AMD64) || (getTarget().arch instanceof AArch64));
79
80 realMethod = theRealMethod;
81 testMethod = theTestMethod;
82
83 StructuredGraph graph = testGraph(testMethod.getName());
84
85 // Check to see if the resulting graph contains the expected node
86 StructuredGraph replacement = getReplacements().getSubstitution(realMethod, -1, false, null);
87 if (replacement == null) {
88 assertInGraph(graph, expectedNode);
89 }
90
91 OptionValues options;
92 boolean needCheckNode = true;
93
94 if (JavaVersionUtil.Java8OrEarlier) {
95 needCheckNode = false;
96 } else {
97 List<String> vmArgs = GraalServices.getInputArguments();
98 Assume.assumeTrue(vmArgs != null);
99 for (String vmArg : vmArgs) {
100 if (vmArg.equals(DISABLE_COMPACTSTRINGS_FLAG)) {
101 needCheckNode = false;
102 }
103 }
104 }
105
106 if (needCheckNode) {
107 options = new OptionValues(getInitialOptions(), RemoveNeverExecutedCode, false);
108 Assert.assertEquals(EXPECT_NODE_COUNT, countNode(testMethod, expectedNode, options));
109 } else {
110 options = getInitialOptions();
111 }
112
113 // Force compilation.
114 testCode = getCode(testMethod, options);
|