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

Fix erroneously large section size in ROM walk #18585

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
8 changes: 6 additions & 2 deletions runtime/util/romclasswalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ void allSlotsInROMClassDo(J9ROMClass* romClass,
#endif /* JAVA_SPEC_VERSION >= 11 */

/* add CP NAS section */
firstMethod = J9ROMCLASS_ROMMETHODS(romClass);
count = (U_32)(((UDATA)firstMethod - (UDATA)srpCursor) / (sizeof(J9SRP) * 2));
if (0 != romClass->romMethodCount) {
firstMethod = J9ROMCLASS_ROMMETHODS(romClass);
count = (U_32)(((UDATA)firstMethod - (UDATA)srpCursor) / (sizeof(J9SRP) * 2));
} else {
count = 0;
}
rangeValid = callbacks->validateRangeCallback(romClass, srpCursor, count * sizeof(J9SRP) * 2, userData);
Copy link
Contributor Author

@cjjdespres cjjdespres Dec 8, 2023

Choose a reason for hiding this comment

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

Most callbacks in this section of the walk still visit a section even if it's empty, so I kept that behaviour here. The one exception is the walk nest members SRPs block immediately above this one, which doesn't walk the nest member SRP block if it has a zero count.

Arguably it makes more sense to skip sections that are empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For instance, this block

https://github.com/eclipse-openj9/openj9/pull/18585/files#diff-46dfbaaa744dce041c4628662712f8529314d107b5d16d2bffb540c41b7a2dc7R186-R195

visits the enclosed inner classes SRP block even if it's empty, which has the odd consequence that the srpCursor for that section will point to the enclosedInnerClasses field of the ROM class, and not past the J9ROMClass header section like you might expect. That's because J9ROMCLASS_ENCLOSEDINNERCLASSES will return a pointer to enclosedInnerClasses when that field is zero. I don't think this ever messes anything up, but its an odd behaviour to have.

if (rangeValid) {
callbacks->sectionCallback(romClass, srpCursor, count * sizeof(J9SRP) * 2, "cpNamesAndSignaturesSRPs", userData);
Expand Down