Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Port an OSHI JNA-based method to OSHI-FFM #4

@dbwiddis

Description

@dbwiddis

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:

  1. 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!

  2. Util classes covering multiple fetches (performance counters, sysctl, WMI).

  3. Hot Path: Process listing (macOS is done, other OS's need it) or CPU ticks listing

Metadata

Metadata

Assignees

No one assigned

    Labels

    hacktoberfestGet credit for PRs during Hacktoberfest!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions