Class VectorizedArrays

java.lang.Object
com.cedarsoftware.util.internal.VectorizedArrays

public final class VectorizedArrays extends Object

Internal API — not for external use.

Range-based array operations that dispatch to JDK 9+ Arrays intrinsics (SIMD-vectorized on supported HW) when the runtime JVM supports them, and fall back to hand-rolled loops on JDK 8. java-util's source/target is JDK 1.8, so the JDK 9+ Arrays.equals(arr, int, int, arr, int, int) / mismatch / compare signatures can't be referenced at compile time — but the same library is overwhelmingly run on modern JVMs in production. This helper bridges the gap with one-time reflective resolution at class load.

Dispatch mechanics

  1. At class load, SystemUtilities.isJavaVersionAtLeast(9, 0) is queried once. On JDK 8 we short-circuit to null handles and skip the reflection cost entirely.
  2. On JDK 9+, each operation is resolved via MethodHandles.publicLookup() and cached in a static final MethodHandle. invokeExact on a static final MH is recognised by HotSpot and inlined to direct intrinsic dispatch in steady state.
  3. Per-call cost is one static-field read + null-check + (on JDK 9+) MH.invokeExact. No per-call version checks.

Exposed operations

(Note: System.arraycopy is already a HotSpot intrinsic on JDK 8+; there's no slower portable fallback to dispatch to, so it's not exposed here. Use System.arraycopy directly.)

Visibility

Exposed to com.cedarsoftware:json-io via a qualified JPMS export (exports com.cedarsoftware.util.internal to com.cedarsoftware.io). Signatures and semantics may change without notice across minor releases.
Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License
  • Method Details

    • equalsRange

      public static boolean equalsRange(char[] a, int aFrom, int aTo, char[] b, int bFrom, int bTo)
      Equivalent to JDK 9+'s Arrays.equals(a, aFrom, aTo, b, bFrom, bTo) — returns true iff the two ranges have the same length and contain element-wise equal chars. SIMD-vectorized on JDK 9+; manual loop on JDK 8.
    • equalsRange

      public static boolean equalsRange(byte[] a, int aFrom, int aTo, byte[] b, int bFrom, int bTo)
    • mismatchRange

      public static int mismatchRange(char[] a, int aFrom, int aTo, char[] b, int bFrom, int bTo)
      Equivalent to JDK 9+'s Arrays.mismatch(a, aFrom, aTo, b, bFrom, bTo). Returns the relative index of the first mismatching element (i.e. 0 for the first element in each range), or -1 if the ranges are equal over their common prefix and have the same length. If the ranges have different lengths and are equal over the common prefix, returns the length of the shorter range.
    • mismatchRange

      public static int mismatchRange(byte[] a, int aFrom, int aTo, byte[] b, int bFrom, int bTo)
    • compareRange

      public static int compareRange(char[] a, int aFrom, int aTo, char[] b, int bFrom, int bTo)
      Equivalent to JDK 9+'s Arrays.compare(a, aFrom, aTo, b, bFrom, bTo). Returns a negative integer, zero, or a positive integer as the first range is lexicographically less than, equal to, or greater than the second. If the ranges are equal over the common prefix, the shorter range compares less.
    • compareRange

      public static int compareRange(byte[] a, int aFrom, int aTo, byte[] b, int bFrom, int bTo)