1 /*
  2  * Copyright (c) 2020, 2024, 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.openjdk.bench.valhalla.acmp.array;
 24 
 25 import org.openjdk.bench.valhalla.types.Int64;
 26 import org.openjdk.bench.valhalla.types.Q64long;
 27 import org.openjdk.jmh.annotations.Benchmark;
 28 import org.openjdk.jmh.annotations.BenchmarkMode;
 29 import org.openjdk.jmh.annotations.CompilerControl;
 30 import org.openjdk.jmh.annotations.Fork;
 31 import org.openjdk.jmh.annotations.Measurement;
 32 import org.openjdk.jmh.annotations.Mode;
 33 import org.openjdk.jmh.annotations.OperationsPerInvocation;
 34 import org.openjdk.jmh.annotations.OutputTimeUnit;
 35 import org.openjdk.jmh.annotations.Scope;
 36 import org.openjdk.jmh.annotations.State;
 37 import org.openjdk.jmh.annotations.Warmup;
 38 
 39 import java.util.concurrent.TimeUnit;
 40 
 41 @Fork(3)
 42 @Warmup(iterations = 3, time = 1)
 43 @Measurement(iterations = 5, time = 1)
 44 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 45 @BenchmarkMode(Mode.AverageTime)
 46 @State(Scope.Thread)
 47 public class InlineIsCmpBranch64long extends StatesQ64long {
 48 
 49     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 50     private static int cmp_Obj(Object[] objects1, Object[] objects2) {
 51         int s = 0;
 52         for (int i = 0; i < SIZE; i++) {
 53             if (objects1[i] == objects2[i]) {
 54                 s += 1;
 55             } else {
 56                 s -= 1;
 57             }
 58         }
 59         return s;
 60     }
 61 
 62     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 63     private static int cmp_Int(Int64[] objects1, Int64[] objects2) {
 64         int s = 0;
 65         for (int i = 0; i < SIZE; i++) {
 66             if (objects1[i] == objects2[i]) {
 67                 s += 1;
 68             } else {
 69                 s -= 1;
 70             }
 71         }
 72         return s;
 73     }
 74 
 75     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 76     private static int cmp_Ref(Q64long[] objects1, Q64long[] objects2) {
 77         int s = 0;
 78         for (int i = 0; i < SIZE; i++) {
 79             if (objects1[i] == objects2[i]) {
 80                 s += 1;
 81             } else {
 82                 s -= 1;
 83             }
 84         }
 85         return s;
 86     }
 87 
 88     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 89     private static int cmp_Val(Q64long[] objects1, Q64long[] objects2) {
 90         int s = 0;
 91         for (int i = 0; i < SIZE; i++) {
 92             if (objects1[i] == objects2[i]) {
 93                 s += 1;
 94             } else {
 95                 s -= 1;
 96             }
 97         }
 98         return s;
 99     }
100 
101 
102     @Benchmark
103     @OperationsPerInvocation(SIZE)
104     @CompilerControl(CompilerControl.Mode.INLINE)
105     public int Obj_equals000(ObjState00 st) {
106         return cmp_Obj(st.arr1, st.arr2);
107     }
108 
109     @Benchmark
110     @OperationsPerInvocation(SIZE)
111     @CompilerControl(CompilerControl.Mode.INLINE)
112     public int Obj_equals025(ObjState25 st) {
113         return cmp_Obj(st.arr1, st.arr2);
114     }
115 
116     @Benchmark
117     @OperationsPerInvocation(SIZE)
118     @CompilerControl(CompilerControl.Mode.INLINE)
119     public int Obj_equals050(ObjState50 st) {
120         return cmp_Obj(st.arr1, st.arr2);
121     }
122 
123     @Benchmark
124     @OperationsPerInvocation(SIZE)
125     @CompilerControl(CompilerControl.Mode.INLINE)
126     public int Obj_equals075(ObjState75 st) {
127         return cmp_Obj(st.arr1, st.arr2);
128     }
129 
130     @Benchmark
131     @OperationsPerInvocation(SIZE)
132     @CompilerControl(CompilerControl.Mode.INLINE)
133     public int Obj_equals100(ObjState100 st) {
134         return cmp_Obj(st.arr1, st.arr2);
135     }
136 
137     @Benchmark
138     @OperationsPerInvocation(SIZE)
139     @CompilerControl(CompilerControl.Mode.INLINE)
140     public int Int_equals000(IntState00 st) {
141         return cmp_Int(st.arr1, st.arr2);
142     }
143 
144     @Benchmark
145     @OperationsPerInvocation(SIZE)
146     @CompilerControl(CompilerControl.Mode.INLINE)
147     public int Int_equals025(IntState25 st) {
148         return cmp_Int(st.arr1, st.arr2);
149     }
150 
151     @Benchmark
152     @OperationsPerInvocation(SIZE)
153     @CompilerControl(CompilerControl.Mode.INLINE)
154     public int Int_equals050(IntState50 st) {
155         return cmp_Int(st.arr1, st.arr2);
156     }
157 
158     @Benchmark
159     @OperationsPerInvocation(SIZE)
160     @CompilerControl(CompilerControl.Mode.INLINE)
161     public int Int_equals075(IntState75 st) {
162         return cmp_Int(st.arr1, st.arr2);
163     }
164 
165     @Benchmark
166     @OperationsPerInvocation(SIZE)
167     @CompilerControl(CompilerControl.Mode.INLINE)
168     public int Int_equals100(IntState100 st) {
169         return cmp_Int(st.arr1, st.arr2);
170     }
171 
172     @Benchmark
173     @OperationsPerInvocation(SIZE)
174     @CompilerControl(CompilerControl.Mode.INLINE)
175     public int Ref_equals000(RefState00 st) {
176         return cmp_Ref(st.arr1, st.arr2);
177     }
178 
179     @Benchmark
180     @OperationsPerInvocation(SIZE)
181     @CompilerControl(CompilerControl.Mode.INLINE)
182     public int Ref_equals025(RefState25 st) {
183         return cmp_Ref(st.arr1, st.arr2);
184     }
185 
186     @Benchmark
187     @OperationsPerInvocation(SIZE)
188     @CompilerControl(CompilerControl.Mode.INLINE)
189     public int Ref_equals050(RefState50 st) {
190         return cmp_Ref(st.arr1, st.arr2);
191     }
192 
193     @Benchmark
194     @OperationsPerInvocation(SIZE)
195     @CompilerControl(CompilerControl.Mode.INLINE)
196     public int Ref_equals075(RefState75 st) {
197         return cmp_Ref(st.arr1, st.arr2);
198     }
199 
200     @Benchmark
201     @OperationsPerInvocation(SIZE)
202     @CompilerControl(CompilerControl.Mode.INLINE)
203     public int Ref_equals100(RefState100 st) {
204         return cmp_Ref(st.arr1, st.arr2);
205     }
206 
207     @Benchmark
208     @OperationsPerInvocation(SIZE)
209     @CompilerControl(CompilerControl.Mode.INLINE)
210     public int Val_equals000(ValState00 st) {
211         return cmp_Val(st.arr1, st.arr2);
212     }
213 
214     @Benchmark
215     @OperationsPerInvocation(SIZE)
216     @CompilerControl(CompilerControl.Mode.INLINE)
217     public int Val_equals025(ValState25 st) {
218         return cmp_Val(st.arr1, st.arr2);
219     }
220 
221     @Benchmark
222     @OperationsPerInvocation(SIZE)
223     @CompilerControl(CompilerControl.Mode.INLINE)
224     public int Val_equals050(ValState50 st) {
225         return cmp_Val(st.arr1, st.arr2);
226     }
227 
228     @Benchmark
229     @OperationsPerInvocation(SIZE)
230     @CompilerControl(CompilerControl.Mode.INLINE)
231     public int Val_equals075(ValState75 st) {
232         return cmp_Val(st.arr1, st.arr2);
233     }
234 
235     @Benchmark
236     @OperationsPerInvocation(SIZE)
237     @CompilerControl(CompilerControl.Mode.INLINE)
238     public int Val_equals100(ValState100 st) {
239         return cmp_Val(st.arr1, st.arr2);
240     }
241 
242     @Benchmark
243     @OperationsPerInvocation(SIZE)
244     @CompilerControl(CompilerControl.Mode.INLINE)
245     public int Val_as_Ref_equals000(ValState00 st) {
246         return cmp_Ref(st.arr1, st.arr2);
247     }
248 
249     @Benchmark
250     @OperationsPerInvocation(SIZE)
251     @CompilerControl(CompilerControl.Mode.INLINE)
252     public int Val_as_Ref_equals025(ValState25 st) {
253         return cmp_Ref(st.arr1, st.arr2);
254     }
255 
256     @Benchmark
257     @OperationsPerInvocation(SIZE)
258     @CompilerControl(CompilerControl.Mode.INLINE)
259     public int Val_as_Ref_equals050(ValState50 st) {
260         return cmp_Ref(st.arr1, st.arr2);
261     }
262 
263     @Benchmark
264     @OperationsPerInvocation(SIZE)
265     @CompilerControl(CompilerControl.Mode.INLINE)
266     public int Val_as_Ref_equals075(ValState75 st) {
267         return cmp_Ref(st.arr1, st.arr2);
268     }
269 
270     @Benchmark
271     @OperationsPerInvocation(SIZE)
272     @CompilerControl(CompilerControl.Mode.INLINE)
273     public int Val_as_Ref_equals100(ValState100 st) {
274         return cmp_Ref(st.arr1, st.arr2);
275     }
276 
277     @Benchmark
278     @OperationsPerInvocation(SIZE)
279     @CompilerControl(CompilerControl.Mode.INLINE)
280     public int Val_as_Int_equals000(ValState00 st) {
281         return cmp_Int(st.arr1, st.arr2);
282     }
283 
284     @Benchmark
285     @OperationsPerInvocation(SIZE)
286     @CompilerControl(CompilerControl.Mode.INLINE)
287     public int Val_as_Int_equals025(ValState25 st) {
288         return cmp_Int(st.arr1, st.arr2);
289     }
290 
291     @Benchmark
292     @OperationsPerInvocation(SIZE)
293     @CompilerControl(CompilerControl.Mode.INLINE)
294     public int Val_as_Int_equals050(ValState50 st) {
295         return cmp_Int(st.arr1, st.arr2);
296     }
297 
298     @Benchmark
299     @OperationsPerInvocation(SIZE)
300     @CompilerControl(CompilerControl.Mode.INLINE)
301     public int Val_as_Int_equals075(ValState75 st) {
302         return cmp_Int(st.arr1, st.arr2);
303     }
304 
305     @Benchmark
306     @OperationsPerInvocation(SIZE)
307     @CompilerControl(CompilerControl.Mode.INLINE)
308     public int Val_as_Int_equals100(ValState100 st) {
309         return cmp_Int(st.arr1, st.arr2);
310     }
311 
312     @Benchmark
313     @OperationsPerInvocation(SIZE)
314     @CompilerControl(CompilerControl.Mode.INLINE)
315     public int Val_as_Obj_equals000(ValState00 st) {
316         return cmp_Obj(st.arr1, st.arr2);
317     }
318 
319     @Benchmark
320     @OperationsPerInvocation(SIZE)
321     @CompilerControl(CompilerControl.Mode.INLINE)
322     public int Val_as_Obj_equals025(ValState25 st) {
323         return cmp_Obj(st.arr1, st.arr2);
324     }
325 
326     @Benchmark
327     @OperationsPerInvocation(SIZE)
328     @CompilerControl(CompilerControl.Mode.INLINE)
329     public int Val_as_Obj_equals050(ValState50 st) {
330         return cmp_Obj(st.arr1, st.arr2);
331     }
332 
333     @Benchmark
334     @OperationsPerInvocation(SIZE)
335     @CompilerControl(CompilerControl.Mode.INLINE)
336     public int Val_as_Obj_equals075(ValState75 st) {
337         return cmp_Obj(st.arr1, st.arr2);
338     }
339 
340     @Benchmark
341     @OperationsPerInvocation(SIZE)
342     @CompilerControl(CompilerControl.Mode.INLINE)
343     public int Val_as_Obj_equals100(ValState100 st) {
344         return cmp_Obj(st.arr1, st.arr2);
345     }
346 
347 }