Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the handling of hidden class field comparisions #18374

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6988,6 +6988,17 @@ TR_J9VMBase::jitFieldsAreSame(TR_ResolvedMethod * method1, I_32 cpIndex1, TR_Res
TR::VMAccessCriticalSection jitFieldsAreSame(this);
bool result = false;

// Hidden classes generated within the same host class do not have distinct class names,
// but share the same field names with different field data types and offsets. Therefore,
// name-based check for whether fields are same can result in false positives when it comes
// to hidden classes unless the fields are from the same j9class objects.
if (method1->classOfMethod()
&& method2->classOfMethod()
&& (isHiddenClass(method1->classOfMethod())
|| isHiddenClass(method2->classOfMethod()))
&& method1->classOfMethod() != method2->classOfMethod())
return false;
hzongaro marked this conversation as resolved.
Show resolved Hide resolved

bool sigSame = true;
if (method1->fieldsAreSame(cpIndex1, method2, cpIndex2, sigSame))
result = true;
Expand Down
9 changes: 9 additions & 0 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,15 @@ class TR_J9VMBase : public TR_FrontEnd

virtual bool isAnonymousClass(TR_OpaqueClassBlock *j9clazz) { return (J9_ARE_ALL_BITS_SET(((J9Class*)j9clazz)->romClass->extraModifiers, J9AccClassAnonClass)); }
virtual bool isAnonymousClass(J9ROMClass *romClass) { return (J9_ARE_ALL_BITS_SET(romClass->extraModifiers, J9AccClassAnonClass)); }

/**
* \brief Check whether or not the class object is a hidden class
*
* \param j9clazz the class location
* \return true if class is hidden class, false otherwise
*/
virtual bool isHiddenClass(TR_OpaqueClassBlock *j9clazz) { return (J9_ARE_ALL_BITS_SET(((J9Class*)j9clazz)->romClass->extraModifiers, J9AccClassHidden)); }

virtual int64_t getCpuTimeSpentInCompThread(TR::Compilation * comp); // resolution is 0.5 sec or worse. Returns -1 if unavailable

virtual void * getClassLoader(TR_OpaqueClassBlock * classPointer);
Expand Down
26 changes: 25 additions & 1 deletion runtime/compiler/env/VMJ9Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,21 @@ TR_J9ServerVM::jitFieldsAreSame(TR_ResolvedMethod * method1, I_32 cpIndex1, TR_R
{
bool result = false;
bool sigSame = true;
if (method1->fieldsAreSame(cpIndex1, method2, cpIndex2, sigSame))
TR_OpaqueClassBlock * classOfMethod1 = static_cast<TR_ResolvedJ9JITServerMethod *>(method1)->classOfMethod();
TR_OpaqueClassBlock * classOfMethod2 = static_cast<TR_ResolvedJ9JITServerMethod *>(method2)->classOfMethod();
// Hidden classes generated within the same host class do not have distinct class names,
// but share the same field names with different field data types and offsets. Therefore,
// name-based check for whether fields are same can result in false positives when it comes
// to hidden classes unless the fields are from the same j9class objects.
if (classOfMethod1
&& classOfMethod2
&& (isHiddenClass(classOfMethod1)
|| isHiddenClass(classOfMethod2))
&& classOfMethod1 != classOfMethod2)
{
result = false;
}
else if (method1->fieldsAreSame(cpIndex1, method2, cpIndex2, sigSame))
{
result = true;
}
Expand Down Expand Up @@ -1943,6 +1957,16 @@ TR_J9ServerVM::isAnonymousClass(TR_OpaqueClassBlock *j9clazz)
return (J9_ARE_ALL_BITS_SET(extraModifiers, J9AccClassAnonClass));
}

bool
TR_J9ServerVM::isHiddenClass(TR_OpaqueClassBlock *j9clazz)
{
uintptr_t extraModifiers = 0;
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
JITServerHelpers::getAndCacheRAMClassInfo((J9Class *)j9clazz, _compInfoPT->getClientData(), stream, JITServerHelpers::CLASSINFO_ROMCLASS_EXTRAMODIFIERS, (void *)&extraModifiers);

return (J9_ARE_ALL_BITS_SET(extraModifiers, J9AccClassHidden));
}

TR_IProfiler *
TR_J9ServerVM::getIProfiler()
{
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/VMJ9Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class TR_J9ServerVM: public TR_J9VM
virtual bool transformJlrMethodInvoke(J9Method *callerMethod, J9Class *callerClass) override;
using TR_J9VM :: isAnonymousClass;
virtual bool isAnonymousClass(TR_OpaqueClassBlock *j9clazz) override;
virtual bool isHiddenClass(TR_OpaqueClassBlock *j9clazz) override;
virtual TR_IProfiler *getIProfiler() override;
virtual TR_StaticFinalData dereferenceStaticFinalAddress(void *staticAddress, TR::DataType addressType) override;
virtual void reserveTrampolineIfNecessary( TR::Compilation *, TR::SymbolReference *symRef, bool inBinaryEncoding) override;
Expand Down