Jvm.NET 1.0.0
Jvm.NET 1.0.0
首个正式版本发布!纯 C# 实现的进程内 JVM 嵌入库,支持 OpenJDK 21 LTS。
First stable release! A pure C# library for embedding an in-process JVM with OpenJDK 21 LTS support.
核心功能 / Features
进程内 JVM 嵌入 / In-process JVM Embedding
- 通过
JNI_CreateJavaVM在当前 .NET 进程内启动完整的 OpenJDK 21 LTS JVM - Start a full OpenJDK 21 LTS JVM inside the current .NET process via
JNI_CreateJavaVM - 自动加载
jvm.dll/libjvm.so/libjvm.dylib,支持bin/server/、lib/server/fallback 路径 - Auto-loads
jvm.dll/libjvm.so/libjvm.dylibwithbin/server/andlib/server/fallback paths
JNI 方法调用 / JNI Method Invocation
FindClass/LoadClass/NewObject/InvokeStatic/InvokeVirtual/RunMain- 支持静态方法、实例方法、构造函数、
main(String[])入口 - Supports static, instance, constructor, and
main(String[])invocation - 自动 global ref 提升,避免 jclass 失效
- Auto global ref promotion prevents jclass invalidation
JVMTI 字节码修改 / JVMTI Bytecode Modification
ClassFileLoadHook:类加载时拦截并改写字节码RetransformClasses:对已加载类重新触发 hookRedefineClasses:直接替换已加载类的字节码IBytecodeTransformer插件式架构,RegisterTransformer返回IDisposable自动注销
JVMTI 事件监听 / JVMTI Event Listening
- 原生支持:
VMInit/VMDeath/ThreadStart/ThreadEnd/ClassLoad/ClassPrepare - Native support:
VMInit/VMDeath/ThreadStart/ThreadEnd/ClassLoad/ClassPrepare - 方案 B 字节码插桩模拟:
MethodEntry/MethodExit/Exception- Scheme B bytecode instrumentation simulation:
MethodEntry/MethodExit/Exception - 通过
ClassFileLoadHook在目标方法字节码中注入invokestatic调用桥接类com.xsy.jn.JnBridge - Injects
invokestaticcalls to bridge classcom.xsy.jn.JnBridgeviaClassFileLoadHook - 绕过
onload-onlycapability 限制(嵌入式 JVM 启动后已处于 live 阶段) - Bypasses
onload-onlycapability restriction (embedded JVM is already in live phase after startup) - 构造函数
<init>跳过 Exception 插桩(避免 stackmap frame 不匹配) - Constructor
<init>skips Exception instrumentation (avoids stackmap frame mismatch)
- Scheme B bytecode instrumentation simulation:
自带 ASM 字节码库 / Bundled ASM Bytecode Library
- 纯 C# 移植的 ASM 核心(22 个文件),不依赖 IKVM 或 Java
- Pure C# port of ASM core (22 files), no IKVM or Java dependency
ClassReader/ClassWriter/MethodVisitor完整访问者模式- Full visitor pattern:
ClassReader/ClassWriter/MethodVisitor - 常量池自动重建,支持不等长字符串替换(如
"Hello from Java!"→"HACKED by ASM") - Auto constant pool rebuild, supports unequal-length string replacement
- 正确处理
invokedynamic(JDK 9+ 字符串拼接makeConcatWithConstants) - Correctly handles
invokedynamic(JDK 9+ string concatenationmakeConcatWithConstants) COMPUTE_MAXS自动计算栈深度,手动 stackmap frame 生成COMPUTE_MAXSauto stack depth, manual stackmap frame generation
跨平台 / Cross-platform
- 支持
net8.0/net9.0/net10.0 - Supports
net8.0/net9.0/net10.0 - Windows / Linux / macOS(x64 / arm64)
- 不使用平台特定 API(如 WinAPI)
文档 / Documentation
- 中英双语 README、API 参考、实现原理文档
- Bilingual README, API reference, and implementation notes
- https://github.com/XSY-HYH/Jvm.NET#readme
测试 / Tests
Jvm.NET.Harness包含 8 个集成测试,覆盖所有核心功能Jvm.NET.Harnessincludes 8 integration tests covering all core features- 所有测试通过(exit code 0)
- All tests pass (exit code 0)
许可证 / License
MIT © XSY_xiaoqi