Lines Matching refs:th

73 vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, VALUE defined_class,
136 vm_set_top_stack(rb_thread_t * th, VALUE iseqval)
146 CHECK_VM_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max);
147 vm_push_frame(th, iseq, VM_FRAME_MAGIC_TOP | VM_FRAME_FLAG_FINISH,
148 th->top_self, rb_cObject, VM_ENVVAL_BLOCK_PTR(0),
149 iseq->iseq_encoded, th->cfp->sp, iseq->local_size, 0);
153 vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t *base_block)
158 CHECK_VM_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max);
159 vm_push_frame(th, iseq, VM_FRAME_MAGIC_EVAL | VM_FRAME_FLAG_FINISH,
162 th->cfp->sp, iseq->local_size, 0);
165 th->cfp->ep[-1] = (VALUE)cref;
170 vm_set_main_stack(rb_thread_t *th, VALUE iseqval)
179 vm_set_eval_stack(th, iseqval, 0, &env->block);
184 bind->env = rb_vm_make_env_object(th, th->cfp);
189 rb_vm_get_binding_creatable_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
191 while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
201 rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
203 while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
213 vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
221 while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
264 #define ENV_IN_HEAP_P(th, env) \
265 (!((th)->stack <= (env) && (env) < ((th)->stack + (th)->stack_size)))
373 vm_make_env_each(rb_thread_t * const th, rb_control_frame_t * const cfp,
381 if (ENV_IN_HEAP_P(th, envptr)) {
389 if (ENV_IN_HEAP_P(th, penvptr)) {
400 penvval = vm_make_env_each(th, pcfp, penvptr, endptr);
424 fprintf(stderr, "%2d ", &envptr[-local_size + i] - th->stack); dp(env->env[i]);
477 vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *ep, VALUE ary)
479 if (ENV_IN_HEAP_P(th, ep)) {
490 static void vm_rewrite_ep_in_errinfo(rb_thread_t *th);
491 static VALUE vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block);
492 static VALUE vm_make_env_object(rb_thread_t * th, rb_control_frame_t *cfp, VALUE *blockprocptr);
495 rb_vm_make_env_object(rb_thread_t * th, rb_control_frame_t *cfp)
498 return vm_make_env_object(th, cfp, &blockprocval);
502 vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *blockprocptr)
509 VALUE blockprocval = vm_make_proc_from_block(th, blockptr);
516 envval = vm_make_env_each(th, cfp, cfp->ep, lep);
517 vm_rewrite_ep_in_errinfo(th);
527 vm_rewrite_ep_in_errinfo(rb_thread_t *th)
529 rb_control_frame_t *cfp = th->cfp;
530 while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
538 if (! ENV_IN_HEAP_P(th, escape_ep)) {
553 rb_vm_stack_to_heap(rb_thread_t *th)
555 rb_control_frame_t *cfp = th->cfp;
556 while ((cfp = rb_vm_get_binding_creatable_next_cfp(th, cfp)) != 0) {
557 rb_vm_make_env_object(th, cfp);
565 vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block)
568 block->proc = rb_vm_make_proc(th, block, rb_cProc);
574 rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass)
584 envval = vm_make_env_object(th, cfp, &blockprocval);
598 proc->safe_level = th->safe_level;
601 if (th->stack < block->ep && block->ep < th->stack + th->stack_size) {
612 invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
626 cfp = th->cfp;
633 opt_pc = vm_yield_setup_args(th, iseq, argc, cfp->sp, blockptr,
636 vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH,
641 th->passed_me);
642 th->passed_me = 0;
645 th->cfp->ep[-1] = (VALUE)cref;
648 return vm_exec(th);
651 return vm_yield_with_cfunc(th, block, self, argc, argv, blockptr);
656 check_block(rb_thread_t *th)
658 const rb_block_t *blockptr = VM_CF_BLOCK_PTR(th->cfp);
668 vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref)
670 const rb_block_t *blockptr = check_block(th);
671 return invoke_block_from_c(th, blockptr, blockptr->self, argc, argv, 0, cref,
676 vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
678 const rb_block_t *blockptr = check_block(th);
679 return invoke_block_from_c(th, blockptr, blockptr->self, argc, argv, 0, 0,
684 vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, VALUE defined_class,
689 volatile int stored_safe = th->safe_level;
691 TH_PUSH_TAG(th);
694 th->safe_level = proc->safe_level;
696 val = invoke_block_from_c(th, &proc->block, self, argc, argv, blockptr, 0,
702 th->safe_level = stored_safe;
712 rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
715 return vm_invoke_proc(th, proc, proc->block.self, proc->block.klass,
722 vm_normal_frame(rb_thread_t *th, rb_control_frame_t *cfp)
726 if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
734 vm_cfp_svar_get(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key)
736 cfp = vm_normal_frame(th, cfp);
737 return lep_svar_get(th, cfp ? VM_CF_LEP(cfp) : 0, key);
741 vm_cfp_svar_set(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key, const VALUE val)
743 cfp = vm_normal_frame(th, cfp);
744 lep_svar_set(th, cfp ? VM_CF_LEP(cfp) : 0, key, val);
750 rb_thread_t *th = GET_THREAD();
751 return vm_cfp_svar_get(th, th->cfp, key);
757 rb_thread_t *th = GET_THREAD();
758 vm_cfp_svar_set(th, th->cfp, key, val);
790 rb_thread_t *th = GET_THREAD();
791 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
804 rb_thread_t *th = GET_THREAD();
805 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
818 rb_thread_t *th = GET_THREAD();
819 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
832 rb_thread_t *th = GET_THREAD();
833 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
856 rb_thread_t *th = GET_THREAD();
857 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
946 NORETURN(static void vm_iter_break(rb_thread_t *th, VALUE val));
949 vm_iter_break(rb_thread_t *th, VALUE val)
951 rb_control_frame_t *cfp = th->cfp;
954 th->state = TAG_BREAK;
955 th->errinfo = (VALUE)NEW_THROW_OBJECT(val, (VALUE)ep, TAG_BREAK);
956 TH_JUMP_TAG(th, TAG_BREAK);
1190 vm_exec(rb_thread_t *th)
1197 TH_PUSH_TAG(th);
1201 result = vm_exec_core(th, initial);
1202 if ((state = th->state) != 0) {
1204 th->state = 0;
1216 err = th->errinfo;
1221 while (th->cfp->pc == 0 || th->cfp->iseq == 0) {
1222 if (UNLIKELY(VM_FRAME_TYPE(th->cfp) == VM_FRAME_MAGIC_CFUNC)) {
1223 const rb_method_entry_t *me = th->cfp->me;
1224 EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass, Qnil);
1225 RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->klass, me->called_id);
1227 th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
1230 cfp = th->cfp;
1256 th->errinfo = Qnil;
1257 vm_pop_frame(th);
1268 *th->cfp->sp++ = (GET_THROWOBJ_VAL(err));
1270 th->errinfo = Qnil;
1307 th->errinfo = Qnil;
1336 *th->cfp->sp++ = (GET_THROWOBJ_VAL(err));
1339 th->errinfo = Qnil;
1340 th->state = 0;
1380 vm_push_frame(th, catch_iseq, VM_FRAME_MAGIC_BLOCK,
1389 th->state = 0;
1390 th->errinfo = Qnil;
1396 switch (VM_FRAME_TYPE(th->cfp)) {
1398 RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0);
1399 EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
1402 EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
1405 EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
1409 if (VM_FRAME_TYPE_FINISH_P(th->cfp)) {
1410 vm_pop_frame(th);
1411 th->errinfo = err;
1416 th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
1431 rb_thread_t *th = GET_THREAD();
1434 vm_set_top_stack(th, iseqval);
1436 val = vm_exec(th);
1444 rb_thread_t *th = GET_THREAD();
1447 vm_set_main_stack(th, iseqval);
1449 val = vm_exec(th);
1483 rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp)
1485 return rb_vm_control_frame_id_and_class(th->cfp, idp, klassp);
1495 rb_thread_current_status(const rb_thread_t *th)
1497 const rb_control_frame_t *cfp = th->cfp;
1522 rb_thread_t *th = GET_THREAD();
1523 const rb_control_frame_t *reg_cfp = th->cfp;
1527 vm_push_frame(th, DATA_PTR(iseqval), VM_FRAME_MAGIC_TOP | VM_FRAME_FLAG_FINISH,
1532 vm_pop_frame(th);
1600 rb_thread_t *th = vm->main_thread;
1606 if (th) {
1607 rb_fiber_reset_root_local_storage(th->self);
1608 thread_free(th);
1790 rb_thread_t *th = NULL;
1793 th = ptr;
1794 if (th->stack) {
1795 VALUE *p = th->stack;
1796 VALUE *sp = th->cfp->sp;
1797 rb_control_frame_t *cfp = th->cfp;
1798 rb_control_frame_t *limit_cfp = (void *)(th->stack + th->stack_size);
1803 rb_gc_mark_locations(p, p + th->mark_stack_len);
1823 RUBY_MARK_UNLESS_NULL(th->first_proc);
1824 if (th->first_proc) RUBY_MARK_UNLESS_NULL(th->first_args);
1826 RUBY_MARK_UNLESS_NULL(th->thgroup);
1827 RUBY_MARK_UNLESS_NULL(th->value);
1828 RUBY_MARK_UNLESS_NULL(th->errinfo);
1829 RUBY_MARK_UNLESS_NULL(th->pending_interrupt_queue);
1830 RUBY_MARK_UNLESS_NULL(th->pending_interrupt_mask_stack);
1831 RUBY_MARK_UNLESS_NULL(th->root_svar);
1832 RUBY_MARK_UNLESS_NULL(th->top_self);
1833 RUBY_MARK_UNLESS_NULL(th->top_wrapper);
1834 RUBY_MARK_UNLESS_NULL(th->fiber);
1835 RUBY_MARK_UNLESS_NULL(th->root_fiber);
1836 RUBY_MARK_UNLESS_NULL(th->stat_insn_usage);
1837 RUBY_MARK_UNLESS_NULL(th->last_status);
1839 RUBY_MARK_UNLESS_NULL(th->locking_mutex);
1841 rb_mark_tbl(th->local_storage);
1843 if (GET_THREAD() != th && th->machine_stack_start && th->machine_stack_end) {
1844 rb_gc_mark_machine_stack(th);
1845 rb_gc_mark_locations((VALUE *)&th->machine_regs,
1846 (VALUE *)(&th->machine_regs) +
1847 sizeof(th->machine_regs) / sizeof(VALUE));
1850 vm_trace_mark_event_hooks(&th->event_hooks);
1859 rb_thread_t *th;
1863 th = ptr;
1865 if (!th->root_fiber) {
1866 RUBY_FREE_UNLESS_NULL(th->stack);
1869 if (th->locking_mutex != Qfalse) {
1870 rb_bug("thread_free: locking_mutex must be NULL (%p:%p)", (void *)th, (void *)th->locking_mutex);
1872 if (th->keeping_mutexes != NULL) {
1873 rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes);
1876 if (th->local_storage) {
1877 st_free_table(th->local_storage);
1880 if (th->vm && th->vm->main_thread == th) {
1885 if (th->altstack) {
1886 free(th->altstack);
1891 if (ruby_current_thread == th)
1901 const rb_thread_t *th = ptr;
1904 if (!th->root_fiber) {
1905 size += th->stack_size * sizeof(VALUE);
1907 if (th->local_storage) {
1908 size += st_memsize(th->local_storage);
1943 rb_thread_t *th = thread_recycle_struct();
1944 obj = TypedData_Wrap_Struct(klass, &thread_data_type, th);
1946 rb_thread_t *th;
1947 obj = TypedData_Make_Struct(klass, rb_thread_t, &thread_data_type, th);
1953 th_init(rb_thread_t *th, VALUE self)
1955 th->self = self;
1960 th->altstack = malloc(rb_sigaltstack_size());
1962 /* th->stack_size is word number.
1963 * th->vm->default_params.thread_vm_stack_size is byte size.
1965 th->stack_size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE);
1966 th->stack = thread_recycle_stack(th->stack_size);
1968 th->cfp = (void *)(th->stack + th->stack_size);
1970 vm_push_frame(th, 0 /* dummy iseq */, VM_FRAME_MAGIC_TOP | VM_FRAME_FLAG_FINISH,
1971 Qnil /* dummy self */, Qnil /* dummy klass */, VM_ENVVAL_BLOCK_PTR(0), 0 /* dummy pc */, th->stack, 1, 0);
1973 th->status = THREAD_RUNNABLE;
1974 th->errinfo = Qnil;
1975 th->last_status = Qnil;
1976 th->waiting_fd = -1;
1977 th->root_svar = Qnil;
1980 th->retval = Qundef;
1987 rb_thread_t *th;
1989 GetThreadPtr(self, th);
1991 th->vm = vm;
1992 th_init(th, self);
1995 th->top_wrapper = 0;
1996 th->top_self = rb_vm_top_self();
1997 th->root_svar = Qnil;
2010 vm_define_method(rb_thread_t *th, VALUE obj, ID id, VALUE iseqval,
2102 rb_thread_t *th = GET_THREAD();
2103 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
2116 proc = rb_vm_make_proc(th, blockptr, rb_cProc);
2339 rb_thread_t *th = GET_THREAD();
2349 th_self = th->self = TypedData_Wrap_Struct(rb_cThread, &thread_data_type, th);
2351 vm->main_thread = th;
2352 vm->running_thread = th;
2353 th->vm = vm;
2354 th->top_wrapper = 0;
2355 th->top_self = rb_vm_top_self();
2356 rb_thread_set_current(th);
2359 st_insert(vm->living_threads, th_self, (st_data_t) th->thread_id);
2363 th->cfp->iseq = iseq;
2364 th->cfp->pc = iseq->iseq_encoded;
2365 th->cfp->self = th->top_self;
2366 th->cfp->klass = Qnil;
2383 rb_thread_t *th = GET_VM()->main_thread;
2384 rb_control_frame_t *cfp = (void *)(th->stack + th->stack_size);
2398 rb_thread_t * th = ruby_mimmalloc(sizeof(*th));
2399 if (!vm || !th) {
2403 MEMZERO(th, rb_thread_t, 1);
2404 rb_thread_set_current_raw(th);
2413 th->vm = vm;
2414 th_init(th, 0);
2415 ruby_thread_init_stack(th);
2658 * @param n n-th operand