-
Notifications
You must be signed in to change notification settings - Fork 736
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
Intialize dataAddr field only for non-zero length array #20869
base: master
Are you sure you want to change the base?
Conversation
ff0ba22
to
5938046
Compare
Off-heap personal build, upstream personal build. My off-heap personal build is looking good so far, only 1 unrelated failure. I'll remove the WIP tag once both builds have passed without off-heap related failures. cc: @r30shah / @zl-wang / @dmitripivkine |
5938046
to
54bf0a5
Compare
Launched new non-off-heap personal build to verify PR changes |
da4a877
to
9b31e29
Compare
1317bac
to
c3c566c
Compare
Relaunched non off-heap build |
648f364
to
068425c
Compare
I have verified the sequence for x and z through a unit test. Need to do the same for power and aarch64 before removing WIP tag. |
068425c
to
6d13fde
Compare
Launched personal non off-heap build for power. |
71bbabb
to
8f03946
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking out the changes, by skimming through the change, I had some intiail questions, I have posted.
if (isOffHeapAllocationEnabled) | ||
{ | ||
TR_ASSERT_FATAL_WITH_NODE(node, | ||
TR::InstOpCode::LGF == loadDimLenOpCode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we have this assert (Checking loadDimLenOpCode to LGF
). That variable is initialized to LGF
at line 4891 and I do not see it ever updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataAddr
field should be 0 for 0 size arrays. Since size will already be 0, I figured we can use that to 0-out dataAddr
field. The issue is that size
is 4 bytes wide whereas dataAddr
is 8 bytes wide, in order to use the same register I need to clear top 4 bytes of firstDimLenReg
. I added the assert to ensure that size is sign extended to 64 bits when being loaded to firstDimLenReg
. Same logic for second LGF
assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do get the reason behind using the LGF instruction. Do you mean to say the logic for the assert is safeguarding someone accidentally changing the code to use other instruction to load firstDimLenReg ? If so instead of putting this assert which I feel is not needed, we should put the comment where you are loading firstDimLenReg on why using LGF instead of LG and warn about the potential functional issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a comment explaining why LGF is used instead of LG.
} | ||
if (isOffHeapAllocationEnabled) | ||
{ | ||
TR_ASSERT_FATAL_WITH_NODE(node, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as before.
861e92d
to
f4ce058
Compare
@r30shah Can I please get another review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Shubham for making changes, I think overall things looks good to me. I have left some question / comments and nitpicks and appreciate if you can address them. Also can you share a instruction selection log to ensure the ICF is correct ?
@@ -4871,7 +4871,6 @@ static TR::Register * generateMultianewArrayWithInlineAllocators(TR::Node *node, | |||
|
|||
#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION) | |||
bool isOffHeapAllocationEnabled = TR::Compiler->om.isOffHeapAllocationEnabled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that this part of the code exists and the changes in this PR is not changing that. But as we are here changing the code, can I request to move initialization on isOffHeapAllocationEnabled
closer to where it is used as with the change it is first used at line 4963 ? This would also help removing unnecessary defined
check here and brings variable declaration and initialization closer.
// In the mainline, first load the first and second dimensions' lengths into registers. | ||
/* In the mainline, first load the first and second dimensions' lengths into registers. | ||
* | ||
* LGF is used instead of LG so that array size register can be used to NULL dataAddr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be L here right? size field is 4 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, you are right, I'll update the code.
if (TR::Compiler->om.compressObjectReferences()) | ||
{ | ||
// Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide. | ||
cursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, firstDimLenReg, generateS390MemoryReference(targetReg, static_cast<int32_t>(fej9->getOffsetOfDiscontiguousArraySizeField()) + 4, cg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment says clear padding but you are storing the firstDimLenReg
for the Array Size. Can you clarify and eventually clean-up comment if needed.
Also why is the inconsistencies with static_cast throughout the code. May be remove it from here (There is anyway implicit cast to int32_t).
if (isOffHeapAllocationEnabled) | ||
{ | ||
cursor = generateRXInstruction(cg, TR::InstOpCode::STG, node, firstDimLenReg, generateS390MemoryReference(targetReg, fej9->getOffsetOfDiscontiguousDataAddrField(), cg)); | ||
iComment("Clear 1st dim dataAddr field."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are dealing with 0 size array at this point, and we used LGF
to load dimension size, firstDimLenReg
will be 0 so I figured we could use that to clear dataAddr
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. This does feel like an implicit assumption. If the register gets modified in future, we end up with wrong code and this is tied with the use of LGF
to use the dimension register. I am ok with this change. But make sure that we write this explicit assumption (That dimension register should contain NULL)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's why I had the assert initially. I'll update the comment with that assumption.
@@ -5026,6 +5020,33 @@ static TR::Register * generateMultianewArrayWithInlineAllocators(TR::Node *node, | |||
iComment("Init 1st dim class field."); | |||
cursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, firstDimLenReg, generateS390MemoryReference(targetReg, fej9->getOffsetOfContiguousArraySizeField(), cg)); | |||
iComment("Init 1st dim size field."); | |||
if (!TR::Compiler->om.compressObjectReferences()) | |||
{ // Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this comment to new line, not besides braces.
if (TR::Compiler->om.compressObjectReferences()) | ||
{ | ||
// Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide. | ||
cursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, secondDimLenReg, generateS390MemoryReference(temp2Reg, static_cast<int32_t>(fej9->getOffsetOfDiscontiguousArraySizeField()) + 4, cg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as before with firstDimLenReg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are dealing with 0 size array at this point, and we used LGF
to load dimension size, secondDimLenReg
will be 0 so I figured we could use that to clear dataAddr
field.
iCursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, eNumReg, | ||
generateS390MemoryReference(resReg, fej9->getOffsetOfDiscontiguousArraySizeField(), cg), iCursor); | ||
// Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide. | ||
iCursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, eNumReg, generateS390MemoryReference(resReg, static_cast<int32_t>(fej9->getOffsetOfDiscontiguousArraySizeField()) + 4, cg), iCursor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra padding is added to the array header for 8 byte boundary alignment; so with that comment I just meant that we add 4 to size field offset to get to the padding. I'll update the comment to be more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okk, does enumReg
contains 0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this works because if enumReg
isn't 0 (i.e. we aren't dealing with 0 size array), whatever we write at getOffsetOfDiscontiguousArraySizeField
will be overwritten by the element or dataAddr field (if present). But I think using XC
might provide better readability. I'll update the code.
// Load address of first array element | ||
iCursor = generateRXInstruction(cg, TR::InstOpCode::LA, node, dataSizeReg, dataAddrMR, iCursor); | ||
// Use cc from CFI to load NULL into dataSizeReg for 0 size array | ||
iCursor = generateRRFInstruction(cg, TR::InstOpCode::LOCGR, node, dataSizeReg, offsetReg, getMaskForBranchCondition(TR::InstOpCode::COND_BE), true, iCursor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we used getMaskForBranchCondition function call here for storing 0x8 otherwise ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thought it was better for overall readability.
iCursor = generateRRInstruction(cg, TR::InstOpCode::XGR, node, offsetReg, offsetReg, iCursor); | ||
iCursor = generateRILInstruction(cg, TR::InstOpCode::CFI, node, enumReg, 0, iCursor); | ||
|
||
dataAddrMR = generateS390MemoryReference(resReg, TR::Compiler->om.contiguousArrayHeaderSizeInBytes(), cg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just going through the code, do we even need the memory reference variable ? If not may be simply use generateS390MemoryReference in the instruction you are using.
if (comp->getOption(TR_TraceCG)) | ||
traceMsg(comp, "Node (%p): Clean out dataAddr field.\n", node); | ||
|
||
uint16_t bytesToClear = static_cast<uint16_t>(TR::Compiler->om.discontiguousArrayHeaderSizeInBytes() - fej9->getOffsetOfDiscontiguousDataAddrField()) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rather confusing. I understand the reason behind subtracting 1, but I think code becomes more readable, if you simply subtract 1 when you are using bytesToClear in the XC instruction generation.
f4ce058
to
fe5e34c
Compare
@r30shah I have updated the PR based on your suggestions, can I please get another review. |
I'll share the instruction selection log shortly. |
Is this what you were looking for?
|
if (isOffHeapAllocationEnabled) | ||
{ | ||
cursor = generateRXInstruction(cg, TR::InstOpCode::STG, node, firstDimLenReg, generateS390MemoryReference(targetReg, fej9->getOffsetOfDiscontiguousDataAddrField(), cg)); | ||
iComment("Clear 1st dim dataAddr field."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. This does feel like an implicit assumption. If the register gets modified in future, we end up with wrong code and this is tied with the use of LGF
to use the dimension register. I am ok with this change. But make sure that we write this explicit assumption (That dimension register should contain NULL)
iCursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, eNumReg, | ||
generateS390MemoryReference(resReg, fej9->getOffsetOfDiscontiguousArraySizeField(), cg), iCursor); | ||
// Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide. | ||
iCursor = generateRXInstruction(cg, TR::InstOpCode::ST, node, eNumReg, generateS390MemoryReference(resReg, static_cast<int32_t>(fej9->getOffsetOfDiscontiguousArraySizeField()) + 4, cg), iCursor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okk, does enumReg
contains 0 ?
cursor = generateS390BranchInstruction(cg, TR::InstOpCode::BRC, TR::InstOpCode::COND_BRC, node, populateFirstDimDataAddrSlot); | ||
} | ||
else | ||
bool isOffHeapAllocationEnabled = TR::Compiler->om.isOffHeapAllocationEnabled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need proper indentation here.
961e9c7
to
152a6d8
Compare
@r30shah I have updated the PR based on your suggestions. Can I please get another review? |
bbd1f85
to
2d64d57
Compare
@r30shah Since we only need to clear dataAddr field for off-heap I have moved padding related changes to a separate PR. I need to do more testing to verify that my changes don't break 32 bit builds. I'll also look into adding an API to determine whether the padding exists or not. Can I please get a review for remaining changes? |
@VermaSh As overall changes are under review and most of the review is done, I would appreciate and prefer to go ahead with the changes in this PR (Just think about the effort on review and testing), unless you make it makes logical sense to do it when most of the review is done and we are about to merge this PR. |
2aa605a
to
5166143
Compare
@r30shah Verified with my changes, we should be good for both clearing padding for 64 bit and 32 bit modes. BTW, I added an assert for |
node, | ||
temp3Reg, | ||
generateS390MemoryReference(targetReg, TR::Compiler->om.contiguousArrayHeaderSizeInBytes(), cg)); | ||
cursor = generateRXInstruction(cg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use query to get store opcode which returns appropriate opcode for platform (I do understand we may not have off heap for 31 bit, but should use query to use right opcde)
// Since 2nd dimension array is 0 length, we can use secondDimLenReg | ||
// to clear dataAddr field. secondDimLenReg is expected to be NULL | ||
// at this point. | ||
cursor = generateRXInstruction(cg, TR::InstOpCode::STG, node, secondDimLenReg, generateS390MemoryReference(temp2Reg, fej9->getOffsetOfDiscontiguousDataAddrField(), cg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as before, should we use query ?
|
||
// Clear 4 byte padding after the size field in the array header. | ||
TR_ASSERT_FATAL_WITH_NODE(node, | ||
TR::Compiler->om.getObjectAlignmentInBytes() == 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rather long message to print for assert and I am not sure if it makes sense to print that out when someone hits the assert. It does not provide any more value to the failure than having a simple comment here that developer can take a look and see. Also what happens to this assert where using 31 bit ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object alignment is 8 bytes on 31 bit as well so this assert will be valid there as well (minimum object alignment). I think it will be better to check OMR_MINIMUM_OBJECT_SIZE
rather than object alignment. Looking to see if we have an API for it or if I need to add one. This will help clean up the assert message as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be I should ask you this differently. Think about the what is it that you want to prevent with having this Fatal Assert here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my train of thought behind adding the assert:
We want to avoid corrupting an other object while clearing padding for contiguous and discontiguous header layout. The padding field exists for contiguous header layout in full refs and for discontiguous header layout in compressed refs. But we don't know if the array we are dealing with has the field, we won't know until we do a runtime check. To avoid the extra instruction, we assume that the array has the field and clear memory at corresponding padding offset.
This is where the minimum object size comes into play. For compressed refs, contiguous header is 8 bytes and discontiguous header is 16 bytes, with the padding field at +12 offset. Since we unconditionally clear memory at +12 offset, we could potentially corrupt the object itself (if the array is actually contiguous) or adjacent objects.
We don't need to worry about corrupting the object itself because we are in allocation phase so there is nothing to corrupt at that memory offset. And as long as OMR_MINIMUM_OBJECT_SIZE
is 16 bytes, we don't need to worry about corrupting any adjacent objects either.
Does that sound good? Should I change the assert and/or add additional details?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the chart I am using for different array header layouts
Source: https://github.com/eclipse-openj9/openj9/blob/master/runtime/oti/j9nonbuilder.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the explanation. What I was asking, is that, we do not need to write this explanation in the ASSERT message when for some reason this condition gets violated. I agree with your reasoning for having the Fatal Assert (To catch the case if things get changed, we catch the issue earlier in testing to prevent accidentally clearing other object).
I will let you figure out what query would be the correct one here , but recommend you to have a concise trace message in the trace so JIT developer/ service team can go through the code and understand why that assert was thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I agree, I'll push updated assert message shortly.
iCursor = generateRRFInstruction(cg, TR::InstOpCode::LOCGR, node, dataSizeReg, offsetReg, getMaskForBranchCondition(TR::InstOpCode::COND_BE), true, iCursor); | ||
|
||
// Write element address to dataAddr field | ||
iCursor = generateRXInstruction(cg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as before, should we use query to get store opcode ?
generateS390MemoryReference(resReg, TR::Compiler->om.contiguousArrayHeaderSizeInBytes(), cg), | ||
iCursor); | ||
// Write first data element address to dataAddr field | ||
iCursor = generateRXInstruction(cg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question as before.
5166143
to
d671f61
Compare
@r30shah I have addressed all expect the object alignment suggestion. I need some more time to fix that. |
e0be939
to
262b9ce
Compare
262b9ce
to
2b0941c
Compare
Update array inline allocation sequence to initialize dataAddr field only for non-zero size arrays. Field should be left blank for zero size arrays. Signed-off-by: Shubham Verma <[email protected]>
2b0941c
to
2bf9312
Compare
Update array inline allocation sequence to initialize dataAddr field only for non-zero length arrays. Field should be left blank for zero length arrays. Additionally this also clears padding field after the size field.