Commit graph

2180 commits

Author SHA1 Message Date
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
Nobuyoshi Nakada
39bc5de833
Remove tainted and trusted features
Already these had been announced to be removed in 3.2.
2021-12-26 23:28:54 +09:00
Yukihiro "Matz" Matsumoto
81c248924d
Development of 3.1.0 started. 2021-12-26 23:22:26 +09:00
Kazuhiro NISHIYAMA
04f07713d1
Fix typos [ci skip] 2021-12-25 10:33:49 +09:00
Samuel Williams
acfe2f2655
Improvements to rb_io_wait return value handling and internal implementation. (#5340) 2021-12-24 23:11:02 +13:00
Samuel Williams
bed920f073
Add fiber scheduler hooks for pread/pwrite, and add support to IO::Buffer. 2021-12-23 12:20:09 +13:00
Samuel Williams
e30920354f
Extended interface for IO::Buffer & documentation. 2021-12-22 10:57:34 +13:00
Samuel Williams
617687df09 Rename IMMUTABLE to READONLY. 2021-12-21 12:25:42 +13:00
Samuel Williams
9fbf94ff04 Improve interface for get/set/copy. 2021-12-21 12:25:42 +13:00
Samuel Williams
c86bcd434d Mark non-private mapped files as external. 2021-12-21 12:25:42 +13:00
Samuel Williams
49166fc74a Improved exception usage/classes. 2021-12-21 12:25:42 +13:00
Samuel Williams
56811617ab Improve IO::Buffer resize and introduce ownership transfer. 2021-12-20 00:17:17 +13:00
Samuel Williams
f3e30b26c5 Default size for IO::Buffer. 2021-12-19 12:25:38 +13:00
Samuel Williams
42d3231154
Introduce io_result wrapper for passing [-errno, size] in VALUE. 2021-12-18 18:19:30 +13:00
Yuta Saito
ecb2ff6050 intern/select/posix.h: remove unused parameter from rb_fd_dup
This unused parameter seems to be accidently introduced by 9e6e39c
2021-12-11 02:23:30 +09:00
Nobuyoshi Nakada
a5baf8d6bc
Revert zero-check for alloca
Something weird results in int-in-bool-context and
stringop-overflow warnings.
2021-12-10 18:39:48 +09:00
Nobuyoshi Nakada
bcc2bb28b0 Fix stack buffer overflow
https://hackerone.com/reports/1306859
2021-12-10 01:04:59 +09:00