-
-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Freezing sometimes in glfw and opengl native methods. #490
Comments
Hey @Alex-----, There's not enough information to be able to reproduce this. It would be simpler if you could prepare an MCVE that exhibits the same behavior. It also sounds unlikely that this is an issue with LWJGL or GLFW. Have you tried logging GCs and seeing if there's a correlation with the freezing? |
I just tried logging GCs and there is one logged right after it unfreezes each time: |
There are no freezes when using -XX:+UseShenandoahGC and adoptopenjdk jdk-12.0.2+10 (windows x64), There are freezes with G1GC and ConcMarkSweepGC. |
Sounds like a GC issue then, which depends on how many allocations are happening in your application. You are not the first person to report bad performance with G1GC. It's weird that you mention a difference between 3.2.1 and newer versions though, there haven't been any changes in LWJGL that would cause higher allocation rates. Also, LWJGL never passes objects between Java and native code, so the choice of GC algorithm doesn't affect the performance of LWJGL bindings. Does the issue get (much) worse if you run with |
ParallelGC is also freezing, -XX:-DoEscapeAnalysis does not affect it very much, it might be freezing a bit less. ZGC is not supported. |
I'm calling glfwWaitEventsTimeout(1) in a loop from the main thread and changing it to glfwWaitEventsTimeout(0.01) stops the freezing. I think it's using a |
Does the freezing stop with |
Yes |
Will be restored in LWJGL 3.3 with the possibility to enable it at runtime, if the JVM can avoid excessive blocking (e.g. using ShenandoahGC).
Hey @Alex-----, I spent several days trying different approaches, but in the end decided that supporting critical JNI natives is too risky for the time being. The next LWJGL 3.2.3 snapshot will support standard JNI only and you shouldn't see any more freezing. A major change is coming in LWJGL 3.3 that will make it possible to enable JNI crits at runtime, when it is appropriate (e.g. when the Shenandoah GC is enabled). The root of the problem is this line in the JDK code. The work behind Btw, the only GCs that return true from @shipilev, sorry to bother you, but I think you may be interested. I understand that critical natives are not officially supported, but they could be made very useful, at least until the release of Project Panama. Specifically:
And a couple more, on the off chance you actually have time to look into this:
|
@Spasi: I forwarded your questions to shenandoah-dev here: https://mail.openjdk.java.net/pipermail/shenandoah-dev/2019-August/010419.html |
I'm curious, is there a way to use critical JNI calls now? It has been a while and it was stated in here that there would be a configuration option for that. |
Hey @gudenau, LWJGL does not currently support It's in my plans to do some more testing with JDK-8233343, which should eliminate freezing and yield lower overhead (no thread transitions). However, any support for critical JNI would necessarily have to be limited to specific JVM configurations (16+ or pre-16 with ShenandoahGC enabled). I'm not sure it's worth the trouble, with Project Panama so close to release. Supporting both crit and non-crit JNI bindings so far meant a lot of complexity and much larger native binaries. My plan was to introduce runtime binding generation (i.e. building shared libraries at runtime with something like TinyCC), which would not only eliminate the duplication, but also entire artifacts (e.g. OpenGL) and the horrible |
Fair enough! I do have some experience with the foreign linker and memory APIs, they are pretty nice to use. For now they are a bit slower than plain old JNI, but I do have hope for them in the next few Java releases. |
Will lwjgl3 be moved to Java 16+? |
Will be restored in LWJGL 3.3 with the possibility to enable it at runtime, if the JVM can avoid excessive blocking (e.g. using ShenandoahGC).
My thread is freezing for about a second sometimes in native glfw and opengl methods (Have seen it happen for glfwSwapBuffers, glfwPostEmptyEvent, glDrawArrays, and glUseProgram). The rate that it freezes at changes, but may be related to the number of native method calls (It freezes every other second on one screen of my app but goes for around 10 seconds without freezing in another, where less is drawn).
The text was updated successfully, but these errors were encountered: