summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--class.c4
-rw-r--r--gc.c8
-rw-r--r--hash.c91
-rw-r--r--internal/class.h8
-rw-r--r--memory_view.c24
-rw-r--r--namespace.c4
-rw-r--r--process.c10
-rw-r--r--ractor.c24
-rw-r--r--shape.c4
-rw-r--r--string.c19
-rw-r--r--thread.c4
-rw-r--r--thread_pthread.c7
-rw-r--r--variable.c81
-rw-r--r--vm.c4
-rw-r--r--vm_insnhelper.c19
-rw-r--r--vm_method.c157
-rw-r--r--yjit.c29
-rw-r--r--zjit.c27
18 files changed, 201 insertions, 323 deletions
@@ -446,8 +446,7 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module)
entry = ZALLOC(rb_subclass_entry_t);
entry->klass = klass;
- RB_VM_LOCK_ENTER();
- {
anchor = RCLASS_WRITABLE_SUBCLASSES(super);
VM_ASSERT(anchor);
ns_subclasses = (rb_ns_subclasses_t *)anchor->ns_subclasses;
@@ -464,7 +463,6 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module)
entry->prev = head;
st_insert(tbl, namespace_subclasses_tbl_key(ns), (st_data_t)entry);
}
- RB_VM_LOCK_LEAVE();
if (is_module) {
RCLASS_WRITE_NS_MODULE_SUBCLASSES(klass, anchor->ns_subclasses);
@@ -2280,11 +2280,9 @@ classext_fields_hash_memsize(rb_classext_t *ext, bool prime, VALUE namespace, vo
{
size_t *size = (size_t *)arg;
size_t count;
- RB_VM_LOCK_ENTER();
- {
count = rb_st_table_size((st_table *)RCLASSEXT_FIELDS(ext));
}
- RB_VM_LOCK_LEAVE();
// class IV sizes are allocated as powers of two
*size += SIZEOF_VALUE << bit_length(count);
}
@@ -4570,8 +4568,7 @@ ruby_gc_set_params(void)
void
rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void *data)
{
- RB_VM_LOCK_ENTER();
- {
if (rb_gc_impl_during_gc_p(rb_gc_get_objspace())) rb_bug("rb_objspace_reachable_objects_from() is not supported while during GC");
if (!RB_SPECIAL_CONST_P(obj)) {
@@ -4587,7 +4584,6 @@ rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void *
vm->gc.mark_func_data = prev_mfd;
}
}
- RB_VM_LOCK_LEAVE();
}
struct root_objects_data {
@@ -5170,8 +5170,7 @@ extern char **environ;
#define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
#endif
-#define ENV_LOCK() RB_VM_LOCK_ENTER()
-#define ENV_UNLOCK() RB_VM_LOCK_LEAVE()
static inline rb_encoding *
env_encoding(void)
@@ -5209,12 +5208,10 @@ static VALUE
getenv_with_lock(const char *name)
{
VALUE ret;
- ENV_LOCK();
- {
const char *val = getenv(name);
ret = env_str_new2(val);
}
- ENV_UNLOCK();
return ret;
}
@@ -5223,11 +5220,9 @@ has_env_with_lock(const char *name)
{
const char *val;
- ENV_LOCK();
- {
val = getenv(name);
}
- ENV_UNLOCK();
return val ? true : false;
}
@@ -5477,13 +5472,11 @@ ruby_setenv(const char *name, const char *value)
*wvalue = L'\0';
}
- ENV_LOCK();
- {
/* Use _wputenv_s() instead of SetEnvironmentVariableW() to make sure
* special variables like "TZ" are interpret by libc. */
failed = _wputenv_s(wname, wvalue);
}
- ENV_UNLOCK();
ALLOCV_END(buf);
/* even if putenv() failed, clean up and try to delete the
@@ -5500,28 +5493,22 @@ ruby_setenv(const char *name, const char *value)
#elif defined(HAVE_SETENV) && defined(HAVE_UNSETENV)
if (value) {
int ret;
- ENV_LOCK();
- {
ret = setenv(name, value, 1);
}
- ENV_UNLOCK();
if (ret) rb_sys_fail_sprintf("setenv(%s)", name);
}
else {
#ifdef VOID_UNSETENV
- ENV_LOCK();
- {
unsetenv(name);
}
- ENV_UNLOCK();
#else
int ret;
- ENV_LOCK();
- {
ret = unsetenv(name);
}
- ENV_UNLOCK();
if (ret) rb_sys_fail_sprintf("unsetenv(%s)", name);
#endif
@@ -5544,8 +5531,7 @@ ruby_setenv(const char *name, const char *value)
snprintf(mem_ptr, mem_size, "%s=%s", name, value);
}
- ENV_LOCK();
- {
for (env_ptr = GET_ENVIRON(environ); (str = *env_ptr) != 0; ++env_ptr) {
if (!strncmp(str, name, len) && str[len] == '=') {
if (!in_origenv(str)) free(str);
@@ -5554,15 +5540,12 @@ ruby_setenv(const char *name, const char *value)
}
}
}
- ENV_UNLOCK();
if (value) {
int ret;
- ENV_LOCK();
- {
ret = putenv(mem_ptr);
}
- ENV_UNLOCK();
if (ret) {
free(mem_ptr);
@@ -5573,8 +5556,7 @@ ruby_setenv(const char *name, const char *value)
size_t len;
int i;
- ENV_LOCK();
- {
i = envix(name); /* where does it go? */
if (environ == origenviron) { /* need we copy environment? */
@@ -5615,7 +5597,6 @@ ruby_setenv(const char *name, const char *value)
finish:;
}
- ENV_UNLOCK();
#endif /* WIN32 */
}
@@ -5700,8 +5681,7 @@ env_keys(int raw)
rb_encoding *enc = raw ? 0 : rb_locale_encoding();
VALUE ary = rb_ary_new();
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -5715,7 +5695,6 @@ env_keys(int raw)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return ary;
}
@@ -5745,8 +5724,7 @@ rb_env_size(VALUE ehash, VALUE args, VALUE eobj)
char **env;
long cnt = 0;
- ENV_LOCK();
- {
env = GET_ENVIRON(environ);
for (; *env ; ++env) {
if (strchr(*env, '=')) {
@@ -5755,7 +5733,6 @@ rb_env_size(VALUE ehash, VALUE args, VALUE eobj)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return LONG2FIX(cnt);
}
@@ -5796,8 +5773,7 @@ env_values(void)
{
VALUE ary = rb_ary_new();
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
@@ -5809,7 +5785,6 @@ env_values(void)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return ary;
}
@@ -5890,8 +5865,7 @@ env_each_pair(VALUE ehash)
VALUE ary = rb_ary_new();
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
@@ -5904,7 +5878,6 @@ env_each_pair(VALUE ehash)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
if (rb_block_pair_yield_optimizable()) {
for (i=0; i<RARRAY_LEN(ary); i+=2) {
@@ -6244,8 +6217,7 @@ env_inspect(VALUE _)
VALUE str = rb_str_buf_new2("{");
rb_encoding *enc = env_encoding();
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
const char *s = strchr(*env, '=');
@@ -6263,7 +6235,6 @@ env_inspect(VALUE _)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
rb_str_buf_cat2(str, "}");
@@ -6284,8 +6255,7 @@ env_to_a(VALUE _)
{
VALUE ary = rb_ary_new();
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -6297,7 +6267,6 @@ env_to_a(VALUE _)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return ary;
}
@@ -6321,13 +6290,11 @@ env_size_with_lock(void)
{
int i = 0;
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (env[i]) i++;
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return i;
}
@@ -6363,15 +6330,13 @@ env_empty_p(VALUE _)
{
bool empty = true;
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
if (env[0] != 0) {
empty = false;
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return RBOOL(empty);
}
@@ -6460,8 +6425,7 @@ env_has_value(VALUE dmy, VALUE obj)
VALUE ret = Qfalse;
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -6476,7 +6440,6 @@ env_has_value(VALUE dmy, VALUE obj)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return ret;
}
@@ -6503,8 +6466,7 @@ env_rassoc(VALUE dmy, VALUE obj)
VALUE result = Qnil;
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
@@ -6521,7 +6483,6 @@ env_rassoc(VALUE dmy, VALUE obj)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return result;
}
@@ -6548,8 +6509,7 @@ env_key(VALUE dmy, VALUE value)
StringValue(value);
VALUE str = Qnil;
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -6564,7 +6524,6 @@ env_key(VALUE dmy, VALUE value)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return str;
}
@@ -6574,8 +6533,7 @@ env_to_hash(void)
{
VALUE hash = rb_hash_new();
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -6587,7 +6545,6 @@ env_to_hash(void)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
return hash;
}
@@ -6727,8 +6684,7 @@ env_shift(VALUE _)
VALUE result = Qnil;
VALUE key = Qnil;
- ENV_LOCK();
- {
char **env = GET_ENVIRON(environ);
if (*env) {
const char *p = *env;
@@ -6741,7 +6697,6 @@ env_shift(VALUE _)
}
FREE_ENVIRON(environ);
}
- ENV_UNLOCK();
if (!NIL_P(key)) {
env_delete(key);
@@ -412,8 +412,7 @@ RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
rb_evict_ivars_to_hash(obj); // fallback to ivptr for ivars from shapes
}
- RB_VM_LOCK_ENTER();
- {
// re-check the classext is not created to avoid the multi-thread race
ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, ns);
if (!ext) {
@@ -424,7 +423,6 @@ RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
}
}
}
- RB_VM_LOCK_LEAVE();
return ext;
}
@@ -572,11 +570,9 @@ RCLASS_FIELDS_COUNT(VALUE obj)
// "Too complex" classes could have their IV hash mutated in
// parallel, so lets lock around getting the hash size.
- RB_VM_LOCK_ENTER();
- {
count = (uint32_t)rb_st_table_size(RCLASS_FIELDS_HASH(obj));
}
- RB_VM_LOCK_LEAVE();
return count;
}
@@ -51,11 +51,11 @@ exported_object_registry_mark(void *ptr)
static void
exported_object_registry_free(void *ptr)
{
- RB_VM_LOCK_ENTER();
- st_clear(exported_object_table);
- st_free_table(exported_object_table);
- exported_object_table = NULL;
- RB_VM_LOCK_LEAVE();
}
const rb_data_type_t rb_memory_view_exported_object_registry_data_type = {
@@ -99,18 +99,18 @@ exported_object_dec_ref(st_data_t *key, st_data_t *val, st_data_t arg, int exist
static void
register_exported_object(VALUE obj)
{
- RB_VM_LOCK_ENTER();
- st_update(exported_object_table, (st_data_t)obj, exported_object_add_ref, 0);
- RB_VM_LOCK_LEAVE();
}
static void
unregister_exported_object(VALUE obj)
{
- RB_VM_LOCK_ENTER();
- if (exported_object_table)
- st_update(exported_object_table, (st_data_t)obj, exported_object_dec_ref, 0);
- RB_VM_LOCK_LEAVE();
}
// MemoryView
@@ -389,11 +389,9 @@ static long
namespace_generate_id(void)
{
long id;
- RB_VM_LOCK_ENTER();
- {
id = ++namespace_id_counter;
}
- RB_VM_LOCK_LEAVE();
return id;
}
@@ -4132,12 +4132,10 @@ rb_fork_ruby(int *status)
rb_thread_acquire_fork_lock();
disable_child_handler_before_fork(&old);
- RB_VM_LOCK_ENTER();
- {
child.pid = pid = rb_fork();
child.error = err = errno;
}
- RB_VM_LOCK_LEAVE();
disable_child_handler_fork_parent(&old); /* yes, bad name */
if (
@@ -8756,9 +8754,9 @@ static VALUE rb_mProcID_Syscall;
static VALUE
proc_warmup(VALUE _)
{
- RB_VM_LOCK_ENTER();
- rb_gc_prepare_heap();
- RB_VM_LOCK_LEAVE();
return Qtrue;
}
@@ -2320,12 +2320,10 @@ rb_ractor_teardown(rb_execution_context_t *ec)
ractor_close_outgoing(ec, cr);
// sync with rb_ractor_terminate_interrupt_main_thread()
- RB_VM_LOCK_ENTER();
- {
VM_ASSERT(cr->threads.main != NULL);
cr->threads.main = NULL;
}
- RB_VM_LOCK_LEAVE();
}
void
@@ -2458,11 +2456,9 @@ ractor_check_blocking(rb_ractor_t *cr, unsigned int remained_thread_cnt, const c
// change ractor status: running -> blocking
rb_vm_t *vm = GET_VM();
- RB_VM_LOCK_ENTER();
- {
rb_vm_ractor_blocking_cnt_inc(vm, cr, file, line);
}
- RB_VM_LOCK_LEAVE();
}
}
@@ -2514,11 +2510,9 @@ rb_ractor_blocking_threads_dec(rb_ractor_t *cr, const char *file, int line)
if (cr->threads.cnt == cr->threads.blocking_cnt) {
rb_vm_t *vm = GET_VM();
- RB_VM_LOCK_ENTER();
- {
rb_vm_ractor_blocking_cnt_dec(vm, cr, __FILE__, __LINE__);
}
- RB_VM_LOCK_LEAVE();
}
cr->threads.blocking_cnt--;
@@ -3067,11 +3061,9 @@ obj_traverse_i(VALUE obj, struct obj_traverse_data *data)
.stop = false,
.data = data,
};
- RB_VM_LOCK_ENTER_NO_BARRIER();
- {
rb_objspace_reachable_objects_from(obj, obj_traverse_reachable_i, &d);
}
- RB_VM_LOCK_LEAVE_NO_BARRIER();
if (d.stop) return 1;
}
break;
@@ -3406,11 +3398,9 @@ static int
obj_refer_only_shareables_p(VALUE obj)
{
int cnt = 0;
- RB_VM_LOCK_ENTER_NO_BARRIER();
- {
rb_objspace_reachable_objects_from(obj, obj_refer_only_shareables_p_i, &cnt);
}
- RB_VM_LOCK_LEAVE_NO_BARRIER();
return cnt == 0;
}
@@ -3840,15 +3830,13 @@ rb_ractor_local_storage_value_newkey(void)
void
rb_ractor_local_storage_delkey(rb_ractor_local_key_t key)
{
- RB_VM_LOCK_ENTER();
- {
if (freed_ractor_local_keys.cnt == freed_ractor_local_keys.capa) {
freed_ractor_local_keys.capa = freed_ractor_local_keys.capa ? freed_ractor_local_keys.capa * 2 : 4;
REALLOC_N(freed_ractor_local_keys.keys, rb_ractor_local_key_t, freed_ractor_local_keys.capa);
}
freed_ractor_local_keys.keys[freed_ractor_local_keys.cnt++] = key;
}
- RB_VM_LOCK_LEAVE();
}
static bool
@@ -517,8 +517,7 @@ get_next_shape_internal(rb_shape_t *shape, ID id, enum shape_type shape_type, bo
}
}
- RB_VM_LOCK_ENTER();
- {
// The situation may have changed while we waited for the lock.
// So we load the edge again.
edges = RUBY_ATOMIC_PTR_LOAD(shape->edges);
@@ -577,7 +576,6 @@ get_next_shape_internal(rb_shape_t *shape, ID id, enum shape_type shape_type, bo
}
}
}
- RB_VM_LOCK_LEAVE();
return res;
}
@@ -682,10 +682,8 @@ fstring_insert_on_resize(struct fstring_table_struct *table, VALUE hash_code, VA
// Rebuilds the table
static void
-fstring_try_resize(VALUE old_table_obj)
{
- RB_VM_LOCK_ENTER();
-
// Check if another thread has already resized
if (RUBY_ATOMIC_VALUE_LOAD(fstring_table_obj) != old_table_obj) {
goto end;
@@ -737,7 +735,14 @@ fstring_try_resize(VALUE old_table_obj)
end:
RB_GC_GUARD(old_table_obj);
- RB_VM_LOCK_LEAVE();
}
static VALUE
@@ -749,7 +754,7 @@ fstring_find_or_insert(VALUE hash_code, VALUE value, struct fstr_update_arg *arg
VALUE table_obj;
struct fstring_table_struct *table;
- retry:
table_obj = RUBY_ATOMIC_VALUE_LOAD(fstring_table_obj);
RUBY_ASSERT(table_obj);
table = RTYPEDDATA_GET_DATA(table_obj);
@@ -798,8 +803,7 @@ fstring_find_or_insert(VALUE hash_code, VALUE value, struct fstr_update_arg *arg
}
else if (candidate == FSTRING_TABLE_MOVED) {
// Wait
- RB_VM_LOCK_ENTER();
- RB_VM_LOCK_LEAVE();
goto retry;
}
@@ -13271,3 +13275,4 @@ Init_String(void)
rb_define_method(rb_cSymbol, "encoding", sym_encoding, 0);
}
@@ -2569,8 +2569,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
terminate_interrupt = interrupt & TERMINATE_INTERRUPT_MASK; // request from other ractors
if (interrupt & VM_BARRIER_INTERRUPT_MASK) {
- RB_VM_LOCK_ENTER();
- RB_VM_LOCK_LEAVE();
}
if (postponed_job_interrupt) {
@@ -6236,3 +6235,4 @@ rb_ractor_interrupt_exec(struct rb_ractor_struct *target_r,
// TODO MEMO: we can create a new thread in a ractor, but not sure how to do that now.
}
@@ -630,8 +630,7 @@ thread_sched_setup_running_threads(struct rb_thread_sched *sched, rb_ractor_t *c
#endif
thread_sched_unlock(sched, lock_owner);
{
- RB_VM_LOCK_ENTER();
- RB_VM_LOCK_LEAVE();
}
thread_sched_lock(sched, lock_owner);
}
@@ -2283,11 +2282,9 @@ rb_threadptr_remove(rb_thread_t *th)
rb_vm_t *vm = th->vm;
th->sched.finished = false;
- RB_VM_LOCK_ENTER();
- {
ccan_list_add(&vm->ractor.sched.zombie_threads, &th->sched.node.zombie_threads);
}
- RB_VM_LOCK_LEAVE();
}
#endif
}
@@ -303,9 +303,7 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name)
if (NIL_P(name)) {
// Set the temporary classpath to NULL (anonymous):
- RB_VM_LOCK_ENTER();
- set_sub_temporary_name(mod, 0);
- RB_VM_LOCK_LEAVE();
}
else {
// Ensure the name is a string:
@@ -322,9 +320,7 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name)
name = rb_str_new_frozen(name);
// Set the temporary classpath to the given name:
- RB_VM_LOCK_ENTER();
- set_sub_temporary_name(mod, name);
- RB_VM_LOCK_LEAVE();
}
return mod;
@@ -1209,14 +1205,12 @@ rb_gen_fields_tbl_get(VALUE obj, ID id, struct gen_fields_tbl **fields_tbl)
st_data_t data;
int r = 0;
- RB_VM_LOCK_ENTER();
- {
if (st_lookup(generic_fields_tbl(obj, id, false), (st_data_t)obj, &data)) {
*fields_tbl = (struct gen_fields_tbl *)data;
r = 1;
}
}
- RB_VM_LOCK_LEAVE();
return r;
}
@@ -1273,8 +1267,7 @@ rb_free_generic_ivar(VALUE obj)
bool too_complex = rb_shape_obj_too_complex_p(obj);
- RB_VM_LOCK_ENTER();
- {
if (st_delete(generic_fields_tbl_no_ractor_check(obj), &key, &value)) {
struct gen_fields_tbl *fields_tbl = (struct gen_fields_tbl *)value;
@@ -1285,7 +1278,6 @@ rb_free_generic_ivar(VALUE obj)
xfree(fields_tbl);
}
}
- RB_VM_LOCK_LEAVE();
}
size_t
@@ -1311,8 +1303,7 @@ rb_generic_shape_id(VALUE obj)
struct gen_fields_tbl *fields_tbl = 0;
shape_id_t shape_id = 0;
- RB_VM_LOCK_ENTER();
- {
st_table* global_iv_table = generic_fields_tbl(obj, 0, false);
if (global_iv_table && st_lookup(global_iv_table, obj, (st_data_t *)&fields_tbl)) {
@@ -1322,7 +1313,6 @@ rb_generic_shape_id(VALUE obj)
shape_id = SPECIAL_CONST_SHAPE_ID;
}
}
- RB_VM_LOCK_LEAVE();
return shape_id;
}
@@ -1421,8 +1411,7 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
bool found = false;
VALUE val;
- RB_VM_LOCK_ENTER();
- {
#if !SHAPE_IN_BASIC_FLAGS
shape_id = RCLASS_SHAPE_ID(obj);
#endif
@@ -1452,7 +1441,6 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
}
}
}
- RB_VM_LOCK_LEAVE();
if (found &&
rb_is_instance_id(id) &&
@@ -1678,8 +1666,7 @@ obj_transition_too_complex(VALUE obj, st_table *table)
RCLASS_SET_FIELDS_HASH(obj, table);
break;
default:
- RB_VM_LOCK_ENTER();
- {
struct st_table *gen_ivs = generic_fields_tbl_no_ractor_check(obj);
struct gen_fields_tbl *old_fields_tbl = NULL;
@@ -1709,7 +1696,6 @@ obj_transition_too_complex(VALUE obj, st_table *table)
fields_tbl->shape_id = shape_id;
#endif
}
- RB_VM_LOCK_LEAVE();
}
xfree(old_fields);
@@ -1911,11 +1897,9 @@ generic_ivar_set_shape_fields(VALUE obj, void *data)
struct gen_fields_lookup_ensure_size *fields_lookup = data;
- RB_VM_LOCK_ENTER();
- {
st_update(generic_fields_tbl(obj, fields_lookup->id, false), (st_data_t)obj, generic_fields_lookup_ensure_size, (st_data_t)fields_lookup);
}
- RB_VM_LOCK_LEAVE();
FL_SET_RAW(obj, FL_EXIVAR);
@@ -1958,11 +1942,9 @@ generic_ivar_set_too_complex_table(VALUE obj, void *data)
#endif
fields_tbl->as.complex.table = st_init_numtable_with_size(1);
- RB_VM_LOCK_ENTER();
- {
st_insert(generic_fields_tbl(obj, fields_lookup->id, false), (st_data_t)obj, (st_data_t)fields_tbl);
}
- RB_VM_LOCK_LEAVE();
FL_SET_RAW(obj, FL_EXIVAR);
}
@@ -2132,8 +2114,7 @@ rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id)
default:
if (shape_id != SPECIAL_CONST_SHAPE_ID) {
struct gen_fields_tbl *fields_tbl = 0;
- RB_VM_LOCK_ENTER();
- {
st_table* global_iv_table = generic_fields_tbl(obj, 0, false);
if (st_lookup(global_iv_table, obj, (st_data_t *)&fields_tbl)) {
@@ -2143,7 +2124,6 @@ rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id)
rb_bug("Expected shape_id entry in global iv table");
}
}
- RB_VM_LOCK_LEAVE();
}
}
#endif
@@ -2501,12 +2481,10 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
* c.fields_tbl may change in gen_fields_copy due to realloc,
* no need to free
*/
- RB_VM_LOCK_ENTER();
- {
generic_fields_tbl_no_ractor_check(dest);
st_insert(generic_fields_tbl_no_ractor_check(obj), (st_data_t)dest, (st_data_t)new_fields_tbl);
}
- RB_VM_LOCK_LEAVE();
rb_shape_set_shape(dest, shape_to_set_on_dest);
}
@@ -2527,8 +2505,7 @@ rb_replace_generic_ivar(VALUE clone, VALUE obj)
{
RUBY_ASSERT(FL_TEST(obj, FL_EXIVAR));
- RB_VM_LOCK_ENTER();
- {
st_data_t fields_tbl, obj_data = (st_data_t)obj;
if (st_delete(generic_fields_tbl_, &obj_data, &fields_tbl)) {
FL_UNSET_RAW(obj, FL_EXIVAR);
@@ -2540,7 +2517,6 @@ rb_replace_generic_ivar(VALUE clone, VALUE obj)
rb_bug("unreachable");
}
}
- RB_VM_LOCK_LEAVE();
}
void
@@ -2554,11 +2530,9 @@ rb_field_foreach(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
case T_CLASS:
case T_MODULE:
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(0);
- RB_VM_LOCK_ENTER();
- {
class_fields_each(obj, func, arg, ivar_only);
}
- RB_VM_LOCK_LEAVE();
break;
default:
if (FL_TEST(obj, FL_EXIVAR)) {
@@ -3367,11 +3341,9 @@ autoload_const_set(struct autoload_const *ac)
{
check_before_mod_set(ac->module, ac->name, ac->value, "constant");
- RB_VM_LOCK_ENTER();
- {
const_tbl_update(ac, true);
}
- RB_VM_LOCK_LEAVE();
return 0; /* ignored */
}
@@ -3916,12 +3888,10 @@ rb_local_constants(VALUE mod)
if (!tbl) return rb_ary_new2(0);
- RB_VM_LOCK_ENTER();
- {
ary = rb_ary_new2(rb_id_table_size(tbl));
rb_id_table_foreach(tbl, rb_local_constants_i, (void *)ary);
}
- RB_VM_LOCK_LEAVE();
return ary;
}
@@ -3934,11 +3904,9 @@ rb_mod_const_at(VALUE mod, void *data)
tbl = st_init_numtable();
}
if (RCLASS_CONST_TBL(mod)) {
- RB_VM_LOCK_ENTER();
- {
rb_id_table_foreach(RCLASS_CONST_TBL(mod), sv_i, tbl);
}
- RB_VM_LOCK_LEAVE();
}
return tbl;
}
@@ -4113,15 +4081,13 @@ set_namespace_path(VALUE named_namespace, VALUE namespace_path)
{
struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace);
- RB_VM_LOCK_ENTER();
- {
RCLASS_WRITE_CLASSPATH(named_namespace, namespace_path, true);
if (const_table) {
rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path);
}
}
- RB_VM_LOCK_LEAVE();
}
static void
@@ -4149,8 +4115,7 @@ const_set(VALUE klass, ID id, VALUE val)
check_before_mod_set(klass, id, val, "constant");
- RB_VM_LOCK_ENTER();
- {
struct rb_id_table *tbl = RCLASS_WRITABLE_CONST_TBL(klass);
if (!tbl) {
tbl = rb_id_table_create(0);
@@ -4170,7 +4135,6 @@ const_set(VALUE klass, ID id, VALUE val)
const_tbl_update(&ac, false);
}
}
- RB_VM_LOCK_LEAVE();
/*
* Resolve and cache class name immediately to resolve ambiguity
@@ -4846,8 +4810,7 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val)
rb_class_ensure_writable(obj);
- RB_VM_LOCK_ENTER();
- {
existing = general_ivar_set(obj, id, val, NULL,
class_ivar_set_shape_fields,
class_ivar_set_shape_resize_fields,
@@ -4855,7 +4818,6 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val)
class_ivar_set_transition_too_complex,
class_ivar_set_too_complex_table).existing;
}
- RB_VM_LOCK_LEAVE();
return existing;
}
@@ -4898,11 +4860,9 @@ const_lookup(struct rb_id_table *tbl, ID id)
if (tbl) {
VALUE val;
bool r;
- RB_VM_LOCK_ENTER();
- {
r = rb_id_table_lookup(tbl, id, &val);
}
- RB_VM_LOCK_LEAVE();
if (r) return (rb_const_entry_t *)val;
}
@@ -4914,3 +4874,4 @@ rb_const_lookup(VALUE klass, ID id)
{
return const_lookup(RCLASS_CONST_TBL(klass), id);
}
@@ -4491,8 +4491,7 @@ rb_vm_register_global_object(VALUE obj)
default:
break;
}
- RB_VM_LOCK_ENTER();
- {
VALUE list = GET_VM()->mark_object_ary;
VALUE head = pin_array_list_append(list, obj);
if (head != list) {
@@ -4500,7 +4499,6 @@ rb_vm_register_global_object(VALUE obj)
}
RB_GC_GUARD(obj);
}
- RB_VM_LOCK_LEAVE();
}
void
@@ -2187,8 +2187,7 @@ rb_vm_search_method_slowpath(const struct rb_callinfo *ci, VALUE klass)
VM_ASSERT_TYPE2(klass, T_CLASS, T_ICLASS);
- RB_VM_LOCK_ENTER();
- {
cc = vm_search_cc(klass, ci);
VM_ASSERT(cc);
@@ -2198,7 +2197,6 @@ rb_vm_search_method_slowpath(const struct rb_callinfo *ci, VALUE klass)
VM_ASSERT(cc == vm_cc_empty() || !METHOD_ENTRY_INVALIDATED(vm_cc_cme(cc)));
VM_ASSERT(cc == vm_cc_empty() || vm_cc_cme(cc)->called_id == vm_ci_mid(ci));
}
- RB_VM_LOCK_LEAVE();
return cc;
}
@@ -6388,15 +6386,13 @@ vm_track_constant_cache(ID id, void *ic)
static void
vm_ic_track_const_chain(rb_control_frame_t *cfp, IC ic, const ID *segments)
{
- RB_VM_LOCK_ENTER();
-
- for (int i = 0; segments[i]; i++) {
- ID id = segments[i];
- if (id == idNULL) continue;
- vm_track_constant_cache(id, ic);
}
-
- RB_VM_LOCK_LEAVE();
}
// For JIT inlining
@@ -7464,3 +7460,4 @@ rb_vm_lvar_exposed(rb_execution_context_t *ec, int index)
const rb_control_frame_t *cfp = ec->cfp;
return cfp->ep[index];
}
@@ -245,91 +245,89 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid)
VM_ASSERT_TYPE2(klass, T_CLASS, T_ICLASS);
if (rb_objspace_garbage_object_p(klass)) return;
- RB_VM_LOCK_ENTER();
- if (LIKELY(RCLASS_SUBCLASSES_FIRST(klass) == NULL)) {
- // no subclasses
- // check only current class
-
- // invalidate CCs
- struct rb_id_table *cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
- invalidate_method_cache_in_cc_table(cc_tbl, mid);
- if (RCLASS_CC_TBL_NOT_PRIME_P(klass, cc_tbl)) {
- invalidate_method_cache_in_cc_table(RCLASS_PRIME_CC_TBL(klass), mid);
- }
-
- // remove from callable_m_tbl, if exists
- struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(klass);
- invalidate_callable_method_entry_in_callable_m_table(cm_tbl, mid);
- if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(klass, cm_tbl)) {
- invalidate_callable_method_entry_in_callable_m_table(RCLASS_PRIME_CALLABLE_M_TBL(klass), mid);
}
-
- RB_DEBUG_COUNTER_INC(cc_invalidate_leaf);
- }
- else {
- const rb_callable_method_entry_t *cme = complemented_callable_method_entry(klass, mid);
-
- if (cme) {
- // invalidate cme if found to invalidate the inline method cache.
- if (METHOD_ENTRY_CACHED(cme)) {
- if (METHOD_ENTRY_COMPLEMENTED(cme)) {
- // do nothing
- }
- else {
- // invalidate cc by invalidating cc->cme
- VALUE owner = cme->owner;
- VM_ASSERT_TYPE(owner, T_CLASS);
- VALUE klass_housing_cme;
- if (cme->def->type == VM_METHOD_TYPE_REFINED && !cme->def->body.refined.orig_me) {
- klass_housing_cme = owner;
}
else {
- klass_housing_cme = RCLASS_ORIGIN(owner);
}
-
- // replace the cme that will be invalid in the all classexts
- invalidate_callable_method_entry_in_every_m_table(klass_housing_cme, mid, cme);
- }
-
- vm_cme_invalidate((rb_callable_method_entry_t *)cme);
- RB_DEBUG_COUNTER_INC(cc_invalidate_tree_cme);
-
- // In case of refinement ME, also invalidate the wrapped ME that
- // could be cached at some callsite and is unreachable from any
- // RCLASS_WRITABLE_CC_TBL.
- if (cme->def->type == VM_METHOD_TYPE_REFINED && cme->def->body.refined.orig_me) {
- vm_cme_invalidate((rb_callable_method_entry_t *)cme->def->body.refined.orig_me);
}
-
- if (cme->def->iseq_overload) {
- rb_callable_method_entry_t *monly_cme = (rb_callable_method_entry_t *)lookup_overloaded_cme(cme);
- if (monly_cme) {
- vm_cme_invalidate(monly_cme);
}
}
}
-
- // invalidate complement tbl
- if (METHOD_ENTRY_COMPLEMENTED(cme)) {
- VALUE defined_class = cme->defined_class;
- struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
- invalidate_complemented_method_entry_in_callable_m_table(cm_tbl, mid);
- if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(defined_class, cm_tbl)) {
- struct rb_id_table *prime_cm_table = RCLASS_PRIME_CALLABLE_M_TBL(defined_class);
- invalidate_complemented_method_entry_in_callable_m_table(prime_cm_table, mid);
- }
}
-
- RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
}
- else {
- invalidate_negative_cache(mid);
- }
- }
-
- rb_gccct_clear_table(Qnil);
-
- RB_VM_LOCK_LEAVE();
}
static void
@@ -502,8 +500,7 @@ rb_vm_ci_lookup(ID mid, unsigned int flag, unsigned int argc, const struct rb_ca
new_ci->flag = flag;
new_ci->argc = argc;
- RB_VM_LOCK_ENTER();
- {
st_table *ci_table = vm->ci_table;
VM_ASSERT(ci_table);
@@ -511,7 +508,6 @@ rb_vm_ci_lookup(ID mid, unsigned int flag, unsigned int argc, const struct rb_ca
st_update(ci_table, (st_data_t)new_ci, ci_lookup_i, (st_data_t)&ci);
} while (ci == NULL);
}
- RB_VM_LOCK_LEAVE();
VM_ASSERT(ci);
@@ -1596,8 +1592,7 @@ callable_method_entry_or_negative(VALUE klass, ID mid, VALUE *defined_class_ptr)
const rb_callable_method_entry_t *cme;
VM_ASSERT_TYPE2(klass, T_CLASS, T_ICLASS);
- RB_VM_LOCK_ENTER();
- {
cme = cached_callable_method_entry(klass, mid);
if (cme) {
@@ -1618,7 +1613,6 @@ callable_method_entry_or_negative(VALUE klass, ID mid, VALUE *defined_class_ptr)
cache_callable_method_entry(klass, mid, cme);
}
}
- RB_VM_LOCK_LEAVE();
return cme;
}
@@ -3165,3 +3159,4 @@ Init_eval_method(void)
REPLICATE_METHOD(rb_eException, idRespond_to_missing);
}
}
@@ -745,21 +745,19 @@ rb_yjit_vm_unlock(unsigned int *recursive_lock_level, const char *file, int line
void
rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception)
{
- RB_VM_LOCK_ENTER();
- rb_vm_barrier();
-
- // Compile a block version starting at the current instruction
- uint8_t *rb_yjit_iseq_gen_entry_point(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception); // defined in Rust
- uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
-
- if (jit_exception) {
- iseq->body->jit_exception = (rb_jit_func_t)code_ptr;
- }
- else {
- iseq->body->jit_entry = (rb_jit_func_t)code_ptr;
- }
-
- RB_VM_LOCK_LEAVE();
}
// GC root for interacting with the GC
@@ -860,3 +858,4 @@ static VALUE yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self) { return Q
// Preprocessed yjit.rb generated during build
#include "yjit.rbinc"
@@ -162,20 +162,18 @@ void rb_zjit_profile_disable(const rb_iseq_t *iseq);
void
rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception)
{
- RB_VM_LOCK_ENTER();
- rb_vm_barrier();
-
- // Convert ZJIT instructions back to bare instructions
- rb_zjit_profile_disable(iseq);
-
- // Compile a block version starting at the current instruction
- uint8_t *rb_zjit_iseq_gen_entry_point(const rb_iseq_t *iseq, rb_execution_context_t *ec); // defined in Rust
- uintptr_t code_ptr = (uintptr_t)rb_zjit_iseq_gen_entry_point(iseq, ec);
-
- // TODO: support jit_exception
- iseq->body->jit_entry = (rb_jit_func_t)code_ptr;
-
- RB_VM_LOCK_LEAVE();
}
extern VALUE *rb_vm_base_ptr(struct rb_control_frame_struct *cfp);
@@ -334,3 +332,4 @@ rb_zjit_print_exception(void)
// Preprocessed zjit.rb generated during build
#include "zjit.rbinc"