43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 2015, 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 |
package org.graalvm.compiler.microbenchmarks.graal;
|
|
24 |
|
|
25 |
import java.util.Arrays;
|
|
26 |
|
48861
|
27 |
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
43972
|
28 |
import org.openjdk.jmh.annotations.Benchmark;
|
48861
|
29 |
import org.openjdk.jmh.annotations.Measurement;
|
43972
|
30 |
import org.openjdk.jmh.annotations.Warmup;
|
|
31 |
|
|
32 |
import org.graalvm.compiler.microbenchmarks.graal.util.MethodSpec;
|
|
33 |
import org.graalvm.compiler.microbenchmarks.graal.util.ScheduleState;
|
|
34 |
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
|
35 |
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
|
36 |
|
48861
|
37 |
@Warmup(iterations = 20)
|
|
38 |
@Measurement(iterations = 10)
|
43972
|
39 |
public class SchedulePhaseBenchmark extends GraalBenchmark {
|
|
40 |
|
|
41 |
@MethodSpec(declaringClass = String.class, name = "equals")
|
|
42 |
public static class StringEquals extends ScheduleState {
|
|
43 |
}
|
|
44 |
|
|
45 |
@Benchmark
|
|
46 |
public void stringEquals(StringEquals s) {
|
|
47 |
s.schedule.apply(s.graph);
|
|
48 |
}
|
|
49 |
|
|
50 |
@Benchmark
|
|
51 |
public void cfgCompute1(StringEquals s) {
|
|
52 |
ControlFlowGraph.compute(s.graph, true, false, false, false);
|
|
53 |
}
|
|
54 |
|
|
55 |
@Benchmark
|
|
56 |
public void cfgCompute2(StringEquals s) {
|
|
57 |
ControlFlowGraph.compute(s.graph, true, true, false, false);
|
|
58 |
}
|
|
59 |
|
|
60 |
@Benchmark
|
|
61 |
public void cfgCompute3(StringEquals s) {
|
|
62 |
ControlFlowGraph.compute(s.graph, true, true, true, false);
|
|
63 |
}
|
|
64 |
|
|
65 |
@Benchmark
|
|
66 |
public void cfgCompute4(StringEquals s) {
|
|
67 |
ControlFlowGraph.compute(s.graph, true, true, true, true);
|
|
68 |
}
|
|
69 |
|
|
70 |
public static int[] intersectionSnippet(int[] in1, int[] in2) {
|
|
71 |
int[] result = new int[Math.min(in1.length, in2.length)];
|
|
72 |
int next = 0;
|
|
73 |
for (int i1 : in1) {
|
|
74 |
for (int i2 : in2) {
|
|
75 |
if (i2 == i1) {
|
|
76 |
result[next++] = i1;
|
|
77 |
break;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
}
|
|
81 |
if (next < result.length) {
|
|
82 |
result = Arrays.copyOf(result, next);
|
|
83 |
}
|
|
84 |
return result;
|
|
85 |
}
|
|
86 |
|
|
87 |
// Checkstyle: stop method name check
|
|
88 |
@MethodSpec(declaringClass = SchedulePhaseBenchmark.class, name = "intersectionSnippet")
|
|
89 |
public static class IntersectionState_LATEST_OPTIMAL extends ScheduleState {
|
|
90 |
public IntersectionState_LATEST_OPTIMAL() {
|
|
91 |
super(SchedulingStrategy.LATEST);
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
@Benchmark
|
|
96 |
public void intersection_LATEST_OPTIMAL(IntersectionState_LATEST_OPTIMAL s) {
|
|
97 |
s.schedule.apply(s.graph);
|
|
98 |
}
|
|
99 |
|
|
100 |
@MethodSpec(declaringClass = SchedulePhaseBenchmark.class, name = "intersectionSnippet")
|
|
101 |
public static class IntersectionState_LATEST_OUT_OF_LOOPS_OPTIMAL extends ScheduleState {
|
|
102 |
public IntersectionState_LATEST_OUT_OF_LOOPS_OPTIMAL() {
|
|
103 |
super(SchedulingStrategy.LATEST_OUT_OF_LOOPS);
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
@Benchmark
|
|
108 |
public void intersection_LATEST_OUT_OF_LOOPS_OPTIMAL(IntersectionState_LATEST_OUT_OF_LOOPS_OPTIMAL s) {
|
|
109 |
s.schedule.apply(s.graph);
|
|
110 |
}
|
|
111 |
|
|
112 |
@MethodSpec(declaringClass = SchedulePhaseBenchmark.class, name = "intersectionSnippet")
|
|
113 |
public static class IntersectionState_EARLIEST_OPTIMAL extends ScheduleState {
|
|
114 |
public IntersectionState_EARLIEST_OPTIMAL() {
|
|
115 |
super(SchedulingStrategy.EARLIEST);
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
@Benchmark
|
|
120 |
public void intersection_EARLIEST_OPTIMAL(IntersectionState_EARLIEST_OPTIMAL s) {
|
|
121 |
s.schedule.apply(s.graph);
|
|
122 |
}
|
48861
|
123 |
|
|
124 |
@MethodSpec(declaringClass = SchedulePhaseBenchmark.class, name = "intersectionSnippet")
|
|
125 |
public static class IntersectionState_EARLIEST_WITH_GUARD_ORDER_OPTIMAL extends ScheduleState {
|
|
126 |
public IntersectionState_EARLIEST_WITH_GUARD_ORDER_OPTIMAL() {
|
|
127 |
super(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
|
|
128 |
}
|
|
129 |
}
|
|
130 |
|
|
131 |
@Benchmark
|
|
132 |
public void intersection_EARLIEST_WITH_GUARD_ORDER_OPTIMAL(IntersectionState_EARLIEST_WITH_GUARD_ORDER_OPTIMAL s) {
|
|
133 |
s.schedule.apply(s.graph);
|
|
134 |
}
|
|
135 |
// Checkstyle: resume method name check
|
|
136 |
|
|
137 |
// Checkstyle: stop method name check
|
|
138 |
@MethodSpec(declaringClass = SchedulePhase.Instance.class, name = "scheduleEarliestIterative")
|
|
139 |
public static class ScheduleEarliestIterative_LATEST_OPTIMAL extends ScheduleState {
|
|
140 |
public ScheduleEarliestIterative_LATEST_OPTIMAL() {
|
|
141 |
super(SchedulingStrategy.LATEST);
|
|
142 |
}
|
|
143 |
}
|
|
144 |
|
|
145 |
@Benchmark
|
|
146 |
public void scheduleEarliestIterative_LATEST_OPTIMAL(ScheduleEarliestIterative_LATEST_OPTIMAL s) {
|
|
147 |
s.schedule.apply(s.graph);
|
|
148 |
}
|
|
149 |
|
|
150 |
@MethodSpec(declaringClass = SchedulePhase.Instance.class, name = "scheduleEarliestIterative")
|
|
151 |
public static class ScheduleEarliestIterative_LATEST_OUT_OF_LOOPS_OPTIMAL extends ScheduleState {
|
|
152 |
public ScheduleEarliestIterative_LATEST_OUT_OF_LOOPS_OPTIMAL() {
|
|
153 |
super(SchedulingStrategy.LATEST_OUT_OF_LOOPS);
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
@Benchmark
|
|
158 |
public void scheduleEarliestIterative_LATEST_OUT_OF_LOOPS_OPTIMAL(ScheduleEarliestIterative_LATEST_OUT_OF_LOOPS_OPTIMAL s) {
|
|
159 |
s.schedule.apply(s.graph);
|
|
160 |
}
|
|
161 |
|
|
162 |
@MethodSpec(declaringClass = SchedulePhase.Instance.class, name = "scheduleEarliestIterative")
|
|
163 |
public static class ScheduleEarliestIterative_EARLIEST_OPTIMAL extends ScheduleState {
|
|
164 |
public ScheduleEarliestIterative_EARLIEST_OPTIMAL() {
|
|
165 |
super(SchedulingStrategy.EARLIEST);
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
@Benchmark
|
|
170 |
public void scheduleEarliestIterative_EARLIEST_OPTIMAL(ScheduleEarliestIterative_EARLIEST_OPTIMAL s) {
|
|
171 |
s.schedule.apply(s.graph);
|
|
172 |
}
|
|
173 |
|
|
174 |
@MethodSpec(declaringClass = SchedulePhase.Instance.class, name = "scheduleEarliestIterative")
|
|
175 |
public static class ScheduleEarliestIterative_EARLIEST_WITH_GUARD_ORDER_OPTIMAL extends ScheduleState {
|
|
176 |
public ScheduleEarliestIterative_EARLIEST_WITH_GUARD_ORDER_OPTIMAL() {
|
|
177 |
super(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
@Benchmark
|
|
182 |
public void scheduleEarliestIterative_EARLIEST_WITH_GUARD_ORDER_OPTIMAL(ScheduleEarliestIterative_EARLIEST_WITH_GUARD_ORDER_OPTIMAL s) {
|
|
183 |
s.schedule.apply(s.graph);
|
|
184 |
}
|
43972
|
185 |
// Checkstyle: resume method name check
|
|
186 |
}
|