Created
December 1, 2012 12:57
-
-
Save authorNari/4182140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/array.c b/array.c | |
index 2454b99..57673b7 100644 | |
--- a/array.c | |
+++ b/array.c | |
@@ -379,11 +379,12 @@ ary_alloc(VALUE klass) | |
static VALUE | |
empty_ary_alloc(VALUE klass) | |
{ | |
+ VALUE ary = ary_alloc(klass); | |
if(RUBY_DTRACE_ARRAY_CREATE_ENABLED()) { | |
- RUBY_DTRACE_ARRAY_CREATE(0, rb_sourcefile(), rb_sourceline()); | |
+ RUBY_DTRACE_ARRAY_CREATE(NUM2LONG(rb_obj_id(ary)), 0, rb_sourcefile(), rb_sourceline()); | |
} | |
- return ary_alloc(klass); | |
+ return ary; | |
} | |
static VALUE | |
@@ -398,10 +399,6 @@ ary_new(VALUE klass, long capa) | |
rb_raise(rb_eArgError, "array size too big"); | |
} | |
- if(RUBY_DTRACE_ARRAY_CREATE_ENABLED()) { | |
- RUBY_DTRACE_ARRAY_CREATE(capa, rb_sourcefile(), rb_sourceline()); | |
- } | |
- | |
ary = ary_alloc(klass); | |
if (capa > RARRAY_EMBED_LEN_MAX) { | |
FL_UNSET_EMBED(ary); | |
@@ -409,6 +406,9 @@ ary_new(VALUE klass, long capa) | |
ARY_SET_CAPA(ary, capa); | |
ARY_SET_HEAP_LEN(ary, 0); | |
} | |
+ if(RUBY_DTRACE_ARRAY_CREATE_ENABLED()) { | |
+ RUBY_DTRACE_ARRAY_CREATE(NUM2LONG(rb_obj_id(ary)), capa, rb_sourcefile(), rb_sourceline()); | |
+ } | |
return ary; | |
} | |
diff --git a/hash.c b/hash.c | |
index a9047be..40b099d 100644 | |
--- a/hash.c | |
+++ b/hash.c | |
@@ -219,11 +219,12 @@ hash_alloc(VALUE klass) | |
static VALUE | |
empty_hash_alloc(VALUE klass) | |
{ | |
+ VALUE hash = hash_alloc(klass); | |
if(RUBY_DTRACE_HASH_CREATE_ENABLED()) { | |
- RUBY_DTRACE_HASH_CREATE(0, rb_sourcefile(), rb_sourceline()); | |
+ RUBY_DTRACE_HASH_CREATE(NUM2LONG(rb_obj_id(hash)), 0, rb_sourcefile(), rb_sourceline()); | |
} | |
- return hash_alloc(klass); | |
+ return hash; | |
} | |
VALUE | |
diff --git a/insns.def b/insns.def | |
index c491896..6d3b045 100644 | |
--- a/insns.def | |
+++ b/insns.def | |
@@ -525,12 +525,12 @@ newhash | |
{ | |
rb_num_t i; | |
+ val = rb_hash_new(); | |
+ | |
if(RUBY_DTRACE_HASH_CREATE_ENABLED()) { | |
- RUBY_DTRACE_HASH_CREATE(num, rb_sourcefile(), rb_sourceline()); | |
+ RUBY_DTRACE_HASH_CREATE(NUM2LONG(rb_obj_id(val)), num, rb_sourcefile(), rb_sourceline()); | |
} | |
- val = rb_hash_new(); | |
- | |
for (i = num; i > 0; i -= 2) { | |
const VALUE v = TOPN(i - 2); | |
const VALUE k = TOPN(i - 1); | |
diff --git a/object.c b/object.c | |
index 712d76a..b089864 100644 | |
--- a/object.c | |
+++ b/object.c | |
@@ -1686,17 +1686,18 @@ rb_obj_alloc(VALUE klass) | |
klass); | |
} | |
+ obj = (*allocator)(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), | |
+ RUBY_DTRACE_OBJECT_CREATE(NUM2LONG(rb_obj_id(obj)), | |
+ rb_class2name(klass), | |
file ? file : "", | |
rb_sourceline()); | |
} | |
#endif | |
- obj = (*allocator)(klass); | |
- | |
if (rb_obj_class(obj) != rb_class_real(klass)) { | |
rb_raise(rb_eTypeError, "wrong instance allocation"); | |
} | |
diff --git a/probes.d b/probes.d | |
index 591b2f4..9e7f601 100644 | |
--- a/probes.d | |
+++ b/probes.d | |
@@ -18,10 +18,10 @@ provider ruby { | |
probe raise(const char *, const char *, int); | |
- probe object__create(const char *, const char *, int); | |
- probe array__create(long, const char *, int); | |
- probe hash__create(long, const char *, int); | |
- probe string__create(long, const char *, int); | |
+ probe object__create(long, const char *, const char *, int); | |
+ probe array__create(long, long, const char *, int); | |
+ probe hash__create(long, long, const char *, int); | |
+ probe string__create(long, long, const char *, int); | |
probe parse__begin(const char *, int); | |
probe parse__end(const char *, int); | |
diff --git a/string.c b/string.c | |
index f2ee280..1ac612e 100644 | |
--- a/string.c | |
+++ b/string.c | |
@@ -385,10 +385,11 @@ str_alloc(VALUE klass) | |
static inline VALUE | |
empty_str_alloc(VALUE klass) | |
{ | |
+ VALUE str = str_alloc(klass); | |
if(RUBY_DTRACE_STRING_CREATE_ENABLED()) { | |
- RUBY_DTRACE_STRING_CREATE(0, rb_sourcefile(), rb_sourceline()); | |
+ RUBY_DTRACE_STRING_CREATE(NUM2LONG(rb_obj_id(str)), 0, rb_sourcefile(), rb_sourceline()); | |
} | |
- return str_alloc(klass); | |
+ return str; | |
} | |
static VALUE | |
@@ -400,10 +401,6 @@ str_new(VALUE klass, const char *ptr, long len) | |
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()); | |
- } | |
- | |
str = str_alloc(klass); | |
if (len > RSTRING_EMBED_LEN_MAX) { | |
RSTRING(str)->as.heap.aux.capa = len; | |
@@ -418,6 +415,11 @@ str_new(VALUE klass, const char *ptr, long len) | |
} | |
STR_SET_LEN(str, len); | |
RSTRING_PTR(str)[len] = '\0'; | |
+ | |
+ if(RUBY_DTRACE_STRING_CREATE_ENABLED()) { | |
+ RUBY_DTRACE_STRING_CREATE(NUM2LONG(rb_obj_id(str)), len, rb_sourcefile(), rb_sourceline()); | |
+ } | |
+ | |
return str; | |
} | |
@@ -932,11 +934,13 @@ rb_str_dup(VALUE str) | |
VALUE | |
rb_str_resurrect(VALUE str) | |
{ | |
+ VALUE new_str = str_alloc(rb_cString); | |
+ | |
if(RUBY_DTRACE_STRING_CREATE_ENABLED()) { | |
RUBY_DTRACE_STRING_CREATE( | |
- RSTRING_LEN(str), rb_sourcefile(), rb_sourceline()); | |
+ NUM2LONG(rb_obj_id(new_str)), RSTRING_LEN(str), rb_sourcefile(), rb_sourceline()); | |
} | |
- return str_replace(str_alloc(rb_cString), str); | |
+ return str_replace(new_str, str); | |
} | |
/* | |
diff --git a/test/dtrace/test_array_create.rb b/test/dtrace/test_array_create.rb | |
index affcd47..993fc45 100644 | |
--- a/test/dtrace/test_array_create.rb | |
+++ b/test/dtrace/test_array_create.rb | |
@@ -4,17 +4,18 @@ module DTrace | |
class TestArrayCreate < TestCase | |
def test_lit | |
trap_probe(probe, '[]') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |num, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line| | |
file == rbfile && num == '0' | |
} | |
assert_equal([rbfile], saw.map { |line| line[1] }) | |
assert_equal(['1'], saw.map { |line| line[2] }) | |
+ saw.each {|line| assert_not_equal(0, line[3].to_i) } | |
} | |
end | |
def test_many_lit | |
trap_probe(probe, '[1,2,3,4]') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |num, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line| | |
file == rbfile && num == '4' && line == '1' | |
} | |
assert_operator saw.length, :>, 0 | |
@@ -27,7 +28,7 @@ module DTrace | |
ruby$target:::#{type}-create | |
/arg1/ | |
{ | |
- printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2); | |
+ printf("%d %d %s %d\\n", arg0, arg1, copyinstr(arg2), arg3); | |
} | |
eoprobe | |
end | |
diff --git a/test/dtrace/test_hash_create.rb b/test/dtrace/test_hash_create.rb | |
index 91dd6ce..75480d3 100644 | |
--- a/test/dtrace/test_hash_create.rb | |
+++ b/test/dtrace/test_hash_create.rb | |
@@ -4,7 +4,7 @@ module DTrace | |
class TestHashCreate < TestCase | |
def test_hash_new | |
trap_probe(probe, 'Hash.new') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |num, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line| | |
file == rbfile && num == '0' | |
} | |
assert_operator saw.length, :>, 0 | |
@@ -13,7 +13,7 @@ module DTrace | |
def test_hash_lit | |
trap_probe(probe, '{}') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |num, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line| | |
file == rbfile && num == '0' | |
} | |
assert_operator saw.length, :>, 0 | |
@@ -22,7 +22,7 @@ module DTrace | |
def test_hash_lit_elements | |
trap_probe(probe, '{ :foo => :bar }') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |num, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line| | |
file == rbfile && num == '2' | |
} | |
assert_operator saw.length, :>, 0 | |
@@ -31,7 +31,7 @@ module DTrace | |
def test_hash_lit_elements_string | |
trap_probe(probe, '{ :foo => :bar, :bar => "baz" }') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |num, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line| | |
file == rbfile && num == '4' | |
} | |
assert_operator saw.length, :>, 0 | |
@@ -44,7 +44,7 @@ module DTrace | |
ruby$target:::hash-create | |
/arg1/ | |
{ | |
- printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2); | |
+ printf("%d %d %s %d\\n", arg0, arg1, copyinstr(arg2), arg3); | |
} | |
eoprobe | |
end | |
diff --git a/test/dtrace/test_object_create_start.rb b/test/dtrace/test_object_create_start.rb | |
index ae4fb74..6dd84b7 100644 | |
--- a/test/dtrace/test_object_create_start.rb | |
+++ b/test/dtrace/test_object_create_start.rb | |
@@ -4,7 +4,7 @@ module DTrace | |
class TestObjectCreateStart < TestCase | |
def test_object_create_start | |
trap_probe(probe, '10.times { Object.new }') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |_, file, _| | |
+ saw = saw.map(&:split).find_all { |_, _, file, _| | |
file == rbfile | |
} | |
assert_equal 10, saw.length | |
@@ -13,12 +13,13 @@ module DTrace | |
def test_object_create_start_name | |
trap_probe(probe, 'Hash.new') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |klass, file, line| | |
+ saw = saw.map(&:split).find_all { |obj_id, klass, file, line| | |
file == rbfile | |
} | |
- assert_equal(%w{ Hash }, saw.map(&:first)) | |
- assert_equal([rbfile], saw.map { |line| line[1] }) | |
- assert_equal(['1'], saw.map { |line| line[2] }) | |
+ saw.each {|line| assert_not_equal(0, line[0].to_i) } | |
+ assert_equal(%w{ Hash }, saw.map{|s| s[1]}) | |
+ assert_equal([rbfile], saw.map { |line| line[2] }) | |
+ assert_equal(['1'], saw.map { |line| line[3] }) | |
} | |
end | |
@@ -27,7 +28,7 @@ module DTrace | |
<<-eoprobe | |
ruby$target:::object-create | |
{ | |
- printf("%s %s %d\\n", copyinstr(arg0), copyinstr(arg1), arg2); | |
+ printf("%s %s %d %d\\n", arg0, copyinstr(arg1), copyinstr(arg2), arg3); | |
} | |
eoprobe | |
end | |
diff --git a/test/dtrace/test_string.rb b/test/dtrace/test_string.rb | |
index 05e8033..e392a15 100644 | |
--- a/test/dtrace/test_string.rb | |
+++ b/test/dtrace/test_string.rb | |
@@ -4,12 +4,13 @@ module DTrace | |
class TestStringProbes < TestCase | |
def test_object_create_start_string_lit | |
trap_probe(probe, '"omglolwutbbq"') { |_,rbfile,saw| | |
- saw = saw.map(&:split).find_all { |klass, file, line, len| | |
+ saw = saw.map(&:split).find_all { |obj_id, klass, file, line, len| | |
file == rbfile && len == '12' && line == '1' | |
} | |
- assert_equal(%w{ String }, saw.map(&:first)) | |
- assert_equal([rbfile], saw.map { |line| line[1] }) | |
- assert_equal(['1'], saw.map { |line| line[2] }) | |
+ saw.each {|line| assert_not_equal(0, line[0].to_i) } | |
+ assert_equal(%w{ String }, saw.map{|line| line[1] }) | |
+ assert_equal([rbfile], saw.map { |line| line[2] }) | |
+ assert_equal(['1'], saw.map { |line| line[3] }) | |
} | |
end | |
@@ -19,7 +20,7 @@ module DTrace | |
ruby$target:::string-create | |
/arg1/ | |
{ | |
- printf("String %s %d %d\\n", copyinstr(arg1), arg2, arg0); | |
+ printf("String %d %s %d %d\\n", arg0, copyinstr(arg2), arg3, arg1); | |
} | |
eoprobe | |
end | |
diff --git a/vm.c b/vm.c | |
index f14d391..10f9ab9 100644 | |
--- a/vm.c | |
+++ b/vm.c | |
@@ -1986,15 +1986,15 @@ m_core_hash_from_ary(VALUE self, VALUE ary) | |
VALUE hash = rb_hash_new(); | |
int i; | |
- if(RUBY_DTRACE_HASH_CREATE_ENABLED()) { | |
- RUBY_DTRACE_HASH_CREATE(RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline()); | |
- } | |
- | |
assert(RARRAY_LEN(ary) % 2 == 0); | |
for (i=0; i<RARRAY_LEN(ary); i+=2) { | |
rb_hash_aset(hash, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]); | |
} | |
+ if(RUBY_DTRACE_HASH_CREATE_ENABLED()) { | |
+ RUBY_DTRACE_HASH_CREATE(NUM2LONG(rb_obj_id(hash)), RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline()); | |
+ } | |
+ | |
return hash; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment