Граф коммитов

184 Коммитов

Автор SHA1 Сообщение Дата
Takashi Kokubun 9aa5fe1bf8
Split compile and link for MinGW support
MinGW test_jit fails with no error message. Perhaps linker flags should
not be passed when compilation is happening.

Anyway splitting these stages doesn't matter for performance. So let me
just split it to fix the issue. Probably this helps Solaris's issue too.
2020-05-03 16:41:25 -07:00
Takashi Kokubun 0776198486
Debug Solaris's MJIT failure
using -Winvalid-pch

https://rubyci.org/logs/rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20200501T170004Z.fail.html.gz
2020-05-03 15:49:51 -07:00
Takashi Kokubun 4aca078bda
Support cc_added_args again
This support was accidentally removed in 818d6d3336.
2020-05-03 00:45:19 -07:00
Takashi Kokubun cc6afff006
Avoid infinite times of JIT compaction
It's to avoid memory leak for actual usage (because they don't get
unloaded properly), but also for fixing CI timed out due to JIT
compaction taking too long time on --jit-wait (which runs every time)
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2911601
2020-05-02 21:43:28 -07:00
Takashi Kokubun e4d3d5ceab
Stop generating MJIT_PCH include guard
to fix
https://ci.appveyor.com/project/ruby/ruby/builds/32577700/job/yh61rom35wt2uv39

It was for JIT compaction, and we don't support it on mswin.
2020-05-01 02:54:50 -07:00
Takashi Kokubun 72aa4dd183
c_file_access_mode should be defined for Windows
as well. And also unit->c_file doesn't exist in mswin.

https://github.com/ruby/ruby/runs/635915704
2020-05-01 01:58:19 -07:00
Takashi Kokubun 818d6d3336
Deduplicate functions in compacted JIT code
to improve code locality.

Using benchmark-driver/sinatra with 100 methods JIT-ed,

[Before] 12149.97 rps
1.3M    /tmp/_ruby_mjit_p31171u145.so

[After] 12818.83 rps
260K    /tmp/_ruby_mjit_p32155u145.so

(VM is 13714.89 rps)
2020-05-01 01:38:16 -07:00
Takashi Kokubun f5ddbba9a2
Include unit id in a function name of an inlined method
I'm trying to make it possible to include all JIT-ed code in a single C
file. This is needed to guarantee uniqueness of all function names
2020-04-30 23:08:13 -07:00
Takashi Kokubun e8a78d7df8
Do not stop the world during JIT compaction
Running C compiler for JIT compaction inside a critical section may lock
main thread for a long time when it triggers GC. As I'm planning to
increase this duration a bit, I'd like to make sure this doesn't stop
the world.

For now, I chose to give up unloading units when it's during JIT
compaction, assuming other calls may unload them later.
2020-04-30 21:38:50 -07:00
卜部昌平 4b853932ea mjit_worker: __GNUC__ is too lax
Namely icc defines __GNUC__, but doesn't have -Wdeprecated-declarations
2020-04-10 16:17:30 +09:00
Nobuyoshi Nakada 3325194ac0
Get rid of bogus warning by VC
```
c:\projects\ruby\mjit_worker.c(1219) : warning C4090: 'function' : different 'const' qualifiers
```

It seems confused by passing "pointer to pointer to const object",
not "pointer to const object".
2020-03-17 19:47:45 +09:00
Takashi Kokubun 6e405b2611
Use a human-readable funcname with --jit-debug
for perf output like:

Samples: 100K of event 'cycles:ppp', Event count (approx.): 1007750000
  Children      Self  Command  Shared Object             Symbol
+   81.58%     1.47%  ruby     ruby                      [.] rb_vm_exec
+   81.06%     7.61%  ruby     ruby                      [.] vm_exec_core
+   80.16%     0.00%  ruby     ruby                      [.] vm_sendish (inlined)
+   75.03%     0.00%  ruby     ruby                      [.] mjit_exec (inlined)
+   74.37%     0.00%  ruby     ruby                      [.] mjit_exec (inlined)
+   73.42%     0.22%  ruby     _ruby_mjit_p11277u42.so   [.] _mjit42_rack_method_override_rb_call
+   73.25%     0.10%  ruby     _ruby_mjit_p11277u41.so   [.] _mjit41_sinatra_show_exceptions_rb_call
+   73.19%     0.22%  ruby     _ruby_mjit_p11277u44.so   [.] _mjit44_rack_head_rb_call
+   73.03%     0.15%  ruby     _ruby_mjit_p11277u45.so   [.] _mjit45_sinatra_base_rb_call
+   72.87%     0.26%  ruby     _ruby_mjit_p11277u49.so   [.] _mjit49_rack_logger_rb_call
+   70.56%     0.11%  ruby     _ruby_mjit_p11277u40.so   [.] _mjit40_sinatra_base_rb_call
+   68.70%     0.11%  ruby     _ruby_mjit_p11277u39.so   [.] _mjit39_sinatra_base_rb_call
+   68.39%     0.29%  ruby     _ruby_mjit_p11277u56.so   [.] _mjit56_rack_protection_frame_options_rb_call
+   67.89%     0.18%  ruby     _ruby_mjit_p11277u37.so   [.] _mjit37_sinatra_base_rb_block_in_call
+   67.04%     0.16%  ruby     _ruby_mjit_p11277u34.so   [.] _mjit34_sinatra_base_rb_synchronize

Reverting deb1c7b97d, fixing `sprint_funcname`'s argument in `compact_all_jit_code`.
Also updating common.mk.
2020-03-14 21:02:09 -07:00
Takashi Kokubun deb1c7b97d
Revert "Use a human-readable funcname with --jit-debug"
This reverts commit cecebf55c4.

debugging test failure...
2020-03-14 20:51:12 -07:00
Takashi Kokubun cecebf55c4
Use a human-readable funcname with --jit-debug
for perf output like:

Samples: 100K of event 'cycles:ppp', Event count (approx.): 1007750000
  Children      Self  Command  Shared Object             Symbol
+   81.58%     1.47%  ruby     ruby                      [.] rb_vm_exec
+   81.06%     7.61%  ruby     ruby                      [.] vm_exec_core
+   80.16%     0.00%  ruby     ruby                      [.] vm_sendish (inlined)
+   75.03%     0.00%  ruby     ruby                      [.] mjit_exec (inlined)
+   74.37%     0.00%  ruby     ruby                      [.] mjit_exec (inlined)
+   73.42%     0.22%  ruby     _ruby_mjit_p11277u42.so   [.] _mjit42_rack_method_override_rb_call
+   73.25%     0.10%  ruby     _ruby_mjit_p11277u41.so   [.] _mjit41_sinatra_show_exceptions_rb_call
+   73.19%     0.22%  ruby     _ruby_mjit_p11277u44.so   [.] _mjit44_rack_head_rb_call
+   73.03%     0.15%  ruby     _ruby_mjit_p11277u45.so   [.] _mjit45_sinatra_base_rb_call
+   72.87%     0.26%  ruby     _ruby_mjit_p11277u49.so   [.] _mjit49_rack_logger_rb_call
+   70.56%     0.11%  ruby     _ruby_mjit_p11277u40.so   [.] _mjit40_sinatra_base_rb_call
+   68.70%     0.11%  ruby     _ruby_mjit_p11277u39.so   [.] _mjit39_sinatra_base_rb_call
+   68.39%     0.29%  ruby     _ruby_mjit_p11277u56.so   [.] _mjit56_rack_protection_frame_options_rb_call
+   67.89%     0.18%  ruby     _ruby_mjit_p11277u37.so   [.] _mjit37_sinatra_base_rb_block_in_call
+   67.04%     0.16%  ruby     _ruby_mjit_p11277u34.so   [.] _mjit34_sinatra_base_rb_synchronize
2020-03-14 20:42:47 -07:00
Takashi Kokubun 0cd7be99e9
Avoid referring to an old value of realloc
OpenBSD RubyCI has failed with SEGV since 4bcd5981e8.
https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20200312T223005Z.fail.html.gz

This was because `status->cc_entries` could be stale after `realloc` call
for inlined iseqs.
2020-03-12 22:51:34 -07:00
Takashi Kokubun 4bcd5981e8
Capture inlined iseq's cc entries in root iseq's
jit_unit to avoid marking wrong cc entries when inlined iseq is compiled
multiple times, resolving the TODO added by daf7c48d88.

