Skip to content

Check for duplicate class definitions when creating rom class - #15322

Merged
tajila merged 1 commit into
eclipse-openj9:masterfrom
dnakamura:linkage_error
Jun 24, 2022
Merged

Check for duplicate class definitions when creating rom class#15322
tajila merged 1 commit into
eclipse-openj9:masterfrom
dnakamura:linkage_error

Conversation

@dnakamura

Copy link
Copy Markdown

Fixes #15166

Signed-off-by: Devin Nakamura devinn@ca.ibm.com

@dnakamura

Copy link
Copy Markdown
Author

@gacholio can you take a look at this? I'm not sure if putting the check in during rom class creation causes us any issues anywhere else, but it seemed the best place to bail out as early as possible.

@tajila
tajila requested a review from gacholio June 14, 2022 20:13
@gacholio

Copy link
Copy Markdown
Contributor

At a glance, I dislike this being in the ROM code since it's calling out to hashClassTableAt. The new code also only comes into play if no name is provided from defineClass - is the case already handled when the name is provided?

Comment thread runtime/bcutil/ROMClassCreationContext.hpp Outdated
@dnakamura

Copy link
Copy Markdown
Author

At a glance, I dislike this being in the ROM code since it's calling out to hashClassTableAt. The new code also only comes into play if no name is provided from defineClass - is the case already handled when the name is provided?

I am also not crazy about putting this in the rom code, however the other option is to do the check after the rom class is created, but that means wasting time creating a rom class which is just going to be thrown away.

In the case where a name is provided the check is performed early in the jcl before attempting to load the class (

vmFuncs->setCurrentExceptionNLSWithArgs(currentThread, J9NLS_JCL_DUPLICATE_CLASS_DEFINITION, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, utf8Length, utf8Name);
)

@gacholio

Copy link
Copy Markdown
Contributor

Although I would consider this to be an error situation that really shouldn't come up in production, we've seen some pretty bad java code in the past, so avoiding creating ROM classes that never go away is probably a good idea (ROM classes are never discarded until the loader is unloaded).

Comment thread runtime/bcutil/ROMClassCreationContext.hpp Outdated
@gacholio

Copy link
Copy Markdown
Contributor

@tajila Are you OK with this (the change is appealingly simple where it is). The NULL check on the javaVM should allow cfdump to continue working.

@gacholio

Copy link
Copy Markdown
Contributor

While you're here, the formatting here is off:

https://github.com/eclipse-openj9/openj9/blob/master/runtime/jcl/common/jcldefine.c#L136-L137

In the case where a name is not specified, this code appears to call the hash code with NULLs which should crash (nothing to do with your change):

if (NULL != vmFuncs->hashClassTableAt(classLoader, utf8Name, utf8Length)) {

@tajila tajila left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need to do something like this to avoid throwing the linkage error after creating the ROM class in cases where no name is passed in. I can't see any alternative that doesn't involve some kind of class file parsing.

Comment thread runtime/bcutil/BuildResult.hpp Outdated
Comment thread runtime/bcutil/defineclass.c Outdated
Comment thread runtime/bcutil/defineclass.c Outdated
@dnakamura

Copy link
Copy Markdown
Author

PR updated

Comment thread runtime/jcl/common/jcldefine.c Outdated
Comment thread runtime/cfdumper/stubs.c Outdated
Fixes eclipse-openj9#15166

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>
@dnakamura

Copy link
Copy Markdown
Author

fixed

@gacholio

Copy link
Copy Markdown
Contributor

jenkins test sanity zlinux jdk11

@gacholio

gacholio commented Jun 23, 2022

Copy link
Copy Markdown
Contributor

I think we need to do something like this to avoid throwing the linkage error after creating the ROM class in cases where no name is passed in. I can't see any alternative that doesn't involve some kind of class file parsing.

@tajila Are you still concerned about anything? If not, I'll merge after testing completes.

@tajila

tajila commented Jun 23, 2022

Copy link
Copy Markdown
Contributor

@tajila Are you still concerned about anything? If not, I'll merge after testing completes.

LGTM

@tajila
tajila merged commit da77f9f into eclipse-openj9:master Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

J9 seems to be missing some reports when facing definclass

4 participants