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

Improvements for Relocatable Compilations #2978

Merged
merged 16 commits into from
Oct 4, 2018

Conversation

dsouzai
Copy link
Contributor

@dsouzai dsouzai commented Sep 18, 2018

This PR introduces changes in OMR required to enable optimizations that are currently implicitly disabled for relocatable compilations.

Issue tracking all the PRs: eclipse-openj9/openj9#2921

@0xdaryl
Copy link
Contributor

0xdaryl commented Sep 18, 2018

Thanks for the contribution. This should be marked WIP until #2977 is merged.

@dsouzai dsouzai changed the title Improvements for Relocatable Compilations Part 2 WIP: Improvements for Relocatable Compilations Part 2 Sep 18, 2018
@vijaysun-omr vijaysun-omr self-assigned this Sep 19, 2018
@dsouzai dsouzai force-pushed the AOTImprovementsPart2 branch 4 times, most recently from 07bf128 to 4339001 Compare September 25, 2018 20:23
Copy link
Contributor

@mstoodle mstoodle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's WIP, but figured I'd comment anyway

(uint8_t *)TR::SymbolType::typeClass,
TR_SymbolFromManager,
cg()), __FILE__, __LINE__, getNode());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should assert here if !cg()->comp()->getOption(TR_UseSymbolValidationManager) ? Otherwise, don't we know we're not relocating a class pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good idea; although before this code, we never created a DataSnippet for a class pointer under AOT - this code is now active under AOT because checkcast inlining was enabled.

if (comp()->compileRelocatableCode() && !comp()->getOption(TR_DisablePeekAOTResolutions))
if (comp()->compileRelocatableCode() &&
!comp()->getOption(TR_UseSymbolValidationManager) &&
!comp()->getOption(TR_DisablePeekAOTResolutions))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a more detailed commit message to cover these changes.

@@ -196,8 +196,6 @@ TR_VirtualGuard::createVftGuard
aconstNode->setInlinedSiteIndex(calleeIndex);
aconstNode->setByteCodeIndex(0);

comp->verifySymbolHasBeenValidated(static_cast<void *>(thisClass));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to squash this change with the one in #2977 that introduced the function in the first place...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right, I was trying to avoid merge conflicts :) . I'll try and clean this up.

@dsouzai dsouzai force-pushed the AOTImprovementsPart2 branch from 4339001 to c1e9686 Compare September 28, 2018 14:49
@dsouzai dsouzai changed the title WIP: Improvements for Relocatable Compilations Part 2 Improvements for Relocatable Compilations Sep 28, 2018
Copy link
Contributor

@mstoodle mstoodle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the primary things that need to be fixed now are to clean up the commit titles/messages and I would like to hear the argument around methods being relocated using the old mechanisms even though classes are in the new mechanism.

* a data structure, looking at several different possible answers
* before finally deciding on one. For a relocatable compile, only
* the final answer is important. Thus, a heuristic region is used to
* ignore all of the intermediate steps in determining the final
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also put this comment into the commit message, please?

{
if (cg->comp()->getOption(TR_UseSymbolValidationManager))
{
cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(displacementLocation,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a better commit message than "Update relocation for ClassAddress" ... I should be able to get the gist of the change just by reading the title and the text without knowing the context.

@@ -868,6 +868,7 @@ TR::X86ImmInstruction::addMetaDataForCodeAddress(uint8_t *cursor)

if (getReloKind() != -1) // TODO: need to change Body info one to use this
{
TR::SymbolType symbolKind = TR::SymbolType::typeClass;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this commit should have a stand-alone title and message.

@@ -1599,6 +1599,7 @@ TR::Node *constrainAload(OMR::ValuePropagation *vp, TR::Node *node)
sym->isFinal()))
haveClassLookaheadInfo = true;

bool allowForAOT = vp->comp()->getOption(TR_UseSymbolValidationManager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given only classes are actually covered properly by the symbol validation manager (methods still use the "old" approach)...have you convinced yourself that the enhanced knowledge about classes doesn't end up enabling an incorrect runtime state due to the methods derived from those classes? Or will that be protected because the queries on the resulting method won't let things get out of hand?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen, TR_MethodPointer is only generated when dealing with Profiled Pointers, so it should be ok using the "old" approach due to the class chain + first class loaded from classloader validations. Additionally, TR_RamMethod seems to be used only (or more specifically, can only be used) for the method being compiled, so that too should be ok using the "old" approach. That said, I'm doing some runs now with these changes made to the appropriate places

-               if (symbolKind == TR::SymbolType::typeClass && cg()->comp()->getOption(TR_UseSymbolValidationManager))
+               if (cg()->comp()->getOption(TR_UseSymbolValidationManager))

since I can't think of any good reason why the "new" approach shouldn't working, Towards the end of this work, I did find a bug in this code that I fixed, so perhaps I won't see that crash now.

@@ -1215,8 +1215,9 @@ TR::VPClassType *TR::VPClassType::create(OMR::ValuePropagation *vp, const char *
if (classObject)
{
bool isClassInitialized = false;
bool allowForAOT = vp->comp()->getOption(TR_UseSymbolValidationManager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another commit that should have a more meaningful commit title and message

@@ -54,9 +54,8 @@ TR::X86DataSnippet::addMetaDataForCodeAddress(uint8_t *cursor)
if (_isClassAddress)
{
bool needRelocation = TR::Compiler->cls.classUnloadAssumptionNeedsRelocation(cg()->comp());
if (needRelocation)
if (needRelocation && !cg()->comp()->compileRelocatableCode())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another commit that should have a more meaningful title and message...These changes do not "Enable checkcast inlining under AOT"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needRelocation should really be renamed to assumptionNeedsRelocation ; I'll allow it in a subsequent PR.

@@ -8058,7 +8058,9 @@ TR_ColdBlockMarker::hasNotYetRun(TR::Node *node)
TR::SymbolReference *symRef = node->getSymbolReference();
bool isUnresolved;

if (comp()->compileRelocatableCode() && !comp()->getOption(TR_DisablePeekAOTResolutions))
if (comp()->compileRelocatableCode() &&
!comp()->getOption(TR_UseSymbolValidationManager) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you just trying to preserve the old behaviour here by overloading on TR_UseSymbolValidationManager? The downstream code doesn't seem dependent on the symbol manager to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you just trying to preserve the old behaviour here by overloading on TR_UseSymbolValidationManager?

Yeah that's exactly it. I wanted there to be a way for the old code to run exactly as it did without all the new changes.

Copy link
Contributor Author

@dsouzai dsouzai Oct 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although... the isInterpretedForHeuristics change also affects the "old" behaviour... Though, it only affects it from a heuristic point of view and, if anything, results in better decisions being made, so I suppose (like 1e645c3) is just a generally good thing to have

@@ -385,6 +385,7 @@ bool TR_ResolvedMethod::isPublic() { not
bool TR_ResolvedMethod::isFinal() { notImplemented("isFinal"); return false; }
bool TR_ResolvedMethod::isStrictFP() { notImplemented("isStrictFP"); return false; }
bool TR_ResolvedMethod::isInterpreted() { notImplemented("isInterpreted"); return false; }
bool TR_ResolvedMethod::isInterpretedForHeuristics() { notImplemented("isInterpretedForHeuristics"); return false; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...makes me wonder if ForHeuristics (or its other state) is a concept worth promoting more broadly...

For example, the isUnresolved() change you had to make in another commit...

@mstoodle
Copy link
Contributor

mstoodle commented Oct 1, 2018

As a general statement, it would be nicer to see these things propagate into the code base in smaller chunks and not all at once. I know Eclipse OpenJ9 is very keen to get these changes into their 0.11 release and these changes are needed to enable even bigger things in OpenJ9, but I suspect at least some of these commits could have been submitted earlier than the full batch was and could have been merged early (i.e. not all of these changes are connected to the new symbol validation manager).

Anyway, it would be nice to see these improvements to the code base flowing in via a more incremental and hopefully spread out process, is my hopeful request for future submissions.

@dsouzai dsouzai force-pushed the AOTImprovementsPart2 branch from c1e9686 to 6245869 Compare October 1, 2018 19:14
Irwin D'Souza added 2 commits October 2, 2018 23:03
If the user specifies higher method counts, don't delay relocation and
make the scount the same as the count.

Signed-off-by: Irwin D'Souza <[email protected]>
If the user specifies disableKnownObjectTable, the KNOT does not get
created. However, some parts of the code assume the KNOT always exist.

Signed-off-by: Irwin D'Souza <[email protected]>
@dsouzai dsouzai force-pushed the AOTImprovementsPart2 branch from 6245869 to c1b5b05 Compare October 3, 2018 17:13
Irwin D'Souza added 9 commits October 4, 2018 10:40
Add new external relocation types to enable the use of the Symbol
Validation Manager which will be used to validate relocatable
compilations.

Signed-off-by: Irwin D'Souza <[email protected]>
Enable the infrastructure to allow inlining of abstract methods inlining
in relocatable compilations.

Signed-off-by: Irwin D'Souza <[email protected]>
This commit adds another field into relodata so that a downstream
project can make use of it.

These fields are generic data fields whose contents can vary based on
the relocation record being generated.

Signed-off-by: Irwin D'Souza <[email protected]>
Previously, because almost everything was "unresolved" under AOT, all
calls would use the unresolved dispatch. However, with the new
validations, very few unresolved pointers are only unresolved because of
AOT. Therefore, generating an unresolved dispatch is incorrect.

The solution to this problem is to assume, during an AOT compile, that
all methods are interpreted. Thus, if a method is resolved, the compiler
will generate a resolved interpreter dispatch snippet, which can patch
the caller if/when the method is compiled.

Signed-off-by: Irwin D'Souza <[email protected]>
Sometimes, when devirtualizing, the compiler keeps the call virtual, but
uses a cpIndex of -1, which causes a problem during relocation. Thus
this commit adds a check to not devirtualize calls based on a Front End
query.

Signed-off-by: Irwin D'Souza <[email protected]>
Add a query to allow the validation of targets to be inlined for
relocatable compiles.

Signed-off-by: Irwin D'Souza <[email protected]>
Under the option to use the Symbol Validation Manager, the correct way
to acquire the address for classes or methods, is to go through the
manager, since it maintains consistency with all the validations as well
as relocations. This commit transmutes the TR_ClassPointer,
TR_MethodPointer, and TR_RamMethod into a TR_SymbolFromManager
relocation record in order to maintain consistency with the rest of the
validations.

Signed-off-by: Irwin D'Souza <[email protected]>
Under the option to use the Symbol Validation Manager, the correct way
to acquire the address for classes is to go through the
manager, since it maintains consistency with all the validations as well
as relocations. This commit transmutes the TR_ClassAddress into a
TR_SymbolFromManager relocation record in order to maintain
consistency with the rest of the validations.

Signed-off-by: Irwin D'Souza <[email protected]>
Irwin D'Souza added 5 commits October 4, 2018 10:44
This commit allows, under AOT and the option to use the Symbol
Validation Manager, some findClassInfoAfterLocking queries in order to
provide the optimizer with more information that was previously
unavailable.

Signed-off-by: Irwin D'Souza <[email protected]>
If a data snippet contains a class address, this address needs to be
relocated. This commit ensures that the necessary relocation record is
created.

Signed-off-by: Irwin D'souza <[email protected]>
Under AOT, the compiler assumes some classes are unresolved, even if
they actually aren't. This is because some queries will return NULL if
the class can't be remembered in the SCC. Some optimizations, such as
cold block marker, are affected by whether or not a block contains an
unresolved reference. In AOT, many more blocks are incorrectly marked
cold. This commit attempts to remedy that.

Signed-off-by: Irwin D'Souza <[email protected]>
Add query for when the compiler asks about whether a method is
interpreted for heuristic reasons, and not for functional correctness
reasons.

Signed-off-by: Irwin D'Souzai <[email protected]>
@dsouzai dsouzai force-pushed the AOTImprovementsPart2 branch from c1b5b05 to e0bc346 Compare October 4, 2018 14:46
@mstoodle
Copy link
Contributor

mstoodle commented Oct 4, 2018

genie-omr build all

@vijaysun-omr vijaysun-omr assigned mstoodle and unassigned mstoodle and vijaysun-omr Oct 4, 2018
@mstoodle
Copy link
Contributor

mstoodle commented Oct 4, 2018

I have opened #3029 to start documenting work that should be happen going forward to tease OpenJ9 and OMR further apart in their mutual dependency in specifically the relocation infrastructure. With that in place, I think we can merge this one now.

@mstoodle mstoodle merged commit 70c42dc into eclipse-omr:master Oct 4, 2018
@dsouzai dsouzai deleted the AOTImprovementsPart2 branch January 4, 2021 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants