mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[wasm] Disallow compaction
WebAssembly doesn't support signals so we can't use read barriers so we can't use compaction.
This commit is contained in:
		
							parent
							
								
									5de62fe37c
								
							
						
					
					
						commit
						663833b08f
					
				
				
				Notes:
				
					git
				
				2022-01-24 23:21:39 +09:00 
				
			
			
			
		
		
					 2 changed files with 27 additions and 12 deletions
				
			
		
							
								
								
									
										38
									
								
								gc.c
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								gc.c
									
										
									
									
									
								
							| 
						 | 
					@ -5014,14 +5014,13 @@ gc_unprotect_pages(rb_objspace_t *objspace, rb_heap_t *heap)
 | 
				
			||||||
static void gc_update_references(rb_objspace_t * objspace);
 | 
					static void gc_update_references(rb_objspace_t * objspace);
 | 
				
			||||||
static void invalidate_moved_page(rb_objspace_t *objspace, struct heap_page *page);
 | 
					static void invalidate_moved_page(rb_objspace_t *objspace, struct heap_page *page);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(__wasi__)
 | 
					#if defined(__wasi__) /* WebAssembly doesn't support signals */
 | 
				
			||||||
// read barrier for pages containing MOVED objects
 | 
					# define GC_COMPACTION_SUPPORTED 0
 | 
				
			||||||
# define GC_ENABLE_READ_SIGNAL_BARRIER 1
 | 
					 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
# define GC_ENABLE_READ_SIGNAL_BARRIER 0
 | 
					# define GC_COMPACTION_SUPPORTED 1
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if GC_ENABLE_READ_SIGNAL_BARRIER
 | 
					#if GC_COMPACTION_SUPPORTED
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
read_barrier_handler(uintptr_t address)
 | 
					read_barrier_handler(uintptr_t address)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -5042,8 +5041,21 @@ read_barrier_handler(uintptr_t address)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    RB_VM_LOCK_LEAVE();
 | 
					    RB_VM_LOCK_LEAVE();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(_WIN32)
 | 
					#if !GC_COMPACTION_SUPPORTED
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					uninstall_handlers(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /* no-op */
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					install_handlers(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /* no-op */
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#elif defined(_WIN32)
 | 
				
			||||||
static LPTOP_LEVEL_EXCEPTION_FILTER old_handler;
 | 
					static LPTOP_LEVEL_EXCEPTION_FILTER old_handler;
 | 
				
			||||||
typedef void (*signal_handler)(int);
 | 
					typedef void (*signal_handler)(int);
 | 
				
			||||||
static signal_handler old_sigsegv_handler;
 | 
					static signal_handler old_sigsegv_handler;
 | 
				
			||||||
| 
						 | 
					@ -5130,8 +5142,6 @@ install_handlers(void)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // GC_ENABLE_READ_SIGNAL_BARRIER
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
revert_stack_objects(VALUE stack_obj, void *ctx)
 | 
					revert_stack_objects(VALUE stack_obj, void *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -5178,9 +5188,7 @@ gc_compact_finish(rb_objspace_t *objspace, rb_size_pool_t *pool, rb_heap_t *heap
 | 
				
			||||||
        gc_unprotect_pages(objspace, heap);
 | 
					        gc_unprotect_pages(objspace, heap);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if GC_ENABLE_READ_SIGNAL_BARRIER
 | 
					 | 
				
			||||||
    uninstall_handlers();
 | 
					    uninstall_handlers();
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* The mutator is allowed to run during incremental sweeping. T_MOVED
 | 
					    /* The mutator is allowed to run during incremental sweeping. T_MOVED
 | 
				
			||||||
     * objects can get pushed on the stack and when the compaction process
 | 
					     * objects can get pushed on the stack and when the compaction process
 | 
				
			||||||
| 
						 | 
					@ -5902,9 +5910,7 @@ gc_compact_start(rb_objspace_t *objspace)
 | 
				
			||||||
    memset(objspace->rcompactor.moved_count_table, 0, T_MASK * sizeof(size_t));
 | 
					    memset(objspace->rcompactor.moved_count_table, 0, T_MASK * sizeof(size_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Set up read barrier for pages containing MOVED objects */
 | 
					    /* Set up read barrier for pages containing MOVED objects */
 | 
				
			||||||
#if GC_ENABLE_READ_SIGNAL_BARRIER
 | 
					 | 
				
			||||||
    install_handlers();
 | 
					    install_handlers();
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -9324,6 +9330,10 @@ gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !GC_COMPACTION_SUPPORTED
 | 
				
			||||||
 | 
					        rb_raise(rb_eNotImpError, "Compaction isn't available on this platform");
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        reason |= GPR_FLAG_COMPACT;
 | 
					        reason |= GPR_FLAG_COMPACT;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
| 
						 | 
					@ -10921,6 +10931,10 @@ gc_set_auto_compact(rb_execution_context_t *ec, VALUE _, VALUE v)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !GC_COMPACTION_SUPPORTED
 | 
				
			||||||
 | 
					    rb_raise(rb_eNotImpError, "Automatic compaction isn't available on this platform");
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ruby_enable_autocompact = RTEST(v);
 | 
					    ruby_enable_autocompact = RTEST(v);
 | 
				
			||||||
    return v;
 | 
					    return v;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@ class TestGCCompact < Test::Unit::TestCase
 | 
				
			||||||
    private
 | 
					    private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def supports_auto_compact?
 | 
					    def supports_auto_compact?
 | 
				
			||||||
 | 
					      return false if /wasm/ =~ RUBY_PLATFORM
 | 
				
			||||||
      return true unless defined?(Etc::SC_PAGE_SIZE)
 | 
					      return true unless defined?(Etc::SC_PAGE_SIZE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue