-
-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add stable API method for checking if a Ruby object has been promoted to the old generation in the GC, equivalent to RB_OBJ_PROMOTED.
Motivation
Understanding object GC generation is important for:
- Implementing efficient write barriers
- Debugging GC-related issues
- Performance analysis of object lifetimes
- Advanced GC-aware data structures
Ruby Source Reference
// include/ruby/internal/gc.h
static inline bool
RB_OBJ_PROMOTED_RAW(VALUE obj)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED);
}
static inline bool
RB_OBJ_PROMOTED(VALUE obj)
{
if (! RB_FL_ABLE(obj)) {
return false;
}
else {
return RB_OBJ_PROMOTED_RAW(obj);
}
}Proposed API
/// Check if an object has been promoted to the old GC generation
/// (akin to `RB_OBJ_PROMOTED`).
///
/// Objects start in the "young" generation and are promoted to "old"
/// after surviving one or more GC cycles. Old objects are scanned less
/// frequently, which is why write barriers are needed when storing
/// references from old to young objects.
///
/// # Safety
/// This function is unsafe because it may dereference a raw pointer
/// to access the object's flags. The caller must ensure the VALUE
/// is a valid Ruby object.
unsafe fn rb_obj_promoted(&self, obj: VALUE) -> bool;Implementation Notes
- Check
RUBY_FL_PROMOTEDflag (same asRUBY_FL_WB_PROTECTED, value1<<5) - Must handle special constants (which are never promoted)
- Reference:
include/ruby/internal/gc.h:705-734
Checklist
- Add method to
StableApiDefinitiontrait - Implement for each Ruby version
- Add C fallback in
compiled.c - Add public macro wrapper in
macros.rs - Add tests
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request