Skip to content

Commit

Permalink
Merge pull request #20552 from theresa-m/fix_20372
Browse files Browse the repository at this point in the history
Set java.lang.reflect.Field flags for value types
  • Loading branch information
hangshao0 authored Nov 12, 2024
2 parents ecbfade + c851331 commit 6f623b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions runtime/jcl/common/reflecthelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ createField(struct J9VMThread *vmThread, jfieldID fieldID)
j9object_t fieldObject = NULL;
J9Class *jlrFieldClass = J9VMJAVALANGREFLECTFIELD(vmThread->javaVM);
UDATA initStatus;
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
U_32 fieldFlags = 0; /* used to calculate value of Field.flags in value type builds */
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */

if (NULL == jlrFieldClass) {
return NULL;
Expand Down Expand Up @@ -837,9 +840,20 @@ createField(struct J9VMThread *vmThread, jfieldID fieldID)
|| J9ROMCLASS_IS_RECORD(j9FieldID->declaringClass->romClass)
|| J9ROMCLASS_IS_HIDDEN(j9FieldID->declaringClass->romClass)
) {
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
fieldFlags |= TRUST_FINAL;
#else /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
J9VMJAVALANGREFLECTFIELD_SET_TRUSTEDFINAL(vmThread, fieldObject, JNI_TRUE);
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
}
}
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
if (J9ROMFIELD_IS_NULL_RESTRICTED(j9FieldID->field)) {
fieldFlags |= NULL_RESTRICTED;
}
/* alias is "int flags;" in value types */
J9VMJAVALANGREFLECTFIELD_SET_TRUSTEDFINAL(vmThread, fieldObject, fieldFlags);
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#endif /* JAVA_SPEC_VERSION >= 15 */

return fieldObject;
Expand Down
6 changes: 6 additions & 0 deletions runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,12 @@ extern "C" {
#define PREVIEW_MINOR_VERSION 65535
#define J9_IS_CLASSFILE_OR_ROMCLASS_VALUETYPE_VERSION(classfileOrRomClass) (((classfileOrRomClass)->majorVersion >= VALUE_TYPES_MAJOR_VERSION) && (PREVIEW_MINOR_VERSION == (classfileOrRomClass)->minorVersion))

#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
/* Constants for java.lang.reflect.Field flags */
#define TRUST_FINAL 0x10
#define NULL_RESTRICTED 0x20
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES)*/

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 6f623b4

Please sign in to comment.