ffi 1.18: #jni_call(s32) → CallIntMethod (slot 49) — make-green
One-line addition to the `call_method_offset` switch in
`emit_llvm.zig` — `.s32 => 49` (CallIntMethod). The 1.17 caching
infrastructure handles the rest: GetObjectClass → NewGlobalRef →
GetMethodID populate the shared `@SX_JNI_{CLS,MID}_<key>` pair on
miss; per-call lowering loads the cached jmethodID and dispatches
through vtable slot 49 with an `i32` return.
IR snapshot at `tests/expected/ffi-jni-call-04-jint-return.ir`
updated: the `ret i32 undef` placeholder is replaced by the full
lazy-cache + CallIntMethod sequence keyed on
`("getCount", "()I")`. Pre-1.18 snapshot was 1d7ea72.
This commit is contained in:
@@ -1220,6 +1220,7 @@ pub const LLVMEmitter = struct {
|
||||
const ret_ty_id = instruction.ty;
|
||||
const call_method_offset: u32 = switch (ret_ty_id) {
|
||||
.void => 61, // CallVoidMethod
|
||||
.s32 => 49, // CallIntMethod
|
||||
else => {
|
||||
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
@g_should_call = internal global i1 false
|
||||
@str = private unnamed_addr constant [9 x i8] c"getCount\00", align 1
|
||||
@str.1 = private unnamed_addr constant [4 x i8] c"()I\00", align 1
|
||||
@SX_JNI_CLS_getCount____I = internal global ptr null
|
||||
@SX_JNI_MID_getCount____I = 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 i32 undef
|
||||
%jni.ifs = load ptr, ptr %load, align 8
|
||||
%jni.cached.mid = load ptr, ptr @SX_JNI_MID_getCount____I, 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_getCount____I, 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_getCount____I, 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 49
|
||||
%jni.callfn = load ptr, ptr %5, align 8
|
||||
%jni.ret = call i32 %jni.callfn(ptr %load, ptr %loadN, ptr %jni.mid)
|
||||
ret i32 %jni.ret
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
|
||||
Reference in New Issue
Block a user