Skip to content

Commit

Permalink
Correct the handling of hidden class field comparisions
Browse files Browse the repository at this point in the history
When using jitFieldsAreSame to compare the fields of two distinct
hidden classes, the result can be a false positive if the field
names and data types match. This can result in disastrous symref
sharing for hidden class stores/loads.

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.

Signed-off-by: Nazim Bhuiyan <[email protected]>
  • Loading branch information
nbhuiyan committed Nov 7, 2023
1 parent 3ba8567 commit 9d68a73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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;

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

0 comments on commit 9d68a73

Please sign in to comment.