File 0583-jit-Add-debug-code-in-emit_enter_runtime-to-catch-mi.patch of Package erlang

From 59696d50538e7168d77c1374c64e9016e54a4896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Wed, 7 Feb 2024 14:19:25 +0100
Subject: [PATCH] jit: Add debug code in emit_enter_runtime to catch missing
 updates

---
 erts/emulator/beam/jit/arm/beam_asm.hpp | 22 ++++++++++++++++++----
 erts/emulator/beam/jit/x86/beam_asm.hpp | 24 ++++++++++++++++++++----
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/erts/emulator/beam/jit/arm/beam_asm.hpp b/erts/emulator/beam/jit/arm/beam_asm.hpp
index 8ef609f4b2..8fc8a7b411 100644
--- a/erts/emulator/beam/jit/arm/beam_asm.hpp
+++ b/erts/emulator/beam/jit/arm/beam_asm.hpp
@@ -461,10 +461,24 @@ protected:
             /* Store HTOP and E in one go. */
             ERTS_CT_ASSERT_FIELD_PAIR(Process, htop, stop);
             a.stp(HTOP, E, arm::Mem(c_p, offsetof(Process, htop)));
-        } else if (Spec & Update::eStack) {
-            a.str(E, arm::Mem(c_p, offsetof(Process, stop)));
-        } else if (Spec & Update::eHeap) {
-            a.str(HTOP, arm::Mem(c_p, offsetof(Process, htop)));
+        } else {
+            if (Spec & Update::eStack) {
+                a.str(E, arm::Mem(c_p, offsetof(Process, stop)));
+            } else {
+#ifdef DEBUG
+                /* Store some garbage in the process structure to catch missing
+                 * updates. */
+                a.str(active_code_ix, arm::Mem(c_p, offsetof(Process, stop)));
+#endif
+            }
+
+            if (Spec & Update::eHeap) {
+                a.str(HTOP, arm::Mem(c_p, offsetof(Process, htop)));
+            } else {
+#ifdef DEBUG
+                a.str(active_code_ix, arm::Mem(c_p, offsetof(Process, htop)));
+#endif
+            }
         }
 
         if (Spec & Update::eReductions) {
diff --git a/erts/emulator/beam/jit/x86/beam_asm.hpp b/erts/emulator/beam/jit/x86/beam_asm.hpp
index c7f085ee62..585ada4d59 100644
--- a/erts/emulator/beam/jit/x86/beam_asm.hpp
+++ b/erts/emulator/beam/jit/x86/beam_asm.hpp
@@ -641,10 +641,26 @@ protected:
                 a.punpcklqdq(x86::xmm0, x86::xmm1);
                 a.movups(x86::xmmword_ptr(c_p, offsetof(Process, htop)),
                          x86::xmm0);
-            } else if (Spec & Update::eHeap) {
-                a.mov(x86::qword_ptr(c_p, offsetof(Process, htop)), HTOP);
-            } else if (Spec & Update::eStack) {
-                a.mov(x86::qword_ptr(c_p, offsetof(Process, stop)), E);
+            } else {
+                if (Spec & Update::eHeap) {
+                    a.mov(x86::qword_ptr(c_p, offsetof(Process, htop)), HTOP);
+                } else {
+#ifdef DEBUG
+                    /* Store some garbage in the process structure to catch
+                     * missing updates. */
+                    a.mov(x86::qword_ptr(c_p, offsetof(Process, htop)),
+                          active_code_ix);
+#endif
+                }
+
+                if (Spec & Update::eStack) {
+                    a.mov(x86::qword_ptr(c_p, offsetof(Process, stop)), E);
+                } else {
+#ifdef DEBUG
+                    a.mov(x86::qword_ptr(c_p, offsetof(Process, stop)),
+                          active_code_ix);
+#endif
+                }
             }
 
 #ifdef NATIVE_ERLANG_STACK
-- 
2.35.3

openSUSE Build Service is sponsored by