Skip to content

Commit

Permalink
Merge pull request #4651 from MarkQingGuo/acm
Browse files Browse the repository at this point in the history
Add ValueType support to the if_acmp bytecodes
  • Loading branch information
gacholio committed Mar 4, 2019
2 parents 0b1db0c + dff98d5 commit 01be53f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
54 changes: 52 additions & 2 deletions runtime/vm/BytecodeInterpreter.hpp
Expand Up @@ -7183,6 +7183,56 @@ done:;
return rc;
}

/*
* Determine if the two objects are substitutable
*
* @param[in] lhs the lhs object of acmp bytecodes
* @param[in] rhs the rhs object of acmp bytecodes
* return true if they are substituable and false otherwise
*/
VMINLINE bool
acmp(j9object_t lhs, j9object_t rhs)
{
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
bool acmpResult = false;
if (rhs == lhs) {
acmpResult = true;
} else if ((NULL == rhs) || (NULL == lhs)) {
acmpResult = false;
} else {
J9Class * lhsClass = J9OBJECT_CLAZZ(_currentThread, lhs);
J9Class * rhsClass = J9OBJECT_CLAZZ(_currentThread, rhs);
if ((J9_IS_J9CLASS_VALUETYPE(rhsClass)
&& J9_IS_J9CLASS_VALUETYPE(lhsClass))
&& (rhsClass == lhsClass)
) {
acmpResult = isSubstitutable(lhs, rhs);
}
}
return acmpResult;
#else /* J9VM_OPT_VALHALLA_VALUE_TYPES */
return (rhs == lhs);
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
}

#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
/*
* Determine if the two valueTypes are substitutable when rhs.class equals lhs.class
*
* @param[in] lhs the lhs object of acmp bytecodes and it's a valueType
* @param[in] rhs the rhs object of acmp bytecodes and it's a valueType
* return true if they are substitutable and false otherwise
*/
VMINLINE bool
isSubstitutable(j9object_t lhs, j9object_t rhs)
{
/*
* TODO: this will be updated in a future PR.
*/
return false;
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */

/* ..., lhs, rhs => ... */
VMINLINE VM_BytecodeAction
ifacmpeq(REGISTER_ARGS_LIST)
Expand All @@ -7192,7 +7242,7 @@ done:;
j9object_t lhs = *(j9object_t*)(_sp + 1);
U_8 *profilingCursor = startProfilingRecord(REGISTER_ARGS, sizeof(U_8));
_sp += 2;
if (lhs == rhs) {
if(acmp(lhs, rhs)) {
_pc += *(I_16*)(_pc + 1);
if (NULL != profilingCursor) {
*profilingCursor = 1;
Expand All @@ -7216,7 +7266,7 @@ done:;
j9object_t lhs = *(j9object_t*)(_sp + 1);
U_8 *profilingCursor = startProfilingRecord(REGISTER_ARGS, sizeof(U_8));
_sp += 2;
if (lhs != rhs) {
if(!acmp(lhs, rhs)) {
_pc += *(I_16*)(_pc + 1);
if (NULL != profilingCursor) {
*profilingCursor = 1;
Expand Down
Expand Up @@ -362,7 +362,38 @@ static public void testWithFieldOnNonExistentClass() throws Throwable {
Assert.fail("should throw error. Class does not exist");
} catch (NoClassDefFoundError e) {}
}


/*
* Test ifacmp on value class
*
* class TestIfacmpOnValueClass {}
*/
@Test(priority=2)
static public void TestIfacmpOnValueClass() throws Throwable {
int x = 0;
int y = 0;

Object valueType = makePoint2D.invoke(x, y);

Object refType = (Object) x;

Assert.assertFalse((valueType == refType), "An identity (==) comparison that contains a valueType should always return false");

Assert.assertFalse((refType == valueType), "An identity (==) comparison that contains a valueType should always return false");

Assert.assertFalse((valueType == valueType), "An identity (==) comparison that contains a valueType should always return false");

Assert.assertTrue((refType == refType), "An identity (==) comparison on the same refType should always return true");

Assert.assertTrue((valueType != refType), "An identity (!=) comparison that contains a valueType should always return true");

Assert.assertTrue((refType != valueType), "An identity (!=) comparison that contains a valueType should always return true");

Assert.assertTrue((valueType != valueType), "An identity (!=) comparison that contains a valueType should always return true");

Assert.assertFalse((refType != refType), "An identity (!=) comparison on the same refType should always return false");
}

static MethodHandle generateGetter(Class<?> clazz, String fieldName, Class<?> fieldType) {
try {
return lookup.findVirtual(clazz, "get"+fieldName, MethodType.methodType(fieldType));
Expand Down

0 comments on commit 01be53f

Please sign in to comment.