ruby-changes:40259
From: nobu <ko1@a...>
Date: Thu, 29 Oct 2015 14:33:09 +0900 (JST)
Subject: [ruby-changes:40259] nobu:r52340 (trunk): RUBY_DTRACE_CREATE_HOOK
nobu 2015-10-29 14:32:57 +0900 (Thu, 29 Oct 2015) New Revision: 52340 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52340 Log: RUBY_DTRACE_CREATE_HOOK * internal.h (RUBY_DTRACE_CREATE_HOOK): macro to call hook at object creation. * vm.c (rb_source_location, rb_source_loc): retrieve source path and line number at once. Modified files: trunk/array.c trunk/hash.c trunk/insns.def trunk/internal.h trunk/object.c trunk/string.c trunk/symbol.c trunk/vm.c Index: symbol.c =================================================================== --- symbol.c (revision 52339) +++ symbol.c (revision 52340) @@ -465,9 +465,7 @@ register_static_symid_str(ID id, VALUE s https://github.com/ruby/ruby/blob/trunk/symbol.c#L465 OBJ_FREEZE(str); str = rb_fstring(str); - if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) { - RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(str), rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str)); register_sym(str, sym); set_id_entry(num, str, sym); @@ -534,9 +532,7 @@ dsymbol_alloc(const VALUE klass, const V https://github.com/ruby/ruby/blob/trunk/symbol.c#L532 register_sym(str, dsym); rb_hash_aset(global_symbols.dsymbol_fstr_hash, str, Qtrue); - if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) { - RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(RSYMBOL(dsym)->fstr), rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(RSYMBOL(dsym)->fstr)); return dsym; } Index: array.c =================================================================== --- array.c (revision 52339) +++ array.c (revision 52340) @@ -453,10 +453,7 @@ ary_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/array.c#L453 static VALUE empty_ary_alloc(VALUE klass) { - if (RUBY_DTRACE_ARRAY_CREATE_ENABLED()) { - RUBY_DTRACE_ARRAY_CREATE(0, rb_sourcefile(), rb_sourceline()); - } - + RUBY_DTRACE_CREATE_HOOK(ARRAY, 0); return ary_alloc(klass); } @@ -472,9 +469,7 @@ ary_new(VALUE klass, long capa) https://github.com/ruby/ruby/blob/trunk/array.c#L469 rb_raise(rb_eArgError, "array size too big"); } - if (RUBY_DTRACE_ARRAY_CREATE_ENABLED()) { - RUBY_DTRACE_ARRAY_CREATE(capa, rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(ARRAY, capa); ary = ary_alloc(klass); if (capa > RARRAY_EMBED_LEN_MAX) { Index: insns.def =================================================================== --- insns.def (revision 52339) +++ insns.def (revision 52340) @@ -526,9 +526,7 @@ newhash https://github.com/ruby/ruby/blob/trunk/insns.def#L526 { rb_num_t i; - if(RUBY_DTRACE_HASH_CREATE_ENABLED()) { - RUBY_DTRACE_HASH_CREATE(num, rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(HASH, num); val = rb_hash_new(); @@ -796,7 +794,7 @@ trace https://github.com/ruby/ruby/blob/trunk/insns.def#L794 RUBY_DTRACE_CMETHOD_ENTRY_ENABLED() || RUBY_DTRACE_CMETHOD_RETURN_ENABLED()) { - switch(flag) { + switch (flag) { case RUBY_EVENT_CALL: RUBY_DTRACE_METHOD_ENTRY_HOOK(th, 0, 0); break; Index: object.c =================================================================== --- object.c (revision 52339) +++ object.c (revision 52340) @@ -1810,14 +1810,7 @@ rb_obj_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/object.c#L1810 klass); } -#if !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED - if (RUBY_DTRACE_OBJECT_CREATE_ENABLED()) { - const char * file = rb_sourcefile(); - RUBY_DTRACE_OBJECT_CREATE(rb_class2name(klass), - file ? file : "", - rb_sourceline()); - } -#endif + RUBY_DTRACE_CREATE_HOOK(OBJECT, rb_class2name(klass)); obj = (*allocator)(klass); Index: string.c =================================================================== --- string.c (revision 52339) +++ string.c (revision 52340) @@ -624,9 +624,7 @@ str_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/string.c#L624 static inline VALUE empty_str_alloc(VALUE klass) { - if (RUBY_DTRACE_STRING_CREATE_ENABLED()) { - RUBY_DTRACE_STRING_CREATE(0, rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(STRING, 0); return str_alloc(klass); } @@ -639,9 +637,7 @@ str_new0(VALUE klass, const char *ptr, l https://github.com/ruby/ruby/blob/trunk/string.c#L637 rb_raise(rb_eArgError, "negative string size (or size too big)"); } - if (RUBY_DTRACE_STRING_CREATE_ENABLED()) { - RUBY_DTRACE_STRING_CREATE(len, rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(STRING, len); str = str_alloc(klass); if (len > RSTRING_EMBED_LEN_MAX) { @@ -746,9 +742,7 @@ str_new_static(VALUE klass, const char * https://github.com/ruby/ruby/blob/trunk/string.c#L742 str = str_new(klass, ptr, len); } else { - if (RUBY_DTRACE_STRING_CREATE_ENABLED()) { - RUBY_DTRACE_STRING_CREATE(len, rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(STRING, len); str = str_alloc(klass); RSTRING(str)->as.heap.len = len; RSTRING(str)->as.heap.ptr = (char *)ptr; @@ -1314,10 +1308,7 @@ rb_str_dup(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1308 VALUE rb_str_resurrect(VALUE str) { - if (RUBY_DTRACE_STRING_CREATE_ENABLED()) { - RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str), - rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(STRING, RSTRING_LEN(str)); return str_duplicate(rb_cString, str); } Index: hash.c =================================================================== --- hash.c (revision 52339) +++ hash.c (revision 52340) @@ -381,9 +381,7 @@ hash_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/hash.c#L381 static VALUE empty_hash_alloc(VALUE klass) { - if (RUBY_DTRACE_HASH_CREATE_ENABLED()) { - RUBY_DTRACE_HASH_CREATE(0, rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_CREATE_HOOK(HASH, 0); return hash_alloc(klass); } Index: internal.h =================================================================== --- internal.h (revision 52339) +++ internal.h (revision 52340) @@ -1183,6 +1183,8 @@ void rb_vm_inc_const_missing_count(void) https://github.com/ruby/ruby/blob/trunk/internal.h#L1183 void rb_thread_mark(void *th); const void **rb_vm_get_insns_address_table(void); VALUE rb_sourcefilename(void); +VALUE rb_source_location(int *pline); +const char *rb_source_loc(int *pline); void rb_vm_pop_cfunc_frame(void); int rb_vm_add_root_module(ID id, VALUE module); void rb_vm_check_redefinition_by_prepend(VALUE klass); @@ -1326,6 +1328,16 @@ VALUE rb_imemo_new(enum imemo_type type, https://github.com/ruby/ruby/blob/trunk/internal.h#L1328 RUBY_SYMBOL_EXPORT_END +#define RUBY_DTRACE_CREATE_HOOK(name, arg) \ +do { \ + if (UNLIKELY(RUBY_DTRACE_##name##_CREATE_ENABLED())) { \ + int dtrace_line; \ + const char *dtrace_file = rb_source_loc(&dtrace_line); \ + if (!dtrace_file) dtrace_file = ""; \ + RUBY_DTRACE_##name##_CREATE(arg, dtrace_file, dtrace_line); \ + } \ +} while (0) + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ Index: vm.c =================================================================== --- vm.c (revision 52339) +++ vm.c (revision 52340) @@ -1111,6 +1111,29 @@ rb_sourceline(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L1111 } } +VALUE +rb_source_location(int *pline) +{ + rb_thread_t *th = GET_THREAD(); + rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp); + + if (cfp) { + if (pline) *pline = rb_vm_get_sourceline(cfp); + return cfp->iseq->body->location.path; + } + else { + return 0; + } +} + +const char * +rb_source_loc(int *pline) +{ + VALUE path = rb_source_location(pline); + if (!path) return 0; + return RSTRING_PTR(path); +} + rb_cref_t * rb_vm_cref(void) { @@ -2428,10 +2451,7 @@ core_hash_from_ary(VALUE ary) https://github.com/ruby/ruby/blob/trunk/vm.c#L2451 { VALUE hash = rb_hash_new(); - if (RUBY_DTRACE_HASH_CREATE_ENABLED()) { - RUBY_DTRACE_HASH_CREATE(RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline()); - } - + RUBY_DTRACE_CREATE_HOOK(HASH, RARRAY_LEN(ary)); return core_hash_merge_ary(hash, ary); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/