Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#17447 from a7ehuo/separate-nullRest…
Browse files Browse the repository at this point in the history
…ricted-remove-q-2

Check flattenable value types and if Q signature is supported
  • Loading branch information
hzongaro committed Jun 7, 2023
2 parents 3260123 + 156b344 commit 50019a8
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 90 deletions.
23 changes: 20 additions & 3 deletions runtime/compiler/env/J9ClassEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,21 @@ static void addEntryForFieldImpl(TR_VMField *field, TR::TypeLayoutBuilder &tlb,
uint32_t mergedLength = 0;
J9UTF8 *signature = J9ROMFIELDSHAPE_SIGNATURE(field->shape);

if (TR::Compiler->om.areValueTypesEnabled() &&
vm->internalVMFunctions->isNameOrSignatureQtype(signature) &&
bool isFieldPrimitiveValueType = false;

if (TR::Compiler->om.areFlattenableValueTypesEnabled())
{
if (TR::Compiler->om.isQDescriptorForValueTypesSupported())
{
isFieldPrimitiveValueType = vm->internalVMFunctions->isNameOrSignatureQtype(signature);
}
else
{
TR_ASSERT_FATAL(false, "Support for null-restricted types without Q descriptor is to be implemented!!!");
}
}

if (isFieldPrimitiveValueType &&
vm->internalVMFunctions->isFlattenableFieldFlattened(definingClass, field->shape))
{
char *prefixForChild = buildTransitiveFieldNames(prefix, prefixLength, field->shape, comp->trMemory()->currentStackRegion(), mergedLength);
Expand Down Expand Up @@ -1043,7 +1056,11 @@ J9::ClassEnv::classNameToSignature(const char *name, int32_t &len, TR::Compilati
{
len += 2;
sig = (char *)comp->trMemory()->allocateMemory(len+1, allocKind);
if (clazz && TR::Compiler->om.areValueTypesEnabled() && self()->isPrimitiveValueTypeClass(clazz))
if (clazz &&
TR::Compiler->om.areFlattenableValueTypesEnabled() &&
TR::Compiler->om.isQDescriptorForValueTypesSupported() &&
self()->isPrimitiveValueTypeClass(clazz)
)
sig[0] = 'Q';
else
sig[0] = 'L';
Expand Down
51 changes: 49 additions & 2 deletions runtime/compiler/env/J9ObjectModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,45 @@ J9::ObjectModel::areValueTypesEnabled()
return javaVM->internalVMFunctions->areValueTypesEnabled(javaVM);
}

bool
J9::ObjectModel::areFlattenableValueTypesEnabled()
{
#if defined(J9VM_OPT_JITSERVER)
if (auto stream = TR::CompilationInfo::getStream())
{
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
return true;
#else /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
return false;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
}
#endif /* defined(J9VM_OPT_JITSERVER) */

J9JavaVM * javaVM = TR::Compiler->javaVM;
return javaVM->internalVMFunctions->areFlattenableValueTypesEnabled(javaVM);
}

bool
J9::ObjectModel::isQDescriptorForValueTypesSupported()
{
// TODO: Implementation is required to determine under which case 'Q' descriptor is removed
#if defined(J9VM_OPT_JITSERVER)
if (auto stream = TR::CompilationInfo::getStream())
{
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
return true;
#else /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
return false;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
}
#endif /* defined(J9VM_OPT_JITSERVER) */

J9JavaVM * javaVM = TR::Compiler->javaVM;
if (javaVM->internalVMFunctions->areFlattenableValueTypesEnabled(javaVM))
return true;

return false;
}

bool
J9::ObjectModel::areValueBasedMonitorChecksEnabled()
Expand All @@ -144,13 +183,21 @@ J9::ObjectModel::isValueTypeArrayFlatteningEnabled()
#if defined(J9VM_OPT_JITSERVER)
if (auto stream = TR::CompilationInfo::getStream())
{
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
auto *vmInfo = TR::compInfoPT->getClientData()->getOrCacheVMInfo(stream);
return J9_ARE_ANY_BITS_SET(vmInfo->_extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_VT_ARRAY_FLATTENING);
return J9_ARE_ANY_BITS_SET(vmInfo->_extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_VT_ARRAY_FLATTENING);
#else /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
return false;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
}
#endif /* defined(J9VM_OPT_JITSERVER) */

J9JavaVM *javaVM = TR::Compiler->javaVM;
return J9_ARE_ALL_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_VT_ARRAY_FLATTENING);

if (javaVM->internalVMFunctions->areFlattenableValueTypesEnabled(javaVM))
return J9_ARE_ALL_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_VT_ARRAY_FLATTENING);
else
return false;
}

int32_t
Expand Down
12 changes: 12 additions & 0 deletions runtime/compiler/env/J9ObjectModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,19 @@ class ObjectModel : public OMR::ObjectModelConnector

bool mayRequireSpineChecks();

/**
* @brief Whether or not value object is enabled
*/
bool areValueTypesEnabled();
/**
* @brief Whether or not flattenable value object (aka null restricted) type is enabled
*/
bool areFlattenableValueTypesEnabled();
/**
* @brief Whether or not `Q` signature is supported
*/
bool isQDescriptorForValueTypesSupported();

/**
* @brief Whether the check is enabled on monitor object being value based class type
*/
Expand Down
8 changes: 6 additions & 2 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,9 @@ TR_J9VMBase::getClassSignature_DEPRECATED(TR_OpaqueClassBlock * clazz, int32_t &
sig[i] = '[';
if (* name != '[')
{
if (TR::Compiler->om.areValueTypesEnabled() && TR::Compiler->cls.isPrimitiveValueTypeClass(myClass))
if (TR::Compiler->om.areFlattenableValueTypesEnabled() &&
TR::Compiler->om.isQDescriptorForValueTypesSupported() &&
TR::Compiler->cls.isPrimitiveValueTypeClass(myClass))
sig[i++] = 'Q';
else
sig[i++] = 'L';
Expand Down Expand Up @@ -2565,7 +2567,9 @@ TR_J9VMBase::getClassSignature(TR_OpaqueClassBlock * clazz, TR_Memory * trMemory
sig[i] = '[';
if (* name != '[')
{
if (TR::Compiler->om.areValueTypesEnabled() && TR::Compiler->cls.isPrimitiveValueTypeClass(myClass))
if (TR::Compiler->om.areFlattenableValueTypesEnabled() &&
TR::Compiler->om.isQDescriptorForValueTypesSupported() &&
TR::Compiler->cls.isPrimitiveValueTypeClass(myClass))
sig[i++] = 'Q';
else
sig[i++] = 'L';
Expand Down
6 changes: 3 additions & 3 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9264,7 +9264,7 @@ TR_J9ByteCodeIlGenerator::packReferenceChainOffsets(TR::Node *node, std::vector<
bool
TR_ResolvedJ9Method::isFieldQType(int32_t cpIndex)
{
if (!TR::Compiler->om.areValueTypesEnabled() ||
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

Expand All @@ -9279,15 +9279,15 @@ TR_ResolvedJ9Method::isFieldQType(int32_t cpIndex)
bool
TR_ResolvedJ9Method::isFieldFlattened(TR::Compilation *comp, int32_t cpIndex, bool isStatic)
{
if (!TR::Compiler->om.areValueTypesEnabled() ||
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

J9VMThread *vmThread = fej9()->vmThread();
J9ROMFieldShape *fieldShape = NULL;
TR_OpaqueClassBlock *containingClass = definingClassAndFieldShapeFromCPFieldRef(comp, cp(), cpIndex, isStatic, &fieldShape);

// No lock is required here. Entires in J9Class::flattenedClassCache are only written during classload.
// No lock is required here. Entries in J9Class::flattenedClassCache are only written during classload.
// They are effectively read only when being exposed to the JIT.
return vmThread->javaVM->internalVMFunctions->isFlattenableFieldFlattened(reinterpret_cast<J9Class *>(containingClass), fieldShape);
}
4 changes: 2 additions & 2 deletions runtime/compiler/env/j9methodServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ TR_ResolvedJ9JITServerMethod::archetypeArgPlaceholderSlot()
bool
TR_ResolvedJ9JITServerMethod::isFieldQType(int32_t cpIndex)
{
if (!TR::Compiler->om.areValueTypesEnabled() ||
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

Expand All @@ -1859,7 +1859,7 @@ TR_ResolvedJ9JITServerMethod::isFieldQType(int32_t cpIndex)
bool
TR_ResolvedJ9JITServerMethod::isFieldFlattened(TR::Compilation *comp, int32_t cpIndex, bool isStatic)
{
if (!TR::Compiler->om.areValueTypesEnabled() ||
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

Expand Down
6 changes: 1 addition & 5 deletions runtime/compiler/ilgen/IlGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,7 @@ TR_J9ByteCodeIlGenerator::genILFromByteCodes()

if (currNode->getOpCodeValue() == TR::checkcast
&& currNode->getSecondChild()->getOpCodeValue() == TR::loadaddr
&& currNode->getSecondChild()->getSymbolReference()->isUnresolved()
&& // check whether the checkcast class is primitive valuetype. Expansion is only needed for checkcast to reference type.
(!TR::Compiler->om.areValueTypesEnabled()
|| !TR::Compiler->cls.isClassRefPrimitiveValueType(comp(), method()->classOfMethod(),
currNode->getSecondChild()->getSymbolReference()->getCPIndex())))
&& currNode->getSecondChild()->getSymbolReference()->isUnresolved())
{
unresolvedCheckcastTopsNeedingNullGuard.add(currTree);
}
Expand Down
Loading

0 comments on commit 50019a8

Please sign in to comment.