From 5945a8c176666f2c1e4302d3e32e90a075025b2a Mon Sep 17 00:00:00 2001 From: agra Date: Tue, 19 May 2026 22:30:49 +0300 Subject: [PATCH] =?UTF-8?q?ffi=201.19:=20#jni=5Fcall(s64)=20=E2=86=92=20Ca?= =?UTF-8?q?llLongMethod=20(slot=2052)=20=E2=80=94=20make-green?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One-line addition to the `call_method_offset` switch: `.s64 => Jni.CallLongMethod`. The 1.17 caching infrastructure and the named- constants struct from c1877fc handle the rest. IR snapshot at `tests/expected/ffi-jni-call-05-jlong-return.ir` updated: `ret i64 undef` replaced by the full lazy-cache + CallLongMethod (vtable slot 52) sequence keyed on `("currentTimeMillis", "()J")`. --- src/ir/emit_llvm.zig | 1 + .../expected/ffi-jni-call-05-jlong-return.ir | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ir/emit_llvm.zig b/src/ir/emit_llvm.zig index 2354b63..bca2bb4 100644 --- a/src/ir/emit_llvm.zig +++ b/src/ir/emit_llvm.zig @@ -1242,6 +1242,7 @@ pub const LLVMEmitter = struct { const call_method_offset: u32 = switch (ret_ty_id) { .void => Jni.CallVoidMethod, .s32 => Jni.CallIntMethod, + .s64 => Jni.CallLongMethod, else => { self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty))); return; diff --git a/tests/expected/ffi-jni-call-05-jlong-return.ir b/tests/expected/ffi-jni-call-05-jlong-return.ir index 94a6832..7238eaa 100644 --- a/tests/expected/ffi-jni-call-05-jlong-return.ir +++ b/tests/expected/ffi-jni-call-05-jlong-return.ir @@ -3,6 +3,8 @@ @g_should_call = internal global i1 false @str = private unnamed_addr constant [18 x i8] c"currentTimeMillis\00", align 1 @str.1 = private unnamed_addr constant [4 x i8] c"()J\00", align 1 +@SX_JNI_CLS_currentTimeMillis____J = internal global ptr null +@SX_JNI_MID_currentTimeMillis____J = internal global ptr null @str.2 = private unnamed_addr constant [4 x i8] c"ok\0A\00", align 1 @str.3 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 @@ -205,7 +207,31 @@ entry: store ptr %1, ptr %allocaN, align 8 %load = load ptr, ptr %alloca, align 8 %loadN = load ptr, ptr %allocaN, align 8 - ret i64 undef + %jni.ifs = load ptr, ptr %load, align 8 + %jni.cached.mid = load ptr, ptr @SX_JNI_MID_currentTimeMillis____J, align 8 + %jni.is.cached = icmp ne ptr %jni.cached.mid, null + br i1 %jni.is.cached, label %jni.cont, label %jni.miss + +jni.miss: ; preds = %entry + %2 = getelementptr inbounds ptr, ptr %jni.ifs, i32 31 + %jni.GetObjectClass = load ptr, ptr %2, align 8 + %jni.cls = call ptr %jni.GetObjectClass(ptr %load, ptr %loadN) + %3 = getelementptr inbounds ptr, ptr %jni.ifs, i32 21 + %jni.NewGlobalRef = load ptr, ptr %3, align 8 + %jni.global.cls = call ptr %jni.NewGlobalRef(ptr %load, ptr %jni.cls) + store ptr %jni.global.cls, ptr @SX_JNI_CLS_currentTimeMillis____J, align 8 + %4 = getelementptr inbounds ptr, ptr %jni.ifs, i32 33 + %jni.GetMethodID = load ptr, ptr %4, align 8 + %jni.fresh.mid = call ptr %jni.GetMethodID(ptr %load, ptr %jni.global.cls, ptr @str, ptr @str.1) + store ptr %jni.fresh.mid, ptr @SX_JNI_MID_currentTimeMillis____J, align 8 + br label %jni.cont + +jni.cont: ; preds = %jni.miss, %entry + %jni.mid = phi ptr [ %jni.cached.mid, %entry ], [ %jni.fresh.mid, %jni.miss ] + %5 = getelementptr inbounds ptr, ptr %jni.ifs, i32 52 + %jni.callfn = load ptr, ptr %5, align 8 + %jni.ret = call i64 %jni.callfn(ptr %load, ptr %loadN, ptr %jni.mid) + ret i64 %jni.ret } ; Function Attrs: nounwind