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

Reimplement getMethodFromName around other queries #4175

Merged
merged 2 commits into from
Jan 4, 2019
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
23 changes: 1 addition & 22 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1459,27 +1459,6 @@ J9::AheadOfTimeCompile::dumpRelocationData()
}
break;

case TR_ValidateMethodByName:
{
cursor++;
if (is64BitTarget)
cursor += 4; // padding
cursor -= sizeof(TR_RelocationRecordBinaryTemplate);
TR_RelocationRecordValidateMethodByNameBinaryTemplate *binaryTemplate =
reinterpret_cast<TR_RelocationRecordValidateMethodByNameBinaryTemplate *>(cursor);
if (isVerbose)
{
traceMsg(self()->comp(), "\n Validate Method By Name: methodID=%d, beholderID=%d, romClassOffsetInSCC=%p romMethodOffsetInSCC=%p ",
(uint32_t)binaryTemplate->_methodID,
(uint32_t)binaryTemplate->_beholderID,
binaryTemplate->_romClassOffsetInSCC,
binaryTemplate->_romMethodOffsetInSCC);
}
cursor += sizeof(TR_RelocationRecordValidateMethodByNameBinaryTemplate);
self()->traceRelocationOffsets(cursor, offsetSize, endOfCurrentRecord, orderedPair);
}
break;

case TR_ValidateMethodFromClass:
{
cursor++;
Expand Down
78 changes: 12 additions & 66 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -6770,40 +6770,21 @@ TR_J9VM::getClassDepthAndFlagsValue(TR_OpaqueClassBlock * classPointer)
#define LOOKUP_OPTION_NO_THROW 8192

TR_OpaqueMethodBlock *
TR_J9VM::getMethodFromName(char *className, char *methodName, char *signature, J9ConstantPool *constantPool)
TR_J9VM::getMethodFromName(char *className, char *methodName, char *signature, TR_OpaqueMethodBlock *callingMethod)
{
TR::VMAccessCriticalSection getMethodFromName(this);
J9Class *methodClass = 0;
if (constantPool)
{
methodClass = jitGetClassFromUTF8(vmThread(), constantPool, className, strlen(className));
}
if (!methodClass) // try the system class loader
{
methodClass = jitGetClassInClassloaderFromUTF8(vmThread(),
(J9ClassLoader *) vmThread()->javaVM->systemClassLoader,
className, strlen(className));
}
TR_OpaqueMethodBlock * result = NULL;
/*
* Call the TR_J9VM version of getMethodFromClass since at this point,
* the methodClass may have never been seen before; if we call the
* TR_J9SharedCacheVM version, the validation manager could assert.
*/
if (methodClass)
result = (TR_OpaqueMethodBlock *)TR_J9VM::getMethodFromClass((TR_OpaqueClassBlock *)methodClass, methodName, signature);
return result;
return getMethodFromName(className, methodName, signature); // ignore callingMethod
}

TR_OpaqueMethodBlock *
TR_J9VM::getMethodFromName(char *className, char *methodName, char *signature, TR_OpaqueMethodBlock *callingMethod)
TR_J9VM::getMethodFromName(char *className, char *methodName, char *signature)
{
J9ConstantPool *cp = NULL;

if (callingMethod)
cp = (J9ConstantPool *) (J9_CP_FROM_METHOD((J9Method*)callingMethod));
TR::VMAccessCriticalSection getMethodFromName(this);
TR_OpaqueClassBlock *methodClass = getSystemClassFromClassName(className, strlen(className), true);
TR_OpaqueMethodBlock * result = NULL;
if (methodClass)
result = (TR_OpaqueMethodBlock *)getMethodFromClass(methodClass, methodName, signature);

return getMethodFromName(className, methodName, signature, cp);
return result;
}

/** \brief
Expand Down Expand Up @@ -8712,9 +8693,7 @@ TR_J9SharedCacheVM::getResolvedMethodForNameAndSignature(TR_Memory * trMemory, T
TR_OpaqueMethodBlock *method = (TR_OpaqueMethodBlock *)((TR_ResolvedJ9Method *)resolvedMethod)->ramMethod();
/*
* TR_J9VM::getResolvedMethodForNameAndSignature will call getMatchingMethodFromNameAndSignature
* which adds a MethodFromClassRecord. Not sure if adding a MethodByNameRecord here will do the
* right validation, since the way TR_J9VM::getResolvedMethodForNameAndSignature gets the class
* by name and signature is different than TR_J9VM::getMethodFromName...
* which adds a MethodFromClassRecord.
*/
validated = comp->getSymbolValidationManager()->addClassFromMethodRecord(getClassFromMethodBlock(method), method);
}
Expand All @@ -8729,37 +8708,6 @@ TR_J9SharedCacheVM::getResolvedMethodForNameAndSignature(TR_Memory * trMemory, T
return NULL;
}


