From c089e480b10798bceacbaf11529e2b17e398ffe7 Mon Sep 17 00:00:00 2001 From: tajila Date: Fri, 30 Nov 2018 14:32:32 -0500 Subject: [PATCH] Fix unsafe and JNI bool writes and returns 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 --- runtime/oti/UnsafeAPI.hpp | 2 +- runtime/oti/VMHelpers.hpp | 2 +- runtime/vm/jnicsup.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/oti/UnsafeAPI.hpp b/runtime/oti/UnsafeAPI.hpp index 3fd7a076ae1..02c825ba1e6 100644 --- a/runtime/oti/UnsafeAPI.hpp +++ b/runtime/oti/UnsafeAPI.hpp @@ -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 diff --git a/runtime/oti/VMHelpers.hpp b/runtime/oti/VMHelpers.hpp index cc15e083e8e..15c842c1e26 100644 --- a/runtime/oti/VMHelpers.hpp +++ b/runtime/oti/VMHelpers.hpp @@ -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; diff --git a/runtime/vm/jnicsup.cpp b/runtime/vm/jnicsup.cpp index da458a0104a..9b66a161711 100644 --- a/runtime/vm/jnicsup.cpp +++ b/runtime/vm/jnicsup.cpp @@ -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)); }