Add "Calling out to C code from Java" pattern: JNI vs FFM API#130
Merged
brunoborges merged 7 commits intomainfrom Mar 3, 2026
Merged
Add "Calling out to C code from Java" pattern: JNI vs FFM API#130brunoborges merged 7 commits intomainfrom
brunoborges merged 7 commits intomainfrom
Conversation
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Simplify C/C++ code integration with Java
Add "Calling out to C code from Java" pattern: JNI vs FFM API
Mar 2, 2026
Member
|
@copilot now add:
|
Adds YAML translation files for de, es, pt-BR, zh-CN, ar, fr, ja, ko, bn, it, pl, tr. Each file contains only translatable fields. Technical terms (JNI, FFM, javac, JNIEnv, MethodHandle, Arena, JDK 22) are unchanged in all languages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
Contributor
Author
Both are now complete:
|
Member
|
@copilot is the old code comparable in functionality with the modern code? |
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
Contributor
Author
They weren't — the old code called a custom This actually makes the comparison stronger: JNI can't call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new advanced
languagepattern contrasting the legacy JNI approach with the modern Foreign Function & Memory (FFM) API introduced in Java 22, highlighting how FFM eliminates the need for C-side Java awareness entirely.New pattern:
content/language/call-c-from-java.yamlBoth the old and modern sides call
strlen("Bambi")and print"Return value 5", making them directly comparable:native long strlen(String s)→ runjavac -h→ write a C wrapper using JNI conventions (JNIEnv*,GetStringUTFChars,ReleaseStringUTFChars, etc.) → compile and link a.sostrlendirectly from the C stdlib viaLinker,Arena, andMethodHandle— no C code required at allThe comparison highlights that JNI can't even call a simple stdlib function without a C wrapper, while FFM calls it directly:
Navigation chain
compact-canonical-constructor→call-c-from-java→enterprise/servlet-vs-jaxrsProof script:
proof/language/CallCFromJava.javastrlenvia FFM; uses//JAVA_OPTIONS --enable-native-access=ALL-UNNAMEDTranslations
de,es,pt-BR,zh-CN,ar,fr,ja,ko,bn,it,pl,trJNI,FFM,javac,JNIEnv,MethodHandle,Arena,JDK 22) are preserved untranslated in all localesOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.