Skip to content

Commit 3c28bb5

Browse files
Make it obvious that field count guard is for debug
This is because when `RVALUE_OVERHEAD` is positive, ie. when `RACTOR_CHECK_MODE` is enabled and we need to store the pointer to the owning ractor, we need to make sure there is enough space to store it. With the previous size pools the smallest size pool was 40 bytes, this gets expanded to 48 bytes when debug mode is on in order to make space for this extra pointer. because rb_obj_embedded_size(0) returns just the header with no field space it wants to be allocated in the 40 byte slot, this gives 16 bytes which is enough for RBasic only, but because this slot is 48 bytes in debug mode, we get the extra space for the pointer. When the smallest slot is 32 bytes it becomes 40 bytes in debug mode, this causes objects with no ivars to to get allocated in this pool because according to this calc it fits. but this doesn't leave the extra word for the ractor pointer. So in debug mode, we'll clamp this to 1 so that there's always enough space for 1 extra field to force allocation into the 40/48 byte pool.
1 parent 5381f0f commit 3c28bb5

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

internal/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ RBASIC_SET_CLASS(VALUE obj, VALUE klass)
6464
static inline size_t
6565
rb_obj_embedded_size(uint32_t fields_count)
6666
{
67+
#if (defined(RACTOR_CHECK_MODE) && RACTOR_CHECK_MODE) || (defined(GC_DEBUG) && GC_DEBUG)
6768
if (fields_count < 1) fields_count = 1;
69+
#endif
6870
return offsetof(struct RObject, as.ary) + (sizeof(VALUE) * fields_count);
6971
}
7072
#endif /* INTERNAL_OBJECT_H */

0 commit comments

Comments
 (0)