Merge pull request #478 from dicej/putDouble

add sun.misc.Unsafe.putDouble(Object,long,double)
This commit is contained in:
Joshua Warner 2016-03-02 15:41:20 +00:00
commit c299319b16
3 changed files with 47 additions and 1 deletions

View File

@ -96,6 +96,14 @@ public final class Unsafe {
putLongVolatile(o, offset, x);
}
public double getDouble(Object o, long offset) {
return getDoubleVolatile(o, offset);
}
public void putDouble(Object o, long offset, double x) {
putDoubleVolatile(o, offset, x);
}
public native void putOrderedLong(Object o, long offset, long x);
public native void putOrderedInt(Object o, long offset, int x);

View File

@ -3093,6 +3093,20 @@ extern "C" AVIAN_EXPORT void JNICALL
fieldAtOffset<int64_t>(o, offset) = value;
}
extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(Thread*,
object,
uintptr_t* arguments)
{
object o = reinterpret_cast<object>(arguments[1]);
int64_t offset;
memcpy(&offset, arguments + 2, 8);
jdouble value;
memcpy(&value, arguments + 4, 8);
fieldAtOffset<jdouble>(o, offset) = value;
}
extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_pageSize(Thread*, object, uintptr_t*)
{

View File

@ -134,7 +134,30 @@ public class UnsafeTest {
== 1.23456789012345D);
}
public static void main(String[] args) {
private static class Data {
public long longField;
public double doubleField;
}
private static void unsafeObject(Unsafe u) throws Exception {
final long longOffset = u.objectFieldOffset
(Data.class.getField("longField"));
final long doubleOffset = u.objectFieldOffset
(Data.class.getField("doubleField"));
Data data = new Data();
u.putLong(data, longOffset, 0x1234567890ABCDEFL);
u.putDouble(data, doubleOffset, 1.23456789012345D);
expect(u.getLong(data, longOffset) == 0x1234567890ABCDEFL);
expect(u.getDouble(data, doubleOffset) == 1.23456789012345D);
}
public static void main(String[] args) throws Exception {
System.out.println("method count is "
+ Unsafe.class.getDeclaredMethods().length);
@ -143,5 +166,6 @@ public class UnsafeTest {
unsafeCatch(u);
unsafeMemory(u);
unsafeArray(u);
unsafeObject(u);
}
}