{"id":48547773,"url":"https://github.com/smallrye/smallrye-ffm","last_synced_at":"2026-04-08T07:30:49.046Z","repository":{"id":341077790,"uuid":"1162008800","full_name":"smallrye/smallrye-ffm","owner":"smallrye","description":"A utility to simplify usage of the Java FFM API","archived":false,"fork":false,"pushed_at":"2026-03-06T21:25:25.000Z","size":97,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-07T01:17:56.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smallrye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-19T19:13:43.000Z","updated_at":"2026-03-06T21:25:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/smallrye/smallrye-ffm","commit_stats":null,"previous_names":["smallrye/smallrye-ffm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/smallrye/smallrye-ffm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallrye%2Fsmallrye-ffm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallrye%2Fsmallrye-ffm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallrye%2Fsmallrye-ffm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallrye%2Fsmallrye-ffm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallrye","download_url":"https://codeload.github.com/smallrye/smallrye-ffm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallrye%2Fsmallrye-ffm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31545904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"online","status_checked_at":"2026-04-08T02:00:06.127Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-08T07:30:48.382Z","updated_at":"2026-04-08T07:30:49.031Z","avatar_url":"https://github.com/smallrye.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SmallRye FFM\n\n## Overview\n\nSmallRye FFM is a utility to simplify usage of the Java FFM API.\nIt is used by way of an API module plus a build system plugin.\n\nUsing the SmallRye FFM API, native functions can be modelled using the `native` method feature of the Java language.\nThe build system plugin replaces these methods with methods which use the special `invokedynamic` JVM instruction to lazily link to native functions.\n\n## Usage\n\n### Maven\n\nTo use SmallRye FFM, the API artifact dependency and the build system plugin must be added to build.\n\nTo add the API dependency using Maven, add the following to the `dependencies` section of your project `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.smallrye.ffm\u003c/groupId\u003e\n    \u003cartifactId\u003esmallrye-ffm\u003c/artifactId\u003e\n    \u003cversion\u003eLATEST\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nYou should replace `LATEST` with the latest release version in order to ensure a stable build.\n\nTo add the plugin using Maven, add the following to the `plugins` sub-element of the `build` section of your project `pom.xml`:\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eio.smallrye.ffm\u003c/groupId\u003e\n    \u003cartifactId\u003esmallrye-ffm-maven-plugin\u003c/artifactId\u003e\n    \u003cversion\u003eLATEST\u003c/version\u003e\n    \u003cexecutions\u003e\n        \u003cexecution\u003e\n            \u003cid\u003effm\u003c/id\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003etransform\u003c/goal\u003e\n            \u003c/goals\u003e\n        \u003c/execution\u003e\n        \u003cexecution\u003e\n            \u003cid\u003effm-test\u003c/id\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003etransform-test\u003c/goal\u003e\n            \u003c/goals\u003e\n        \u003c/execution\u003e\n    \u003c/executions\u003e\n\u003c/plugin\u003e\n```\n\nAgain, you should replace `LATEST` with the latest release version in order to ensure a stable build.\n\n### Native function methods\n\nTo declare a native function method, create a `native` method in your class\n(it can be a `static` method or an instance method)\nand annotate it with the `@Link` annotation.\n\n```java\n// simple example: call the libc `cosf` function\n@Link\nprivate static native float cosf(float value);\n```\n\nThe first invocation of this method will link the call site before invoking the function.\nSubsequent invocations will directly invoke the function through the linked downcall method handle.\nIf the function cannot be linked, calling the native method will result in an `UnsatisfiedLinkError` being thrown.\n\n### Types and `@As`\n\nThe C ABI and calling conventions allow a high degree of variability between platforms.\nBasic C types, such as `int` or `long`, may have different sizes between platforms.\nAdditionally, the signedness of `char` is highly platform-dependent.\nThe ABI for certain OSes and/or CPUs may also specify special rules for handling certain value types.\n\nTherefore, to ensure correct operation, it is usually necessary to declare the C type of each\nfunction argument and the function return value.\nThis allows SmallRye FFM to apply the correct integer conversion at link time to ensure correct operation.\nThis can be accomplished using the `@As` annotation.\n\nThe `@As` annotation takes a single value which corresponds to the native C type to use for a given argument\nor the method return value.\n\nThe following example specifies the type of both the argument and return type of a function\nto correspond to the C `long int` type, whose size is platform-dependent.\n\n```java\n// example of specifying explicit types\n@Link\n@As(stdc_long)\nprivate static native long labs(@As(stdc_long) long value);\n```\n\n### Supported types\n\nThe full set of supported types is found and documented in the `AsType` enumeration.\nSome of the more frequently useful types are:\n\n* `stdc_char` - the C `char` type\n* `stdc_unsigned_char` - the C `unsigned char` type\n* `stdc_int` - the C signed `int` type, also useful for `enum` type arguments\n* `stdc_unsigned_int` - the C `unsigned int` type\n* `f32` - a 32-bit float type (usable for the C type `float`)\n* `f64` - a 64-bit float type (usable for the C type `double`)\n* `intptr` and `uintptr` - signed and unsigned pointer-sized integer (usable for the standard C types `intptr_t` and `uintptr_t`)\n* `size_t` and `ssize_t` - unsigned and signed integers frequently used in standard C and POSIX functions\n* `ptr` - a pointer value (use this in conjunction with `MemorySegment`, `String`, or primitive arrays)\n\nBy default, this is the mapping of Java types to `AsType` constants:\n\n* `byte` - `AsType.s8`\n* `short` - `AsType.s16`\n* `char` - `AsType.u16`\n* `int` - `AsType.s32`\n* `long` - `AsType.s64`\n* `boolean` - `AsType.stdc_bool`\n* `float` - `AsType.f32`\n* `double` - `AsType.f64`\n* `MemorySegment`, primitive arrays, and `String` - `AsType.ptr`\n\n### `Errno` support\n\nSmallRye FFM includes an enumeration called `Errno` which can be used as an integer argument or return type.\nBecause it is a Java `enum`, `Errno` values can be used in `switch` statements.\n\nSince most standard C or POSIX functions do not return `Errno` directly, there is also an `ErrnoConsumer`\ninterface which can provided as an argument to the `native` method.\nThe consumer will be populated with the `Errno` constant after the method is called.\nNote that many APIs do not specify whether the `Errno` value is sensible if the operation succeeded,\nso care should be taken to check the result of the function before using the error value\nif the function has a separate success indicator.\n\n```java\n// example of handling errno\n@Link\nprivate static native double log(double value, ErrnoConsumer handler);\n\npublic static double log(double value) throws ArithmeticException {\n    var errnoHolder = new ErrnoConsumer() {\n        Errno errno;\n\n        public void accept(Errno errno) {\n            this.errno = errno;\n        }\n    };\n    double result = log(value, errnoHolder);\n    if (errnoHolder.errno != Errno.SUCCESS) {\n        throw new ArithmeticException(errnoHolder.errno.message());\n    }\n    return result;\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallrye%2Fsmallrye-ffm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallrye%2Fsmallrye-ffm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallrye%2Fsmallrye-ffm/lists"}