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

SIGSEGV when getting class data via condy from a virtual method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Not an Issue
    • Affects Version/s: 15
    • Fix Version/s: 15
    • Component/s: core-libs

      Description

      If MethodHandles::classData is invoked from <clinit> and store them in static final fields, that works properly.

      But if MethodHandles::classData is called from a virtual method, VM crashes with SIGSEGV.

      # SIGSEGV (0xb) at pc=0x000000010cfc5ea5, pid=10577, tid=26371
      #
      # JRE version: Java(TM) SE Runtime Environment (15.0) (fastdebug build 15-internal+0-adhoc.mlchung.open)
      # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 15-internal+0-adhoc.mlchung.open, mixed mode, sharing, tiered, compressed oops, g1 gc, bsd-amd64)
      # Problematic frame:
      # V [libjvm.dylib+0x7c5ea5] CallInfo::set_common(Klass*, methodHandle const&, methodHandle const&, CallInfo::CallKind, int, Thread*)+0x55
      --------------- T H R E A D ---------------

      Current thread (0x00007fade70f2a20): JavaThread "MainThread" [_thread_in_vm, id=26371, stack(0x0000700010c13000,0x0000700010d13000)]

      Stack: [0x0000700010c13000,0x0000700010d13000], sp=0x0000700010d104c0, free space=1013k
      Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
      V [libjvm.dylib+0x7c5ea5] CallInfo::set_common(Klass*, methodHandle const&, methodHandle const&, CallInfo::CallKind, int, Thread*)+0x55
      V [libjvm.dylib+0x7c60b1] CallInfo::set_virtual(Klass*, methodHandle const&, methodHandle const&, int, Thread*)+0xb7
      V [libjvm.dylib+0x7cab28] LinkResolver::runtime_resolve_virtual_method(CallInfo&, methodHandle const&, Klass*, Handle, Klass*, bool, Thread*)
      +0x2a0
      V [libjvm.dylib+0x7ca607] LinkResolver::resolve_virtual_call(CallInfo&, Handle, Klass*, LinkInfo const&, bool, Thread*)+0x67
      V [libjvm.dylib+0x7cbd23] LinkResolver::resolve_invokevirtual(CallInfo&, Handle, constantPoolHandle const&, int, Thread*)+0x10d
      V [libjvm.dylib+0x5214aa] InterpreterRuntime::resolve_invoke(JavaThread*, Bytecodes::Code)+0x48a
      V [libjvm.dylib+0x521c17] InterpreterRuntime::resolve_from_cache(JavaThread*, Bytecodes::Code)+0x89
      j java.lang.invoke.MemoryAccessVarHandleIntHelper1+0x0000000800bf0840.accessModeTypeUncached(Ljava/lang/invoke/VarHandle$AccessMode;)Ljava/lang/invoke/MethodType;+9 java.base@15-internal
      j java.lang.invoke.VarHandle.accessModeType(Ljava/lang/invoke/VarHandle$AccessMode;)Ljava/lang/invoke/MethodType;+35 java.base@15-internal
      j java.lang.invoke.VarHandle.coordinateTypes()Ljava/util/List;+4 java.base@15-internal
      j java.lang.invoke.VarHandles.filterCoordinates(Ljava/lang/invoke/VarHandle;I[Ljava/lang/invoke/MethodHandle;)Ljava/lang/invoke/VarHandle;+11 java.base@15-internal
      j java.lang.invoke.MethodHandleImpl$1.filterCoordinates(Ljava/lang/invoke/VarHandle;I[Ljava/lang/invoke/MethodHandle;)Ljava/lang/invoke/VarHandle;+3 java.base@15-internal
      j jdk.incubator.foreign.MemoryHandles.filterCoordinates(Ljava/lang/invoke/VarHandle;I[Ljava/lang/invoke/MethodHandle;)Ljava/lang/invoke/VarHandle;+6 jdk.incubator.foreign@15-internal
      j jdk.internal.foreign.Utils.fixUpVarHandle(Ljava/lang/invoke/VarHandle;)Ljava/lang/invoke/VarHandle;+12 jdk.incubator.foreign@15-internal
      j jdk.internal.foreign.LayoutPath.dereferenceHandle(Ljava/lang/Class;)Ljava/lang/invoke/VarHandle;+144 jdk.incubator.foreign@15-internal
      j jdk.incubator.foreign.MemoryLayout.lambda$varHandle$2(Ljava/lang/Class;Ljdk/internal/foreign/LayoutPath;)Ljava/lang/invoke/VarHandle;+2 jdk.incubator.foreign@15-internal
      j jdk.incubator.foreign.MemoryLayout$$Lambda$46+0x0000000800baa5a0.apply(Ljava/lang/Object;)Ljava/lang/Object;+8 jdk.incubator.foreign@15-internal
      j jdk.incubator.foreign.MemoryLayout.computePathOp(Ljdk/internal/foreign/LayoutPath;Ljava/util/function/Function;Ljava/util/Set;[Ljdk/incubator/foreign/MemoryLayout$PathElement;)Ljava/lang/Object;+89 jdk.incubator.foreign@15-internal
      j jdk.incubator.foreign.MemoryLayout.varHandle(Ljava/lang/Class;[Ljdk/incubator/foreign/MemoryLayout$PathElement;)Ljava/lang/invoke/VarHandle;+19 jdk.incubator.foreign@15-internal
      j TestByteBuffer.<clinit>()V+206


      To reproduce, apply this patch to jdk/jdk repo:

      diff --git a/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java b/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java
      --- a/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java
      +++ b/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java
      @@ -287,7 +287,7 @@
               mv.visitFieldInsn(GETFIELD, Type.getInternalName(VarHandle.AccessMode.class), "at", VarHandle.AccessType.class.descriptorString());
               mv.visitLdcInsn(Type.getType(MemoryAddressProxy.class));
               mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Class.class));
      - mv.visitFieldInsn(GETSTATIC, implClassName, "carrier", Class.class.descriptorString());
      + mv.visitMethodInsn(INVOKEVIRTUAL, implClassName, "carrier", "()Ljava/lang/Class;", false);
               mv.visitFieldInsn(GETSTATIC, implClassName, "intermediate", Class[].class.descriptorString());
       
               mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(VarHandle.AccessType.class),
      @@ -403,7 +403,14 @@
           void addCarrierAccessor(ClassWriter cw) {
               MethodVisitor mv = cw.visitMethod(ACC_FINAL, "carrier", "()Ljava/lang/Class;", null, null);
               mv.visitCode();
      - mv.visitFieldInsn(GETSTATIC, implClassName, "carrier", Class.class.descriptorString());
      + MethodType mtype = MethodType.methodType(Object.class, MethodHandles.Lookup.class, String.class, Class.class);
      + Handle bsm = new Handle(H_INVOKESTATIC, Type.getInternalName(MethodHandles.class), "classData",
      + mtype.descriptorString(), false);
      + ConstantDynamic dynamic = new ConstantDynamic("classData", Object[].class.descriptorString(), bsm);
      + mv.visitLdcInsn(dynamic);
      + mv.visitInsn(ICONST_0);
      + mv.visitInsn(AALOAD);
      + mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Class.class));
               mv.visitInsn(ARETURN);
               mv.visitMaxs(0, 0);
               mv.visitEnd();

      VM crashses when running test/jdk/java/foreign/TestByteBuffer.java.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              mchung Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: