Skip to content

Commit af0d3d3

Browse files
Aditi Srinivas MAditi Srinivas M
authored andcommitted
Add value type hash logic under Valhalla flag
- Guard zero hashcode check with Valhalla flags. Signed-off-by: Aditi Srinivas M <Aditi.Srini@ibm.com>
1 parent 619bdfd commit af0d3d3

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

jcl/src/java.base/share/classes/java/lang/J9VMInternals.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,20 +504,26 @@ static int fastIdentityHashCode(Object anObject) {
504504
if ((ptr & com.ibm.oti.vm.VM.OBJECT_HEADER_HAS_BEEN_MOVED_IN_CLASS) != 0) {
505505
int j9class = ptr & com.ibm.oti.vm.VM.J9_JAVA_CLASS_MASK;
506506
int hashValue = h.getIntFromObject(anObject, h.getBackfillOffsetFromJ9Class32(j9class));
507+
/*[IF INLINE-TYPES]*/
507508
/* If the hash is 0, it may be a value object and the hash should be calculated. */
508-
if (0 != hashValue) {
509-
return hashValue;
509+
if ((0 == hashValue) && anObject.getClass().isValue()) {
510+
return identityHashCode(anObject);
510511
}
512+
/*[ENDIF] INLINE-TYPES */
513+
return hashValue;
511514
}
512515
} else {
513516
long ptr = (com.ibm.oti.vm.VM.FJ9OBJECT_SIZE == 4) ? Integer.toUnsignedLong(h.getIntFromObject(anObject, 0L)) : h.getLongFromObject(anObject, 0L);
514517
if ((ptr & com.ibm.oti.vm.VM.OBJECT_HEADER_HAS_BEEN_MOVED_IN_CLASS) != 0) {
515518
long j9class = ptr & com.ibm.oti.vm.VM.J9_JAVA_CLASS_MASK;
516519
int hashValue = h.getIntFromObject(anObject, h.getBackfillOffsetFromJ9Class64(j9class));
520+
/*[IF INLINE-TYPES]*/
517521
/* If the hash is 0, it may be a value object and the hash should be calculated. */
518-
if (0 != hashValue) {
519-
return hashValue;
522+
if ((0 == hashValue) && anObject.getClass().isValue()) {
523+
return identityHashCode(anObject);
520524
}
525+
/*[ENDIF] INLINE-TYPES */
526+
return hashValue;
521527
}
522528
}
523529
return identityHashCode(anObject);

runtime/gc_glue_java/ObjectModel.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,12 @@ class GC_ObjectModel : public GC_ObjectModelBase
422422
uintptr_t hashOffset = getHashcodeOffset(object);
423423
int32_t *hashCodePointer = (int32_t *)((uint8_t *)object + hashOffset);
424424
result = *hashCodePointer;
425+
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
425426
if (0 == result) {
426427
result = internalConvertObjectToHash(vm, object);
427428
*hashCodePointer = result;
428429
}
430+
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
429431
} else {
430432
atomicSetObjectFlags(object, 0, OBJECT_HEADER_HAS_BEEN_HASHED_IN_CLASS);
431433
result = internalConvertObjectToHash(vm, object);

0 commit comments

Comments
 (0)