1 /*
  2  * Copyright (c) 2020, 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.arraytotal.fill;
 24 
 25 import org.openjdk.bench.valhalla.arraytotal.util.StatesQ64long;
 26 import org.openjdk.bench.valhalla.types.Int64;
 27 import org.openjdk.bench.valhalla.types.Q64long;
 28 import org.openjdk.jmh.annotations.Benchmark;
 29 import org.openjdk.jmh.annotations.CompilerControl;
 30 import org.openjdk.jmh.annotations.Scope;
 31 import org.openjdk.jmh.annotations.State;
 32 
 33 import java.util.Arrays;
 34 
 35 public class Inline64longFillInstObj extends StatesQ64long {
 36 
 37 
 38     @State(Scope.Thread)
 39     public static class InstanceField {
 40         Object f = new Q64long(42);
 41     }
 42 
 43     @Benchmark
 44     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 45     public void Obj_to_Val_as_Val_fillinst0(Val_as_Val st, InstanceField f) {
 46         Q64long[] arr = st.arr;
 47         for (int i = 0; i < arr.length; i++) {
 48             arr[i] = (Q64long) f.f;
 49         }
 50     }
 51 
 52     @Benchmark
 53     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 54     public void Obj_to_Val_as_Val_fillinst1(Val_as_Val st, InstanceField f) {
 55         int len = st.arr.length;
 56         for (int i = 0; i < len; i++) {
 57             st.arr[i] = (Q64long) f.f;
 58         }
 59     }
 60 
 61     @Benchmark
 62     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 63     public void Obj_to_Val_as_Ref_fillinst0(Val_as_Ref st, InstanceField f) {
 64         Q64long.ref[] arr = st.arr;
 65         for (int i = 0; i < arr.length; i++) {
 66             arr[i] = (Q64long) f.f;
 67         }
 68     }
 69 
 70     @Benchmark
 71     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 72     public void Obj_to_Val_as_Ref_fillinst1(Val_as_Ref st, InstanceField f) {
 73         int len = st.arr.length;
 74         for (int i = 0; i < len; i++) {
 75             st.arr[i] = (Q64long) f.f;
 76         }
 77     }
 78 
 79     @Benchmark
 80     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 81     public void Obj_to_Ref_as_Ref_fillinst0(Ref_as_Ref st, InstanceField f) {
 82         Q64long.ref[] arr = st.arr;
 83         for (int i = 0; i < arr.length; i++) {
 84             arr[i] = (Q64long) f.f;
 85         }
 86     }
 87 
 88     @Benchmark
 89     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 90     public void Obj_to_Ref_as_Ref_fillinst1(Ref_as_Ref st, InstanceField f) {
 91         int len = st.arr.length;
 92         for (int i = 0; i < len; i++) {
 93             st.arr[i] = (Q64long) f.f;
 94         }
 95     }
 96 
 97     @Benchmark
 98     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 99     public void Obj_to_Val_as_Int_fillinst0(Val_as_Int st, InstanceField f) {
100         Int64[] arr = st.arr;
101         for (int i = 0; i < arr.length; i++) {
102             arr[i] = (Int64) f.f;
103         }
104     }
105 
106     @Benchmark
107     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
108     public void Obj_to_Val_as_Int_fillinst1(Val_as_Int st, InstanceField f) {
109         int len = st.arr.length;
110         for (int i = 0; i < len; i++) {
111             st.arr[i] = (Int64) f.f;
112         }
113     }
114 
115     @Benchmark
116     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
117     public void Obj_to_Ref_as_Int_fillinst0(Ref_as_Int st, InstanceField f) {
118         Int64[] arr = st.arr;
119         for (int i = 0; i < arr.length; i++) {
120             arr[i] = (Int64) f.f;
121         }
122     }
123 
124     @Benchmark
125     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
126     public void Obj_to_Ref_as_Int_fillinst1(Ref_as_Int st, InstanceField f) {
127         int len = st.arr.length;
128         for (int i = 0; i < len; i++) {
129             st.arr[i] = (Int64) f.f;
130         }
131     }
132 
133     @Benchmark
134     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
135     public void Obj_to_Int_as_Int_fillinst0(Int_as_Int st, InstanceField f) {
136         Int64[] arr = st.arr;
137         for (int i = 0; i < arr.length; i++) {
138             arr[i] = (Int64) f.f;
139         }
140     }
141 
142     @Benchmark
143     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
144     public void Obj_to_Int_as_Int_fillinst1(Int_as_Int st, InstanceField f) {
145         int len = st.arr.length;
146         for (int i = 0; i < len; i++) {
147             st.arr[i] = (Int64) f.f;
148         }
149     }
150 
151     @Benchmark
152     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
153     public void Obj_to_Val_as_Obj_fillinst0(Val_as_Obj st, InstanceField f) {
154         Object[] arr = st.arr;
155         for (int i = 0; i < arr.length; i++) {
156             arr[i] = f.f;
157         }
158     }
159 
160     @Benchmark
161     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
162     public void Obj_to_Val_as_Obj_fillinst1(Val_as_Obj st, InstanceField f) {
163         int len = st.arr.length;
164         for (int i = 0; i < len; i++) {
165             st.arr[i] = f.f;
166         }
167     }
168 
169     @Benchmark
170     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
171     public void Obj_to_Ref_as_Obj_fillinst0(Ref_as_Obj st, InstanceField f) {
172         Object[] arr = st.arr;
173         for (int i = 0; i < arr.length; i++) {
174             arr[i] = f.f;
175         }
176     }
177 
178     @Benchmark
179     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
180     public void Obj_to_Ref_as_Obj_fillinst1(Ref_as_Obj st, InstanceField f) {
181         int len = st.arr.length;
182         for (int i = 0; i < len; i++) {
183             st.arr[i] = f.f;
184         }
185     }
186 
187     @Benchmark
188     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
189     public void Obj_to_Int_as_Obj_fillinst0(Int_as_Obj st, InstanceField f) {
190         Object[] arr = st.arr;
191         for (int i = 0; i < arr.length; i++) {
192             arr[i] = f.f;
193         }
194     }
195 
196     @Benchmark
197     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
198     public void Obj_to_Int_as_Obj_fillinst1(Int_as_Obj st, InstanceField f) {
199         int len = st.arr.length;
200         for (int i = 0; i < len; i++) {
201             st.arr[i] = f.f;
202         }
203     }
204 
205     @Benchmark
206     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
207     public void Obj_to_Obj_as_Obj_fillinst0(Obj_as_Obj st, InstanceField f) {
208         Object[] arr = st.arr;
209         for (int i = 0; i < arr.length; i++) {
210             arr[i] = f.f;
211         }
212     }
213 
214     @Benchmark
215     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
216     public void Obj_to_Obj_as_Obj_fillinst1(Obj_as_Obj st, InstanceField f) {
217         int len = st.arr.length;
218         for (int i = 0; i < len; i++) {
219             st.arr[i] = f.f;
220         }
221     }
222 
223     @Benchmark
224     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
225     public void Obj_to_Val_as_Val_arrayfillinst(Val_as_Val st, InstanceField f) {
226         Arrays.fill(st.arr, f.f);
227     }
228 
229     @Benchmark
230     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
231     public void Obj_to_Val_as_Ref_arrayfillinst(Val_as_Ref st, InstanceField f) {
232         Arrays.fill(st.arr, f.f);
233     }
234 
235     @Benchmark
236     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
237     public void Obj_to_Ref_as_Ref_arrayfillinst(Ref_as_Ref st, InstanceField f) {
238         Arrays.fill(st.arr, f.f);
239     }
240 
241     @Benchmark
242     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
243     public void Obj_to_Val_as_Int_arrayfillinst(Val_as_Int st, InstanceField f) {
244         Arrays.fill(st.arr, f.f);
245     }
246 
247     @Benchmark
248     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
249     public void Obj_to_Ref_as_Int_arrayfillinst(Ref_as_Int st, InstanceField f) {
250         Arrays.fill(st.arr, f.f);
251     }
252 
253     @Benchmark
254     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
255     public void Obj_to_Int_as_Int_arrayfillinst(Int_as_Int st, InstanceField f) {
256         Arrays.fill(st.arr, f.f);
257     }
258 
259     @Benchmark
260     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
261     public void Obj_to_Val_as_Obj_arrayfillinst(Val_as_Obj st, InstanceField f) {
262         Arrays.fill(st.arr, f.f);
263     }
264 
265     @Benchmark
266     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
267     public void Obj_to_Ref_as_Obj_arrayfillinst(Ref_as_Obj st, InstanceField f) {
268         Arrays.fill(st.arr, f.f);
269     }
270 
271     @Benchmark
272     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
273     public void Obj_to_Int_as_Obj_arrayfillinst(Int_as_Obj st, InstanceField f) {
274         Arrays.fill(st.arr, f.f);
275     }
276 
277     @Benchmark
278     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
279     public void Obj_to_Obj_as_Obj_arrayfillinst(Obj_as_Obj st, InstanceField f) {
280         Arrays.fill(st.arr, f.f);
281     }
282 
283 }