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

Align mutable fields of x86 PIC data #4604

Merged
merged 4 commits into from
Feb 14, 2019

Conversation

jdmpapin
Copy link
Contributor

@jdmpapin jdmpapin commented Feb 5, 2019

To prevent tearing, this series aligns fields of the x86 VPIC and IPIC data that are written at runtime. The IPIC data is aligned simply by adjusting the start of the snippet. In the VPIC data snippet, the end of the VPIC data is already aligned, so we get the necessary field alignment by reordering the fields. This reordering requires some changes to PicBulider to remove lingering implicit assumptions about data layout. There is an unused and (almost certainly) broken function in PicBuilder which is removed instead of modified. See the individual commit messages for more.

@andrewcraik
Copy link
Contributor

@0dvictor this looks good to me but would appreciate your expert opinion on the x codegen changes.

@0dvictor
Copy link
Contributor

0dvictor commented Feb 6, 2019

The changes look good to me.
Just one comment: I'm not sure if it is beneficial to update deprecated X86PicBuilder.inc and X86PicBuilder.pasm. I believe both file are being deleted soon and large portion of the code is not tested and potentially out-of-date.

@0dvictor
Copy link
Contributor

0dvictor commented Feb 6, 2019

FYI, #4627 removes the X86PicBuilder.inc and X86PicBuilder.pasm.

@jdmpapin
Copy link
Contributor Author

jdmpapin commented Feb 6, 2019

Yeah I knew the deletion was coming. I modified the .inc and .pasm files because they were still in use on 32-bit when I started writing this change. Should I revert them? I've already had to rebase this and re-test once due to a conflict with the removal of an ifdef WINDOWS related to a lock cmpxchg in the deleted function. I guess if #4627 is merged quickly enough there won't even be a choice though

@andrewcraik
Copy link
Contributor

@jdmpapin can you fix the merge conflicts please?

The resolveAndPopulateVTableDispatch function is used only by
TR::X86UnresolvedVirtualCallSnippet, which is never created.
Furthermore, if a TR::X86UnresolvedVirtualCallSnippet were to be
created, this part of PicBuilder wouldn't work properly in its current
state. For instance, it calls jitResolveVirtualMethod passing the same
address twice, once as the JIT return address, and once as the VPIC data
address, even though those addresses should be different.

This commit deletes both resolveAndPopulateVTableDispatch and
TR::X86UnresolvedVirtualCallSnippet to prevent further bit-rot.

Signed-off-by: Devin Papineau <devinmp@ca.ibm.com>
PicBuilder on x86 was modified in bada7c8 to locate fields of the VPIC
data using named constants rather than hard-coded offsets, but there
were a few remaining places where the code continued to rely on implicit
assumptions about the layout. In particular,

- cpAddr was assumed to have offset 0, with pointers to the beginning of
  the VPIC data being treated as pointers to cpAddr; and

- on 32-bit, cmpRegImm4ModRM was assumed to be the last byte.

PicBuilder is updated to avoid relying on these implicit assumptions, in
order to facilitate the rearrangement of the fields of the VPIC data.

Because of jitResolveVirtualMethod(), cpIndex must still always follow
immediately after cpAddr.

Signed-off-by: Devin Papineau <devinmp@ca.ibm.com>
Because directMethod is written at runtime, and might be concurrently
read by another thread, it must be properly aligned to ensure that
accesses to it are atomic. Currently it's possible to observe tearing,
which can lead PicBuilder to attempt direct dispatch with a bogus
J9Method pointer.

The necessary alignment is achieved by reordering the fields of the VPIC
data so that the pointer-sized fields are at the end. The VPIC data
immediately precedes a patchable instruction, which itself is aligned on
an 8-byte boundary, so this rearrangement ensures that all of the
pointer-sized fields (including directMethod) are naturally aligned.

Fixes eclipse-openj9#4446
Signed-off-by: Devin Papineau <devinmp@ca.ibm.com>

Signed-off-by: Devin Papineau <devinmp@ca.ibm.com>
Because the interface class and itable offset can be written at runtime,
and might be read concurrently by another thread, they need to be
aligned so that the accesses will be atomic. Currently it's possible to
observe tearing, which can lead PicBuilder to attempt direct dispatch
with a bogus J9Method pointer. Such tearing might also interfere with
standard interface dispatch.

The start of the snippet is now adjusted to effect the alignment.

Fixes eclipse-openj9#4446
Signed-off-by: Devin Papineau <devinmp@ca.ibm.com>
@jdmpapin
Copy link
Contributor Author

jdmpapin commented Feb 8, 2019

Updated to leave the (now deleted) old asm files unmodified

@andrewcraik
Copy link
Contributor

@0dvictor are you good with this now?

@0dvictor
Copy link
Contributor

LGTM.

@andrewcraik
Copy link
Contributor

Jenkins test sanity xlinux,win jdk8,jdk11

@jdmpapin
Copy link
Contributor Author

Is this good to go now?

@andrewcraik andrewcraik merged commit b1cb17c into eclipse-openj9:master Feb 14, 2019
@jdmpapin jdmpapin deleted the pic-data-alignment branch April 9, 2021 21:59
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.

5 participants