author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 55633 | 9d7c2d9f822c |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
55630
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 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 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.api.directives.test; |
26 |
||
55630
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
27 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
28 |
|
43972 | 29 |
import org.graalvm.compiler.api.directives.GraalDirectives; |
30 |
import org.graalvm.compiler.core.test.GraalCompilerTest; |
|
31 |
import org.graalvm.compiler.graph.iterators.NodeIterable; |
|
32 |
import org.graalvm.compiler.nodes.AbstractBeginNode; |
|
33 |
import org.graalvm.compiler.nodes.IfNode; |
|
46371 | 34 |
import org.graalvm.compiler.nodes.ReturnNode; |
43972 | 35 |
import org.graalvm.compiler.nodes.StructuredGraph; |
46371 | 36 |
import org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode; |
37 |
import org.junit.Assert; |
|
38 |
import org.junit.Test; |
|
43972 | 39 |
|
40 |
public class ProbabilityDirectiveTest extends GraalCompilerTest { |
|
41 |
||
55630
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
42 |
/** |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
43 |
* Called before a test is compiled. |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
44 |
*/ |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
45 |
@Override |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
46 |
protected void before(ResolvedJavaMethod method) { |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
47 |
// don't let -Xcomp pollute profile |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
48 |
method.reprofile(); |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
49 |
} |
10f1928a33b5
8227237: [Graal] org.graalvm.compiler.api.directives.test.ProbabilityDirectiveTest fails with -Xcomp
dlong
parents:
52910
diff
changeset
|
50 |
|
43972 | 51 |
public static int branchProbabilitySnippet(int arg) { |
52 |
if (GraalDirectives.injectBranchProbability(0.125, arg > 0)) { |
|
53 |
GraalDirectives.controlFlowAnchor(); // prevent removal of the if |
|
54 |
return 1; |
|
55 |
} else { |
|
56 |
GraalDirectives.controlFlowAnchor(); // prevent removal of the if |
|
57 |
return 2; |
|
58 |
} |
|
59 |
} |
|
60 |
||
61 |
@Test |
|
62 |
public void testBranchProbability() { |
|
63 |
test("branchProbabilitySnippet", 5); |
|
64 |
} |
|
65 |
||
48861 | 66 |
public static int branchProbabilitySnippet2(int arg) { |
67 |
if (!GraalDirectives.injectBranchProbability(0.125, arg <= 0)) { |
|
68 |
GraalDirectives.controlFlowAnchor(); // prevent removal of the if |
|
69 |
return 2; |
|
70 |
} else { |
|
71 |
GraalDirectives.controlFlowAnchor(); // prevent removal of the if |
|
72 |
return 1; |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
@Test |
|
77 |
public void testBranchProbability2() { |
|
78 |
test("branchProbabilitySnippet2", 5); |
|
79 |
} |
|
80 |
||
43972 | 81 |
@Override |
55509 | 82 |
protected void checkLowTierGraph(StructuredGraph graph) { |
43972 | 83 |
NodeIterable<IfNode> ifNodes = graph.getNodes(IfNode.TYPE); |
84 |
Assert.assertEquals("IfNode count", 1, ifNodes.count()); |
|
85 |
||
86 |
IfNode ifNode = ifNodes.first(); |
|
46371 | 87 |
AbstractBeginNode oneSuccessor; |
88 |
if (returnValue(ifNode.trueSuccessor()) == 1) { |
|
89 |
oneSuccessor = ifNode.trueSuccessor(); |
|
90 |
} else { |
|
91 |
assert returnValue(ifNode.falseSuccessor()) == 1; |
|
92 |
oneSuccessor = ifNode.falseSuccessor(); |
|
93 |
} |
|
94 |
Assert.assertEquals("branch probability of " + ifNode, 0.125, ifNode.probability(oneSuccessor), 0); |
|
43972 | 95 |
} |
46371 | 96 |
|
97 |
private static int returnValue(AbstractBeginNode b) { |
|
98 |
ControlFlowAnchorNode anchor = (ControlFlowAnchorNode) b.next(); |
|
99 |
ReturnNode returnNode = (ReturnNode) anchor.next(); |
|
100 |
return returnNode.result().asJavaConstant().asInt(); |
|
101 |
} |
|
43972 | 102 |
} |