oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
19.99k stars 1.6k forks source link

In my JNI library call a function in another share libray built by native-image, message : Segmentation fault #9216

Open chyohn opened 6 days ago

chyohn commented 6 days ago

Describe the issue

Hi, as the title I want to call a share function in my JNI, all code build by native-image. it's crashed when invoke at the line of call the shared function, message as below.

[ [ SegfaultHandler caught a segfault in thread 0x00000253050ec940 ] ]
siginfo: ExceptionCode: -1073741819, reading address 0x0000025c4d592e58 (heapBase + 39863791192)
General purpose register values:
  RAX 0x00000000290225cb is an unknown value
  RBX 0x000000000003ef65 is an unknown value
  RCX 0x0000007a1a4fef10 points into the stack for thread 0x00000253050ec940
  RDX 0x0000025b057631c8 is an unknown value
  RBP 0x0000000000000000
  RSI 0x000000000000000b is an unknown value
  RDI 0x000000000000000b is an unknown value
  RSP 0x0000007a1a4fec00 points into the stack for thread 0x00000253050ec940
  R8  0x0000025b055f3958 is an unknown value
  R9  0x0000000000000000
  R10 0x0000000000000000
  R11 0x000000000000000b is an unknown value
  R12 0x0000000000000000
  R13 0x0000000000000000
  R14 0x0000025b05480000 is an unknown value
  R15 0x00000253050fbc40 is an unknown value
  EFL 0x0000000000010202 is an unknown value
  RIP 0x00007ff87db7c73a is an unknown value

Printing instructions (ip=0x00007ff87db7c73a):
  0x00007ff87db7c63a: 0x24 0x38 0x02 0x00 0x00 0x4c 0x89 0xa4 0x24 0x40 0x02 0x00 0x00 0x4c 0x89 0x9c
  0x00007ff87db7c64a: 0x24 0x48 0x02 0x00 0x00 0x4c 0x89 0x94 0x24 0x50 0x02 0x00 0x00 0x4c 0x89 0x8c
  0x00007ff87db7c65a: 0x24 0x58 0x02 0x00 0x00 0x4c 0x89 0x84 0x24 0x60 0x02 0x00 0x00 0x48 0x89 0xbc
  0x00007ff87db7c66a: 0x24 0x68 0x02 0x00 0x00 0x48 0x89 0xb4 0x24 0x70 0x02 0x00 0x00 0x48 0x89 0x9c
  0x00007ff87db7c67a: 0x24 0x78 0x02 0x00 0x00 0x48 0x89 0x94 0x24 0x80 0x02 0x00 0x00 0x48 0x89 0x8c
  0x00007ff87db7c68a: 0x24 0x88 0x02 0x00 0x00 0x48 0x89 0x84 0x24 0x90 0x02 0x00 0x00 0xc5 0x7e 0x7f
  0x00007ff87db7c69a: 0x7c 0x24 0x38 0xc5 0x7e 0x7f 0x74 0x24 0x58 0xc5 0x7e 0x7f 0x6c 0x24 0x78 0xc5
  0x00007ff87db7c6aa: 0x7e 0x7f 0xa4 0x24 0x98 0x00 0x00 0x00 0xc5 0x7e 0x7f 0x9c 0x24 0xb8 0x00 0x00
  0x00007ff87db7c6ba: 0x00 0xc5 0x7e 0x7f 0x94 0x24 0xd8 0x00 0x00 0x00 0xc5 0x7e 0x7f 0x8c 0x24 0xf8
  0x00007ff87db7c6ca: 0x00 0x00 0x00 0xc5 0x7e 0x7f 0x84 0x24 0x18 0x01 0x00 0x00 0xc5 0xfe 0x7f 0xbc
  0x00007ff87db7c6da: 0x24 0x38 0x01 0x00 0x00 0xc5 0xfe 0x7f 0xb4 0x24 0x58 0x01 0x00 0x00 0xc5 0xfe
  0x00007ff87db7c6ea: 0x7f 0xac 0x24 0x78 0x01 0x00 0x00 0xc5 0xfe 0x7f 0xa4 0x24 0x98 0x01 0x00 0x00
  0x00007ff87db7c6fa: 0xc5 0xfe 0x7f 0x9c 0x24 0xb8 0x01 0x00 0x00 0xc5 0xfe 0x7f 0x94 0x24 0xd8 0x01
  0x00007ff87db7c70a: 0x00 0x00 0xc5 0xfe 0x7f 0x8c 0x24 0xf8 0x01 0x00 0x00 0xc5 0xfe 0x7f 0x84 0x24
  0x00007ff87db7c71a: 0x18 0x02 0x00 0x00 0x49 0x3b 0x67 0x08 0x0f 0x86 0x24 0x04 0x00 0x00 0x49 0x8d
  0x00007ff87db7c72a: 0x96 0xc8 0x31 0x2e 0x00 0x8b 0x42 0x04 0x85 0xc0 0x0f 0x84 0xd5 0x01 0x00 0x00
