Skip to content

Commit

Permalink
Add TR_RelocationRecord subclass and corresponding binary template
Browse files Browse the repository at this point in the history
This commit adds a new `TR_RelocationRecord` subclass
for `IsClassVisibleRecord` called
`TR_RelocationRecordValidateIsClassVisible`,
and an associated binary template called
`TR_RelocationRecordValidateIsClassVisibleBinaryTemplate`

Issue: eclipse-openj9#4765
Signed-off-by: Dylan Tuttle <[email protected]>
  • Loading branch information
dylanjtuttle committed Oct 4, 2022
1 parent eca2c32 commit 355c320
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 36 deletions.
71 changes: 71 additions & 0 deletions runtime/compiler/runtime/RelocationRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ struct TR_RelocationRecordValidateJ2IThunkFromMethodBinaryTemplate : public TR_R
uint16_t _methodID;
};

struct TR_RelocationRecordValidateIsClassVisibleBinaryTemplate : public TR_RelocationRecordBinaryTemplate
{
uint16_t _sourceClassID;
uint16_t _destClassID;
uint8_t _isVisible;
};

// END OF BINARY TEMPLATES

uint8_t
Expand Down Expand Up @@ -854,6 +861,9 @@ TR_RelocationRecord::create(TR_RelocationRecord *storage, TR_RelocationRuntime *
case TR_StaticDefaultValueInstance:
reloRecord = new (storage) TR_RelocationRecordStaticDefaultValueInstance(reloRuntime, record);
break;
case TR_ValidateIsClassVisible:
reloRecord = new (storage) TR_RelocationRecordValidateIsClassVisible(reloRuntime, record);
break;
default:
// TODO: error condition
printf("Unexpected relo record: %d\n", reloType);fflush(stdout);
Expand Down Expand Up @@ -6369,6 +6379,66 @@ TR_RelocationRecordValidateJ2IThunkFromMethod::methodID(TR_RelocationTarget *rel
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateJ2IThunkFromMethodBinaryTemplate *)_record)->_methodID);
}

TR_RelocationErrorCode
TR_RelocationRecordValidateIsClassVisible::applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
uint16_t sourceClassID = this->sourceClassID(reloTarget);
uint16_t destClassID = this->destClassID(reloTarget);
bool isVisible = this->isVisible(reloTarget);

if (reloRuntime->comp()->getSymbolValidationManager()->validateIsClassVisibleRecord(sourceClassID, destClassID, isVisible))
return TR_RelocationErrorCode::relocationOK;
else
return TR_RelocationErrorCode::isClassVisibleValidationFailure;
}

void
TR_RelocationRecordValidateIsClassVisible::print(TR_RelocationRuntime *reloRuntime)
{
TR_RelocationTarget *reloTarget = reloRuntime->reloTarget();
TR_RelocationRuntimeLogger *reloLogger = reloRuntime->reloLogger();
TR_RelocationRecord::print(reloRuntime);
reloLogger->printf("\tsourceClassID %d\n", sourceClassID(reloTarget));
reloLogger->printf("\tdestClassID %d\n", destClassID(reloTarget));
reloLogger->printf("\tisVisible %s\n", isVisible(reloTarget) ? "true" : "false");
}

void
TR_RelocationRecordValidateIsClassVisible::setSourceClassID(TR_RelocationTarget *reloTarget, uint16_t sourceClassID)
{
reloTarget->storeUnsigned16b(sourceClassID, (uint8_t *) &((TR_RelocationRecordValidateIsClassVisibleBinaryTemplate *)_record)->_sourceClassID);
}

uint16_t
TR_RelocationRecordValidateIsClassVisible::sourceClassID(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateIsClassVisibleBinaryTemplate *)_record)->_sourceClassID);
}

void
TR_RelocationRecordValidateIsClassVisible::setDestClassID(TR_RelocationTarget *reloTarget, uint16_t destClassID)
{
reloTarget->storeUnsigned16b(destClassID, (uint8_t *) &((TR_RelocationRecordValidateIsClassVisibleBinaryTemplate *)_record)->_destClassID);
}

uint16_t
TR_RelocationRecordValidateIsClassVisible::destClassID(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateIsClassVisibleBinaryTemplate *)_record)->_destClassID);
}

void
TR_RelocationRecordValidateIsClassVisible::setIsVisible(TR_RelocationTarget *reloTarget, bool isVisible)
{
reloTarget->storeUnsigned8b((uint8_t)isVisible, (uint8_t *) &((TR_RelocationRecordValidateIsClassVisibleBinaryTemplate *)_record)->_isVisible);
}

bool
TR_RelocationRecordValidateIsClassVisible::isVisible(TR_RelocationTarget *reloTarget)
{
return (bool)reloTarget->loadUnsigned8b((uint8_t *) &((TR_RelocationRecordValidateIsClassVisibleBinaryTemplate *)_record)->_isVisible);
}


char *
TR_RelocationRecordStaticDefaultValueInstance::name()
Expand Down Expand Up @@ -6528,5 +6598,6 @@ uint32_t TR_RelocationRecord::_relocationRecordHeaderSizeTable[TR_NumExternalRel
0, // TR_VMINLMethod = 109
sizeof(TR_RelocationRecordValidateJ2IThunkFromMethodBinaryTemplate), // TR_ValidateJ2IThunkFromMethod = 110
sizeof(TR_RelocationRecordConstantPoolWithIndexBinaryTemplate), // TR_StaticDefaultValueInstance = 111
sizeof(TR_RelocationRecordValidateIsClassVisibleBinaryTemplate), // TR_ValidateIsClassVisible = 112
};
// The _relocationRecordHeaderSizeTable table should be the last thing in this file
22 changes: 22 additions & 0 deletions runtime/compiler/runtime/RelocationRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1929,5 +1929,27 @@ class TR_RelocationRecordStaticDefaultValueInstance : public TR_RelocationRecord
virtual TR_RelocationErrorCode applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocationHigh, uint8_t *reloLocationLow);
};

