summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-02-24 13:42:27 -0800
committerAaron Patterson <tenderlove@ruby-lang.org>2021-02-24 13:44:10 -0800
commit08d5db4064a76649effef1bf2ab79f04cd848a6a (patch)
treef7e2820c207247cc3fab1980f7fd736585a10550
parentf3c8e477e1e1d38a0178d05e060ceeed2ef5a011 (diff)
Reverting PR #4221
It seems this breaks tests on Solaris, so I'm reverting it until we figure out the right fix. http://rubyci.s3.amazonaws.com/solaris11-sunc/ruby-master/log/20210224T210007Z.fail.html.gz
-rw-r--r--configure.ac3
-rw-r--r--gc.c57
-rw-r--r--test/ruby/test_gc_compact.rb16
3 files changed, 15 insertions, 61 deletions
diff --git a/configure.ac b/configure.ac
index 911ebdfdd5..41f2879645 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1931,6 +1931,7 @@ AC_CHECK_FUNCS(lutimes)
AC_CHECK_FUNCS(malloc_usable_size)
AC_CHECK_FUNCS(malloc_size)
AC_CHECK_FUNCS(mblen)
+AC_CHECK_FUNCS(memalign)
AC_CHECK_FUNCS(memset_s)
AC_CHECK_FUNCS(writev)
AC_CHECK_FUNCS(memrchr)
@@ -1938,11 +1939,11 @@ AC_CHECK_FUNCS(memmem)
AC_CHECK_FUNCS(mkfifo)
AC_CHECK_FUNCS(mknod)
AC_CHECK_FUNCS(mktime)
-AC_CHECK_FUNCS(mmap)
AC_CHECK_FUNCS(openat)
AC_CHECK_FUNCS(pipe2)
AC_CHECK_FUNCS(poll)
AC_CHECK_FUNCS(posix_fadvise)
+AC_CHECK_FUNCS(posix_memalign)
AC_CHECK_FUNCS(ppoll)
AC_CHECK_FUNCS(pread)
AC_CHECK_FUNCS(pwrite)
diff --git a/gc.c b/gc.c
index 073d1bc7df..8aad4b9243 100644
--- a/gc.c
+++ b/gc.c
@@ -1765,14 +1765,14 @@ heap_unlink_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *pag
heap->total_slots -= page->total_slots;
}
-static void rb_aligned_free(void *ptr, size_t size);
+static void rb_aligned_free(void *ptr);
static void
heap_page_free(rb_objspace_t *objspace, struct heap_page *page)
{
heap_allocated_pages--;
objspace->profile.total_freed_pages++;
- rb_aligned_free(GET_PAGE_BODY(page->start), HEAP_PAGE_SIZE);
+ rb_aligned_free(GET_PAGE_BODY(page->start));
free(page);
}
@@ -1824,7 +1824,7 @@ heap_page_allocate(rb_objspace_t *objspace)
/* assign heap_page entry */
page = calloc1(sizeof(struct heap_page));
if (page == 0) {
- rb_aligned_free(page_body, HEAP_PAGE_SIZE);
+ rb_aligned_free(page_body);
rb_memerror();
}
@@ -9986,13 +9986,6 @@ gc_set_auto_compact(rb_execution_context_t *ec, VALUE _, VALUE v)
rb_raise(rb_eNotImpError, "Automatic compaction isn't available on this platform");
}
#endif
-
- /* If not MinGW, Windows, or does not have mmap, we cannot use mprotect for
- * the read barrier, so we must disable automatic compaction. */
-#if !defined(__MINGW32__) && !defined(_WIN32) && !defined(HAVE_MMAP)
- rb_raise(rb_eNotImpError, "Automatic compaction isn't available on this platform");
-#endif
-
ruby_enable_autocompact = RTEST(v);
return v;
}
@@ -10389,36 +10382,15 @@ rb_aligned_malloc(size_t alignment, size_t size)
#elif defined _WIN32
void *_aligned_malloc(size_t, size_t);
res = _aligned_malloc(size, alignment);
-#elif defined(HAVE_MMAP)
- GC_ASSERT(alignment % sysconf(_SC_PAGE_SIZE) == 0);
-
- char *ptr = mmap(NULL, alignment + size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
- if (ptr == MAP_FAILED) {
- return NULL;
- }
-
- char *aligned = ptr + alignment;
- aligned -= ((VALUE)aligned & (alignment - 1));
- GC_ASSERT(aligned > ptr);
- GC_ASSERT(aligned <= ptr + alignment);
-
- size_t start_out_of_range_size = aligned - ptr;
- GC_ASSERT(start_out_of_range_size % sysconf(_SC_PAGE_SIZE) == 0);
- if (start_out_of_range_size > 0) {
- if (munmap(ptr, start_out_of_range_size)) {
- rb_bug("rb_aligned_malloc: munmap faile for start");
- }
+#elif defined(HAVE_POSIX_MEMALIGN)
+ if (posix_memalign(&res, alignment, size) == 0) {
+ return res;
}
-
- size_t end_out_of_range_size = alignment - start_out_of_range_size;
- GC_ASSERT(end_out_of_range_size % sysconf(_SC_PAGE_SIZE) == 0);
- if (end_out_of_range_size > 0) {
- if (munmap(aligned + size, end_out_of_range_size)) {
- rb_bug("rb_aligned_malloc: munmap failed for end");
- }
+ else {
+ return NULL;
}
-
- res = (void *)aligned;
+#elif defined(HAVE_MEMALIGN)
+ res = memalign(alignment, size);
#else
char* aligned;
res = malloc(alignment + size + sizeof(void*));
@@ -10435,17 +10407,14 @@ rb_aligned_malloc(size_t alignment, size_t size)
}
static void
-rb_aligned_free(void *ptr, size_t size)
+rb_aligned_free(void *ptr)
{
#if defined __MINGW32__
__mingw_aligned_free(ptr);
#elif defined _WIN32
_aligned_free(ptr);
-#elif defined HAVE_MMAP
- GC_ASSERT(size % sysconf(_SC_PAGE_SIZE) == 0);
- if (munmap(ptr, size)) {
- rb_bug("rb_aligned_free: munmap failed");
- }
+#elif defined(HAVE_MEMALIGN) || defined(HAVE_POSIX_MEMALIGN)
+ free(ptr);
#else
free(((void**)ptr)[-1]);
#endif
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index c4277d1ffe..4a8cff33f4 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -60,22 +60,6 @@ class TestGCCompact < Test::Unit::TestCase
GC.auto_compact = before
end
- def test_bug_17652
- assert_in_out_err([], "#{<<~"{#"}#{<<~'};'}", timeout: 60)
- {#
- GC.auto_compact = true
-
- times = 20_000_000
- arr = Array.new(times)
- times.times do |i|
- arr[i] = "#{i}"
- end
-
- arr = Array.new(1_000_000, 42)
- GC.start
- };
- end
-
private
def supports_auto_compact?