summaryrefslogtreecommitdiff
path: root/iseq.c
AgeCommit message (Collapse)Author
2018-12-23iseq.c: avoid Null pointer dereferencek0kubun
detected by coverity scan git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20iseq.c: resurrect literal hash operandsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Return same ISeq object for one src.ko1
* iseq.c: before this patch, RubyVM::InstructionSequence.of(src) (ISeq in short) returns different ISeq (wrapper) objects point to one ISeq internal object. This patch changes this behavior to cache created ISeq (wrapper) objects and return same ISeq object for an internal ISeq object. * iseq.h (ISEQ_EXECUTABLE_P): introduced to check executable ISeq objects. * iseq.h (ISEQ_COMPILE_DATA_ALLOC): reordr setting flag line to avoid ISEQ_USE_COMPILE_DATA but compiled_data == NULL case. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::wrapper` and `rb_iseq_t::aux::exec`. Move `rb_iseq_t::local_hooks` to `rb_iseq_t::aux::exec::local_hooks`. * test/ruby/test_iseq.rb: add ISeq.of() tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Prefer rb_check_arity when 0 or 1 argumentsnobu
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27Add rb_typeddata_is_instance_ofnobu
Similar to rb_typeddata_is_kind_of, except for that inherited type is not an instance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27fix for ISeq.of(method).ko1
* iseq.c (iseqw_s_of): `rb_method_iseq(method)` can return NULL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27`RubyVM::ISeq.of` accept ISeq.ko1
* iseq.c (iseqw_s_of): return given object if the given object is a `RubyVM::InstructionSequence`. We can specify ISeq for `TracePoint#enable(target:)`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26`TracePoint#enable(target_line:)` is supported. [Feature #15289]ko1
* vm_trace.c: `TracePoint#enable(target_line:)` is supported. This option enables a hook only at specified target_line. target_line should be combination with target and :line event. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26fix for ansi-pedantic compile option.ko1
* iseq.c (iseq_add_local_tracepoint_i): extract aggregate initialization. See https://travis-ci.org/ruby/ruby/jobs/459881277 * iseq.c (iseq_remove_local_tracepoint_i): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26fix type error.ko1
* iseq.c (iseq_iterate_children): should use cast to `int`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Support targetting TracePoint [Feature #15289]ko1
* vm_trace.c (rb_tracepoint_enable_for_target): support targetting TracePoint. [Feature #15289] Tragetting TracePoint is only enabled on specified method, proc and so on, example: `tp.enable(target: code)`. `code` should be consisted of InstructionSeuqnece (iseq) (RubyVM::InstructionSeuqnece.of(code) should not return nil) If code is a tree of iseq, TracePoint is enabled on all of iseqs in a tree. Enabled tragetting TracePoints can not enabled again with and without target. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::local_hooks` to store local hooks. `rb_iseq_t::aux::trace_events` is renamed to `global_trace_events` to contrast with `local_hooks`. * vm_core.h (rb_hook_list_t): add `rb_hook_list_t::running` to represent how many Threads/Fibers are used this list. If this field is 0, nobody using this hooks and we can delete it. This is why we can remove code from cont.c. * vm_core.h (rb_vm_t): because of above change, we can eliminate `rb_vm_t::trace_running` field. Also renamed from `rb_vm_t::event_hooks` to `global_hooks`. * vm_core.h, vm.c (ruby_vm_event_enabled_global_flags): renamed from `ruby_vm_event_enabled_flags. * vm_core.h, vm.c (ruby_vm_event_local_num): added to count enabled targetting TracePoints. * vm_core.h, vm_trace.c (rb_exec_event_hooks): accepts hook list. * vm_core.h (rb_vm_global_hooks): added for convinience. * method.h (rb_method_bmethod_t): added to maintain Proc and `rb_hook_list_t` for bmethod (defined by define_method). * prelude.rb (TracePoint#enable): extracet a keyword parameter (because it is easy than writing in C). It calls `TracePoint#__enable` internal method written in C. * vm_insnhelper.c (vm_trace): check also iseq->local_hooks. * vm.c (invoke_bmethod): check def->body.bmethod.hooks. * vm.c (hook_before_rewind): check iseq->local_hooks and def->body.bmethod.hooks before rewind by exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-05* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-05Implement `RubyVM::AST.of` [Feature #14836]yui-knk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20Remove tracecoverage instructionsmame
The instructions were used only for branch coverage. Instead, it now uses a trace framework [Feature #14104]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20iseq.c (rb_iseq_trace_flag_cleared): Accept size_t for type consistencymame
It caused "implicit conversion loses integer precision" on clang. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20ext/coverage/: add the oneshot modemame
This patch introduces "oneshot_lines" mode for `Coverage.start`, which checks "whether each line was executed at least once or not", instead of "how many times each line was executed". A hook for each line is fired at most once, and after it is fired, the hook flag was removed; it runs with zero overhead. See [Feature #15022] in detail. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13Prefer `rb_fstring_lit` over `rb_fstring_cstr`nobu
The former states explicitly that the argument must be a literal, and can optimize away `strlen` on all compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-04check argument type.ko1
* iseq.c (iseqw_s_compile): check argument type (T_STRING) to avoid SEGV. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13iseq.c: prefix rb_ to non-static iseq functionsk0kubun
I assume we always prefix rb_ to non-static functions to avoid conflict. These functions are not exported and safe to be renamed. iseq.h: ditto compile.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23iseq.c (rb_vm_encoded_insn_data_table_init): add a cast to build on clangmame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23iseq.c (rb_iseq_trace_set): refactoring by using encoded_insn_datamame
Now it uses encoded_insn_data to identify and replace each encoded insn. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23iseq.c: add a map from encoded insn to insn datamame
This enhances rb_vm_insn_addr2insn which retrieves a decoded insn number from encoded insn. The insn data table include not only decoded insn number, but also its len, trace and non-trace version of encoded insn. This table can be used to simplify trace instrumentation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23check trace flags at loading [Bug #14702]ko1
* iseq.c (iseq_init_trace): at ISeq loading time, we need to check `ruby_vm_event_enabled_flags` to turn on trace instructions. Seprate this checking code from `finish_iseq_build()` and make new function. `iseq_ibf_load()` calls this funcation after loading. * test/ruby/test_iseq.rb: add a test for this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22parse.y: remove coverage-related code fragmentsmame
The code fragments that initializes coverage data were scattered into both parse.y and compile.c. parse.y allocated a coverage data, and compile.c initialize the data. To remove this cross-cutting concern, this change moves the allocation from "coverage" function of parse.y to "rb_iseq_new_top" of iseq.c. For the sake, parse.y just counts the line number of the original source code, and the number is passed via rb_ast_body_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22prototizednobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22thread.c (rb_reset_coverages): remove coverage counters from all ISeqsmame
When coverage measurement is enabled, the compiler makes each iseq have a reference to the counter array of coverage. Even after coverage measurement is disabled, the reference is kept. And, if coverage measurement is restarted, a coverage hook will increase the counter. This is completely meaningless; it brings just overhead. To remove this meaninglessness, this change removes all the reference when coverage measuement is stopped. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10insns.def (invokesuper): remove a dummy receiever flag hack for ZSUPERmame
This is just a refactoring. The receiver of "invokesuper" was a boolean to represent if it is ZSUPER or not. This was used in vm_search_super_method to prohibit ZSUPER call in define_method. (It is currently prohibited because of the limitation of the implementation.) This change removes the hack by introducing an explicit flag, VM_CALL_SUPER, to signal the information. Now, the implementation of "invokesuper" is consistent with "send" instruction. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23mjit.c: disable calling JIT-ed codek0kubun
when TracePoint is enabled. We're cancelling JIT-ed code execution AFTER each instruction, but there is no guard before the first insn of method. To prevent spoiling performance, I don't want to modify the JIT-ed code to fix this. So this commit replaces `mjit_enabled` check with `mjit_call_p` check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-13Make VM_INSN_INFO_TABLE_IMPL=1 workmame
rb_iseq_insns_info_decode_positions is used only when VM_INSN_INFO_TABLE_IMPL=2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-06rb_vm_insn_addr2insn: use st to perform addr2insn mappingnormal
The current VM_INSTRUCTION_SIZE is 198, so the linear search painful during a major GC phase. I noticed rb_vm_insn_addr2insn2 showing up at the top of some profiles while working on some malloc-related stuff, so I decided to attack it. Most notably, the benchmark/bm_vm3_gc.rb improves by over 40%: https://80x24.org/spew/20180602220554.GA9991@whir/raw [ruby-core:87361] [Feature #14814] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-19iseq.c: Fix segfault when debug is not 0yui-knk
* iseq.c (get_insn_info_succinct_bitvector): If VM_CHECK_MODE is 0, `body->insns_info.positions` is freed in `rb_iseq_insns_info_encode_positions`. Print `position` only when VM_CHECK_MODE is set. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-16iseq body local variablesnobu
* compile.c, iseq.c: extract body and param.keyword in iseq as local variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-12iseq.c: iseq body local variablesnobu
* iseq.c: extract body and param.keyword in iseq as local variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-12iseq.c: refactoring rb_iseq_freenobu
* iseq.c (rb_iseq_free): call mjit_free_iseq only if iseq->body is not NULL too, as the function accesses the body. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09RSTRING_PTR is not guaranteed to be VALUE-aligned (retry)shyouhei
Don't abuse struct RString to hold arbitrary memory region. Raw pointer should just suffice. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-02tool/ruby_vm/views/_insn_name_info.erb: Auto-detect the longest insn namemame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-02iseq.c (rb_iseq_disasm_insn): Change the width of insn namesmame
Currently "trace_opt_send_without_block" (28 letters) is the longest insn. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-27iseq.c: consistent rb_bug messagesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-21insns.def: checktypenobu
* insns.def (checktype): split branchiftype to checktype and branchif, to make branch condition negation possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-13Add write barrier calls for direct marking objects.tenderlove
This commit adds write barriers for objects marked from `rb_iseq_mark`. r62851 introduced direct marking from iseqs to: * keyword arg default values * catch table iseqs * VALUEs embedded in encoded instructions This patch adds missing write barrier calls to those references. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-05compile.c: do not dump pointersnobu
* compile.c (ibf_dump_iseq_each): do not dump succ_index_table pointer. positions are dumped as integer arrays. pointer values are meaningless outside the process. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-04iseq.c: indent iseq dumpnobu
* iseq.c (rb_iseq_disasm): indent catch_table iseq entries. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-04iseq.c: strip trailing spaces in dumpnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-21iseq.c: constfied validate_get_insn_info [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-20compile.c: fix ibf_load_codenobu
* compile.c (ibf_load_iseq_each): manage iseq_size to point loaded objects in iseq_encoded. now marking iseq scans iseq_encoded directly. * test/ruby/test_iseq.rb (test_to_binary_with_objects): skip for now, but fix argument order of assert_equal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19Reverting r62775, this should fix i686 buildstenderlove
We need to mark default values for kwarg methods. This also fixes Bootsnap. IBF iseq loading needed to mark iseqs as "having markable objects". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e