Repository navigation
Fix handling of interface methods in JIT linkToVirtual() - #13578
Conversation
f52699d to
ec77938
Compare
|
Pushed a small update to the commit messages, rephrasing from "iTable offset" to "iTable index," since a |
|
Jenkins test sanity,extended all jdk17 depends eclipse-omr/omr#6186 Pre-emptively launching tests before review is finished. |
|
Windows CI failure may be #10732. |
ec77938 to
028e263
Compare
|
Pushed an update to split the helper into two. I didn't bother to factor out common logic because the call to |
|
Converted to draft while I re-test |
The result is the value of J9JNIMethodID::vTableIndex, which is UDATA. The high bit of this value is a flag that distinguishes VFT offsets from iTable indices. The previous return type (int32_t) required this value to be truncated on 64-bit platforms, losing the value of the flag, leaving callers with no way to distinguish the cases.
vTableOrITableIndexFromMemberName() returns either a VFT offset or an iTable index tagged with J9_JNI_MID_INTERFACE. In the latter case, treating it as a VFT offset and generating a virtual call is incorrect. We could determine the interface callee and replace linkToVirtual() with an interface call, but interface call sites currently require a CP index in order to find call targets. Additionally, vTableOrITableIndexFromMemberName() can return zero to indicate that the method should be dispached directly. This case is now handled properly by setting isIndirectCall to false, which results in the creation of a direct call site. Previously we would get a virtual call site, which would find the correct (nonoverridden) target method, but that method would not be inlined with the correct guard (in particular, an HCR guard in HCR mode, which is the default).
vTableOrITableIndexFromMemberName() returns either a VFT offset or an iTable index tagged with J9_JNI_MID_INTERFACE. In the latter case, treating it as a VFT offset and generating a virtual call is incorrect. In case an attempt to do so results in a positive JIT VFT offset and consequently a direct call, that is also incorrect. We could determine the interface callee and replace linkToVirtual() with an interface call, but interface call nodes must currently be unresolved. Code generation requires a CP index in the dispatch.
...created by recognized call transformer for linkToVirtual().
These subtrees were previously of the following form:
calli com/ibm/jit/JITHelpers.dispatchVirtual(JJLjava/lang/Object;...)
lloadi <generic int shadow>
l2a (**)
lsub (**)
aloadi <vft-symbol>
aload receiverTemp
n1n lsub (*)
lload vftOffsetTemp (**)
lconst 376 (*)
lmul (**)
n1n ==>lsub (*)
lconst -1 (*)
...args
There are a few problems with the above trees:
- They do integer subtraction on an address when they should instead use
an address offset operation
- Nodes marked (**) vary in type according to bitness, but nodes marked
(*) are always 64-bit, which would result in ill-typed trees on 32-bit
- Tree simplification rewrites (mul (sub a (const k)) (const -1)) into
(sub (mul a (const -1)) (const -k)), which causes the compiler to
generate two separate subtractions
These subtrees are changed to use aladd or aiadd, perform the
subtraction labelled n1n in the opposite direction (since both uses
now actually need the negative of the old result), and to use
pointer-sized integers throughout:
calli com/ibm/jit/JITHelpers.dispatchVirtual(JJLjava/lang/Object;...)
lloadi <generic int shadow>
aladd (**)
aloadi <vft-symbol>
aload receiverTemp
n1n lsub (**)
lconst 376 (**)
lload vftOffsetTemp (**)
n1n ==>lsub (**)
...args
These subtrees are well-typed on 64-bit, and they allow the commoning to
survive all the way to code generation. They should also be well-typed
on 32-bit, but this has not yet been tested because only Java 8 still
supports 32-bit builds, but Java 8 doesn't have support yet for OpenJDK
method handles.
Additionally, within recognized method transformer's linkToVirtual()
transformation, a few variables are renamed for clarity:
- mhSymRef -> receiverSymRef
- xcmpne -> ifxcmpne
- vtableOffset -> jitVFTOffset (negated)
- jittedMethodAddressNode -> jitVFTSlotPtr
- jittedMethodAddressLoadNode -> jittedMethodEntryPoint
028e263 to
86db6e5
Compare
|
Rebased to bring the branch up to date |
|
Jenkins test sanity,extended all jdk17 depends eclipse-omr/omr#6186 |
|
@gacholio, would you mind reviewing the new helpers again? (noting #13578 (comment)) |
There was a problem hiding this comment.
Odd spacing and lack of brackets. Suggest:
UDATA iTableOffset = sizeof(struct J9ITable) + (iTableIndex * sizeof(UDATA));
gacholio
left a comment
There was a problem hiding this comment.
Looks good (one trivial formatting change).
|
@0xdaryl, the test failures appear to be just "java.lang.OutOfMemoryError: Java heap space", which I doubt is related to my changes. What do you think? I'll push the formatting change once you've had a chance to take a look |
|
I tend to agree. However, it is suspicious that similar jobs on different builds (Mac vs Linux) fail in a similar manner. Can you make the formatting change and push it? I'll re-run just these two failing jobs and make a determination from that. All other testing passed successfully. |
|
The OOM failures may be related to #13584. |
...as transformed by recognized call transformer. Previously, the generated code would ignore the J9_JNI_MID_INTERFACE flag and treat a tagged iTable index instead as a VFT offset, resulting in a segfault. The generated code will now detect this flag and, if it is set, call a new VM helper jitLookupDynamicInterfaceMethod() to find the VFT offset.
This behaves in the same way as jitLookupDynamicInterfaceMethod(), except that it checks to see whether the selected callee is public, throwing IllegalAccessError if not. This should make it straightforward to transform linkToInterface() in recognized call transformer in almost exactly the same way as we currently do for linkToVirtual().
I agree. This failure is specific to the head stream. If there is a concern, a PR can be created against 0.29 and PR tested against this branch, but I don't think it's necessary. |
86db6e5 to
61fd734
Compare
|
Updated the formatting of the |
|
Given @pshipton's remarks above I won't re-run full CI testing for a simple formatting change. |
|
Dependent upstream PR has merged. |
|
OK, I'm just waiting for my own builds to complete before I take this back out of draft status. (They were supposed to run after I rebased last night, but they didn't and I had to launch new ones this morning) I'm not expecting the code here to change much (or at all, really) as a result of those builds though, so if any more review is needed in the meantime, I don't think it has to wait |
|
I am satisfied with the changes. Just un-draft it when you're comfortable with your testing. |
|
Previous CI testing was successful prior to the last push of a simple formatting change. Merging. |
|
This change causes a build break with AArch64 Linux. -- Correction: Not only on AArch64 Linux. |
|
The build break seems to be caused by Helpers.inc in the OMR project. |
|
Ah, that would do it |
|
I'm going to revert this temporarily until we get OMR promoted. Artifactory is down atm, not sure when we'll have the OMR promotion build running again. |
|
Merged again via #13716 |
uintptr_tfromvTableOrITableIndexFromMemberName()linkToVirtualto interface method inInterpreterEmulatorlinkToVirtualto interface method in MH transformerdispatchVitual()VFT slot-related subtreeslinkToVirtual()Please see the individual commits for more detail
This requires eclipse-omr/omr#6186
Fixes #13472