Skip to content

Commit

Permalink
Fix unsafe and JNI bool writes and returns
Browse files Browse the repository at this point in the history
The spec rules on bool's `the int value is narrowed by taking the
bitwise AND of value and 1, resulting in value` only apply to JVM
bytecodes. The Unsafe behaviour in the RI writes `(0 != value)`. 
JNI returns behave the same way.

Signed-off-by: tajila <[email protected]>
  • Loading branch information
tajila committed Nov 30, 2018
1 parent f4a00be commit c089e48
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion runtime/oti/UnsafeAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class VM_UnsafeAPI
static VMINLINE void
putBoolean(J9VMThread *currentThread, MM_ObjectAccessBarrierAPI *objectAccessBarrier, j9object_t object, UDATA offset, bool isVolatile, U_8 value)
{
put32(currentThread, objectAccessBarrier, object, offset, isVolatile, 0, false, (I_32)(value & 1));
put32(currentThread, objectAccessBarrier, object, offset, isVolatile, 0, false, (I_32)(0 != value));
}

static VMINLINE I_16
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/VMHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ class VM_VMHelpers
}
break;
case J9NtcBoolean:
*returnStorage = ((UDATA)(U_8)*returnStorage) & 1;
*returnStorage = ((UDATA)(U_8)(0 != *returnStorage));
break;
case J9NtcByte:
*returnStorage = (UDATA)(IDATA)(I_8)*returnStorage;
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/jnicsup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ JNICALL throwNew(JNIEnv *env, jclass clazz, const char *message)

static void JNICALL setStaticBooleanField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean value)
{
setStaticIntField(env, cls, fieldID, (jint)(value != 0));
setStaticIntField(env, cls, fieldID, (jint)(value & 1));
}


Expand Down

0 comments on commit c089e48

Please sign in to comment.