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

Check the InnerClass attribute of the enclosing class #13199

Conversation

ChengJin01
Copy link

The change is to check to see whether an valid entry for
the specified class exists in the InnerClass attribute
of its enclosing class given the InnerClass attribute
of both the inner class and its enclosing class must
remain consistent with each other.

Fixes: #12992

Signed-off-by: Cheng Jin jincheng@ca.ibm.com

@ChengJin01
Copy link
Author

The changes were verified in internal builds & open sourced builds

Reviewer: @pshipton
FYI: @gacholio, @tajila

@ChengJin01 ChengJin01 force-pushed the vm_icce_getdeclaringclass_check_innerclass_v3 branch from f734795 to 9a9c2fe Compare July 15, 2021 00:52
@pshipton
Copy link
Member

Adding new fields to ROMClass is the only way to make this work? Can you pls describe what other solutions were tried that didn't add new fields, and why they didn't work.

If we do go with this, it's going to break shared cache compatibility so the shared cache generation number needs to be updated as part of this change.

@ChengJin01
Copy link
Author

ChengJin01 commented Jul 28, 2021

Adding new fields to ROMClass is the only way to make this work? Can you pls describe what other solutions were tried that didn't add new fields, and why they didn't work.

  1. The first option I used to try without modifying ROMClass (e.g. at ChengJin01@26b6cd0) was to simply add the remaining inner class entries of the class file to the existing innerClasses of J9ROMClass, in which case
    [1] all native code with declared class at /runtime/jcl/common/java_lang_Class.cpp must be updated to exclude these newly added items in innerClasses (which is infeasible in that a class with a NULL outer class name doesn't mean it is an inner class of a specified enclosing class). In addition, any code specific to declared classes must be updated accordingly.
    [2] the outer class info in the entries are removed during the class transformation in ClassFileWriter::writeAttributes() at /runtime/bcutil/ClassFileWriter.cpp, which inevitably causes problem (no way to differentiate them from other entries) in building ROM class from the transformed class.

  2. Another option I tried at ChengJin01@8817c04 was to count the entries separately (still need to add a new field skippedInnerClassCount) but still ended up with pretty much the same issues (and even more failures) as the first option above.

The fundamental reason for these options is that it is difficult to correctly identify these remaining inner class entries in building ROMClass in any case (e.g. after the class transformation)

So the only safe way to avoid changing the existing code to handle these tricky situations is adding the remaining entries separately to a new field in ROMClass, in which case it won't affect any existing implementation even though there is any update related to the inner class entries in the future.

the shared cache generation number needs to be updated as part of this change.

I just updated the number at runtime/shared_common/OSCache.hpp in our case.

@ChengJin01 ChengJin01 force-pushed the vm_icce_getdeclaringclass_check_innerclass_v3 branch 3 times, most recently from 47b46a0 to 534655b Compare July 28, 2021 20:48
@hangshao0
Copy link
Contributor

If the cache generation is updated, it needs to be documented in release notes.

@DanHeidinga
Copy link
Member

DanHeidinga commented Jul 29, 2021

@ChengJin01 with this change, are we still removing parts of the InnerClass attribute when writing the romClass? My reading of the code is we've just spread them into a different format - innerClasses & enclosedInnerClasses. Is that correct?

An easy check on this would be if the innerClassCount + enclosedInnerClassCount == InnerClasses_attribute.number_of_classes

@ChengJin01
Copy link
Author

ChengJin01 commented Jul 29, 2021

Hi @DanHeidinga,

are we still removing parts of the InnerClass attribute when writing the romClass?

Yes. There is no big difference in dealing with enclosedInnerClasses as compared to the existing code in handling innerClasses given the only thing we care is the inner class itself.

My reading of the code is we've just spread them into a different format - innerClasses & enclosedInnerClasses. Is that correct?

Correct. We avoid changing the existing implementation on declared classes by splitting InnerClass into two places, which is easy for us to check whether the requested class is the inner class of the enclosing class as long as it exists in enclosedInnerClasses.

An easy check on this would be if the innerClassCount + enclosedInnerClassCount == InnerClasses_attribute.number_of_classes

Strictly speaking, all the remaining entries (except the entries that the current class itself is the inner class which are already excluded in the existing code) of the InnerClass attribute are added to enclosedInnerClasses, which guarantees that the check on the relationship between the inner classes and its enclosing class covers any case for inner class. Thus, enclosedInnerClassCount is undoubtedly the result of (InnerClasses_attribute.number_of_classes - innerClassCount) for the enclosing class.

@gacholio
Copy link
Contributor

I am going on vacation for a week, so I will not get to this (especially as the approach is still under active discussion).

@ChengJin01
Copy link
Author

ChengJin01 commented Aug 19, 2021

Hi @DanHeidinga and @pshipton, any other concern on this PR?

jcl/src/java.base/share/classes/java/lang/Class.java Outdated Show resolved Hide resolved
jcl/src/java.base/share/classes/java/lang/Class.java Outdated Show resolved Hide resolved
runtime/bcutil/ClassFileOracle.cpp Outdated Show resolved Hide resolved
runtime/jcl/common/java_lang_Class.cpp Outdated Show resolved Hide resolved
@ChengJin01 ChengJin01 force-pushed the vm_icce_getdeclaringclass_check_innerclass_v3 branch from 534655b to 05bf39b Compare November 19, 2021 01:08
@pshipton
Copy link
Member

jenkins test sanity win jdk8

@pshipton
Copy link
Member

@DanHeidinga @gacholio @tajila any concerns before this is merged?

Copy link
Contributor

@gacholio gacholio left a comment

Choose a reason for hiding this comment

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

Some minor formatting complaints.

The change is to check to see whether an valid entry for
the specified class exists in the InnerClass attribute
of its enclosing class given the InnerClass attribute
of both the inner class and its enclosing class must
remain consistent with each other.

Fixes: eclipse-openj9#12992

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
@ChengJin01 ChengJin01 force-pushed the vm_icce_getdeclaringclass_check_innerclass_v3 branch from 05bf39b to 12257af Compare November 19, 2021 16:45
@gacholio
Copy link
Contributor

jenkins test sanity win jdk8

@pshipton pshipton merged commit b16777a into eclipse-openj9:master Nov 19, 2021
@hangshao0
Copy link
Contributor

I see the cache generation is incremented by this PR. Just a reminder that this should be documented in the release notes. (Doc change last time on this was eclipse-openj9/openj9-docs#347)

ChengJin01 pushed a commit to ChengJin01/openj9-docs that referenced this pull request Nov 23, 2021
ChengJin01 pushed a commit to ChengJin01/openj9-docs that referenced this pull request Nov 23, 2021
ChengJin01 pushed a commit to ChengJin01/openj9-docs that referenced this pull request Nov 23, 2021
ChengJin01 pushed a commit to ChengJin01/openj9-docs that referenced this pull request Nov 23, 2021
ChengJin01 pushed a commit to ChengJin01/openj9-docs that referenced this pull request Nov 23, 2021
ChengJin01 pushed a commit to ChengJin01/openj9-docs that referenced this pull request Nov 23, 2021
@ChengJin01 ChengJin01 deleted the vm_icce_getdeclaringclass_check_innerclass_v3 branch March 17, 2022 16:51
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.

Hotspot threw IncompatibleClassChangeError, while J9 executed normally
6 participants