-
Notifications
You must be signed in to change notification settings - Fork 586
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
JVM stuck forever at Pointer.physicalBytesInaccurate()
#767
Comments
Please try to set the "org.bytedeco.javacpp.nopointergc" system property to "true". |
Thank you Samuel @saudet, I'll try to and get back with my feedback in a short while. For what it's worth, the JVM thread is stuck at Stack: So I think I'll also play with memory settings ( |
Samuel @saudet, after some time spent searching, it looks like my issue is similar to tensorflow/java#208, and I have two questions:
|
When maxPhysicalBytes is 0 it just doesn't try as hard to release memory, that's all. Yes, Pointer.close() is for that purpose, but it's easier to use PointerScope: |
Samuel @saudet, thank you for your response, I really appreciate your feedback. Unfortunately, adding despite our used JVM heap is shallow (< 1 GB): There're indeed minor "drops" in Working Set (or, consequently, Private Bytes values) whenever a Can this issue be caused by a recursive nature of Libclang and its Can you suggest how we can further diagnose the problem? We've tried what looks like all possible combinations of property values:
— but made very little progress so far. |
Samuel @saudet, a few more observations. Here's the expected growth of the Working Set in the presence of unidentified memory leaks: If I sprinkle the code with more Finally, despite memory limits and garbage collection are essentially disabled ( |
In the case of C APIs we need to release memory manually, so please refer
to libclang's documentation.
…On Fri, Jul 12, 2024, 03:01 Andrey S. ***@***.***> wrote:
Samuel @saudet <https://github.com/saudet>, a a few more observations.
Here's the expected growth of the *Working Set* in the presence of
unidentified memory leaks:
image.png (view on web)
<https://github.com/bytedeco/javacpp/assets/73111822/e47ecd7a-4fac-49cc-9282-40139f158ca4>
If I sprinkle the code with more PointerScope instances here and there,
memory leaks don't go away -- instead, this merely slows everything down
(as you can see, the graph gets scaled horizontally):
image.png (view on web)
<https://github.com/bytedeco/javacpp/assets/73111822/e22c0b70-5889-4627-9a1b-e72bc88ac296>
Finally, despite memory limits and garbage collection are essentially
disabled (maxBytes=*0*, maxPhysicalBytes=*0*, maxRetries=*0*, noPointerGC=
*true*), sometimes *JavaCPP* may still think it has run out of memory; in
this case all useful (application's) I/O stops and CPU usage hits *80%*
(in native code):
image.png (view on web)
<https://github.com/bytedeco/javacpp/assets/73111822/8e7b82dc-9a7e-44f2-8715-d952f5246eb7>
—
Reply to this email directly, view it on GitHub
<#767 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZMQF4CKQIQI2PA5CFJHWTZL3CARAVCNFSM6AAAAABKTHCAASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRTGU2TIOJVGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
By trial and error, I figured out how to prevent memory leaks when using Libclang, despite its documentation is brief and insufficient.
One the above is done, the Java application can be safely launched with pointer garbage collection disabled, and in my scenario memory usage stabilizes at around 600 to 700 MB (as opposed to 5 GB with memory leaks):
I've set up a sample repo with my findings available as a runnable code. This issue can be closed. Thank you for your support. |
Thanks for the detailed explanations! It would be great if your could contribute sample code that demonstrate all this |
Definitely. I could merge my source code into a single self-contained Java file and add it to Yet, the existing LLVM samples are currently intended to also run on Java 7. I backported my own samples from Java 17 to Java 7 and 8. The question is: which version (7, 8, or 17) do you want added to LLVM samples? |
It doesn't really matter what version of Java the samples are in, whichever is fine 👍 |
Thanks for the contribution! |
I'm parsing multiple C++ files with llvm from javacpp-presets.
At some point, after parsing ~100 files (the exact threshold varies), the JVM process gets permanently stuck at
Pointer.physicalBytesInaccurate()
, not returning even after spending an hour inside this method. The JVM stack trace is:As you can see, my code is calling
clang.clang_getTypeSpelling()
, and this attempt hangs while trying to invoke thePointer.init()
→Pointer.deallocator()
→Pointer.physicalBytesInaccurate()
chain.org.bytedeco.javacpp:1.5.9
.The JVM arguments are as follows:
The maximum process memory to be used by either JVM or Libclang is set to 1 GB (1073741824), and the maximum heap size is set to be 80% of that value (i.e. 786 MB).
The reverse call tree obtained from the profiler:
The text was updated successfully, but these errors were encountered: