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

Create relocation records of type TR_BlockFrequency and TR_RecompQueuedFlag #5202

Merged

Conversation

ashu-mehra
Copy link
Contributor

@ashu-mehra ashu-mehra commented May 15, 2020

In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in TR_BlockFrequencInfo class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
This commit adds the code for generating the relocation records
for block frequency and the recompilation queued flag.
Currently it only handles x and p architectures.

Signed-off-by: Ashutosh Mehra mehra.ashutosh@ibm.com

Copy link
Contributor

@dsouzai dsouzai left a comment

Choose a reason for hiding this comment

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

Overall looks ok to me.

@@ -2970,6 +2970,14 @@ OMR::Power::CodeGenerator::addMetaDataForLoadAddressConstantFixed(
TR::DebugCounter::generateRelocation(comp, firstInstruction, node, counter, seqKind);
return;
}

case TR_BlockFrequency:
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting.

@vijaysun-omr vijaysun-omr self-assigned this May 21, 2020
@vijaysun-omr
Copy link
Contributor

I don't have questions related to the "how" in this PR but I did have a question around "why" we feel that relocating this data is important ?

@vijaysun-omr
Copy link
Contributor

@genie-omr build all

@Leonardo2718
Copy link
Contributor

I don't have questions related to the "how" in this PR but I did have a question around "why" we feel that relocating this data is important ?

It would be good if that information was in the commit message too.

@vijaysun-omr
Copy link
Contributor

Ping @ashu-mehra this is probably only awaiting some more description from you before it can be considered for merging.

@vijaysun-omr
Copy link
Contributor

Ping again to see if this can be pushed forward in the next few days

@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch from c4d5d33 to df97e33 Compare August 19, 2020 19:29
@vijaysun-omr
Copy link
Contributor

The request for a more descriptive commit message in prior comments probably needs to be addressed.

@ashu-mehra
Copy link
Contributor Author

ashu-mehra commented Aug 20, 2020

This PR depends on OpenJ9 PR #5202. There is some more work needed and hence it is still in draft mode.

ashu-mehra pushed a commit to ashu-mehra/omr that referenced this pull request Aug 20, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for block frequency.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this pull request Aug 20, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for recompilation queue flag.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch from df97e33 to c215809 Compare August 20, 2020 14:06
@ashu-mehra
Copy link
Contributor Author

I have updated the commit messages to provide more information.

@vijaysun-omr
Copy link
Contributor

Okay if you don't mind, please make it WIP until you are ready to have me consider it for merging. That way, I don't mistakenly take action when you did not want me to.

@ashu-mehra ashu-mehra changed the title Create relocation records of type TR_BlockFrequency WIP Create relocation records of type TR_BlockFrequency Aug 20, 2020
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this pull request Aug 26, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for block frequency.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this pull request Aug 26, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for recompilation queue flag.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch from c215809 to c16938a Compare August 26, 2020 23:17
ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Sep 11, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for block frequency.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Sep 11, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for recompilation queue flag.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
@vijaysun-omr
Copy link
Contributor

Any update on this ?

ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Oct 22, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for block frequency.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Oct 22, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for recompilation queue flag.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Oct 22, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for block frequency.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Oct 22, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for recompilation queue flag.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
ashu-mehra pushed a commit to ashu-mehra/openj9-omr that referenced this pull request Oct 23, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
specifically for block frequency.

Signed-off-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch 2 times, most recently from deeb63f to f77ef57 Compare November 4, 2020 15:18
ashu-mehra added a commit to ashu-mehra/omr that referenced this pull request Nov 4, 2020
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
for block frequency and the recompilation queued flag.

Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch from f77ef57 to 831b33e Compare November 4, 2020 16:31
ashu-mehra added a commit to ashu-mehra/openj9-omr that referenced this pull request Jan 7, 2021
In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
OpenJ9 PR eclipse-omr/omr#5202 creates the necessary
structures representing the relocation record for this data.
This commit adds the code for generating the relocation records
for block frequency and the recompilation queued flag.

Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch from 831b33e to 3943892 Compare January 8, 2021 21:07
@ashu-mehra ashu-mehra marked this pull request as ready for review January 8, 2021 21:09
@ashu-mehra ashu-mehra changed the title WIP Create relocation records of type TR_BlockFrequency Create relocation records of type TR_BlockFrequency Jan 8, 2021
@ashu-mehra
Copy link
Contributor Author

Windows failure is due to SegFault in ThreadCreateTest that runs as part of threadtest. It cannot be related to the changes in this PR.

@ashu-mehra
Copy link
Contributor Author

@dsouzai another pr for your review.

@ashu-mehra ashu-mehra changed the title Create relocation records of type TR_BlockFrequency Create relocation records of type TR_BlockFrequency and TR_RecompQueuedFlag Jan 8, 2021
Copy link
Contributor

@dsouzai dsouzai left a comment

Choose a reason for hiding this comment

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

I noticed that you you've only created the relo records for x and p; I know that this stuff isn't supported on the other platforms, but you might as well add them for the others. That way when it's finally enabled on the other platforms, the infra will already be in place.

(uint8_t *)recordInfo,
TR_BlockFrequency, self());
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How come you don't also need a relo record for TR_RecompQueuedFlag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TR_RecompQueuedFlag gets taken care by the default case towards the end of the method:

   if (!relo)
      {
      relo = new (self()->trHeapMemory()) TR::BeforeBinaryEncodingExternalRelocation(
         firstInstruction,
         (uint8_t *)value,
         (uint8_t *)seqKind,
         (TR_ExternalRelocationTargetKind)typeAddress,
         self());
      }

(uint8_t *)recordInfo,
(TR_ExternalRelocationTargetKind)typeAddress, self()),
__FILE__, __LINE__, node);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How come you don't also need a relo record for TR_RecompQueuedFlag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TR_RecompQueuedFlag gets taken care by the last else if block:

   else if (typeAddress != -1)
      {
      TR_RelocationRecordInformation *recordInfo = ( TR_RelocationRecordInformation *)comp->trMemory()->allocateMemory(sizeof( TR_RelocationRecordInformation), heapAlloc);
      recordInfo->data1 = (uintptr_t)value;
      recordInfo->data3 = orderedPairSequence2;
      self()->addExternalRelocation(new (self()->trHeapMemory()) TR::ExternalOrderedPair32BitRelocation((uint8_t *)firstInstruction,
                                                                                          (uint8_t *)secondInstruction,
                                                                                          (uint8_t *)recordInfo,
                                                                                          (TR_ExternalRelocationTargetKind)typeAddress, self()),
                           __FILE__, __LINE__, node);
      }

Comment on lines 520 to 522
//TR::StaticSymbol *staticSym = sr.getSymbol()->getStaticSymbol();
//TR_ASSERT(staticSym, "Expected static symbol for block frequency\n");
//TR::Relocation *relocation = new (cg->trHeapMemory()) TR::ExternalRelocation(displacementLocation, (uint8_t *)staticSym->getStaticAddress(), TR_BlockFrequency, cg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these comments be removed?

TR::Relocation *relocation = new (cg->trHeapMemory()) TR::ExternalRelocation(displacementLocation, (uint8_t *)recordInfo, TR_BlockFrequency, cg);
cg->addExternalRelocation(relocation, __FILE__, __LINE__, containingInstruction->getNode());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How come you don't also need a relo record for TR_RecompQueuedFlag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm it does look like TR_RecompQueuedFlag should be handled here, but during my testing I noticed relocation records are getting generated for TR_RecompQueuedFlag. Probably they are getting generated from other locations.
Let me check why it is working without the relo record for TR_RecompQueuedFlag here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the relocation records generated with this change set I see TR_BlockFrequency is getting generated twice for the same offset, eg:

TR_BlockFrequency (102)             /home/asmehra/data/ashu-mehra/openj9-openjdk-jdk11/omr/compiler/x/amd64/codegen/OMRMemoryReference.cpp   524      0191       0151 00007F9E174BFD80
TargetAddress1:00007F9E15DE4D10,  TargetAddress2:0000000000000000
TR_BlockFrequency (102)             /home/asmehra/data/ashu-mehra/openj9-openjdk-jdk11/omr/compiler/x/codegen/X86BinaryEncoding.cpp  2937      0191       0151 00007F9E174BFD80
TargetAddress1:00007F9E15DE4DA0,  TargetAddress2:0000000000000000

but TR_RecompQueuedFlag is generated only once.

OMR::X86::AMD64::MemoryReference::generateBinaryEncoding creates a new instruction to move the addr to reg [1].
Then we add metadata for the address as part of which relocation records are generated [2].
This is the place where this patch has code for creating relo record for TR_BlockFrequency but not for TR_RecompQueuedFlag.
Then further down in OMR::X86::AMD64::MemoryReference::generateBinaryEncoding when the binary encoding for the new instruction is generated [3], we again generate metadata [4] where this patch creates relo records for TR_BlockFrequency and TR_RecompQueuedFlag.
So effectively we end up creating duplicate relo records for TR_BlockFrequency. We should be generating the relo record only at one place, which I feel should be when adding metadata for the instruction. Going by that logic, the relo record generated at [2] for TR_BlockFrequency should be avoided.

On similar note, probably TR_DebugCounter also has similar issue of duplicate records getting generated.

@dsouzai your thoughts on this?

[1] https://github.com/eclipse/omr/blob/bded46caf73287830139853961ffacb96cc9758e/compiler/x/amd64/codegen/OMRMemoryReference.cpp#L612
[2] https://github.com/eclipse/omr/blob/bded46caf73287830139853961ffacb96cc9758e/compiler/x/amd64/codegen/OMRMemoryReference.cpp#L644
[3] https://github.com/eclipse/omr/blob/bded46caf73287830139853961ffacb96cc9758e/compiler/x/amd64/codegen/OMRMemoryReference.cpp#L664
[4] https://github.com/eclipse/omr/blob/bded46caf73287830139853961ffacb96cc9758e/compiler/x/codegen/X86BinaryEncoding.cpp#L2796

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm interesting. Yeah I think you're right; the debug counter relo doesn't look like it belongs in [2] above, especially since there's no TR_DataAddress in [2]. So TR_BlockFrequency doesn't belong in [2] either.


case TR_RecompQueuedFlag:
{
TR::StaticSymbol *staticSym = symbol->getStaticSymbol();
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be unused.

}
else if (symbol->isRecompQueuedFlag())
{
TR::StaticSymbol *staticSym = symbol->getStaticSymbol();
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be unused.

In OpenJ9 the JProfiling framework is used to create profiled code
which contains references to internal data structures like block
frequencies stored in `TR_BlockFrequencInfo` class, or the flag for
checking if the method is already in recompilation queue.
To support AOT compilation for such code, we need to generate relocation
records for such data structures referenced by the compiled code.
This commit adds the code for generating the relocation records
for block frequency and the recompilation queued flag.
Currently it only handles x and p architectures.

Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
@ashu-mehra ashu-mehra force-pushed the create_relorecord_block_frequency branch from 27a98fd to c249f4d Compare January 18, 2021 16:51
@ashu-mehra
Copy link
Contributor Author

@dsouzai I have updated the pr addressing the review comments and also added the changes for z arch.

Thanks to @dchopra001 for testing the z changes using eclipse-openj9/openj9#11625.

Copy link
Contributor

@dsouzai dsouzai left a comment

Choose a reason for hiding this comment

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

lgtm; thanks @ashu-mehra

@vijaysun-omr
Copy link
Contributor

@genie-omr build all

@vijaysun-omr
Copy link
Contributor

Checks have passed and code has been reviewed by @dsouzai and @mpirvu. I am merging.

@ashu-mehra
Copy link
Contributor Author

@vijaysun-omr can this be merged?

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