Skip to content

Commit

Permalink
Merge pull request #18179 from a7ehuo/check-isFieldNullRestricted-PR
Browse files Browse the repository at this point in the history
Check NullRestricted attribute
  • Loading branch information
hzongaro committed Sep 26, 2023
2 parents f24c6d5 + 0405834 commit 20fb92b
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 143 deletions.
18 changes: 10 additions & 8 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Expand Up @@ -1845,6 +1845,16 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, methodInfos, ramMethods, implCount);
}
break;
case MessageType::ResolvedMethod_isFieldNullRestricted:
{
auto recv = client->getRecvData<TR_ResolvedJ9Method *, int32_t, bool, bool>();
auto mirror = std::get<0>(recv);
int32_t cpIndex = std::get<1>(recv);
bool isStatic = std::get<2>(recv);
bool isStore = std::get<3>(recv);
client->write(response, mirror->isFieldNullRestricted(comp, cpIndex, isStatic, isStore));
}
break;
case MessageType::ResolvedMethod_isFieldFlattened:
{
auto recv = client->getRecvData<TR_ResolvedJ9Method *, int32_t, bool>();
Expand Down Expand Up @@ -2060,14 +2070,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, TR::Compiler->cls.superClassesOf(clazz)[index]);
}
break;
case MessageType::ClassEnv_isClassRefPrimitiveValueType:
{
auto recv = client->getRecvData<TR_OpaqueClassBlock *, int32_t>();
auto clazz = std::get<0>(recv);
auto cpIndex = std::get<1>(recv);
client->write(response, TR::Compiler->cls.isClassRefPrimitiveValueType(comp, clazz, cpIndex));
}
break;
case MessageType::ClassEnv_flattenedArrayElementSize:
{
auto recv = client->getRecvData<TR_OpaqueClassBlock *>();
Expand Down
20 changes: 1 addition & 19 deletions runtime/compiler/env/J9ClassEnv.cpp
Expand Up @@ -524,7 +524,7 @@ static void addEntryForFieldImpl(TR_VMField *field, TR::TypeLayoutBuilder &tlb,
}
else
{
TR_ASSERT_FATAL(false, "Support for null-restricted types without Q descriptor is to be implemented!!!");
isFieldPrimitiveValueType = vm->internalVMFunctions->isFieldNullRestricted(field->shape);
}
}

Expand Down Expand Up @@ -1018,24 +1018,6 @@ J9::ClassEnv::containsZeroOrOneConcreteClass(TR::Compilation *comp, List<TR_Pers
return true;
}

bool
J9::ClassEnv::isClassRefPrimitiveValueType(TR::Compilation *comp, TR_OpaqueClassBlock *cpContextClass, int32_t cpIndex)
{
#if defined(J9VM_OPT_JITSERVER)
if (auto stream = comp->getStream())
{
stream->write(JITServer::MessageType::ClassEnv_isClassRefPrimitiveValueType, cpContextClass, cpIndex);
return std::get<0>(stream->read<bool>());
}
else // non-jitserver
#endif /* defined(J9VM_OPT_JITSERVER) */
{
J9Class * j9class = reinterpret_cast<J9Class *>(cpContextClass);
J9JavaVM *vm = comp->fej9()->getJ9JITConfig()->javaVM;
return vm->internalVMFunctions->isClassRefQtype(j9class, cpIndex);
}
}

char *
J9::ClassEnv::classNameToSignature(const char *name, int32_t &len, TR::Compilation *comp, TR_AllocationKind allocKind, TR_OpaqueClassBlock *clazz)
{
Expand Down
15 changes: 0 additions & 15 deletions runtime/compiler/env/J9ClassEnv.hpp
Expand Up @@ -183,21 +183,6 @@ class OMR_EXTENSIBLE ClassEnv : public OMR::ClassEnvConnector
bool isString(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
bool jitStaticsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2);
bool jitFieldsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2, int32_t isStatic);
/*
* \brief
* Tells whether a class reference entry in the constant pool represents a primitive value type class.
*
* \param cpContextClass
* The class whose constant pool contains the class reference entry being looked at. In another words,
* it's the class of the method referring to the class reference entry.
*
* \param cpIndex
* The constant pool index of the class reference entry.
*
* \note
* The class reference entry doesn't need to be resolved because the information is encoded in class name string
*/
bool isClassRefPrimitiveValueType(TR::Compilation *comp, TR_OpaqueClassBlock *cpContextClass, int32_t cpIndex);

/** \brief
* Populates a TypeLayout object.
Expand Down
49 changes: 45 additions & 4 deletions runtime/compiler/env/j9method.cpp
Expand Up @@ -9312,17 +9312,58 @@ TR_J9ByteCodeIlGenerator::packReferenceChainOffsets(TR::Node *node, std::vector<

bool
TR_ResolvedJ9Method::isFieldQType(int32_t cpIndex)
{
J9ROMFieldRef *ref = (J9ROMFieldRef *) (&romCPBase()[cpIndex]);
J9ROMNameAndSignature *nameAndSignature = J9ROMFIELDREF_NAMEANDSIGNATURE(ref);
J9UTF8 *signature = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature);

J9VMThread *vmThread = fej9()->vmThread();
return vmThread->javaVM->internalVMFunctions->isNameOrSignatureQtype(signature);
}

bool
TR_ResolvedJ9Method::isFieldNullRestricted(TR::Compilation *comp, int32_t cpIndex, bool isStatic, bool isStore)
{
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

if (TR::Compiler->om.isQDescriptorForValueTypesSupported())
{
if (isFieldQType(cpIndex)) // Temporary until javac supports NullRestricted attribute
return true;
}

J9VMThread *vmThread = fej9()->vmThread();
J9ROMFieldRef *ref = (J9ROMFieldRef *) (&romCPBase()[cpIndex]);
J9ROMNameAndSignature *nameAndSignature = J9ROMFIELDREF_NAMEANDSIGNATURE(ref);
J9UTF8 *signature = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature);
J9ROMFieldShape *fieldShape = NULL;

return vmThread->javaVM->internalVMFunctions->isNameOrSignatureQtype(signature);
bool failCompilation = false;
{
TR::VMAccessCriticalSection isFieldNullRestricted(fej9());
if (isStatic)
{
void *staticAddress = jitCTResolveStaticFieldRefWithMethod(vmThread, ramMethod(), cpIndex, isStore, &fieldShape);
if (!staticAddress)
{
failCompilation = true;
}
}
else
{
IDATA fieldOffset = jitCTResolveInstanceFieldRefWithMethod(vmThread, ramMethod(), cpIndex, isStore, &fieldShape);
if (fieldOffset == -1)
{
failCompilation = true;
}
}
}

if (failCompilation)
{
comp->failCompilation<TR::CompilationException>(isStatic ? "jitCTResolveStaticFieldRefWithMethod failed" : "jitCTResolveInstanceFieldRefWithMethod failed");
}

return vmThread->javaVM->internalVMFunctions->isFieldNullRestricted(fieldShape);
}

bool
Expand Down
17 changes: 14 additions & 3 deletions runtime/compiler/env/j9method.h
Expand Up @@ -470,6 +470,13 @@ class TR_ResolvedJ9Method : public TR_J9Method, public TR_ResolvedJ9MethodBase
TR_ResolvedMethod * aotMaskResolvedPossiblyPrivateVirtualMethod(TR::Compilation *comp, TR_ResolvedMethod *method);
TR_ResolvedMethod * aotMaskResolvedImproperInterfaceMethod(TR::Compilation *comp, TR_ResolvedMethod *method);

/**
* @brief Check if a field is a QType or not.
*
* @param[in] cpIndex : the constant pool index of the field
*/
virtual bool isFieldQType(int32_t cpIndex);

public:
virtual bool virtualMethodIsOverridden();
virtual void setVirtualMethodIsOverridden();
Expand Down Expand Up @@ -518,17 +525,21 @@ class TR_ResolvedJ9Method : public TR_J9Method, public TR_ResolvedJ9MethodBase
virtual void makeParameterList(TR::ResolvedMethodSymbol *methodSym);

/**
* @brief Check if a field is a QType or not.
* @brief Check if a field has the NullRestricted attribute.
*
* @param[in] comp : The current compilation object
* @param[in] cpIndex : the constant pool index of the field
* @param[in] isStatic: whether the field is static
* @param[in] isStore : whether the field is being used in the context of a store into the field
*/
virtual bool isFieldQType(int32_t cpIndex);
virtual bool isFieldNullRestricted(TR::Compilation *comp, int32_t cpIndex, bool isStatic, bool isStore);

/**
* @brief Check if a field is flattened or not by calling the VM API.
*
* @param[in] comp : The current compilation object
* @param[in] cpIndex : the constant pool index of the field
* @param[in] isStatic : whether the field is static
* @param[in] isStatic : whether the field is static
*/
virtual bool isFieldFlattened(TR::Compilation *comp, int32_t cpIndex, bool isStatic);

Expand Down
20 changes: 16 additions & 4 deletions runtime/compiler/env/j9methodServer.cpp
Expand Up @@ -1845,10 +1845,6 @@ TR_ResolvedJ9JITServerMethod::archetypeArgPlaceholderSlot()
bool
TR_ResolvedJ9JITServerMethod::isFieldQType(int32_t cpIndex)
{
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

auto comp = _fe->_compInfoPT->getCompilation();
int32_t sigLen;
char *sig = fieldOrStaticSignatureChars(cpIndex, sigLen);
Expand All @@ -1858,6 +1854,22 @@ TR_ResolvedJ9JITServerMethod::isFieldQType(int32_t cpIndex)
return vmThread->javaVM->internalVMFunctions->isNameOrSignatureQtype(utfWrapper);
}

bool
TR_ResolvedJ9JITServerMethod::isFieldNullRestricted(TR::Compilation *comp, int32_t cpIndex, bool isStatic, bool isStore)
{
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() ||
(-1 == cpIndex))
return false;

if (TR::Compiler->om.isQDescriptorForValueTypesSupported())
{
return isFieldQType(cpIndex);
}

_stream->write(JITServer::MessageType::ResolvedMethod_isFieldNullRestricted, _remoteMirror, cpIndex, isStatic, isStore);
return std::get<0>(_stream->read<bool>());
}

bool
TR_ResolvedJ9JITServerMethod::isFieldFlattened(TR::Compilation *comp, int32_t cpIndex, bool isStatic)
{
Expand Down
4 changes: 3 additions & 1 deletion runtime/compiler/env/j9methodServer.hpp
Expand Up @@ -216,7 +216,7 @@ class TR_ResolvedJ9JITServerMethod : public TR_ResolvedJ9Method
virtual void getFaninInfo(uint32_t *count, uint32_t *weight, uint32_t *otherBucketWeight = NULL) override;
virtual bool getCallerWeight(TR_ResolvedJ9Method *caller, uint32_t *weight, uint32_t pcIndex=~0) override;
virtual uint16_t archetypeArgPlaceholderSlot() override;
virtual bool isFieldQType(int32_t cpIndex) override;
virtual bool isFieldNullRestricted(TR::Compilation *comp, int32_t cpIndex, bool isStatic, bool isStore) override;
virtual bool isFieldFlattened(TR::Compilation *comp, int32_t cpIndex, bool isStatic) override;
bool isForceInline() const { return _isForceInline; }
bool isDontInline() const { return _isDontInline; }
Expand All @@ -242,6 +242,8 @@ class TR_ResolvedJ9JITServerMethod : public TR_ResolvedJ9Method
virtual bool validateMethodFieldAttributes(const TR_J9MethodFieldAttributes &attributes, bool isStatic, int32_t cpIndex, bool isStore, bool needAOTValidation);
virtual bool canCacheFieldAttributes(int32_t cpIndex, const TR_J9MethodFieldAttributes &attributes, bool isStatic);

virtual bool isFieldQType(int32_t cpIndex) override;

private:

J9ROMClass *_romClass; // cached copy of ROM class from client
Expand Down

0 comments on commit 20fb92b

Please sign in to comment.