Skip to content

Releases: XSY-HYH/Jvm.NET

v2.2.0

Choose a tag to compare

@XSY-HYH XSY-HYH released this 17 Jul 00:11

New features / 新增功能

  • IJvmInvoker.DefineClass: Define a Java class directly from bytecode (equivalent to JNI DefineClass). Useful for ASM-generated bridge classes that need to be loaded without writing to disk.
  • IJvmInvoker.NewGlobalRef / DeleteGlobalRef: Promote JNI local references to global references, so Java objects returned by InvokeStatic / InvokeVirtual / NewObject can be held across JNI frames (e.g. stored in static fields for later callbacks).

.NET 10 compatibility / .NET 10 兼容性修复

  • JdkRuntimeBase now registers a DllImportResolver so [DllImport("jvm")] resolves to the runtime-loaded jvm.dll — avoids the .NET 10 P/Invoke thunk crash on delegate* unmanaged / Marshal.GetDelegateForFunctionPointer.
  • CreateJavaVm calls JNI_CreateJavaVM via unsafe pointers (delegate* unmanaged[Cdecl]), bypassing .NET 10 marshalling issues on out/ref IntPtr parameters.
  • NativeMethods.GetCreateJavaVMPtr returns the unmanaged function pointer directly.
  • New Interop/PInvoke.cs declares the unsafe P/Invoke entry point.

Full Changelog: v2.1.0...v2.2.0

Jvm.NET 2.0.0 — Pluggable JDK Implementations

Choose a tag to compare

@XSY-HYH XSY-HYH released this 14 Jul 19:53

Breaking Change

\JvmVersion\ enum has been replaced with a plain \int\ version number. Third-party packages can now register any JDK version (e.g. JDK 8, 11, 17) without waiting for the core package to extend an enum. Update call sites from \Version = JdkVersion.Jdk21\ to \Version = 21.

New Features

  • Pluggable JDK implementation API: implement \IJdkImplementation\ and register via \JdkImplementationRegistry.Register(...)\ before \JvmInitializer.Initialize. The core package auto-registers JDK 21-25 defaults via \ModuleInitializer.
  • Built-in JDK 22/23/24/25 support: each version has its own folder under \Abstractions/jdkXX/\ (JNI \

Jvm.NET 1.0.1

Choose a tag to compare

@XSY-HYH XSY-HYH released this 14 Jul 19:13

Jvm.NET 1.0.1

Bug fix + API addition for advanced bytecode scenarios.
Bug 修复 + 高阶字节码场景 API 补充。

Fixed / 修复

  • MethodWriter.CanCopyMethodAttributes: return false instead of throwing NotImplementedException. Enables ClassVisitor patterns that return MethodWriter directly (e.g. method body override).
    MethodWriter.CanCopyMethodAttributes:返回 false 而非抛出 NotImplementedException。支持直接返回 MethodWriterClassVisitor 模式(如方法体重写)。

Added / 新增

  • IJvmInvoker.NewStringArray(string[]): creates a Java String[] for passing to methods like main via InvokeStatic.
    IJvmInvoker.NewStringArray(string[]):创建 Java String[],用于通过 InvokeStatic 调用 main 等方法。
  • Test 9-12 covering: RedefineClasses hot-swap, RetransformClasses re-trigger, multiple transformer stacking, and main method body override.
    Test 9-12 覆盖:RedefineClasses 热替换、RetransformClasses 重走 hook、多 transformer 叠加、main 方法体覆盖。

NuGet

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