summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2019-08-06 18:38:55 -0400
committerKoichi Sasada <ko1@atdot.net>2019-08-08 14:22:56 +0900
commit1ad0f4e593563d460e3015fc4a2542ce1bb80d6e (patch)
tree8fce972e6bdc5989a5d5f664d96af68d385fd149
parent1c7d3a13caa718ef52ec6b55988b1459a002f965 (diff)
Add *_clear methods to VM_COLLECT_USAGE_DETAILS API
Add RubyVM::USAGE_ANALYSIS_INSN_CLEAR, RubyVM::USAGE_ANALYSIS_OPERAND_CLEAR, and RubyVM::USAGE_ANALYSIS_REGISTER_CLEAR to clear VM instruction hash constants. Closes: https://github.com/ruby/ruby/pull/2258
-rw-r--r--vm.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 7ba6099..8d5d856 100644
--- a/vm.c
+++ b/vm.c
@@ -2899,6 +2899,9 @@ static VALUE usage_analysis_register_stop(VALUE self);
static VALUE usage_analysis_insn_running(VALUE self);
static VALUE usage_analysis_operand_running(VALUE self);
static VALUE usage_analysis_register_running(VALUE self);
+static VALUE usage_analysis_insn_clear(VALUE self);
+static VALUE usage_analysis_operand_clear(VALUE self);
+static VALUE usage_analysis_register_clear(VALUE self);
#endif
void
@@ -3128,6 +3131,9 @@ Init_VM(void)
rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_INSN_RUNNING", usage_analysis_insn_running, 0);
rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_OPERAND_RUNNING", usage_analysis_operand_running, 0);
rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_REGISTER_RUNNING", usage_analysis_register_running, 0);
+ rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_INSN_CLEAR", usage_analysis_insn_clear, 0);
+ rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_OPERAND_CLEAR", usage_analysis_operand_clear, 0);
+ rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_REGISTER_CLEAR", usage_analysis_register_clear, 0);
#endif
/* ::RubyVM::OPTS, which shows vm build options */
@@ -3543,6 +3549,53 @@ usage_analysis_register_running(VALUE self)
return Qtrue;
}
+/* :nodoc: */
+static VALUE
+usage_analysis_insn_clear(VALUE self)
+{
+ ID usage_hash;
+ ID bigram_hash;
+ VALUE uh;
+ VALUE bh;
+
+ CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
+ CONST_ID(bigram_hash, "USAGE_ANALYSIS_INSN_BIGRAM");
+ uh = rb_const_get(rb_cRubyVM, usage_hash);
+ bh = rb_const_get(rb_cRubyVM, bigram_hash);
+ rb_hash_clear(uh);
+ rb_hash_clear(bh);
+
+ return Qtrue;
+}
+
+/* :nodoc: */
+static VALUE
+usage_analysis_operand_clear(VALUE self)
+{
+ ID usage_hash;
+ VALUE uh;
+
+ CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
+ uh = rb_const_get(rb_cRubyVM, usage_hash);
+ rb_hash_clear(uh);
+
+ return Qtrue;
+}
+
+/* :nodoc: */
+static VALUE
+usage_analysis_register_clear(VALUE self)
+{
+ ID usage_hash;
+ VALUE uh;
+
+ CONST_ID(usage_hash, "USAGE_ANALYSIS_REGS");
+ uh = rb_const_get(rb_cRubyVM, usage_hash);
+ rb_hash_clear(uh);
+
+ return Qtrue;
+}
+
#else
MAYBE_UNUSED(static void (*ruby_vm_collect_usage_func_insn)(int insn)) = NULL;