File 8061-erts-Add-erts_write_heap_filler-utility-function.patch of Package erlang
From bab195a3072a3c0b25c355ba6ca3b88331b2a9ac Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Mon, 7 Oct 2024 18:32:01 +0200
Subject: [PATCH 1/2] erts: Add erts_write_heap_filler() utility function
Just to abstract away the specifics of what garbage term
we choose to write.
---
erts/emulator/beam/dist.c | 4 ++--
erts/emulator/beam/erl_bif_info.c | 2 +-
erts/emulator/beam/erl_gc.c | 2 +-
erts/emulator/beam/erl_map.c | 10 +++++-----
erts/emulator/beam/erl_term.h | 8 ++++++++
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/erts/emulator/beam/dist.c b/erts/emulator/beam/dist.c
index 59281208a6..6f2bd972b0 100644
--- a/erts/emulator/beam/dist.c
+++ b/erts/emulator/beam/dist.c
@@ -2172,10 +2172,10 @@ int erts_net_message(Port *prt,
goto decode_error;
}
- /* Fill the unused part of the hfrag with a bignum header */
+ /* Fill the unused part of the hfrag */
if (ede_hfrag && ede_hfrag->mem + ede_hfrag->used_size > factory.hp) {
Uint slot = factory.hp - ede_hfrag->mem;
- ede_hfrag->mem[slot] = make_pos_bignum_header(ede_hfrag->used_size - slot - 1);
+ erts_write_heap_filler(&ede_hfrag->mem[slot], ede_hfrag->used_size - slot);
}
if (is_not_tuple(arg) ||
diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c
index 6395bbefbd..d239d05e2a 100644
--- a/erts/emulator/beam/erl_bif_info.c
+++ b/erts/emulator/beam/erl_bif_info.c
@@ -5135,7 +5135,7 @@ BIF_RETTYPE erts_debug_set_internal_state_2(BIF_ALIST_2)
UWord left = HeapWordsLeft(BIF_P);
if (left > 1) {
Eterm* hp = HAlloc(BIF_P, left);
- *hp = make_pos_bignum_header(left - 1);
+ erts_write_heap_filler(hp, left);
}
if (BIF_ARG_2 == am_true) {
FLAGS(BIF_P) |= F_NEED_FULLSWEEP;
diff --git a/erts/emulator/beam/erl_gc.c b/erts/emulator/beam/erl_gc.c
index 49d75171b2..910b4dd8a5 100644
--- a/erts/emulator/beam/erl_gc.c
+++ b/erts/emulator/beam/erl_gc.c
@@ -567,7 +567,7 @@ delay_garbage_collection(Process *p, int need, int fcalls)
else {
/* Do not leave a hole in the abandoned heap... */
if (orig_htop < orig_hend) {
- *orig_htop = make_pos_bignum_header(orig_hend-orig_htop-1);
+ erts_write_heap_filler(orig_htop, orig_hend-orig_htop);
if (orig_htop + 1 < orig_hend) {
orig_hend[-1] = (Uint) (orig_htop - orig_heap);
p->flags |= F_ABANDONED_HEAP_USE;
diff --git a/erts/emulator/beam/erl_map.c b/erts/emulator/beam/erl_map.c
index 13a3af61da..bdbd10d222 100644
--- a/erts/emulator/beam/erl_map.c
+++ b/erts/emulator/beam/erl_map.c
@@ -457,11 +457,11 @@ static Eterm flatmap_from_validated_list(Process *p, Eterm list, Eterm fill_valu
if (unused_size) {
/* the key tuple is embedded in the heap
- * write a bignum to clear it.
+ * write a heap filler to clear it.
*/
/* release values as normal since they are on the top of the heap */
- ks[size] = make_pos_bignum_header(unused_size - 1);
+ erts_write_heap_filler(ks + size, unused_size);
HRelease(p, vs + size + unused_size, vs + size);
}
@@ -1384,8 +1384,8 @@ static Eterm flatmap_merge(Process *p, Eterm map1, Eterm map2) {
hp_release = thp - unused_size;
}
else {
- /* Unused values are embedded in the heap, write bignum to clear them */
- *vs = make_pos_bignum_header(unused_size - 1);
+ /* Unused values are embedded in the heap, write filler to clear them */
+ erts_write_heap_filler(vs, unused_size);
/* Release unused keys */
hp_release = ks;
}
@@ -2220,7 +2220,7 @@ Eterm erts_maps_put(Process *p, Eterm key, Eterm value, Eterm map) {
* this will work out fine once we get the size word
* in the header.
*/
- *shp = make_pos_bignum_header(0);
+ erts_write_heap_filler(shp, 1);
return res;
found_key:
diff --git a/erts/emulator/beam/erl_term.h b/erts/emulator/beam/erl_term.h
index 1d9ef1607b..036dd84979 100644
--- a/erts/emulator/beam/erl_term.h
+++ b/erts/emulator/beam/erl_term.h
@@ -1463,8 +1463,16 @@ do { \
#define ET_ASSERT(expr,file,line) do { } while(0)
#endif
+ERTS_GLB_INLINE void erts_write_heap_filler(Eterm *hp, size_t sz);
+
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
+ERTS_GLB_INLINE void erts_write_heap_filler(Eterm *hp, size_t sz)
+{
+ ASSERT(sz > 0);
+ *hp = make_pos_bignum_header(sz - 1);
+}
+
#if ET_DEBUG
ERTS_GLB_INLINE unsigned tag_val_def(Eterm x, const char *file, unsigned line)
#else
--
2.43.0