bell-sw / LibericaNIK

Native Image Kit
4 stars 0 forks source link

Native JavaFX image got segmentation fault on Windows 10 #19

Closed sgyeme closed 1 year ago

sgyeme commented 1 year ago

Describe the issue I successfully created native image for simple JavaFX app , but the image got segmentation fault when I tried to run.

Describe NIK and your environment:

NIK version: 21.3.3.1 & 22.3 JDK major version: 17 OS: Windows 10 64bit

Steps to reproduce the issue It's JavaFX simple Native Image

`public class App extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
   var vbox=new VBox(new Label("Native Image Kit JavaFX"));
   vbox.setPrefSize(400d, 400d);
    var scene = new Scene(vbox);
    primaryStage.setScene(scene);
    primaryStage.sizeToScene();
    primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}

}

public class AppStarter {

public static void main(String[] args) {
    Application.launch(App.class, args);

}

}

`MAVEN TOOLS USED

org.graalvm.buildtools native-maven-plugin

StackTrace [ [ SubstrateSegfaultHandler caught a segfault in thread 0x000001b6398feb80 ] ] siginfo: ExceptionCode: -1073741819, reading address 0x0000000000000000 General purpose register values: RAX 0x00007ff7c4970c30 is an unknown value RBX 0x0000000000000002 is an unknown value RCX 0x0000000000000000 RDX 0x00000026294ff620 points into the stack for thread 0x000001b6398feb80 RBP 0x0000000000000000 RSI 0x0000000000000001 is an unknown value RDI 0x000001b6398e5e30 is an unknown value RSP 0x00000026294ff5f0 points into the stack for thread 0x000001b6398feb80 R8 0x0000000000010002 is an unknown value R9 0x0000000000000032 is an unknown value R10 0x0000000000000000 R11 0x00c0000000000000 is an unknown value R12 0x00007ff7c3a7f8dd is an unknown value R13 0x00000026294ff6b0 points into the stack for thread 0x000001b6398feb80 R14 0x000001b63b300000 is the heap base R15 0x000001b6398feb80 is a thread EFL 0x0000000000010206 is an unknown value RIP 0x00007ff7c4929cb6 is an unknown value

Printing Instructions (ip=0x00007ff7c4929cb6): 0x00007ff7c4929c96: 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0x48 0x83 0xec 0x28 0x48 0x8b 0x00007ff7c4929ca6: 0x0d 0x15 0xbd 0x06 0x00 0x48 0x8d 0x54 0x24 0x30 0x41 0xb8 0x02 0x00 0x01 0x00 0x00007ff7c4929cb6: 0x48 0x8b 0x01 0xff 0x50 0x30 0x48 0x8b 0x44 0x24 0x30 0x48 0x83 0xc4 0x28 0xc3 0x00007ff7c4929cc6: 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0xcc 0x48 0x8b 0x05 0xe9 0xbc 0x06

Top of stack (sp=0x00000026294ff5f0): 0x00000026294ff5f0: 0x0000000000000048 0x00007ff7c3786e9c 0x00000026294ff600: 0x0000597253e1eeb8 0x00007ff7c3792241 0x00000026294ff610: 0x0000000000000002 0x00007ff7c492e6e1 0x00000026294ff620: 0x000001b644801028 0x0000000000000002 0x00000026294ff630: 0x0000000000000030 0x00007ff7c3791fef 0x00000026294ff640: 0x0000000000000000 0x000001b644801028 0x00000026294ff650: 0x000001b64441b280 0x00007ff7c39b4bcf 0x00000026294ff660: 0x0000000000100000 0x000001b6398de250 0x00000026294ff670: 0x0000000000000001 0x00007ff7c3a7f8f0 0x00000026294ff680: 0x0000000000769048 0x000000000911b280 0x00000026294ff690: 0x0000000000000000 0x000001b63be94940 0x00000026294ff6a0: 0x000001b64441b5f0 0x000001b64441b280 0x00000026294ff6b0: 0x00007ff7c3a7f8dd 0x00000026294ff680 0x00000026294ff6c0: 0x0000000000000000 0x0000000000000000 0x00000026294ff6d0: 0x0000000200000001 0x00007ff7c3a82090 0x00000026294ff6e0: 0x000001b64441b5f0 0x000001b64441b280 0x00000026294ff6f0: 0x000001b64441b5a8 0x00007ff7c3a7ed49 0x00000026294ff700: 0x0000000000000000 0x00007ff7c412a9b4 0x00000026294ff710: 0x0000000000000003 0x00007ff7c3823981 0x00000026294ff720: 0x0000000000000004 0x0000000000000354 0x00000026294ff730: 0x000001b64441b5f0 0x000001b63bdfa540 0x00000026294ff740: 0x0000000000000004 0x00007ff7c382b669 0x00000026294ff750: 0x0000000000000000 0x00007ff700000000 0x00000026294ff760: 0x0000000100000001 0x00007ff7c38259ac 0x00000026294ff770: 0x0000000000000000 0x00007ff7c494fcbe 0x00000026294ff780: 0x0000000000000354 0x00007ff7c37784bb 0x00000026294ff790: 0x0000000000000000 0x0000000000000000 0x00000026294ff7a0: 0x0000000000000000 0x000001b6398dea00 0x00000026294ff7b0: 0x0000000000000000 0x0000000000000000 0x00000026294ff7c0: 0x0000000000000000 0x0000000000000000 0x00000026294ff7d0: 0x0000000000000000 0x0000000000000000 0x00000026294ff7e0: 0x0000000000000000 0x0000000000000000

Top frame info: Does not look like a Java Frame. Use JavaFrameAnchors to find LastJavaSP: Found matching Anchor:0x00000026294ff6b0 LastJavaSP 0x00000026294ff680 LastJavaIP 0x00007ff7c3a7f8dd

Threads: 0x000001b6398feb80 STATUS_IN_JAVA (safepoints disabled) "WindowsNativeRunloopThread" - java.lang.Thread@0x000001b64441b5f0, stack(0x0000002629400000,0x0000002629500000) 0x000001b6398fe900 STATUS_IN_NATIVE "InvokeLaterDispatcher" - com.sun.glass.ui.InvokeLaterDispatcher@0x000001b64441b2b8, daemon, stack(0x0000002629300000,0x0000002629400000) 0x000001b639889b00 STATUS_IN_NATIVE "QuantumRenderer-0" - java.lang.Thread@0x000001b640004c50, daemon, stack(0x0000002629200000,0x0000002629300000) 0x000001b639892fc0 STATUS_IN_NATIVE "JavaFX-Launcher" - java.lang.Thread@0x000001b63c902ac0, stack(0x0000002629100000,0x0000002629200000) 0x000001b639899c00 STATUS_IN_NATIVE "main" - java.lang.Thread@0x000001b63bcc3ed8, stack(0x0000002628ae0000,0x0000002628be0000)

VM thread locals for the failing thread 0x000001b6398feb80: 0 (8 bytes): com.oracle.svm.jni.JNIThreadLocalEnvironment.jniFunctions = (bytes) 0x000001b6398feb80: 0x000001b63b97d010 8 (8 bytes): com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.stackBoundaryTL = (Word) 1 (0x0000000000000001) 16 (4 bytes): com.oracle.svm.core.thread.Safepoint.safepointRequested = (int) 2147463898 (0x7fffb2da) 20 (4 bytes): com.oracle.svm.core.thread.VMThreads$StatusSupport.statusTL = (int) 1 (0x00000001) 24 (32 bytes): com.oracle.svm.core.genscavenge.ThreadLocalAllocation.regularTLAB = (bytes) 0x000001b6398feb98: 0x000001b644800000 0x000001b644900000 0x000001b6398feba8: 0x000001b644801230 0x0000000000000000 56 (8 bytes): com.oracle.svm.core.thread.JavaThreads.currentThread = (Object) java.lang.Thread (0x000001b64441b5f0) 64 (8 bytes): com.oracle.svm.core.stack.JavaFrameAnchors.lastAnchor = (Word) 163901863600 (0x00000026294ff6b0) 72 (8 bytes): com.oracle.svm.core.heap.NoAllocationVerifier.openVerifiers = (Object) null 80 (8 bytes): com.oracle.svm.core.identityhashcode.IdentityHashCodeSupport.hashCodeGeneratorTL = (Object) null 88 (8 bytes): com.oracle.svm.core.snippets.ExceptionUnwind.currentException = (Object) null 96 (8 bytes): com.oracle.svm.core.thread.ThreadingSupportImpl.activeTimer = (Object) null 104 (8 bytes): com.oracle.svm.graal.isolated.IsolatedCompileClient.currentClient = (Object) null 112 (8 bytes): com.oracle.svm.graal.isolated.IsolatedCompileContext.currentContext = (Object) null 120 (8 bytes): com.oracle.svm.jni.JNIObjectHandles.handles = (Object) com.oracle.svm.core.handles.ThreadLocalHandles (0x000001b644801028) 128 (8 bytes): com.oracle.svm.jni.JNIThreadLocalPendingException.pendingException = (Object) null 136 (8 bytes): com.oracle.svm.jni.JNIThreadLocalPinnedObjects.pinnedObjectsListHead = (Object) null 144 (8 bytes): com.oracle.svm.jni.JNIThreadOwnedMonitors.ownedMonitors = (Object) null 152 (8 bytes): com.oracle.svm.core.SubstrateDiagnostics.threadOnlyAttachedForCrashHandler = (bytes) 0x000001b6398fec18: 0x0000000000000000 160 (8 bytes): com.oracle.svm.core.thread.VMThreads.IsolateTL = (Word) 1882188677120 (0x000001b63b300000) 168 (8 bytes): com.oracle.svm.core.thread.VMThreads.OSThreadHandleTL = (Word) 860 (0x000000000000035c) 176 (8 bytes): com.oracle.svm.core.thread.VMThreads.OSThreadIdTL = (Word) 8916 (0x00000000000022d4) 184 (8 bytes): com.oracle.svm.core.thread.VMThreads.StackBase = (Word) 163901865984 (0x0000002629500000) 192 (8 bytes): com.oracle.svm.core.thread.VMThreads.StackEnd = (Word) 163900817408 (0x0000002629400000) 200 (8 bytes): com.oracle.svm.core.thread.VMThreads.nextTL = (Word) 1882161408256 (0x000001b6398fe900) 208 (8 bytes): com.oracle.svm.core.thread.VMThreads.unalignedIsolateThreadMemoryTL = (Word) 1882161408880 (0x000001b6398feb70) 216 (4 bytes): com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.yellowZoneStateTL = (int) 2130640638 (0x7efefefe) 220 (4 bytes): com.oracle.svm.core.snippets.ImplicitExceptions.implicitExceptionsAreFatal = (int) 0 (0x00000000) 224 (4 bytes): com.oracle.svm.core.thread.ThreadingSupportImpl.currentPauseDepth = (int) 0 (0x00000000) 228 (4 bytes): com.oracle.svm.core.thread.VMThreads$ActionOnExitSafepointSupport.actionTL = (int) 0 (0x00000000) 232 (4 bytes): com.oracle.svm.core.thread.VMThreads$ActionOnTransitionToJavaSupport.actionTL = (int) 0 (0x00000000) 236 (4 bytes): com.oracle.svm.core.thread.VMThreads$StatusSupport.safepointsDisabledTL = (int) 1 (0x00000001)

No VMOperation in progress

The 10 most recent VM operation status changes (oldest first):

Counters:

Java frame anchors for the failing thread 0x000001b6398feb80: Anchor 0x00000026294ff6b0 LastJavaSP 0x00000026294ff680 LastJavaIP 0x00007ff7c3a7f8dd

Stacktrace for the failing thread 0x000001b6398feb80: SP 0x00000026294ff5f0 IP 0x00007ff7c4929cb6 IP is not within Java code. Trying frame anchor of last Java frame instead. SP 0x00000026294ff680 IP 0x00007ff7c3a7f8dd [image code] com.sun.glass.ui.win.WinApplication._init(WinApplication.java) SP 0x00000026294ff6e0 IP 0x00007ff7c3a82090 [image code] com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:183) SP 0x00000026294ff700 IP 0x00007ff7c3a7ed49 [image code] com.sun.glass.ui.win.WinApplication$$Lambda$d50d83fb978dca219ba176fffb492bc5ef0b971f.run(Unknown Source) SP 0x00000026294ff710 IP 0x00007ff7c412a9b4 [image code] java.lang.Thread.run(Thread.java:833) SP 0x00000026294ff720 IP 0x00007ff7c3823981 [image code] com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:600) SP 0x00000026294ff750 IP 0x00007ff7c382b669 [image code] com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:138) SP 0x00000026294ff790 IP 0x00007ff7c37784bb [image code] com.oracle.svm.core.code.IsolateEnterStub.WindowsJavaThreads_osThreadStartRoutine_4bc03aa26f8cdfc97ebd54050e8ae4bce1023851(IsolateEnterStub.java:0)

VM mutexes: mutex "mainVMOperationControlWorkQueue" is unlocked. mutex "referencePendingList" is unlocked. mutex "thread" is unlocked.

Heap settings and statistics: Supports isolates: true Heap base: 0x000001b63b300000 Object reference size: 8 Aligned chunk size: 1048576 Incremental collections: 0 Complete collections: 0

Native image heap boundaries: ReadOnly Primitives: 0x000001b63b401028 - 0x000001b63b722d00 ReadOnly References: 0x000001b63b722d00 - 0x000001b63b97c438 ReadOnly Relocatables: 0x000001b63b97d000 - 0x000001b63baddba8 Writable Primitives: 0x000001b63bade000 - 0x000001b63bc3c9e8 Writable References: 0x000001b63bc3c9e8 - 0x000001b63c116038 Writable Huge: 0x000001b63c200030 - 0x000001b63c234170 ReadOnly Huge: 0x000001b63c235030 - 0x000001b63c7c4338

Heap: Young generation: Eden: edenSpace: aligned: 0/0 unaligned: 0/0 Survivors:

Old generation: oldFromSpace: aligned: 0/0 unaligned: 0/0 oldToSpace: aligned: 0/0 unaligned: 0/0

Unused: aligned: 0/0

Segfault detected, aborting process. Use runtime option -R:-InstallSegfaultHandler if you don't want to use SubstrateSegfaultHandler.

petermz commented 1 year ago

Cannot reproduce so far. Here’s what I did on my Windows 10 Pro, 64 bit box:

Could you please report the size of your native executable? Mine is about 36 Mb. Could you also run native-image with the --verbose option and post its output?

sgyeme commented 1 year ago

The size of the ececutable is 35Mb I run from _x64 Native Tools Command Prompt for VS 2019

output.txt

sgyeme commented 1 year ago

I have tired many times without success. I have invoked the native-image directly without the native-maven-plugin but I still get the same error.

petermz commented 1 year ago

Hi @sgyeme -- could you please conduct a couple more experiments and post results here?

sgyeme commented 1 year ago

Find below output: --JVM run and --Native image run

There are alot of DLL that failed to load in both cases

jvm-run-output.txt native image-run-output.txt

sgyeme commented 1 year ago

It is finally working after setting java.library.path But I will welcome a better approach.

`public class AppStarter {

public static void main(String[] args) {
    System.setProperty("java.library.path","C:\\Windows\\System32\\downlevel");
    Application.launch(App.class, args);

}

}`

lvxingtu commented 1 year ago

I have same problem. What is java.library.path, how to do it?