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

2096 Коммитов

Автор SHA1 Сообщение Дата
Alan Wu 714a4942fd
Remove unused and accidentally public rb_str_shared_root_p()
This function was added to a public header in [1] probably
unintentionally since it's not used anywhere, exposes implementation
details, and isn't related to the goals of that pull request.

[1]: 56cc3e99b6
2022-06-16 07:20:20 -04:00
John Hawthorn 17d260a87f Restore rb_exec_recursive_outer
This was a public method, so we should probably keep it.
2022-06-15 16:07:29 -07:00
Matt Valentine-House 56cc3e99b6 Move String RVALUES between pools
And re-embed any strings that can now fit inside the slot they've been
moved to
2022-06-13 10:11:27 -07:00
John Hawthorn 52da90acee Make method id explicit in rb_exec_recursive_outer
Previously, because opt_aref and opt_aset don't push a frame, when they
would call rb_hash to determine the hash value of the key, the initial
level of recursion would incorrectly use the method id at the top of the
stack instead of "hash".

This commit replaces rb_exec_recursive_outer with
rb_exec_recursive_outer_mid, which takes an explicit method id, so that
we can make the hash calculation behave consistently.

rb_exec_recursive_outer was documented as being internal, so I believe
this should be okay to change.
2022-06-10 14:48:21 -07:00
Jean Boussier 9125374726 [Feature #18339] GVL Instrumentation API
Ref: https://bugs.ruby-lang.org/issues/18339

Design:

- This tries to minimize the overhead when no hook is registered.
  It should only incur an extra unsynchronized boolean check.
- The hook list is protected with a read-write lock as to cause
  contention when some hooks are registered.
- The hooks MUST be thread safe, and MUST NOT call into Ruby as they
  are executed outside the GVL.
- It's simply a noop on Windows.

API:

```
rb_internal_thread_event_hook_t * rb_internal_thread_add_event_hook(rb_internal_thread_event_callback callback, rb_event_flag_t internal_event, void *user_data);
bool rb_internal_thread_remove_event_hook(rb_internal_thread_event_hook_t * hook);
```

You can subscribe to 3 events:

  - READY: called right before attempting to acquire the GVL
  - RESUMED: called right after successfully acquiring the GVL
  - SUSPENDED: called right after releasing the GVL.

The hooks MUST be threadsafe, as they are executed outside of the GVL, they also MUST NOT call any Ruby API.
2022-06-03 15:13:33 +02:00
Jemma Issroff a04d8c9513
Remove trailing comma from FL_USER3 (#5958) 2022-05-26 15:40:34 -07:00
Jemma Issroff 33fdff3c30 Remove unused RMODULE_INCLUDED_INTO_REFINEMENT flag 2022-05-26 12:09:04 -07:00
Jemma Issroff 80ad0e751f Remove unnecessary module flag, add module assertions to other module flags 2022-05-23 11:04:34 -07:00
Daisuke Fujimura (fd0) 3d6fd162a4 Undefine RUBY_DLN_CHECK_ABI on cygwin 2022-05-19 17:15:30 +09:00
Peter Zhu a41fbc2c95 Increase SIZE_POOL_COUNT to 5
Having more size pools will allow us to allocate larger objects
through Variable Width Allocation.

I have attached some benchmark results below.

Discourse:
  On Discourse, we don't see much change in response times. We do see
  a small reduction in RSS.

  Branch RSS: 377.8 MB
  Master RSS: 396.3 MB

railsbench:
  On railsbench, we don't see a big change in RPS or p99 performance.
  We see a small increase in RSS.

  Branch RPS: 815.38
  Master RPS: 811.73

  Branch p99: 1.69 ms
  Master p99: 1.68 ms

  Branch RSS: 90.6 MB
  Master RSS: 89.4 MB

liquid:
  We don't see a significant change in liquid performance.

  Branch parse & render: 29.041 I/s
  Master parse & render: 29.211 I/s
2022-05-09 08:45:24 -04:00
Jean Boussier 4a2b5102c1 Expose `rb_hash_new_capa(long)`
[Feature #18683]

This allows parsers and similar libraries to create Hashes of
a certain capacity in advance. It's useful when the key and values
are streamed, hence `bulk_insert()` can't be used.
2022-04-26 16:12:47 +02:00
卜部昌平 dcc42d4688 [Doc] correct my understanding about nonblocking mode
I was wrong.  Nonblocking mode nowadays does not interface with
IO#read.  Document updated. [ci skip]
2022-04-21 14:59:03 +09:00
Alex Matchneer dbb227d3b6
[DOC] add missing size params in fiber scheduler.h (#5441) 2022-04-14 07:34:49 +12:00
Kevin Newton 6068da8937 Finer-grained constant cache invalidation (take 2)
This commit reintroduces finer-grained constant cache invalidation.
After 8008fb7 got merged, it was causing issues on token-threaded
builds (such as on Windows).

The issue was that when you're iterating through instruction sequences
and using the translator functions to get back the instruction structs,
you're either using `rb_vm_insn_null_translator` or
`rb_vm_insn_addr2insn2` depending if it's a direct-threading build.
`rb_vm_insn_addr2insn2` does some normalization to always return to
you the non-trace version of whatever instruction you're looking at.
`rb_vm_insn_null_translator` does not do that normalization.

This means that when you're looping through the instructions if you're
trying to do an opcode comparison, it can change depending on the type
of threading that you're using. This can be very confusing. So, this
commit creates a new translator function
`rb_vm_insn_normalizing_translator` to always return the non-trace
version so that opcode comparisons don't have to worry about different
configurations.

[Feature #18589]
2022-04-01 14:48:22 -04:00
Yusuke Endoh ffc3b37f96 re.c: Add Regexp.timeout= and Regexp.timeout
[Feature #17837]
2022-03-30 16:50:46 +09:00
Nobuyoshi Nakada 69967ee64e
Revert "Finer-grained inline constant cache invalidation"
This reverts commits for [Feature #18589]:
* 8008fb7352
  "Update formatting per feedback"
* 8f6eaca2e1
  "Delete ID from constant cache table if it becomes empty on ISEQ free"
* 629908586b
  "Finer-grained inline constant cache invalidation"

MSWin builds on AppVeyor have been crashing since the merger.
2022-03-25 20:29:09 +09:00
Kevin Newton 629908586b Finer-grained inline constant cache invalidation
Current behavior - caches depend on a global counter. All constant mutations cause caches to be invalidated.

```ruby
class A
  B = 1
end

def foo
  A::B # inline cache depends on global counter
end

foo # populate inline cache
foo # hit inline cache

C = 1 # global counter increments, all caches are invalidated

foo # misses inline cache due to `C = 1`
```

Proposed behavior - caches depend on name components. Only constant mutations with corresponding names will invalidate the cache.

```ruby
class A
  B = 1
end

def foo
  A::B # inline cache depends constants named "A" and "B"
end

foo # populate inline cache
foo # hit inline cache

C = 1 # caches that depend on the name "C" are invalidated

foo # hits inline cache because IC only depends on "A" and "B"
```

Examples of breaking the new cache:

```ruby
module C
  # Breaks `foo` cache because "A" constant is set and the cache in foo depends
  # on "A" and "B"
  class A; end
end

B = 1
```

We expect the new cache scheme to be invalidated less often because names aren't frequently reused. With the cache being invalidated less, we can rely on its stability more to keep our constant references fast and reduce the need to throw away generated code in YJIT.
2022-03-24 09:14:38 -07:00
Peter Zhu a51f30c671 [Feature #18634] Implement Arrays on Variable Width Allocation
This commit implements arrays on Variable Width Allocation. This allows
longer arrays to be embedded (i.e. contents directly follow the object
header) which improves performance through better cache locality.
2022-03-22 09:42:39 -04:00
Nobuyoshi Nakada f91ea23324
Honor if `_Bool` is available
`AC_HEADER_STDBOOL` rejects stdbool.h in c2x, which is not
conforming to C99.
2022-03-16 17:50:13 +09:00
Peter Zhu 1289721892 Wrap ruby_abi_version in `extern "C"` for C++
Make ruby_abi_version have C linkage so that the symbol can be found
in the shared object.
2022-03-01 13:38:48 -05:00
Peter Zhu 25ad9eabc7 Only define RUBY_DLN_CHECK_ABI when supported 2022-03-01 09:44:39 -05:00
Lars Kanis eebc24218a [DOC] Fix reference in rb_enc_associate() description 2022-03-01 10:11:59 +09:00
Lars Kanis 1a20bb1c98 [DOC] Fix function name in example 2022-03-01 09:59:12 +09:00
Peter Zhu 3df16924b4 [Feature #18249] Implement ABI checking
Header file include/ruby/internal/abi.h contains RUBY_ABI_VERSION which
is the ABI version. This value should be bumped whenever an ABI
incompatible change is introduced.

When loading dynamic libraries, Ruby will compare its own
`ruby_abi_version` and the `ruby_abi_version` of the loaded library. If
these two values don't match it will raise a `LoadError`. This feature
can also be turned off by setting the environment variable
`RUBY_RUBY_ABI_CHECK=0`.

This feature will prevent cases where previously installed native gems
fail in unexpected ways due to incompatibility of changes in header
files. This will force the developer to recompile their gems to use the
same header files as the built Ruby.

In Ruby, the ABI version is exposed through
`RbConfig::CONFIG["ruby_abi_version"]`.
2022-02-22 09:55:21 -05:00
Nobuyoshi Nakada 7470780058 Check if `__assume` is supported 2022-02-19 23:32:52 +09:00
Nobuyoshi Nakada 131154f878 Define `HAVE___BUILTIN_UNREACHABLE` instead of `UNREACHABLE`
`UNREACHABLE` in ruby/internal/has/builtin.h is only used as just
a flag now, and redefined in ruby/backward/2/assume.h then.
2022-02-19 23:32:52 +09:00
Nobuyoshi Nakada 59a91f229b
Mark `rb_clear_constant_cache` as internal use only
In the past, many internal functions are declared in intern.h
under include/ruby directory, because there were no headers for
internal use.
2022-01-20 13:54:37 +09:00
Yuta Saito 528344b8de include/ruby/win32.h: explicitly define HAVE_SHUTDOWN
Configuration for mingw32 can't detect 'shutdown' due to wrong -l
option even though it's available (this has been going on for a while,
and it needs to be fixed).
In this situation, include/ruby/missing.h declares a stub shutdown
function since 7ee786388a, and another shutdown decl is came from
system header. They are incompatible at stdcall attribute, so it
causes compilation failure.
This change defines a HAVE_SHUTDOWN to guard a newly introduced stub
decl in include/ruby/missing.h
2022-01-19 17:52:19 +09:00
Yuta Saito 8c21701968 include/ruby/io.h: use 0 as POLLPRI when no support for it
0x003 is not suitable as a bit mask, and it's ok just to be 0 to avoid
setting unsupported bit.
2022-01-19 13:19:58 +09:00
Yuta Saito 50f1468bfd [wasm] include/ruby/io.h: define RB_WAITFD_PRI by ourselves for wasi
RB_WAITFD_PRI uses POLLPRI for other platforms, but wasi-libc doesn't
have POLLPRI for now.
2022-01-19 11:19:06 +09:00
Yuta Saito 420622b5a7 [wasm] add no thread variant for freestanding environment
This implementation does nothing around preemptive context switching
because there is no native thread.
2022-01-19 11:19:06 +09:00
Yuta Saito 7ee786388a [wasm] wasm/missing.{c,h}: add missing libc stubs for wasi-libc 2022-01-19 11:19:06 +09:00
Jeremy Evans e7b4abf384 Don't assume __builtin_bswap32 and __builtin_bswap64 are defined on OpenBSD
At least OpenBSD/sparc64 doesn't appear to define them, and possibly
some other OpenBSD GCC platforms don't (most OpenBSD platforms have
already switched to clang).
2022-01-18 11:40:13 -08:00
Peter Zhu ffda21b7ba [Feature #18491] Drop support for HP-UX
IA64 support was dropped in ticket #15894, so we can drop support for
HP-UX.
2022-01-18 09:52:15 -05:00
Yuta Saito 6729258839
include/ruby/win32.h: define HAVE_X for the missing prototypes (#5456) 2022-01-18 19:08:07 +09:00
Nobuyoshi Nakada 9fa9cf4006 Suppress possible loss of data warnings 2022-01-14 13:46:12 +09:00
Nobuyoshi Nakada d1a55851e8
[DOC] Fix a typo in a doc 2022-01-13 11:32:35 +09:00
Peter Zhu 98fb0ab60e Enable Variable Width Allocation by default 2022-01-12 12:00:55 -05:00
Peter Zhu 2d81a718ec Make embedded string length a long for VWA
A short (2 bytes) will cause unaligned struct accesses when strings are
used as a buffer to directly store binary data.
2022-01-12 12:00:55 -05:00
Peter Zhu 33cc8816be Revert "Enable Variable Width Allocation by default"
This reverts commit c365c5921e.
2022-01-08 15:07:57 -05:00
Peter Zhu bc643bbe2e Use unsigned short for length of embedded strings 2022-01-07 15:48:06 -05:00
Peter Zhu c365c5921e Enable Variable Width Allocation by default 2022-01-07 13:27:13 -05:00
Peter Zhu aeb344e65c Revert "Enable Variable Width Allocation by default"
This reverts commit d4a95428bb.
2022-01-06 16:47:49 -05:00
Peter Zhu d4a95428bb Enable Variable Width Allocation by default 2022-01-06 14:33:35 -05:00
Nobuyoshi Nakada 8727161fcf
Flush deprecation declarations for versions older than 3.0 2021-12-30 18:52:04 +09:00
Nobuyoshi Nakada a90d188b57 Remove declarations of deprecated functions 2021-12-30 15:33:40 +09:00
U.Nakamura 4e007d705c Fix some bornheads 2021-12-27 17:15:09 +09:00
U.Nakamura 9790f54bff Call FlushInstrucitonCache() when PROT_EXEC is specified to mprotect 2021-12-27 16:38:29 +09:00
U.Nakamura 85a426dc86 Tiny mmap emulation for Windows
- prerequisite of supporting YJIT with VC++.
- note that now can specfily `--yjit` on mswin64, but not enabled
  YJIT'ed code because of YJIT requires `OPT_DIRECT_THREADED_CODE`
  or `OPT_CALL_THREADED_CODE` in `rb_yjit_compile_iseq`.
2021-12-27 15:56:23 +09:00
Nobuyoshi Nakada 7c738ce5e6
Remove deprecate rb_cData [Bug #18433]
Also enable the warning for T_DATA allocator.
2021-12-26 23:28:54 +09:00