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.traversal;
 24 
 25 import org.openjdk.bench.valhalla.util.SizeBase;
 26 import org.openjdk.bench.valhalla.types.Int64;
 27 import org.openjdk.bench.valhalla.types.Q64long;
 28 import org.openjdk.bench.valhalla.util.Utils;
 29 import org.openjdk.jmh.annotations.Benchmark;
 30 import org.openjdk.jmh.annotations.CompilerControl;
 31 import org.openjdk.jmh.annotations.Setup;
 32 
 33 public class Inline64 extends SizeBase {
 34 
 35     public static abstract class IntState extends SizeState {
 36         public Int64[] arr;
 37         void fill() {
 38             int[] a = Utils.makeRandomRing(arr.length);
 39             for (int i = 0; i < a.length; i++) {
 40                 arr[i] = new Q64long(a[i]);
 41             }
 42         }
 43     }
 44 
 45     public static abstract class RefState extends SizeState {
 46         public Q64long[] arr;
 47         void fill() {
 48             int[] a = Utils.makeRandomRing(arr.length);
 49             for (int i = 0; i < a.length; i++) {
 50                 arr[i] = new Q64long(a[i]);
 51             }
 52         }
 53     }
 54 
 55     public static abstract class ValState extends SizeState {
 56         public Q64long[] arr;
 57         void fill() {
 58             int[] a = Utils.makeRandomRing(arr.length);
 59             for (int i = 0; i < a.length; i++) {
 60                 arr[i] = new Q64long(a[i]);
 61             }
 62         }
 63     }
 64 
 65 
 66     public static class Int_as_Int extends IntState {
 67         @Setup
 68         public void setup() {
 69             arr = new Int64[size];
 70             fill();
 71         }
 72     }
 73 
 74     public static class Ref_as_Int extends IntState {
 75         @Setup
 76         public void setup() {
 77             arr = new Q64long[size];
 78             fill();
 79         }
 80     }
 81 
 82     public static class Val_as_Int extends IntState {
 83         @Setup
 84         public void setup() {
 85             arr = new Q64long[size];
 86             fill();
 87         }
 88     }
 89 
 90     public static class Ref_as_Ref extends RefState {
 91         @Setup
 92         public void setup() {
 93             arr = new Q64long[size];
 94             fill();
 95         }
 96     }
 97 
 98     public static class Val_as_Ref extends RefState {
 99         @Setup
100         public void setup() {
101             arr = new Q64long[size];
102             fill();
103         }
104     }
105 
106     public static class Val_as_Val extends ValState {
107         @Setup
108         public void setup() {
109             arr = new Q64long[size];
110             fill();
111         }
112     }
113 
114     @Benchmark
115     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
116     public int Int_as_Int_walk(Int_as_Int s) {
117         int steps = 0;
118         Int64[] values = s.arr;
119         for (int i = values[0].intValue(); i != 0; i = values[i].intValue()) steps++;
120         return steps;
121     }
122 
123     @Benchmark
124     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
125     public int Ref_as_Int_walk(Ref_as_Int s) {
126         int steps = 0;
127         Int64[] values = s.arr;
128         for (int i = values[0].intValue(); i != 0; i = values[i].intValue()) steps++;
129         return steps;
130     }
131 
132     @Benchmark
133     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
134     public int Val_as_Int_walk(Val_as_Int s) {
135         int steps = 0;
136         Int64[] values = s.arr;
137         for (int i = values[0].intValue(); i != 0; i = values[i].intValue()) steps++;
138         return steps;
139     }
140 
141     @Benchmark
142     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
143     public int Ref_as_Ref_walk(Ref_as_Ref s) {
144         int steps = 0;
145         Q64long[] values = s.arr;
146         for (int i = values[0].intValue(); i != 0; i = values[i].intValue()) steps++;
147         return steps;
148     }
149 
150     @Benchmark
151     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
152     public int Val_as_Ref_walk(Val_as_Ref s) {
153         int steps = 0;
154         Q64long[] values = s.arr;
155         for (int i = values[0].intValue(); i != 0; i = values[i].intValue()) steps++;
156         return steps;
157     }
158 
159     @Benchmark
160     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
161     public int Val_as_Val_walk(Val_as_Val s) {
162         int steps = 0;
163         Q64long[] values = s.arr;
164         for (int i = values[0].intValue(); i != 0; i = values[i].intValue()) steps++;
165         return steps;
166     }
167 
168 }