TR_OpaqueMethodBlock *
TR_J9SharedCacheVM::getMethodFromName(char *className, char *methodName, char *signature, TR_OpaqueMethodBlock *callingMethod)
{
TR_OpaqueMethodBlock *omb = this->TR_J9VM::getMethodFromName(className, methodName, signature, callingMethod);
if (omb)
{
TR::Compilation* comp = _compInfo->getCompInfoForCompOnAppThread() ? _compInfo->getCompInfoForCompOnAppThread()->getCompilation() : _compInfoPT->getCompilation();
TR_ASSERT(comp, "Should be called only within a compilation");

if (comp->getOption(TR_UseSymbolValidationManager))
{
TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();
SVM_ASSERT_ALREADY_VALIDATED(svm, callingMethod);
bool validated = svm->addMethodByNameRecord(omb, getClassFromMethodBlock(callingMethod)) &&
svm->addClassFromMethodRecord(getClassFromMethodBlock(omb), omb);

if (!validated)
omb = NULL;
}
else
{
J9Class* methodClass = (J9Class*)getClassFromMethodBlock(omb);
if (!((TR_ResolvedRelocatableJ9Method*) comp->getCurrentMethod())->validateArbitraryClass(comp, methodClass))
omb = NULL;
}
}

return omb;
}

bool
TR_J9SharedCacheVM::isClassLibraryMethod(TR_OpaqueMethodBlock *method, bool vettedForAOT)
{
Expand All @@ -8783,9 +8731,7 @@ TR_J9SharedCacheVM::getMethodFromClass(TR_OpaqueClassBlock * methodClass, char *

if (comp->getOption(TR_UseSymbolValidationManager))
{
bool validated = callingClass &&
comp->getSymbolValidationManager()->addMethodFromClassAndSignatureRecord(omb, methodClass, callingClass);

bool validated = comp->getSymbolValidationManager()->addMethodFromClassAndSignatureRecord(omb, methodClass, callingClass);
if (!validated)
omb = NULL;
}
Expand Down
7 changes: 3 additions & 4 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1042,8 +1042,8 @@ class TR_J9VM : public TR_J9VMBase
virtual void initializeHasFixedFrameC_CallingConvention();

virtual bool isPublicClass(TR_OpaqueClassBlock *clazz);
TR_OpaqueMethodBlock * getMethodFromName(char * className, char *methodName, char *signature, J9ConstantPool *constantPool);
virtual TR_OpaqueMethodBlock *getMethodFromName(char * className, char *methodName, char *signature, TR_OpaqueMethodBlock *callingMethod=0);
virtual TR_OpaqueMethodBlock *getMethodFromName(char * className, char *methodName, char *signature, TR_OpaqueMethodBlock *callingMethod);
virtual TR_OpaqueMethodBlock *getMethodFromName(char * className, char *methodName, char *signature);
virtual uintptrj_t getClassDepthAndFlagsValue(TR_OpaqueClassBlock * classPointer);

virtual TR_OpaqueClassBlock * getComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass);
Expand Down Expand Up @@ -1165,7 +1165,6 @@ class TR_J9SharedCacheVM : public TR_J9VM
virtual bool isPublicClass(TR_OpaqueClassBlock *clazz);
virtual bool hasFinalizer(TR_OpaqueClassBlock * classPointer);
virtual uintptrj_t getClassDepthAndFlagsValue(TR_OpaqueClassBlock * classPointer);
virtual TR_OpaqueMethodBlock * getMethodFromName(char * className, char *methodName, char *signature, TR_OpaqueMethodBlock *callingMethod=0);
virtual TR_OpaqueMethodBlock * getMethodFromClass(TR_OpaqueClassBlock *, char *, char *, TR_OpaqueClassBlock * = NULL);
virtual bool isPrimitiveClass(TR_OpaqueClassBlock *clazz);
virtual TR_OpaqueClassBlock * getComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass);
Expand Down
8 changes: 4 additions & 4 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -6724,7 +6724,7 @@ TR_ResolvedJ9Method::getResolvedDynamicMethod(TR::Compilation * comp, I_32 callS
J9ROMNameAndSignature *nameAndSig = NNSRP_GET(namesAndSigs[callSiteIndex], J9ROMNameAndSignature*);
J9UTF8 *signature = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSig);

TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "invokeExact", JSR292_invokeExactSig, getNonPersistentIdentifier());
TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "invokeExact", JSR292_invokeExactSig);
result = _fe->createResolvedMethodWithSignature(comp->trMemory(), dummyInvokeExact, NULL, utf8Data(signature), J9UTF8_LENGTH(signature), this);
}

Expand Down Expand Up @@ -6757,7 +6757,7 @@ TR_ResolvedJ9Method::getResolvedHandleMethod(TR::Compilation * comp, I_32 cpInde
#if defined(J9VM_OPT_REMOVE_CONSTANT_POOL_SPLITTING)
if (unresolvedInCP)
*unresolvedInCP = isUnresolvedMethodTypeTableEntry(cpIndex);
TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "invokeExact", JSR292_invokeExactSig, getNonPersistentIdentifier());
TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "invokeExact", JSR292_invokeExactSig);
J9ROMMethodRef *romMethodRef = (J9ROMMethodRef *)(cp()->romConstantPool + cpIndex);
J9ROMNameAndSignature *nameAndSig = J9ROMMETHODREF_NAMEANDSIGNATURE(romMethodRef);
int32_t signatureLength;
Expand All @@ -6784,7 +6784,7 @@ TR_ResolvedJ9Method::getResolvedHandleMethodWithSignature(TR::Compilation * comp
return 0;
#else
// TODO:JSR292: Dummy would be unnecessary if we could create a TR_ResolvedJ9Method without a j9method
TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "invokeExact", JSR292_invokeExactSig, getNonPersistentIdentifier());
TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "invokeExact", JSR292_invokeExactSig);
TR_ResolvedMethod *resolvedMethod = _fe->createResolvedMethodWithSignature(comp->trMemory(), dummyInvokeExact, NULL, signature, strlen(signature), this);
return resolvedMethod;
#endif
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/optimizer/StringPeepholes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -211,7 +211,7 @@ TR::SymbolReference* TR_StringPeepholes::MethodEnumToArgsForMethodSymRefFromName
// TODO: This is a workaround as we switched to using a byte[] backing array in String*. Remove this workaround once obsolete.
if (m == SPH_String_init_AIIZ)
{
if (!fe()->getMethodFromName(classNames[m], methodNames[m], signatures[m], comp()->getCurrentMethod()->getNonPersistentIdentifier()))
if (!fe()->getMethodFromName(classNames[m], methodNames[m], signatures[m]))
{
return comp()->getSymRefTab()->methodSymRefFromName(comp()->getMethodSymbol(), classNames[m], methodNames[m], "([CIIZ)V", TR::MethodSymbol::Special);
}
Expand Down
32 changes: 1 addition & 31 deletions runtime/compiler/runtime/RelocationRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,6 @@ TR_RelocationRecord::create(TR_RelocationRecord *storage, TR_RelocationRuntime *
case TR_ValidateClassChain:
reloRecord = new (storage) TR_RelocationRecordValidateClassChain(reloRuntime, record);
break;
case TR_ValidateMethodByName:
reloRecord = new (storage) TR_RelocationRecordValidateMethodByName(reloRuntime, record);
break;
case TR_ValidateMethodFromClass:
reloRecord = new (storage) TR_RelocationRecordValidateMethodFromClass(reloRuntime, record);
break;
Expand Down Expand Up @@ -3558,33 +3555,6 @@ TR_RelocationRecordValidateClassChain::applyRelocation(TR_RelocationRuntime *rel
return compilationAotClassReloFailure;
}

int32_t
TR_RelocationRecordValidateMethodByName::applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
uint16_t methodID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodByNameBinaryTemplate *)_record)->_methodID);
uint16_t beholderID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodByNameBinaryTemplate *)_record)->_beholderID);

void *romClassOffset = (void *)reloTarget->loadRelocationRecordValue((uintptrj_t *) &((TR_RelocationRecordValidateMethodByNameBinaryTemplate *)_record)->_romClassOffsetInSCC);
void *romClass = reloRuntime->fej9()->sharedCache()->pointerFromOffsetInSharedCache(romClassOffset);

void *romMethodOffset = (void *)reloTarget->loadRelocationRecordValue((uintptrj_t *) &((TR_RelocationRecordValidateMethodByNameBinaryTemplate *)_record)->_romMethodOffsetInSCC);
void *romMethod = reloRuntime->fej9()->sharedCache()->pointerFromOffsetInSharedCache(romMethodOffset);

if (reloRuntime->reloLogger()->logEnabled())
{
reloRuntime->reloLogger()->printf("%s\n", name());
reloRuntime->reloLogger()->printf("\tapplyRelocation: methodID %d\n", methodID);
reloRuntime->reloLogger()->printf("\tapplyRelocation: beholderID %d\n", beholderID);
reloRuntime->reloLogger()->printf("\tapplyRelocation: romClass %p\n", romClass);
reloRuntime->reloLogger()->printf("\tapplyRelocation: romMethod %p\n", romMethod);
}

if (reloRuntime->comp()->getSymbolValidationManager()->validateMethodByNameRecord(methodID, beholderID, static_cast<J9ROMClass *>(romClass), static_cast<J9ROMMethod *>(romMethod)))
return 0;
else
return compilationAotClassReloFailure;
}

int32_t
TR_RelocationRecordValidateMethodFromClass::applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
Expand Down Expand Up @@ -4547,7 +4517,7 @@ uint32_t TR_RelocationRecord::_relocationRecordHeaderSizeTable[TR_NumExternalRel
0, // TR_ValidateRomClass = 80
0, // TR_ValidatePrimitiveClass = 81
0, // TR_ValidateMethodFromInlinedSite = 82
sizeof(TR_RelocationRecordValidateMethodByNameBinaryTemplate), // TR_ValidatedMethodByName = 83
0, // TR_ValidatedMethodByName = 83
sizeof(TR_RelocationRecordValidateMethodFromClassBinaryTemplate), // TR_ValidatedMethodFromClass = 84
sizeof(TR_RelocationRecordValidateStaticMethodFromCPBinaryTemplate), // TR_ValidateStaticMethodFromCP = 85
sizeof(TR_RelocationRecordValidateSpecialMethodFromCPBinaryTemplate), // TR_ValidateSpecialMethodFromCP = 86
Expand Down
22 changes: 1 addition & 21 deletions runtime/compiler/runtime/RelocationRecord.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -300,14 +300,6 @@ struct TR_RelocationRecordValidateClassChainBinaryTemplate : public TR_Relocatio
UDATA _classChainOffsetInSCC;
};

struct TR_RelocationRecordValidateMethodByNameBinaryTemplate : public TR_RelocationRecordBinaryTemplate
{
uint16_t _methodID;
uint16_t _beholderID;
UDATA _romClassOffsetInSCC;
UDATA _romMethodOffsetInSCC;
};

struct TR_RelocationRecordValidateMethodFromClassBinaryTemplate : public TR_RelocationRecordBinaryTemplate
{
uint16_t _methodID;
Expand Down Expand Up @@ -1588,18 +1580,6 @@ class TR_RelocationRecordValidateClassChain : public TR_RelocationRecord
virtual int32_t applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);
};

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

class TR_RelocationRecordValidateMethodFromClass : public TR_RelocationRecord
{
public:
Expand Down
Loading