File 4716-erts-Move-erts_get_ethread_info-implementation.patch of Package erlang

From d1f1015ffad3cb1c4f1831a2d8e27d173a7502c2 Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Mon, 27 Jan 2020 15:29:24 -0800
Subject: [PATCH 06/11] erts: Move erts_get_ethread_info implementation

The new Windows compiler (2019), seems to have some bug
that makes this function inline the erts_bld functions
incorrectly which causes the emulator to crash. Maybe
someday this will be fixed, but for now keep it in another
file so that no inlining will be done.
---
 erts/emulator/beam/erl_bif_info.c | 194 +++++++++++++++++++++++++++++++++++++
 erts/emulator/beam/utils.c        | 195 --------------------------------------
 2 files changed, 194 insertions(+), 195 deletions(-)

diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c
index 5945bf48d9..26020ef5b2 100644
--- a/erts/emulator/beam/erl_bif_info.c
+++ b/erts/emulator/beam/erl_bif_info.c
@@ -4797,6 +4797,200 @@ BIF_RETTYPE erts_debug_set_internal_state_2(BIF_ALIST_2)
     BIF_ERROR(BIF_P, BADARG);
 }
 
+Eterm
+erts_get_ethread_info(Process *c_p)
+{
+    Uint sz, *szp;
+    Eterm res, *hp, **hpp, *end_hp = NULL;
+
+    sz = 0;
+    szp = &sz;
+    hpp = NULL;
+
+    while (1) {
+	Eterm tup, list, name;
+#if defined(ETHR_NATIVE_ATOMIC32_IMPL)	  \
+    || defined(ETHR_NATIVE_ATOMIC64_IMPL)	\
+    || defined(ETHR_NATIVE_DW_ATOMIC_IMPL)
+	char buf[1024];
+	int i;
+	char **str;
+#endif
+
+	res = NIL;
+
+#ifdef ETHR_X86_MEMBAR_H__
+
+	tup = erts_bld_tuple(hpp, szp, 2,
+			     erts_bld_string(hpp, szp, "sse2"),
+#ifdef ETHR_X86_RUNTIME_CONF_HAVE_SSE2__
+			     erts_bld_string(hpp, szp,
+					     (ETHR_X86_RUNTIME_CONF_HAVE_SSE2__
+					      ? "yes" : "no"))
+#else
+			     erts_bld_string(hpp, szp, "yes")
+#endif
+	    );
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+	tup = erts_bld_tuple(hpp, szp, 2,
+			     erts_bld_string(hpp, szp,
+					     "x86"
+#ifdef ARCH_64
+					     "_64"
+#endif
+					     " OOO"),
+			     erts_bld_string(hpp, szp,
+#ifdef ETHR_X86_OUT_OF_ORDER
+					     "yes"
+#else
+					     "no"
+#endif
+				 ));
+
+	res = erts_bld_cons(hpp, szp, tup, res);
+#endif
+
+#ifdef ETHR_SPARC_V9_MEMBAR_H__
+
+	tup = erts_bld_tuple(hpp, szp, 2,
+			     erts_bld_string(hpp, szp, "Sparc V9"),
+			     erts_bld_string(hpp, szp,
+#if defined(ETHR_SPARC_TSO)
+					     "TSO"
+#elif defined(ETHR_SPARC_PSO)
+					     "PSO"
+#elif defined(ETHR_SPARC_RMO)
+					     "RMO"
+#else
+					     "undefined"
+#endif
+				 ));
+
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+#endif
+
+#ifdef ETHR_PPC_MEMBAR_H__
+
+	tup = erts_bld_tuple(hpp, szp, 2,
+			     erts_bld_string(hpp, szp, "lwsync"),
+			     erts_bld_string(hpp, szp,
+#if defined(ETHR_PPC_HAVE_LWSYNC)
+					     "yes"
+#elif defined(ETHR_PPC_HAVE_NO_LWSYNC)
+					     "no"
+#elif defined(ETHR_PPC_RUNTIME_CONF_HAVE_LWSYNC__)
+					     ETHR_PPC_RUNTIME_CONF_HAVE_LWSYNC__ ? "yes" : "no"
+#else
+					     "undefined"
+#endif
+				 ));
+
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+#endif
+
+	tup = erts_bld_tuple(hpp, szp, 2,
+			     erts_bld_string(hpp, szp, "Native rw-spinlocks"),
+#ifdef ETHR_NATIVE_RWSPINLOCK_IMPL
+			     erts_bld_string(hpp, szp, ETHR_NATIVE_RWSPINLOCK_IMPL)
+#else
+			     erts_bld_string(hpp, szp, "no")
+#endif
+	    );
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+	tup = erts_bld_tuple(hpp, szp, 2,
+			     erts_bld_string(hpp, szp, "Native spinlocks"),
+#ifdef ETHR_NATIVE_SPINLOCK_IMPL
+			     erts_bld_string(hpp, szp, ETHR_NATIVE_SPINLOCK_IMPL)
+#else
+			     erts_bld_string(hpp, szp, "no")
+#endif
+	    );
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+
+	list = NIL;
+#ifdef ETHR_NATIVE_DW_ATOMIC_IMPL
+	if (ethr_have_native_dw_atomic()) {
+	    name = erts_bld_string(hpp, szp, ETHR_NATIVE_DW_ATOMIC_IMPL);
+	    str = ethr_native_dw_atomic_ops();
+	    for (i = 0; str[i]; i++) {
+		erts_snprintf(buf, sizeof(buf), "ethr_native_dw_atomic_%s()", str[i]);
+		list = erts_bld_cons(hpp, szp,
+				     erts_bld_string(hpp, szp, buf),
+				     list);
+	    }
+	    str = ethr_native_su_dw_atomic_ops();
+	    for (i = 0; str[i]; i++) {
+		erts_snprintf(buf, sizeof(buf), "ethr_native_su_dw_atomic_%s()", str[i]);
+		list = erts_bld_cons(hpp, szp,
+				     erts_bld_string(hpp, szp, buf),
+				     list);
+	    }
+	}
+	else 
+#endif
+	    name = erts_bld_string(hpp, szp, "no");
+
+	tup = erts_bld_tuple(hpp, szp, 3,
+			     erts_bld_string(hpp, szp, "Double word native atomics"),
+			     name,
+			     list);
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+	list = NIL;
+#ifdef ETHR_NATIVE_ATOMIC64_IMPL
+	name = erts_bld_string(hpp, szp, ETHR_NATIVE_ATOMIC64_IMPL);
+	str = ethr_native_atomic64_ops();
+	for (i = 0; str[i]; i++) {
+	    erts_snprintf(buf, sizeof(buf), "ethr_native_atomic64_%s()", str[i]);
+	    list = erts_bld_cons(hpp, szp,
+				 erts_bld_string(hpp, szp, buf),
+				 list);
+	}
+#else
+	name = erts_bld_string(hpp, szp, "no");
+#endif
+	tup = erts_bld_tuple(hpp, szp, 3,
+			     erts_bld_string(hpp, szp, "64-bit native atomics"),
+			     name,
+			     list);
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+	list = NIL;
+#ifdef ETHR_NATIVE_ATOMIC32_IMPL
+	name = erts_bld_string(hpp, szp, ETHR_NATIVE_ATOMIC32_IMPL);
+	str = ethr_native_atomic32_ops();
+	for (i = 0; str[i]; i++) {
+	    erts_snprintf(buf, sizeof(buf), "ethr_native_atomic32_%s()", str[i]);
+	    list = erts_bld_cons(hpp, szp,
+				erts_bld_string(hpp, szp, buf),
+				list);
+	}
+#else
+	name = erts_bld_string(hpp, szp, "no");
+#endif
+	tup = erts_bld_tuple(hpp, szp, 3,
+			     erts_bld_string(hpp, szp, "32-bit native atomics"),
+			     name,
+			     list);
+	res = erts_bld_cons(hpp, szp, tup, res);
+
+	if (hpp) {
+	    HRelease(c_p, end_hp, *hpp)
+	    return res;
+	}
+
+	hp = HAlloc(c_p, sz);
+	end_hp = hp + sz;
+	hpp = &hp;
+	szp = NULL;
+    }
+}
+
 static BIF_RETTYPE
 gather_histograms_helper(Process * c_p, Eterm arg_tuple,
                          int gather(Process *, int, int, int, UWord, Eterm))
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c
index d6e069f756..42cc5bd236 100644
--- a/erts/emulator/beam/utils.c
+++ b/erts/emulator/beam/utils.c
@@ -4883,201 +4883,6 @@ erts_get_emu_args(Process *c_p)
     return res;
 }
 
