Граф коммитов

2435 Коммитов

Автор SHA1 Сообщение Дата
Peter Zhu c2170e5c2b Fix typo from gloabl_object_list to global_object_list 2024-03-14 13:52:20 -04:00
Peter Zhu 4559a161af Move gloabl_object_list from objspace to VM
This is to be consistent with the mark_object_ary that is in the VM.
2024-03-14 13:29:59 -04:00
Peter Zhu ff51dc5654 [Feature #20265] Remove rb_newobj_of and RB_NEWOBJ_OF 2024-03-14 12:53:04 -04:00
Peter Zhu 8e1831406f [Feature #20265] Remove rb_newobj and RB_NEWOBJ 2024-03-14 12:53:04 -04:00
Peter Zhu 3896f9940e Make special const and too complex shapes before T_OBJECT shapes 2024-03-13 09:55:52 -04:00
Peter Zhu 6b0434c0f7 Don't create per size pool shapes for non-T_OBJECT 2024-03-13 09:55:52 -04:00
Peter Zhu 6ad347a105 Don't directly read the SIZE_POOL_COUNT in shapes
This removes the assumption about SIZE_POOL_COUNT for shapes.
2024-03-13 09:55:52 -04:00
Peter Zhu e12bc5c572 Remove dead function rb_obj_rgengc_promoted_p 2024-03-11 11:04:20 -04:00
Peter Zhu 9f31577987 Reuse rb_gc_writebarrier_unprotect in rb_copy_wb_protected_attribute 2024-03-11 09:30:15 -04:00
Jean Boussier d4f3dcf4df Refactor VM root modules
This `st_table` is used to both mark and pin classes
defined from the C API. But `vm->mark_object_ary` already
does both much more efficiently.

Currently a Ruby process starts with 252 rooted classes,
which uses `7224B` in an `st_table` or `2016B` in an `RArray`.

So a baseline of 5kB saved, but since `mark_object_ary` is
preallocated with `1024` slots but only use `405` of them,
it's a net `7kB` save.

`vm->mark_object_ary` is also being refactored.

Prior to this changes, `mark_object_ary` was a regular `RArray`, but
since this allows for references to be moved, it was marked a second
time from `rb_vm_mark()` to pin these objects.

This has the detrimental effect of marking these references on every
minors even though it's a mostly append only list.

But using a custom TypedData we can save from having to mark
all the references on minor GC runs.

Addtionally, immediate values are now ignored and not appended
to `vm->mark_object_ary` as it's just wasted space.
2024-03-06 15:33:43 -05:00
Jean Boussier b4a69351ec Move FL_SINGLETON to FL_USER1
This frees FL_USER0 on both T_MODULE and T_CLASS.

Note: prior to this, FL_SINGLETON was never set on T_MODULE,
so checking for `FL_SINGLETON` without first checking that
`FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-03-06 13:11:41 -05:00
Peter Zhu 5a3ae06a09 Remove dead function rb_obj_rgengc_writebarrier_protected_p 2024-03-01 15:41:16 -05:00
Peter Zhu 6f31dd495c Don't check_rvalue_consistency in is_markable_object
is_markable_object is called by rb_objspace_markable_object_p, which
may pass a T_NONE object. check_rvalue_consistency will fail if a T_NONE
object is passed in.
2024-03-01 13:38:49 -05:00
Peter Zhu d3ae5808bb Remove each_machine_stack_value
The function is only used by rb_gc_mark_machine_stack.
2024-02-29 14:26:31 -05:00
Peter Zhu 3d61477900 Remove unused gc_mark_stack_values 2024-02-29 13:23:50 -05:00
Peter Zhu 6665ec26db Remove check for is_markable_object in gc_mark_stack_values
gc_mark_and_pin already checks for is_markable_object.
2024-02-29 13:23:50 -05:00
Peter Zhu 4c0f0b90a4 Assume that FL_FINALIZE is in finalizer_table
If FL_FINALIZE is set but not in finalizer_table, then rb_bug.
2024-02-29 11:07:53 -05:00
Peter Zhu 8a918b456c Add gc_each_object for walking the heap 2024-02-29 10:57:24 -05:00
Peter Zhu 950c60623b Delete from finalizer_table before running finalizer
The finalizer could trigger a GC, which would cause FL_FINALIZE to be
out of sync with the finalizer table.
2024-02-29 09:38:13 -05:00
Peter Zhu d5bca0668c Unset FL_FINALIZE before running the finalizer
The finalizer could trigger a GC, so FL_FINALIZE could get out of sync
with the finalizer table.
2024-02-29 09:37:38 -05:00
Peter Zhu 4b92b60f0b Use array initialization rather than for loop 2024-02-28 14:54:21 -05:00
Peter Zhu 5481dbef07 Make rb_define_finalizer_no_check private 2024-02-28 13:45:19 -05:00
Peter Zhu dcc976add9 Remove unused rb_gc_id2ref_obj_tbl 2024-02-28 12:21:38 -05:00
Peter Zhu 7b69563b36 Add check for finalizer in verify_internal_constency
This adds a check in GC.verify_internal_constency that FL_FINALIZE flags
is set if, and only if it is in finalizer_table.
2024-02-28 10:41:11 -05:00
Peter Zhu 48f433fd40 Change T_ZOMBIE flag check from an assertion
Assertions are only enable on debug builds, so it will now check for
flags of T_ZOMBIE objects on all builds in GC.verify_internal_consistency.
2024-02-28 10:41:11 -05:00
Peter Zhu e8e2415bb3 Use RB_SPECIAL_CONST_P instead of rb_special_const_p
rb_special_const_p returns a VALUE (Qtrue or Qfalse), so we shouldn't
assume that Qfalse is 0. We should instead use RB_SPECIAL_CONST_P.
2024-02-27 21:11:11 -05:00
Peter Zhu 08731182b8 Change is_garbage_object to return a bool 2024-02-27 14:52:02 -05:00
Peter Zhu 3c44f6da6c Simplify is_garbage_object 2024-02-27 14:52:02 -05:00
Peter Zhu 1f740cd111 Remove is_swept_object
The name is misleading, as it seems like the function checks whether the
object is swept or not. But the function only checks whether the page is
before or after sweeping.
2024-02-27 12:10:48 -05:00
Peter Zhu 2396b7a62f Change is_live_object to return a bool 2024-02-27 10:03:42 -05:00
Peter Zhu 9ba53cb688 Simplify is_live_object 2024-02-27 10:03:42 -05:00
Peter Zhu 78ae6dbb11 Remove rb_objspace_marked_object_p
rb_objspace_marked_object_p is no longer used in the objspace module, so
we can remove it.
2024-02-26 17:05:34 -05:00
Peter Zhu 7538703d1b Make rb_objspace_data_type_memsize private
rb_objspace_data_type_memsize is not used in the objspace module, so we
can make it private.
2024-02-26 17:05:34 -05:00
Peter Zhu c9b6cd4223 Remove unused rb_objspace_each_objects_without_setup 2024-02-26 14:34:24 -05:00
Peter Zhu 27e3e44390 Fix verify_internal_consistency_i for zombie objects
FL_FINALIZE is now kept for zombie objects.
2024-02-26 11:38:44 -05:00
Peter Zhu 83e676e5f9 Don't lookup finalizers if FL_FINALIZE flag not set
The FL_FINALIZE flag is set when there are finalizers for the object. We
can improver performance by not looking up in the table if the flag is
not set.

Using the following C extension:

    #include "ruby/ruby.h"

    static void data_free(void *_ptr) {}

    static const rb_data_type_t data_type = {
        "my_type",
        {
            NULL,
            data_free,
        },
        0, 0, 0
    };

    static VALUE data_alloc(VALUE klass) {
        return TypedData_Wrap_Struct(klass, &data_type, (void *)1);
    }

    void Init_myext(void) {
        VALUE my_klass = rb_define_class("MyClass", rb_cObject);
        rb_define_alloc_func(my_klass, data_alloc);
    }

And the following benchmark:

    require "benchmark"

    final_objs = 1_000_000.times.map do
      o = Object.new
      ObjectSpace.define_finalizer(o, proc {})
      o
    end

    puts(Benchmark.measure do
      100_000_000.times do
        MyClass.new
      end
    end)

Before:

    10.974190   0.355037  11.329227 ( 11.416772)

After:

    7.664310   0.347598   8.011908 (  8.268969)
2024-02-26 09:20:05 -05:00
Peter Zhu e65315a725 Extract imemo functions from gc.c into imemo.c 2024-02-22 11:35:09 -05:00
Peter Zhu 330830dd1a Add IMEMO_NEW
Rather than exposing that an imemo has a flag and four fields, this
changes the implementation to only expose one field (the klass) and
fills the rest with 0. The type will have to fill in the values themselves.
2024-02-21 11:33:05 -05:00
Peter Zhu 402690c3b6 Fix incomplete switch statement in imemo_memsize
The switch statement is not exhaustive, meaning the "unreachable"
comment was not correct. This commit fixes it by making the list
exhaustive and adding an rb_bug in the default case.
2024-02-21 10:13:36 -05:00
John Hawthorn 1c97abaaba De-dup identical callinfo objects
Previously every call to vm_ci_new (when the CI was not packable) would
result in a different callinfo being returned this meant that every
kwarg callsite had its own CI.

When calling, different CIs result in different CCs. These CIs and CCs
both end up persisted on the T_CLASS inside cc_tbl. So in an eval loop
this resulted in a memory leak of both types of object. This also likely
resulted in extra memory used, and extra time searching, in non-eval
cases.

For simplicity in this commit I always allocate a CI object inside
rb_vm_ci_lookup, but ideally we would lazily allocate it only when
needed. I hope to do that as a follow up in the future.
2024-02-20 18:55:00 -08:00
Peter Zhu 97d4363d3b [DOC] Improve docs for GC.latest_compact_info 2024-02-20 17:39:46 -05:00
Peter Zhu c184aa8740 Use rb_gc_mark_and_move for imemo 2024-02-20 10:39:30 -05:00
Peter Zhu 24645cff0d Removed duplicated variable in push_mark_stack 2024-02-16 13:27:16 -05:00
Peter Zhu 4411cdeef9 Fix typo in gc.c 2024-02-16 11:44:27 -05:00
Peter Zhu 28709d591d Remove unused argument in cc_table_free 2024-02-14 16:25:05 -05:00
Peter Zhu ae8db4b65a Remove unused function rb_cc_table_free 2024-02-14 15:52:15 -05:00
Peter Zhu 1d3b306753 Move rb_class_allocate_instance from gc.c to object.c 2024-02-14 13:43:02 -05:00
Alan Wu 5add999dee Comment about not marking RSYMBOL(obj)->fstr [ci skip] 2024-02-13 14:49:54 -05:00
Peter Zhu 190a55d27f Drill newobj cache instead of ractor 2024-02-12 09:43:38 -05:00
Peter Zhu a50e35888b Free all remaining objects in rb_objspace_free_objects
rb_objspace_call_finalizer didn't free fibers and neither did
rb_objspace_free_objects, which caused fibers to be reported as leaked
when using RUBY_FREE_AT_EXIT. This commit changes rb_objspace_free_objects
to free all remaining Ruby objects.
2024-02-06 10:54:05 -05:00