Java Code Examples for sun.misc.Unsafe#ARRAY_BYTE_INDEX_SCALE
The following examples show how to use
sun.misc.Unsafe#ARRAY_BYTE_INDEX_SCALE .
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: BitBlt.java From trufflesqueak with MIT License | 5 votes |
private boolean loadBitBltDestForm() { if (!(isPointers(destForm) && slotSizeOf(destForm) >= 4)) { return false; } final Object destBitsValue = fetchPointerofObject(FORM.BITS, destForm); destWidth = fetchIntegerofObject(FORM.WIDTH, destForm); destHeight = fetchIntegerofObject(FORM.HEIGHT, destForm); if (!(destWidth >= 0 && destHeight >= 0)) { return false; } destDepth = fetchIntegerofObject(FORM.DEPTH, destForm); if (!(destMSB = destDepth > 0)) { destDepth = 0 - destDepth; } if (!isWordsOrBytes(destBitsValue)) { if (destBitsValue instanceof Long) { throw SqueakException.create("Not supported: Query for actual surface dimensions"); } else { return false; } } destPPW = div(32, destDepth); destPitch = div(destWidth + destPPW - 1, destPPW) * 4; final NativeObject destBitsNative = (NativeObject) destBitsValue; final long destBitsSize; if (isWords(destBitsNative)) { destBits = destBitsNative.getIntStorage(); destBitsSize = destBitsNative.getIntLength() * Integer.BYTES; destBitsBaseOffset = Unsafe.ARRAY_INT_BASE_OFFSET; destBitsIndexScale = Unsafe.ARRAY_INT_INDEX_SCALE; } else { destBits = destBitsNative.getByteStorage(); destBitsSize = destBitsNative.getByteLength(); destBitsBaseOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET; destBitsIndexScale = Unsafe.ARRAY_BYTE_INDEX_SCALE * Integer.BYTES; } return destBitsSize >= destPitch * destHeight; }
Example 2
Source File: BitBlt.java From trufflesqueak with MIT License | 4 votes |
private boolean loadBitBltSourceForm() { if (!(isPointers(sourceForm) && slotSizeOf(sourceForm) >= 4)) { return false; } final Object sourceBitsValue = fetchPointerofObject(FORM.BITS, sourceForm); sourceWidth = fetchIntOrFloatofObject(FORM.WIDTH, sourceForm); sourceHeight = fetchIntOrFloatofObject(FORM.HEIGHT, sourceForm); if (!(sourceWidth >= 0 && sourceHeight >= 0)) { return false; } sourceDepth = fetchIntegerofObject(FORM.DEPTH, sourceForm); if (!(sourceMSB = sourceDepth > 0)) { sourceDepth = 0 - sourceDepth; } if (!isWordsOrBytes(sourceBitsValue)) { if (sourceBitsValue instanceof Long) { throw SqueakException.create("Not supported: Query for actual surface dimensions"); } else { return false; } } sourcePPW = div(32, sourceDepth); sourcePitch = div(sourceWidth + sourcePPW - 1, sourcePPW) * 4; final NativeObject sourceBitsNative = (NativeObject) sourceBitsValue; if (isWords(sourceBitsNative)) { final int[] ints = sourceBitsNative.getIntStorage(); sourceBits = ints; sourceBitsBaseOffset = Unsafe.ARRAY_INT_BASE_OFFSET; sourceBitsIndexScale = Unsafe.ARRAY_INT_INDEX_SCALE; return ints.length * Integer.BYTES >= sourcePitch * sourceHeight; } else { final byte[] bytes = sourceBitsNative.getByteStorage(); if (bytes.length >= sourcePitch * sourceHeight) { sourceBits = bytes; sourceBitsBaseOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET; sourceBitsIndexScale = Unsafe.ARRAY_BYTE_INDEX_SCALE * Integer.BYTES; return true; } else { return false; } } }
Example 3
Source File: VirtualArrayNode.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static int entryIndexForOffset(long constantOffset, JavaKind expectedEntryKind, ResolvedJavaType componentType, int length) { int baseOffset; int indexScale; switch (componentType.getJavaKind()) { case Boolean: baseOffset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET; indexScale = Unsafe.ARRAY_BOOLEAN_INDEX_SCALE; break; case Byte: baseOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET; indexScale = Unsafe.ARRAY_BYTE_INDEX_SCALE; break; case Short: baseOffset = Unsafe.ARRAY_SHORT_BASE_OFFSET; indexScale = Unsafe.ARRAY_SHORT_INDEX_SCALE; break; case Char: baseOffset = Unsafe.ARRAY_CHAR_BASE_OFFSET; indexScale = Unsafe.ARRAY_CHAR_INDEX_SCALE; break; case Int: baseOffset = Unsafe.ARRAY_INT_BASE_OFFSET; indexScale = Unsafe.ARRAY_INT_INDEX_SCALE; break; case Long: baseOffset = Unsafe.ARRAY_LONG_BASE_OFFSET; indexScale = Unsafe.ARRAY_LONG_INDEX_SCALE; break; case Float: baseOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET; indexScale = Unsafe.ARRAY_FLOAT_INDEX_SCALE; break; case Double: baseOffset = Unsafe.ARRAY_DOUBLE_BASE_OFFSET; indexScale = Unsafe.ARRAY_DOUBLE_INDEX_SCALE; break; case Object: baseOffset = Unsafe.ARRAY_OBJECT_BASE_OFFSET; indexScale = Unsafe.ARRAY_OBJECT_INDEX_SCALE; break; default: return -1; } long offset; if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && componentType.isPrimitive()) { // On big endian, we do just get expect the type be right aligned in this memory slot offset = constantOffset - (componentType.getJavaKind().getByteCount() - Math.min(componentType.getJavaKind().getByteCount(), 4 + expectedEntryKind.getByteCount())); } else { offset = constantOffset; } long index = offset - baseOffset; if (index % indexScale != 0) { return -1; } long elementIndex = index / indexScale; if (elementIndex < 0 || elementIndex >= length) { return -1; } return (int) elementIndex; }