Skip to content

Commit

Permalink
Merge pull request MobiVM#715 from fgnm/master
Browse files Browse the repository at this point in the history
Add support for putDouble and getDouble from Unsafe.
  • Loading branch information
Tom-Ski authored Mar 27, 2023
2 parents 4a81986 + f45e477 commit 36ce197
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/rt/libcore/libdvm/src/main/java/sun/misc/Unsafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ public native void putObjectVolatile(Object obj, long offset,
*/
public native byte getByte(Object obj, long offset);

/**
* Gets a <code>double</code> field from the given object.
*
* @param obj non-null; object containing the field
* @param offset offset to the field within <code>obj</code>
* @return the retrieved value
*/
public native double getDouble(Object obj, long offset);

/**
* Stores an <code>int</code> field into the given object.
*
Expand Down Expand Up @@ -287,6 +296,15 @@ public native void putObjectVolatile(Object obj, long offset,
*/
public native void putByte(Object obj, long offset, byte newValue);

/**
* Stores a <code>double</code> field into the given object.
*
* @param obj non-null; object containing the field
* @param offset offset to the field within <code>obj</code>
* @param newValue the value to store
*/
public native void putDouble(Object obj, long offset, double newValue);

/**
* Gets an <code>float</code> field from the given object.
*
Expand Down
12 changes: 12 additions & 0 deletions compiler/vm/rt/robovm/sun_misc_Unsafe.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ jbyte Java_sun_misc_Unsafe_getByte(Env* env, Object* unsafe, Object* obj, jlong
return *address;
}

jdouble Java_sun_misc_Unsafe_getDouble(Env* env, Object* unsafe, Object* obj, jlong offset) {
if (!checkNull(env, obj)) return 0;
jdouble* address = (jdouble*) getFieldAddress(obj, offset);
return *address;
}

jint Java_sun_misc_Unsafe_getIntVolatile(Env* env, Object* unsafe, Object* obj, jlong offset) {
if (!checkNull(env, obj)) return 0;
jint* address = (jint*) getFieldAddress(obj, offset);
Expand Down Expand Up @@ -164,6 +170,12 @@ void Java_sun_misc_Unsafe_putByte(Env* env, Object* unsafe, Object* obj, jlong o
*address = newValue;
}

void Java_sun_misc_Unsafe_putDouble(Env* env, Object* unsafe, Object* obj, jlong offset, jdouble newValue) {
if (!checkNull(env, obj)) return;
jdouble* address = (jdouble*) getFieldAddress(obj, offset);
*address = newValue;
}

void Java_sun_misc_Unsafe_putIntVolatile(Env* env, Object* unsafe, Object* obj, jlong offset, jint newValue) {
if (!checkNull(env, obj)) return;
jint* address = (jint*) getFieldAddress(obj, offset);
Expand Down

0 comments on commit 36ce197

Please sign in to comment.