Skip to content

Jvm.NET 1.0.0

Choose a tag to compare

@XSY-HYH XSY-HYH released this 14 Jul 17:39

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.dylib with bin/server/ and lib/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:对已加载类重新触发 hook
  • RedefineClasses:直接替换已加载类的字节码
  • 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 invokestatic calls to bridge class com.xsy.jn.JnBridge via ClassFileLoadHook
    • 绕过 onload-only capability 限制(嵌入式 JVM 启动后已处于 live 阶段)
    • Bypasses onload-only capability restriction (embedded JVM is already in live phase after startup)
    • 构造函数 <init> 跳过 Exception 插桩(避免 stackmap frame 不匹配)
    • Constructor <init> skips Exception instrumentation (avoids stackmap frame mismatch)

自带 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 concatenation makeConcatWithConstants)
  • COMPUTE_MAXS 自动计算栈深度,手动 stackmap frame 生成
  • COMPUTE_MAXS auto 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

测试 / Tests

  • Jvm.NET.Harness 包含 8 个集成测试,覆盖所有核心功能
  • Jvm.NET.Harness includes 8 integration tests covering all core features
  • 所有测试通过(exit code 0)
  • All tests pass (exit code 0)

许可证 / License

MIT © XSY_xiaoqi