Skip to content

Commit

Permalink
Merge pull request #17960 from theresa-m/ic_vm
Browse files Browse the repository at this point in the history
Correct implicit creation attribute flag storage
  • Loading branch information
hangshao0 authored Aug 16, 2023
2 parents 949a4df + 936aa13 commit 8e0d9da
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 24 deletions.
5 changes: 0 additions & 5 deletions runtime/bcutil/ClassFileOracle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,13 +1035,8 @@ class RecordComponentIterator
}
#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 {
Expand Down
18 changes: 7 additions & 11 deletions runtime/bcutil/ROMClassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,8 @@ ROMClassBuilder::finishPrepareAndLaydown(
* + UNUSED
* + UNUSED
*
* + AccImplicitCreateHasDefaultValue
* + AccImplicitCreateNonAtomic
* + UNUSED
* + UNUSED
* + J9AccClassIsValueBased
* + J9AccClassHiddenOptionNestmate
*
Expand Down Expand Up @@ -1337,15 +1337,6 @@ ROMClassBuilder::computeExtraModifiers(ClassFileOracle *classFileOracle, ROMClas
modifiers |= J9AccSealed;
}

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

return modifiers;
}

Expand Down Expand Up @@ -1394,6 +1385,11 @@ ROMClassBuilder::computeOptionalFlags(ClassFileOracle *classFileOracle, ROMClass
optionalFlags |= J9_ROMCLASS_OPTINFO_PRELOAD_ATTRIBUTE;
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (classFileOracle->hasImplicitCreation()) {
optionalFlags |= J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
return optionalFlags;
}

Expand Down
37 changes: 35 additions & 2 deletions runtime/bcutil/ROMClassWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ ROMClassWriter::ROMClassWriter(BufferManager *bufferManager, ClassFileOracle *cl
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
_injectedInterfaceInfoSRPKey(srpKeyProducer->generateKey()),
_preloadInfoSRPKey(srpKeyProducer->generateKey()),
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
_implicitCreationSRPKey(srpKeyProducer->generateKey()),
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
_permittedSubclassesInfoSRPKey(srpKeyProducer->generateKey())
{
_methodNotes = (MethodNotes *) _bufferManager->alloc(classFileOracle->getMethodsCount() * sizeof(MethodNotes));
Expand Down Expand Up @@ -459,6 +462,9 @@ ROMClassWriter::writeROMClass(Cursor *cursor,
writeInjectedInterfaces(cursor, markAndCountOnly);
writePreload(cursor, markAndCountOnly);
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
writeImplicitCreation(cursor, markAndCountOnly);
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
writeOptionalInfo(cursor);
writeCallSiteData(cursor, markAndCountOnly);
#if defined(J9VM_OPT_METHOD_HANDLE)
Expand Down Expand Up @@ -1883,6 +1889,27 @@ ROMClassWriter::writePermittedSubclasses(Cursor *cursor, bool markAndCountOnly)
}
}

#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
/*
* ImplicitCreation ROM class layout:
* 4 bytes for flags (actually takes up two, but use 4 for alignment)
*/
void
ROMClassWriter::writeImplicitCreation(Cursor *cursor, bool markAndCountOnly)
{
if (_classFileOracle->hasImplicitCreation()) {
cursor->mark(_implicitCreationSRPKey);

U_16 flags = _classFileOracle->getImplicitCreationFlags();
if (markAndCountOnly) {
cursor->skip(sizeof(U_32));
} else {
cursor->writeU32(flags, Cursor::GENERIC);
}
}
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
/*
* Preload ROM class layout:
Expand Down Expand Up @@ -1966,6 +1993,7 @@ ROMClassWriter::writeOptionalInfo(Cursor *cursor)
* SRP to PermittedSubclasses attribute
* SRP to injected interfaces info
* SRP to Preload attribute
* SRP to ImplicitCreation attribute
*/
cursor->mark(_optionalInfoSRPKey);

Expand Down Expand Up @@ -2014,7 +2042,12 @@ ROMClassWriter::writeOptionalInfo(Cursor *cursor)
if (_classFileOracle->hasPreloadClasses()) {
cursor->writeSRP(_preloadInfoSRPKey, Cursor::SRP_TO_GENERIC);
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (_classFileOracle->hasImplicitCreation()) {
cursor->writeSRP(_implicitCreationSRPKey, Cursor::SRP_TO_GENERIC);
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
}

void
Expand Down
8 changes: 7 additions & 1 deletion runtime/bcutil/ROMClassWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class ROMClassWriter
void writeInjectedInterfaces(Cursor *cursor, bool markAndCountOnly);
void writePreload(Cursor *cursor, bool markAndCountOnly);
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
void writeImplicitCreation(Cursor *cursor, bool markAndCountOnly);
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

BufferManager *_bufferManager;
ClassFileOracle *_classFileOracle;
Expand Down Expand Up @@ -195,7 +198,10 @@ class ROMClassWriter
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
UDATA _injectedInterfaceInfoSRPKey;
UDATA _preloadInfoSRPKey;
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
UDATA _implicitCreationSRPKey;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
};

#endif /* ROMCLASSWRITER_HPP_ */
2 changes: 0 additions & 2 deletions runtime/oti/j9modifiers_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@
#define J9ROMCLASS_IS_RECORD(romClass) (_J9ROMCLASS_J9MODIFIER_IS_SET((romClass), J9AccRecord) && J9ROMCLASS_IS_FINAL(romClass) && !J9ROMCLASS_IS_ABSTRACT(romClass))
#define J9ROMCLASS_IS_SEALED(romClass) _J9ROMCLASS_J9MODIFIER_IS_SET((romClass), J9AccSealed)
#define J9ROMCLASS_IS_VALUEBASED(romClass) _J9ROMCLASS_J9MODIFIER_IS_SET((romClass), J9AccClassIsValueBased)
#define J9ROMCLASS_ALLOWS_NON_ATOMIC_CREATION(romClass) _J9ROMCLASS_J9MODIFIER_IS_SET((romClass), J9AccImplicitCreateNonAtomic)
#define J9ROMCLASS_HAS_DEFAULT(romClass) _J9ROMCLASS_J9MODIFIER_IS_SET((romClass), J9AccImplicitCreateHasDefaultValue)

/*
* Note that resolvefield ignores this flag if the cache line size cannot be determined.
Expand Down
6 changes: 5 additions & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,12 @@
#define J9_ROMCLASS_OPTINFO_VERIFY_EXCLUDE 0x4000
#define J9_ROMCLASS_OPTINFO_CLASS_ANNOTATION_INFO 0x8000
#define J9_ROMCLASS_OPTINFO_VARIABLE_TABLE_HAS_GENERIC 0x10000
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
#define J9_ROMCLASS_OPTINFO_PRELOAD_ATTRIBUTE 0x20000
#define J9_ROMCLASS_OPTINFO_UNUSED_40000 0x40000
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
#define J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE 0x40000
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
#define J9_ROMCLASS_OPTINFO_UNUSED_80000 0x80000
#define J9_ROMCLASS_OPTINFO_UNUSED_100000 0x100000
#define J9_ROMCLASS_OPTINFO_UNUSED 0x200000
Expand Down
13 changes: 13 additions & 0 deletions runtime/oti/util_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,19 @@ J9UTF8*
preloadClassNameAtIndex(U_32* permittedSubclassesCountPtr, U_32 index);
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */

#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
/**
* Retrieves flags stored in ImplicitCreation attribute. This method assumes
* there is an ImplicitCreation attribute in the ROM class (J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE
* is set in romClass->optionalFlags).
*
* @param J9ROMClass class
* @return ImplicitCreation flags
*/
U_16
getImplicitCreationFlags(J9ROMClass *romClass);
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

/**
* Retrieves number of record components in this record. Assumes that
* ROM class parameter references a record class.
Expand Down
13 changes: 13 additions & 0 deletions runtime/util/optinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,19 @@ preloadClassNameAtIndex(U_32* preloadInfoPtr, U_32 index)
return NNSRP_PTR_GET(preloadClassesPtr, J9UTF8*);
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
U_16
getImplicitCreationFlags(J9ROMClass *romClass)
{
U_32 *ptr = getSRPPtr(J9ROMCLASS_OPTIONALINFO(romClass), romClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE);
U_32* implicitCreationInfo = NULL;

Assert_VMUtil_true(ptr != NULL);
implicitCreationInfo = SRP_PTR_GET(ptr, U_32*);

return (U_16)*implicitCreationInfo;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

BOOLEAN
recordComponentHasSignature(J9ROMRecordComponentShape* recordComponent)
Expand Down
7 changes: 5 additions & 2 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,13 +2301,16 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C
}

#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (J9ROMCLASS_ALLOWS_NON_ATOMIC_CREATION(romClass)) {
if (J9_ARE_ALL_BITS_SET(romClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE)) {
U_16 implicitCreationFlags = getImplicitCreationFlags(romClass);
if (J9_ARE_ALL_BITS_SET(implicitCreationFlags, J9AccImplicitCreateNonAtomic)) {
classFlags |= J9ClassAllowsNonAtomicCreation;
}
if (J9ROMCLASS_HAS_DEFAULT(romClass)) {
if (J9_ARE_ALL_BITS_SET(implicitCreationFlags, J9AccImplicitCreateHasDefaultValue)) {
/* J9ClassIsValueType is being reused here intentionally */
classFlags |= J9ClassIsValueType;
}
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

if (J9ROMCLASS_IS_VALUE(romClass)) {
Expand Down

0 comments on commit 8e0d9da

Please sign in to comment.