Java Code Examples for jdk.internal.misc.Unsafe#ADDRESS_SIZE
The following examples show how to use
jdk.internal.misc.Unsafe#ADDRESS_SIZE .
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: TestShrinkAuxiliaryData.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Detects maximum possible size of G1ConcRSLogCacheSize available for * current process based on maximum available process memory size * * @return power of two */ private static int getMaxCacheSize() { long availableMemory = Runtime.getRuntime().freeMemory() - ShrinkAuxiliaryDataTest.getMemoryUsedByTest() - 1l; if (availableMemory <= 0) { return 0; } long availablePointersCount = availableMemory / Unsafe.ADDRESS_SIZE; return (63 - (int) Long.numberOfLeadingZeros(availablePointersCount)); }
Example 2
Source File: CRC32C.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Updates the CRC-32C checksum with the specified array of bytes. */ @HotSpotIntrinsicCandidate private static int updateBytes(int crc, byte[] b, int off, int end) { // Do only byte reads for arrays so short they can't be aligned // or if bytes are stored with a larger witdh than one byte.,% if (end - off >= 8 && Unsafe.ARRAY_BYTE_INDEX_SCALE == 1) { // align on 8 bytes int alignLength = (8 - ((Unsafe.ARRAY_BYTE_BASE_OFFSET + off) & 0x7)) & 0x7; for (int alignEnd = off + alignLength; off < alignEnd; off++) { crc = (crc >>> 8) ^ byteTable[(crc ^ b[off]) & 0xFF]; } if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { crc = Integer.reverseBytes(crc); } // slicing-by-8 for (; off < (end - Long.BYTES); off += Long.BYTES) { int firstHalf; int secondHalf; if (Unsafe.ADDRESS_SIZE == 4) { // On 32 bit platforms read two ints instead of a single 64bit long firstHalf = UNSAFE.getInt(b, (long)Unsafe.ARRAY_BYTE_BASE_OFFSET + off); secondHalf = UNSAFE.getInt(b, (long)Unsafe.ARRAY_BYTE_BASE_OFFSET + off + Integer.BYTES); } else { long value = UNSAFE.getLong(b, (long)Unsafe.ARRAY_BYTE_BASE_OFFSET + off); if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { firstHalf = (int) value; secondHalf = (int) (value >>> 32); } else { // ByteOrder.BIG_ENDIAN firstHalf = (int) (value >>> 32); secondHalf = (int) value; } } crc ^= firstHalf; if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { crc = byteTable7[crc & 0xFF] ^ byteTable6[(crc >>> 8) & 0xFF] ^ byteTable5[(crc >>> 16) & 0xFF] ^ byteTable4[crc >>> 24] ^ byteTable3[secondHalf & 0xFF] ^ byteTable2[(secondHalf >>> 8) & 0xFF] ^ byteTable1[(secondHalf >>> 16) & 0xFF] ^ byteTable0[secondHalf >>> 24]; } else { // ByteOrder.BIG_ENDIAN crc = byteTable0[secondHalf & 0xFF] ^ byteTable1[(secondHalf >>> 8) & 0xFF] ^ byteTable2[(secondHalf >>> 16) & 0xFF] ^ byteTable3[secondHalf >>> 24] ^ byteTable4[crc & 0xFF] ^ byteTable5[(crc >>> 8) & 0xFF] ^ byteTable6[(crc >>> 16) & 0xFF] ^ byteTable7[crc >>> 24]; } } if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { crc = Integer.reverseBytes(crc); } } // Tail for (; off < end; off++) { crc = (crc >>> 8) ^ byteTable[(crc ^ b[off]) & 0xFF]; } return crc; }
Example 3
Source File: CRC32C.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Updates the CRC-32C checksum with the specified array of bytes. */ @HotSpotIntrinsicCandidate private static int updateBytes(int crc, byte[] b, int off, int end) { // Do only byte reads for arrays so short they can't be aligned // or if bytes are stored with a larger witdh than one byte.,% if (end - off >= 8 && Unsafe.ARRAY_BYTE_INDEX_SCALE == 1) { // align on 8 bytes int alignLength = (8 - ((Unsafe.ARRAY_BYTE_BASE_OFFSET + off) & 0x7)) & 0x7; for (int alignEnd = off + alignLength; off < alignEnd; off++) { crc = (crc >>> 8) ^ byteTable[(crc ^ b[off]) & 0xFF]; } if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { crc = Integer.reverseBytes(crc); } // slicing-by-8 for (; off < (end - Long.BYTES); off += Long.BYTES) { int firstHalf; int secondHalf; if (Unsafe.ADDRESS_SIZE == 4) { // On 32 bit platforms read two ints instead of a single 64bit long firstHalf = UNSAFE.getInt(b, (long)Unsafe.ARRAY_BYTE_BASE_OFFSET + off); secondHalf = UNSAFE.getInt(b, (long)Unsafe.ARRAY_BYTE_BASE_OFFSET + off + Integer.BYTES); } else { long value = UNSAFE.getLong(b, (long)Unsafe.ARRAY_BYTE_BASE_OFFSET + off); if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { firstHalf = (int) value; secondHalf = (int) (value >>> 32); } else { // ByteOrder.BIG_ENDIAN firstHalf = (int) (value >>> 32); secondHalf = (int) value; } } crc ^= firstHalf; if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { crc = byteTable7[crc & 0xFF] ^ byteTable6[(crc >>> 8) & 0xFF] ^ byteTable5[(crc >>> 16) & 0xFF] ^ byteTable4[crc >>> 24] ^ byteTable3[secondHalf & 0xFF] ^ byteTable2[(secondHalf >>> 8) & 0xFF] ^ byteTable1[(secondHalf >>> 16) & 0xFF] ^ byteTable0[secondHalf >>> 24]; } else { // ByteOrder.BIG_ENDIAN crc = byteTable0[secondHalf & 0xFF] ^ byteTable1[(secondHalf >>> 8) & 0xFF] ^ byteTable2[(secondHalf >>> 16) & 0xFF] ^ byteTable3[secondHalf >>> 24] ^ byteTable4[crc & 0xFF] ^ byteTable5[(crc >>> 8) & 0xFF] ^ byteTable6[(crc >>> 16) & 0xFF] ^ byteTable7[crc >>> 24]; } } if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { crc = Integer.reverseBytes(crc); } } // Tail for (; off < end; off++) { crc = (crc >>> 8) ^ byteTable[(crc ^ b[off]) & 0xFF]; } return crc; }