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