Java Code Examples for jdk.internal.misc.Unsafe#ARRAY_INT_BASE_OFFSET

The following examples show how to use jdk.internal.misc.Unsafe#ARRAY_INT_BASE_OFFSET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArraysSupport.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public static int mismatch(int[] a, int aFromIndex,
                           int[] b, int bFromIndex,
                           int length) {
    int i = 0;
    if (length > 1) {
        if (a[aFromIndex] != b[bFromIndex])
            return 0;
        int aOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_INT_INDEX_SCALE);
        int bOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (bFromIndex << LOG2_ARRAY_INT_INDEX_SCALE);
        i = vectorizedMismatch(
                a, aOffset,
                b, bOffset,
                length, LOG2_ARRAY_INT_INDEX_SCALE);
        if (i >= 0)
            return i;
        i = length - ~i;
    }
    for (; i < length; i++) {
        if (a[aFromIndex + i] != b[bFromIndex + i])
            return i;
    }
    return -1;
}
 
Example 2
Source File: HotSpotJVMCIRuntimeProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The offset from the origin of an array to the first element.
 *
 * @return the offset in bytes
 */
static int getArrayBaseOffset(JavaKind kind) {
    switch (kind) {
        case Boolean:
            return Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;
        case Byte:
            return Unsafe.ARRAY_BYTE_BASE_OFFSET;
        case Char:
            return Unsafe.ARRAY_CHAR_BASE_OFFSET;
        case Short:
            return Unsafe.ARRAY_SHORT_BASE_OFFSET;
        case Int:
            return Unsafe.ARRAY_INT_BASE_OFFSET;
        case Long:
            return Unsafe.ARRAY_LONG_BASE_OFFSET;
        case Float:
            return Unsafe.ARRAY_FLOAT_BASE_OFFSET;
        case Double:
            return Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
        case Object:
            return Unsafe.ARRAY_OBJECT_BASE_OFFSET;
        default:
            throw new JVMCIError("%s", kind);
    }
}
 
Example 3
Source File: ArraysSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static int mismatch(int[] a, int aFromIndex,
                    int[] b, int bFromIndex,
                    int length) {
    int i = 0;
    if (length > 1) {
        int aOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_INT_INDEX_SCALE);
        int bOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (bFromIndex << LOG2_ARRAY_INT_INDEX_SCALE);
        i = vectorizedMismatch(
                a, aOffset,
                b, bOffset,
                length, LOG2_ARRAY_INT_INDEX_SCALE);
        if (i >= 0)
            return i;
        i = length - ~i;
    }
    for (; i < length; i++) {
        if (a[aFromIndex + i] != b[bFromIndex + i])
            return i;
    }
    return -1;
}
 
Example 4
Source File: RenderBuffer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public RenderBuffer put(int[] x, int offset, int length) {
    // assert (position() % SIZEOF_INT == 0);
    if (length > COPY_FROM_ARRAY_THRESHOLD) {
        long offsetInBytes = offset * SIZEOF_INT + Unsafe.ARRAY_INT_BASE_OFFSET;
        long lengthInBytes = length * SIZEOF_INT;
        unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
        position(position() + lengthInBytes);
    } else {
        int end = offset + length;
        for (int i = offset; i < end; i++) {
            putInt(x[i]);
        }
    }
    return this;
}
 
Example 5
Source File: RenderBuffer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public RenderBuffer put(int[] x, int offset, int length) {
    // assert (position() % SIZEOF_INT == 0);
    if (length > COPY_FROM_ARRAY_THRESHOLD) {
        long offsetInBytes = offset * SIZEOF_INT + Unsafe.ARRAY_INT_BASE_OFFSET;
        long lengthInBytes = length * SIZEOF_INT;
        unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
        position(position() + lengthInBytes);
    } else {
        int end = offset + length;
        for (int i = offset; i < end; i++) {
            putInt(x[i]);
        }
    }
    return this;
}