Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8303022

"assert(allocates2(pc)) failed: not in CodeBuffer memory" When linking downcall handle

XMLWordPrintable

      When linking the following function (generated by fuzzer):

      EXPORT struct S6 F84(struct S6 (*cb)(void*, short, long long, int, short, struct S5, long long, char, double, char,
                                           float, char, void*, char, struct S6, union U3, double, int, double, char, union U5,
                                           int),
              void* a0, short a1, long long a2, int a3, short a4, struct S5 a5, long long a6, char a7, double a8, char a9,
              float a10, char a11, void* a12, char a13, struct S6 a14, union U3 a15, double a16, int a17, double a18,
              char a19, union U5 a20, int a21){
          return cb(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21);
      }

      (see also attached diff)

      We hit an assert:

      #
      # A fatal error has been detected by the Java Runtime Environment:
      #
      # Internal Error (src/hotspot/share/asm/codeBuffer.hpp:194), pid=19794, tid=19819
      # assert(allocates2(pc)) failed: not in CodeBuffer memory: 0x00007f356843cc80 <= 0x00007f356843d112 <= 0x00007f356843d110
      #
      # JRE version: OpenJDK Runtime Environment (21.0) (fastdebug build 21-internal-adhoc.jorn.foreign-abi)
      # Java VM: OpenJDK 64-Bit Server VM (fastdebug 21-internal-adhoc.jorn.foreign-abi, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
      # Problematic frame:
      # V [libjvm.so+0x770b3b] CodeSection::set_end(unsigned char*)+0x5b
      #
      # Core dump will be written. Default location: core.19794 (may not exist)
      #

      With the following stack track:

      Stack: [0x00007f35510f0000,0x00007f35511f0000], sp=0x00007f35511ebcd8, free space=1007k
      Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
      V [libjvm.so+0x770b3b] CodeSection::set_end(unsigned char*)+0x5b (codeBuffer.hpp:194)
      V [libjvm.so+0x6d7303] Assembler::emit_operand_helper(int, int, int, Address::ScaleFactor, int, RelocationHolder const&, int)+0x4a3 (codeBuffer.hpp:226)
      V [libjvm.so+0x6d8535] Assembler::emit_operand(Register, Register, Register, Address::ScaleFactor, int, RelocationHolder const&, int) [clone .constprop.5]+0x65 (assembler_x86.cpp:713)
      V [libjvm.so+0x767ad2] Assembler::movq(Address, Register)+0x142 (assembler_x86.cpp:1259)
      V [libjvm.so+0x1572889] MacroAssembler::movptr(Address, Register)+0x69 (macroAssembler_x86.cpp:2582)
      V [libjvm.so+0xda0949] RegSpiller::pd_store_reg(MacroAssembler*, int, VMStorage)+0x89 (foreignGlobals_x86_64.cpp:85)
      V [libjvm.so+0xd9da19] RegSpiller::generate(MacroAssembler*, int, bool) const+0x89 (foreignGlobals.cpp:108)
      V [libjvm.so+0xd2c83b] DowncallStubGenerator::generate()+0x18bb (foreignGlobals.hpp:108)
      V [libjvm.so+0xd2cbbf] DowncallLinker::make_downcall_stub(BasicType*, int, BasicType, ABIDescriptor const&, GrowableArray<VMStorage> const&, GrowableArray<VMStorage> const&, bool, int, bool)+0x2cf (downcallLinker_x86_64.cpp:112)
      V [libjvm.so+0x16dedff] NEP_makeDowncallStub+0x7df (nativeEntryPoint.cpp:79)
      j jdk.internal.foreign.abi.NativeEntryPoint.makeDowncallStub(Ljava/lang/invoke/MethodType;Ljdk/internal/foreign/abi/ABIDescriptor;[Ljdk/internal/foreign/abi/VMStorage;[Ljdk/internal/foreign/abi/VMStorage;ZIZ)J+0 java.base@21-internal
      j jdk.internal.foreign.abi.NativeEntryPoint.lambda$make$1(Ljava/lang/invoke/MethodType;Ljdk/internal/foreign/abi/ABIDescriptor;[Ljdk/internal/foreign/abi/VMStorage;[Ljdk/internal/foreign/abi/VMStorage;ZIZLjdk/internal/foreign/abi/NativeEntryPoint$CacheKey;)Ljdk/internal/foreign/abi/NativeEntryPoint;+10 java.base@21-internal
      j jdk.internal.foreign.abi.NativeEntryPoint$$Lambda$101+0x000000080103a310.apply(Ljava/lang/Object;)Ljava/lang/Object;+32 java.base@21-internal
      j jdk.internal.foreign.abi.SoftReferenceCache$Node.get(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;+45 java.base@21-internal
      j jdk.internal.foreign.abi.SoftReferenceCache.get(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;+21 java.base@21-internal
      j jdk.internal.foreign.abi.NativeEntryPoint.make(Ljdk/internal/foreign/abi/ABIDescriptor;[Ljdk/internal/foreign/abi/VMStorage;[Ljdk/internal/foreign/abi/VMStorage;Ljava/lang/invoke/MethodType;ZIZ)Ljdk/internal/foreign/abi/NativeEntryPoint;+79 java.base@21-internal
      j jdk.internal.foreign.abi.DowncallLinker.getBoundMethodHandle()Ljava/lang/invoke/MethodHandle;+75 java.base@21-internal
      j jdk.internal.foreign.abi.x64.sysv.CallArranger.arrangeDowncall(Ljava/lang/invoke/MethodType;Ljava/lang/foreign/FunctionDescriptor;Ljdk/internal/foreign/abi/LinkerOptions;)Ljava/lang/invoke/MethodHandle;+22 java.base@21-internal
      j jdk.internal.foreign.abi.x64.sysv.SysVx64Linker.arrangeDowncall(Ljava/lang/invoke/MethodType;Ljava/lang/foreign/FunctionDescriptor;Ljdk/internal/foreign/abi/LinkerOptions;)Ljava/lang/invoke/MethodHandle;+3 java.base@21-internal
      j jdk.internal.foreign.abi.AbstractLinker.lambda$downcallHandle$0(Ljdk/internal/foreign/abi/AbstractLinker$LinkRequest;)Ljava/lang/invoke/MethodHandle;+19 java.base@21-internal
      j jdk.internal.foreign.abi.AbstractLinker$$Lambda$74+0x0000000801074b60.apply(Ljava/lang/Object;)Ljava/lang/Object;+8 java.base@21-internal
      j jdk.internal.foreign.abi.SoftReferenceCache$Node.get(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;+45 java.base@21-internal
      j jdk.internal.foreign.abi.SoftReferenceCache.get(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;+21 java.base@21-internal
      j jdk.internal.foreign.abi.AbstractLinker.downcallHandle(Ljava/lang/foreign/FunctionDescriptor;[Ljava/lang/foreign/Linker$Option;)Ljava/lang/invoke/MethodHandle;+39 java.base@21-internal
      j java.lang.foreign.Linker.downcallHandle(Ljava/lang/foreign/MemorySegment;Ljava/lang/foreign/FunctionDescriptor;[Ljava/lang/foreign/Linker$Option;)Ljava/lang/invoke/MethodHandle;+7 java.base@21-internal
      j NativeTestHelper.downcallHandle(Ljava/lang/String;Ljava/lang/foreign/FunctionDescriptor;[Ljava/lang/foreign/Linker$Option;)Ljava/lang/invoke/MethodHandle;+9
      j TestPCAssert.testOOB()V+189
      ...

            jvernee Jorn Vernee
            jvernee Jorn Vernee
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: