From 47007c2a22853c910dc684851db80c2105aae8f3 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Sun, 14 Sep 2025 11:22:42 +0300 Subject: [PATCH 1/3] [mono][metadata] Enable compressed interface bitmap by default --- src/mono/mono/metadata/class-internals.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/mono/mono/metadata/class-internals.h b/src/mono/mono/metadata/class-internals.h index bc8e9729702943..4f0b60c29d2f97 100644 --- a/src/mono/mono/metadata/class-internals.h +++ b/src/mono/mono/metadata/class-internals.h @@ -287,11 +287,7 @@ union _MonoClassSizes { int generic_param_token; /* for generic param types, both var and mvar */ }; -/* enabled only with small config for now: we might want to do it unconditionally */ -#ifdef MONO_SMALL_CONFIG #define COMPRESSED_INTERFACE_BITMAP 1 -#endif - #ifdef ENABLE_CHECKED_BUILD_PRIVATE_TYPES #define MONO_CLASS_DEF_PRIVATE 1 From 92c7d702c0410477bd4a1f587d86e95c788e0da8 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Mon, 15 Sep 2025 15:21:22 +0300 Subject: [PATCH 2/3] Fix build on windows --- src/mono/mono/metadata/class-init.c | 4 ++-- src/mono/mono/mini/type-checking.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index 92ce8abddddbe9..2f834a8e78b84d 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -1805,7 +1805,7 @@ mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size) while (bitmap < end) { if (*bitmap || numz == 255) { if (dest) { - *dest++ = numz; + *dest++ = (uint8_t)numz; *dest++ = *bitmap; } res += 2; @@ -1819,7 +1819,7 @@ mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size) if (numz) { res += 2; if (dest) { - *dest++ = numz; + *dest++ = (uint8_t)numz; *dest++ = 0; } } diff --git a/src/mono/mono/mini/type-checking.c b/src/mono/mono/mini/type-checking.c index 6f453f88610ff4..41b0f2c0054e5a 100644 --- a/src/mono/mono/mini/type-checking.c +++ b/src/mono/mono/mini/type-checking.c @@ -137,7 +137,7 @@ mini_emit_interface_bitmap_check (MonoCompile *cfg, int intf_bit_reg, int base_r #ifdef COMPRESSED_INTERFACE_BITMAP MonoInst *args [2]; MonoInst *res, *ins; - NEW_LOAD_MEMBASE (cfg, ins, OP_LOAD_MEMBASE, ibitmap_reg, base_reg, offset); + NEW_LOAD_MEMBASE (cfg, ins, OP_LOAD_MEMBASE, ibitmap_reg, base_reg, (target_mgreg_t)offset); MONO_ADD_INS (cfg->cbb, ins); args [0] = ins; args [1] = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_IID, klass); From b62f4555f02cdb3d4e6d25dd7a779cb4455600d4 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Mon, 15 Sep 2025 15:24:38 +0300 Subject: [PATCH 3/3] Fix publishing of compressed bitmap Before this commit we were doing changes on the published data which is problematic for multithreaded environments. We ensure the bitmap is fully processed before publishing it so that we can rely on the data dependency memory ordering constraint for correctness. --- src/mono/mono/metadata/class-setup-vtable.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/metadata/class-setup-vtable.c b/src/mono/mono/metadata/class-setup-vtable.c index 618e6b05019abe..2d0a245e033be0 100644 --- a/src/mono/mono/metadata/class-setup-vtable.c +++ b/src/mono/mono/metadata/class-setup-vtable.c @@ -346,10 +346,12 @@ mono_class_setup_interface_offsets_internal (MonoClass *klass, int cur_slot, int } if (!klass->interface_bitmap) { #ifdef COMPRESSED_INTERFACE_BITMAP - int i = mono_compress_bitmap (NULL, bitmap, bsize); - klass->interface_bitmap = mono_class_alloc0 (klass, i); - mono_compress_bitmap (klass->interface_bitmap, bitmap, bsize); + int len = mono_compress_bitmap (NULL, bitmap, bsize); + uint8_t *compressed_bitmap = mono_class_alloc0 (klass, len); + mono_compress_bitmap (compressed_bitmap, bitmap, bsize); g_free (bitmap); + + klass->interface_bitmap = compressed_bitmap; #else klass->interface_bitmap = bitmap; #endif