This obviates pseudo jit_unit in inlined iseq introduced by 7ec2359374
and fixes memory leak of the adhoc unit.
2020-03-10 00:53:35 -07:00
Nobuyoshi Nakada 364526cd70
[win32] suppress false warning by MSVC 2020-03-04 21:02:24 +09:00
Takashi Kokubun 83705c42ce
Add missing free on cc_entries
Looks like an oversight in b9007b6c54 and
7ec2359374.
2020-02-26 00:37:37 -08:00
Takashi Kokubun 69f377a3d6
Internalize rb_mjit_unit definition again
Fixed a TODO in b9007b6c54
2020-02-26 00:27:29 -08:00
Takashi Kokubun daf7c48d88
Explain the situation of inner cc_entries [ci skip]
Add a little more details in 7ec2359374
2020-02-25 23:55:54 -08:00
Takashi Kokubun 55923ba883
Note a situation around xmalloc vs free in MJIT [ci skip]
shared by ko1
2020-02-25 23:48:49 -08:00
Koichi Sasada 84d1a99a3f should be initialize jit_unit->cc_entries.
GC can invoke just after allocation of jit_unit->cc_entries so
it should be zero-cleared.
2020-02-25 13:37:52 +09:00
Koichi Sasada 7ec2359374 prevent GC from mjit worker.
ALLOC_N() can causes GC. Sometimes `mjit_copy_job_handler()`
can be called by mjit_worker thread which is not a Ruby thread,
so we need to prevent GC in this function. This patch has some
issues, but I introduce it to pass the tests.
2020-02-25 12:57:10 +09:00
Koichi Sasada b9007b6c54 Introduce disposable call-cache.
This patch contains several ideas:

(1) Disposable inline method cache (IMC) for race-free inline method cache
    * Making call-cache (CC) as a RVALUE (GC target object) and allocate new
      CC on cache miss.
    * This technique allows race-free access from parallel processing
      elements like RCU.
(2) Introduce per-Class method cache (pCMC)
    * Instead of fixed-size global method cache (GMC), pCMC allows flexible
      cache size.
    * Caching CCs reduces CC allocation and allow sharing CC's fast-path
      between same call-info (CI) call-sites.
(3) Invalidate an inline method cache by invalidating corresponding method
    entries (MEs)
    * Instead of using class serials, we set "invalidated" flag for method
      entry itself to represent cache invalidation.
    * Compare with using class serials, the impact of method modification
      (add/overwrite/delete) is small.
    * Updating class serials invalidate all method caches of the class and
      sub-classes.
    * Proposed approach only invalidate the method cache of only one ME.

