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.Scope; 28 import org.openjdk.jmh.annotations.Setup; 29 import org.openjdk.jmh.annotations.State; 30 31 import java.util.BitSet; 32 import java.util.Random; 33 34 public class StatesQ64long { 35 36 public static final int SIZE = 100; 37 38 private static BitSet indices(Random rnd, int bound, int size) { 39 return rnd.ints(0, bound) 40 .distinct() 41 .limit(size) 42 .collect(BitSet::new, BitSet::set, BitSet::or); 43 } 44 45 private static void populate(Object[] arr1, Object[] arr2, int eq) { 46 BitSet eqset = (eq > 0 && eq < 100) ? indices(new Random(42), SIZE, (eq * SIZE) / 100) : null; 47 for (int i = 0; i < SIZE; i++) { 48 if (eq > 0 && (eq >= 100 || eqset.get(i))) { 49 arr2[i] = arr1[i] = new Q64long(i); 50 } else { 51 arr1[i] = new Q64long(2 * i); 52 arr2[i] = new Q64long(2 * i + 1); 53 } 54 } 55 } 56 57 @State(Scope.Thread) 58 public abstract static class ObjState { 59 Object[] arr1, arr2; 60 } 61 62 @State(Scope.Thread) 63 public abstract static class IntState { 64 Int64[] arr1, arr2; 65 } 66 67 @State(Scope.Thread) 68 public abstract static class RefState { 69 Q64long[] arr1, arr2; 70 } 71 72 @State(Scope.Thread) 73 public abstract static class ValState { 74 Q64long[] arr1, arr2; 75 } 76 77 public static class ObjState00 extends ObjState { 78 @Setup 79 public void setup() { 80 arr1 = new Object[SIZE]; 81 arr2 = new Object[SIZE]; 82 populate(arr1, arr2, 0); 83 } 84 85 } 86 87 public static class ObjState25 extends ObjState { 88 @Setup 89 public void setup() { 90 arr1 = new Object[SIZE]; 91 arr2 = new Object[SIZE]; 92 populate(arr1, arr2, 25); 93 } 94 95 } 96 97 public static class ObjState50 extends ObjState { 98 @Setup 99 public void setup() { 100 arr1 = new Object[SIZE]; 101 arr2 = new Object[SIZE]; 102 populate(arr1, arr2, 50); 103 } 104 105 } 106 107 public static class ObjState75 extends ObjState { 108 @Setup 109 public void setup() { 110 arr1 = new Object[SIZE]; 111 arr2 = new Object[SIZE]; 112 populate(arr1, arr2, 75); 113 } 114 115 } 116 117 public static class ObjState100 extends ObjState { 118 @Setup 119 public void setup() { 120 arr1 = new Object[SIZE]; 121 arr2 = new Object[SIZE]; 122 populate(arr1, arr2, 100); 123 } 124 } 125 126 public static class IntState00 extends IntState { 127 @Setup 128 public void setup() { 129 arr1 = new Int64[SIZE]; 130 arr2 = new Int64[SIZE]; 131 populate(arr1, arr2, 0); 132 } 133 } 134 135 public static class IntState25 extends IntState { 136 @Setup 137 public void setup() { 138 arr1 = new Int64[SIZE]; 139 arr2 = new Int64[SIZE]; 140 populate(arr1, arr2, 25); 141 } 142 } 143 144 public static class IntState50 extends IntState { 145 @Setup 146 public void setup() { 147 arr1 = new Int64[SIZE]; 148 arr2 = new Int64[SIZE]; 149 populate(arr1, arr2, 50); 150 } 151 } 152 153 public static class IntState75 extends IntState { 154 @Setup 155 public void setup() { 156 arr1 = new Int64[SIZE]; 157 arr2 = new Int64[SIZE]; 158 populate(arr1, arr2, 75); 159 } 160 } 161 162 public static class IntState100 extends IntState { 163 @Setup 164 public void setup() { 165 arr1 = new Int64[SIZE]; 166 arr2 = new Int64[SIZE]; 167 populate(arr1, arr2, 100); 168 } 169 } 170 171 public static class RefState00 extends RefState { 172 @Setup 173 public void setup() { 174 arr1 = new Q64long[SIZE]; 175 arr2 = new Q64long[SIZE]; 176 populate(arr1, arr2, 0); 177 } 178 } 179 180 public static class RefState25 extends RefState { 181 @Setup 182 public void setup() { 183 arr1 = new Q64long[SIZE]; 184 arr2 = new Q64long[SIZE]; 185 populate(arr1, arr2, 25); 186 } 187 } 188 189 public static class RefState50 extends RefState { 190 @Setup 191 public void setup() { 192 arr1 = new Q64long[SIZE]; 193 arr2 = new Q64long[SIZE]; 194 populate(arr1, arr2, 50); 195 } 196 } 197 198 public static class RefState75 extends RefState { 199 @Setup 200 public void setup() { 201 arr1 = new Q64long[SIZE]; 202 arr2 = new Q64long[SIZE]; 203 populate(arr1, arr2, 75); 204 } 205 } 206 207 public static class RefState100 extends RefState { 208 @Setup 209 public void setup() { 210 arr1 = new Q64long[SIZE]; 211 arr2 = new Q64long[SIZE]; 212 populate(arr1, arr2, 100); 213 } 214 } 215 216 public static class ValState00 extends ValState { 217 @Setup 218 public void setup() { 219 arr1 = new Q64long[SIZE]; 220 arr2 = new Q64long[SIZE]; 221 populate(arr1, arr2, 0); 222 } 223 } 224 225 public static class ValState25 extends ValState { 226 @Setup 227 public void setup() { 228 arr1 = new Q64long[SIZE]; 229 arr2 = new Q64long[SIZE]; 230 populate(arr1, arr2, 25); 231 } 232 } 233 234 public static class ValState50 extends ValState { 235 @Setup 236 public void setup() { 237 arr1 = new Q64long[SIZE]; 238 arr2 = new Q64long[SIZE]; 239 populate(arr1, arr2, 50); 240 } 241 } 242 243 public static class ValState75 extends ValState { 244 @Setup 245 public void setup() { 246 arr1 = new Q64long[SIZE]; 247 arr2 = new Q64long[SIZE]; 248 populate(arr1, arr2, 75); 249 } 250 } 251 252 public static class ValState100 extends ValState { 253 @Setup 254 public void setup() { 255 arr1 = new Q64long[SIZE]; 256 arr2 = new Q64long[SIZE]; 257 populate(arr1, arr2, 100); 258 } 259 } 260 261 }