Java Code Examples for sun.misc.Unsafe#putShort()
The following examples show how to use
sun.misc.Unsafe#putShort() .
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: UnsafeUtils.java From message-queue-java with MIT License | 5 votes |
public static void main(String[] args) { Unsafe unsafe = getUnsafe(); long address = unsafe.allocateMemory(2); short number = 1; unsafe.putShort(address, number); if (unsafe.getByte(address) == 0) System.out.println("Big Endian"); else System.out.println("Little Endian"); unsafe.freeMemory(address); }
Example 2
Source File: UnsafeSubstitutionsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("all") public static int unsafePutShort(Unsafe unsafe, Object obj, long offset, short value) { int res = 1; unsafe.putShort(obj, offset, (short) (value + 1)); res += unsafe.getShort(obj, offset); unsafe.putShortVolatile(obj, offset, (short) (value + 2)); res += unsafe.getShort(obj, offset); return res; }
Example 3
Source File: UnsafeSubstitutionsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("all") public static double unsafeDirectMemoryWrite(Unsafe unsafe, long address, long value) { // Unsafe.putBoolean(long) and Unsafe.putObject(long) do not exist unsafe.putByte(address + 0, (byte) value); unsafe.putShort(address + 8, (short) value); unsafe.putChar(address + 16, (char) value); unsafe.putInt(address + 24, (int) value); unsafe.putLong(address + 32, value); unsafe.putFloat(address + 40, value); unsafe.putDouble(address + 48, value); return unsafeDirectMemoryRead(unsafe, address); }
Example 4
Source File: BeanAccessor.java From TarsJava with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void setBeanValue(Object bean, String fieldName, Object data) { if (bean == null || fieldName == null) { return; } Class<?> clazz = bean.getClass(); Map<String, Field> fieldMap = getBeanFieldMap(clazz); Field field = fieldMap.get(fieldName); Unsafe unsafe = getUnsafeInstance(); if (unsafe == null) { try { field.set(bean, data); } catch (Exception e) { throw new RuntimeException(e); } } long offset = getBeanFieldOffset(clazz, fieldName); if (offset == -1) { return; } Class<?> type = field.getType(); if (type == boolean.class) { unsafe.putBoolean(bean, offset, ((Boolean) data).booleanValue()); } else if (type == byte.class) { unsafe.putByte(bean, offset, ((Byte) data).byteValue()); } else if (type == short.class) { unsafe.putShort(bean, offset, ((Short) data).shortValue()); } else if (type == char.class) { unsafe.putChar(bean, offset, ((Character) data).charValue()); } else if (type == int.class) { unsafe.putInt(bean, offset, ((Integer) data).intValue()); } else if (type == long.class) { unsafe.putLong(bean, offset, ((Long) data).longValue()); } else if (type == float.class) { unsafe.putFloat(bean, offset, ((Float) data).floatValue()); } else if (type == double.class) { unsafe.putDouble(bean, offset, ((Double) data).doubleValue()); } else { unsafe.putObject(bean, offset, data); } }