Skip to content

Commit

Permalink
Add missing write barrier in array-replace (#2309)
Browse files Browse the repository at this point in the history
Co-authored-by: Kasper Lund <kasper@toit.io>
  • Loading branch information
erikcorry and kasperl committed May 17, 2024
1 parent a153070 commit 62da783
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/primitive_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1700,14 +1700,19 @@ 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();
word source_length = source->length();
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);
Expand Down

0 comments on commit 62da783

Please sign in to comment.