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

Change J9Module::moduleName from a j9object_t to a J9UTF8 pointer #20740

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

ThanHenderson
Copy link
Contributor

@ThanHenderson ThanHenderson commented Dec 3, 2024

Signed-off-by: Nathan Henderson [email protected]

@ThanHenderson
Copy link
Contributor Author

Part of addressing: #20612

@babsingh could you review?

We may need to test across multiple GC policies.

J9UTF8 *moduleName = module->moduleName;
U_8 *nameData = J9UTF8_DATA(moduleName);
UDATA nameLength = J9UTF8_LENGTH(moduleName);
nameBuffer = (char *)j9mem_allocate_memory(nameLength + 1, OMRMEM_CATEGORY_VM);
Copy link
Contributor

Choose a reason for hiding this comment

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

malloc's failure case needs to be addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed this. Thanks.

Copy link
Contributor

@babsingh babsingh Dec 4, 2024

Choose a reason for hiding this comment

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

Maybe we can introduce copyJ9UTF8ToUTF8WithMemAlloc, similar to copyStringToUTF8WithMemAlloc, which could be used in most places?

Copy link
Contributor Author

@ThanHenderson ThanHenderson Dec 4, 2024

Choose a reason for hiding this comment

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

The problem is that when we add the rest of the support for snapshotting modules, we need to allcocate the moduleName J9UTF8s with the snapshot sub-allocator.

The API could just take a function pointer to the allocator to get around that, or we could have a snapshot specific function for when snapshots are enabled.

Note: my above description doesn't apply to where this comment is, but to other paths in this patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

The API could just take a function pointer to the allocator to get around that

This one seems better (less code). Instead of a function pointer, we can also use a boolean to toggle between the allocators.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can also use a boolean to toggle between the allocators

To keep it general/reusable beyond snapshotting, I think it is better to have the allocator as a parameter rather than a boolean to switch between the two.

But here, I will use the functions that we already have, and add a copyJ9UTF8ToUTF8WithMemAlloc function as if we were ignorant of the future module snapshotting support. Then in the PR that adds modules to the snapshots, I will add a variant that takes an allocator pointer and use that anywhere we need.

runtime/vm/classsupport.c Outdated Show resolved Hide resolved
runtime/verbose/verbose.c Outdated Show resolved Hide resolved
@babsingh
Copy link
Contributor

babsingh commented Dec 4, 2024

@dmitripivkine Please review the GC code.

runtime/j9vm/java11vmi.c Outdated Show resolved Hide resolved
runtime/j9vm/java11vmi.c Outdated Show resolved Hide resolved
Copy link
Contributor

@dmitripivkine dmitripivkine left a comment

Choose a reason for hiding this comment

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

GC part of the change looks good to me

runtime/util/cphelp.c Outdated Show resolved Hide resolved
runtime/vm/stringhelpers.cpp Outdated Show resolved Hide resolved
runtime/jcl/common/jclexception.cpp Outdated Show resolved Hide resolved
@ThanHenderson
Copy link
Contributor Author

I've addressed the comments.

