Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#17781 from theresa-m/part1
Browse files Browse the repository at this point in the history
JEP 401 NullRestricted attribute part 1
  • Loading branch information
hangshao0 authored Aug 3, 2023
2 parents 21eae58 + c4d4742 commit a40721e
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 67 deletions.
13 changes: 11 additions & 2 deletions runtime/bcutil/ClassFileOracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ ClassFileOracle::ClassFileOracle(BufferManager *bufferManager, J9CfrClassFile *c
_hasNonStaticFields(false),
_hasNonEmptyConstructor(false),
_preloadAttribute(NULL),
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
_implicitCreation(NULL),
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
_recordComponentCount(0),
_permittedSubclassesAttribute(NULL),
_isSealed(false),
Expand Down Expand Up @@ -457,6 +459,11 @@ ClassFileOracle::walkFields()
case CFR_ATTRIBUTE_Deprecated:
/* Do nothing */
break;
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
case CFR_ATTRIBUTE_NullRestricted:
_fieldsInfo[fieldIndex].isNullRestricted = true;
break;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
default:
Trc_BCU_ClassFileOracle_walkFields_UnknownAttribute((U_32)attrib->tag, (U_32)getUTF8Length(attrib->nameIndex), getUTF8Data(attrib->nameIndex), attrib->length);
break;
Expand Down Expand Up @@ -615,11 +622,13 @@ ClassFileOracle::walkAttributes()
}
break;
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
case CFR_ATTRIBUTE_ImplicitCreation: {
_implicitCreation = (J9CfrAttributeImplicitCreation *)attrib;
break;
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
#if JAVA_SPEC_VERSION >= 11
case CFR_ATTRIBUTE_NestMembers:
/* ignore CFR_ATTRIBUTE_NestMembers for hidden classes, as the nest members never know the name of hidden classes */
Expand Down
29 changes: 19 additions & 10 deletions runtime/bcutil/ClassFileOracle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
* */
#define UTF8_INDEX_FROM_CLASS_INDEX(cp, cpIndex) ((U_16)((cpIndex == 0)? 0 : cp[cpIndex].slot1))

#define IMPLICIT_CREATION_FLAGS_DEFAULT 1
#define IMPLICIT_CREATION_FLAGS_NON_ATOMIC 2

class BufferManager;
class ConstantPoolMap;
class ROMClassCreationContext;
Expand All @@ -68,6 +65,9 @@ class ClassFileOracle
J9CfrAttributeRuntimeVisibleAnnotations *annotationsAttribute;
J9CfrAttributeRuntimeVisibleTypeAnnotations *typeAnnotationsAttribute;
bool isFieldContended;
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
bool isNullRestricted;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
};

struct StackMapFrameInfo
Expand Down Expand Up @@ -345,7 +345,9 @@ class FieldIterator
bool hasAnnotation() const { return _fieldsInfo[_index].annotationsAttribute != NULL;}
bool hasTypeAnnotation() const { return _fieldsInfo[_index].typeAnnotationsAttribute != NULL;}
bool isFieldContended() const { return _fieldsInfo[_index].isFieldContended; }

#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
bool isNullRestricted() const { return _fieldsInfo[_index].isNullRestricted; }
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

U_32 getConstantValueSlot1() const { return _classFile->constantPool[getConstantValueConstantPoolIndex()].slot1; }
U_32 getConstantValueSlot2() const { return _classFile->constantPool[getConstantValueConstantPoolIndex()].slot2; }
Expand Down Expand Up @@ -1020,10 +1022,6 @@ class RecordComponentIterator
bool needsIdentityFlag() const { return _isIdentityFlagNeeded; }
bool hasIdentityFlagSet() const { return _hasIdentityFlagSet; }
bool isValueType() const { return _isValueType; }
bool hasImplicitCreation() const { return NULL != _implicitCreation; }
U_16 getImplicitCreationFlags() const { return hasImplicitCreation() ? _implicitCreation->implicitCreationFlags : 0; }
bool isImplicitCreationHasDefaultValue() const { return J9_ARE_ALL_BITS_SET(getImplicitCreationFlags(), IMPLICIT_CREATION_FLAGS_DEFAULT); }
bool isImplicitCreationNonAtomic() const { return J9_ARE_ALL_BITS_SET(getImplicitCreationFlags(), IMPLICIT_CREATION_FLAGS_NON_ATOMIC); }
bool hasPreloadClasses() const { return NULL != _preloadAttribute; }
U_16 getPreloadClassCount() const { return hasPreloadClasses() ? _preloadAttribute->numberOfClasses : 0; }

Expand All @@ -1035,7 +1033,16 @@ class RecordComponentIterator
}
return result;
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
#define IMPLICIT_CREATION_FLAGS_DEFAULT 1
#define IMPLICIT_CREATION_FLAGS_NON_ATOMIC 2

bool hasImplicitCreation() const { return NULL != _implicitCreation; }
U_16 getImplicitCreationFlags() const { return hasImplicitCreation() ? _implicitCreation->implicitCreationFlags : 0; }
bool isImplicitCreationHasDefaultValue() const { return J9_ARE_ALL_BITS_SET(getImplicitCreationFlags(), IMPLICIT_CREATION_FLAGS_DEFAULT); }
bool isImplicitCreationNonAtomic() const { return J9_ARE_ALL_BITS_SET(getImplicitCreationFlags(), IMPLICIT_CREATION_FLAGS_NON_ATOMIC); }
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

U_16 getPermittedSubclassesClassNameAtIndex(U_16 index) const {
U_16 result = 0;
Expand Down Expand Up @@ -1165,9 +1172,11 @@ class RecordComponentIterator
J9CfrAttributeBootstrapMethods *_bootstrapMethodsAttribute;
J9CfrAttributePermittedSubclasses *_permittedSubclassesAttribute;
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
J9CfrAttributeImplicitCreation *_implicitCreation;
J9CfrAttributePreload *_preloadAttribute;
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
J9CfrAttributeImplicitCreation *_implicitCreation;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
#if JAVA_SPEC_VERSION >= 11
J9CfrAttributeNestMembers *_nestMembers;
#endif /* JAVA_SPEC_VERSION >= 11 */
Expand Down
4 changes: 2 additions & 2 deletions runtime/bcutil/ROMClassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,14 +1337,14 @@ ROMClassBuilder::computeExtraModifiers(ClassFileOracle *classFileOracle, ROMClas
modifiers |= J9AccSealed;
}

#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (classFileOracle->isImplicitCreationNonAtomic()) {
modifiers |= J9AccImplicitCreateNonAtomic;
}
if (classFileOracle->isImplicitCreationHasDefaultValue()) {
modifiers |= J9AccImplicitCreateHasDefaultValue;
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

return modifiers;
}
Expand Down
5 changes: 5 additions & 0 deletions runtime/bcutil/ROMClassWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ ROMClassWriter::writeFields(Cursor *cursor, bool markAndCountOnly)
if (iterator.hasTypeAnnotation()) {
modifiers |= J9FieldFlagHasTypeAnnotations;
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (iterator.isNullRestricted()) {
modifiers |= J9FieldFlagIsNullRestricted;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

cursor->writeU32(modifiers, Cursor::GENERIC);
}
Expand Down
6 changes: 5 additions & 1 deletion runtime/bcutil/attrlookup.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
* This file is the input to the gperf utility for generating a perfect
* hash table of attribute names, which is used by attributeTagFor().
*
* To generate attrlookup.h, use the following command-line with gperf 3.0.4:
* Types generated by gperf cause compiler issues in the OpenJ9 Windows builds,
* use the existing types.
*
* To generate attrlookup.h, use the following command-line with the latest version of gperf:
*
* gperf -CD -t --output-file=attrlookup.h attrlookup.gperf
*
Expand Down Expand Up @@ -74,3 +77,4 @@ Record, CFR_ATTRIBUTE_Record, CFR_ATTRIBUTE_Record
PermittedSubclasses, CFR_ATTRIBUTE_PermittedSubclasses, CFR_ATTRIBUTE_PermittedSubclasses
ImplicitCreation, CFR_ATTRIBUTE_ImplicitCreation, CFR_ATTRIBUTE_ImplicitCreation
Preload, CFR_ATTRIBUTE_Preload, CFR_ATTRIBUTE_Preload
NullRestricted, CFR_ATTRIBUTE_NullRestricted, CFR_ATTRIBUTE_NullRestricted
86 changes: 44 additions & 42 deletions runtime/bcutil/attrlookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/

/* ANSI-C code produced by gperf version 3.0.4 */
/* ANSI-C code produced by gperf version 3.1 */
/* Command-line: gperf -CD -t --output-file=attrlookup.h attrlookup.gperf */
/* Computed positions: -k'2' */

Expand Down Expand Up @@ -48,18 +48,18 @@
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-[email protected]>."
#error "gperf generated tables don't work with this execution character set. Please report a bug to <[email protected]>."
#endif

#line 39 "attrlookup.gperf"
#line 42 "attrlookup.gperf"
struct AttribType
{
const char *name;
U_8 attribCode;
U_8 strippedAttribCode;
};

#define TOTAL_KEYWORDS 30
#define TOTAL_KEYWORDS 31
#define MIN_WORD_LENGTH 4
#define MAX_WORD_LENGTH 36
#define MIN_HASH_VALUE 4
Expand All @@ -73,8 +73,8 @@ __inline
inline
#endif
#endif
static unsigned int
attributeHash (register const char *str, register unsigned int len)
static size_t
attributeHash (register const char *str, register size_t len)
{
static const unsigned char asso_values[] =
{
Expand Down Expand Up @@ -115,85 +115,87 @@ __attribute__ ((__gnu_inline__))
#endif
#endif
const struct AttribType *
lookupKnownAttribute (register const char *str, register unsigned int len)
lookupKnownAttribute (register const char *str, register size_t len)
{
static const struct AttribType wordlist[] =
{
#line 47 "attrlookup.gperf"
#line 50 "attrlookup.gperf"
{"Code", CFR_ATTRIBUTE_Code, CFR_ATTRIBUTE_Code},
#line 76 "attrlookup.gperf"
#line 79 "attrlookup.gperf"
{"Preload", CFR_ATTRIBUTE_Preload, CFR_ATTRIBUTE_Preload},
#line 49 "attrlookup.gperf"
#line 52 "attrlookup.gperf"
{"Synthetic", CFR_ATTRIBUTE_Synthetic, CFR_ATTRIBUTE_Synthetic},
#line 53 "attrlookup.gperf"
#line 56 "attrlookup.gperf"
{"SourceFile", CFR_ATTRIBUTE_SourceFile, CFR_ATTRIBUTE_SourceFile},
#line 54 "attrlookup.gperf"
#line 57 "attrlookup.gperf"
{"InnerClasses", CFR_ATTRIBUTE_InnerClasses, CFR_ATTRIBUTE_InnerClasses},
#line 55 "attrlookup.gperf"
#line 58 "attrlookup.gperf"
{"ConstantValue", CFR_ATTRIBUTE_ConstantValue, CFR_ATTRIBUTE_ConstantValue},
#line 57 "attrlookup.gperf"
#line 80 "attrlookup.gperf"
{"NullRestricted", CFR_ATTRIBUTE_NullRestricted, CFR_ATTRIBUTE_NullRestricted},
#line 60 "attrlookup.gperf"
{"EnclosingMethod", CFR_ATTRIBUTE_EnclosingMethod, CFR_ATTRIBUTE_EnclosingMethod},
#line 59 "attrlookup.gperf"
#line 62 "attrlookup.gperf"
{"BootstrapMethods", CFR_ATTRIBUTE_BootstrapMethods, CFR_ATTRIBUTE_BootstrapMethods},
#line 60 "attrlookup.gperf"
#line 63 "attrlookup.gperf"
{"AnnotationDefault", CFR_ATTRIBUTE_AnnotationDefault, CFR_ATTRIBUTE_AnnotationDefault},
#line 61 "attrlookup.gperf"
#line 64 "attrlookup.gperf"
{"LocalVariableTable", CFR_ATTRIBUTE_LocalVariableTable, CFR_ATTRIBUTE_StrippedLocalVariableTable},
#line 62 "attrlookup.gperf"
#line 65 "attrlookup.gperf"
{"SourceDebugExtension", CFR_ATTRIBUTE_SourceDebugExtension, CFR_ATTRIBUTE_StrippedSourceDebugExtension},
#line 75 "attrlookup.gperf"
#line 78 "attrlookup.gperf"
{"ImplicitCreation", CFR_ATTRIBUTE_ImplicitCreation, CFR_ATTRIBUTE_ImplicitCreation},
#line 63 "attrlookup.gperf"
#line 66 "attrlookup.gperf"
{"LocalVariableTypeTable", CFR_ATTRIBUTE_LocalVariableTypeTable, CFR_ATTRIBUTE_StrippedLocalVariableTypeTable},
#line 48 "attrlookup.gperf"
#line 51 "attrlookup.gperf"
{"StackMap", CFR_ATTRIBUTE_StackMap, CFR_ATTRIBUTE_StackMap},
#line 50 "attrlookup.gperf"
#line 53 "attrlookup.gperf"
{"Signature", CFR_ATTRIBUTE_Signature, CFR_ATTRIBUTE_Signature},
#line 64 "attrlookup.gperf"
#line 67 "attrlookup.gperf"
{"RuntimeVisibleAnnotations", CFR_ATTRIBUTE_RuntimeVisibleAnnotations, CFR_ATTRIBUTE_RuntimeVisibleAnnotations},
#line 65 "attrlookup.gperf"
#line 68 "attrlookup.gperf"
{"RuntimeInvisibleAnnotations", CFR_ATTRIBUTE_RuntimeInvisibleAnnotations, CFR_ATTRIBUTE_RuntimeInvisibleAnnotations},
#line 56 "attrlookup.gperf"
#line 59 "attrlookup.gperf"
{"StackMapTable", CFR_ATTRIBUTE_StackMapTable, CFR_ATTRIBUTE_StackMapTable},
#line 66 "attrlookup.gperf"
#line 69 "attrlookup.gperf"
{"RuntimeVisibleTypeAnnotations", CFR_ATTRIBUTE_RuntimeVisibleTypeAnnotations, CFR_ATTRIBUTE_RuntimeVisibleTypeAnnotations},
#line 58 "attrlookup.gperf"
#line 61 "attrlookup.gperf"
{"LineNumberTable", CFR_ATTRIBUTE_LineNumberTable, CFR_ATTRIBUTE_StrippedLineNumberTable},
#line 67 "attrlookup.gperf"
#line 70 "attrlookup.gperf"
{"RuntimeInvisibleTypeAnnotations", CFR_ATTRIBUTE_RuntimeInvisibleTypeAnnotations, CFR_ATTRIBUTE_RuntimeInvisibleTypeAnnotations},
#line 68 "attrlookup.gperf"
#line 71 "attrlookup.gperf"
{"RuntimeVisibleParameterAnnotations", CFR_ATTRIBUTE_RuntimeVisibleParameterAnnotations, CFR_ATTRIBUTE_RuntimeVisibleParameterAnnotations},
#line 52 "attrlookup.gperf"
#line 55 "attrlookup.gperf"
{"Exceptions", CFR_ATTRIBUTE_Exceptions, CFR_ATTRIBUTE_Exceptions},
#line 69 "attrlookup.gperf"
#line 72 "attrlookup.gperf"
{"RuntimeInvisibleParameterAnnotations", CFR_ATTRIBUTE_RuntimeInvisibleParameterAnnotations, CFR_ATTRIBUTE_RuntimeInvisibleParameterAnnotations},
#line 73 "attrlookup.gperf"
#line 76 "attrlookup.gperf"
{"Record", CFR_ATTRIBUTE_Record, CFR_ATTRIBUTE_Record},
#line 72 "attrlookup.gperf"
#line 75 "attrlookup.gperf"
{"NestHost", CFR_ATTRIBUTE_NestHost, CFR_ATTRIBUTE_NestHost},
#line 51 "attrlookup.gperf"
#line 54 "attrlookup.gperf"
{"Deprecated", CFR_ATTRIBUTE_Deprecated, CFR_ATTRIBUTE_Deprecated},
#line 71 "attrlookup.gperf"
#line 74 "attrlookup.gperf"
{"NestMembers", CFR_ATTRIBUTE_NestMembers, CFR_ATTRIBUTE_NestMembers},
#line 70 "attrlookup.gperf"
#line 73 "attrlookup.gperf"
{"MethodParameters", CFR_ATTRIBUTE_MethodParameters, CFR_ATTRIBUTE_MethodParameters},
#line 74 "attrlookup.gperf"
#line 77 "attrlookup.gperf"
{"PermittedSubclasses", CFR_ATTRIBUTE_PermittedSubclasses, CFR_ATTRIBUTE_PermittedSubclasses}
};

static const signed char lookup[] =
{
-1, -1, -1, -1, 0, -1, -1, 1, -1, 2, 3, -1, 4, 5,
-1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, -1, 16,
17, 18, 19, 20, -1, -1, 21, 22, 23, 24, -1, 25, -1, 26,
27, -1, -1, -1, -1, 28, -1, -1, 29
6, 7, 8, 9, 10, -1, 11, 12, 13, 14, 15, 16, -1, 17,
18, 19, 20, 21, -1, -1, 22, 23, 24, 25, -1, 26, -1, 27,
28, -1, -1, -1, -1, 29, -1, -1, 30
};

if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = attributeHash (str, len);
register size_t key = attributeHash (str, len);

if (key <= MAX_HASH_VALUE && key >= 0)
if (key <= MAX_HASH_VALUE)
{
register int index = lookup[key];

Expand Down
Loading

0 comments on commit a40721e

Please sign in to comment.