Skip to content

8359386: Fix incorrect value for max_size of C2CodeStub when APX is used #25787

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

Closed
wants to merge 3 commits into from

Conversation

vamsi-parasa
Copy link
Contributor

@vamsi-parasa vamsi-parasa commented Jun 12, 2025

The goal of this PR is to fix the value of max_size of the C2CodeStub hardcoded in the C2_MacroAssembler::convertF2I() function when Intel APX instrucitons are used. Currently, max_size is hardcoded to 23 (introduced in JDK-8306706) . However, this value is incorrect when Intel APX instructions with extended general-purpose registers (EGPRs) are used in the code stub as using EGPRs with APX instructions leads to an increase in the instruction encoding size by additional 1 byte.

Without this fix, we see the following error for the C2 compiler tests below:

compiler/vectorization/runner/ArrayTypeConvertTest.java
compiler/intrinsics/zip/TestFpRegsABI.java
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (/src/hotspot/share/opto/c2_CodeStubs.cpp:50), pid=3961123, tid=3961332
# assert(max_size >= actual_size) failed: Expected stub size (23) must be larger than or equal to actual stub size (24)
#
# JRE version: OpenJDK Runtime Environment (26.0) (fastdebug build 26-internal-adhoc.parasa.jdkdemotion)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 26-internal-adhoc.parasa.jdkdemotion, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V [libjvm.so+0x955a77] C2CodeStubList::emit(C2_MacroAssembler&)+0x227
#

This PR fixes the errors in the above-mentioned tests.

Currently, the ConvertF2I macro works as follows:

vcvttss2si %xmm1,%eax
    cmp    $0x80000000,%eax
    je     STUB
CONTINUE:

STUB:
    sub    $0x8,%rsp
    vmovss %xmm1,(%rsp)
    call   Stub::f2i_fixup              ;   {runtime_call StubRoutines (initial stubs)}
    pop    %rax
    jmp    CONTINUE

The maximum size (max_size) of the stub is precomputed as 23. However, as seen in the convertF2I_slowpath implementation (below), the usage of pop(dst) instruction increases the instruction encoding size by 1 byte if dst is an extended general-purpose register (R16-R31) .

For example, pop (r15) is encoded as 41 5f, whereas pop(r21) is encoded as d5 10 5d.

static void convertF2I_slowpath(C2_MacroAssembler& masm, C2GeneralStub<Register, XMMRegister, address>& stub) {
#define __ masm.
  Register dst = stub.data<0>();
  XMMRegister src = stub.data<1>();
  address target = stub.data<2>();
  __ bind(stub.entry());
  __ subptr(rsp, 8);
  __ movdbl(Address(rsp), src);
  __ call(RuntimeAddress(target));
  __ pop(dst); // <-------- APX REX2 encoding for pop(dst) increases the stub size by 1 byte.
  __ jmp(stub.continuation());
#undef __
}

This PR fixes the issue with max_size hardcoding by adding 1 byte to the max_size when APX is used.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8359386: Fix incorrect value for max_size of C2CodeStub when APX is used (Bug - P3)(⚠️ The fixVersion in this issue is [25] but the fixVersion in .jcheck/conf is 26, a new backport will be created when this pr is integrated.)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25787/head:pull/25787
$ git checkout pull/25787

Update a local copy of the PR:
$ git checkout pull/25787
$ git pull https://git.openjdk.org/jdk.git pull/25787/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25787

View PR using the GUI difftool:
$ git pr show -t 25787

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25787.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 12, 2025

👋 Welcome back sparasa! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 12, 2025

@vamsi-parasa This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8359386: Fix incorrect value for max_size of C2CodeStub when APX is used

Reviewed-by: thartmann, shade, jbhateja, sviswanathan

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 70 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@sviswa7, @TobiHartmann, @shipilev, @jatin-bhateja) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 12, 2025
@openjdk
Copy link

openjdk bot commented Jun 12, 2025

@vamsi-parasa The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Jun 12, 2025

Webrevs

Copy link

@sviswa7 sviswa7 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 12, 2025
@@ -4687,7 +4687,9 @@ void C2_MacroAssembler::convertF2I(BasicType dst_bt, BasicType src_bt, Register
}
}

auto stub = C2CodeStub::make<Register, XMMRegister, address>(dst, src, slowpath_target, 23, convertF2I_slowpath);
// Using the APX extended general purpose registers increases the instruction encoding size by 4 bytes.
int max_size = dst->encoding() <= 15 ? 23 : 27;
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to write it in a more explicit way then?

int max_size = 23 + (UseAPX ? 4 : 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion! Please see suggested change incorporated in the updated code.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 16, 2025
@vamsi-parasa
Copy link
Contributor Author

vamsi-parasa commented Jun 17, 2025

Please see the updated version which fixes the error in the initial PR. While it's true that the size of the convert with truncation and the compare instruction increases by 4 bytes in the main common path, it does not contribute to the increase in the stub size. As explained in the updated PR description, the increase in size by 1 byte is being caused by pop(dst) instruction in the stub.

@vamsi-parasa
Copy link
Contributor Author

Hello Jatin (@jatin-bhateja),

Please see the updated PR description which fixed the error in the initial PR.

Thanks,
Vamsi

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 18, 2025
Copy link
Member

@jatin-bhateja jatin-bhateja left a comment

Choose a reason for hiding this comment

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

My testing passed.

LGTM

@vamsi-parasa
Copy link
Contributor Author

Thank you Tobias (@TobiHartmann), Aleksey (@shipilev) and Jatin (@jatin-bhateja) for approving the changes!

@vamsi-parasa
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 18, 2025
@openjdk
Copy link

openjdk bot commented Jun 18, 2025

@vamsi-parasa
Your change (at version 4fe56be) is now ready to be sponsored by a Committer.

@sviswa7
Copy link

sviswa7 commented Jun 18, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 18, 2025

Going to push as commit b52af18.
Since your change was applied there have been 72 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 18, 2025
@openjdk openjdk bot closed this Jun 18, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 18, 2025
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Jun 18, 2025
@openjdk
Copy link

openjdk bot commented Jun 18, 2025

@sviswa7 @vamsi-parasa Pushed as commit b52af18.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants