Commit Graph

11567 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto faed5054f8 Initialized local variables in mrb_hash_shift(). 2020-08-03 15:53:50 +09:00
Yukihiro "Matz" Matsumoto 0a505dcfd6 Simplify khash.h.
- Remove ` kh_put_prepare` function used only internally
- Remove `n_occupied` member from `kh_` struct
2020-07-31 18:14:02 +09:00
Yukihiro "Matz" Matsumoto 1517d77e93 Fix puts in mruby-print on no argument; 0e9bd24
`puts` should print newline when called without arguments.
2020-07-31 06:57:05 +09:00
Yukihiro "Matz" Matsumoto 9571a4c07e Merge pull request #5050 from dearblue/memsize_of2
Update document for `ObjectSpace.memsize_of` [ci skip]
2020-07-26 13:56:26 +09:00
dearblue 0983c723c5 Update document for ObjectSpace.memsize_of [ci skip]
The `recurse` keyword is removed by f00657ead7.
2020-07-26 13:12:01 +09:00
Yukihiro "Matz" Matsumoto 425b5f32d6 Merge pull request #5049 from shuujii/use-type-tag-for-hash-code-in-ht_hash_func
Use type tag for hash code in `ht_hash_func()`
2020-07-25 19:40:05 +09:00
KOBAYASHI Shuji 0c88c71786 Use type tag for hash code in ht_hash_func()
The function corresponding to `ht_hash_func()` was as follows in the days of
khash implementation (before d78acc7a).

  ```c
  mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
  {
    enum mrb_vtype t = mrb_type(key);
    ...
    switch (t) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (khint_t)t ^ (khint_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

When switched to the segmented list implementation (d78acc7a), this function
was changed as follows.

  ```c
  sg_hash_func(mrb_state *mrb, seglist *t, mrb_value key)
  {
    enum mrb_vtype tt = mrb_type(key);
    ...
    switch (tt) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (size_t)t ^ (size_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

Since the argument `t` was added, the variable for type tag was changed from
`t` to `tt`, but the variable used in the expression of `h` remained `t`.

Probably this is an omission of change, so fixed it.
2020-07-25 16:59:02 +09:00
Yukihiro "Matz" Matsumoto f868d7d357 Change the logic to calculate object (iv_tbl) size; #5045 2020-07-24 13:13:06 +09:00
Yukihiro "Matz" Matsumoto c69ca2c7f8 Merge pull request #5045 from dearblue/memsize_of
Improve `mruby-os-memsize`
2020-07-24 12:02:05 +09:00
dearblue ccd5f203bf Improve prototype for mrb_objspace_page_slot_size(); ref #5032
If it qualify a return type that is not a pointer with `const`, the
compiler ignores it.
2020-07-24 11:48:09 +09:00
dearblue 5c2b11d215 Avoid using FPU with mruby-os-memsize; ref #5032
And, in the calculation of the instance variable size, the fraction was
always rounded down because of division of integers, so fix it.

At the same time, test items that are no longer passed due to this
change are deleted.
2020-07-24 11:42:37 +09:00
dearblue c9ba761b9e Support without mruby-method for mruby-os-memsize; ref #5032 2020-07-24 11:42:26 +09:00
dearblue 2b588b8566 Add NUL terminator to string object size calculation; ref #5032 2020-07-24 11:42:16 +09:00
Yukihiro "Matz" Matsumoto b4f4f5968b ObjectSpace.count_objects to support MRB_TT_ISTRUCT; #5046 2020-07-23 07:10:35 +09:00
Yukihiro "Matz" Matsumoto e7599050dc Fix a bug with ht_index called with size==0; fix #5046
It happens when a hash made empty calls `rehash`.
2020-07-23 07:06:35 +09:00
Yukihiro "Matz" Matsumoto 0e9bd24827 Fix puts to print newline with empty strings; ref b184772 2020-07-22 17:50:01 +09:00
Yukihiro "Matz" Matsumoto b920270508 Use more mrb_field_write_barrier for instance variables. 2020-07-22 15:01:55 +09:00
Yukihiro "Matz" Matsumoto 491aa1bfe5 Use more local variables.
To make debugging easy, and to improve the performance little bit.
2020-07-22 15:01:54 +09:00
Yukihiro "Matz" Matsumoto c99bb756c4 Move gray_list update from gc_mark_children.
The responsibility moved to caller to avoid confusion. Currently the
function is called from only 2 places, so it is relatively easy to
ensure not to update `gray_list` in the caller.  But the assumption
may change in the future.
2020-07-22 15:01:54 +09:00
Yukihiro "Matz" Matsumoto 097f525817 Avoid using mrb_ary_modify from the internal function.
`mrb_ary_modify` calls `mrb_write_barrier`, so can cause the same
problem of the past `push`. It is provided for use-level API.
2020-07-22 15:01:54 +09:00
Yukihiro "Matz" Matsumoto 5533c29833 Use mrb_field_write_barrier instead of mrb_write_barrier for push.
When the array is very big, the simpler `mrb_write_barrier` causes
calling `gc_mark_children` for big arrays repeatedly. That would hinder
performance very badly.
2020-07-22 15:01:53 +09:00
Yukihiro "Matz" Matsumoto 0bb4d10ca7 Define Array#to_a to avoid unnecessary loops. 2020-07-22 14:56:56 +09:00
Yukihiro "Matz" Matsumoto 914da3d712 Small comment fix in mrblib/array.c. 2020-07-22 14:56:36 +09:00
Yukihiro "Matz" Matsumoto 670622f45d Skip unnecessary mark_context if mrb->c == mrb->root_c. 2020-07-22 14:56:03 +09:00
dearblue 97f71b5a67 Fixed garbled characters; ref #5041 2020-07-22 00:03:17 +09:00
dearblue 639703cf01 Remove unnecessory methods in mruby-objectspace; ref #5041
The `ObjectSpace#memsize_of` and `ObjectSpace#memsize_of_all` in `mruby-objectspace` ware
migrated to `mruby-os-memsize` mrbgem.
2020-07-21 23:32:30 +09:00
Yukihiro "Matz" Matsumoto 6334949ba6 Fix the VM stack handling bug in 'mrb_yield_with_class()`; fix #5042 2020-07-21 12:47:35 +09:00
Yukihiro "Matz" Matsumoto b1847721e8 Implement Kernel#print and Kernel#puts in C. 2020-07-20 23:35:17 +09:00
Yukihiro "Matz" Matsumoto f0afdf7496 Merge pull request #5041 from RoryO/extract-memsize-to-gem
Extract memsize to gem
2020-07-20 08:23:46 +09:00
Rory OConnell 0685784119 Adding to authors 2020-07-19 15:40:29 -07:00
Rory OConnell 5f4a27217e Separate memsize_of and memsize_of_all to a separate gem; #5040
Those methods are originally CRuby specific.

Co-authored-by: Yukihiro "Matz" Matsumoto <matz@ruby.or.jp>
2020-07-19 15:36:08 -07:00
Yukihiro "Matz" Matsumoto c9ea39843b Remove some tests from mruby-objectspace gem; #5040
Those tests succeeds only on some configuration.
2020-07-20 06:05:06 +09:00
Yukihiro "Matz" Matsumoto a6f31ad6ce Avoid accessing obj.tt of mrb_value; #5040
The old code compiles only on `MRB_NO_BOXING`.
2020-07-20 06:05:06 +09:00
Yukihiro "Matz" Matsumoto 07b75d927e Replace 0 by MRB_EACH_OBJ_OK; #5040 2020-07-20 06:04:54 +09:00
Yukihiro "Matz" Matsumoto 71254be076 Skip MRB_TT_FREE and MRB_TT_BREAK in each_object. 2020-07-19 13:11:53 +09:00
Yukihiro "Matz" Matsumoto 1d2c5c12d3 Reorder members of struct os_each_object_data to stop warnings.
`mrb_value` may or may not be struct according to configuration.
2020-07-19 13:10:08 +09:00
Yukihiro "Matz" Matsumoto 00337543a5 Should have updated the arg spec for memsize_of&memsize_of_all; #5040 2020-07-19 09:11:16 +09:00
Yukihiro "Matz" Matsumoto f76defd310 Use c specifier for mrb_get_args. 2020-07-19 07:47:07 +09:00
Yukihiro "Matz" Matsumoto d023adcb12 Add new specifier c to mrb_get_args.
`C` retrieves a `mrb_value` that refers a class/module.
`c` retrieves a `struct RClass*` pointer to a class/module.
2020-07-19 07:45:16 +09:00
Yukihiro "Matz" Matsumoto 5b2763821e Fix memsize_of_all to count all objects if no argument given; #5040 2020-07-19 07:42:35 +09:00
Yukihiro "Matz" Matsumoto 6d073f8d99 Fix memsize_of_all to count memory of subclass instances; #5040
`ObjectSpace.memsize_of_all` takes a class and count memory size of all
instances of the class and its subclasses (if any).
2020-07-19 06:57:34 +09:00
Yukihiro "Matz" Matsumoto 667ace2bfe Merge pull request #5040 from RoryO/add-memsize-of-all
Add ObjectSpace.memsize_of_all
2020-07-19 06:43:13 +09:00
Rory O'Connell ffe8bf6323 Avoid singleton classes with mrb_class_real 2020-07-18 13:55:45 -07:00
Rory OConnell a79d1ba9ff Adding memsize_of_all doc 2020-07-17 20:21:23 -07:00
Rory OConnell fe1ec9afdd Add ObjectSpace.memsize_of_all 2020-07-17 20:09:44 -07:00
Yukihiro "Matz" Matsumoto 1952004d5a Use proc->env to check block_given? if possible; fix #5039
This bug has been there since mruby 1.4.0 (2018-04).
2020-07-17 16:15:47 +09:00
Yukihiro "Matz" Matsumoto e41f1f5139 Fix indent of compiler conditions; #5032 2020-07-17 12:32:54 +09:00
Yukihiro "Matz" Matsumoto 495c1a377a Fix memsize_of to count method table size; #5032
Also avoid `mrb_funcall` to minimize VM recursion.
2020-07-17 12:31:00 +09:00
Yukihiro "Matz" Matsumoto 9f52bcfca9 Fix memsize_of Fibers; #5032
Memory size of a Fiber is calculated by stack size only in CRuby.
2020-07-17 11:50:12 +09:00
Yukihiro "Matz" Matsumoto a2b8c08a52 Add const to irep pointer in os_memsize_of_irep; #5032 2020-07-17 11:43:55 +09:00