< prev index next >

src/java.base/share/classes/sun/misc/Unsafe.java

Print this page

        

*** 1010,1037 **** * {@link NullPointerException} * @since 1.9 */ public final long getLongUnaligned(Object o, long offset) { if ((offset & 7) == 0) { ! return getLong(o, offset); } else if ((offset & 3) == 0) { ! return makeLong(getInt(o, offset), ! getInt(o, offset + 4)); } else if ((offset & 1) == 0) { ! return makeLong(getShort(o, offset), ! getShort(o, offset + 2), ! getShort(o, offset + 4), ! getShort(o, offset + 6)); } else { ! return makeLong(getByte(o, offset), ! getByte(o, offset + 1), ! getByte(o, offset + 2), ! getByte(o, offset + 3), ! getByte(o, offset + 4), ! getByte(o, offset + 5), ! getByte(o, offset + 6), ! getByte(o, offset + 7)); } } /** * As {@link #getLongUnaligned(Object, long)} but with an * additional argument which specifies the endianness of the value --- 1010,1037 ---- * {@link NullPointerException} * @since 1.9 */ public final long getLongUnaligned(Object o, long offset) { if ((offset & 7) == 0) { ! return getLong(o, offset << 1); } else if ((offset & 3) == 0) { ! return makeLong(getInt(o, (offset + 0) << 1), ! getInt(o, (offset + 4) << 1)); } else if ((offset & 1) == 0) { ! return makeLong(getShort(o, (offset + 0) << 1), ! getShort(o, (offset + 2) << 1), ! getShort(o, (offset + 4) << 1), ! getShort(o, (offset + 6) << 1)); } else { ! return makeLong(getByte(o, (offset + 0) << 1), ! getByte(o, (offset + 1) << 1), ! getByte(o, (offset + 2) << 1), ! getByte(o, (offset + 3) << 1), ! getByte(o, (offset + 4) << 1), ! getByte(o, (offset + 5) << 1), ! getByte(o, (offset + 6) << 1), ! getByte(o, (offset + 7) << 1)); } } /** * As {@link #getLongUnaligned(Object, long)} but with an * additional argument which specifies the endianness of the value
*** 1048,1080 **** } /** @see #getLongUnaligned(Object, long) */ public final int getIntUnaligned(Object o, long offset) { if ((offset & 3) == 0) { ! return getInt(o, offset); } else if ((offset & 1) == 0) { ! return makeInt(getShort(o, offset), ! getShort(o, offset + 2)); } else { ! return makeInt(getByte(o, offset), ! getByte(o, offset + 1), ! getByte(o, offset + 2), ! getByte(o, offset + 3)); } } /** @see #getLongUnaligned(Object, long, boolean) */ public final int getIntUnaligned(Object o, long offset, boolean bigEndian) { return convEndian(bigEndian, getIntUnaligned(o, offset)); } /** @see #getLongUnaligned(Object, long) */ public final short getShortUnaligned(Object o, long offset) { if ((offset & 1) == 0) { ! return getShort(o, offset); } else { ! return makeShort(getByte(o, offset), ! getByte(o, offset + 1)); } } /** @see #getLongUnaligned(Object, long, boolean) */ public final short getShortUnaligned(Object o, long offset, boolean bigEndian) { return convEndian(bigEndian, getShortUnaligned(o, offset)); --- 1048,1080 ---- } /** @see #getLongUnaligned(Object, long) */ public final int getIntUnaligned(Object o, long offset) { if ((offset & 3) == 0) { ! return getInt(o, offset << 1); } else if ((offset & 1) == 0) { ! return makeInt(getShort(o, (offset + 0) << 1), ! getShort(o, (offset + 2) << 1)); } else { ! return makeInt(getByte(o, (offset + 0) << 1), ! getByte(o, (offset + 1) << 1), ! getByte(o, (offset + 2) << 1), ! getByte(o, (offset + 3) << 1)); } } /** @see #getLongUnaligned(Object, long, boolean) */ public final int getIntUnaligned(Object o, long offset, boolean bigEndian) { return convEndian(bigEndian, getIntUnaligned(o, offset)); } /** @see #getLongUnaligned(Object, long) */ public final short getShortUnaligned(Object o, long offset) { if ((offset & 1) == 0) { ! return getShort(o, offset << 1); } else { ! return makeShort(getByte(o, (offset + 0) << 1), ! getByte(o, (offset + 1) << 1)); } } /** @see #getLongUnaligned(Object, long, boolean) */ public final short getShortUnaligned(Object o, long offset, boolean bigEndian) { return convEndian(bigEndian, getShortUnaligned(o, offset));
*** 1117,1127 **** * {@link NullPointerException} * @since 1.9 */ public final void putLongUnaligned(Object o, long offset, long x) { if ((offset & 7) == 0) { ! putLong(o, offset, x); } else if ((offset & 3) == 0) { putLongParts(o, offset, (int)(x >> 0), (int)(x >>> 32)); } else if ((offset & 1) == 0) { --- 1117,1127 ---- * {@link NullPointerException} * @since 1.9 */ public final void putLongUnaligned(Object o, long offset, long x) { if ((offset & 7) == 0) { ! putLong(o, offset << 1, x); } else if ((offset & 3) == 0) { putLongParts(o, offset, (int)(x >> 0), (int)(x >>> 32)); } else if ((offset & 1) == 0) {
*** 1158,1168 **** } /** @see #putLongUnaligned(Object, long, long) */ public final void putIntUnaligned(Object o, long offset, int x) { if ((offset & 3) == 0) { ! putInt(o, offset, x); } else if ((offset & 1) == 0) { putIntParts(o, offset, (short)(x >> 0), (short)(x >>> 16)); } else { --- 1158,1168 ---- } /** @see #putLongUnaligned(Object, long, long) */ public final void putIntUnaligned(Object o, long offset, int x) { if ((offset & 3) == 0) { ! putInt(o, offset << 1, x); } else if ((offset & 1) == 0) { putIntParts(o, offset, (short)(x >> 0), (short)(x >>> 16)); } else {
*** 1179,1189 **** } /** @see #putLongUnaligned(Object, long, long) */ public final void putShortUnaligned(Object o, long offset, short x) { if ((offset & 1) == 0) { ! putShort(o, offset, x); } else { putShortParts(o, offset, (byte)(x >>> 0), (byte)(x >>> 8)); } --- 1179,1189 ---- } /** @see #putLongUnaligned(Object, long, long) */ public final void putShortUnaligned(Object o, long offset, short x) { if ((offset & 1) == 0) { ! putShort(o, offset << 1, x); } else { putShortParts(o, offset, (byte)(x >>> 0), (byte)(x >>> 8)); }
*** 1257,1298 **** // These methods write integers to memory from smaller parts // provided by their caller. The ordering in which these parts // are written is the native endianness of this platform. private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) { ! putByte(o, offset + 0, pick(i0, i7)); ! putByte(o, offset + 1, pick(i1, i6)); ! putByte(o, offset + 2, pick(i2, i5)); ! putByte(o, offset + 3, pick(i3, i4)); ! putByte(o, offset + 4, pick(i4, i3)); ! putByte(o, offset + 5, pick(i5, i2)); ! putByte(o, offset + 6, pick(i6, i1)); ! putByte(o, offset + 7, pick(i7, i0)); } private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) { ! putShort(o, offset + 0, pick(i0, i3)); ! putShort(o, offset + 2, pick(i1, i2)); ! putShort(o, offset + 4, pick(i2, i1)); ! putShort(o, offset + 6, pick(i3, i0)); } private void putLongParts(Object o, long offset, int i0, int i1) { ! putInt(o, offset + 0, pick(i0, i1)); ! putInt(o, offset + 4, pick(i1, i0)); } private void putIntParts(Object o, long offset, short i0, short i1) { ! putShort(o, offset + 0, pick(i0, i1)); ! putShort(o, offset + 2, pick(i1, i0)); } private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) { ! putByte(o, offset + 0, pick(i0, i3)); ! putByte(o, offset + 1, pick(i1, i2)); ! putByte(o, offset + 2, pick(i2, i1)); ! putByte(o, offset + 3, pick(i3, i0)); } private void putShortParts(Object o, long offset, byte i0, byte i1) { ! putByte(o, offset + 0, pick(i0, i1)); ! putByte(o, offset + 1, pick(i1, i0)); } // Zero-extend an integer private static int toUnsignedInt(byte n) { return n & 0xff; } private static int toUnsignedInt(short n) { return n & 0xffff; } --- 1257,1298 ---- // These methods write integers to memory from smaller parts // provided by their caller. The ordering in which these parts // are written is the native endianness of this platform. private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) { ! putByte(o, (offset + 0) << 1, pick(i0, i7)); ! putByte(o, (offset + 1) << 1, pick(i1, i6)); ! putByte(o, (offset + 2) << 1, pick(i2, i5)); ! putByte(o, (offset + 3) << 1, pick(i3, i4)); ! putByte(o, (offset + 4) << 1, pick(i4, i3)); ! putByte(o, (offset + 5) << 1, pick(i5, i2)); ! putByte(o, (offset + 6) << 1, pick(i6, i1)); ! putByte(o, (offset + 7) << 1, pick(i7, i0)); } private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) { ! putShort(o, (offset + 0) << 1, pick(i0, i3)); ! putShort(o, (offset + 2) << 1, pick(i1, i2)); ! putShort(o, (offset + 4) << 1, pick(i2, i1)); ! putShort(o, (offset + 6) << 1, pick(i3, i0)); } private void putLongParts(Object o, long offset, int i0, int i1) { ! putInt(o, (offset + 0) << 1, pick(i0, i1)); ! putInt(o, (offset + 4) << 1, pick(i1, i0)); } private void putIntParts(Object o, long offset, short i0, short i1) { ! putShort(o, (offset + 0) << 1, pick(i0, i1)); ! putShort(o, (offset + 2) << 1, pick(i1, i0)); } private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) { ! putByte(o, (offset + 0) << 1, pick(i0, i3)); ! putByte(o, (offset + 1) << 1, pick(i1, i2)); ! putByte(o, (offset + 2) << 1, pick(i2, i1)); ! putByte(o, (offset + 3) << 1, pick(i3, i0)); } private void putShortParts(Object o, long offset, byte i0, byte i1) { ! putByte(o, (offset + 0) << 1, pick(i0, i1)); ! putByte(o, (offset + 1) << 1, pick(i1, i0)); } // Zero-extend an integer private static int toUnsignedInt(byte n) { return n & 0xff; } private static int toUnsignedInt(short n) { return n & 0xffff; }
< prev index next >