-
Notifications
You must be signed in to change notification settings - Fork 728
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
base: master
Are you sure you want to change the base?
Conversation
Related to #20444 |
runtime/vm/classsupport.c
Outdated
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); |
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.
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.
runtime/vm/classsupport.c
Outdated
utf8Name[i] = '/'; | ||
} | ||
} | ||
Assert_VM_true(J9UTF8_DATA_EQUALS( |
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.
Better to compare the class name length first before doing full class name comparison. . Also the class names should be captures in the failure case, something like;getStringUTF8Length()
could help you get the length of a string
/* do class name comparison */
if (ClassNamesDiffers) {
Trc_VM_Class_Found_Has_Diff_Name(currentThread, className1, len1, className2, len2, whetherFromClassTable);
Trc_VM_Assert_ShouldNeverHappen();
}
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.
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]>
8d4a78d
to
b59d906
Compare
@@ -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++) { |
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.
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.
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.
You don't need this for loop if J9_STR_XLAT
is already set in stringFlags
.
This PR is not meant to be merged.