@@ -57,6 +57,7 @@ struct objspace {
5757
5858 uintptr_t vo_bit_log_region_size ;
5959 uintptr_t vo_bit_base_addr ;
60+ size_t max_non_los_default_alloc_bytes ;
6061};
6162
6263#define OBJ_FREE_BUF_CAPACITY 128
@@ -110,6 +111,7 @@ RB_THREAD_LOCAL_SPECIFIER VALUE marking_parent_object;
110111#include <pthread.h>
111112
112113#define MMTK_ALLOCATION_SEMANTICS_DEFAULT 0
114+ #define MMTK_ALLOCATION_SEMANTICS_LOS 2
113115
114116static inline VALUE rb_mmtk_call_object_closure (VALUE obj , bool pin );
115117
@@ -604,6 +606,7 @@ rb_gc_impl_objspace_init(void *objspace_ptr)
604606
605607 objspace -> vo_bit_log_region_size = mmtk_get_vo_bit_log_region_size ();
606608 objspace -> vo_bit_base_addr = mmtk_get_vo_bit_base_addr ();
609+ objspace -> max_non_los_default_alloc_bytes = mmtk_max_non_los_default_alloc_bytes ();
607610}
608611
609612void
@@ -687,6 +690,8 @@ rb_gc_impl_zjit_new_obj_fastpath(void *objspace_ptr, size_t alloc_size, VALUE fl
687690 size_t object_size = total_size - sizeof (VALUE ) - RB_GC_OBJ_SUFFIX_SIZE ;
688691 size_t value_size_shift = sizeof (VALUE ) == 8 ? 3 : 2 ;
689692
693+ if (total_size > objspace -> max_non_los_default_alloc_bytes ) return false;
694+
690695 struct rb_gc_zjit_mmtk_new_obj_fastpath mmtk_fastpath = {
691696 objspace ,
692697 offsetof(struct objspace , total_allocated_objects ),
@@ -956,21 +961,26 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
956961 struct MMTk_ractor_cache * ractor_cache = cache_ptr ;
957962
958963 if (alloc_size == 0 ) {
959- rb_bug ("rb_gc_impl_new_obj: allocation size is zero" );
964+ rb_bug ("rb_gc_impl_new_obj: allocation size out of range (size=%" PRIuSIZE ")" , alloc_size );
960965 }
961966
962967 // Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RB_GC_OBJ_SUFFIX_SIZE)]
963968 size_t total_size = rb_mmtk_align_obj_size (alloc_size + sizeof (VALUE ) + RB_GC_OBJ_SUFFIX_SIZE );
964969 size_t object_size = total_size - sizeof (VALUE ) - RB_GC_OBJ_SUFFIX_SIZE ;
970+ MMTk_AllocationSemantics semantics = total_size > objspace -> max_non_los_default_alloc_bytes
971+ ? MMTK_ALLOCATION_SEMANTICS_LOS
972+ : MMTK_ALLOCATION_SEMANTICS_DEFAULT ;
965973 * actual_alloc_size = object_size ;
966974
967975 if (objspace -> gc_stress ) {
968976 mmtk_handle_user_collection_request (ractor_cache , false, false);
969977 }
970978
971- VALUE * alloc_obj = (VALUE * )rb_mmtk_alloc_fast_path (objspace , ractor_cache , total_size , MMTk_MIN_OBJ_ALIGN );
979+ VALUE * alloc_obj = semantics == MMTK_ALLOCATION_SEMANTICS_DEFAULT
980+ ? (VALUE * )rb_mmtk_alloc_fast_path (objspace , ractor_cache , total_size , MMTk_MIN_OBJ_ALIGN )
981+ : NULL ;
972982 if (!alloc_obj ) {
973- alloc_obj = mmtk_alloc (ractor_cache -> mutator , total_size , MMTk_MIN_OBJ_ALIGN , 0 , MMTK_ALLOCATION_SEMANTICS_DEFAULT );
983+ alloc_obj = mmtk_alloc (ractor_cache -> mutator , total_size , MMTk_MIN_OBJ_ALIGN , 0 , semantics );
974984
975985 // On heap exhaustion raise NoMemoryError.
976986 if (RB_UNLIKELY (alloc_obj == NULL )) {
@@ -983,8 +993,8 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
983993 alloc_obj [0 ] = flags ;
984994 alloc_obj [1 ] = klass ;
985995
986- if (ractor_cache -> bump_pointer == NULL ) {
987- mmtk_post_alloc (ractor_cache -> mutator , (void * )alloc_obj , object_size , MMTK_ALLOCATION_SEMANTICS_DEFAULT );
996+ if (semantics == MMTK_ALLOCATION_SEMANTICS_LOS || ractor_cache -> bump_pointer == NULL ) {
997+ mmtk_post_alloc (ractor_cache -> mutator , (void * )alloc_obj , total_size , semantics );
988998 }
989999 else {
9901000 // We can use the post alloc fast path if we're using Immix bump pointer allocator
@@ -1024,7 +1034,7 @@ rb_gc_impl_size_allocatable_p(size_t size)
10241034size_t
10251035rb_gc_impl_max_allocation_size (void )
10261036{
1027- return SIZE_T_MAX ;
1037+ return SIZE_MAX ;
10281038}
10291039
10301040// Malloc
0 commit comments