|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | +package org.openjdk.bench.vm.compiler; |
| 25 | + |
| 26 | +import org.openjdk.jmh.annotations.*; |
| 27 | +import org.openjdk.jmh.infra.Blackhole; |
| 28 | +import org.openjdk.jmh.runner.Runner; |
| 29 | +import org.openjdk.jmh.runner.options.Options; |
| 30 | +import org.openjdk.jmh.runner.options.OptionsBuilder; |
| 31 | + |
| 32 | +import java.lang.invoke.MethodHandles; |
| 33 | +import java.lang.invoke.VarHandle; |
| 34 | +import java.lang.reflect.Field; |
| 35 | +import java.nio.ByteOrder; |
| 36 | +import java.util.Random; |
| 37 | +import java.util.concurrent.TimeUnit; |
| 38 | + |
| 39 | +import jdk.internal.misc.Unsafe; |
| 40 | + |
| 41 | +@BenchmarkMode(Mode.AverageTime) |
| 42 | +@OutputTimeUnit(TimeUnit.NANOSECONDS) |
| 43 | +@State(Scope.Thread) |
| 44 | +@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) |
| 45 | +@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS) |
| 46 | +@Fork(value = 3, jvmArgsAppend = {"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"}) |
| 47 | +public class MergeStoreBench { |
| 48 | + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); |
| 49 | + |
| 50 | + final static VarHandle INT_L = MethodHandles.byteArrayViewVarHandle(int[].class , ByteOrder.LITTLE_ENDIAN); |
| 51 | + final static VarHandle INT_B = MethodHandles.byteArrayViewVarHandle(int[].class , ByteOrder.BIG_ENDIAN); |
| 52 | + final static VarHandle LONG_L = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.LITTLE_ENDIAN); |
| 53 | + final static VarHandle LONG_B = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.BIG_ENDIAN); |
| 54 | + final static VarHandle CHAR_L = MethodHandles.byteArrayViewVarHandle(char[].class, ByteOrder.LITTLE_ENDIAN); |
| 55 | + final static VarHandle CHAR_B = MethodHandles.byteArrayViewVarHandle(char[].class, ByteOrder.BIG_ENDIAN); |
| 56 | + |
| 57 | + final static int NUMBERS = 8192; |
| 58 | + |
| 59 | + final byte[] bytes4 = new byte[NUMBERS * 4]; |
| 60 | + final byte[] bytes8 = new byte[NUMBERS * 8]; |
| 61 | + final int [] ints = new int [NUMBERS ]; |
| 62 | + final long[] longs = new long[NUMBERS ]; |
| 63 | + final char[] chars = new char[NUMBERS ]; |
| 64 | + |
| 65 | + @Setup |
| 66 | + public void setup() { |
| 67 | + Random r = new Random(); |
| 68 | + for (int i = 0; i < ints.length; i++) { |
| 69 | + ints[i] = r.nextInt(); |
| 70 | + INT_L.set(bytes4, i * 4, i); |
| 71 | + } |
| 72 | + |
| 73 | + for (int i = 0; i < longs.length; i++) { |
| 74 | + longs[i] = r.nextLong(); |
| 75 | + LONG_L.set(bytes8, i * 8, i); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + /* |
| 80 | + * The names of these cases have the following `B/L/V/U` suffixes, which are: |
| 81 | + * ``` |
| 82 | + * B BigEndian |
| 83 | + * L LittleEndian |
| 84 | + * V VarHandle |
| 85 | + * U Unsafe |
| 86 | + * R ReverseBytes |
| 87 | + * C Unsafe.getChar & putChar |
| 88 | + * S Unsafe.getShort & putShort |
| 89 | + * ``` |
| 90 | + */ |
| 91 | + |
| 92 | + @Benchmark |
| 93 | + public void getIntB(Blackhole BH) { |
| 94 | + int sum = 0; |
| 95 | + for (int i = 0; i < ints.length; i++) { |
| 96 | + sum += getIntB(bytes4, i * 4); |
| 97 | + } |
| 98 | + BH.consume(sum); |
| 99 | + } |
| 100 | + |
| 101 | + @Benchmark |
| 102 | + public void getIntBU(Blackhole BH) { |
| 103 | + int sum = 0; |
| 104 | + for (int i = 0; i < ints.length; i++) { |
| 105 | + sum += getIntBU(bytes4, i * 4); |
| 106 | + } |
| 107 | + BH.consume(sum); |
| 108 | + } |
| 109 | + |
| 110 | + @Benchmark |
| 111 | + public void getIntBV(Blackhole BH) { |
| 112 | + int sum = 0; |
| 113 | + for (int i = 0; i < ints.length; i++) { |
| 114 | + sum += (int) INT_B.get(bytes4, i * 4); |
| 115 | + } |
| 116 | + BH.consume(sum); |
| 117 | + } |
| 118 | + |
| 119 | + @Benchmark |
| 120 | + public void getIntL(Blackhole BH) { |
| 121 | + int sum = 0; |
| 122 | + for (int i = 0; i < ints.length; i++) { |
| 123 | + sum += getIntL(bytes4, i * 4); |
| 124 | + } |
| 125 | + BH.consume(sum); |
| 126 | + } |
| 127 | + |
| 128 | + @Benchmark |
| 129 | + public void getIntLU(Blackhole BH) { |
| 130 | + int sum = 0; |
| 131 | + for (int i = 0; i < ints.length; i++) { |
| 132 | + sum += getIntLU(bytes4, i * 4); |
| 133 | + } |
| 134 | + BH.consume(sum); |
| 135 | + } |
| 136 | + |
| 137 | + @Benchmark |
| 138 | + public void getIntLV(Blackhole BH) { |
| 139 | + int sum = 0; |
| 140 | + for (int i = 0; i < ints.length; i++) { |
| 141 | + sum += (int) INT_L.get(bytes4, i * 4); |
| 142 | + } |
| 143 | + BH.consume(sum); |
| 144 | + } |
| 145 | + |
| 146 | + @Benchmark |
| 147 | + public void getIntRB(Blackhole BH) { |
| 148 | + int sum = 0; |
| 149 | + for (int i = 0; i < ints.length; i++) { |
| 150 | + sum += getIntRB(bytes4, i * 4); |
| 151 | + } |
| 152 | + BH.consume(sum); |
| 153 | + } |
| 154 | + |
| 155 | + @Benchmark |
| 156 | + public void getIntRBU(Blackhole BH) { |
| 157 | + int sum = 0; |
| 158 | + for (int i = 0; i < ints.length; i++) { |
| 159 | + sum += getIntRBU(bytes4, i * 4); |
| 160 | + } |
| 161 | + BH.consume(sum); |
| 162 | + } |
| 163 | + |
| 164 | + @Benchmark |
| 165 | + public void getIntRL(Blackhole BH) { |
| 166 | + int sum = 0; |
| 167 | + for (int i = 0; i < ints.length; i++) { |
| 168 | + sum += getIntRL(bytes4, i * 4); |
| 169 | + } |
| 170 | + BH.consume(sum); |
| 171 | + } |
| 172 | + |
| 173 | + @Benchmark |
| 174 | + public void getIntRLU(Blackhole BH) { |
| 175 | + int sum = 0; |
| 176 | + for (int i = 0; i < ints.length; i++) { |
| 177 | + sum += getIntRLU(bytes4, i * 4); |
| 178 | + } |
| 179 | + BH.consume(sum); |
| 180 | + } |
| 181 | + |
| 182 | + @Benchmark |
| 183 | + public void getIntRU(Blackhole BH) { |
| 184 | + int sum = 0; |
| 185 | + for (int i = 0; i < ints.length; i++) { |
| 186 | + sum += Integer.reverseBytes( |
| 187 | + UNSAFE.getInt(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 4)); |
| 188 | + } |
| 189 | + BH.consume(sum); |
| 190 | + } |
| 191 | + |
| 192 | + @Benchmark |
| 193 | + public void getIntU(Blackhole BH) { |
| 194 | + int sum = 0; |
| 195 | + for (int i = 0; i < ints.length; i++) { |
| 196 | + sum += UNSAFE.getInt(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 4); |
| 197 | + } |
| 198 | + BH.consume(sum); |
| 199 | + } |
| 200 | + |
| 201 | + @Benchmark |
| 202 | + public void setIntB(Blackhole BH) { |
| 203 | + int sum = 0; |
| 204 | + for (int i = 0; i < ints.length; i++) { |
| 205 | + int v = ints[i]; |
| 206 | + setIntB(bytes4, i * 4, v); |
| 207 | + sum += v; |
| 208 | + } |
| 209 | + BH.consume(sum); |
| 210 | + } |
| 211 | + |
| 212 | + @Benchmark |
| 213 | + public void setIntBU(Blackhole BH) { |
| 214 | + int sum = 0; |
| 215 | + for (int i = 0; i < ints.length; i++) { |
| 216 | + int v = ints[i]; |
| 217 | + setIntBU(bytes4, i * 4, v); |
| 218 | + sum += v; |
| 219 | + } |
| 220 | + BH.consume(sum); |
| 221 | + } |
| 222 | + |
| 223 | + @Benchmark |
| 224 | + public void setIntBV(Blackhole BH) { |
| 225 | + int sum = 0; |
| 226 | + for (int i = 0; i < ints.length; i++) { |
| 227 | + int v = ints[i]; |
| 228 | + INT_B.set(bytes4, i * 4, v); |
| 229 | + sum += v; |
| 230 | + } |
| 231 | + BH.consume(sum); |
| 232 | + } |
| 233 | + |
| 234 | + @Benchmark |
| 235 | + public void setIntL(Blackhole BH) { |
| 236 | + int sum = 0; |
| 237 | + for (int i = 0; i < ints.length; i++) { |
| 238 | + int v = ints[i]; |
| 239 | + setIntL(bytes4, i * 4, v); |
| 240 | + sum += v; |
| 241 | + } |
| 242 | + BH.consume(sum); |
| 243 | + } |
| 244 | + |
| 245 | + @Benchmark |
| 246 | + public void setIntLU(Blackhole BH) { |
| 247 | + int sum = 0; |
| 248 | + for (int i = 0; i < ints.length; i++) { |
| 249 | + int v = ints[i]; |
| 250 | + setIntLU(bytes4, i * 4, v); |
| 251 | + sum += v; |
| 252 | + } |
| 253 | + BH.consume(sum); |
| 254 | + } |
| 255 | + |
| 256 | + @Benchmark |
| 257 | + public void setIntLV(Blackhole BH) { |
| 258 | + long sum = 0; |
| 259 | + for (int i = 0; i < ints.length; i++) { |
| 260 | + int v = ints[i]; |
| 261 | + INT_L.set(bytes4, i * 4, v); |
| 262 | + sum += v; |
| 263 | + } |
| 264 | + BH.consume(sum); |
| 265 | + } |
| 266 | + |
| 267 | + @Benchmark |
| 268 | + public void setIntRB(Blackhole BH) { |
| 269 | + long sum = 0; |
| 270 | + for (int i = 0; i < ints.length; i++) { |
| 271 | + int v = ints[i]; |
| 272 | + setIntRB(bytes4, i * 4, ints[i]); |
| 273 | + sum += v; |
| 274 | + } |
| 275 | + BH.consume(sum); |
| 276 | + } |
| 277 | + |
| 278 | + @Benchmark |
| 279 | + public void setIntRBU(Blackhole BH) { |
| 280 | + long sum = 0; |
| 281 | + for (int i = 0; i < ints.length; i++) { |
| 282 | + int v = ints[i]; |
| 283 | + setIntRBU(bytes4, i * 4, v); |
| 284 | + sum += v; |
| 285 | + } |
| 286 | + BH.consume(sum); |
| 287 | + } |
| 288 | + |
| 289 | + @Benchmark |
| 290 | + public void setIntRL(Blackhole BH) { |
| 291 | + long sum = 0; |
| 292 | + for (int i = 0; i < ints.length; i++) { |
| 293 | + int v = ints[i]; |
| 294 | + setIntRL(bytes4, i * 4, ints[i]); |
| 295 | + sum += v; |
| 296 | + } |
| 297 | + BH.consume(sum); |
| 298 | + } |
| 299 | + |
| 300 | + @Benchmark |
| 301 | + public void setIntRLU(Blackhole BH) { |
| 302 | + long sum = 0; |
| 303 | + for (int i = 0; i < ints.length; i++) { |
| 304 | + int v = ints[i]; |
| 305 | + setIntRLU(bytes4, i * 4, v); |
| 306 | + sum += v; |
| 307 | + } |
| 308 | + BH.consume(sum); |
| 309 | + } |
| 310 | + |
| 311 | + @Benchmark |
| 312 | + public void setIntRU(Blackhole BH) { |
| 313 | + long sum = 0; |
| 314 | + for (int i = 0; i < ints.length; i++) { |
| 315 | + int v = ints[i]; |
| 316 | + v = Integer.reverseBytes(v); |
| 317 | + UNSAFE.putInt(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 4, v); |
| 318 | + sum += v; |
| 319 | + } |
| 320 | + BH.consume(sum); |
| 321 | + } |
| 322 | + |
| 323 | + @Benchmark |
| 324 | + public void setIntU(Blackhole BH) { |
| 325 | + long sum = 0; |
| 326 | + for (int i = 0; i < ints.length; i++) { |
| 327 | + int v = ints[i]; |
| 328 | + UNSAFE.putInt(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 4, v); |
| 329 | + sum += v; |
| 330 | + } |
| 331 | + BH.consume(sum); |
| 332 | + } |
| 333 | + |
| 334 | + @Benchmark |
| 335 | + public void getLongB(Blackhole BH) { |
| 336 | + long sum = 0; |
| 337 | + for (int i = 0; i < longs.length; i++) { |
| 338 | + sum += getLongB(bytes8, i * 8); |
| 339 | + } |
| 340 | + BH.consume(sum); |
| 341 | + } |
| 342 | + |
| 343 | + @Benchmark |
| 344 | + public void getLongBU(Blackhole BH) { |
| 345 | + long sum = 0; |
| 346 | + for (int i = 0; i < longs.length; i++) { |
| 347 | + sum += getLongBU(bytes8, i * 8); |
| 348 | + } |
| 349 | + BH.consume(sum); |
| 350 | + } |
| 351 | + |
| 352 | + @Benchmark |
| 353 | + public void getLongBV(Blackhole BH) { |
| 354 | + long sum = 0; |
| 355 | + for (int i = 0; i < ints.length; i++) { |
| 356 | + sum += (long) LONG_B.get(bytes8, i * 8); |
| 357 | + } |
| 358 | + BH.consume(sum); |
| 359 | + } |
| 360 | + |
| 361 | + @Benchmark |
| 362 | + public void getLongL(Blackhole BH) { |
| 363 | + long sum = 0; |
| 364 | + for (int i = 0; i < longs.length; i++) { |
| 365 | + sum += getLongL(bytes8, i * 8); |
| 366 | + } |
| 367 | + BH.consume(sum); |
| 368 | + } |
| 369 | + |
| 370 | + @Benchmark |
| 371 | + public void getLongLU(Blackhole BH) { |
| 372 | + long sum = 0; |
| 373 | + for (int i = 0; i < longs.length; i++) { |
| 374 | + sum += getLongLU(bytes8, i * 8); |
| 375 | + } |
| 376 | + BH.consume(sum); |
| 377 | + } |
| 378 | + |
| 379 | + @Benchmark |
| 380 | + public void getLongLV(Blackhole BH) { |
| 381 | + long sum = 0; |
| 382 | + for (int i = 0; i < ints.length; i++) { |
| 383 | + sum += (long) LONG_L.get(bytes8, i * 8); |
| 384 | + } |
| 385 | + BH.consume(sum); |
| 386 | + } |
| 387 | + |
| 388 | + @Benchmark |
| 389 | + public void getLongRB(Blackhole BH) { |
| 390 | + long sum = 0; |
| 391 | + for (int i = 0; i < longs.length; i++) { |
| 392 | + sum += getLongRB(bytes8, i * 8); |
| 393 | + } |
| 394 | + BH.consume(sum); |
| 395 | + } |
| 396 | + |
| 397 | + @Benchmark |
| 398 | + public void getLongRBU(Blackhole BH) { |
| 399 | + long sum = 0; |
| 400 | + for (int i = 0; i < longs.length; i++) { |
| 401 | + sum += getLongRBU(bytes8, i * 8); |
| 402 | + } |
| 403 | + BH.consume(sum); |
| 404 | + } |
| 405 | + |
| 406 | + @Benchmark |
| 407 | + public void getLongRL(Blackhole BH) { |
| 408 | + long sum = 0; |
| 409 | + for (int i = 0; i < longs.length; i++) { |
| 410 | + sum += getLongRL(bytes8, i * 8); |
| 411 | + } |
| 412 | + BH.consume(sum); |
| 413 | + } |
| 414 | + |
| 415 | + @Benchmark |
| 416 | + public void getLongRLU(Blackhole BH) { |
| 417 | + long sum = 0; |
| 418 | + for (int i = 0; i < longs.length; i++) { |
| 419 | + sum += getLongRLU(bytes8, i * 8); |
| 420 | + } |
| 421 | + BH.consume(sum); |
| 422 | + } |
| 423 | + |
| 424 | + @Benchmark |
| 425 | + public void getLongRU(Blackhole BH) { |
| 426 | + long sum = 0; |
| 427 | + for (int i = 0; i < longs.length; i++) { |
| 428 | + sum += Long.reverseBytes( |
| 429 | + UNSAFE.getLong(bytes8, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 8)); |
| 430 | + } |
| 431 | + BH.consume(sum); |
| 432 | + } |
| 433 | + |
| 434 | + @Benchmark |
| 435 | + public void getLongU(Blackhole BH) { |
| 436 | + long sum = 0; |
| 437 | + for (int i = 0; i < longs.length; i++) { |
| 438 | + sum += UNSAFE.getLong(bytes8, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 8); |
| 439 | + } |
| 440 | + BH.consume(sum); |
| 441 | + } |
| 442 | + |
| 443 | + @Benchmark |
| 444 | + public void setLongB(Blackhole BH) { |
| 445 | + long sum = 0; |
| 446 | + for (int i = 0; i < longs.length; i++) { |
| 447 | + long v = longs[i]; |
| 448 | + setLongB(bytes8, i * 8, v); |
| 449 | + sum += v; |
| 450 | + } |
| 451 | + BH.consume(sum); |
| 452 | + } |
| 453 | + |
| 454 | + @Benchmark |
| 455 | + public void setLongBU(Blackhole BH) { |
| 456 | + long sum = 0; |
| 457 | + for (int i = 0; i < longs.length; i++) { |
| 458 | + long v = longs[i]; |
| 459 | + setLongBU(bytes8, i * 8, v); |
| 460 | + sum += v; |
| 461 | + } |
| 462 | + BH.consume(sum); |
| 463 | + } |
| 464 | + |
| 465 | + @Benchmark |
| 466 | + public void setLongBV(Blackhole BH) { |
| 467 | + long sum = 0; |
| 468 | + for (int i = 0; i < longs.length; i++) { |
| 469 | + long v = longs[i]; |
| 470 | + LONG_B.set(bytes8, i * 8, v); |
| 471 | + sum += v; |
| 472 | + } |
| 473 | + BH.consume(sum); |
| 474 | + } |
| 475 | + |
| 476 | + @Benchmark |
| 477 | + public void setLongL(Blackhole BH) { |
| 478 | + long sum = 0; |
| 479 | + for (int i = 0; i < longs.length; i++) { |
| 480 | + long v = longs[i]; |
| 481 | + setLongL(bytes8, i * 8, v); |
| 482 | + sum += v; |
| 483 | + } |
| 484 | + BH.consume(sum); |
| 485 | + } |
| 486 | + |
| 487 | + @Benchmark |
| 488 | + public void setLongLU(Blackhole BH) { |
| 489 | + long sum = 0; |
| 490 | + for (int i = 0; i < longs.length; i++) { |
| 491 | + long v = longs[i]; |
| 492 | + setLongLU(bytes8, i * 8, v); |
| 493 | + sum += v; |
| 494 | + } |
| 495 | + BH.consume(sum); |
| 496 | + } |
| 497 | + |
| 498 | + @Benchmark |
| 499 | + public void setLongLV(Blackhole BH) { |
| 500 | + long sum = 0; |
| 501 | + for (int i = 0; i < longs.length; i++) { |
| 502 | + long v = longs[i]; |
| 503 | + LONG_L.set(bytes8, i * 8, v); |
| 504 | + sum += v; |
| 505 | + } |
| 506 | + BH.consume(sum); |
| 507 | + } |
| 508 | + |
| 509 | + @Benchmark |
| 510 | + public void setLongRB(Blackhole BH) { |
| 511 | + long sum = 0; |
| 512 | + for (int i = 0; i < longs.length; i++) { |
| 513 | + long v = longs[i]; |
| 514 | + setLongRB(bytes8, i * 8, v); |
| 515 | + sum += v; |
| 516 | + } |
| 517 | + BH.consume(sum); |
| 518 | + } |
| 519 | + |
| 520 | + @Benchmark |
| 521 | + public void setLongRBU(Blackhole BH) { |
| 522 | + long sum = 0; |
| 523 | + for (int i = 0; i < longs.length; i++) { |
| 524 | + long v = longs[i]; |
| 525 | + setLongRBU(bytes8, i * 8, v); |
| 526 | + sum += v; |
| 527 | + } |
| 528 | + BH.consume(sum); |
| 529 | + } |
| 530 | + |
| 531 | + @Benchmark |
| 532 | + public void setLongRL(Blackhole BH) { |
| 533 | + long sum = 0; |
| 534 | + for (int i = 0; i < longs.length; i++) { |
| 535 | + long v = longs[i]; |
| 536 | + setLongRL(bytes8, i * 8, v); |
| 537 | + sum += v; |
| 538 | + } |
| 539 | + BH.consume(sum); |
| 540 | + } |
| 541 | + |
| 542 | + @Benchmark |
| 543 | + public void setLongRLU(Blackhole BH) { |
| 544 | + long sum = 0; |
| 545 | + for (int i = 0; i < longs.length; i++) { |
| 546 | + long v = longs[i]; |
| 547 | + setLongRLU(bytes8, i * 8, v); |
| 548 | + sum += v; |
| 549 | + } |
| 550 | + BH.consume(sum); |
| 551 | + } |
| 552 | + |
| 553 | + @Benchmark |
| 554 | + public void setLongRU(Blackhole BH) { |
| 555 | + long sum = 0; |
| 556 | + for (int i = 0; i < longs.length; i++) { |
| 557 | + long v = longs[i]; |
| 558 | + v = Long.reverseBytes(v); |
| 559 | + UNSAFE.putLong(bytes8, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 8, v); |
| 560 | + sum += v; |
| 561 | + } |
| 562 | + BH.consume(sum); |
| 563 | + } |
| 564 | + |
| 565 | + @Benchmark |
| 566 | + public void setLongU(Blackhole BH) { |
| 567 | + long sum = 0; |
| 568 | + for (int i = 0; i < longs.length; i++) { |
| 569 | + long v = longs[i]; |
| 570 | + UNSAFE.putLong(bytes8, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 8, v); |
| 571 | + sum += v; |
| 572 | + } |
| 573 | + BH.consume(sum); |
| 574 | + } |
| 575 | + |
| 576 | + @Benchmark |
| 577 | + public void getCharB(Blackhole BH) { |
| 578 | + long sum = 0; |
| 579 | + for (int i = 0; i < longs.length; i++) { |
| 580 | + char c = getCharB(bytes4, i); |
| 581 | + sum += c; |
| 582 | + } |
| 583 | + BH.consume(sum); |
| 584 | + } |
| 585 | + |
| 586 | + @Benchmark |
| 587 | + public void getCharBV(Blackhole BH) { |
| 588 | + long sum = 0; |
| 589 | + for (int i = 0; i < longs.length; i++) { |
| 590 | + char c = (char) CHAR_B.get(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 2); |
| 591 | + sum += c; |
| 592 | + } |
| 593 | + BH.consume(sum); |
| 594 | + } |
| 595 | + |
| 596 | + @Benchmark |
| 597 | + public void getCharBU(Blackhole BH) { |
| 598 | + long sum = 0; |
| 599 | + for (int i = 0; i < longs.length; i++) { |
| 600 | + char c = getCharBU(bytes4, i); |
| 601 | + sum += c; |
| 602 | + } |
| 603 | + BH.consume(sum); |
| 604 | + } |
| 605 | + |
| 606 | + @Benchmark |
| 607 | + public void getCharL(Blackhole BH) { |
| 608 | + long sum = 0; |
| 609 | + for (int i = 0; i < longs.length; i++) { |
| 610 | + char c = getCharL(bytes4, i); |
| 611 | + sum += c; |
| 612 | + } |
| 613 | + BH.consume(sum); |
| 614 | + } |
| 615 | + @Benchmark |
| 616 | + public void getCharLU(Blackhole BH) { |
| 617 | + long sum = 0; |
| 618 | + for (int i = 0; i < longs.length; i++) { |
| 619 | + char c = getCharLU(bytes4, i); |
| 620 | + sum += c; |
| 621 | + } |
| 622 | + BH.consume(sum); |
| 623 | + } |
| 624 | + |
| 625 | + |
| 626 | + @Benchmark |
| 627 | + public void getCharLV(Blackhole BH) { |
| 628 | + long sum = 0; |
| 629 | + for (int i = 0; i < longs.length; i++) { |
| 630 | + char c = (char) CHAR_L.get(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 2); |
| 631 | + sum += c; |
| 632 | + } |
| 633 | + BH.consume(sum); |
| 634 | + } |
| 635 | + |
| 636 | + @Benchmark |
| 637 | + public void getCharC(Blackhole BH) { |
| 638 | + long sum = 0; |
| 639 | + for (int i = 0; i < longs.length; i++) { |
| 640 | + char c = UNSAFE.getChar(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 2); |
| 641 | + sum += c; |
| 642 | + } |
| 643 | + BH.consume(sum); |
| 644 | + } |
| 645 | + |
| 646 | + @Benchmark |
| 647 | + public void setCharBS(Blackhole BH) { |
| 648 | + long sum = 0; |
| 649 | + for (int i = 0; i < chars.length; i++) { |
| 650 | + char c = chars[i]; |
| 651 | + putShortB(bytes4, i * 2, c); |
| 652 | + sum += c; |
| 653 | + } |
| 654 | + BH.consume(sum); |
| 655 | + } |
| 656 | + |
| 657 | + @Benchmark |
| 658 | + public void setCharBV(Blackhole BH) { |
| 659 | + long sum = 0; |
| 660 | + for (int i = 0; i < chars.length; i++) { |
| 661 | + char c = chars[i]; |
| 662 | + CHAR_B.set(bytes4, i * 2, c); |
| 663 | + sum += c; |
| 664 | + } |
| 665 | + BH.consume(sum); |
| 666 | + } |
| 667 | + |
| 668 | + @Benchmark |
| 669 | + public void setCharLS(Blackhole BH) { |
| 670 | + long sum = 0; |
| 671 | + for (int i = 0; i < chars.length; i++) { |
| 672 | + char c = chars[i]; |
| 673 | + putShortL(bytes4, i * 2, c); |
| 674 | + sum += c; |
| 675 | + } |
| 676 | + BH.consume(sum); |
| 677 | + } |
| 678 | + |
| 679 | + @Benchmark |
| 680 | + public void setCharLV(Blackhole BH) { |
| 681 | + long sum = 0; |
| 682 | + for (int i = 0; i < chars.length; i++) { |
| 683 | + char c = chars[i]; |
| 684 | + CHAR_L.set(bytes4, i * 2, c); |
| 685 | + sum += c; |
| 686 | + } |
| 687 | + BH.consume(sum); |
| 688 | + } |
| 689 | + |
| 690 | + @Benchmark |
| 691 | + public void setCharC(Blackhole BH) { |
| 692 | + long sum = 0; |
| 693 | + for (int i = 0; i < chars.length; i++) { |
| 694 | + char c = chars[i]; |
| 695 | + UNSAFE.putChar(bytes4, Unsafe.ARRAY_BYTE_BASE_OFFSET + i * 2, c); |
| 696 | + sum += c; |
| 697 | + } |
| 698 | + BH.consume(sum); |
| 699 | + } |
| 700 | + |
| 701 | + /* |
| 702 | + * putChars4 Test whether four constant chars can be MergeStored |
| 703 | + * |
| 704 | + */ |
| 705 | + @Benchmark |
| 706 | + public void putChars4B(Blackhole BH) { |
| 707 | + long sum = 0; |
| 708 | + for (int i = 0; i < longs.length; i++) { |
| 709 | + putChars4B(bytes8, i * 4); |
| 710 | + sum += longs[i]; |
| 711 | + } |
| 712 | + BH.consume(sum); |
| 713 | + } |
| 714 | + |
| 715 | + @Benchmark |
| 716 | + public void putChars4BU(Blackhole BH) { |
| 717 | + long sum = 0; |
| 718 | + for (int i = 0; i < longs.length; i++) { |
| 719 | + putChars4BU(bytes8, i * 4); |
| 720 | + sum += longs[i]; |
| 721 | + } |
| 722 | + BH.consume(sum); |
| 723 | + } |
| 724 | + |
| 725 | + @Benchmark |
| 726 | + public void putChars4BV(Blackhole BH) { |
| 727 | + long sum = 0; |
| 728 | + for (int i = 0; i < longs.length; i++) { |
| 729 | + putChars4BV(bytes8, i * 4); |
| 730 | + sum += longs[i]; |
| 731 | + } |
| 732 | + BH.consume(sum); |
| 733 | + } |
| 734 | + |
| 735 | + @Benchmark |
| 736 | + public void putChars4L(Blackhole BH) { |
| 737 | + long sum = 0; |
| 738 | + for (int i = 0; i < longs.length; i++) { |
| 739 | + putChars4L(bytes8, i * 4); |
| 740 | + sum += longs[i]; |
| 741 | + } |
| 742 | + BH.consume(sum); |
| 743 | + } |
| 744 | + |
| 745 | + @Benchmark |
| 746 | + public void putChars4LU(Blackhole BH) { |
| 747 | + long sum = 0; |
| 748 | + for (int i = 0; i < longs.length; i++) { |
| 749 | + putChars4LU(bytes8, i * 4); |
| 750 | + sum += longs[i]; |
| 751 | + } |
| 752 | + BH.consume(sum); |
| 753 | + } |
| 754 | + |
| 755 | + @Benchmark |
| 756 | + public void putChars4LV(Blackhole BH) { |
| 757 | + long sum = 0; |
| 758 | + for (int i = 0; i < longs.length; i++) { |
| 759 | + putChars4LV(bytes8, i * 4); |
| 760 | + sum += longs[i]; |
| 761 | + } |
| 762 | + BH.consume(sum); |
| 763 | + } |
| 764 | + |
| 765 | + @Benchmark |
| 766 | + public void putChars4C(Blackhole BH) { |
| 767 | + long sum = 0; |
| 768 | + for (int i = 0; i < longs.length; i++) { |
| 769 | + putChars4C(bytes8, i * 4); |
| 770 | + sum += longs[i]; |
| 771 | + } |
| 772 | + BH.consume(sum); |
| 773 | + } |
| 774 | + |
| 775 | + @Benchmark |
| 776 | + public void putChars4S(Blackhole BH) { |
| 777 | + long sum = 0; |
| 778 | + for (int i = 0; i < longs.length; i++) { |
| 779 | + putChars4S(bytes8, i * 4); |
| 780 | + sum += longs[i]; |
| 781 | + } |
| 782 | + BH.consume(sum); |
| 783 | + } |
| 784 | + |
| 785 | + static int getIntB(byte[] array, int offset) { |
| 786 | + return ((array[offset ] & 0xff) << 24) |
| 787 | + | ((array[offset + 1] & 0xff) << 16) |
| 788 | + | ((array[offset + 2] & 0xff) << 8) |
| 789 | + | ((array[offset + 3] & 0xff) ); |
| 790 | + } |
| 791 | + |
| 792 | + static int getIntBU(byte[] array, int offset) { |
| 793 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 794 | + return ((UNSAFE.getByte(array, address ) & 0xff) << 24) |
| 795 | + | ((UNSAFE.getByte(array, address + 1) & 0xff) << 16) |
| 796 | + | ((UNSAFE.getByte(array, address + 2) & 0xff) << 8) |
| 797 | + | ((UNSAFE.getByte(array, address + 3) & 0xff) ); |
| 798 | + } |
| 799 | + |
| 800 | + static int getIntL(byte[] array, int offset) { |
| 801 | + return ((array[offset ] & 0xff) ) |
| 802 | + | ((array[offset + 1] & 0xff) << 8) |
| 803 | + | ((array[offset + 2] & 0xff) << 16) |
| 804 | + | ((array[offset + 3] & 0xff) << 24); |
| 805 | + } |
| 806 | + |
| 807 | + static int getIntRB(byte[] array, int offset) { |
| 808 | + return Integer.reverseBytes(getIntB(array, offset)); |
| 809 | + } |
| 810 | + |
| 811 | + static int getIntRBU(byte[] array, int offset) { |
| 812 | + return Integer.reverseBytes(getIntBU(array, offset)); |
| 813 | + } |
| 814 | + |
| 815 | + static int getIntRL(byte[] array, int offset) { |
| 816 | + return Integer.reverseBytes(getIntL(array, offset)); |
| 817 | + } |
| 818 | + |
| 819 | + static int getIntRLU(byte[] array, int offset) { |
| 820 | + return Integer.reverseBytes(getIntLU(array, offset)); |
| 821 | + } |
| 822 | + |
| 823 | + static void setIntB(byte[] array, int offset, int value) { |
| 824 | + array[offset ] = (byte) (value >> 24); |
| 825 | + array[offset + 1] = (byte) (value >> 16); |
| 826 | + array[offset + 2] = (byte) (value >> 8); |
| 827 | + array[offset + 3] = (byte) (value ); |
| 828 | + } |
| 829 | + |
| 830 | + static void setIntBU(byte[] array, int offset, int value) { |
| 831 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 832 | + UNSAFE.putByte(array, address , (byte) (value >> 24)); |
| 833 | + UNSAFE.putByte(array, address + 1, (byte) (value >> 16)); |
| 834 | + UNSAFE.putByte(array, address + 2, (byte) (value >> 8)); |
| 835 | + UNSAFE.putByte(array, address + 3, (byte) (value )); |
| 836 | + } |
| 837 | + |
| 838 | + public static void setIntL(byte[] array, int offset, int value) { |
| 839 | + array[offset ] = (byte) value; |
| 840 | + array[offset + 1] = (byte) (value >> 8); |
| 841 | + array[offset + 2] = (byte) (value >> 16); |
| 842 | + array[offset + 3] = (byte) (value >> 24); |
| 843 | + } |
| 844 | + |
| 845 | + public static void setIntLU(byte[] array, int offset, int value) { |
| 846 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 847 | + UNSAFE.putByte(array, address , (byte) value ); |
| 848 | + UNSAFE.putByte(array, address + 1, (byte) (value >> 8)); |
| 849 | + UNSAFE.putByte(array, address + 2, (byte) (value >> 16)); |
| 850 | + UNSAFE.putByte(array, address + 3, (byte) (value >> 24)); |
| 851 | + } |
| 852 | + |
| 853 | + public static void setIntRL(byte[] array, int offset, int value) { |
| 854 | + value = Integer.reverseBytes(value); |
| 855 | + setIntL(array, offset, value); |
| 856 | + } |
| 857 | + |
| 858 | + public static void setIntRLU(byte[] array, int offset, int value) { |
| 859 | + value = Integer.reverseBytes(value); |
| 860 | + setIntLU(array, offset, value); |
| 861 | + } |
| 862 | + |
| 863 | + public static void setIntRB(byte[] array, int offset, int value) { |
| 864 | + value = Integer.reverseBytes(value); |
| 865 | + setIntB(array, offset, value); |
| 866 | + } |
| 867 | + |
| 868 | + public static void setIntRBU(byte[] array, int offset, int value) { |
| 869 | + value = Integer.reverseBytes(value); |
| 870 | + setIntBU(array, offset, value); |
| 871 | + } |
| 872 | + |
| 873 | + static long getLongB(byte[] array, int offset) { |
| 874 | + return (((long) array[offset ] & 0xff) << 56) |
| 875 | + | (((long) array[offset + 1] & 0xff) << 48) |
| 876 | + | (((long) array[offset + 2] & 0xff) << 40) |
| 877 | + | (((long) array[offset + 3] & 0xff) << 32) |
| 878 | + | (((long) array[offset + 4] & 0xff) << 24) |
| 879 | + | (((long) array[offset + 5] & 0xff) << 16) |
| 880 | + | (((long) array[offset + 6] & 0xff) << 8) |
| 881 | + | (((long) array[offset + 7] & 0xff) ); |
| 882 | + } |
| 883 | + |
| 884 | + static long getLongBU(byte[] array, int offset) { |
| 885 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 886 | + return (((long)(UNSAFE.getByte(array, address) & 0xff)) << 56) |
| 887 | + | (((long)(UNSAFE.getByte(array, address + 1) & 0xff)) << 48) |
| 888 | + | (((long)(UNSAFE.getByte(array, address + 2) & 0xff)) << 40) |
| 889 | + | (((long)(UNSAFE.getByte(array, address + 3) & 0xff)) << 32) |
| 890 | + | (((long)(UNSAFE.getByte(array, address + 4) & 0xff)) << 24) |
| 891 | + | (((long)(UNSAFE.getByte(array, address + 5) & 0xff)) << 16) |
| 892 | + | (((long)(UNSAFE.getByte(array, address + 6) & 0xff)) << 8) |
| 893 | + | (((long)(UNSAFE.getByte(array, address + 7) & 0xff)) ); |
| 894 | + } |
| 895 | + |
| 896 | + public static long getLongL(byte[] array, int offset) { |
| 897 | + return (((long) array[offset ] & 0xff) ) |
| 898 | + | (((long) array[offset + 1] & 0xff) << 8) |
| 899 | + | (((long) array[offset + 2] & 0xff) << 16) |
| 900 | + | (((long) array[offset + 3] & 0xff) << 24) |
| 901 | + | (((long) array[offset + 4] & 0xff) << 32) |
| 902 | + | (((long) array[offset + 5] & 0xff) << 40) |
| 903 | + | (((long) array[offset + 6] & 0xff) << 48) |
| 904 | + | (((long) array[offset + 7] & 0xff) << 56); |
| 905 | + } |
| 906 | + |
| 907 | + static long getLongLU(byte[] array, int offset) { |
| 908 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 909 | + return (((long)(UNSAFE.getByte(array, address ) & 0xff)) ) |
| 910 | + | (((long)(UNSAFE.getByte(array, address + 1) & 0xff)) << 8) |
| 911 | + | (((long)(UNSAFE.getByte(array, address + 2) & 0xff)) << 16) |
| 912 | + | (((long)(UNSAFE.getByte(array, address + 3) & 0xff)) << 24) |
| 913 | + | (((long)(UNSAFE.getByte(array, address + 4) & 0xff)) << 32) |
| 914 | + | (((long)(UNSAFE.getByte(array, address + 5) & 0xff)) << 40) |
| 915 | + | (((long)(UNSAFE.getByte(array, address + 6) & 0xff)) << 48) |
| 916 | + | (((long)(UNSAFE.getByte(array, address + 7) & 0xff)) << 56); |
| 917 | + } |
| 918 | + |
| 919 | + static long getLongRB(byte[] array, int offset) { |
| 920 | + return getLongB(array, offset); |
| 921 | + } |
| 922 | + |
| 923 | + static long getLongRBU(byte[] array, int offset) { |
| 924 | + return getLongBU(array, offset); |
| 925 | + } |
| 926 | + |
| 927 | + static long getLongRL(byte[] array, int offset) { |
| 928 | + return getLongL(array, offset); |
| 929 | + } |
| 930 | + |
| 931 | + static long getLongRLU(byte[] array, int offset) { |
| 932 | + return getLongLU(array, offset); |
| 933 | + } |
| 934 | + |
| 935 | + static void setLongB(byte[] array, int offset, long value) { |
| 936 | + array[offset] = (byte) (value >> 56); |
| 937 | + array[offset + 1] = (byte) (value >> 48); |
| 938 | + array[offset + 2] = (byte) (value >> 40); |
| 939 | + array[offset + 3] = (byte) (value >> 32); |
| 940 | + array[offset + 4] = (byte) (value >> 24); |
| 941 | + array[offset + 5] = (byte) (value >> 16); |
| 942 | + array[offset + 6] = (byte) (value >> 8); |
| 943 | + array[offset + 7] = (byte) (value ); |
| 944 | + } |
| 945 | + |
| 946 | + public static void setLongL(byte[] array, int offset, long value) { |
| 947 | + array[offset] = (byte) value ; |
| 948 | + array[offset + 1] = (byte) (value >> 8 ); |
| 949 | + array[offset + 2] = (byte) (value >> 16); |
| 950 | + array[offset + 3] = (byte) (value >> 24); |
| 951 | + array[offset + 4] = (byte) (value >> 32); |
| 952 | + array[offset + 5] = (byte) (value >> 40); |
| 953 | + array[offset + 6] = (byte) (value >> 48); |
| 954 | + array[offset + 7] = (byte) (value >> 56); |
| 955 | + } |
| 956 | + |
| 957 | + public static void setLongRL(byte[] array, int offset, long value) { |
| 958 | + value = Long.reverseBytes(value); |
| 959 | + setLongL(array, offset, value); |
| 960 | + } |
| 961 | + |
| 962 | + public static void setLongRLU(byte[] array, int offset, long value) { |
| 963 | + value = Long.reverseBytes(value); |
| 964 | + setLongLU(array, offset, value); |
| 965 | + } |
| 966 | + |
| 967 | + public static void setLongRB(byte[] array, int offset, long value) { |
| 968 | + value = Long.reverseBytes(value); |
| 969 | + setLongB(array, offset, value); |
| 970 | + } |
| 971 | + |
| 972 | + public static void setLongRBU(byte[] array, int offset, long value) { |
| 973 | + value = Long.reverseBytes(value); |
| 974 | + setLongBU(array, offset, value); |
| 975 | + } |
| 976 | + |
| 977 | + public static void setLongBU(byte[] array, int offset, long value) { |
| 978 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 979 | + UNSAFE.putByte(array, address , (byte) (value >> 56)); |
| 980 | + UNSAFE.putByte(array, address + 1, (byte) (value >> 48)); |
| 981 | + UNSAFE.putByte(array, address + 2, (byte) (value >> 40)); |
| 982 | + UNSAFE.putByte(array, address + 3, (byte) (value >> 32)); |
| 983 | + UNSAFE.putByte(array, address + 4, (byte) (value >> 24)); |
| 984 | + UNSAFE.putByte(array, address + 5, (byte) (value >> 16)); |
| 985 | + UNSAFE.putByte(array, address + 6, (byte) (value >> 8)); |
| 986 | + UNSAFE.putByte(array, address + 7, (byte) value ); |
| 987 | + } |
| 988 | + |
| 989 | + public static void setLongLU(byte[] array, int offset, long value) { |
| 990 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 991 | + UNSAFE.putByte(array, address , (byte) value ); |
| 992 | + UNSAFE.putByte(array, address + 1, (byte) (value >> 8)); |
| 993 | + UNSAFE.putByte(array, address + 2, (byte) (value >> 16)); |
| 994 | + UNSAFE.putByte(array, address + 3, (byte) (value >> 24)); |
| 995 | + UNSAFE.putByte(array, address + 4, (byte) (value >> 32)); |
| 996 | + UNSAFE.putByte(array, address + 5, (byte) (value >> 40)); |
| 997 | + UNSAFE.putByte(array, address + 6, (byte) (value >> 48)); |
| 998 | + UNSAFE.putByte(array, address + 7, (byte) (value >> 56)); |
| 999 | + } |
| 1000 | + |
| 1001 | + public static int getIntLU(byte[] array, int offset) { |
| 1002 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + offset; |
| 1003 | + return ((UNSAFE.getByte(array, address ) & 0xff) ) |
| 1004 | + | ((UNSAFE.getByte(array, address + 1) & 0xff) << 8) |
| 1005 | + | ((UNSAFE.getByte(array, address + 2) & 0xff) << 16) |
| 1006 | + | ((UNSAFE.getByte(array, address + 3) & 0xff) << 24); |
| 1007 | + } |
| 1008 | + |
| 1009 | + public static char getCharB(byte[] val, int index) { |
| 1010 | + index <<= 1; |
| 1011 | + return (char)(((val[index ] & 0xff) << 8) |
| 1012 | + | ((val[index + 1] & 0xff))); |
| 1013 | + } |
| 1014 | + |
| 1015 | + public static char getCharBR(byte[] val, int index) { |
| 1016 | + return Character.reverseBytes(getCharB(val, index)); |
| 1017 | + } |
| 1018 | + |
| 1019 | + public static char getCharL(byte[] val, int index) { |
| 1020 | + index <<= 1; |
| 1021 | + return (char)(((val[index ] & 0xff)) |
| 1022 | + | ((val[index + 1] & 0xff) << 8)); |
| 1023 | + } |
| 1024 | + |
| 1025 | + public static char getCharLR(byte[] val, int index) { |
| 1026 | + return Character.reverseBytes(getCharL(val, index)); |
| 1027 | + } |
| 1028 | + |
| 1029 | + public static char getCharBU(byte[] array, int offset) { |
| 1030 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + (offset << 1); |
| 1031 | + return (char) (((UNSAFE.getByte(array, address ) & 0xff) << 8) |
| 1032 | + | ((UNSAFE.getByte(array, address + 1) & 0xff) )); |
| 1033 | + } |
| 1034 | + |
| 1035 | + public static char getCharLU(byte[] array, int offset) { |
| 1036 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + (offset << 1); |
| 1037 | + return (char) (((UNSAFE.getByte(array, address ) & 0xff) ) |
| 1038 | + | ((UNSAFE.getByte(array, address + 1) & 0xff) << 8)); |
| 1039 | + } |
| 1040 | + |
| 1041 | + public void putChars4B(byte[] bytes, int offset) { |
| 1042 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1043 | + putShortB(bytes, offset , c0); |
| 1044 | + putShortB(bytes, offset + 1, c1); |
| 1045 | + putShortB(bytes, offset + 2, c2); |
| 1046 | + putShortB(bytes, offset + 3, c3); |
| 1047 | + } |
| 1048 | + |
| 1049 | + public void putChars4BU(byte[] bytes, int offset) { |
| 1050 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1051 | + putShortBU(bytes, offset , c0); |
| 1052 | + putShortBU(bytes, offset + 1, c1); |
| 1053 | + putShortBU(bytes, offset + 2, c2); |
| 1054 | + putShortBU(bytes, offset + 3, c3); |
| 1055 | + } |
| 1056 | + |
| 1057 | + public void putChars4BV(byte[] bytes, int offset) { |
| 1058 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1059 | + offset <<= 1; |
| 1060 | + CHAR_B.set(bytes, offset , c0); |
| 1061 | + CHAR_B.set(bytes, offset + 2, c1); |
| 1062 | + CHAR_B.set(bytes, offset + 4, c2); |
| 1063 | + CHAR_B.set(bytes, offset + 6, c3); |
| 1064 | + } |
| 1065 | + |
| 1066 | + public void putChars4L(byte[] bytes, int offset) { |
| 1067 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1068 | + putShortL(bytes, offset , c0); |
| 1069 | + putShortL(bytes, offset + 1, c1); |
| 1070 | + putShortL(bytes, offset + 2, c2); |
| 1071 | + putShortL(bytes, offset + 3, c3); |
| 1072 | + } |
| 1073 | + |
| 1074 | + public void putChars4LV(byte[] bytes, int offset) { |
| 1075 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1076 | + offset <<= 1; |
| 1077 | + CHAR_L.set(bytes, offset , c0); |
| 1078 | + CHAR_L.set(bytes, offset + 2, c1); |
| 1079 | + CHAR_L.set(bytes, offset + 4, c2); |
| 1080 | + CHAR_L.set(bytes, offset + 6, c3); |
| 1081 | + } |
| 1082 | + |
| 1083 | + public void putChars4LU(byte[] bytes, int offset) { |
| 1084 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1085 | + putShortLU(bytes, offset , c0); |
| 1086 | + putShortLU(bytes, offset + 1, c1); |
| 1087 | + putShortLU(bytes, offset + 2, c2); |
| 1088 | + putShortLU(bytes, offset + 3, c3); |
| 1089 | + } |
| 1090 | + |
| 1091 | + public void putChars4C(byte[] bytes, int offset) { |
| 1092 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1093 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + (offset << 1); |
| 1094 | + UNSAFE.putChar(bytes, address , c0); |
| 1095 | + UNSAFE.putChar(bytes, address + 2, c1); |
| 1096 | + UNSAFE.putChar(bytes, address + 4, c2); |
| 1097 | + UNSAFE.putChar(bytes, address + 6, c3); |
| 1098 | + } |
| 1099 | + |
| 1100 | + public void putChars4S(byte[] bytes, int offset) { |
| 1101 | + char c0 = 'n', c1 = 'u', c2 = 'l', c3 = 'l'; |
| 1102 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + (offset << 1); |
| 1103 | + UNSAFE.putShort(bytes, address , (short) c0); |
| 1104 | + UNSAFE.putShort(bytes, address + 2, (short) c1); |
| 1105 | + UNSAFE.putShort(bytes, address + 4, (short) c2); |
| 1106 | + UNSAFE.putShort(bytes, address + 6, (short) c3); |
| 1107 | + } |
| 1108 | + |
| 1109 | + private static void putShortB(byte[] val, int index, int c) { |
| 1110 | + index <<= 1; |
| 1111 | + val[index ] = (byte)(c >> 8); |
| 1112 | + val[index + 1] = (byte)(c ); |
| 1113 | + } |
| 1114 | + |
| 1115 | + public static void putShortBU(byte[] array, int offset, int c) { |
| 1116 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + (offset << 1); |
| 1117 | + UNSAFE.putByte(array, address , (byte) (c >> 8)); |
| 1118 | + UNSAFE.putByte(array, address + 1, (byte) (c )); |
| 1119 | + } |
| 1120 | + |
| 1121 | + private static void putShortL(byte[] val, int index, int c) { |
| 1122 | + index <<= 1; |
| 1123 | + val[index ] = (byte)(c ); |
| 1124 | + val[index + 1] = (byte)(c >> 8); |
| 1125 | + } |
| 1126 | + |
| 1127 | + public static void putShortLU(byte[] array, int offset, int c) { |
| 1128 | + final long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + (offset << 1); |
| 1129 | + UNSAFE.putByte(array, address , (byte) (c )); |
| 1130 | + UNSAFE.putByte(array, address + 1, (byte) (c >> 8)); |
| 1131 | + } |
| 1132 | +} |
0 commit comments