> 0x00007ff87db7c73a: 0x41 0x8b 0x14 0xc6 0xc1 0xea 0x05 0x81 0xfa 0xb4 0xc0 0x03 0x00 0x0f 0x85 0x09
  0x00007ff87db7c74a: 0x04 0x00 0x00 0x89 0x44 0x24 0x2c 0x49 0x8d 0x8e 0x78 0x36 0x2d 0x00 0x41 0x8b
  0x00007ff87db7c75a: 0x54 0xc6 0x08 0x49 0x8d 0x1c 0xc6 0x49 0x8d 0xb6 0x60 0xbb 0x13 0x00 0x85 0xd2
  0x00007ff87db7c76a: 0x0f 0x84 0xb6 0x01 0x00 0x00 0x48 0x89 0x74 0x24 0x18 0x48 0x8b 0xd3 0x4c 0x8b
  0x00007ff87db7c77a: 0xc1 0x48 0x89 0x4c 0x24 0x20 0x48 0x89 0x5c 0x24 0x10 0xe8 0x76 0x63 0x1a 0x00
  0x00007ff87db7c78a: 0x90 0x8b 0x4c 0x24 0x2c 0x41 0x8b 0x54 0xce 0x04 0x85 0xd2 0x0f 0x84 0xcd 0x03
  0x00007ff87db7c79a: 0x00 0x00 0x41 0x8b 0x5c 0xd6 0x04 0x41 0x8b 0x74 0xce 0x08 0x49 0x8d 0x3c 0xf6
  0x00007ff87db7c7aa: 0x66 0x0f 0x1f 0x44 0x00 0x00 0x81 0xfb 0x00 0x02 0x00 0x00 0x0f 0x83 0x8e 0x01
  0x00007ff87db7c7ba: 0x00 0x00 0x85 0xf6 0x0f 0x84 0xb8 0x03 0x00 0x00 0x41 0x3b 0x44 0xf6 0x04 0x0f
  0x00007ff87db7c7ca: 0x83 0xb3 0x03 0x00 0x00 0x44 0x8b 0xc0 0x46 0x0f 0xb6 0x44 0x07 0x08 0x45 0x85
  0x00007ff87db7c7da: 0xc0 0x0f 0x84 0x3e 0x01 0x00 0x00 0x41 0xff 0xc8 0x41 0x8b 0xc0 0xd1 0xe0 0x0f
  0x00007ff87db7c7ea: 0x1f 0x80 0x00 0x00 0x00 0x00 0x3b 0xd8 0x0f 0x86 0x90 0x03 0x00 0x00 0x49 0x8d
  0x00007ff87db7c7fa: 0x14 0xd6 0x8b 0xc8 0x8b 0x54 0x8a 0x08 0x81 0xfa 0xcf 0xa6 0x05 0x00 0x0f 0x84
  0x00007ff87db7c80a: 0x94 0x01 0x00 0x00 0x8b 0x4c 0x24 0x2c 0x41 0x8b 0x5c 0xce 0x0c 0x85 0xdb 0x0f
  0x00007ff87db7c81a: 0x84 0xbe 0x02 0x00 0x00 0x49 0x8d 0x34 0xd6 0x81 0xfb 0xeb 0xc5 0x05 0x00 0x0f
  0x00007ff87db7c82a: 0x85 0xf2 0x01 0x00 0x00 0x89 0x44 0x24 0x34 0x44 0x89 0x44 0x24 0x30 0x48 0x8b

Top of stack (sp=0x0000007a1a4fec00):
  0x0000007a1a4febe0: 0x000000000000019b 0x000000000000019b 0x0000000200000000 0x0000000600000001
> 0x0000007a1a4fec00: 0x0000000000000101 0x0000000000000000 0x00000000000001b1 0x0000000000000000
  0x0000007a1a4fec20: 0x00000253050fe470 0x00007ff8d1741c4e 0x0000000100000000 0x0000000000000000
  0x0000007a1a4fec40: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fec60: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fec80: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4feca0: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fecc0: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fece0: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fed00: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fed20: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fed40: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fed60: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fed80: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4feda0: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000
  0x0000007a1a4fedc0: 0x0000000000000000 0x766e692074627573 0x6974616e20656b6f 0x0000000000000000
  0x0000007a1a4fede0: 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000