-
-Eterm
-erts_get_ethread_info(Process *c_p)
-{
-    Uint sz, *szp;
-    Eterm res, *hp, **hpp, *end_hp = NULL;
-
-    sz = 0;
-    szp = &sz;
-    hpp = NULL;
-
-    while (1) {
-	Eterm tup, list, name;
-#if defined(ETHR_NATIVE_ATOMIC32_IMPL)	  \
-    || defined(ETHR_NATIVE_ATOMIC64_IMPL)	\
-    || defined(ETHR_NATIVE_DW_ATOMIC_IMPL)
-	char buf[1024];
-	int i;
-	char **str;
-#endif
-
-	res = NIL;
-
-#ifdef ETHR_X86_MEMBAR_H__
-
-	tup = erts_bld_tuple(hpp, szp, 2,
-			     erts_bld_string(hpp, szp, "sse2"),
-#ifdef ETHR_X86_RUNTIME_CONF_HAVE_SSE2__
-			     erts_bld_string(hpp, szp,
-					     (ETHR_X86_RUNTIME_CONF_HAVE_SSE2__
-					      ? "yes" : "no"))
-#else
-			     erts_bld_string(hpp, szp, "yes")
-#endif
-	    );
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-	tup = erts_bld_tuple(hpp, szp, 2,
-			     erts_bld_string(hpp, szp,
-					     "x86"
-#ifdef ARCH_64
-					     "_64"
-#endif
-					     " OOO"),
-			     erts_bld_string(hpp, szp,
-#ifdef ETHR_X86_OUT_OF_ORDER
-					     "yes"
-#else
-					     "no"
-#endif
-				 ));
-
-	res = erts_bld_cons(hpp, szp, tup, res);
-#endif
-
-#ifdef ETHR_SPARC_V9_MEMBAR_H__
-
-	tup = erts_bld_tuple(hpp, szp, 2,
-			     erts_bld_string(hpp, szp, "Sparc V9"),
-			     erts_bld_string(hpp, szp,
-#if defined(ETHR_SPARC_TSO)
-					     "TSO"
-#elif defined(ETHR_SPARC_PSO)
-					     "PSO"
-#elif defined(ETHR_SPARC_RMO)
-					     "RMO"
-#else
-					     "undefined"
-#endif
-				 ));
-
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-#endif
-
-#ifdef ETHR_PPC_MEMBAR_H__
-
-	tup = erts_bld_tuple(hpp, szp, 2,
-			     erts_bld_string(hpp, szp, "lwsync"),
-			     erts_bld_string(hpp, szp,
-#if defined(ETHR_PPC_HAVE_LWSYNC)
-					     "yes"
-#elif defined(ETHR_PPC_HAVE_NO_LWSYNC)
-					     "no"
-#elif defined(ETHR_PPC_RUNTIME_CONF_HAVE_LWSYNC__)
-					     ETHR_PPC_RUNTIME_CONF_HAVE_LWSYNC__ ? "yes" : "no"
-#else
-					     "undefined"
-#endif
-				 ));
-
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-#endif
-
-	tup = erts_bld_tuple(hpp, szp, 2,
-			     erts_bld_string(hpp, szp, "Native rw-spinlocks"),
-#ifdef ETHR_NATIVE_RWSPINLOCK_IMPL
-			     erts_bld_string(hpp, szp, ETHR_NATIVE_RWSPINLOCK_IMPL)
-#else
-			     erts_bld_string(hpp, szp, "no")
-#endif
-	    );
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-	tup = erts_bld_tuple(hpp, szp, 2,
-			     erts_bld_string(hpp, szp, "Native spinlocks"),
-#ifdef ETHR_NATIVE_SPINLOCK_IMPL
-			     erts_bld_string(hpp, szp, ETHR_NATIVE_SPINLOCK_IMPL)
-#else
-			     erts_bld_string(hpp, szp, "no")
-#endif
-	    );
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-
-	list = NIL;
-#ifdef ETHR_NATIVE_DW_ATOMIC_IMPL
-	if (ethr_have_native_dw_atomic()) {
-	    name = erts_bld_string(hpp, szp, ETHR_NATIVE_DW_ATOMIC_IMPL);
-	    str = ethr_native_dw_atomic_ops();
-	    for (i = 0; str[i]; i++) {
-		erts_snprintf(buf, sizeof(buf), "ethr_native_dw_atomic_%s()", str[i]);
-		list = erts_bld_cons(hpp, szp,
-				     erts_bld_string(hpp, szp, buf),
-				     list);
-	    }
-	    str = ethr_native_su_dw_atomic_ops();
-	    for (i = 0; str[i]; i++) {
-		erts_snprintf(buf, sizeof(buf), "ethr_native_su_dw_atomic_%s()", str[i]);
-		list = erts_bld_cons(hpp, szp,
-				     erts_bld_string(hpp, szp, buf),
-				     list);
-	    }
-	}
-	else 
-#endif
-	    name = erts_bld_string(hpp, szp, "no");
-
-	tup = erts_bld_tuple(hpp, szp, 3,
-			     erts_bld_string(hpp, szp, "Double word native atomics"),
-			     name,
-			     list);
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-	list = NIL;
-#ifdef ETHR_NATIVE_ATOMIC64_IMPL
-	name = erts_bld_string(hpp, szp, ETHR_NATIVE_ATOMIC64_IMPL);
-	str = ethr_native_atomic64_ops();
-	for (i = 0; str[i]; i++) {
-	    erts_snprintf(buf, sizeof(buf), "ethr_native_atomic64_%s()", str[i]);
-	    list = erts_bld_cons(hpp, szp,
-				 erts_bld_string(hpp, szp, buf),
-				 list);
-	}
-#else
-	name = erts_bld_string(hpp, szp, "no");
-#endif
-	tup = erts_bld_tuple(hpp, szp, 3,
-			     erts_bld_string(hpp, szp, "64-bit native atomics"),
-			     name,
-			     list);
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-	list = NIL;
-#ifdef ETHR_NATIVE_ATOMIC32_IMPL
-	name = erts_bld_string(hpp, szp, ETHR_NATIVE_ATOMIC32_IMPL);
-	str = ethr_native_atomic32_ops();
-	for (i = 0; str[i]; i++) {
-	    erts_snprintf(buf, sizeof(buf), "ethr_native_atomic32_%s()", str[i]);
-	    list = erts_bld_cons(hpp, szp,
-				erts_bld_string(hpp, szp, buf),
-				list);
-	}
-#else
-	name = erts_bld_string(hpp, szp, "no");
-#endif
-	tup = erts_bld_tuple(hpp, szp, 3,
-			     erts_bld_string(hpp, szp, "32-bit native atomics"),
-			     name,
-			     list);
-	res = erts_bld_cons(hpp, szp, tup, res);
-
-	if (hpp) {
-	    HRelease(c_p, end_hp, *hpp)
-	    return res;
-	}
-
-	hp = HAlloc(c_p, sz);
-	end_hp = hp + sz;
-	hpp = &hp;
-	szp = NULL;
-    }
-}
-
 /*
  * To be used to silence unused result warnings, but do not abuse it.
  */
-- 
2.16.4

openSUSE Build Service is sponsored by