From 623f73e495c85dc8e4aa0b3ec3ff153c0a237848 Mon Sep 17 00:00:00 2001 From: Theresa Mammarella Date: Tue, 29 Aug 2023 11:35:16 -0400 Subject: [PATCH] NullRestricted Valhalla attribute cfdump support Signed-off-by: Theresa Mammarella --- runtime/bcutil/ClassFileWriter.cpp | 17 +++++++++++++++++ runtime/cfdumper/main.c | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/runtime/bcutil/ClassFileWriter.cpp b/runtime/bcutil/ClassFileWriter.cpp index 16df5db01d8..5f912b84466 100644 --- a/runtime/bcutil/ClassFileWriter.cpp +++ b/runtime/bcutil/ClassFileWriter.cpp @@ -69,6 +69,7 @@ DECLARE_UTF8_ATTRIBUTE_NAME(PRELOAD, "Preload"); #endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */ #if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) DECLARE_UTF8_ATTRIBUTE_NAME(IMPLICITCREATION, "ImplicitCreation"); +DECLARE_UTF8_ATTRIBUTE_NAME(NULLRESTRICTED, "NullRestricted"); #endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */ #if JAVA_SPEC_VERSION >= 11 DECLARE_UTF8_ATTRIBUTE_NAME(NEST_MEMBERS, "NestMembers"); @@ -435,6 +436,12 @@ ClassFileWriter::analyzeFields() } } +#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) + if (J9_ARE_ALL_BITS_SET(fieldShape->modifiers, J9FieldFlagIsNullRestricted)) { + addEntry((void *) &NULLRESTRICTED, 0, CFR_CONSTANT_Utf8); + } +#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */ + fieldShape = romFieldsNextDo(&fieldWalkState); } } @@ -805,6 +812,11 @@ ClassFileWriter::writeField(J9ROMFieldShape * fieldShape) if (NULL != typeAnnotationsData) { attributesCount += 1; } +#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) + if (J9_ARE_ALL_BITS_SET(fieldShape->modifiers, J9FieldFlagIsNullRestricted)) { + attributesCount += 1; + } +#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */ writeU16(U_16(fieldShape->modifiers & CFR_FIELD_ACCESS_MASK)); writeU16(indexForUTF8(name)); @@ -844,6 +856,11 @@ ClassFileWriter::writeField(J9ROMFieldShape * fieldShape) if (NULL != typeAnnotationsData) { writeTypeAnnotationsAttribute(typeAnnotationsData); } +#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) + if (J9_ARE_ALL_BITS_SET(fieldShape->modifiers, J9FieldFlagIsNullRestricted)) { + writeAttributeHeader((J9UTF8 *) &NULLRESTRICTED, 0); + } +#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */ } void diff --git a/runtime/cfdumper/main.c b/runtime/cfdumper/main.c index 88ce90d05be..ace315b3008 100644 --- a/runtime/cfdumper/main.c +++ b/runtime/cfdumper/main.c @@ -1362,6 +1362,14 @@ static void printField(J9CfrClassFile* classfile, J9CfrField* field) for(i = 0; i < arity; i++) j9tty_printf( PORTLIB, "[]"); +#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) + for(i = 0; i < field->attributesCount; i++) { + if (CFR_ATTRIBUTE_NullRestricted == field->attributes[i]->tag) { + j9tty_printf(PORTLIB, "!"); + } + } +#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */ + j9tty_printf( PORTLIB, " %s;\n", classfile->constantPool[field->nameIndex].bytes); return;