Java Code Examples for sun.misc.Unsafe#putDouble()

The following examples show how to use sun.misc.Unsafe#putDouble() . 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: UnsafeSubstitutionsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("all")
public static double unsafePutDouble(Unsafe unsafe, Object obj, long offset, double value) {
    double res = 1;
    unsafe.putDouble(obj, offset, value);
    res += unsafe.getDouble(obj, offset);
    unsafe.putDoubleVolatile(obj, offset, value);
    res += unsafe.getDouble(obj, offset);
    return res;
}
 
Example 2
Source File: UnsafeSubstitutionsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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 3
Source File: BeanAccessor.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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);
    }
}