Comment on lines 345 to 357
public static String getModuleName(J9ModulePointer modulePtr) throws CorruptDataException {
String moduleName = null;
if (modulePtr != null) {
Object mn = modulePtr.moduleName();
if (mn instanceof J9ObjectPointer) {
moduleName = J9ObjectHelper.stringValue((J9ObjectPointer)mn);
} else if (mn instanceof J9UTF8Pointer) {
moduleName = J9UTF8Helper.stringValue((J9UTF8Pointer)mn);
} else {
throw new CorruptDataException("Invalid module name data type encountered: " + mn.toString());
}
}
return moduleName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Tabs will need to be used here. We should perform a brief sanity check using jdmpview + core file to confirm that this helper is functioning correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is something wrong with my auto indent functionality between vim/VSCode; really need to nail that down. Thanks for catching that. I'll test it too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function won't work on older core files because J9ModulePointer::moduleName() is generated for the build of jdmpview based on they moduleName type in the JDK build. i.e. the signature is (and from now on will be):

@com.ibm.j9ddr.GeneratedFieldAccessor(offsetFieldName="_moduleNameOffset_", declaredType="J9UTF8*")
public J9UTF8Pointer moduleName() throws CorruptDataException {...}

Using an older core file doesn't change the fact that this function returns a J9UTF8Pointer.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the contrary, the blob in an old core records the fact that moduleName was J9Object*.

$ omr_blob_reader jdk-21/lib/default/j9ddr.dat
...
Struct name: J9Module
 no superName
 sizeOf: 64
 fieldCount: 9
 constCount: 0
 Field declaredName: moduleName
  declaredType: struct J9Object*
  offset: 0

Also, the indentation is a mix of tabs and spaces; here, the indentation should be exclusively tabs.

Copy link
Contributor

@keithc-ca keithc-ca Dec 9, 2024

Choose a reason for hiding this comment

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

I'm not sure there is precedent for changing the type of a field used in DDR code. We may need to use a new name for the J9UTF8 flavour. Of course, that means that neither can be a "required" field in the sense used in AuxFieldInfo29.dat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the contrary, the blob in an old core records the fact that moduleName was J9Object*

I understand that this is the case. My point was that using a newer jdmpview with the changed type to examine an older core, results in the J9ModulePointer::moduleName() to cause a:

java.lang.NoSuchMethodError: com/ibm/j9ddr/vm29/pointer/generated/J9ModulePointer.moduleName()Lcom/ibm/j9ddr/vm29/pointer/generated/J9UTF8Pointer; (loaded from <Unknown> by J9DDRClassloader for com.ibm.j9ddr.vm29.) called from class com.ibm.j9ddr.vm29.tools.ddrinteractive.ModularityHelper (loaded from <Unknown> by J9DDRClassloader for com.ibm.j9ddr.vm29.).

because of this difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the signature of the reference is baked into ModularityHelper.class.

runtime/vm/lookupmethod.c Outdated Show resolved Hide resolved
runtime/vm/stringhelpers.cpp Show resolved Hide resolved
runtime/vm/stringhelpers.cpp Outdated Show resolved Hide resolved
runtime/vm/stringhelpers.cpp Show resolved Hide resolved
vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0);
J9UTF8 *moduleName = fromModule->moduleName;
if (NULL != moduleName) {
Trc_MODULE_createPackage(currentThread, package, (const char *)J9UTF8_DATA(moduleName), fromModule);
Copy link
Contributor

Choose a reason for hiding this comment

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

J9UTF8 data isn't necessarily null-terminated: this may need to specify the length. This issues is present multiple places.

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 figured these could be skirted since we enforce null-termination of the moduleName J9UTF8 on J9Module creation.

runtime/j9vm/java11vmi.c Outdated Show resolved Hide resolved
runtime/vm/ModularityHashTables.c Outdated Show resolved Hide resolved
runtime/vm/ModularityHashTables.c Outdated Show resolved Hide resolved
runtime/vm/classsupport.c Outdated Show resolved Hide resolved
runtime/vm/stringhelpers.cpp Show resolved Hide resolved
@ThanHenderson ThanHenderson force-pushed the j9utf8modulename branch 3 times, most recently from 04d5610 to e22d2d6 Compare December 10, 2024 16:41
runtime/oti/j9consts.h Show resolved Hide resolved
runtime/oti/j9nonbuilder.h Outdated Show resolved Hide resolved
@keithc-ca
Copy link
Contributor

Jenkins test sanity alinux jdk21

@keithc-ca
Copy link
Contributor

Also tested locally with new system dump and one from 0.48.0.

@keithc-ca keithc-ca merged commit 771463d into eclipse-openj9:master Dec 11, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants