1 /*
2 * Copyright (c) 2011, 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 */
54
55 /**
56 * Usages of the constant {@code " "} are replaced with the constant {@code "-"} and it is
57 * verified that executing the compiled code produces a result that the preserves the node
58 * replacement unless deoptimization occurs (e.g., due to -Xcomp causing profiles to be
59 * missing).
60 */
61 @Test
62 public void test1() {
63 final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
64 final StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.NO);
65 new CanonicalizerPhase().apply(graph, getProviders());
66 new DeadCodeEliminationPhase().apply(graph);
67
68 for (ConstantNode node : ConstantNode.getConstantNodes(graph)) {
69 if (node.getStackKind() == JavaKind.Object && " ".equals(getSnippetReflection().asObject(String.class, node.asJavaConstant()))) {
70 node.replace(graph, ConstantNode.forConstant(getSnippetReflection().forObject("-"), getMetaAccess(), graph));
71 }
72 }
73
74 InstalledCode compiledMethod = getCode(javaMethod, graph);
75 try {
76 Object result = compiledMethod.executeVarargs("1", "2", "3");
77 if (!"1-2-3".equals(result)) {
78 // Deoptimization probably occurred
79 Assert.assertEquals("interpreter", result);
80 }
81 } catch (InvalidInstalledCodeException t) {
82 Assert.fail("method invalidated");
83 }
84 }
85
86 @Test
87 public void test3() {
88 final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
89 InstalledCode compiledMethod = getCode(javaMethod);
90 try {
91 Object result = compiledMethod.executeVarargs("1", "2", "3");
92 Assert.assertEquals("1 2 3", result);
93 } catch (InvalidInstalledCodeException t) {
94 Assert.fail("method invalidated");
|
1 /*
2 * Copyright (c) 2011, 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 */
54
55 /**
56 * Usages of the constant {@code " "} are replaced with the constant {@code "-"} and it is
57 * verified that executing the compiled code produces a result that the preserves the node
58 * replacement unless deoptimization occurs (e.g., due to -Xcomp causing profiles to be
59 * missing).
60 */
61 @Test
62 public void test1() {
63 final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
64 final StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.NO);
65 new CanonicalizerPhase().apply(graph, getProviders());
66 new DeadCodeEliminationPhase().apply(graph);
67
68 for (ConstantNode node : ConstantNode.getConstantNodes(graph)) {
69 if (node.getStackKind() == JavaKind.Object && " ".equals(getSnippetReflection().asObject(String.class, node.asJavaConstant()))) {
70 node.replace(graph, ConstantNode.forConstant(getSnippetReflection().forObject("-"), getMetaAccess(), graph));
71 }
72 }
73
74 InstalledCode compiledMethod = getCode(javaMethod, graph, true);
75 try {
76 Object result = compiledMethod.executeVarargs("1", "2", "3");
77 if (!"1-2-3".equals(result)) {
78 // Deoptimization probably occurred
79 Assert.assertEquals("interpreter", result);
80 }
81 } catch (InvalidInstalledCodeException t) {
82 Assert.fail("method invalidated");
83 }
84 }
85
86 @Test
87 public void test3() {
88 final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
89 InstalledCode compiledMethod = getCode(javaMethod);
90 try {
91 Object result = compiledMethod.executeVarargs("1", "2", "3");
92 Assert.assertEquals("1 2 3", result);
93 } catch (InvalidInstalledCodeException t) {
94 Assert.fail("method invalidated");
|