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

564 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada aa2f505825
Make autoloading_const_entry static 2019-06-23 02:49:39 +09:00
git c5c3486340 * expand tabs. 2019-06-23 01:47:40 +09:00
Nobuyoshi Nakada 9384383019
Module#constant_source_location [Feature #10771] 2019-06-23 01:46:38 +09:00
Nobuyoshi Nakada 5084233b88
Split global search for module 2019-06-23 01:26:48 +09:00
Nobuyoshi Nakada 151843b981
Hoisted out autoloading_const_entry 2019-06-23 01:26:42 +09:00
git c997f7daaa * expand tabs. 2019-06-21 17:29:08 +09:00
Nobuyoshi Nakada 5b7cc63d11
Turned `recur` into `int` [Feature #15777] 2019-06-21 17:28:37 +09:00
Jean Boussier fb85a42860
Add an optional `inherit` argument to Module#autoload?
[Feature #15777]

Closes: https://github.com/ruby/ruby/pull/2173
2019-06-21 17:28:37 +09:00
Aaron Patterson 6db2d6d852
Add compaction support for more types.
This commit adds compaction support for:

* Fibers
* Continuations
* Autoload Constants
2019-06-11 09:16:14 -07:00
Nobuyoshi Nakada c1e5299787
Fix FrozenError when assigning frozen class to constant
* variable.c (set_namespace_path): modules/classes can get named
  by assignment to constant, even if frozen.  [Bug #15891]
2019-06-01 02:41:14 +09:00
Nobuyoshi Nakada 48f3dc3cce
Set namespace tree
* variable.c (set_namespace_path): set path to the whole namespace
  tree.  [Feature #15765]
2019-05-22 15:47:00 +09:00
Alan Wu 1b20d6a6c6
Extract build_const_pathname
* variable.c (build_const_pathname): build constant path from
  name as a string.  [Feature #15765]
2019-05-22 15:47:00 +09:00
Alan Wu b00f280d4b
Eagerly name modules and classes
* variable.c: make the hidden ivars `classpath` and `tmp_classpath` the source
  of truth for module and constant names. Assign to them when modules are bind
  to constants.

* variable.c: remove references to module name cache, as what used to be the cache
  is now the source of truth. Remove rb_class_path_no_cache().

* variable.c: remove the hidden ivar `classid`. This existed for the purposes of
  module name search, which is now replaced. Also, remove the associated
  rb_name_class().

* class.c: use rb_set_class_path_string to set the name of Object during boot.
  Must use a fstring as this runs before rb_cString is initialized and
  creating a normal string leads to a VALUE without a class.

* spec/ruby/core/module/name_spec.rb: add a few specs to specify what happens
  to Module#name across multiple operations. These specs pass without other
  code changes in this commit.

[Feature #15765]
2019-05-22 15:46:47 +09:00
Aaron Patterson 154a67f140
Rename rb_gc_new_location to rb_gc_location
The function will return new or existing locations depending on whether
or not the object actually moved, so give it a more appropriate name.
2019-05-18 12:24:28 +03:00
Urabe, Shyouhei aa190abe20 newptr should not be NULL
obj_ivar_heap_alloc already handles that situation.
2019-04-26 15:59:40 +09:00
Urabe, Shyouhei f02760fc0a avoid reading uninitialized variable
autoload_reset() can read this state.result.  Because autoload_reset
is a function passed to rb_ensure, there is a chance when an
execption raises before actually filling this memory region.

test/ruby/test_defined.rb:test_autoload_noload is one of such case.

Found using memory sanitizer.

==54014==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x557a683f3e5a in autoload_reset variable.c:2372:9
    #1 0x557a6707a93b in rb_ensure eval.c:1084:5
    #2 0x557a683efbf5 in rb_autoload_load variable.c:2475:14
    #3 0x557a685fc460 in vm_get_ev_const vm_insnhelper.c:938:4
    #4 0x557a68448e0a in vm_exec_core insns.def:267:11
2019-04-26 15:59:40 +09:00
tenderlove 91793b8967 Add `GC.compact` again.
🙏

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 01:19:47 +00:00
tenderlove 744e5df715 Reverting compaction for now
For some reason symbols (or classes) are being overridden in trunk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 09:41:41 +00:00
tenderlove 3c55b643ae Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 03:17:25 +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
tenderlove 3ef4db15e9 Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09 20:32:04 +00:00
nobu 978290515e [DOC] Fix method references to Method instance methods
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:36 +00:00
nobu de0ef1a9df [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:35 +00:00
svn 28f619e301 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-09 00:12:53 +00:00
nobu 5aecf03ec3 variable.c: hoisted out rb_namespace_p
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-09 00:12:52 +00:00
svn b0d24baf8a * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28 10:33:04 +00:00
nobu d54a86d49d Hoisted out undefined_constant
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28 10:33:02 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
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-12-06 07:49:24 +00:00
nobu 98f8baf944 No new entry when getting undefined global variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-25 04:05:09 +00:00
nobu 7ac1ff5fb7 Prefer ALLOCV over ALLOCA
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-25 03:36:10 +00:00
ko1 c39797e872 introduce USE_TRANSIENT_HEAP to enable/disable theap.
* include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro
  to enable/disable transient heap.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01 08:53:44 +00:00
ko1 2c62beb6b6 remove '//' style comments.
* variable.c (obj_ivar_set): remove '//' style comments pointed out by the
  following build log: https://travis-ci.org/ruby/ruby/jobs/448551951


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31 02:39:08 +00:00
ko1 873d57347f support theap for T_OBJECT.
* variable.c: now instance variable space has theap supports.
  obj_ivar_heap_alloc() tries to acquire memory from theap.

* debug_counter.h: add some counters for theap.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:01:17 +00:00
svn 69b8ffcd5b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:02:12 +00:00
ko1 7d359f9b69 revert r65444 and r65446 because of commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:01:55 +00:00
ko1 efe869c0e5 support theap for T_OBJECT.
* variable.c: now instance variable space has theap supports.
  obj_ivar_heap_alloc() tries to acquire memory from theap.

* debug_counter.h: add some counters for theap.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 20:49:35 +00:00
shyouhei c2bfb4e93c add new instruction attribute called leaf
An instruction is leaf if it has no rb_funcall inside.  In order to
check this property, we introduce stack canary which is a random
number collected at runtime.  Stack top is always filled with this
number and checked for stack smashing operations, when VM_CHECK_MODE.
[GH-1947]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11 09:48:58 +00:00
mame ffb09d8e87 eval.c: rename "rb_frozen_class_p" to "rb_class_modify_check"
Just refactoring.  Despite its name, the function does NOT return a
boolean but raises an exception when the class given is frozen.
I don't think the new name "rb_class_modify_check" is the best, but
it follows the precedeint "rb_ary_modify_check", and is definitely
better than "*_p".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-27 13:57:14 +00:00
nobu 97e05dad7f UNREACHABLE_RETURN
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end
  of non-void functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24 05:38:07 +00:00
watson1978 91061e74e4 Fix documentation in Object#remove_instance_variable
It should be described that the string argument will be accept like Object#instance_variable_get.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-14 17:04:56 +00:00
nobu 7387c08373 const_missing on private constants
* variable.c (rb_const_search): call #const_missing method on
  private constants, as well as uninitialized constants.
  [Feature #14328]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-06 13:56:58 +00:00
nobu 1b474b869c variable.c: fix receiver on private constant
* variable.c (rb_const_search): fix NameError :receiver attribute
  on private constant, should raise with the included module, not
  the ICLASS.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-19 08:15:52 +00:00
normal ec959fbb4b variable.c: fix multiple autoload with identical file (again)
We need to ensure autoload declarations pointing to the same
feature (aka "file") can wait on each other to avoid deadlock
situations.

So, reorganize autoload data structures to maintain a
feature => autoload_data_i mapping, and have module constant
tables point to the new autoload_const struct instead of
directly to autoload_data_i.  This allows multiple
autoload_const structs to refer to the SAME autoload_data_i
struct, and with it, the on-stack autoload_state.waitq.

The end result is different constants can share the same waitq
(tied to the feature name), and not deadlock each other during
loading.

Thanks to Eugene Kenny for the bug report and reproducible test case.

Reported-by: Eugene Kenny <elkenny@gmail.com>

* variable.c (autoload_featuremap): new global
  (struct autoload_const): new per-const struct
  (struct autoload_state): reference autoload_const instead of autoload_data_i
  (struct autoload_data_i): remove per-const
  (autoload_i_mark): delete from autoload_featuremap if unreferenced
  (autoload_c_mark): new dmark callback
  (autoload_c_free): new dfree callback
  (autoload_c_memsize): new memsize callback
  (autoload_const_type): new data type
  (get_autoload_data): set autoload_const as well
  (rb_autoload_str): use new data structures
  (autoload_delete): cleanup from autoload_featuremap
  (check_autoload_required): adjust for new internals
  (rb_autoloading_value): ditto
  (struct autoload_const_set_args): remove, redundant with autoload_const
  (const_tbl_update): adjust for new internals
  (autoload_const_set): ditto
  (autoload_require): ditto
  (autoload_reset): ditto
  (rb_autoload_load): ditto
  (rb_const_set): ditto
  (current_autoload_data): ditto
  (set_const_visibility): ditto
* test/ruby/test_autoload.rb (test_autoload_same_file): new test
  (test_no_leak): new test
  [ruby-core:86935] [Bug #14742]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-10 08:54:26 +00:00
normal 18b2cee206 revert r63387 and r63389 for now
I can't reproduce the problem on my 32-bit machine, and I have
connectivity problems to my 64-bit systems at the moment.
Will revisit in a few hours hopefully.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-10 05:10:13 +00:00
normal 6726038d76 variable.c: fix autoload object lifetimes and leak
We must not call normal Hash methods inside GC free callback,
either, however identity hash may be used.

[ruby-core:86935] [Bug #14742]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-10 04:18:28 +00:00
normal b74131132f variable.c: fix multiple autoload with identical file
We need to ensure autoload declarations pointing to the same
feature (aka "file") can wait on each other to avoid deadlock
situations.

So, reorganize autoload data structures to maintain a
feature => autoload_data_i mapping, and have module constant
tables point to the new autoload_const struct instead of
directly to autoload_data_i.  This allows multiple
autoload_const structs to refer to the SAME autoload_data_i
struct, and with it, the on-stack autoload_state.waitq.

The end result is different constants can share the same waitq
(tied to the feature name), and not deadlock each other during
loading.

Thanks to Eugene Kenny for the bug report and reproducible test case.

Reported-by: Eugene Kenny <elkenny@gmail.com>

* variable.c (autoload_featuremap): new global
  (struct autoload_const): new per-const struct
  (struct autoload_state): reference autoload_const instead of autoload_data_i
  (struct autoload_data_i): remove per-const
  (autoload_i_mark): delete from autoload_featuremap if unreferenced
  (autoload_c_mark): new dmark callback
  (autoload_c_free): new dfree callback
  (autoload_c_memsize): new memsize callback
  (autoload_const_type): new data type
  (get_autoload_data): set autoload_const as well
  (rb_autoload_str): use new data structures
  (autoload_delete): cleanup from autoload_featuremap
  (check_autoload_required): adjust for new internals
  (rb_autoloading_value): ditto
  (struct autoload_const_set_args): remove, redundant with autoload_const
  (const_tbl_update): adjust for new internals
  (autoload_const_set): ditto
  (autoload_require): ditto
  (autoload_reset): ditto
  (rb_autoload_load): ditto
  (rb_const_set): ditto
  (current_autoload_data): ditto
  (set_const_visibility): ditto
* test/ruby/test_autoload.rb (test_autoload_same_file): new test
  [ruby-core:86935] [Bug #14742]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-10 01:19:20 +00:00
normal b456eab2ea variable.c: fix thread + fork errors in autoload
This is fairly non-intrusive bugfix to prevent children
from trying to reach into thread stacks of the parent.
I will probably reuse this idea and redo r62934, too
(same bug).

* vm_core.h (typedef struct rb_vm_struct): add fork_gen counter
* thread.c (rb_thread_atfork_internal): increment fork_gen
* variable.c (struct autoload_data_i): store fork_gen
* variable.c (check_autoload_data): remove (replaced with get_...)
* variable.c (get_autoload_data): check fork_gen when retrieving
* variable.c (check_autoload_required): use get_autoload_data
* variable.c (rb_autoloading_value): ditto
* variable.c (rb_autoload_p): ditto
* variable.c (current_autoload_data): ditto
* variable.c (autoload_reset): reset fork_gen, adjust indent
* variable.c (rb_autoload_load): set fork_gen when setting state
* test/ruby/test_autoload.rb (test_autoload_fork): new test
  [ruby-core:86410] [Bug #14634]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20 03:22:26 +00:00
nobu 4691daccc1 variable.c: hoisted out overtaken cvar warnings
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:15:26 +00:00
nobu 248ff4f1b1 variable.c: flags at autoloading
* variable.c (const_tbl_update): flags by deprecate_constant /
  private_constant set during autoloading should be preserved
  after required.  [ruby-core:85516] [Bug #14469]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 09:36:35 +00:00
usa 66652bb632 revert r62392
check the declaration of `rb_autoloading_value()` in vm_core.h and the call in
vm_insnhelper.c, and retry it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 09:34:37 +00:00
nobu a6a596a5bd variable.c: flags at autoloading
* variable.c (const_tbl_update): flags by deprecate_constant /
  private_constant set during autoloading should be preserved
  after required.  [ruby-core:85516] [Bug #14469]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 09:11:02 +00:00
k0kubun ed935aa5be mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.

This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.

This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).

Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.

I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.

common.mk: update dependencies for mjit_compile.c.

internal.h: declare `rb_vm_insn_addr2insn` for MJIT.

vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.

win32/mkexports.rb: export thread/ec functions, which are used by MJIT.

include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.

array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.

I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.

Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>

Part of [Feature #14235]

---

* Known issues
  * Code generated by gcc is faster than clang. The benchmark may be worse
    in macOS. Following benchmark result is provided by gcc w/ Linux.
  * Performance is decreased when Google Chrome is running
  * JIT can work on MinGW, but it doesn't improve performance at least
    in short running benchmark.
  * Currently it doesn't perform well with Rails. We'll try to fix this
    before release.

---

* Benchmark reslts

Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores

- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option

** Optcarrot fps

Benchmark: https://github.com/mame/optcarrot

|         |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:--------|:--------|:--------|:--------|:--------|
|fps      |37.32    |51.46    |51.31    |58.88    |
|vs 2.0.0 |1.00x    |1.38x    |1.37x    |1.58x    |

** MJIT benchmarks

Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)

|           |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:----------|:--------|:--------|:--------|:--------|
|aread      |1.00     |1.09     |1.07     |2.19     |
|aref       |1.00     |1.13     |1.11     |2.22     |
|aset       |1.00     |1.50     |1.45     |2.64     |
|awrite     |1.00     |1.17     |1.13     |2.20     |
|call       |1.00     |1.29     |1.26     |2.02     |
|const2     |1.00     |1.10     |1.10     |2.19     |
|const      |1.00     |1.11     |1.10     |2.19     |
|fannk      |1.00     |1.04     |1.02     |1.00     |
|fib        |1.00     |1.32     |1.31     |1.84     |
|ivread     |1.00     |1.13     |1.12     |2.43     |
|ivwrite    |1.00     |1.23     |1.21     |2.40     |
|mandelbrot |1.00     |1.13     |1.16     |1.28     |
|meteor     |1.00     |2.97     |2.92     |3.17     |
|nbody      |1.00     |1.17     |1.15     |1.49     |
|nest-ntimes|1.00     |1.22     |1.20     |1.39     |
|nest-while |1.00     |1.10     |1.10     |1.37     |
|norm       |1.00     |1.18     |1.16     |1.24     |
|nsvb       |1.00     |1.16     |1.16     |1.17     |
|red-black  |1.00     |1.02     |0.99     |1.12     |
|sieve      |1.00     |1.30     |1.28     |1.62     |
|trees      |1.00     |1.14     |1.13     |1.19     |
|while      |1.00     |1.12     |1.11     |2.41     |

** Discourse's script/bench.rb

Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb

NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
 to fix it. Please wait for the fix.)

*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 17
  75: 18
  90: 22
  99: 29
home_admin:
  50: 21
  75: 21
  90: 27
  99: 40
topic_admin:
  50: 17
  75: 18
  90: 22
  99: 32
categories:
  50: 35
  75: 41
  90: 43
  99: 77
home:
  50: 39
  75: 46
  90: 49
  99: 95
topic:
  50: 46
  75: 52
  90: 56
  99: 101

*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 19
  75: 21
  90: 25
  99: 33
home_admin:
  50: 24
  75: 26
  90: 30
  99: 35
topic_admin:
  50: 19
  75: 20
  90: 25
  99: 30
categories:
  50: 40
  75: 44
  90: 48
  99: 76
home:
  50: 42
  75: 48
  90: 51
  99: 89
topic:
  50: 49
  75: 55
  90: 58
  99: 99

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 11:22:28 +00:00
nobu 9a74cc0a55 variable.c: removed old warning
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 13:29:23 +00:00
nobu 9473f86fb0 defined? returns nil for toplevel constant lookup
* variable.c (rb_const_defined_0): toplevel constant lookup has
  been removed, should return nil too.
  [ruby-core:85142] [Bug #14407] [Fix GH-1800]

From: Gonzalo <grzuy0@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27 06:12:09 +00:00
kazu b8cc476ce9 use predefined IDs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22 13:09:37 +00:00
shyouhei 9e746a3518 rb_global_tbl marked as static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:52 +00:00
nobu 6b5e0bd98c exclude flexible array size with old compilers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-14 11:19:18 +00:00
mame ccc5c73258 variable.c (struct gen_ivtbl): Use FLEX_ARY_LEN.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-13 12:17:42 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
normal 7bbff60485 variable.c: fix autoload stack space regression
r61560 ("offsetof(type, foo.bar) is (arguably) a GCCism")
introduced 16 bytes of stack overhead on 64-bit systems.
Remove that overhead and cast, instead.  While we're at it,
restore the "waitq" name to clarify the purpose of the field.

(This is one unfortunate consequence of the CC0 ccan/list.h
 implementation compared to the *GPL ones in glibc/urcu/linux)

* variable.c (struct autoload_state): remove head field, clarify naming
  (autoload_reset): cast and adjust
  (autoload_sleep_done): ditto
  (rb_autoload_load): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 21:51:59 +00:00
shyouhei 5851706073 fix SEGV touching uninitialized memory
This function can be called from boot_defclass().
No assumption can be made about object internals.

(lldb) run
Process 2386 launched: './miniruby' (x86_64)
Process 2386 stopped
* thread #1: tid = 0x13f3b6, 0x00000001001e0b26 miniruby`rb_class_path_cached(klass=4311373720) + 20 at variable.c:321, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x00000001001e0b26 miniruby`rb_class_path_cached(klass=4311373720) + 20 at variable.c:321
   318  VALUE
   319  rb_class_path_cached(VALUE klass)
   320  {
-> 321      st_table *ivtbl = RCLASS_IV_TBL(klass);
   322      st_data_t n;
   323
   324      if (!ivtbl) return Qnil;
(lldb) bt
* thread #1: tid = 0x13f3b6, 0x00000001001e0b26 miniruby`rb_class_path_cached(klass=4311373720) + 20 at variable.c:321, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
  * frame #0: 0x00000001001e0b26 miniruby`rb_class_path_cached(klass=4311373720) + 20 at variable.c:321
    frame #1: 0x000000010009cbd0 miniruby`rb_raw_obj_info(buff="0x0000000100fa5798 [2    ] T_CLASS", buff_size=256, obj=4311373720) + 1393 at gc.c:9341
    frame #2: 0x000000010009cf16 miniruby`obj_info(obj=4311373720) + 98 at gc.c:9423
    frame #3: 0x000000010008ca87 miniruby`newobj_init(klass=0, flags=66, v1=0, v2=0, v3=0, wb_protected=1, objspace=0x00000001007cf280, obj=4311373720) + 338 at gc.c:1887
    frame #4: 0x000000010008cd51 miniruby`newobj_of(klass=0, flags=66, v1=0, v2=0, v3=0, wb_protected=1) + 171 at gc.c:1970
    frame #5: 0x000000010008ce1b miniruby`rb_wb_protected_newobj_of(klass=0, flags=66) + 54 at gc.c:1990
    frame #6: 0x0000000100027563 miniruby`class_alloc(flags=2, klass=0) + 46 at class.c:165
    frame #7: 0x000000010002761a miniruby`rb_class_boot(super=0) + 35 at class.c:203
    frame #8: 0x0000000100028612 miniruby`boot_defclass(name="BasicObject", super=0) + 28 at class.c:537
    frame #9: 0x000000010002868b miniruby`Init_class_hierarchy + 26 at class.c:548
    frame #10: 0x00000001000efe69 miniruby`InitVM_Object + 9 at object.c:3892
    frame #11: 0x00000001000f138e miniruby`Init_Object + 57 at object.c:4122
    frame #12: 0x00000001000a59bd miniruby`rb_call_inits + 29 at inits.c:23
    frame #13: 0x000000010007af30 miniruby`ruby_setup + 229 at eval.c:61
    frame #14: 0x000000010007af7e miniruby`ruby_init + 13 at eval.c:78
    frame #15: 0x0000000100000c58 miniruby`main(argc=2, argv=0x00007fff5fbfdbf0) + 88 at main.c:41
    frame #16: 0x00007fff88eda5ad libdyld.dylib`start + 1
(lldb)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:58 +00:00
shyouhei 5471bf9cc2 offsetof(type, foo.bar) is (arguably) a GCCism
TL;DR see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2031.htm

Suppose we have:

struct X {
  struct Y {
    z_t z;
  } y;
} x;

then, you _cant_ infer offsetof(struct X, y.z). The ISO C99 section
7.17 says nothing about such situation. At least clang warns this
being an extension to the language (-Wextended-offsetof).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:56 +00:00
nobu f6631c3096 variable.c: public rb_autoload
* variable.c (rb_autoload): restore the visibility for backward
  compatibility.  [ruby-core:84454] [Bug #14236]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-26 05:30:31 +00:00
normal 2ab827042e variable.c (autoload_sleep_done): avoid needless list_node init
We do not need list_del_init in ensure callbacks, only list_del,
since it can only ever be called after list_del_init in
autoload_reset.  So avoid the needless re-initialization.

* variable.c (autoload_sleep_done): s/list_del_init/list_del/

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-22 23:41:50 +00:00
normal 94a7a4e908 autoload: always wait on loading thread
We cannot assume autoload_provided/rb_feature_provided returning
TRUE means it is safe to proceed without waiting.  Another
thread may call rb_provide_feature before setting the constant
(via autoload_const_set).  So we must wait until autoload is
completed by another thread.

Note: this patch was tested with an explicit rb_thread_schedule
in rb_provide_feature to make the race condition more apparent
as suggested by <s.wanabe@gmail.com>:
> --- a/load.c
> +++ b/load.c
> @@ -563,6 +563,7 @@ rb_provide_feature(VALUE feature)
>      rb_str_freeze(feature);
>
>      rb_ary_push(features, rb_fstring(feature));
> +rb_thread_schedule();
>      features_index_add(feature, INT2FIX(RARRAY_LEN(features)-1));
>      reset_loaded_features_snapshot();
>  }

* variable.c (check_autoload_required): do not assume a provided
  feature means autoload is complete, always wait if autoload is
  being performed by another thread.
  [ruby-core:81105] [Bug #11384] Thanks to <s.wanabe@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-12 21:52:04 +00:00
normal c7ff36c6f0 variable.c: cleanup waitq upon thread death
* variable.c (autoload_reset): use idempotent list_del_init
  (autoload_sleep): moved code from rb_autoload_load
  (autoload_sleep_done): cleanup for use with rb_ensure
  (rb_autoload_load): ensure list delete happens in case the
  thread dies during sleep
* test/ruby/bug-13526.rb: new script for separate execution
* test/ruby/test_autoload.rb (test_bug_13526): new test
  [ruby-core:81016] [Bug #13526]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 04:26:37 +00:00
ko1 10b800133e add several counters to analyze ivar inline caches.
* debug_counter.h: add (and renamed) several counters:
  ivar_get_ic_hit
  ivar_get_ic_miss
  ivar_get_ic_miss_serial
  ivar_get_ic_miss_unset
  ivar_get_ic_miss_noobject
  ivar_set_ic_hit
  ivar_set_ic_miss
  ivar_set_ic_miss_serial
  ivar_set_ic_miss_unset
  ivar_set_ic_miss_oorange
  ivar_set_ic_miss_noobject
  ivar_get_base
  ivar_set_base

  See related source code to know what counters mean.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-15 08:25:58 +00:00
ko1 76c4cca19c add performance counting mechanism for MRI debug/tuning purpose.
* How to enable this feature?
  * define USE_DEBUG_COUNTER as 1.
  * you can disable to output the result with
    RUBY_DEBUG_COUNTER_DISABLE environment variable
    even if USE_DEBUG_COUNTER == 1.

* How to add new counter?
  * add COUNTER(<name>) line on debug_counter.h.
  * include "debug_counter.h"
  * insert RB_DEBUG_COUNTER_INC(<name>) line on your favorite place.

* counter output example:
  [RUBY_DEBUG_COUNTER]    mc_inline_hit   999
  [RUBY_DEBUG_COUNTER]    mc_inline_miss  3
  [RUBY_DEBUG_COUNTER]    mc_global_hit   23
  [RUBY_DEBUG_COUNTER]    mc_global_miss  273
  [RUBY_DEBUG_COUNTER]    mc_global_state_miss    3
  [RUBY_DEBUG_COUNTER]    mc_class_serial_miss    0
  [RUBY_DEBUG_COUNTER]    mc_cme_complement       0
  [RUBY_DEBUG_COUNTER]    mc_cme_complement_hit   0
  [RUBY_DEBUG_COUNTER]    mc_search_super 1384
  [RUBY_DEBUG_COUNTER]    ivar_get_hit    0
  [RUBY_DEBUG_COUNTER]    ivar_get_miss   0
  [RUBY_DEBUG_COUNTER]    ivar_set_hit    0
  [RUBY_DEBUG_COUNTER]    ivar_set_miss   0
  [RUBY_DEBUG_COUNTER]    ivar_get        431
  [RUBY_DEBUG_COUNTER]    ivar_set        465

  * mc_... is related to method caching.
  * ivar_... is related to instance variable accesses.

* compare with dtrace/system tap features, there are completely
  no performacne penalties when it is disabled.

* This feature is supported only on __GNUC__ compilers.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 08:18:15 +00:00
nobu cd0426c00b variable.c: remove deprecated internal feature
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 06:16:49 +00:00
nobu a9c1522969 variable.c: noreturn in GCC
* variable.c (rb_generic_ivar_table): declare as noreturn only in
  GCC, which does not err on different attributes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 01:28:30 +00:00
ko1 56c38a648b remove harmful declaration.
* variable.c (gen_ivtbl_get): declaration conflict on VC++.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-20 19:12:52 +00:00
naruse 11eba07b83 Supress warning: function might be candidate for attribute 'noreturn'
GCC7 shows it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-20 10:59:10 +00:00
nobu 6877de73de DEPRECATED_INTERNAL_FEATURE
* error.c (ruby_deprecated_internal_feature): renamed, to
  explicitly represent deprecation.

* internal.h (DEPRECATED_INTERNAL_FEATURE): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-17 05:45:44 +00:00
nobu 14d61a94ff variable.c: fatal rb_generic_ivar_table
* variable.c (rb_generic_ivar_table): raise fatal error.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-16 14:48:12 +00:00
nobu 1df80905a3 variable.c: fix the condition to cache
* variable.c (rb_const_set): fix the condition to cache the class
  path and cache permanent or temporary path corresponding to the
  outer klass.  [ruby-core:79039] [Bug #13120]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-11 04:12:56 +00:00
nobu faf472a2bb variable.c: resolve permanent name only
* variable.c (rb_const_set): resolve and cache class name
  immediately only if the outer class/module has the name,
  otherwise just set the ID.  [ruby-core:79007] [Bug #13113]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-08 01:59:54 +00:00
nobu 44a2576f79 variable.c: top-level constant look-up
* variable.c (rb_const_search): [EXPERIMENTAL] remove top-level
  constant look-up.  [Feature #11547]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-01 09:07:56 +00:00
tenderlove e04167bc32 Stop reading past the end of `ivptr` array
If you have code like this:

```ruby
class A
  def initialize
    @a = nil
    @b = nil
    @c = nil
    @d = nil
    @e = nil
  end
end

x = A.new
y = x.clone
100.times { |z| x.instance_variable_set(:"@foo#{z}", nil) }
puts y.inspect
```

`x` and `y` will share `iv_index_tbl` hashes.  However, the size of the
hash will grow larger than the number if entries in `ivptr` in `y`.
Before this commit, `rb_ivar_count` would use the size of the hash to
determine how far to read in to the array, but this means that it could
read past the end of the array and cause the program to segv

[ruby-core:78403]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-29 17:06:35 +00:00
nobu e6a260ecdb variable.c: rb_deprecate_constant
* variable.c (rb_deprecate_constant): new function to deprecate a
  constant by the name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-09 03:02:22 +00:00
nobu 6054e6d65e variable.c: fix deprecated constant message
* variable.c (rb_const_search): warn with the actual class/module
  name which defines the deprecated constant.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-09 01:10:01 +00:00
nobu a3cc3cc5c9 variable.c: fix private constant message
* variable.c (rb_const_search): raise with the actual class/module
  name which defines the private constant.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-09 01:07:41 +00:00
nobu 6ea002a7a2 variable.c: exclude private constants
* variable.c (rb_local_constants_i): exclude private constants
  when excluding inherited constants too.  [Bug #12345]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-19 06:39:01 +00:00
nobu 0ce3fab422 variable.c: consider length
* variable.c (rb_path_to_class): consider the string length
  instead of a terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-19 02:19:45 +00:00
nobu 5707ba30aa variable.c: rb_const_search
* variable.c (rb_path_to_class): search the constant at once
  instead of checking if defined and then getting it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-19 01:54:42 +00:00
nobu 55a39399ff variable.c: check length
* variable.c (check_autoload_required): check length first before
  checking the first byte.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30 05:18:16 +00:00
nobu c57c719e4a variable.c: hidden constants
* variable.c (rb_local_constants_i): exclude hidden constants.
  [ruby-core:75575] [Bug #12389]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-27 08:38:50 +00:00
nobu 5cb5692ac8 vm_insnhelper.c: deprecated constant in class
* vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even
  in the class context.  [ruby-core:75505] [Bug #12382]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-15 01:57:28 +00:00
nobu bc65dbcdeb variable.c: fix implicit conversion
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22 10:04:47 +00:00
naruse 3738fe3333 * variable.c: use uint32_t instead of long to avoid confusion about
the type of ivtbl->numiv.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22 09:47:34 +00:00
hsbt b33841b32a * variable.c: Added documentation about order of `Module#constants`
[ci skip][Bug #12121][ruby-dev:49505][fix GH-1301]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-23 01:39:41 +00:00
nobu 92e803c9c8 variable.c: matched backrefs only
* variable.c (rb_f_global_variables): add matched back references
  only, as well as defiend? operator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-14 08:36:49 +00:00
nobu 7e825eeefc variable.c: $1..$9 in global_variables
* variable.c (rb_f_global_variables): add $1..$9 only if $~ is
  set.  fix the condition removed at r14014.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-14 02:45:03 +00:00
normal 244916d43b resolve class name earlier and more consistently
This further avoids class name resolution issues which came
about due to relying on hash table ordering before r53376.

Pre-caching the class name when it is never used raises memory
use, but the overall gain from moving away from st still gives
us a small gain.  Reverting r53376 and this patch and testing with
"valgrind -v ./ruby -rrdoc -eexit" on x86 (32-bit) shows:

before:
    in use at exit: 1,662,239 bytes in 25,286 blocks
  total heap usage: 49,514 allocs, 24,228 frees, 6,005,561 bytes allocated

after, with this change:
    in use at exit: 1,646,529 bytes in 24,572 blocks
  total heap usage: 48,891 allocs, 24,319 frees, 6,003,921 bytes allocated

* class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP
* object.c (rb_mod_const_set): move name resolution to rb_const_set
* variable.c (rb_const_set): do class resolution here
  [ruby-core:72807] [Bug #11977]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-12 19:26:07 +00:00
sho-h d5f4a2ba12 variable.c (rb_mod_deprecate_constant): [DOC] added
documentation for Module#deprecate_constant. [ci skip]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-04 07:08:05 +00:00
normal 1142de8e2a use id_table for constant tables
valgrind 3.9.0 on x86-64 reports a minor reduction in memory usage
when loading only RubyGems and RDoc by running: ruby -rrdoc -eexit

before: HEAP SUMMARY:
    in use at exit: 2,913,448 bytes in 27,394 blocks
  total heap usage: 48,362 allocs, 20,968 frees, 9,034,621 bytes alloc

after: HEAP SUMMARY:
    in use at exit: 2,880,056 bytes in 26,712 blocks
  total heap usage: 47,791 allocs, 21,079 frees, 9,046,507 bytes alloc

* class.c (struct clone_const_arg): adjust for id_table
  (clone_const): ditto
  (clone_const_i): ditto
  (rb_mod_init_copy): ditto
  (rb_singleton_class_clone_and_attach): ditto
  (rb_include_class_new): ditto
  (include_modules_at): ditto
* constant.h (rb_free_const_table): ditto
* gc.c (free_const_entry_i): ditto
  (rb_free_const_table): ditto
  (obj_memsize_of): ditto
  (mark_const_entry_i): ditto
  (mark_const_tbl): ditto
* internal.h (struct rb_classext_struct): ditto
* object.c (rb_mod_const_set): resolve class name on assignment
* variable.c (const_update): replace with const_tbl_update
  (const_tbl_update): new function
  (fc_i): adjust for id_table
  (find_class_path): ditto
  (autoload_const_set): st_update => const_tbl_update
  (rb_const_remove): adjust for id_table
  (sv_i): ditto
  (rb_local_constants_i): ditto
  (rb_local_constants): ditto
  (rb_mod_const_at): ditto
  (rb_mod_const_set): ditto
  (rb_const_lookup): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-29 20:19:14 +00:00
ngoto 3bf3f825c3 * variable.c (struct ivar_update): rename "extended" to "iv_extended"
to avoid name conflict with /usr/include/floatingpoint.h on
  Solaris. [Bug #11853] [ruby-dev:49448]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-21 12:35:29 +00:00
nobu bb4d72c51f make local symbols static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:07:41 +00:00
normal a2e025a7d0 introduce rb_autoload_str to replace rb_autoload
rb_autoload_str may be safer by preventing premature GC.  It
can also be more efficient by passing a pre-frozen string that
can be deduped using rb_fstring.  Common autoload callers (e.g.
rubygems, rdoc) already use string literals as the file
argument.

There seems to be no reason to expose rb_autoload_str to the
public C API since autoload is not performance-critical.
Applications may declare autoloads in Ruby code or via
rb_funcall; so merely deprecate rb_autoload without exposing
rb_autoload_str to new users.

Running: valgrind -v ruby -rrdoc -rubygems -e exit
shows a minor memory reduction (32-bit userspace)

before:

  in use at exit: 1,600,621 bytes in 28,819 blocks
total heap usage: 55,786 allocs, 26,967 frees, 6,693,790 bytes allocated

after:

  in use at exit: 1,599,778 bytes in 28,789 blocks
total heap usage: 55,739 allocs, 26,950 frees, 6,692,973 bytes allocated

* include/ruby/intern.h (rb_autoload): deprecate
* internal.h (rb_autoload_str): declare
* load.c (rb_mod_autoload): use rb_autoload_str
* variable.c (rb_autoload): become compatibility wrapper
  (rb_autoload_str): hoisted out from old rb_autoload
  [ruby-core:71369] [Feature #11664]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-06 12:28:09 +00:00
normal 9f9861699b variable.c: remove spurious #define for globals
Removing the indirection helps me with readability, at
least.  It doesn't seem like there are many other places
in the Ruby code where macros are used like this.

[ruby-core:71735] [Feature #11749]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-29 23:53:43 +00:00
normal 64c08dafe2 variable.c (rb_autoload_load): allow recursive calls
* variable.c (rb_autoload_load): allow recursive calls
  [ruby-core:71345] [Bug #11658]
* test/ruby/test_autoload.rb (test_autoload_while_autoloading):
  new test by: Hiroshi Shirosaki <h.shirosaki@gmail.com>
  [ruby-core:71390]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-09 21:18:42 +00:00
nobu c8803b10d1 variable.c: suppress a warning
* variable.c (autoload_reset): initialize formally to suppress a
  warning from container_off_var() by Visual C.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-04 06:59:15 +00:00
normal ca86c3abb8 variable.c: remove casts for rb_class_ivar_set callers
Casting any arguments of rb_class_ivar_set to st_data_t is wrong
as the function does not take any st_data_t parameters anymore.
There's no functional change, as ID, VALUE, and st_data_t are
all the same type, but this reduces confusion and improves
maintainability for future type changes.

* variable.c (find_class_path): remove cast for rb_class_ivar_set
  (rb_ivar_set): ditto
  (rb_cvar_set): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-02 21:50:24 +00:00
normal 5aef9e1d78 variable.c (rb_global_tbl): convert to id_table
Mainly this is to reduce casting a tiny amount; and
probably nothing depends on the order of globals.
Likely no measurable memory usage improvement as globals
are not common, but maybe some weird code out there benefits.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-02 21:26:26 +00:00
nobu 1546ffed49 use rb_source_loc and rb_source_location
* error.c, eval.c, eval_error.c, gc.c, variable.c, vm.c,
  vm_eval.c, vm_trace.c: use rb_source_loc/rb_source_location
  instead of combination of rb_sourcefile/rb_sourcefilename and
  rb_sourceline.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-31 01:02:26 +00:00
nobu 6f77d0a3aa variable.c: rb_class_ivar_set
* variable.c (rb_class_ivar_set): rename as class specific ivar
  setter, and st_table is no longer involved.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-30 03:07:06 +00:00
normal 0a9f20ae02 variable.c (generic_ivar_remove): return original value
This fixes a bug introduced in r50678
("variable.c: use indices for generic ivars")
and does not affect any released version of Ruby

* variable.c (generic_ivar_remove): adjust type, set valp
  (rb_obj_remove_instance_variable): simplify call
* test/ruby/test_object.rb (test_remove_instance_variable):
  expand for implementation details

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-30 02:37:59 +00:00
normal a666e9b5f2 variable.c (rb_st_insert_id_and_value): reduce args
Minor simplification; this will hopefully make future patches
for switching to id_table easier-to-review.

* internal.h (rb_st_insert_id_and_value): update prototype
* variable.c (rb_st_insert_id_and_value): reduce args
  (find_class_path): adjust call for less args
  (rb_ivar_set): ditto
  (rb_cvar_set): ditto
* class.c (rb_singleton_class_attached): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-30 01:40:28 +00:00
normal fc87b3b7e0 variable.c: reduce heap usage for autoload_data_i
For the loader (first thread which hits autoload, it is wasteful
to have extra elements on the stack.  For the lifetime of the
process, it is wasteful to waste 2 words for every autoload
entry.  So this makes full use of existing stack overhead
while reducing heap overhead for long-lived autoload_data_i
structs.

* variable.c (struct autoload_state): usable as wait-queue head
  (struct autoload_data_i): remove 2 words of overhead
  (autoload_i_mark): remove marking for thread
  (autoload_reset): adjust for struct changes
  (rb_autoload): ditto
  (rb_autoloading_value): ditto
  (rb_autoload_load): ditto
  (const_update): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 01:14:45 +00:00
normal cdc251c695 variable.c: additional locking around autoload
[ruby-core:70075] [ruby-core:71239] [Bug #11384]

Note: this open-coding locking method may go into
rb_mutex/rb_thread_shield types.  It is smaller and simpler and
based on the wait queue implementation of the Linux kernel.

When/if we get rid of GVL, native mutexes may be used as-is.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-28 23:59:45 +00:00
nobu a4f838c742 error.c: receiver in NameError
* error.c (rb_name_err_new): store the receiver directly.
* error.c (name_err_receiver): return directly stored receiver.
  [Feature #10881]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-28 06:36:13 +00:00
nobu 72ff61f4a8 NameError#receiver of uninitialized constant
* error.c (name_err_mesg_to_str): quote the name if unprintable.
* object.c (check_setter_id): use rb_check_id to convert names.
* variable.c (uninitialized_constant): use NameError::message to
  keep the receiver of uninitialized constant.  [Feature #10881]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-28 06:24:12 +00:00
nobu dfa9eb54bd variable.c: fail if frozen
* variable.c (set_const_visibility): fail if the class/module is
  frozen.  [ruby-core:70828] [Bug #11532]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-16 11:39:29 +00:00
normal 1e6a643fa9 variable.c: wrap long lines
Make code easier to read and hunt for bugs with my tiny terminal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-04 03:13:19 +00:00
nobu 83cd51e3fe variable.c: Module#deprecate_constant
* variable.c (rb_const_get_0): warn deprecated constant reference.
* variable.c (rb_mod_deprecate_constant): mark constants to be
  warned as deprecated.  [Feature #11398]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-30 04:20:00 +00:00
normal 1782dd8cd7 variable.c: remove FL_ABLE check for generic ivars
Missed this in r50758.

* variable.c (generic_ivar_set): remove FL_ABLE check
  (gen_ivar_copy): ditto
  [ruby-core:69715]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-24 00:24:32 +00:00
normal 152d36a79e variable.c: remove generic ivar support for special constants
Special constants are all frozen since [Feature #8923] and cannot
support ivars.  Remove some unused code we had for supporting them.

* variable.c (special_generic_ivar): remove flag
  (givar_i, rb_mark_generic_ivar_tbl): remove functions
  (rb_free_generic_ivar, rb_ivar_lookup, rb_ivar_delete,
   generic_ivar_set, rb_ivar_set, rb_ivar_defined,
   rb_copy_generic_ivar, rb_ivar_foreach, rb_ivar_count,
   rb_obj_remove_instance_variable):
   adjust for lack of ivar support in special constants
* test/ruby/test_variable.rb: test ivars for special consts
* internal.h: remove rb_mark_generic_ivar_tbl decl
* gc.c (gc_mark_roots): remove rb_mark_generic_ivar_tbl call

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 20:53:35 +00:00
normal f6cd582505 variable.c: avoid compatibility table with generic ivars
This recovers and improves performance of Marshal.dump/load on
Time objects compared to when we implemented generic ivars
entirely using st_table.

This also recovers some performance on other generic ivar objects,
but does not bring bring Marshal.dump/load performance up to
previous speeds.

benchmark results:
minimum results in each 10 measurements.
Execution time (sec)
		name    trunk   geniv   after
marshal_dump_flo        0.343   0.334   0.335
marshal_dump_load_geniv 0.487   0.527   0.495
marshal_dump_load_time  1.262   1.401   1.257

Speedup ratio: compare with the result of `trunk' (greater is better)
		name    geniv   after
marshal_dump_flo        1.026   1.023
marshal_dump_load_geniv 0.925   0.985
marshal_dump_load_time  0.901   1.004

* include/ruby/intern.h (rb_generic_ivar_table): deprecate
* internal.h (rb_attr_delete): declare
* marshal.c (has_ivars): use rb_ivar_foreach
  (w_ivar): ditto
  (w_object): update for new interface
* time.c (time_mload): use rb_attr_delete
* variable.c (generic_ivar_delete): implement
  (rb_ivar_delete): ditto
  (rb_attr_delete): ditto
  [ruby-core:69323] [Feature #11170]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30 00:20:15 +00:00
normal 9d9aea7fe5 variable.c: use indices for generic ivars
This reduces memory overhead of ivars for common types such as
T_DATA the same way T_OBJECT does it.

For 9992 accepted clients on an OpenSSL server, this reduces
memory from 77160K to 69248K with the script in
https://bugs.ruby-lang.org/issues/11170

* variable.c (static int special_generic_ivar): move
  (rb_generic_ivar_table): rewrite for compatibility
  (gen_ivtbl_bytes): new function
  (generic_ivar_get): update to use ivar index
  (generic_ivar_update): ditto
  (generic_ivar_set): ditto
  (generic_ivar_defined): ditto
  (generic_ivar_remove): ditto
  (rb_mark_generic_ivar): ditto
  (givar_i): ditto
  (rb_free_generic_ivar): ditto
  (rb_mark_generic_ivar_tbl): ditto
  (rb_generic_ivar_memsize): ditto
  (rb_copy_generic_ivar): ditto
  (rb_ivar_set): ditto
  (rb_ivar_foreach): ditto
  (rb_ivar_count): ditto
  (givar_mark_i): remove
  (gen_ivtbl_mark): new function
  (gen_ivar_each): ditto
  (iv_index_tbl_extend): update for struct ivar_update
  (iv_index_tbl_newsize): ditto
  [ruby-core:69323] [Feature #11170]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-29 23:42:49 +00:00
normal ff4b73601b variable.c: extract common functions for generic ivar indices
* variable.c (iv_index_tbl_make): extract from rb_ivar_set
  (iv_index_tbl_extend): ditto
  (iv_index_tbl_newsize): ditto
  (rb_ivar_set): use extracted functions
  [ruby-core:69323] (Part 1)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-29 23:22:40 +00:00
normal 4b0987a629 variable.c: generic_iv_tbl is unavoidable
Even miniruby creates one generic ivar (plain "ruby" creates 9),
so there's no point in lazily allocating the table.

I dumped generic ivar counts with the following trivial patch:

  --- a/variable.c
  +++ b/variable.c
  @@ -24,6 +24,10 @@ static void check_before_mod_set(VALUE, ID, VALUE, const char *);
   static void setup_const_entry(rb_const_entry_t *, VALUE, VALUE, rb_const_flag_t);
   static int const_update(st_data_t *, st_data_t *, st_data_t, int);
   static st_table *generic_iv_tbl;
  +__attribute__((destructor)) static void count_genivar(void)
  +{
  +    fprintf(stderr, "genivars: %zu\n", (size_t)generic_iv_tbl->num_entries);
  +}

   void
   Init_var_tables(void)

* variable.c (Init_var_tables): init generic_iv_tbl
  (rb_generic_ivar_table, generic_ivar_get, generic_ivar_set,
   generic_ivar_defined, generic_ivar_remove,
   rb_mark_generic_ivar, givar_i, rb_mark_generic_ivar_tbl,
   rb_free_generic_ivar, rb_copy_generic_ivar, rb_ivar_foreach,
   rb_ivar_count): remove checks for uninitialize generic_iv_tbl
  [ruby-core:69155] [Feature #11146]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-21 00:15:00 +00:00
nobu 6fb9349d85 allocate structs with wrapper
* parse.y (rb_parser_new, ripper_s_allocate): allocate structs
  with making new wrapper objects and get rid of potential memory
  leak.

* variable.c (rb_autoload): ditto.

* ext/digest/digest.c (rb_digest_base_alloc): ditto.

* ext/strscan/strscan.c (strscan_s_allocate): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-16 12:56:48 +00:00
tenderlove cd465d552c * variable.c: Change autoload to call `require` through Ruby rather
than directly calling `rb_require_safe`.  This allows things like
  RubyGems to intercept file loading done though `autoload`.
  [Feature #11140]

* test/ruby/test_autoload.rb: Test for change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-14 21:57:33 +00:00
nobu 6fefba37d0 variable.c: no intermediate IDs
* variable.c (rb_set_class_path_string, rb_set_class_path): get
  rid of creating intermediate IDs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-13 22:01:33 +00:00
nobu 8d6fbbe862 variable.c: const_update
* variable.c (autoload_delete): no longer delete const entry
  itself.

* variable.c (autoload_const_set, rb_const_set): update const
  entry instead of adding after removal.

* variable.c (const_update): extract from rb_const_set.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-13 07:54:59 +00:00
nobu 3124d55a3c variable.c: setup_const_entry
* variable.c (setup_const_entry): extract rb_const_entry_t setup
  from rb_const_set.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-13 07:54:52 +00:00
nobu 938910492c variable.c: ensure
* variable.c (rb_autoload_load): prefer rb_ensure than rb_protect
  for rollback.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-13 07:54:39 +00:00
nobu 74768415d8 variable.c: escape erred name
* variable.c (rb_path_to_class): escape erred name.  as precision
  delimits the formatted result only, not region of an argument
  string, need to make a substring for the particular region.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-22 14:31:53 +00:00
ko1 724012a23d * internal.h, node.h: move a definition of `struct rb_global_entry'
and related functions from node.h to internal.h.
* variable.c: remove unused include pragma.
* common.mk: remove unused dependency.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-12 01:55:58 +00:00
nobu badb4de72a variable.c: rb_search_class_path
* variable.c (rb_tmp_class_path): defer making temporary class
  path string.
* variable.c (rb_search_class_path): search class path or return
  Qnil or Qfalse if unnamed, not creating a temporary path.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-28 06:42:29 +00:00
nobu 1ef1a0c602 variable.c: preserve name encoding of subclass
* variable.c (rb_tmp_class_path): preserve name encoding of an
  anonymous instance of module/class subclass.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-28 06:02:06 +00:00
nobu 4194ca02fb revert r45487
* variable.c (rb_alias_variable): IDs are always immportal now, no
  pin down is needed.

* vm_method.c (rb_method_entry_make): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-06 02:33:47 +00:00
nobu e98b307036 variable.c: ignore mortal classid
* variable.c (classname): ignore classid if it is a mortal symbol.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-06 02:33:41 +00:00
nobu e580a631be use 0 for reserved
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01 06:38:04 +00:00
nobu 8eb0c810b2 get rid of inadvertent ID creation
* object.c (rb_mod_const_get, rb_mod_const_defined): ditto.
* variable.c (rb_const_missing, rb_mod_const_missing): call
  const_missing without new ID to get rid of inadvertent ID
  creation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-21 16:11:55 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
nobu 6e21b611aa variable.c, vm_insnhelper.c: improve performance
* variable.c (rb_ivar_get), vm_insnhelper.c (vm_getivar): improve
  instance variable retrieval performance by checking ruby_verbose
  before call of rb_warning and evaluation of its argument.
  [ruby-core:65786] [Feature #10396]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-19 17:23:31 +00:00
nobu 26a29ffbed variable.c: use st_update
* variable.c (generic_ivar_set): use st_update to insert object
  which does not have generic instance variables yet.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-08 14:49:49 +00:00
nobu c8d7d587ac variable.c: use st_update
* variable.c (sv_i, cv_i): use st_update to insert non-existing
  entries.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-08 08:27:54 +00:00
nobu 02fe713b46 constant.h: constant visibilities
* constant.h (RB_CONST_PRIVATE_P, RB_CONST_PUBLIC_P): macros to
  predicate constant visibilities.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-08 08:27:51 +00:00
normal d2e3c03409 simplify some trivial rb_data_type_t callbacks
* process.c (free_exec_arg): remove
  (memsize_exec_arg): ptr is never NULL
  (exec_arg_data_type): use RUBY_TYPED_DEFAULT_FREE

* variable.c (autoload_i_free): remove
  (autoload_data_i_type): use RUBY_TYPED_DEFAULT_FREE
  (autoload_memsize): ptr is never NULL

* vm_backtrace.c (location_free): remove
  (location_mark): ptr is never NULL
  (location_data_type): use RUBY_TYPED_DEFAULT_FREE
  (backtrace_mark): ditto
  (backtrace_free): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-13 05:14:51 +00:00
normal 02dade3b9e variable.c (rb_ivar_set): remove unnecessary check
r47512 contains the proper fix

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 09:00:06 +00:00
nobu ddf6eb40c7 variable.c: check index overflow
* variable.c (rb_ivar_set), vm_insnhelper.c (vm_setivar): check
  instance variable index overflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 08:05:12 +00:00
normal b3a4367ce4 rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.

ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody

This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
  total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
  total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated

* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
  ci->index becomes a 32-bit signed int (from signed long).
  Reorder for better packing on 64-bit, giving an 8 byte reduction
  from 104 to 96 bytes for each ci.

* compile.c (new_callinfo, setup_args, iseq_compile_each,
  iseq_build_from_ary_body): adjust for type changes

* vm_insnhelper.c (vm_getivar): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 06:32:44 +00:00
normal 4938045735 variable: cleanup to use rb_const_lookup
* variable.c: cleanup to use rb_const_lookup
* vm_insnshelper.c: ditto

This reduces casting and long lines.  This should make it easier to
switch to alternatives to st for constant storage.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-04 01:12:53 +00:00
normal 48a2b96d2b introduce ZALLOC{,_N} to replace ALLOC{,_N}+MEMZERO use
Using calloc where possible reduces code and binary sizes.

* include/ruby/ruby.h (ZALLOC, ZALLOC_N): implement
  (Data_Make_Struct, TypedData_Make_Struct):
  ZALLOC replaces ALLOC+memset
* compile.c (iseq_seq_sequence): ZALLOC_N replaces ALLOC_N+MEMZERO
* cont.c (fiber_t_alloc): ZALLOC replaces ALLOC+MEMZERO
* io.c (rb_io_reopen): ditto
* iseq.c (prepare_iseq_build): ditto
* parse.y (new_args_tail_gen, parser_new, ripper_s_allocate): ditto
* re.c (match_alloc): ditto
* variable.c (rb_const_set): ditto
* ext/socket/raddrinfo.c (get_addrinfo): ditto
* ext/strscan/strscan.c (strscan_s_allocate): ditto
* gc.c (rb_objspace_alloc): calloc replaces malloc+MEMZERO

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-25 21:34:35 +00:00
ko1 76a929a7fc * parse.y: change Symbol <-> ID relationship to avoid
exposing IDs from collectable symbols.
  [Bug #10014]
  Now, rb_check_id() returns 0 if corresponding symbol is
  pinned dynamic symbol.
  There is remaining intern_cstr_without_pindown(), it can return
  IDs from collectable symbols. We must be careful to use it
  (only used in parse.y).  I think it should be removed if
  it does not have impact for performance.
* parse.y:
  add:
  * STATIC_SYM2ID()
  * STATIC_ID2SYM()
  rename:
  * rb_pin_dynamic_symbol() -> dsymbol_pindown()
* internal.h:
  remove:
  * rb_check_id_without_pindown()
  * rb_sym2id_without_pindown()
  add:
  * rb_check_symbol()
  * rb_check_symbol_cstr()
* load.c: use rb_check_id() or rb_check_id_cstr().
* object.c: ditto.
* struct.c: ditto.
* thread.c: ditto.
* vm_method.c: ditto.
* string.c (sym_find): use only rb_check_symbol().
* sprintf.c (rb_str_format): use rb_check_symbol_cstr().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-09 06:14:41 +00:00
nobu 876bfc6b4e Init functions don't need ID caches
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-03 03:38:10 +00:00
nobu e99ee55abc constify parameters
* include/ruby/intern.h: constify `argv` parameters.

* include/ruby/ruby.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-18 06:16:39 +00:00
nobu 6b9b85318a variable.c, vm_method.c: pin down
* variable.c (rb_alias_variable): ensure pinned down.

* vm_method.c (rb_method_entry_make): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-31 14:38:38 +00:00
nari 90b7073842 * parse.y: support Symbol GC. [ruby-trunk Feature #9634]
See this ticket about Symbol GC.

* include/ruby/ruby.h:
  Declare few functions.
  * rb_sym2id: almost same as old SYM2ID but support dynamic symbols.
  * rb_id2sym: almost same as old ID2SYM but support dynamic symbols.
  * rb_sym2str: almost same as `rb_id2str(SYM2ID(sym))` but not
    pin down a dynamic symbol.
  Declare a new struct.
  * struct RSymbol: represents a dynamic symbol as object in
    Ruby's heaps.
  Add few macros.
  * STATIC_SYM_P: check a static symbol.
  * DYNAMIC_SYM_P: check a dynamic symbol.
  * RSYMBOL: cast to RSymbol

* gc.c: declare RSymbol. support T_SYMBOL.

* internal.h: Declare few functions.
  * rb_gc_free_dsymbol: free up a dynamic symbol. GC call this
    function at a sweep phase.
  * rb_str_dynamic_intern: convert a string to a dynamic symbol.
  * rb_check_id_without_pindown: not pinning function.
  * rb_sym2id_without_pindown: ditto.
  * rb_check_id_cstr_without_pindown: ditto.

* string.c (Init_String): String#intern and String#to_sym use
  rb_str_dynamic_intern.

* template/id.h.tmpl: use LSB of ID as a flag for determining a
  static symbol, so we shift left other ruby_id_types.

* string.c: use rb_sym2str instead `rb_id2str(SYM2ID(sym))` to
  avoid pinning.

* load.c: use xx_without_pindown function at creating temporary ID
  to avoid pinning.

* object.c: ditto.

* sprintf.c: ditto.

* struct.c: ditto.

* thread.c: ditto.

* variable.c: ditto.

* vm_method.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-26 04:57:47 +00:00