matsim-org / matsim-libs

Multi-Agent Transport Simulation
www.matsim.org
486 stars 449 forks source link

problem with jogl/gluegen on mac with arm64 #2928

Open kainagel opened 1 year ago

kainagel commented 1 year ago

I download the zipfile from https://github.com/matsim-org/matsim-example-project , import this into Intellij, and run RunMatsim. Works ok.

I then uncomment the line `controler.addOverridingModule( new OTFVisLiveModule() );'. It then fails with the attached error message.

Looks like a problem related to the switch from x86 to arm CPUs for mac. Probably same as https://github.com/matsim-org/matsim-libs/issues/1961 . Has anybody found a systematic solution to this?

2023-11-13T12:10:07,030 ERROR MatsimRuntimeModifications$1:63 Getting uncaught Exception in Thread AWT-EventQueue-0 java.lang.UnsatisfiedLinkError: /private/var/folders/1_/5_c3r6w902j0bjqb2kzmbh4w0000gn/T/jogamp_0000/file_cache/jln2169133887102665096/jln4081141966354528481/natives/macosx-universal/libgluegenrt.dylib: dlopen(/private/var/folders/1/5_c3r6w902j0bjqb2kzmbh4w0000gn/T/jogamp_0000/file_cache/jln2169133887102665096/jln4081141966354528481/natives/macosx-universal/libgluegenrt.dylib, 0x0001): tried: '/private/var/folders/1/5_c3r6w902j0bjqb2kzmbh4w0000gn/T/jogamp_0000/file_cache/jln2169133887102665096/jln4081141966354528481/natives/macosx-universal/libgluegen_rt.dylib' (mach-o file, but is an incompatible architecture (have 'x8664', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/1/5_c3r6w902j0bjqb2kzmbh4w0000gn/T/jogamp_0000/file_cache/jln2169133887102665096/jln4081141966354528481/natives/macosx-universal/libgluegenrt.dylib' (no such file), '/private/var/folders/1/5_c3r6w902j0bjqb2kzmbh4w0000gn/T/jogamp_0000/file_cache/jln2169133887102665096/jln4081141966354528481/natives/macosx-universal/libgluegen_rt.dylib' (ma at jdk.internal.loader.NativeLibraries.load(Native Method) ~[?:?] at jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388) ~[?:?] at jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232) ~[?:?] at jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174) ~[?:?] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389) ~[?:?] at java.lang.Runtime.load0(Runtime.java:755) ~[?:?] at java.lang.System.load(System.java:1953) ~[?:?] at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:604) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:64) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:107) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:488) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:427) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at com.jogamp.common.os.Platform$1.run(Platform.java:321) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at java.security.AccessController.doPrivileged(AccessController.java:318) ~[?:?] at com.jogamp.common.os.Platform.(Platform.java:290) ~[gluegen-rt-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at com.jogamp.opengl.GLProfile.(GLProfile.java:154) ~[jogl-all-2.4.0-matsim-1.jar:2.4.0-rc-20200306] at org.matsim.vis.otfvis.opengl.drawer.OTFOGLDrawer.createGLCanvas(OTFOGLDrawer.java:330) ~[otfvis-15.0.jar:?] at org.matsim.vis.otfvis.OTFClientLive$1.run(OTFClientLive.java:78) ~[otfvis-15.0.jar:?] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) ~[?:?] at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771) ~[?:?] at java.awt.EventQueue$4.run(EventQueue.java:722) ~[?:?] at java.awt.EventQueue$4.run(EventQueue.java:716) ~[?:?] at java.security.AccessController.doPrivileged(AccessController.java:399) ~[?:?] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) ~[?:?] at java.awt.EventQueue.dispatchEvent(EventQueue.java:741) ~[?:?] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) [?:?] at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) [?:?] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) [?:?] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) [?:?] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:?] at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) [?:?]

kainagel commented 1 year ago

A workaround (but probably not a longterm solution) is: These are my available java SDKs:

[matsim-example-project-master]$ /usr/libexec/java_home -V
Matching Java Virtual Machines (8):
    17.0.7 (arm64) "MacPorts" - "OpenJDK 17.0.7" /Library/Java/JavaVirtualMachines/openjdk17/Contents/Home
    17.0.2 (x86_64) "Oracle Corporation" - "OpenJDK 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
    17 (arm64) "Oracle Corporation" - "OpenJDK 17" /Library/Java/JavaVirtualMachines/openjdk17-bootstrap/Contents/Home
    14.0.1 (x86_64) "UNDEFINED" - "OpenJDK 14.0.1" /usr/local/Cellar/openjdk/14.0.1/libexec/openjdk.jdk/Contents/Home
    14.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 14.0.1" /Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home
    11.0.10 (arm64) "Azul Systems, Inc." - "Zulu 11.45.27" /Library/Java/JavaVirtualMachines/openjdk11-bootstrap/Contents/Home
    9 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 9" /Library/Java/JavaVirtualMachines/adoptopenjdk-9.jdk/Contents/Home
    1.8.0_252 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk17/Contents/Home
[matsim-example-project-master]$

If I select one that says x86_64, then otfvis works. If I select one that says arm64, then it does not work. ((I haven't tested this systematically, though.))

My intuition is that with x86_64 it runs on Rosetta, i.e. pretending to be x86, and thus it works, but presumably java will be slower.

As Chengqi states in https://github.com/matsim-org/matsim-libs/issues/1961, we probably somehow have to get the arm64 variants into the corresponding dylib files.

kainagel commented 1 year ago

There is https://jogamp.org/wiki/index.php/Maven . It says that everything after 2.3.2 is at the Jogamp Test Repository (which needs to be added as repository in maven). If I then use 2.5.0, it seems to work on my mac even with a arm64 Java version.

However, as far as I can tell, this will no longer support certain windows architectures: See https://jogamp.org/deployment/maven/org/jogamp/jogl/jogl-all/2.5.0/ and compare to https://jogamp.org/deployment/maven/org/jogamp/jogl/jogl-all/2.3.2/ and in particular note that windows-i586 was dropped. I can't say if that would have consequences for windows users.

kainagel commented 1 year ago

https://jogamp.org/wiki/index.php/Maven also states that there is a ``trick'' that one does not have to list all the native files separately (as we currently do).

mrieser commented 1 year ago

i586 is and Pentium-related 32-bit architecture introduced in 1993. I doubt anybody still runs MATSim and OTFVis on a pure 32-bit system, so I guess it's okay to drop support for this.