You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are hundreds of methods in OSHI leveraging JNA. Port one of them!
It's easier than you might think!
You will need to be using JDK 19. Because the FFM API is a preview API, you must compile and run the code with preview features enabled, i.e., javac --release 19 --enable-preview ... and java --enable-preview. Most IDEs will enable you to add these arguments. (In Eclipse I clicked a checkbox to enable preview features and added --enable-native-access=ooo.oshi to my VM arguments in run configurations... done!)
If you start a tutorial that has you use jlink, stop. It won't be helpful for you here. You need to use the basic method invoking and memory functions described in JEP 424. These largely have a direct correspondence to the existing JNA implementations. Some code is already committed for macOS process listings that gives a good feel for all the possibilities.
For methods and structures, check out the SystemLibrary class for macOS and usages in SysctlUtil, MacOperatingSystem and MacOSProcess. There should be enough examples there to hint you toward modeling new data structures. In summary:
For methods, copy the corresponding JNA interface method, and wrap the call to the MethodHandle in a try/catch. Then make a corresponding private method implementing the mapping. You'll need to tweak non-primitive arguments.
For structures, the GroupLayout examples at the bottom of the SystemLibrary class, and the access in the MacOSProcess class are good examples.
There's probably going to be a need for a generic IntByReference and LongByReference equivalent at some point...
Priority:
Anything you can contribute. If it's your first time doing a FFM function, pick an easy one. Any help is appreciated. Truly. Don't know where to put it in the API? Don't worry! Just submit a standalone class with the implementation and we'll move it to where it's needed!
Would it be interesting for OSHI to use JExtract, which can mechanically generate the Java code that can call C functions from a given header-file using the FFM-API? https://github.com/openjdk/jextract
IIRC there is even a Maven-Plugin to generate the Java sources or binaries in a Maven build, but when I last saw it was still under development.
This is a great initiative @dbwiddis. I have used the OSHI library to build one of my own projects. I am also planning to contribute to this FFM library.
Could you please quickly help me know if there are any new features already built or are work-in-progress? So that, I can focus on other unfinished tasks. Small disclaimer, I am new to FFM. Thus, I may take some time to gear up to my coding pace. 🙏
I don't think there are any works in progress... feel free to step up wherever you'd like. My initial goal is to get most-used features like CPU usage and memory usage ported over, and I did a bit of the macOS work to support that.
There are hundreds of methods in OSHI leveraging JNA. Port one of them!
It's easier than you might think!
You will need to be using JDK 19. Because the FFM API is a preview API, you must compile and run the code with preview features enabled, i.e.,
javac --release 19 --enable-preview
... andjava --enable-preview
. Most IDEs will enable you to add these arguments. (In Eclipse I clicked a checkbox to enable preview features and added--enable-native-access=ooo.oshi
to my VM arguments in run configurations... done!)If you start a tutorial that has you use
jlink
, stop. It won't be helpful for you here. You need to use the basic method invoking and memory functions described in JEP 424. These largely have a direct correspondence to the existing JNA implementations. Some code is already committed for macOS process listings that gives a good feel for all the possibilities.For methods and structures, check out the
SystemLibrary
class for macOS and usages inSysctlUtil
,MacOperatingSystem
andMacOSProcess
. There should be enough examples there to hint you toward modeling new data structures. In summary:There's probably going to be a need for a generic IntByReference and LongByReference equivalent at some point...
Priority:
Anything you can contribute. If it's your first time doing a FFM function, pick an easy one. Any help is appreciated. Truly. Don't know where to put it in the API? Don't worry! Just submit a standalone class with the implementation and we'll move it to where it's needed!
Util classes covering multiple fetches (performance counters, sysctl, WMI).
Hot Path: Process listing (macOS is done, other OS's need it) or CPU ticks listing
The text was updated successfully, but these errors were encountered: