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

Srinivas Vamsi Parasa sparasa at openjdk.org
Wed Jun 18 18:32:36 UTC 2025


On Thu, 12 Jun 2025 19:41:01 GMT, Srinivas Vamsi Parasa <sparasa at openjdk.org> wrote:

> 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](https://bugs.openjdk.org/browse/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 ...

This pull request has now been integrated.

Changeset: b52af182
Author:    Srinivas Vamsi Parasa <sparasa at openjdk.org>
Committer: Sandhya Viswanathan <sviswanathan at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/b52af182c43380186decd7e35625e42c7cafb8c2
Stats:     4 lines in 1 file changed: 3 ins; 0 del; 1 mod

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

Reviewed-by: thartmann, shade, jbhateja, sviswanathan

-------------

PR: https://git.openjdk.org/jdk/pull/25787


More information about the hotspot-compiler-dev mailing list