66 #if VM_COLLECT_USAGE_DETAILS
67 static void vm_collect_usage_operand(
int insn,
int n,
VALUE op);
68 static void vm_collect_usage_insn(
int insn);
69 static void vm_collect_usage_register(
int reg,
int isset);
141 if (iseq->
type != ISEQ_TYPE_TOP) {
248 typedef void rb_vm_at_exit_func(
rb_vm_t*);
264 #define ENV_IN_HEAP_P(th, env) \
265 (!((th)->stack <= (env) && (env) < ((th)->stack + (th)->stack_size)))
266 #define ENV_VAL(env) ((env)[1])
346 fprintf(stderr,
"---\n");
347 fprintf(stderr,
"envptr: %p\n", (
void *)&env->
block.
ep[0]);
348 fprintf(stderr,
"envval: %10p ", (
void *)env->
block.
ep[1]);
350 fprintf(stderr,
"ep: %10p\n", (
void *)env->
block.
ep);
352 fprintf(stderr,
">>\n");
354 fprintf(stderr,
"<<\n");
376 VALUE envval, penvval = 0;
385 if (envptr != endptr) {
393 while (pcfp->
ep != penvptr) {
421 for (i = 0; i <= local_size; i++) {
422 env->
env[
i] = envptr[-local_size +
i];
424 fprintf(stderr,
"%2d ", &envptr[-local_size + i] - th->
stack);
dp(env->
env[i]);
427 envptr[-local_size +
i] = 0;
433 nenvptr = &env->
env[i - 1];
513 *blockprocptr = blockprocval;
533 (cfp->
iseq->
type == ISEQ_TYPE_RESCUE ||
534 cfp->
iseq->
type == ISEQ_TYPE_ENSURE)) {
539 VALUE epval = *escape_ep;
576 VALUE procval, envval, blockprocval = 0;
581 rb_bug(
"rb_vm_make_proc: Proc value is already created.");
602 rb_bug(
"invalid ptr: block->ep");
622 int i, opt_pc, arg_size = iseq->
arg_size;
629 for (i=0; i<
argc; i++) {
630 cfp->
sp[
i] = argv[
i];
716 argc, argv, blockptr);
724 while (cfp->
pc == 0) {
843 debug_cref(
NODE *cref)
847 printf(
"%ld\n", cref->nd_visi);
848 cref = cref->nd_next;
1044 #define OP(mid_, bop_) (mid = id##mid_, bop = BOP_##bop_, ruby_vm_redefined_flag[bop] = 0)
1045 #define C(k) add_opt_method(rb_c##k, mid, bop)
1046 OP(PLUS, PLUS), (
C(Fixnum),
C(Float),
C(String),
C(Array));
1047 OP(MINUS, MINUS), (
C(Fixnum),
C(Float));
1048 OP(MULT, MULT), (
C(Fixnum),
C(Float));
1051 OP(Eq, EQ), (
C(Fixnum),
C(Float),
C(String));
1052 OP(Eqq, EQQ), (
C(Fixnum),
C(Bignum),
C(Float),
C(Symbol),
C(String));
1053 OP(LT, LT), (
C(Fixnum),
C(Float));
1054 OP(LE, LE), (
C(Fixnum),
C(Float));
1055 OP(GT, GT), (
C(Fixnum),
C(Float));
1056 OP(GE, GE), (
C(Fixnum),
C(Float));
1057 OP(LTLT, LTLT), (
C(String),
C(Array));
1059 OP(ASET, ASET), (
C(Array),
C(Hash));
1060 OP(Length, LENGTH), (
C(Array),
C(String),
C(Hash));
1061 OP(Size, SIZE), (
C(Array),
C(String),
C(Hash));
1062 OP(EmptyP, EMPTY_P), (
C(Array),
C(String),
C(Hash));
1063 OP(Succ, SUCC), (
C(Fixnum),
C(String),
C(Time));
1202 if ((state = th->
state) != 0) {
1205 goto exception_handler;
1211 unsigned long epc, cont_pc, cont_sp;
1212 VALUE catch_iseqval;
1219 cont_pc = cont_sp = catch_iseqval = 0;
1236 if (cfp->
ep == escape_ep) {
1245 if (entry->
start < epc && entry->
end >= epc) {
1247 catch_iseqval = entry->
iseq;
1248 cont_pc = entry->
cont;
1249 cont_sp = entry->
sp;
1254 if (!catch_iseqval) {
1265 #if OPT_STACK_CACHING
1279 if (entry->
start < epc && entry->
end >= epc) {
1283 catch_iseqval = entry->
iseq;
1284 cont_pc = entry->
cont;
1285 cont_sp = entry->
sp;
1294 if (entry->
start < epc && entry->
end >= epc) {
1297 catch_iseqval = entry->
iseq;
1298 cont_pc = entry->
cont;
1299 cont_sp = entry->
sp;
1305 if (cfp->
ep == escape_ep) {
1314 else if (state ==
TAG_BREAK && ((
VALUE)escape_ep & ~0x03) == 0) {
1317 search_restart_point:
1321 if (entry->
start < epc && entry->
end >= epc) {
1323 catch_iseqval = entry->
iseq;
1324 cont_pc = entry->
cont;
1325 cont_sp = entry->
sp;
1328 else if (entry->
type == type) {
1333 #if OPT_STACK_CACHING
1348 goto search_restart_point;
1352 goto search_restart_point;
1357 if (entry->
start < epc && entry->
end >= epc) {
1360 catch_iseqval = entry->
iseq;
1361 cont_pc = entry->
cont;
1362 cont_sp = entry->
sp;
1369 if (catch_iseqval != 0) {
1417 goto exception_handler;
1458 if (!iseq && cfp->
me) {
1460 if (klassp) *klassp = cfp->
me->
klass;
1465 if (idp)
CONST_ID(*idp,
"<ifunc>");
1466 if (klassp) *klassp = 0;
1471 if (klassp) *klassp = iseq->
klass;
1500 if (cfp->
iseq != 0) {
1554 RUBY_GC_INFO(
"-------------------------------------------------\n");
1601 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
1614 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
1622 ruby_current_vm = 0;
1656 #define SET(name) rb_hash_aset(result, ID2SYM(rb_intern(#name)), SIZET2NUM(vm->default_params.name));
1657 SET(thread_vm_stack_size);
1658 SET(thread_machine_stack_size);
1659 SET(fiber_vm_stack_size);
1660 SET(fiber_machine_stack_size);
1670 size_t result = default_value;
1671 if ((envval =
getenv(name)) != 0) {
1672 long val = atol(envval);
1673 if (val < (
long)min_value) {
1674 val = (long)min_value;
1678 if (0) fprintf(stderr,
"%s: %"PRIdSIZE"\n", name, result);
1686 #ifdef PTHREAD_STACK_MIN
1687 size_t size = *sizep;
1690 #ifdef __SYMBIAN32__
1694 #ifdef PTHREAD_STACK_MIN
1695 if (size < PTHREAD_STACK_MIN) {
1696 *sizep = PTHREAD_STACK_MIN * 2;
1710 get_param(
"RUBY_THREAD_MACHINE_STACK_SIZE",
1720 get_param(
"RUBY_FIBER_MACHINE_STACK_SIZE",
1742 #define USE_THREAD_DATA_RECYCLE 1
1744 #if USE_THREAD_DATA_RECYCLE
1745 #define RECYCLE_MAX 64
1752 if (thread_recycle_stack_count) {
1762 #define thread_recycle_stack(size) ALLOC_N(VALUE, (size))
1768 #if USE_THREAD_DATA_RECYCLE
1770 thread_recycle_stack_slot[thread_recycle_stack_count++] = stack;
1777 #ifdef USE_THREAD_RECYCLE
1779 thread_recycle_struct(
void)
1805 while (cfp != limit_cfp) {
1870 rb_bug(
"thread_free: locking_mutex must be NULL (%p:%p)", (
void *)th, (
void *)th->
locking_mutex);
1873 rb_bug(
"thread_free: keeping_mutexes must be NULL (%p:%p)", (
void *)th, (
void *)th->
keeping_mutexes);
1884 #ifdef USE_SIGALTSTACK
1891 if (ruby_current_thread == th)
1892 ruby_current_thread =
NULL;
1917 #define thread_data_type ruby_threadptr_data_type
1942 #ifdef USE_THREAD_RECYCLE
1958 #ifdef USE_SIGALTSTACK
1979 #if OPT_CALL_THREADED_CODE
2013 VALUE klass = cref->nd_clss;
2014 int noex = (int)cref->nd_visi;
2035 miseq->klass = klass;
2036 miseq->defined_method_id =
id;
2045 #define REWIND_CFP(expr) do { \
2046 rb_thread_t *th__ = GET_THREAD(); \
2047 th__->cfp++; expr; th__->cfp--; \
2107 rb_bug(
"m_core_set_postexe: unreachable");
2113 blockptr->
iseq = blockiseq;
2159 for (i=1; i<
argc; i+=2) {
2193 extern VALUE *rb_gc_register_stack_start;
2212 #include <execinfo.h>
2213 #define MAX_NATIVE_TRACE 1024
2214 static void *trace[MAX_NATIVE_TRACE];
2215 int n = backtrace(trace, MAX_NATIVE_TRACE);
2216 char **syms = backtrace_symbols(trace, n);
2223 for (i=0; i<n; i++) {
2231 #if VM_COLLECT_USAGE_DETAILS
2232 static VALUE usage_analysis_insn_stop(
VALUE self);
2233 static VALUE usage_analysis_operand_stop(
VALUE self);
2234 static VALUE usage_analysis_register_stop(
VALUE self);
2276 #if VM_COLLECT_USAGE_DETAILS
2290 #if OPT_DIRECT_THREADED_CODE
2292 #elif OPT_TOKEN_THREADED_CODE
2294 #elif OPT_CALL_THREADED_CODE
2298 #if OPT_STACK_CACHING
2301 #if OPT_OPERANDS_UNIFICATION
2304 #if OPT_INSTRUCTIONS_UNIFICATION
2307 #if OPT_INLINE_METHOD_CACHE
2310 #if OPT_BLOCKINLINING
2340 volatile VALUE th_self;
2387 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
2398 fprintf(stderr,
"[FATAL] failed to allocate memory\n");
2405 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
2408 ruby_current_vm = vm;
2427 return GET_VM()->top_self;
2470 int len,
size_t pos,
VALUE *pnop,
VALUE child);
2472 #if VM_COLLECT_USAGE_DETAILS
2474 #define HASH_ASET(h, k, v) st_insert(RHASH_TBL(h), (st_data_t)(k), (st_data_t)(v))
2488 vm_analysis_insn(
int insn)
2492 static int prev_insn = -1;
2498 CONST_ID(usage_hash,
"USAGE_ANALYSIS_INSN");
2499 CONST_ID(bigram_hash,
"USAGE_ANALYSIS_INSN_BIGRAM");
2503 HASH_ASET(uh,
INT2FIX(insn), ihash);
2511 if (prev_insn != -1) {
2530 vm_analysis_operand(
int insn,
int n,
VALUE op)
2540 CONST_ID(usage_hash,
"USAGE_ANALYSIS_INSN");
2545 HASH_ASET(uh,
INT2FIX(insn), ihash);
2549 HASH_ASET(ihash,
INT2FIX(n), ophash);
2562 vm_analysis_register(
int reg,
int isset)
2567 static const char regstrs[][5] = {
2575 static const char getsetstr[][4] = {
2579 static VALUE syms[
sizeof(regstrs) /
sizeof(regstrs[0])][2];
2583 CONST_ID(usage_hash,
"USAGE_ANALYSIS_REGS");
2588 for (i = 0; i < (int)(
sizeof(regstrs) /
sizeof(regstrs[0])); i++) {
2590 for (j = 0; j < 2; j++) {
2591 snprintf(buff, 0x10,
"%d %s %-4s", i, getsetstr[j], regstrs[i]);
2596 valstr = syms[reg][isset];
2613 usage_analysis_insn_stop(
VALUE self)
2621 usage_analysis_operand_stop(
VALUE self)
2629 usage_analysis_register_stop(
VALUE self)
2643 #if VM_COLLECT_USAGE_DETAILS
2646 vm_collect_usage_insn(
int insn)
2648 if (RUBY_DTRACE_INSN_ENABLED()) {
2652 (*ruby_vm_collect_usage_func_insn)(insn);
2660 vm_collect_usage_operand(
int insn,
int n,
VALUE op)
2662 if (RUBY_DTRACE_INSN_OPERAND_ENABLED()) {
2671 (*ruby_vm_collect_usage_func_operand)(insn, n, op);
2677 vm_collect_usage_register(
int reg,
int isset)
2680 (*ruby_vm_collect_usage_func_register)(reg, isset);