VM thread locals for the failing thread 0x00000253050ec940:
  0: JNIThreadLocalEnvironment.jniFunctions = (bytes) 0x0000025305652008
  8: StackOverflowCheckImpl.stackBoundaryTL = (Word) 0x0000000000000001 (1)
  16: Safepoint.safepointRequested = (int) 0x7fffb286 (2147463814)
  20: StatusSupport.statusTL = (int) 0x00000001 (1)
  24: ThreadLocalAllocation.regularTLAB = (bytes)
    0x00000253050ec958: 0x0000025305880000 0x0000025305900000
    0x00000253050ec968: 0x0000025305884040 0x0000000000000000
  56: JavaFrameAnchors.lastAnchor = (Word) 0x0000007a1a4ff530 (524427457840)
  64: JavaThreads.currentVThreadId = (long) 0x0000000000000001 (1)
  72: PlatformThreads.currentThread = (Object) 0x00000253056ebd80
    is an object of type java.lang.Thread
  80: SubstrateDiagnostics.threadOnlyAttachedForCrashHandler = (bytes) 0x0000000000000000
  88: ThreadLocalAllocation.allocatedBytes = (Word) 0x0000000000000000 (0)
  96: VMThreads.IsolateTL = (Word) 0x0000025305480000 (2555594145792)
  104: VMThreads.OSThreadHandleTL = (Word) 0x00000000000000e8 (232)
  112: VMThreads.OSThreadIdTL = (Word) 0x0000000000006310 (25360)
  120: VMThreads.StackBase = (Word) 0x0000007a1a500000 (524427460608)
  128: VMThreads.StackEnd = (Word) 0x0000007a1a400000 (524426412032)
  136: VMThreads.StartedByCurrentIsolate = (bytes) 0x0000000000000000
  144: VMThreads.nextTL = (Word) 0x0000000000000000 (0)
  152: VMThreads.unalignedIsolateThreadMemoryTL = (Word) 0x00000253050ec920 (2555590396192)
  160: ExceptionUnwind.currentException = (Object) 0x0000000000000000
  164: IsolatedCompileClient.currentClient = (Object) 0x0000000000000000
  168: IsolatedCompileContext.currentContext = (Object) 0x0000000000000000
  172: JNIObjectHandles.handles = (Object) 0x0000025305880928
    is an object of type com.oracle.svm.core.handles.ThreadLocalHandles
  176: JNIThreadLocalPendingException.pendingException = (Object) 0x0000000000000000
  180: JNIThreadLocalReferencedObjects.referencedObjectsListHead = (Object) 0x0000000000000000
  184: JNIThreadOwnedMonitors.ownedMonitors = (Object) 0x0000000000000000
  188: NoAllocationVerifier.openVerifiers = (Object) 0x0000000000000000
  192: RecurringCallbackTimer.exception = (Object) 0x0000000000000000
  196: ThreadingSupportImpl.activeTimer = (Object) 0x0000000000000000
  200: ActionOnTransitionToJavaSupport.actionTL = (int) 0x00000000 (0)
  204: ImplicitExceptions.implicitExceptionsAreFatal = (int) 0x00000000 (0)
  208: StackOverflowCheckImpl.yellowZoneStateTL = (int) 0x7efefefe (2130640638)
  212: StatusSupport.safepointBehaviorTL = (int) 0x00000001 (1)
  216: ThreadingSupportImpl.currentPauseDepth = (int) 0x00000000 (0)

Java frame anchors for the failing thread 0x00000253050ec940:
  Anchor 0x0000007a1a4ff530 LastJavaSP 0x0000007a1a4ff500 LastJavaIP 0x00007ff768ad4882

Stacktrace for the failing thread 0x00000253050ec940 (A=AOT compiled, J=JIT compiled, D=deoptimized, i=inlined):
  SP 0x0000007a1a4fec00 IP 0x00007ff87db7c73a  IP is not within Java code. Trying frame anchor of last Java frame instead.
  A  SP 0x0000007a1a4ff500 IP 0x00007ff768ad4882 size=112   org.example.jnilib.MyMath.sub(Native Method)
  A  SP 0x0000007a1a4ff570 IP 0x00007ff768ad40b5 size=32    org.example.jnilib.Main.main(Main.java:14)
  i  SP 0x0000007a1a4ff590 IP 0x00007ff76881b5e9 size=16    java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
  i  SP 0x0000007a1a4ff590 IP 0x00007ff76881b5e9 size=16    com.oracle.svm.core.JavaMainWrapper.invokeMain(JavaMainWrapper.java:182)
  A  SP 0x0000007a1a4ff590 IP 0x00007ff76881b5e9 size=16    com.oracle.svm.core.JavaMainWrapper.runCore0(JavaMainWrapper.java:233)
  i  SP 0x0000007a1a4ff5a0 IP 0x00007ff76884ab60 size=496   com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:202)
  i  SP 0x0000007a1a4ff5a0 IP 0x00007ff76884ab60 size=496   com.oracle.svm.core.JavaMainWrapper.doRun(JavaMainWrapper.java:301)
  i  SP 0x0000007a1a4ff5a0 IP 0x00007ff76884ab60 size=496   com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:286)
  A  SP 0x0000007a1a4ff5a0 IP 0x00007ff76884ab60 size=496   com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(IsolateEnterStub.java:0)

Threads:
  0x00000253050f3f80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "Reference Handler" - 0x00000253056ebdf0, daemon, stack(0x0000007a1a800000,0x0000007a1a900000)
  0x00000253050ec940 STATUS_IN_JAVA (PREVENT_VM_FROM_REACHING_SAFEPOINT) "main" - 0x00000253056ebd80, stack(0x0000007a1a400000,0x0000007a1a500000)

No VMOperation in progress

The 30 most recent VM operation status changes:

VM mutexes:
  mutex "thread" is unlocked.
  mutex "freeList" is unlocked.
  mutex "referencePendingList" is unlocked.
  mutex "RealLog.backTracePrinterMutex" is unlocked.
  mutex "mainVMOperationControlWorkQueue" is unlocked.

Build time information:
  Version: 22.0.1+8, serial gc, compressed references
  Platform: windows/amd64
  Page size: 4096
  Container support: true
  CPU features used for AOT compiled code: CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, LZCNT, AVX, AVX2, BMI1, BMI2, FMA, F16C

Runtime information:
  CPU cores (container): unknown
  CPU cores (OS): 8
  Memory: 16134M
  Page size: 4096
  VM uptime: 0.352s
  Current timestamp: 1719816667700
  AOT compiled code: 0x00007ff768811000 - 0x00007ff768b0daaf

Command line:

Heap settings and statistics:
  Supports isolates: true
  Heap base: 0x0000025305480000
  Object reference size: 4
  Reserved object header bits: 0b11111
  Aligned chunk size: 524288
  Large array threshold: 131072
  Incremental collections: 0
  Complete collections: 0

Heap usage:
  Eden: 0.50M (0.00M in 0 aligned chunks, 0.00M in 0 unaligned chunks)
  Old: 0.00M (0.00M in 0 aligned chunks, 0.00M in 0 unaligned chunks)

Native image heap boundaries:
  ReadOnly Primitives: 0x0000025305500830 - 0x00000253055c4840
  ReadOnly References: 0x00000253055c4840 - 0x0000025305651680
  ReadOnly Relocatables: 0x0000025305652000 - 0x000002530568d7c0
  Writable Primitives: 0x000002530568e000 - 0x00000253056cf838
  Writable References: 0x00000253056cf838 - 0x000002530576d4a8
  Writable Huge: 0x0000000000000000 - 0x0000000000000000
  ReadOnly Huge: 0x0000025305780038 - 0x0000025305829638

Heap chunks: E=eden, S=survivor, O=old, F=free; A=aligned chunk, U=unaligned chunk; T=to space

Segfault detected, aborting process. Use '-XX:-InstallSegfaultHandler' to disable the segfault handler at run time and create a core dump instead. Rebuild with '-R:-InstallSegfaultHandler' to disable the handler permanently at build time.

Steps to reproduce the issue

My demo is here graalvm-demo and my detailed steps is in README.md

Describe GraalVM and your environment:

java -version

java version "22.0.1" 2024-04-16
Java(TM) SE Runtime Environment Oracle GraalVM 22.0.1+8.1 (build 22.0.1+8-jvmci-b01)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 22.0.1+8.1 (build 22.0.1+8-jvmci-b01, mixed mode, sharing)
selhagani commented 6 days ago

Hi @chyohn, thank you for reporting this. Could you please share with me your OS information and your system's architecture?

chyohn commented 6 days ago

Hi @selhagani , Thanks for your reply. I'm using graalvm version: GraalVM for JDK 22 OS: win10 Architecture: intel 64