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

NULL initialize dataAddr field for 0 size arrays #20892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VermaSh
Copy link
Contributor

@VermaSh VermaSh commented Jan 8, 2025

Update array inline allocation sequence to initialize dataAddr field only for non-zero size arrays. Field should be left blank for zero size arrays. Additionally this also clears padding field after the size field.

@VermaSh
Copy link
Contributor Author

VermaSh commented Jan 8, 2025

@hzongaro Can I please get a review?

@hzongaro hzongaro self-assigned this Jan 8, 2025
@hzongaro hzongaro self-requested a review January 8, 2025 20:38
Copy link
Member

@hzongaro hzongaro left a comment

Choose a reason for hiding this comment

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

I have some questions about whether the padding field always exists.

Also, I wonder whether it would be worthwhile having methods that will return the offset of the padding field instead of calculating it here, and perhaps a method that will indicate whether the padding field even exists, if it might not exist.

runtime/compiler/x/codegen/J9TreeEvaluator.cpp Outdated Show resolved Hide resolved
runtime/compiler/x/codegen/J9TreeEvaluator.cpp Outdated Show resolved Hide resolved
@@ -1554,37 +1553,18 @@ static TR::Register * generateMultianewArrayWithInlineAllocators(TR::Node *node,
// Init size and mustBeZero ('0') fields to 0
generateMemImmInstruction(TR::InstOpCode::S4MemImm4, node, generateX86MemoryReference(targetReg, fej9->getOffsetOfContiguousArraySizeField(), cg), 0, cg);
generateMemImmInstruction(TR::InstOpCode::S4MemImm4, node, generateX86MemoryReference(targetReg, fej9->getOffsetOfDiscontiguousArraySizeField(), cg), 0, cg);
if (TR::Compiler->om.compressObjectReferences())
{ // Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide.
generateMemImmInstruction(TR::InstOpCode::S4MemImm4, node, generateX86MemoryReference(targetReg, fej9->getOffsetOfDiscontiguousArraySizeField() + 4, cg), 0, cg);
Copy link
Member

Choose a reason for hiding this comment

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

Do you know why this padding wasn’t previously being cleared? What problems will failing to clear it cause?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it just slipped through the cracks. It hasn't caused any failures as of now, I don't think we read the padding. I am clearing it mostly because of the implicit expectation that all non used "fields" in an array header should be NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it is already being done for VM allocated arrays. @tajila Can you please confirm if this is true?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@dmitripivkine dmitripivkine Jan 23, 2025

Choose a reason for hiding this comment

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

GC always zeroes header of the object before initialization (including possible padding) if it has not been zeroed before as part of pre-zeroed TLH. So, yes, padding in the header is zeroed always.

Copy link
Contributor

@dmitripivkine dmitripivkine Jan 23, 2025

Choose a reason for hiding this comment

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

My concern about changes like this is logic connected with Indexable header shapes happen to be used now. Any change in this area would require to fix (and find first!) all places like this. I understand any generalization can impact JIT performance, but we should think about it. Also if we want to clear padding using 32-bit instruction (is it right?) why do J9IndexableObjectDiscontiguousCompressed->size offset + 4 bytes, why not to use J9IndexableObjectDiscontiguousCompressed->padding directly?

runtime/compiler/x/codegen/J9TreeEvaluator.cpp Outdated Show resolved Hide resolved
runtime/compiler/x/codegen/J9TreeEvaluator.cpp Outdated Show resolved Hide resolved
@@ -1633,6 +1613,28 @@ static TR::Register * generateMultianewArrayWithInlineAllocators(TR::Node *node,
generateMemRegInstruction(TR::InstOpCode::SMemReg(use64BitClasses), node, generateX86MemoryReference(targetReg, TR::Compiler->om.offsetOfObjectVftField(), cg), classReg, cg);
// Init 1st dim array size field
generateMemRegInstruction(TR::InstOpCode::S4MemReg, node, generateX86MemoryReference(targetReg, fej9->getOffsetOfContiguousArraySizeField(), cg), firstDimLenReg, cg);
if (!TR::Compiler->om.compressObjectReferences())
{ // Clear padding in contiguous array header layout. +4 because size field is 4 bytes wide.
generateMemImmInstruction(TR::InstOpCode::S4MemImm4, node, generateX86MemoryReference(targetReg, fej9->getOffsetOfContiguousArraySizeField() + 4, cg), 0, cg);
Copy link
Member

Choose a reason for hiding this comment

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

Does the padding field exist for contiguous array header in 32-bit mode? Looking at j9nonbuilder.h, I don't think it does. Sorry if I'm misreading it!

runtime/compiler/x/codegen/J9TreeEvaluator.cpp Outdated Show resolved Hide resolved
@VermaSh
Copy link
Contributor Author

VermaSh commented Jan 22, 2025

That's a good suggestions. I'll open a separate PR with APIs to indicate whether padding field exists and get it's offset. I'll use this PR just for dataAddr changes since it must be cleared for off-heap but we can get away by not clearing padding field.

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 <shubhamv.sv@gmail.com>
@VermaSh
Copy link
Contributor Author

VermaSh commented Jan 22, 2025

@hzongaro I have moved my padding field changes to #20998. Can I please get another review for the remaining changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants