Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Java Interoperating with Golang
Search
swt02026
April 23, 2019
Programming
70
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Java Interoperating with Golang
GraalVM
JNI
swt02026
April 23, 2019
More Decks by swt02026
See All by swt02026
Interoperating Golang with Swift
swt02026
0
60
Java Interoperating with Golang V2
swt02026
0
54
Other Decks in Programming
See All in Programming
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
Domain-Driven Transformation
hschwentner
2
2.3k
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
Railsバージョンを4倍にした話
optim
0
350
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
ChromeでローカルLLM
ryu1013
0
140
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
170
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
A Soul's Torment
seathinner
8
3.8k
My Coaching Mixtape
mlcsv
0
360
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
330
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Typedesign – Prime Four
hannesfritz
42
3.2k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Transcript
Create Go Library for Java https://tinyurl.com/yy6kws3n 簡報連結 https://tinyurl.com/yxq97hj3 Colab連結 https://tinyurl.com/yypgxmwh
Source Repo
[email protected]
Kuan Ting, Lee
為什麼今天要講這個題目呢?
你想的沒錯!
媽祖託夢叫我講的
我喜歡雜交 Hybrid Programming
先決條件 • 不進行兩個語言間的 Struct / Class / Object 傳遞 •
Java 主動呼叫 Go Binary • 中間產生 Binary 除了 .class 檔,其餘 C ABI 為主 • 不處理非跨平台部分,如 ◦ OS ◦ 專用硬體 ◦ 編譯器預設行為 • 不涉及 JVM 跟 Go Runtime 的 LifeCycle ,如 ◦ Exception ◦ Goroutine ◦ Thread ◦ Garbage Collection ◦ Schedule
Go的部分講完,大家可以走了
Go程式產出 Shared Library • 被使用的 function 加上 "//export <function name>"
• 執行"go build -buildmode" • 產出 .so 檔與 .h • 此時產出的 .so 符合 C ABI
方法一: Java Native Interface(JNI) • 利用 JVM 外掛機制,使 Java 程式可以執行
C 撰寫的程式 • Java 程式 ◦ 針對需要綁定 Native Function 的 Method 加上"native" ◦ 使用"System.loadLibrary" 提示 JVM 執行時要載入的 Library (.so) • 執行 "javah -jni" • 產出 .h 檔,再依照 .h 中的 Prototype 撰寫 .c • 執行 "gcc -fpie -shared",將 C source 轉換成 .so • 使用 JVM 載入 .class 檔,便會自動載入 .so 檔 • Java 程式會動態利用 JVM 的服務,依照 JVM Life Cycle 運作
None
JVM JNI Class File JNI C Library Go Library OS
Loader
方法二: Native Images in Oracle GraalVM • Java AOT Compiler
的實作 • Java程式加入 Annotation 使 C Header 與 Library 資訊加入 .class檔 • 執行 "javac" 產出 .class檔 • 執行 "native-image" 將 .class 編譯成 Native Object File,此時會進行 Object Linking,解析 .so 中的 Symbol • 執行產出的 Native Object File 則會使用 OS 預設 Loading 行為 • Binary 中原先 JVM 行為,改由 GraalVM 提供的 SubstrateVM 抽象層嵌入 Binary 中(類似 Go Runtime)
None
Class File Go Library OS Loader GraalVM Tool Chain Native
Object
JNI vs Native Images JNI • JDK 版本間介面異動不大 • 需要自行撰寫
C Source • 必須要有 JVM • 需要在 C 程式中使用反射才得以存取 Object/Struct 欄位 Native Images • 新技術,版本間異動較大,較不穩定 • 可直接使用現有的 C ABI Library • 無需 JVM • Native Image 提供 Annotation 綁定需要 的欄位即可
方法三: 使用 LLVM 生態系 • 使用 llgo 將 go 程式編譯成
LLVM bitcode • 使用 GraalVM 1. sulong : LLVM bitcode to Truffle AST 2. Polyglot : 隔離 Truffle 與 sulong 之間運作 (Heap address) 3. Truffle : AST Runtime
LLVM bitcode (gen by llgo) Class File JVM Truffle polyglot
API LLVM bitcode to AST (sulong)