-
Notifications
You must be signed in to change notification settings - Fork 722
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
Account HCR for OpenJDK MethodHandles #11528
Comments
The |
Two questions:
|
Yes.
We inject those fields during runtime. They are not @fengxue-IS for confirmation. |
The JIT treats them as final fields. If they can change, the JIT needs to know about it or detect their change for functional correctness. |
For methods generated for MethodHandle, my understanding is that they're not visible to the user, so user can't and shouldn't redefine them. How can the user get hold of those methods and redefine them? Those methods are critical to MethodHandle implementation, why they are allowed to be redefined? |
I am not familiar with HCR. ++ @gacholio @DanHeidinga @tajila To help address @liqunl's above concerns: #11528 (comment) and #11528 (comment). |
Will methods generated for MHs always be in hidden/anon classes? I cant recall if those are allowed to be redefined, the rules have changed in the past. We currently have a comment indicating that it is not possible
|
It looks like from Java 11+ they are unmodifiable
|
Yes. References:
For JDK8, anon classes will be modifiable. Should we look into making OJDK MH generated classes unmodifiable for JDK8; instead of adding HCR support? |
We should make them unmodifiable if we continue to pass all the required tests. If we are not able to make them unmodifiable, I suggest we do nothing and let the VM crash if someone is foolish enough to attempt this. I suspect no customer will ever report this. |
All OJDK MH/VH generated anon classes should have |
Update: |
In #12306 and #12304,
|
@DanHeidinga |
@EricYangIBM good question. And welcome to having to understand the poorly named "HCR" feature(s) in openj9. We refer to HCR in a very loose way to mean class redefinition but there are two different modes of HCR:
For the For the tldr; this is mostly not a problem for fastHCR but you'll need to validate the cases of specially tagged itable indexes. FSD will need a heap walk if itables are redefined. |
The information that MH store related to a J9Class is
With a closer look at how the data is stored, I am not sure if clearing the invokeCache table would be sufficient as other classes could have MemberName references into the J9Class being redefined. So for HCR, since we can keep the old
@nbhuiyan how would this affect jit code for MethodHandle? does JIT already have check for redefinition and regenerate the compiled code? |
Actually, nvm for the above on keeping pointer address, I checked the code for |
HCR is an ambiguous term. We need to be more specific here as the above is true for fastHCR but wrong for FSD. |
As far as I know we don't have a mechanism in the JIT to check for MH class redefinitions. If |
Thanks for the correction Dan, I didn't think about FSD here. For FSD, I think we also need to update the class object stored in
@DanHeidinga @gacholio In the case that field/method does not exist in new class, should we still allow MemberName to reference the old ID? if not, what value should the vmindex/vmtarget be set to? |
Will using the old ID continue to function is some sensible way? Adding and removing methods is an OpenJ9 extension, so there's no spec for this case. The other option is to put an invalid value like UDATA_MAX in there. The issue then becomes detecting the invalid value at all of the appropriate places. If extended FSD HCR is used, I believe we flush the JIT code cache, so there's no need to put the check in compiled code. |
Does the call to Lines 2058 to 2081 in b2b6f49
|
No, that function fixes the classes of heap objects. |
@gacholio For FSD, what fixes the heap classObjects? I.e. the Class<?> references. |
Assuming you mean what fixes up the java.lang.Class references to the J9Class: |
|
There is only ever one java.lang.Class instance - replacing classes results in multiple J9Class pointing to the single java.lang.Class, and the java object always points back to the current version of the J9Class. |
Disable fixDirectHandles when building for OJDK method handles. Issue: eclipse-openj9#11528 Signed-off-by: Eric Yang <eric.yang@ibm.com>
@EricYangIBM #12799 and #12806 were recently merged to resolve this issue. Can you evaluate if these PRs are sufficient to close this issue? If not, let us know the next steps. |
Yes I believe so. |
Closing issue as per #11528 (comment). |
HCR - Hot Code Replacement
For OpenJDK
MethodHandles
, an instance ofMemberName
stores:MemberName->vmtarget
(J9Method
)MemberName->vmindex
(J9JNIMethodID
)The above
J9Method
andJ9JNIMethodID
references can become outdated due to HCR. They need to be kept updated.#11367 (comment) [Babneet Singh]
Should
VM_VMHelpers::currentClass
get the most current version of class after HCR?Do we also need to update the
J9Method
ref stored inMemberName
for HCR? Related code:J9Methods
stored in OpenJ9 MHs are updated. We probably need to do the same forMemberNames->vmtarget
(J9Method
).MemberNames->vmindex
(J9JNIMethodID
).hshelp.c::fixJNIRefs
andhshelp.c::fixDirectHandles
.#11367 (comment) [Dan Heidinga]
This solves half the problem in that it ensures the most up-to-date version of the class is used in the itable search. Unfortunately, the itableIndex may not point to the same method in the new version of the class if the methods have been reordered.
It's really two pieces of data - class version & itable index - and both need to kept consistent and up to date.
This is carefully set up thru cooperation between the MH creation java code & the redef code to avoid a full heap walk to find the DirectHandles. We may be able to make the same invariants hold for MemberName but I'm less clear on how to do that without patching the OJDK java code.
Couple of options here:
I'd suggest starting with option 1 as it's the easiest to get right and we can figure out how to optimize it later.
The text was updated successfully, but these errors were encountered: