Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set java.lang.reflect.Field flags for value types #20552

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hangshao0 marked this conversation as resolved.
Show resolved Hide resolved
#define NULL_RESTRICTED 0x20
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES)*/

#ifdef __cplusplus
}
#endif
Expand Down