mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Revert "Disable auto compaction on platforms that can't support it"
This reverts commit63ad55cd88
. Revert "Disable read barrier on explicit compaction request" This reverts commit490b57783d
.
This commit is contained in:
parent
00f046ef57
commit
fed67fe6b2
3 changed files with 51 additions and 122 deletions
52
gc.c
52
gc.c
|
@ -682,7 +682,7 @@ typedef struct rb_objspace {
|
||||||
unsigned int dont_gc : 1;
|
unsigned int dont_gc : 1;
|
||||||
unsigned int dont_incremental : 1;
|
unsigned int dont_incremental : 1;
|
||||||
unsigned int during_gc : 1;
|
unsigned int during_gc : 1;
|
||||||
unsigned int during_compacting : 2;
|
unsigned int during_compacting : 1;
|
||||||
unsigned int gc_stressful: 1;
|
unsigned int gc_stressful: 1;
|
||||||
unsigned int has_hook: 1;
|
unsigned int has_hook: 1;
|
||||||
unsigned int during_minor_gc : 1;
|
unsigned int during_minor_gc : 1;
|
||||||
|
@ -3090,17 +3090,6 @@ Init_heap(void)
|
||||||
{
|
{
|
||||||
rb_objspace_t *objspace = &rb_objspace;
|
rb_objspace_t *objspace = &rb_objspace;
|
||||||
|
|
||||||
#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
|
|
||||||
/* If Ruby's heap pages are not a multiple of the system page size, we
|
|
||||||
* cannot use mprotect for the read barrier, so we must disable automatic
|
|
||||||
* compaction. */
|
|
||||||
int pagesize;
|
|
||||||
pagesize = (int)sysconf(_SC_PAGE_SIZE);
|
|
||||||
if ((HEAP_PAGE_SIZE % pagesize) != 0) {
|
|
||||||
ruby_enable_autocompact = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
objspace->next_object_id = INT2FIX(OBJ_ID_INITIAL);
|
objspace->next_object_id = INT2FIX(OBJ_ID_INITIAL);
|
||||||
objspace->id_to_obj_tbl = st_init_table(&object_id_hash_type);
|
objspace->id_to_obj_tbl = st_init_table(&object_id_hash_type);
|
||||||
objspace->obj_to_id_tbl = st_init_numtable();
|
objspace->obj_to_id_tbl = st_init_numtable();
|
||||||
|
@ -4400,11 +4389,6 @@ static VALUE gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free);
|
||||||
static void
|
static void
|
||||||
lock_page_body(rb_objspace_t *objspace, struct heap_page_body *body)
|
lock_page_body(rb_objspace_t *objspace, struct heap_page_body *body)
|
||||||
{
|
{
|
||||||
/* If this is an explicit compaction (GC.compact), we don't need a read
|
|
||||||
* barrier, so just return early. */
|
|
||||||
if (objspace->flags.during_compacting >> 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
DWORD old_protect;
|
DWORD old_protect;
|
||||||
|
|
||||||
|
@ -4421,11 +4405,6 @@ lock_page_body(rb_objspace_t *objspace, struct heap_page_body *body)
|
||||||
static void
|
static void
|
||||||
unlock_page_body(rb_objspace_t *objspace, struct heap_page_body *body)
|
unlock_page_body(rb_objspace_t *objspace, struct heap_page_body *body)
|
||||||
{
|
{
|
||||||
/* If this is an explicit compaction (GC.compact), we don't need a read
|
|
||||||
* barrier, so just return early. */
|
|
||||||
if (objspace->flags.during_compacting >> 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
DWORD old_protect;
|
DWORD old_protect;
|
||||||
|
|
||||||
|
@ -7051,7 +7030,7 @@ gc_marks_start(rb_objspace_t *objspace, int full_mark)
|
||||||
#endif
|
#endif
|
||||||
objspace->flags.during_minor_gc = FALSE;
|
objspace->flags.during_minor_gc = FALSE;
|
||||||
if (ruby_enable_autocompact) {
|
if (ruby_enable_autocompact) {
|
||||||
objspace->flags.during_compacting |= TRUE;
|
objspace->flags.during_compacting = TRUE;
|
||||||
}
|
}
|
||||||
objspace->profile.major_gc_count++;
|
objspace->profile.major_gc_count++;
|
||||||
objspace->rgengc.uncollectible_wb_unprotected_objects = 0;
|
objspace->rgengc.uncollectible_wb_unprotected_objects = 0;
|
||||||
|
@ -8078,9 +8057,7 @@ gc_start(rb_objspace_t *objspace, int reason)
|
||||||
|
|
||||||
/* reason may be clobbered, later, so keep set immediate_sweep here */
|
/* reason may be clobbered, later, so keep set immediate_sweep here */
|
||||||
objspace->flags.immediate_sweep = !!((unsigned)reason & GPR_FLAG_IMMEDIATE_SWEEP);
|
objspace->flags.immediate_sweep = !!((unsigned)reason & GPR_FLAG_IMMEDIATE_SWEEP);
|
||||||
|
objspace->flags.during_compacting = !!((unsigned)reason & GPR_FLAG_COMPACT);
|
||||||
/* Explicitly enable compaction (GC.compact) */
|
|
||||||
objspace->flags.during_compacting = (!!((unsigned)reason & GPR_FLAG_COMPACT) << 1);
|
|
||||||
|
|
||||||
if (!heap_allocated_pages) return FALSE; /* heap is not ready */
|
if (!heap_allocated_pages) return FALSE; /* heap is not ready */
|
||||||
if (!(reason & GPR_FLAG_METHOD) && !ready_to_gc(objspace)) return TRUE; /* GC is not allowed */
|
if (!(reason & GPR_FLAG_METHOD) && !ready_to_gc(objspace)) return TRUE; /* GC is not allowed */
|
||||||
|
@ -9270,19 +9247,6 @@ heap_check_moved_i(void *vstart, void *vend, size_t stride, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
|
||||||
gc_compact(rb_execution_context_t *ec, VALUE self)
|
|
||||||
{
|
|
||||||
/* Clear the heap. */
|
|
||||||
gc_start_internal(ec, self, Qtrue, Qtrue, Qtrue, Qfalse);
|
|
||||||
|
|
||||||
/* At this point, all references are live and the mutator is not allowed
|
|
||||||
* to run, so we don't need a read barrier. */
|
|
||||||
gc_start_internal(ec, self, Qtrue, Qtrue, Qtrue, Qtrue);
|
|
||||||
|
|
||||||
return gc_compact_stats(ec, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
gc_verify_compaction_references(rb_execution_context_t *ec, VALUE self, VALUE double_heap, VALUE toward_empty)
|
gc_verify_compaction_references(rb_execution_context_t *ec, VALUE self, VALUE double_heap, VALUE toward_empty)
|
||||||
{
|
{
|
||||||
|
@ -9901,16 +9865,6 @@ gc_disable(rb_execution_context_t *ec, VALUE _)
|
||||||
static VALUE
|
static VALUE
|
||||||
gc_set_auto_compact(rb_execution_context_t *ec, VALUE _, VALUE v)
|
gc_set_auto_compact(rb_execution_context_t *ec, VALUE _, VALUE v)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
|
|
||||||
/* If Ruby's heap pages are not a multiple of the system page size, we
|
|
||||||
* cannot use mprotect for the read barrier, so we must disable automatic
|
|
||||||
* compaction. */
|
|
||||||
int pagesize;
|
|
||||||
pagesize = (int)sysconf(_SC_PAGE_SIZE);
|
|
||||||
if ((HEAP_PAGE_SIZE % pagesize) != 0) {
|
|
||||||
rb_raise(rb_eNotImpError, "Automatic compaction isn't available on this platform");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
ruby_enable_autocompact = RTEST(v);
|
ruby_enable_autocompact = RTEST(v);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
3
gc.rb
3
gc.rb
|
@ -199,7 +199,8 @@ module GC
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.compact
|
def self.compact
|
||||||
Primitive.gc_compact
|
Primitive.gc_start_internal true, true, true, true
|
||||||
|
Primitive.gc_compact_stats
|
||||||
end
|
end
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
|
|
@ -1,15 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'fiddle'
|
require 'fiddle'
|
||||||
require 'etc'
|
|
||||||
|
|
||||||
class TestGCCompact < Test::Unit::TestCase
|
class TestGCCompact < Test::Unit::TestCase
|
||||||
class AutoCompact < Test::Unit::TestCase
|
|
||||||
def setup
|
|
||||||
skip "autocompact not supported on this platform" unless supports_auto_compact?
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_enable_autocompact
|
def test_enable_autocompact
|
||||||
before = GC.auto_compact
|
before = GC.auto_compact
|
||||||
GC.auto_compact = true
|
GC.auto_compact = true
|
||||||
|
@ -60,25 +53,6 @@ class TestGCCompact < Test::Unit::TestCase
|
||||||
GC.auto_compact = before
|
GC.auto_compact = before
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def supports_auto_compact?
|
|
||||||
return true unless defined?(Etc::SC_PAGE_SIZE)
|
|
||||||
|
|
||||||
begin
|
|
||||||
return GC::INTERNAL_CONSTANTS[:HEAP_PAGE_SIZE] % Etc.sysconf(Etc::SC_PAGE_SIZE) == 0
|
|
||||||
rescue NotImplementedError
|
|
||||||
rescue ArgumentError
|
|
||||||
end
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def os_page_size
|
|
||||||
return true unless defined?(Etc::SC_PAGE_SIZE)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_gc_compact_stats
|
def test_gc_compact_stats
|
||||||
list = []
|
list = []
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue