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
Draft
Show file tree
Hide file tree
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
34 changes: 33 additions & 1 deletion runtime/vm/classsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ internalFindClassString(J9VMThread* currentThread, j9object_t moduleName, j9obje
J9Class *result = NULL;
J9JavaVM* vm = currentThread->javaVM;
BOOLEAN fastMode = J9_ARE_ALL_BITS_SET(vm->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_FAST_CLASS_HASH_TABLE);
PORT_ACCESS_FROM_JAVAVM(vm);

/* If -XX:+FastClassHashTable is enabled, do not lock anything to do the initial table peek */
if (!fastMode) {
Expand All @@ -334,7 +335,6 @@ internalFindClassString(J9VMThread* currentThread, j9object_t moduleName, j9obje
U_8 *utf8Name = NULL;
UDATA utf8Length = 0;
UDATA stringFlags = J9_STR_NULL_TERMINATE_RESULT;
PORT_ACCESS_FROM_JAVAVM(vm);

if (CLASSNAME_INVALID == allowedBitsForClassName) {
stringFlags |= J9_STR_XLAT;
Expand Down Expand Up @@ -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.

if (utf8Name[i] == '.') {
utf8Name[i] = '/';
}
}

if (NULL != result) {
J9UTF8 *romClassName = J9ROMCLASS_CLASSNAME(result->romClass);
if (!J9CLASS_IS_ARRAY(result) && !J9UTF8_DATA_EQUALS(
J9UTF8_DATA(romClassName), J9UTF8_LENGTH(romClassName),
utf8Name, utf8Length)) {
printf("find class\n");
Trc_VM_Class_Found_Has_Diff_Name(currentThread, utf8Name, utf8Length, J9UTF8_DATA(romClassName), J9UTF8_LENGTH(romClassName), 0);
Assert_VM_true(0);
}
}
if (utf8Name != localBuf) {
j9mem_free_memory(utf8Name);
}
} else {
if (!J9CLASS_IS_ARRAY(result)) {
J9UTF8 *romClassName = J9ROMCLASS_CLASSNAME(result->romClass);
if (!compareStringToUTF8(currentThread, className, 1, J9UTF8_DATA(romClassName), J9UTF8_LENGTH(romClassName))) {
printf("find class\n");
U_8 *utf8Name = NULL;
UDATA utf8Length = 0;
U_8 localBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH];

utf8Name = (U_8*)copyStringToUTF8WithMemAlloc(currentThread, className, J9_STR_NULL_TERMINATE_RESULT, "", 0, (char *)localBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, &utf8Length);
Trc_VM_Class_Found_Has_Diff_Name(currentThread, utf8Name, utf8Length, J9UTF8_DATA(romClassName), J9UTF8_LENGTH(romClassName), 1);
Assert_VM_true(0);
}
}
}

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/j9vm.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,5 @@ TraceException=Trc_VM_loadJFRMetadataBlob_blobDir_OOM NoEnv Overhead=1 Level=1 T
TraceException=Trc_VM_loadJFRMetadataBlob_fileLength_too_large NoEnv Overhead=1 Level=1 Template="JFR loadJFRMetadataBlob fileLength(%llx) not less than 2G"
TraceException=Trc_VM_loadJFRMetadataBlob_metaDataBlobFile_OOM NoEnv Overhead=1 Level=1 Template="JFR loadJFRMetadataBlob j9mem_allocate_memory failed for metaDataBlobFile"
TraceException=Trc_VM_loadJFRMetadataBlob_bad_fileDescriptor NoEnv Overhead=1 Level=1 Template="JFR loadJFRMetadataBlob j9file_open returns fileDescriptor(-1)"

TraceException=Trc_VM_Class_Found_Has_Diff_Name Overhead=1 Level=1 Template="Expected class name: %.*s, found class name: %.*s, fromClassTable=%d"