Bug 1536762
| Summary: | Misuse of JNI by libguestfs Java bindings | ||
|---|---|---|---|
| Product: | [Community] Virtualization Tools | Reporter: | Demi Marie Obenour <demiobenour> |
| Component: | libguestfs | Assignee: | Richard W.M. Jones <rjones> |
| Status: | NEW --- | QA Contact: | |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | unspecified | CC: | ptoscano, stenavin |
| Target Milestone: | --- | Keywords: | Reopened |
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2025-10-17 00:10:40 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
|
Description
Demi Marie Obenour
2018-01-20 22:03:09 UTC
I have to say I don't know very much about JNI. Do you have suggested patches or outline changes that need to be made? * Firstly, any calls to `FindClass`, `Get*MethodID`, and other such methods (anything that returns a `jclass`, `jmethodid`, or a `jfieldid`) should be done in `JNI_OnLoad` and the `jclass` objects converted to global refs. * Java exceptions need to be checked (using `ExceptionCheck`) after every operation that might throw them, unless the function return code guarantees that there is no pending exception, or unless one is simply returning. * Local references must be released with `DeleteLocalRef` when no longer needed. If the number of local references may exceed 16, it is necessary to call `EnsureLocalCapacity` and check its return value. * Any data that is not of small and fixed size should be stored in direct `ByteBuffer`s on the Java side and accessed using `GetDirectBufferAddress` or (better yet) the corresponding call from `sun.misc.Unsafe`. It should be accessed from Java using the corresponding functions of `ByteBuffer` or `Unsafe`. This is the only way to avoid an O(n) copy on JVMs that do not support pinning (most of them) with native methods that might block (most of them). * Calling into native from Java is much, much faster than the reverse. Marshalling code should thus be in Java, rather than in C. This product has been discontinued or is no longer tracked in Red Hat Bugzilla. Reopening because Virtualization Tools has not been discontinued. |