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.array.fill;
 24 
 25 import org.openjdk.bench.valhalla.array.util.StatesQ64int;
 26 import org.openjdk.bench.valhalla.types.Q64int;
 27 import org.openjdk.jmh.annotations.Benchmark;
 28 import org.openjdk.jmh.annotations.CompilerControl;
 29 import org.openjdk.jmh.annotations.Scope;
 30 import org.openjdk.jmh.annotations.State;
 31 
 32 import java.util.Arrays;
 33 
 34 public class Inline64int extends StatesQ64int {
 35 
 36     public static class RefStaticField {
 37         static Q64int f = new Q64int(42);
 38     }
 39 
 40     public static class ValStaticField {
 41         static Q64int f = new Q64int(42);
 42     }
 43 
 44     @State(Scope.Thread)
 45     public static class RefInstanceField {
 46         Q64int f = new Q64int(42);
 47     }
 48 
 49     @State(Scope.Thread)
 50     public static class ValInstanceField {
 51         Q64int f = new Q64int(42);
 52     }
 53 
 54     @Benchmark
 55     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 56     public void Def_to_Val_as_Val_fill(Val_as_Val st) {
 57         Q64int[] arr = st.arr;
 58         for (int i = 0; i < arr.length; i++) {
 59             arr[i] = new Q64int()  ;
 60         }
 61     }
 62 
 63     @Benchmark
 64     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 65     public void New_to_Val_as_Val_fill(Val_as_Val st) {
 66         Q64int[] arr = st.arr;
 67         Q64int v = new Q64int(42);
 68         for (int i = 0; i < arr.length; i++) {
 69             arr[i] = v;
 70         }
 71     }
 72 
 73     @Benchmark
 74     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 75     public void Ref_to_Val_as_Val_fillstat(Val_as_Val st) {
 76         Q64int[] arr = st.arr;
 77         for (int i = 0; i < arr.length; i++) {
 78             arr[i] = RefStaticField.f;
 79         }
 80     }
 81 
 82     @Benchmark
 83     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 84     public void Val_to_Val_as_Val_fillstat(Val_as_Val st) {
 85         Q64int[] arr = st.arr;
 86         for (int i = 0; i < arr.length; i++) {
 87             arr[i] = ValStaticField.f;
 88         }
 89     }
 90 
 91     @Benchmark
 92     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 93     public void Ref_to_Val_as_Val_fillinst(Val_as_Val st, RefInstanceField f) {
 94         Q64int[] arr = st.arr;
 95         for (int i = 0; i < arr.length; i++) {
 96             arr[i] = f.f;
 97         }
 98     }
 99 
100     @Benchmark
101     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
102     public void Val_to_Val_as_Val_fillinst(Val_as_Val st, ValInstanceField f) {
103         Q64int[] arr = st.arr;
104         for (int i = 0; i < arr.length; i++) {
105             arr[i] = f.f;
106         }
107     }
108 
109     @Benchmark
110     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
111     public void Def_to_Ref_as_Ref_fill(Ref_as_Ref st) {
112         Q64int[] arr = st.arr;
113         for (int i = 0; i < arr.length; i++) {
114             arr[i] = new Q64int()  ;
115         }
116     }
117 
118     @Benchmark
119     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
120     public void New_to_Ref_as_Ref_fill(Ref_as_Ref st) {
121         Q64int[] arr = st.arr;
122         Q64int v = new Q64int(42);
123         for (int i = 0; i < arr.length; i++) {
124             arr[i] = v;
125         }
126     }
127 
128     @Benchmark
129     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
130     public void Ref_to_Ref_as_Ref_fillstat(Ref_as_Ref st) {
131         Q64int[] arr = st.arr;
132         for (int i = 0; i < arr.length; i++) {
133             arr[i] = RefStaticField.f;
134         }
135     }
136 
137     @Benchmark
138     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
139     public void Val_to_Ref_as_Ref_fillstat(Ref_as_Ref st) {
140         Q64int[] arr = st.arr;
141         for (int i = 0; i < arr.length; i++) {
142             arr[i] = ValStaticField.f;
143         }
144     }
145 
146     @Benchmark
147     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
148     public void Ref_to_Ref_as_Ref_fillinst(Ref_as_Ref st, RefInstanceField f) {
149         Q64int[] arr = st.arr;
150         for (int i = 0; i < arr.length; i++) {
151             arr[i] = f.f;
152         }
153     }
154 
155     @Benchmark
156     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
157     public void Val_to_Ref_as_Ref_fillinst(Ref_as_Ref st, ValInstanceField f) {
158         Q64int[] arr = st.arr;
159         for (int i = 0; i < arr.length; i++) {
160             arr[i] = f.f;
161         }
162     }
163 
164     @Benchmark
165     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
166     public void Def_to_Val_as_Val_arrayfill(Val_as_Val st) {
167         Arrays.fill(st.arr, new Q64int()  );
168     }
169 
170     @Benchmark
171     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
172     public void New_to_Val_as_Val_arrayfill(Val_as_Val st) {
173         Arrays.fill(st.arr, new Q64int(42));
174     }
175 
176     @Benchmark
177     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
178     public void Ref_to_Val_as_Val_arrayfillstat(Val_as_Val st) {
179         Arrays.fill(st.arr, RefStaticField.f);
180     }
181 
182     @Benchmark
183     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
184     public void Val_to_Val_as_Val_arrayfillstat(Val_as_Val st) {
185         Arrays.fill(st.arr, ValStaticField.f);
186     }
187 
188     @Benchmark
189     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
190     public void Ref_to_Val_as_Val_arrayfillinst(Val_as_Val st, RefInstanceField f) {
191         Arrays.fill(st.arr, f.f);
192     }
193 
194     @Benchmark
195     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
196     public void Val_to_Val_as_Val_arrayfillinst(Val_as_Val st, ValInstanceField f) {
197         Arrays.fill(st.arr, f.f);
198     }
199 
200     @Benchmark
201     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
202     public void Def_to_Ref_as_Ref_arrayfill(Ref_as_Ref st) {
203         Arrays.fill(st.arr, new Q64int()  );
204     }
205 
206     @Benchmark
207     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
208     public void New_to_Ref_as_Ref_arrayfill(Ref_as_Ref st) {
209         Arrays.fill(st.arr, new Q64int(42));
210     }
211 
212     @Benchmark
213     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
214     public void Ref_to_Ref_as_Ref_arrayfillstat(Ref_as_Ref st) {
215         Arrays.fill(st.arr, RefStaticField.f);
216     }
217 
218     @Benchmark
219     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
220     public void Val_to_Ref_as_Ref_arrayfillstat(Ref_as_Ref st) {
221         Arrays.fill(st.arr, ValStaticField.f);
222     }
223 
224     @Benchmark
225     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
226     public void Ref_to_Ref_as_Ref_arrayfillinst(Ref_as_Ref st, RefInstanceField f) {
227         Arrays.fill(st.arr, f.f);
228     }
229 
230     @Benchmark
231     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
232     public void Val_to_Ref_as_Ref_arrayfillinst(Ref_as_Ref st, ValInstanceField f) {
233         Arrays.fill(st.arr, f.f);
234     }
235 
236 }