Skip to content

Commit f38ff71

Browse files
committed
Do not use rb_str_tmp_frozen_no_embed_acquire with MMTk
It was intended to work around https://bugs.ruby-lang.org/issues/20169, but it is unnecessary for MMTk.
1 parent b9e24e8 commit f38ff71

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Diff for: string.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,20 @@ rb_str_tmp_frozen_acquire(VALUE orig)
17381738
VALUE
17391739
rb_str_tmp_frozen_no_embed_acquire(VALUE orig)
17401740
{
1741+
WHEN_USING_MMTK({
1742+
// The default GC may lock (mprotect with PROT_NONE) pages of GC memory during compaction.
1743+
// If that happens while a pointer to the string payload in an embedded string is used for
1744+
// IO, with GVL released, the OS or external native programs may read or write protected
1745+
// pages, causing segmentation fault. The intention of `rb_str_tmp_frozen_no_embed_acquire`
1746+
// is working around this problem by forcing the given `orig` string to be allocated in the
1747+
// malloc heap.
1748+
//
1749+
// When using MMTk, this doesn't make sense because MMTk never protect pages of live
1750+
// objects, and we allocate non-embedded string buffers as `imemo:mmtk_strbuf` in the MMTk
1751+
// heap. So we simply call `rb_str_tmp_frozen_acquire` instead.
1752+
return rb_str_tmp_frozen_acquire(orig);
1753+
})
1754+
17411755
if (OBJ_FROZEN_RAW(orig) && !STR_EMBED_P(orig) && !rb_str_reembeddable_p(orig)) return orig;
17421756
if (STR_SHARED_P(orig) && !STR_EMBED_P(RSTRING(orig)->as.heap.aux.shared)) return rb_str_tmp_frozen_acquire(orig);
17431757

@@ -1762,13 +1776,6 @@ rb_str_tmp_frozen_no_embed_acquire(VALUE orig)
17621776
RSTRING(str)->as.heap.ptr = RSTRING(orig)->as.heap.ptr;
17631777
RBASIC(str)->flags |= RBASIC(orig)->flags & STR_NOFREE;
17641778
RBASIC(orig)->flags &= ~STR_NOFREE;
1765-
1766-
WHEN_USING_MMTK({
1767-
// Note: The root may be no-free.
1768-
VALUE strbuf = rb_mmtk_str_get_strbuf_nullable(orig);
1769-
rb_mmtk_str_set_strbuf(str, strbuf);
1770-
})
1771-
17721779
STR_SET_SHARED(orig, str);
17731780
}
17741781

0 commit comments

Comments
 (0)