See [Feature #16614] for more details.
2020-02-22 09:58:59 +09:00
Takashi Kokubun a19d625e66
Allow specifying arbitrary MJIT flags by --jit-debug
This is a secret feature for me. It's only for testing and any behavior
with this flag override is unsupported.

I needed this because I sometimes want to add debug options but do not
want to disable optimizations, for using Linux perf.
2019-12-01 00:58:47 -08:00
Takashi Kokubun 6fa3492362
Eliminate the possibility to leave freed ISeq
in active_units

Hoping to fix:
http://ci.rvm.jp/results/trunk-mjit@silicon-docker/2311375
2019-10-13 19:31:18 -07:00
Takashi Kokubun 183b421509
Delay the free until we stop referring to a unit
`if (unit->iseq)` might have referred to a freed unit. Therefore this
commit delays its free.
2019-10-13 14:15:14 -07:00
Takashi Kokubun 26fae9aa9d
Remove the quick stop path after convert_unit_to_func
Now I'm not exactly sure why I needed to check `stop_worker_p` after
`mjit_copy_cache_from_main_thread` of `convert_unit_to_func`
in 4161674b2f.
If it's for avoiding deadlock under `in_gc` condition, we should keep it.

However, if it's not the case and it's just for retrying accidental
compilation failure or just to avoid `MJIT_ATOMIC_SET` and
`compact_all_jit_code`, I think this quick stop path is not mandatory.

Because this path is somewhat problematic in my upcoming fix in
mjit_worker, let me try to remove this first and see how CI goes.
2019-10-13 09:59:44 -07:00
Yusuke Endoh 4171909695 mjit_worker.c: Add `-lm` to the C compiler in MJIT on Android
To avoid:

    cannot locate symbol "modf" referenced by .../_ruby_mjit_XXX.so"
2019-10-10 23:22:37 +09:00
Takashi Kokubun 5d8f112505
RubyVM::MJIT.pause(wait: true) should wait
for all compilations and compaction.

Prior to this commit, the last-compiled code has not been used because
MJIT worker is stopped before setting the code, and compaction has also
been skipped.

But it was not intentional and `wait: true` pause should wait until
those two things by its feature.
2019-09-26 16:28:34 +09:00
Takashi Kokubun b0a291f6f6
Split CC_LINKER_ARGS from CC_DLDFLAGS_ARGS
to drop MJIT_DLDFLAGS from compile_c_to_o for OpenBSD failure
https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd65/ruby-master/log/20190830T110008Z.fail.html.gz.

8c7f4e8f8b did not work for i686-linux
https://travis-ci.org/ruby/ruby/jobs/578808112.
2019-08-30 22:33:21 +09:00
Takashi Kokubun 8c7f4e8f8b
Try dropping DLDFLAGS from compile_c_to_o
I think this did not work for some environments, but this seems to fix
OpenBSD RubyCI failure:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd65/ruby-master/log/20190830T110008Z.fail.html.gz

Let me check RubyCI impact by this.
2019-08-30 22:03:37 +09:00
Takashi Kokubun 88a37dc620
Stop passing CC_LIBS in compile_c_to_o
To fix "gcc: -lgcc: linker input file unused because linking not done" in
https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd65/ruby-master/log/20190826T200009Z.log.html.gz

Still I'm intentionally leaving CC_DLDFLAGS_ARGS because making compiler
options different might result in compile/link failure. (Of course
CC_DLDFLAGS_ARGS usually should not have compiler options, but it might
include by bad configure setup)

The same problem may exist in MJIT_LIBS used inside CC_LIBS as well, but
I just ignored that case because it impacts only MinGW / cygwin, hoping
that their users do not perform a wrong configure.
2019-08-28 00:56:15 +09:00
Takashi Kokubun dd4f128ac5
Handle failure of opening a null device
This issue is detected by Coverity Scan.
2019-07-15 10:39:07 +09:00
Takashi Kokubun a191009a26
Simplify start_process by exploiting C99
Having a block for mixing a declaration was confusing.
Also I moved `dev_null` and `pid` to limit their scope.
2019-07-15 10:31:01 +09:00
Takashi Kokubun 00a97d9412
Always call va_end in form_args()
This issue is detected by Coverity Scan.
2019-07-15 09:35:57 +09:00
Takashi Kokubun 7ac7685fa7
Simplify link_o_to_so arguments
by C99 compound literal for array and non-constant array initializer
2019-07-14 22:12:59 +09:00
Takashi Kokubun d8cc41c43b
Fix a wrong buffer size to avoid stack corruption
[Bug #15986]
2019-07-14 21:48:45 +09:00
Takashi Kokubun 4402c66978
Refactor mjit_worker command line with C99
Mostly non-constatnt array initializer, and mixed declarations and code.
2019-07-14 12:53:42 +09:00
Takashi Kokubun 814eaa25e2
Do not use rb_iseq_path() while moving ISeq pointers
in GC.compact.

While `in_jit` is false, GC.compact is allowed to run and it may be
moving ISeq-related pointers. So calling rb_iseq_path() when `in_jit`
is true is illegal.
2019-05-30 04:12:11 +09:00
Takashi Kokubun 7c0639f3f8
Never make a method call from MJIT worker
by showing line number only when it's Fixnum.

When it's not Fixnum, we need to call a method to know the line number.
2019-05-29 16:48:07 +09:00
Takashi Kokubun ce7b1132c5
Do not call FIX2INT while GC.compact may be running
because FIX2INT might crash by moving method entry pointer:
http://ci.rvm.jp/results/trunk-mjit@silicon-docker/2063412
2019-05-29 16:22:27 +09:00
Takashi Kokubun 82332c7d8b
Rename mjit_gc_finish_hook to mjit_gc_exit_hook
because @ko1 said "gc_finish" is confusing like a finish of entire GC
process
2019-05-15 23:14:07 -07:00
tenderlove 79accaf8d4 fix strict compile errors
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 03:00:08 +00:00
k0kubun 009a0a3870 Avoid crash on logging GC-ed ISeq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14 12:49:20 +00:00
k0kubun e45c9a40a2 Do not execute MJIT copy job when ISeq is GC-ed
I assumed that ISeq is never GC-ed by `in_jit` + `mjit_mark` on copy job
ISeq, but unfortunately I found SEGV on `mjit_copy_job_handler` in which
iseq->body was somehow Qnil. And it seems to be fixed by disabling the
job when `mjit_free_iseq` is called for the ISeq.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14 12:40:44 +00:00
k0kubun 18b5148215 Add debug counter for MJIT stale_units
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14 07:12:44 +00:00
k0kubun fa13bb1a6f Unify comment styles across MJIT sources
I'm writing `//` comments in newer MJIT code after C99 enablement
(because I write 1-line comments more often than multi-line comments
 and `//` requires fewer chars on 1-line) and then they are mixed
with `/* */` now.

For consistency and to avoid the conversion in future changes, let me
finish the rewrite in MJIT-related code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14 05:26:46 +00:00
k0kubun 9b6b4674d7 Recompile JIT-ed code without optimization
based on inline cache when JIT cancel happens by that.

This feature was in the original MJIT implementation by Vladimir, but on
merging MJIT to Ruby it was removed for simplification. This commit adds
the functionality again for the following benchmark:

52f05781f6/concurrent-map/bench.rb
(shown float is duration seconds. shorter is better)

* Before
```
$ INHERIT=0 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
--
1.6507579649914987

$ INHERIT=0 ruby -v --jit bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
--
1.5091587850474752

$ INHERIT=1 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
--
1.6124781150138006

$ INHERIT=1 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
--
1.7495657080435194 # <-- this
```

* After
```
$ INHERIT=0 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.653559010999743

$ INHERIT=0 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.4738391840364784

$ INHERIT=1 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.645227018976584

$ INHERIT=1 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.523708809982054 # <-- this
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14 04:52:02 +00:00
nobu b9e52ef8b6 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 12:43:33 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
nobu 5ae753dfa3 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 06:44:41 +00:00
mame 9249346c0b mjit_worker.c: explicitly ignore the unused result of RB_DEBUG_COUNTER_INC_IF
By adding `(void)`.  This makes Coverity Scan happy.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29 23:26:31 +00:00
k0kubun 9d047fd3e5 Add mjit_compile_failures debug counter
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29 14:44:09 +00:00
k0kubun 5ee256da68 Prevent mjit length counters from being 0
It seems that `debug_counter_show_results_at_exit` could be called
earlier than `mjit_finish` sometimes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29 14:08:51 +00:00
k0kubun a75ae6faa9 Use alloca again instead of malloc and free
by changing interface of `mjit_copy_cache_from_main_thread`.

This is also fixing deadlock introduced by r67299.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18 17:20:21 +00:00
k0kubun 4d426e28d2 Resurrect r67287 and r67288
I noticed that r67287 was illegal because memory allocated by `alloca`
was used after the stack is expired.

So I just replaced that with `malloc` and `free` for now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18 16:32:48 +00:00
k0kubun 78e87b7d4f Revert "Eliminate mjit_copy_job_t reference from mjit_worker"
This reverts commit ba51ae0109.

CI is failing again...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18 16:14:57 +00:00
k0kubun ba51ae0109 Eliminate mjit_copy_job_t reference from mjit_worker
Take 2 of r67287.

For some reasons, passing pointer of pointer on stack to a function
and assigning an addresse to a pointer dereferenced from the pointer
seems not working on mswin.

So I achieved to return multiple values by returning struct instead of
taking pointers.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18 14:01:52 +00:00
k0kubun 908b530112 Revert "Request inline cache values from mjit_compile"
This reverts commit 4161674b2f.

Revert "Eliminate mjit_copy_job_t reference from mjit_worker"

This reverts commit d86a1aa045.

Reverting them because of CI failures

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18 01:52:45 +00:00
k0kubun 4161674b2f Request inline cache values from mjit_compile
rather than preparing beforehand.

By having this change, implementing inlining by calling
`mjit_copy_cache_from_main_thread` for inlined methods was made
possible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17 18:29:30 +00:00
k0kubun d86a1aa045 Eliminate mjit_copy_job_t reference from mjit_worker
and make `copy_cache_from_main_thread` easier to use.

For implementing inlining later, I'll use `copy_cache_from_main_thread`
inside `mjit_compile`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17 18:07:06 +00:00
k0kubun 3fc26f6013 Drop rb_mjit_unit from mjit_copy_job
and guard iseq from GC by marking iseq in mjit_copy_job.

This is a refactoring for implementing inlining later and
should not be fixing or introducing any bugs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17 17:12:47 +00:00
kazu cebc640790 Fix a typo [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17 16:35:20 +00:00
k0kubun 46549d6b11 Revert "mjit_worker.c: try to simplify CC_DLDFLAGS_ARGS"
This reverts commit 405940234e.

Not working on MinGW
https://ci.appveyor.com/project/ruby/ruby/builds/21737578/job/09a2tr94vof6fstt

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-19 09:08:10 +00:00
k0kubun 405940234e mjit_worker.c: try to simplify CC_DLDFLAGS_ARGS
assuming that -nostartfiles is just optional for mingw, cygwin, and AIX.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-19 07:35:30 +00:00
k0kubun a5de8d1ccb mjit_worker.c: do not use GCC_NOSTDLIB_FLAGS for OpenBSD
OpenBSD's GCC compiler has local extensions that break when
`-nostartfiles -nodefaultlibs -nostdlib` is used.

From: Jeremy Evans <merch-redmine@jeremyevans.net>

[Bug #15548]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-19 07:26:59 +00:00
k0kubun 5e84537d32 Revert "mjit_worker.c: try passing -nostdlib to AIX"
This reverts commit b32fb23083.

This didn't work on AIX.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-15 04:02:53 +00:00
k0kubun ec3cdb34ce mjit_worker.c: pass -nostdlib when making pch as well
[Bug #15513]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14 07:28:34 +00:00
k0kubun b32fb23083 mjit_worker.c: try passing -nostdlib to AIX
r66812 might have allowed this. Testing.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14 06:45:24 +00:00
k0kubun d14089fb3c mjit_worker.c: pass -lgcc to GCC platforms
using `-nodefaultlibs -nostdlib`.

I assume libgcc is needed when we use -nostdlib, and it's linked on some
platforms but not linked on some platforms (like aarch64, and possibly
AIX as well) as said in https://wiki.osdev.org/Libgcc :

> You can link with libgcc by passing -lgcc when linking your kernel
with your compiler. You don't need to do this unless you pass the
-nodefaultlibs option (implied by -nostdlib)

Also note that -nostdlib is not strictly needed (rather implied
-nodefaultlibs is problematic for Gentoo like Bug#15513, which will be
approached later) but helpful for performance. So I want to keep it for
now.

[Bug #15522]

I'm not trying to add `-nodefaultlibs -nostdlib` for AIX in this commit
because AIX RubyCI is dead right now, but I'll try to add them again
once RubyCI is fixed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14 06:18:53 +00:00
k0kubun d89d1d4687 mjit_worker.c: untangle CC_LIBS nesting
This should have no impact.
The CC_LIBS was too hard to read for human.

I don't remember whether the order of -lmsvcrt and -lgcc matters or not,
but I kept that for the best safety.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14 05:50:13 +00:00
kazu ad0ba0dc27 trivial fix r66778 [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12 12:39:41 +00:00
k0kubun 56bf732aaf mjit.c: use boolean type for boolean variables
and functions to clarify the intention and make sure it's not used in a
surprising way (like using 2, 3, ... other than 0, 1 even while it seems
to be a boolean).

This is a retry of r66775. It included some typos...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 14:31:18 +00:00
k0kubun efd99b5331 Revert "mjit.c: use boolean type for boolean variables"
This reverts commit bb1a1aeab0.

We hit something on ci.rvm.jp, reverting until investigation is done.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 13:29:29 +00:00
k0kubun bb1a1aeab0 mjit.c: use boolean type for boolean variables
and functions to clarify the intention and make sure it's not used in a
surprising way (like using 2, 3, ... other than 0, 1 even while it seems
to be a boolean).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 13:21:58 +00:00
nobu 78d6e33702 Fix styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 13:58:49 +00:00
odaira d612c44dad Enable MJIT on AIX
* configure.ac: disable using __builtin_setjmp to avoid errors when execution
  globally jumps out of JITted code. Specify -std=gnu99 to JIT compilation
  to avoid errors regarding the "restrict" keyword in the precompiled header.
  Specify -shared in addition to -Wl,-G when building shared libraries
  to make mjit_build_dir.so expose the MJIT_BUILD_DIR symbol.  Use LDR_PRELOAD
  to load mjit_build_dir.so.

* mjit_worker.c: do not specify -nodefaultlibs or -nostdlibs because on AIX
  JITted code internally refers to the memcpy function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04 22:19:09 +00:00
k0kubun 60989daa1b mjit.c: eliminate -save-temps flag
in a new variable cc_common_args.

`cflags=-save-temps=obj` makes MJIT fail like:
https://rubyci.org/logs/www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20181203T095000Z.log.html.gz

This rubyci specifies -save-temps=obj in CFLAGS to use update-deps, and
the flag is harmful when we want to use -pipe flag.

mjit_worker.c: prefer cc_common_args over CC_COMMON_ARGS

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 12:32:01 +00:00
k0kubun 33eebfd301 mjit_worker.c: undefine CC_PATH
because we mostly use cc_path now and the comment is obsolete (CC_PATH
is now absolute path and the TODO is already resolved).

mjit.c: use CC_COMMON_ARGS[0] directly

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 12:00:27 +00:00
normal eb38fb670b vm_trace.c: workqueue as thread-safe version of postponed_job
postponed_job is safe to use in signal handlers, but is not
thread-safe for MJIT.  Implement a workqueue for MJIT
thread-safety.

[Bug #15316]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-30 03:56:29 +00:00
k0kubun 86cb3d319f mjit_worker.c: promote mjit_copy_job from function
-local variable to global variable.

Consider this case:
1. MJIT worker: dequeue ISeq (stop_worker_p was still FALSE)
2. Ruby thread: call Kernel#exec, which calls mjit_finish(FALSE),
                sets `stop_worker_p = TRUE`, and fires RUBY_VM_CHECK_INTS() once
3. MJIT worker: register copy job, but found stop_worker_p is TRUE.
                set `worker_stopped = TRUE` and the thread stops.
4. Function-local job variable expires by the thread stop (this is eliminated by this commit)
5. Ruby thread: find `worker_stopped` becamse TRUE, start Kernel#exec.
                Kernel#exec fails but exception is rescued.
6. Ruby thread: call RUBY_VM_CHECK_INTS. copy job is dispatched but job variable
                is already expired.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27 12:00:51 +00:00
ko1 96990203b7 Support targetting TracePoint [Feature #15289]
* 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-26 18:16:39 +00:00
k0kubun a3bb9f1093 mjit_worker.c: disable running copy job
after MJIT worker stop.

r65928 didn't fix the SEGV. This commit hopes to fix
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1478576

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 12:50:42 +00:00
k0kubun 2751b5366d mjit.c: avoid running copy job handler after ISeq GC
like this http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1471633

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22 13:29:44 +00:00
k0kubun d53220848c mjit_worker.c: avoid GC when modifying ISeq
This is hoped to fix the SEGV:
https://app.wercker.com/ruby/ruby/runs/mjit-test1/5bf392cf183106002856c1f0?step=5bf3bddc87436a0006292535

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20 11:18:59 +00:00
k0kubun fe6974a8fc mjit_worker.c: support MJIT in forked Ruby process
by launching MJIT worker thread in child Ruby process.

See the comment before `mjit_child_after_fork` for details.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18 08:25:48 +00:00
k0kubun bdf5eb3b91 mjit_worker.c: fix typo [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18 08:22:46 +00:00
k0kubun c8cfd78b40 mjit_worker.c: stop expanding already-absolute MJIT_CC
r65577 seems to have made MJIT_CC (MJIT_CC_COMMONA) become an absolute
path. So start_process doesn't need to find that from PATH by dln_find_exe_r.

This commit is motivated by the msys2 AppVeyor CI failure:
https://ci.appveyor.com/project/ruby/ruby/builds/20084104/job/1pg15os4dtttyl0q

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07 08:04:39 +00:00
k0kubun 6c2014768e mjit_worker.c: don't use _one for now
I'm planning to use _one later, but it may be doubly registered by
switching `stop_worker_p` now and so we should not use _one for now.

Otherwise stale job may reject new job registration and
copy_cache_from_main_thread may wait forever.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-06 07:30:37 +00:00
k0kubun 7a2263fb38 mjit_worker.c: strictly control MJIT copy job
-available region. reducing risk of SEGV in mjit_copy_job_handler() like
http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1446117

I'm not sure which exact part is causing "[BUG] Segmentation fault at 0x0000000000000008"
on `(mjit_copy_job_handler+0x12) [0x564a6c4ce632] /home/ko1/ruby/src/trunk-mjit/mjit.c:26`...

mjit.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-06 07:22:25 +00:00
k0kubun 6e9703b011 mjit_worker.c: do no access pointer after free
When we return there, `unit` is already freed.
This is detected by coverity scan.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-02 11:40:43 +00:00
k0kubun f1d545a76f mjit_worker.c: emphasize free_list of compact_units [ci skip]
In https://bugs.ruby-lang.org/issues/14867#note-98, it's considered
useless at once. So I emphasized the necessity of it in the comment.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01 01:47:26 +00:00
normal 143776f6fe mjit: get rid of rb_mjit_unit_node and use ccan/list
rb_mjit_unit can either exist in unit_queue or active_units, but
not both.  This will make state transitions for event-based MJIT
process management easier.

v2: recheck unit->iseq after GC wakeup

The iseq may be GC-ed while we were waiting for it since we
delete the unit from unit_queue during get_from_list

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31 23:55:22 +00:00
k0kubun 883f93a12e Revert "revert r65471 and include Eric's patch as well"
This reverts commit ff5dc2cbbf.

Deadlock: http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1438883

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31 13:12:39 +00:00
k0kubun ff5dc2cbbf revert r65471 and include Eric's patch as well
https://bugs.ruby-lang.org/issues/14867#note-112

I wanna touch similar places. To avoid our conflict, let me merge Eric's patch earlier.
Let's watch trunk-mjit / trunk-mjit-wait CIs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31 12:21:55 +00:00
normal dc8a744d6e Revert "mjit: get rid of rb_mjit_unit_node and use ccan/list"
This reverts commit c5177fa846. r65468

Many CI failures like:
 http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1438415

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31 06:44:42 +00:00
normal c5177fa846 mjit: get rid of rb_mjit_unit_node and use ccan/list
rb_mjit_unit can either exist in unit_queue or active_units, but
not both.  This will make state transitions for event-based MJIT
process management easier.

[ruby-core:89654]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31 03:02:01 +00:00
ko1 8f675cdd00 support theap for T_HASH. [Feature #14989]
* hash.c, internal.h: support theap for small Hash.
  Introduce RHASH_ARRAY (li_table) besides st_table and small Hash
  (<=8 entries) are managed by an array data structure.
  This array data can be managed by theap.
  If st_table is needed, then converting array data to st_table data.

  For st_table using code, we prepare "stlike" APIs which accepts hash value
  and are very similar to st_ APIs.

  This work is based on the GSoC achievement
  by tacinight <tacingiht@gmail.com> and refined by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:11:51 +00:00
k0kubun 456a54de69 mjit_worker.c: don't ask MJIT copy job to main thread
when main thread is waiting for MJIT worker forever without executing
RUBY_VM_CHECK_INTS due to --jit-wait.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-23 13:05:29 +00:00