396 Commits
Author SHA1 Message Date
Luke Gruber 4c2968348e Use mark context when marking execution_context 2026-10-16 12:33:52 -04:00
Hiroshi SHIBATAandClaude Opus 5.5 6b3b0b8083 Use rb_len_t for String and Array lengths in ext/coverage and ext/objspace
ObjectSpace.dump writes the lengths with dump_append_sizet, because dump_append_ld takes a long and is also used for Fixnum values. The lengths are never negative, so the output does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 16:45:25 +09:00
Peter Zhu 8972135571 Include JIT call count in ObjectSpace dumps of iseq
This commit adds `jit_calls` and `jit_threshold_reached` to iseq dumps which
dumps the number of calls to the iseq and whether the iseq has been JIT
compiled or not, respectively.
2026-10-09 08:56:20 +09:00
Peter Zhu 5299d8d132 Dump Hash AR/ST status in ObjectSpace.dump 2026-09-26 09:54:59 +09:00
Peter Zhu 59595825ce Define IMEMO_MASK from FL_USER bits 2026-09-03 08:38:46 +09:00
Koichi SasadaandClaude Fable 5 13c50963b9 objspace: allocation tracing must tolerate reused addresses
Since the FREEOBJ internal event fires only for the main objspace (a
non-main Ractor's lock-free sweep must not run arbitrary C callbacks),
an object that dies in another Ractor leaves its allocation-tracing
entry behind, still marked living.  When the allocator reuses that
address, newobj_i tripped its debug assertion; release builds already
recycle the entry.  Drop the stale assertion.

This was latent but rare while a dead Ractor's pages waited for the
inheritor's next major GC; the previous commits return those pages to
the pool at death, which made it deterministic
(TestObjSpaceRactor#test_tracing_does_not_crash on assert builds).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 03:33:40 +09:00
Luke Gruber 63a726f762 Fix ObjectSpace.shareable_objects_from: don't return foreign unshareables
After the rlgc merge, this method and also ObjectSpace.shareable_objects_from_roots could
return foreign unshareables which violates Ractor containment.
2026-08-10 09:57:05 -04:00
Nobuyoshi Nakada b68ef95a51 [Feature #22215] Extract internal objspace API
Provide narrow accessors so `ext/objspace` does not depend on call
cache and call info layouts.
2026-08-07 09:59:15 +09:00
Hiroshi SHIBATA 2d7947d082 [DOC] Use trace_object_allocations_start in the dump_all example
ObjectSpace.trace_object_allocations raises LocalJumpError when called
without a block.
2026-08-05 19:38:31 +09:00
Nobuyoshi Nakada 7d4461e162 [Misc #22206] Generate dependencies without compiler builds
Replace `tool/update-deps` with a Ruby source scanner so dependency
updates no longer require GNU make, a configured build, or compiler
preprocessor output.

Keep compact source mappings and scanner declarations in dependency
files, and expand complete rules into the build directory.  Avoid the
temporary fixture headers required by the compiler-driven prototype.

Use the generated rules from GNU make, BSD make, and NMake builds.
Support out-of-tree and read-only source trees, and retain expanded
dependencies shipped in release archives when baseruby is unavailable.
2026-07-23 00:04:47 +09:00
Jean Boussier 74bd057f9c Get rid of ROBJECT_FIELDS_HASH 2026-07-15 20:52:47 +02:00
Jean Boussier 0b681246d6 Get rid of ROBJECT_FIELDS_COUNT
It's basrely used.
2026-07-15 20:52:47 +02:00
Jean Boussier 86951165b8 Get rid of ROBJECT_HEAP flag
This flag is now entirely redundant with the shape_id layout bits.
2026-07-15 15:43:28 +02:00
Nobuyoshi Nakada 92c6f4331b Bound GC and VM diagnostic strings 2026-07-15 13:28:39 +09:00
Peter Zhu a6e302509b [DOC] Improve docs for ObjectSpace::InternalObjectWrapper#internal_object_id 2026-06-14 14:19:50 +09:00
Peter Zhu 28da8f9104 [DOC] Improve docs for ObjectSpace::InternalObjectWrapper#type 2026-06-11 14:31:46 +09:00
Peter Zhu 8c434d03bd [DOC] Improve class docs for ObjectSpace::InternalObjectWrapper 2026-06-10 10:08:32 +09:00
Peter Zhu 82329a5053 [DOC] Improve docs for ObjectSpace.internal_super_of 2026-06-09 09:17:13 +09:00
John Hawthorn dd9213c41d Convert object_tracing to use weak references
Object tracing listens to the NEWOBJ hook to see all objects allocated
while it is active. Previously it also enabled a FREEOBJ tracepoint to
drop each object's record as the object was freed.

However the FREEOBJ tracepoint only fires while tracing is active. An
object recorded during tracing can be freed after tracing stops, and
that free was missed, leaving a stale record in object_table keyed by a
freed object. These dangling keys are unsafe during compaction, which
was previously mitigated with rb_gc_pointer_to_heap_p (which I'd like to
stop using). These dangling keys could also become incorrectly
associated with a new object allocated in its place.

Instead we can declare object_table's keys as weak references. The GC
then invokes our weak reference callback on every collection, whether or
not tracing is running, letting us reap the records of objects about to
be freed. This callback runs before the FREEOBJ hook, which makes the
FREEOBJ tracepoint unnecessary.
2026-06-05 10:56:16 -07:00
Peter Zhu 623fa94e9e [DOC] Improve docs for ObjectSpace.memsize_of 2026-06-04 07:55:45 +09:00
Peter Zhu 2ff671c93d [DOC] Improve docs for ObjectSpace.internal_class_of 2026-06-03 14:33:09 +09:00
Peter Zhu 1d3e2bd2b8 [DOC] Improve docs for ObjectSpace.reachable_objects_from_root 2026-06-03 09:31:49 +09:00
Nobuyoshi Nakada 5497859f40 Remove use of RTYPEDDATA_P and rbimpl_rtypeddata_p 2026-05-28 19:29:32 +09:00
Jean Boussier 99dc513d15 Use IMEMO to store cdhash
RHash isn't a good fit for storing `cdhash` as this force to allow
arbitrary hash types into RHash, which doesn't work with AR tables.

It also cause the cdhash to be larger than needed.
2026-05-18 08:58:32 +03:00
Jean Boussier 5eb4284144 Stop using rb_class_path_cached, and deprecate it.
That API made sense before b00f280d4b
as finding a module name was costly, but it now is a very cheap
operation, and that function is now just an outdated alias.
2026-05-17 20:15:21 +03:00
John Hawthorn f71840a230 Replace subclasses linked list with weakref array 2026-05-13 18:36:51 -07:00
Peter Zhu b1a26097ad [DOC] Improve docs for ObjectSpace.reachable_objects_from 2026-05-13 20:01:54 -04:00
Peter Zhu 834a828f9b [DOC] Improve docs for ObjectSpace.count_objects_size 2026-05-07 20:27:45 -04:00
Peter Zhu 4f28236d51 [DOC] Fix hash style in ObjectSpace.count_objects_size 2026-05-06 21:27:56 -04:00
Jean Boussier deceb9f62e Rename rb_shape_obj_* into rb_obj_shape_*
For consistency.
2026-05-06 10:10:16 +02:00
Jean Boussier 4eeec614bb shapes: Rename TOO_COMPLEX in just COMPLEX
The `too_` prefix wasn't consistently used and just make the
thing longer for no benefit.
2026-05-06 10:10:16 +02:00
Jean Boussier beffa58b65 shape: Get rid of the "raw_id" terminology in favor of "offset"
It better describe that part of a `shape_id`.
2026-05-03 23:40:36 +02:00
Jean Boussier 47e061277a class.c: Make cvc_tbl a managed object
[Bug #21952]

Solves the double-free or use after-free concern with boxes.
Now entries can safely be used for copy-on-write.

Also is likely necessary to make it save to read cvar from
secondary ractors, as allowed since: ab32c0e690
2026-04-21 16:30:14 +09:00
John Hawthorn 6721ec2612 Include free_immediately: false in heap dumps
This adds "free_immediately: false" to the heap dump for any T_DATA
which doesn't specify RUBY_TYPED_FREE_IMMEDIATELY. These are the objects
which end up as T_ZOMBIE and will have their dfree callback deferred to
later when the program is running holding the GVL.

This is useful to include because there is more overhead to freeing
these objects, and it's worth knowing how many there are.
2026-03-16 15:56:52 -07:00
Augustin Gottlieb 6ef0eb29c6 Add early type validation for ObjectSpace.memsize_of_all klass argument 2026-01-23 11:00:37 +09:00
Jean Boussier 6cd4549060 Optimize File.join common use case
`File.join` is a hotspot for common libraries such as Zeitwerk
and Bootsnap. It has a fairly flexible signature, but 99% of
the time it's called with just two (or a small number of) UTF-8 strings.

If we optimistically optimize for that use case we can cut down a large
number of type and encoding checks, significantly speeding up the method.

The one remaining expensive check we could try to optimize is `str_null_check`.
Given it's common to use the same base string for joining, we could memoize it.
Also we could precompute it for literal strings.

```
compare-ruby: ruby 4.1.0dev (2026-01-17T14:40:03Z master 00a3b71eaf) +PRISM [arm64-darwin25]
built-ruby: ruby 4.1.0dev (2026-01-18T12:10:38Z spedup-file-join 069bab58d4) +PRISM [arm64-darwin25]
warming up....

|              |compare-ruby|built-ruby|
|:-------------|-----------:|---------:|
|two_strings   |      2.475M|    9.444M|
|              |           -|     3.82x|
|many_strings  |    551.975k|    2.346M|
|              |           -|     4.25x|
|array         |    514.946k|  522.034k|
|              |           -|     1.01x|
|mixed         |    621.236k|  633.189k|
|              |           -|     1.02x|
```
2026-01-18 16:31:31 +01:00
Peter Zhu 00a3b71eaf [DOC] Improve docs for ObjectSpace.memsize_of_all 2026-01-17 09:40:03 -05:00
Peter Zhu 61c372a1b7 [DOC] Improve docs for ObjectSpace.count_symbols 2026-01-11 10:46:56 -05:00
Peter Zhu 1267a3ab56 [DOC] Improve docs for ObjectSpace.count_imemo_objects 2026-01-11 10:46:56 -05:00
Peter Zhu cf5c5abe1e [DOC] Improve docs for ObjectSpace.count_tdata_objects 2026-01-11 10:46:56 -05:00
Peter Zhu e8c61f5139 Remove ObjectSpace.count_nodes
ObjectSpace.count_nodes has been a no-op and returning an empty hash since
Ruby 2.5 because parser nodes are not GC managed.
2026-01-09 18:05:43 -05:00
Peter Zhu 7379b9ed78 Optimize rb_mark_generic_ivar for T_DATA and T_STRUCT
T_DATA and T_STRUCT could have ivars but might not use the generic_fields_tbl.
This commit skips lookup in the generic_fields_tbl for those cases.
2026-01-09 17:31:10 +01:00
Luke Gruber 56b67f1684 ObjectSpace.{dump,dump_all,dump_shapes} needs vm barrier. (#15569)
This allows these methods to be called from ractors.

Add new exported function `rb_vm_lock_with_barrier()` that requires
users to include "vm_sync.h"
2025-12-17 12:17:30 -05:00
Peter Zhu 87493e32ed Fix memory leak in ObjectSpace tracing
allocation_info_tracer_compact_update_object_table_i deletes entries where
the key is no longer in the GC heap but did not free the allocation_info
causing the memory to be leaked.
2025-11-10 16:34:00 -08:00
Nobuyoshi Nakada 87c39667bf [DOC] ObjectSpace.trace_object_allocations_debug_start 2025-11-09 22:11:40 +09:00
Satoshi Tagomori aaa1234702 update referenced filenames from namespace to box 2025-11-07 13:14:54 +09:00
Jean Boussier 5257e1298c Replace ROBJECT_EMBED by ROBJECT_HEAP
The embed layout is way more common than the heap one,
especially since WVA.

I think it makes for more readable code to inverse the
flag.
2025-08-27 12:41:07 +02:00
John Hawthorn 640a2f1dc7 Ensure ObjectSpace.dump won't call cc_cme on invalidated CC 2025-08-06 15:57:13 -07:00
Jean Boussier f0c31c5e64 Get rid of RSHAPE_PARENT in favor of RSHAPE_DIRECT_CHILD_P
`RSHAPE_PARENT` is error prone because it returns a raw untagged
shape_id.

To check if a shape is a direct parent of another, tags should be
discarded. So providing a comparison function is better than exposing
untagged ids.
2025-07-31 21:55:51 +02:00
Jean Boussier 7ee127d2d1 Get rid of imemo_ast
It has been marked as obsolete for a while and I see no reason
to keep it.
2025-07-29 13:05:12 +02:00