2017-02-21 08:18:15 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
debug_counter.h -
|
|
|
|
|
|
|
|
created at: Tue Feb 21 16:51:18 2017
|
|
|
|
|
|
|
|
Copyright (C) 2017 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef USE_DEBUG_COUNTER
|
|
|
|
#define USE_DEBUG_COUNTER 0
|
|
|
|
#endif
|
|
|
|
|
2017-03-10 07:18:03 +00:00
|
|
|
#ifdef RB_DEBUG_COUNTER
|
2017-05-31 06:46:57 +00:00
|
|
|
|
2020-01-08 16:14:01 +09:00
|
|
|
// method cache (IMC: inline method cache)
|
|
|
|
RB_DEBUG_COUNTER(mc_inline_hit) // IMC hit
|
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_klass) // IMC miss by different class
|
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_invalidated) // IMC miss by invalidated ME
|
2020-12-14 17:56:34 +09:00
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_empty) // IMC miss because prev is empty slot
|
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_same_cc) // IMC miss, but same CC
|
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_same_cme) // IMC miss, but same CME
|
2020-12-14 18:37:22 +09:00
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_same_def) // IMC miss, but same definition
|
2020-12-14 17:56:34 +09:00
|
|
|
RB_DEBUG_COUNTER(mc_inline_miss_diff) // IMC miss, different methods
|
|
|
|
|
2021-06-01 13:34:06 -04:00
|
|
|
RB_DEBUG_COUNTER(cvar_write_inline_hit) // cvar cache hit on write
|
|
|
|
RB_DEBUG_COUNTER(cvar_read_inline_hit) // cvar cache hit on read
|
|
|
|
RB_DEBUG_COUNTER(cvar_inline_miss) // miss inline cache
|
|
|
|
RB_DEBUG_COUNTER(cvar_class_invalidate) // invalidate cvar cache when define a cvar that's defined on a subclass
|
|
|
|
RB_DEBUG_COUNTER(cvar_include_invalidate) // invalidate cvar cache on module include or prepend
|
|
|
|
|
2020-01-08 16:14:01 +09:00
|
|
|
RB_DEBUG_COUNTER(mc_cme_complement) // number of acquiring complement CME
|
2020-03-16 23:21:08 +09:00
|
|
|
RB_DEBUG_COUNTER(mc_cme_complement_hit) // number of cache hit for complemented CME
|
2020-01-08 16:14:01 +09:00
|
|
|
|
|
|
|
RB_DEBUG_COUNTER(mc_search) // count for method lookup in class tree
|
|
|
|
RB_DEBUG_COUNTER(mc_search_notfound) // method lookup, but not found
|
|
|
|
RB_DEBUG_COUNTER(mc_search_super) // total traversed classes
|
2017-05-24 06:46:44 +00:00
|
|
|
|
VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).
iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).
To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).
struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.
rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-01-08 08:20:36 +09:00
|
|
|
// callinfo
|
2020-01-08 16:14:01 +09:00
|
|
|
RB_DEBUG_COUNTER(ci_packed) // number of packed CI
|
|
|
|
RB_DEBUG_COUNTER(ci_kw) // non-packed CI w/ keywords
|
|
|
|
RB_DEBUG_COUNTER(ci_nokw) // non-packed CI w/o keywords
|
|
|
|
RB_DEBUG_COUNTER(ci_runtime) // creating temporary CI
|
|
|
|
|
|
|
|
// callcache
|
|
|
|
RB_DEBUG_COUNTER(cc_new) // number of CC
|
|
|
|
RB_DEBUG_COUNTER(cc_temp) // dummy CC (stack-allocated)
|
2020-12-15 12:10:35 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_found_in_ccs) // count for CC lookup success in CCS
|
|
|
|
RB_DEBUG_COUNTER(cc_not_found_in_ccs) // count for CC lookup success in CCS
|
2020-01-08 16:14:01 +09:00
|
|
|
|
|
|
|
RB_DEBUG_COUNTER(cc_ent_invalidate) // count for invalidating cc (cc->klass = 0)
|
2020-03-16 23:21:08 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_cme_invalidate) // count for invalidating CME
|
2020-01-08 16:14:01 +09:00
|
|
|
|
2021-04-26 00:10:39 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_leaf) // count for invalidating klass if klass has no-subclasses
|
2020-01-08 16:14:01 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_leaf_ccs) // corresponding CCS
|
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_leaf_callable) // complimented cache (no-subclasses)
|
2021-04-26 00:10:39 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_tree) // count for invalidating klass if klass has subclasses
|
2020-01-08 16:14:01 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_tree_cme) // cme if cme is found in this class or superclasses
|
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_tree_callable) // complimented cache (subclasses)
|
2020-12-14 10:49:07 +09:00
|
|
|
RB_DEBUG_COUNTER(cc_invalidate_negative) // count for invalidating negative cache
|
2020-01-08 16:14:01 +09:00
|
|
|
|
|
|
|
RB_DEBUG_COUNTER(ccs_free) // count for free'ing ccs
|
|
|
|
RB_DEBUG_COUNTER(ccs_maxlen) // maximum length of ccs
|
2020-12-14 18:17:35 +09:00
|
|
|
RB_DEBUG_COUNTER(ccs_found) // count for finding corresponding ccs on method lookup
|
|
|
|
RB_DEBUG_COUNTER(ccs_not_found) // count for not found corresponding ccs on method lookup
|
2020-01-08 16:14:01 +09:00
|
|
|
|
2020-12-15 12:10:35 +09:00
|
|
|
// vm_eval.c
|
|
|
|
RB_DEBUG_COUNTER(call0_public)
|
|
|
|
RB_DEBUG_COUNTER(call0_other)
|
2021-01-21 03:33:59 +09:00
|
|
|
RB_DEBUG_COUNTER(gccct_hit)
|
|
|
|
RB_DEBUG_COUNTER(gccct_miss)
|
|
|
|
RB_DEBUG_COUNTER(gccct_null)
|
2020-12-15 12:10:35 +09:00
|
|
|
|
2020-01-08 16:14:01 +09:00
|
|
|
// iseq
|
|
|
|
RB_DEBUG_COUNTER(iseq_num) // number of total created iseq
|
|
|
|
RB_DEBUG_COUNTER(iseq_cd_num) // number of total created cd (call_data)
|
VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).
iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).
To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).
struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.
rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-01-08 08:20:36 +09:00
|
|
|
|
2019-03-22 07:57:26 +00:00
|
|
|
/*
|
|
|
|
* call cache fastpath usage
|
|
|
|
*/
|
|
|
|
RB_DEBUG_COUNTER(ccf_general)
|
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_setup)
|
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_setup_0start)
|
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_setup_tailcall_0start)
|
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_fix) /* several functions created with tool/mk_call_iseq_optimized.rb */
|
2019-03-29 12:31:08 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_opt) /* has_opt == TRUE (has optional parameters), but other flags are FALSE */
|
2019-03-29 13:06:48 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_kw1) /* vm_call_iseq_setup_kwparm_kwarg() */
|
2019-03-29 12:31:08 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_kw2) /* vm_call_iseq_setup_kwparm_nokwarg() */
|
2019-03-22 07:57:26 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_cfunc)
|
2020-04-13 20:32:59 -07:00
|
|
|
RB_DEBUG_COUNTER(ccf_cfunc_with_frame)
|
2019-03-29 12:31:08 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_ivar) /* attr_reader */
|
|
|
|
RB_DEBUG_COUNTER(ccf_attrset) /* attr_writer */
|
2019-03-22 07:57:26 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_method_missing)
|
|
|
|
RB_DEBUG_COUNTER(ccf_zsuper)
|
|
|
|
RB_DEBUG_COUNTER(ccf_bmethod)
|
|
|
|
RB_DEBUG_COUNTER(ccf_opt_send)
|
|
|
|
RB_DEBUG_COUNTER(ccf_opt_call)
|
|
|
|
RB_DEBUG_COUNTER(ccf_opt_block_call)
|
2021-11-18 11:01:31 +09:00
|
|
|
RB_DEBUG_COUNTER(ccf_opt_struct_aref)
|
|
|
|
RB_DEBUG_COUNTER(ccf_opt_struct_aset)
|
2019-03-22 07:57:26 +00:00
|
|
|
RB_DEBUG_COUNTER(ccf_super_method)
|
2023-08-25 18:27:56 -04:00
|
|
|
RB_DEBUG_COUNTER(ccf_cfunc_other)
|
|
|
|
RB_DEBUG_COUNTER(ccf_cfunc_only_splat)
|
|
|
|
RB_DEBUG_COUNTER(ccf_cfunc_only_splat_kw)
|
|
|
|
RB_DEBUG_COUNTER(ccf_iseq_bmethod)
|
|
|
|
RB_DEBUG_COUNTER(ccf_noniseq_bmethod)
|
|
|
|
RB_DEBUG_COUNTER(ccf_opt_send_complex)
|
|
|
|
RB_DEBUG_COUNTER(ccf_opt_send_simple)
|
2019-03-22 07:57:26 +00:00
|
|
|
|
2018-09-28 01:10:43 +00:00
|
|
|
/*
|
|
|
|
* control frame push counts.
|
|
|
|
*
|
|
|
|
* * frame_push: frame push counts.
|
2018-09-28 03:35:15 +00:00
|
|
|
* * frame_push_*: frame push counts per each type.
|
|
|
|
* * frame_R2R: Ruby frame to Ruby frame
|
|
|
|
* * frame_R2C: Ruby frame to C frame
|
|
|
|
* * frame_C2C: C frame to C frame
|
|
|
|
* * frame_C2R: C frame to Ruby frame
|
2018-09-28 01:10:43 +00:00
|
|
|
*/
|
|
|
|
RB_DEBUG_COUNTER(frame_push)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_method)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_block)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_class)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_top)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_cfunc)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_ifunc)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_eval)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_rescue)
|
|
|
|
RB_DEBUG_COUNTER(frame_push_dummy)
|
|
|
|
|
2018-09-28 03:35:15 +00:00
|
|
|
RB_DEBUG_COUNTER(frame_R2R)
|
|
|
|
RB_DEBUG_COUNTER(frame_R2C)
|
|
|
|
RB_DEBUG_COUNTER(frame_C2C)
|
|
|
|
RB_DEBUG_COUNTER(frame_C2R)
|
|
|
|
|
2023-02-14 14:41:23 -08:00
|
|
|
/* instance variable counts */
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_obj_hit) // Only T_OBJECT hits
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_obj_miss) // Only T_OBJECT misses
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_ic_hit) // All hits
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_ic_miss) // All misses
|
|
|
|
RB_DEBUG_COUNTER(ivar_set_ic_hit) // All hits
|
|
|
|
RB_DEBUG_COUNTER(ivar_set_obj_hit) // Only T_OBJECT hits
|
|
|
|
RB_DEBUG_COUNTER(ivar_set_obj_miss) // Only T_OBJECT misses
|
|
|
|
RB_DEBUG_COUNTER(ivar_set_ic_miss) // All misses
|
|
|
|
RB_DEBUG_COUNTER(ivar_set_ic_miss_noobject) // Miss because non T_OBJECT
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_base) // Calls to `rb_ivar_get` (very slow path)
|
|
|
|
RB_DEBUG_COUNTER(ivar_set_base) // Calls to `ivar_set` (very slow path)
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_ic_miss_set) // Misses on IV reads where the cache was wrong
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_cc_miss_set) // Misses on attr_reader where the cache was wrong
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_ic_miss_unset) // Misses on IV read where the cache wasn't set
|
|
|
|
RB_DEBUG_COUNTER(ivar_get_cc_miss_unset) // Misses on attr_reader where the cache wasn't set
|
2017-05-24 06:46:44 +00:00
|
|
|
|
2018-09-25 18:13:29 +00:00
|
|
|
/* local variable counts
|
|
|
|
*
|
|
|
|
* * lvar_get: total lvar get counts (VM insn)
|
|
|
|
* * lvar_get_dynamic: lvar get counts if accessing upper env (VM insn)
|
|
|
|
* * lvar_set*: same as "get"
|
|
|
|
* * lvar_set_slowpath: counts using vm_env_write_slowpath()
|
|
|
|
*/
|
2017-05-31 06:46:57 +00:00
|
|
|
RB_DEBUG_COUNTER(lvar_get)
|
|
|
|
RB_DEBUG_COUNTER(lvar_get_dynamic)
|
|
|
|
RB_DEBUG_COUNTER(lvar_set)
|
|
|
|
RB_DEBUG_COUNTER(lvar_set_dynamic)
|
|
|
|
RB_DEBUG_COUNTER(lvar_set_slowpath)
|
|
|
|
|
2018-10-24 22:17:03 +00:00
|
|
|
/* GC counts:
|
|
|
|
*
|
|
|
|
* * count: simple count
|
|
|
|
* * _minor: minor gc
|
|
|
|
* * _major: major gc
|
|
|
|
* * other suffix is corresponding to last_gc_info or
|
|
|
|
* gc_profile_record_flag in gc.c.
|
|
|
|
*/
|
|
|
|
RB_DEBUG_COUNTER(gc_count)
|
|
|
|
RB_DEBUG_COUNTER(gc_minor_newobj)
|
|
|
|
RB_DEBUG_COUNTER(gc_minor_malloc)
|
|
|
|
RB_DEBUG_COUNTER(gc_minor_method)
|
|
|
|
RB_DEBUG_COUNTER(gc_minor_capi)
|
|
|
|
RB_DEBUG_COUNTER(gc_minor_stress)
|
|
|
|
RB_DEBUG_COUNTER(gc_major_nofree)
|
|
|
|
RB_DEBUG_COUNTER(gc_major_oldgen)
|
|
|
|
RB_DEBUG_COUNTER(gc_major_shady)
|
|
|
|
RB_DEBUG_COUNTER(gc_major_force)
|
2018-10-25 02:23:58 +00:00
|
|
|
RB_DEBUG_COUNTER(gc_major_oldmalloc)
|
2018-10-24 22:17:03 +00:00
|
|
|
|
2020-12-17 17:03:05 +09:00
|
|
|
RB_DEBUG_COUNTER(gc_enter_start)
|
2023-02-14 15:50:45 -05:00
|
|
|
RB_DEBUG_COUNTER(gc_enter_continue)
|
2020-12-17 17:03:05 +09:00
|
|
|
RB_DEBUG_COUNTER(gc_enter_rest)
|
|
|
|
RB_DEBUG_COUNTER(gc_enter_finalizer)
|
|
|
|
|
2019-05-07 14:06:25 +09:00
|
|
|
RB_DEBUG_COUNTER(gc_isptr_trial)
|
|
|
|
RB_DEBUG_COUNTER(gc_isptr_range)
|
|
|
|
RB_DEBUG_COUNTER(gc_isptr_align)
|
|
|
|
RB_DEBUG_COUNTER(gc_isptr_maybe)
|
|
|
|
|
2018-09-25 18:13:29 +00:00
|
|
|
/* object allocation counts:
|
|
|
|
*
|
|
|
|
* * obj_newobj: newobj counts
|
|
|
|
* * obj_newobj_slowpath: newobj with slowpath counts
|
2020-03-16 23:21:08 +09:00
|
|
|
* * obj_newobj_wb_unprotected: newobj for wb_unprotected.
|
2018-09-25 18:13:29 +00:00
|
|
|
* * obj_free: obj_free() counts
|
2018-09-26 07:28:04 +00:00
|
|
|
* * obj_promote: promoted counts (oldgen)
|
|
|
|
* * obj_wb_unprotect: wb unprotect counts
|
2018-09-25 18:13:29 +00:00
|
|
|
*
|
2018-09-28 01:10:43 +00:00
|
|
|
* * obj_[type]_[attr]: *free'ed counts* for each type.
|
|
|
|
* Note that it is not a allocated counts.
|
2018-09-25 18:13:29 +00:00
|
|
|
* * [type]
|
|
|
|
* * _obj: T_OBJECT
|
|
|
|
* * _str: T_STRING
|
|
|
|
* * _ary: T_ARRAY
|
2018-09-28 01:10:43 +00:00
|
|
|
* * _xxx: T_XXX (hash, struct, ...)
|
2018-09-25 18:13:29 +00:00
|
|
|
*
|
|
|
|
* * [attr]
|
|
|
|
* * _ptr: R?? is not embed.
|
|
|
|
* * _embed: R?? is embed.
|
|
|
|
* * type specific attr.
|
|
|
|
* * str_shared: str is shared.
|
|
|
|
* * str_nofree: nofree
|
|
|
|
* * str_fstr: fstr
|
|
|
|
* * hash_empty: hash is empty
|
2019-07-19 16:24:14 +09:00
|
|
|
* * hash_1_4: has 1 to 4 entries
|
|
|
|
* * hash_5_8: has 5 to 8 entries
|
|
|
|
* * hash_g8: has n entries (n>8)
|
2019-04-20 00:44:51 +01:00
|
|
|
* * match_under4: has under 4 oniguruma regions allocated
|
|
|
|
* * match_ge4: has n regions allocated (4<=n<8)
|
|
|
|
* * match_ge8: has n regions allocated (8<=n)
|
2018-09-28 01:10:43 +00:00
|
|
|
* * data_empty: T_DATA but no memory free.
|
|
|
|
* * data_xfree: free'ed by xfree().
|
|
|
|
* * data_imm_free: free'ed immediately.
|
|
|
|
* * data_zombie: free'ed with zombie.
|
|
|
|
* * imemo_*: T_IMEMO with each type.
|
2018-09-25 18:13:29 +00:00
|
|
|
*/
|
|
|
|
RB_DEBUG_COUNTER(obj_newobj)
|
|
|
|
RB_DEBUG_COUNTER(obj_newobj_slowpath)
|
|
|
|
RB_DEBUG_COUNTER(obj_newobj_wb_unprotected)
|
2017-05-24 06:46:44 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_free)
|
2018-09-26 07:28:04 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_promote)
|
|
|
|
RB_DEBUG_COUNTER(obj_wb_unprotect)
|
2017-05-24 06:46:44 +00:00
|
|
|
|
2018-10-30 21:01:55 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_obj_embed)
|
2018-10-30 22:01:17 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_obj_ptr)
|
2022-12-08 17:16:52 -05:00
|
|
|
RB_DEBUG_COUNTER(obj_obj_too_complex)
|
2018-09-25 18:13:29 +00:00
|
|
|
|
2017-05-24 06:46:44 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_str_ptr)
|
|
|
|
RB_DEBUG_COUNTER(obj_str_embed)
|
|
|
|
RB_DEBUG_COUNTER(obj_str_shared)
|
|
|
|
RB_DEBUG_COUNTER(obj_str_nofree)
|
|
|
|
RB_DEBUG_COUNTER(obj_str_fstr)
|
|
|
|
|
2018-10-30 21:01:55 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_ary_embed)
|
2018-10-30 22:01:17 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_ary_ptr)
|
2019-09-25 16:55:54 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_ary_extracapa)
|
2019-07-19 13:02:38 +09:00
|
|
|
/*
|
|
|
|
ary_shared_create: shared ary by Array#dup and so on.
|
|
|
|
ary_shared: finished in shard.
|
|
|
|
ary_shared_root_occupied: shared_root but has only 1 refcnt.
|
|
|
|
The number (ary_shared - ary_shared_root_occupied) is meaningful.
|
|
|
|
*/
|
|
|
|
RB_DEBUG_COUNTER(obj_ary_shared_create)
|
|
|
|
RB_DEBUG_COUNTER(obj_ary_shared)
|
|
|
|
RB_DEBUG_COUNTER(obj_ary_shared_root_occupied)
|
2017-05-24 06:46:44 +00:00
|
|
|
|
2018-09-25 18:13:29 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_hash_empty)
|
2019-08-02 14:59:29 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_hash_1)
|
|
|
|
RB_DEBUG_COUNTER(obj_hash_2)
|
|
|
|
RB_DEBUG_COUNTER(obj_hash_3)
|
|
|
|
RB_DEBUG_COUNTER(obj_hash_4)
|
2019-07-19 16:24:14 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_hash_5_8)
|
|
|
|
RB_DEBUG_COUNTER(obj_hash_g8)
|
2019-08-02 14:59:29 +09:00
|
|
|
|
|
|
|
RB_DEBUG_COUNTER(obj_hash_null)
|
2018-12-14 01:10:15 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_hash_ar)
|
2018-10-30 22:11:51 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_hash_st)
|
|
|
|
RB_DEBUG_COUNTER(obj_hash_force_convert)
|
2018-09-25 18:13:29 +00:00
|
|
|
|
2018-09-26 07:28:04 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_struct_embed)
|
2018-10-30 22:03:42 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_struct_ptr)
|
2018-09-26 07:28:04 +00:00
|
|
|
|
2018-09-28 01:10:43 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_data_empty)
|
|
|
|
RB_DEBUG_COUNTER(obj_data_xfree)
|
|
|
|
RB_DEBUG_COUNTER(obj_data_imm_free)
|
|
|
|
RB_DEBUG_COUNTER(obj_data_zombie)
|
|
|
|
|
2019-04-20 00:44:51 +01:00
|
|
|
RB_DEBUG_COUNTER(obj_match_under4)
|
|
|
|
RB_DEBUG_COUNTER(obj_match_ge4)
|
|
|
|
RB_DEBUG_COUNTER(obj_match_ge8)
|
2018-09-28 01:10:43 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_match_ptr)
|
2019-12-23 16:30:45 +09:00
|
|
|
|
|
|
|
RB_DEBUG_COUNTER(obj_iclass_ptr)
|
|
|
|
RB_DEBUG_COUNTER(obj_class_ptr)
|
|
|
|
RB_DEBUG_COUNTER(obj_module_ptr)
|
|
|
|
|
2018-09-28 01:10:43 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_bignum_ptr)
|
2019-12-23 16:30:45 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_bignum_embed)
|
|
|
|
RB_DEBUG_COUNTER(obj_float)
|
|
|
|
RB_DEBUG_COUNTER(obj_complex)
|
|
|
|
RB_DEBUG_COUNTER(obj_rational)
|
2018-09-28 01:10:43 +00:00
|
|
|
|
2019-12-23 16:30:45 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_regexp_ptr)
|
|
|
|
RB_DEBUG_COUNTER(obj_file_ptr)
|
2018-09-28 01:10:43 +00:00
|
|
|
RB_DEBUG_COUNTER(obj_symbol)
|
|
|
|
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_ment)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_iseq)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_env)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_tmpbuf)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_ast)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_cref)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_svar)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_throw_data)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_ifunc)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_memo)
|
|
|
|
RB_DEBUG_COUNTER(obj_imemo_parser_strterm)
|
VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).
iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).
To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).
struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.
rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-01-08 08:20:36 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_imemo_callinfo)
|
2020-01-08 16:14:01 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_imemo_callcache)
|
2021-01-04 18:08:25 +09:00
|
|
|
RB_DEBUG_COUNTER(obj_imemo_constcache)
|
2025-05-22 14:01:46 +02:00
|
|
|
RB_DEBUG_COUNTER(obj_imemo_class_fields)
|
2018-09-28 01:10:43 +00:00
|
|
|
|
Inline Class#new.
This commit inlines instructions for Class#new. To make this work, we
added a new YARV instructions, `opt_new`. `opt_new` checks whether or
not the `new` method is the default allocator method. If it is, it
allocates the object, and pushes the instance on the stack. If not, the
instruction jumps to the "slow path" method call instructions.
Old instructions:
```
> ruby --dump=insns -e'Object.new'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)>
0000 opt_getconstant_path <ic:0 Object> ( 1)[Li]
0002 opt_send_without_block <calldata!mid:new, argc:0, ARGS_SIMPLE>
0004 leave
```
New instructions:
```
> ./miniruby --dump=insns -e'Object.new'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)>
0000 opt_getconstant_path <ic:0 Object> ( 1)[Li]
0002 putnil
0003 swap
0004 opt_new <calldata!mid:new, argc:0, ARGS_SIMPLE>, 11
0007 opt_send_without_block <calldata!mid:initialize, argc:0, FCALL|ARGS_SIMPLE>
0009 jump 14
0011 opt_send_without_block <calldata!mid:new, argc:0, ARGS_SIMPLE>
0013 swap
0014 pop
0015 leave
```
This commit speeds up basic object allocation (`Foo.new`) by 60%, but
classes that take keyword parameters see an even bigger benefit because
no hash is allocated when instantiating the object (3x to 6x faster).
Here is an example that uses `Hash.new(capacity: 0)`:
```
> hyperfine "ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'" "./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'"
Benchmark 1: ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
Time (mean ± σ): 1.082 s ± 0.004 s [User: 1.074 s, System: 0.008 s]
Range (min … max): 1.076 s … 1.088 s 10 runs
Benchmark 2: ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
Time (mean ± σ): 627.9 ms ± 3.5 ms [User: 622.7 ms, System: 4.8 ms]
Range (min … max): 622.7 ms … 633.2 ms 10 runs
Summary
./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' ran
1.72 ± 0.01 times faster than ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
```
This commit changes the backtrace for `initialize`:
```
aaron@tc ~/g/ruby (inline-new)> cat test.rb
class Foo
def initialize
puts caller
end
end
def hello
Foo.new
end
hello
aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
test.rb:8:in 'Class#new'
test.rb:8:in 'Object#hello'
test.rb:11:in '<main>'
aaron@tc ~/g/ruby (inline-new)> ./miniruby -v test.rb
ruby 3.5.0dev (2025-03-28T23:59:40Z inline-new c4157884e4) +PRISM [arm64-darwin24]
test.rb:8:in 'Object#hello'
test.rb:11:in '<main>'
```
It also increases memory usage for calls to `new` by 122 bytes:
```
aaron@tc ~/g/ruby (inline-new)> cat test.rb
require "objspace"
class Foo
def initialize
puts caller
end
end
def hello
Foo.new
end
puts ObjectSpace.memsize_of(RubyVM::InstructionSequence.of(method(:hello)))
aaron@tc ~/g/ruby (inline-new)> make runruby
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems ./test.rb
656
aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
544
```
Thanks to @ko1 for coming up with this idea!
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2025-03-17 16:59:19 -07:00
|
|
|
RB_DEBUG_COUNTER(opt_new_hit)
|
|
|
|
RB_DEBUG_COUNTER(opt_new_miss)
|
|
|
|
|
2019-01-17 16:53:10 +00:00
|
|
|
/* ar_table */
|
|
|
|
RB_DEBUG_COUNTER(artable_hint_hit)
|
|
|
|
RB_DEBUG_COUNTER(artable_hint_miss)
|
|
|
|
RB_DEBUG_COUNTER(artable_hint_notfound)
|
|
|
|
|
2018-09-25 18:13:29 +00:00
|
|
|
/* heap function counts
|
|
|
|
*
|
|
|
|
* * heap_xmalloc/realloc/xfree: call counts
|
|
|
|
*/
|
|
|
|
RB_DEBUG_COUNTER(heap_xmalloc)
|
|
|
|
RB_DEBUG_COUNTER(heap_xrealloc)
|
|
|
|
RB_DEBUG_COUNTER(heap_xfree)
|
|
|
|
|
2020-12-16 10:10:05 +09:00
|
|
|
// VM sync
|
|
|
|
RB_DEBUG_COUNTER(vm_sync_lock)
|
|
|
|
RB_DEBUG_COUNTER(vm_sync_lock_enter)
|
|
|
|
RB_DEBUG_COUNTER(vm_sync_lock_enter_nb)
|
|
|
|
RB_DEBUG_COUNTER(vm_sync_lock_enter_cr)
|
|
|
|
RB_DEBUG_COUNTER(vm_sync_barrier)
|
|
|
|
|
2018-09-25 18:13:29 +00:00
|
|
|
/* load (not implemented yet) */
|
|
|
|
/*
|
2017-06-01 00:05:33 +00:00
|
|
|
RB_DEBUG_COUNTER(load_files)
|
|
|
|
RB_DEBUG_COUNTER(load_path_is_not_realpath)
|
2018-09-25 18:13:29 +00:00
|
|
|
*/
|
2017-03-10 07:18:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RUBY_DEBUG_COUNTER_H
|
|
|
|
#define RUBY_DEBUG_COUNTER_H 1
|
|
|
|
|
2020-05-08 18:31:09 +09:00
|
|
|
#include "ruby/internal/config.h"
|
2019-12-25 14:19:48 +09:00
|
|
|
#include <stddef.h> /* for size_t */
|
|
|
|
#include "ruby/ruby.h" /* for VALUE */
|
|
|
|
|
2017-02-21 08:18:15 +00:00
|
|
|
#if !defined(__GNUC__) && USE_DEBUG_COUNTER
|
|
|
|
#error "USE_DEBUG_COUNTER is not supported by other than __GNUC__"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum rb_debug_counter_type {
|
2017-03-10 07:18:03 +00:00
|
|
|
#define RB_DEBUG_COUNTER(name) RB_DEBUG_COUNTER_##name,
|
2024-06-02 21:22:39 +09:00
|
|
|
#include "debug_counter.h"
|
2017-02-21 08:18:15 +00:00
|
|
|
RB_DEBUG_COUNTER_MAX
|
2017-03-10 07:18:03 +00:00
|
|
|
#undef RB_DEBUG_COUNTER
|
2017-02-21 08:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if USE_DEBUG_COUNTER
|
2017-03-10 07:18:03 +00:00
|
|
|
extern size_t rb_debug_counter[];
|
2020-12-17 01:29:15 +09:00
|
|
|
RUBY_EXTERN struct rb_ractor_struct *ruby_single_main_ractor;
|
|
|
|
RUBY_EXTERN void rb_debug_counter_add_atomic(enum rb_debug_counter_type type, int add);
|
2017-02-21 08:18:15 +00:00
|
|
|
|
|
|
|
inline static int
|
|
|
|
rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond)
|
|
|
|
{
|
|
|
|
if (cond) {
|
2020-12-17 01:29:15 +09:00
|
|
|
if (ruby_single_main_ractor != NULL) {
|
|
|
|
rb_debug_counter[(int)type] += add;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_debug_counter_add_atomic(type, add);
|
|
|
|
}
|
2017-02-21 08:18:15 +00:00
|
|
|
}
|
|
|
|
return cond;
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:14:01 +09:00
|
|
|
inline static int
|
|
|
|
rb_debug_counter_max(enum rb_debug_counter_type type, unsigned int num)
|
|
|
|
{
|
2020-12-17 01:29:15 +09:00
|
|
|
// TODO: sync
|
2020-01-08 16:14:01 +09:00
|
|
|
if (rb_debug_counter[(int)type] < num) {
|
|
|
|
rb_debug_counter[(int)type] = num;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix rb_define_singleton_method warning
for debug counters
```
../include/ruby/intern.h:1175:137: warning: passing argument 3 of 'rb_define_singleton_method0' from incompatible pointer type [-Wincompatible-pointer-types]
#define rb_define_singleton_method(klass, mid, func, arity) rb_define_singleton_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
^
../vm.c:2958:5: note: in expansion of macro 'rb_define_singleton_method'
rb_define_singleton_method(rb_cRubyVM, "show_debug_counters", rb_debug_counter_show, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/ruby/intern.h:1139:99: note: expected 'VALUE (*)(VALUE) {aka long unsigned int (*)(long unsigned int)}' but argument is of type 'VALUE (*)(void) {aka long unsigned int (*)(void)}'
__attribute__((__unused__,__weakref__("rb_define_singleton_method"),__nonnull__(2,3)))static void rb_define_singleton_method0 (VALUE,const char*,VALUE(*)(VALUE),int);
```
2019-09-20 17:44:16 +09:00
|
|
|
VALUE rb_debug_counter_reset(VALUE klass);
|
|
|
|
VALUE rb_debug_counter_show(VALUE klass);
|
2019-04-14 06:57:21 +00:00
|
|
|
|
2017-02-21 08:18:15 +00:00
|
|
|
#define RB_DEBUG_COUNTER_INC(type) rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, 1)
|
|
|
|
#define RB_DEBUG_COUNTER_INC_UNLESS(type, cond) (!rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, !(cond)))
|
2020-07-10 13:02:31 +09:00
|
|
|
#define RB_DEBUG_COUNTER_INC_IF(type, cond) rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, !!(cond))
|
2020-01-08 16:14:01 +09:00
|
|
|
#define RB_DEBUG_COUNTER_ADD(type, num) rb_debug_counter_add(RB_DEBUG_COUNTER_##type, (num), 1)
|
|
|
|
#define RB_DEBUG_COUNTER_SETMAX(type, num) rb_debug_counter_max(RB_DEBUG_COUNTER_##type, (unsigned int)(num))
|
2017-02-21 08:18:15 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#define RB_DEBUG_COUNTER_INC(type) ((void)0)
|
2020-07-10 13:02:31 +09:00
|
|
|
#define RB_DEBUG_COUNTER_INC_UNLESS(type, cond) (!!(cond))
|
|
|
|
#define RB_DEBUG_COUNTER_INC_IF(type, cond) (!!(cond))
|
2020-01-08 16:14:01 +09:00
|
|
|
#define RB_DEBUG_COUNTER_ADD(type, num) ((void)0)
|
|
|
|
#define RB_DEBUG_COUNTER_SETMAX(type, num) 0
|
2017-02-21 08:18:15 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-25 18:13:29 +00:00
|
|
|
void rb_debug_counter_show_results(const char *msg);
|
|
|
|
|
2019-12-25 01:32:37 +09:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
|
|
|
|
|
|
size_t ruby_debug_counter_get(const char **names_ptr, size_t *counters_ptr);
|
|
|
|
void ruby_debug_counter_reset(void);
|
|
|
|
void ruby_debug_counter_show_at_exit(int enable);
|
|
|
|
|
|
|
|
RUBY_SYMBOL_EXPORT_END
|
|
|
|
|
2017-02-21 08:18:15 +00:00
|
|
|
#endif /* RUBY_DEBUG_COUNTER_H */
|