class TR_RelocationRecordValidateIsClassVisible : public TR_RelocationRecord
{
public:
TR_RelocationRecordValidateIsClassVisible() {}
TR_RelocationRecordValidateIsClassVisible(TR_RelocationRuntime *reloRuntime, TR_RelocationRecordBinaryTemplate *record) : TR_RelocationRecord(reloRuntime, record) {}
virtual bool isValidationRecord() { return true; }
virtual char *name() { return "TR_RelocationRecordValidateIsClassVisible"; }
virtual void preparePrivateData(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget) {}
virtual TR_RelocationErrorCode applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);

virtual void print(TR_RelocationRuntime *reloRuntime);

void setSourceClassID(TR_RelocationTarget *reloTarget, uint16_t sourceClassID);
uint16_t sourceClassID(TR_RelocationTarget *reloTarget);

void setDestClassID(TR_RelocationTarget *reloTarget, uint16_t destClassID);
uint16_t destClassID(TR_RelocationTarget *reloTarget);

void setIsVisible(TR_RelocationTarget *reloTarget, bool isVisible);
bool isVisible(TR_RelocationTarget *reloTarget);
};

#endif // RELOCATION_RECORD_INCL

35 changes: 18 additions & 17 deletions runtime/compiler/runtime/RelocationRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,24 @@ char *TR_RelocationRuntime::_reloErrorCodeNames[] =
"methodFromSingleInterfaceImplValidationFailure", // 41
"methodFromSingleAbstractImplValidationFailure", // 42
"j2iThunkFromMethodValidationFailure", // 43
"svmValidationFailure", // 44
"wkcValidationFailure", // 45

"classAddressRelocationFailure", // 46
"inlinedMethodRelocationFailure", // 47
"symbolFromManagerRelocationFailure", // 48
"thunkRelocationFailure", // 49
"trampolineRelocationFailure", // 50
"picTrampolineRelocationFailure", // 51
"cacheFullRelocationFailure", // 52
"blockFrequencyRelocationFailure", // 53
"recompQueuedFlagRelocationFailure", // 54
"debugCounterRelocationFailure", // 55
"directJNICallRelocationFailure", // 56
"ramMethodConstRelocationFailure", // 57

"maxRelocationError" // 58
"isClassVisibleValidationFailure", // 44
"svmValidationFailure", // 45
"wkcValidationFailure", // 46

"classAddressRelocationFailure", // 47
"inlinedMethodRelocationFailure", // 48
"symbolFromManagerRelocationFailure", // 49
"thunkRelocationFailure", // 50
"trampolineRelocationFailure", // 51
"picTrampolineRelocationFailure", // 52
"cacheFullRelocationFailure", // 53
"blockFrequencyRelocationFailure", // 54
"recompQueuedFlagRelocationFailure", // 55
"debugCounterRelocationFailure", // 56
"directJNICallRelocationFailure", // 57
"ramMethodConstRelocationFailure", // 58

"maxRelocationError" // 59
};

TR_RelocationRuntime::TR_RelocationRuntime(J9JITConfig *jitCfg)
Expand Down
39 changes: 20 additions & 19 deletions runtime/compiler/runtime/RelocationRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,26 @@ struct TR_RelocationError
methodFromSingleInterfaceImplValidationFailure = (41 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,
methodFromSingleAbstractImplValidationFailure = (42 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,
j2iThunkFromMethodValidationFailure = (43 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,
svmValidationFailure = (44 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,
wkcValidationFailure = (45 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,

classAddressRelocationFailure = (46 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
inlinedMethodRelocationFailure = (47 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
symbolFromManagerRelocationFailure = (48 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
thunkRelocationFailure = (49 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
trampolineRelocationFailure = (50 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
picTrampolineRelocationFailure = (51 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
cacheFullRelocationFailure = (52 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
blockFrequencyRelocationFailure = (53 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
recompQueuedFlagRelocationFailure = (54 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
debugCounterRelocationFailure = (55 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
directJNICallRelocationFailure = (56 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
ramMethodConstRelocationFailure = (57 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,

staticDefaultValueInstanceRelocationFailure = (58 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,

maxRelocationError = (59 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::NO_RELO_ERROR
isClassVisibleValidationFailure = (44 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,
svmValidationFailure = (45 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,
wkcValidationFailure = (46 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::VALIDATION,

classAddressRelocationFailure = (47 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
inlinedMethodRelocationFailure = (48 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
symbolFromManagerRelocationFailure = (49 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
thunkRelocationFailure = (50 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
trampolineRelocationFailure = (51 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
picTrampolineRelocationFailure = (52 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
cacheFullRelocationFailure = (53 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
blockFrequencyRelocationFailure = (54 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
recompQueuedFlagRelocationFailure = (55 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
debugCounterRelocationFailure = (56 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
directJNICallRelocationFailure = (57 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,
ramMethodConstRelocationFailure = (58 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,

staticDefaultValueInstanceRelocationFailure = (59 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::RELOCATION,

maxRelocationError = (60 << RELO_ERRORCODE_SHIFT) | TR_RelocationErrorCodeType::NO_RELO_ERROR
};

static uint32_t decode(TR_RelocationErrorCode errorCode) { return static_cast<uint32_t>(errorCode >> RELO_ERRORCODE_SHIFT); }
Expand Down

0 comments on commit 355c320

Please sign in to comment.