From 62da7836b6a6f6882342ae735379056c02e37802 Mon Sep 17 00:00:00 2001 From: Erik Corry Date: Fri, 17 May 2024 08:24:44 +0200 Subject: [PATCH] Add missing write barrier in array-replace (#2309) Co-authored-by: Kasper Lund --- src/primitive_core.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/primitive_core.cc b/src/primitive_core.cc index 7a42bb67c..5c42b1643 100644 --- a/src/primitive_core.cc +++ b/src/primitive_core.cc @@ -1700,7 +1700,7 @@ PRIMITIVE(array_expand) { return new_array; } -// Memcpy betwen arrays. +// Memmove between arrays. PRIMITIVE(array_replace) { ARGS(Array, dest, word, index, Array, source, word, from, word, to); word dest_length = dest->length(); @@ -1708,6 +1708,11 @@ PRIMITIVE(array_replace) { if (index < 0 || from < 0 || from > to || to > source_length) FAIL(OUT_OF_BOUNDS); word len = to - from; if (index + len > dest_length) FAIL(OUT_OF_BOUNDS); + // Our write barrier is only there to record the presence of pointers + // from old-space to new-space, and the resolution is per-object. If + // there were no pointers from old-space to new-space then an intra- + // array copy is not going to create any. + if (len != 0 && dest != source) GcMetadata::insert_into_remembered_set(dest); memmove(dest->content() + index * WORD_SIZE, source->content() + from * WORD_SIZE, len * WORD_SIZE);