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

Add assertion in internalFindClassString #20501

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

Conversation

thallium
Copy link
Contributor

@thallium thallium commented Nov 4, 2024

This PR is not meant to be merged.

@hangshao0 hangshao0 marked this pull request as draft November 4, 2024 20:36
@hangshao0
Copy link
Contributor

Related to #20444

@thallium thallium changed the title Add assertion Add assertion in internalFindClassString Nov 4, 2024
U_8 localBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH];
J9UTF8 *romClassName = J9ROMCLASS_CLASSNAME(result->romClass);

utf8Name = (U_8*)copyStringToUTF8WithMemAlloc(currentThread, className, J9_STR_NULL_TERMINATE_RESULT, "", 0, (char *)localBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, &utf8Length);
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to create utf8Name if the class is newly loaded by line 379:
result = internalFindClassInModule(currentThread, j9module, utf8Name, utf8Length, classLoader, options);
You can add new code right after line 379 to check the class name.

If the class is found by hashClassTableAtString(), you can add an else block at line 384, and use compareStringToUTF8() to do the class name comparison.

utf8Name[i] = '/';
}
}
Assert_VM_true(J9UTF8_DATA_EQUALS(
Copy link
Contributor

@hangshao0 hangshao0 Nov 4, 2024

Choose a reason for hiding this comment

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

Better to compare the class name length first before doing full class name comparison. getStringUTF8Length() could help you get the length of a string. Also the class names should be captures in the failure case, something like;

 /* do class name comparison */
if (ClassNamesDiffers)  {
      Trc_VM_Class_Found_Has_Diff_Name(currentThread, className1, len1, className2, len2, whetherFromClassTable);
      Trc_VM_Assert_ShouldNeverHappen();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

On my second thought, there is no need to do class name length comparison first. I've edited the previous comment.

Signed-off-by: Gengchen Tuo <[email protected]>
@@ -378,10 +378,42 @@ internalFindClassString(J9VMThread* currentThread, j9object_t moduleName, j9obje

result = internalFindClassInModule(currentThread, j9module, utf8Name, utf8Length, classLoader, options);
}

for (int i = 0; i < utf8Length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to go through the for loop if the result is null or it is an array. The for loop can be moved after the null check and array check.

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this for loop if J9_STR_XLAT is already set in stringFlags.

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

Successfully merging this pull request may close these issues.

2 participants