1
0
Fork 0
mirror of https://github.com/rubyjs/mini_racer synced 2023-03-27 23:21:28 -04:00
Commit graph

348 commits

Author SHA1 Message Date
Gerhard Schlager
3d110768ee
Fix GitHub Actions and add tests for mutable strings ()
* Fix GitHub Actions

* Disable tests with `musl` for arm64 because there's no `libv8-node` gem for aarch64-linux-musl at the moment
* Fix tests on older Ruby versions by running `gem update --system`
* Removes macOS 10.15 (it will be unsupported by 2022-08-30 anyway)
* Adds macOS 12 to the matrix
* Run TruffleRuby job on macOS as well
* Use `ruby/setup-ruby` action where possible and update `actions/checkout` to v3
* Run tests for pull requests

* Raise sleep duration in tests to fix CI failures on macOS

* Add tests for mutable string arguments and return values
2022-07-22 08:45:20 +10:00
Brandon Fish
e0f5a7ac66
FEATURE: Implement MiniRacer for TruffleRuby () 2022-07-21 15:02:32 +10:00
Jun Jiang
7419fd154e
fix an incorrect syntax () 2022-03-22 15:45:40 +11:00
Sam Saffron
4414ea40f9
hide all libv8 symbols on ELF targets
This gives a nice binary size reduction and may allow us to eliminate
the mini_racer_loader shim:

         text           data    bss
before:  63987419       718108  110676
 after:  56535503       454196  110676

append_ldflags is available in Ruby 2.3+ mkmf.rb, allowing us
to probe for supported LDFLAGS without extra conditionals.
2022-02-24 11:26:01 +11:00
Sam Saffron
9cf4ed6d92
Ruby internals are optimized for common encodings such as UTF-8,
whereas rb_enc_find requires an extra hash lookup.  That said,
I've yet to measure an improvement in current benchmarks, though
binary size is reduced:

             text          data     bss
before: 63988228         718148  110676
 after: 63987419         718108  110676
2022-02-22 15:43:35 +11:00
Sam Saffron
bdb0977d81
simplify timeout implementation
Merely closing the pipe is enough to trigger a wakeup from
IO#wait_readable, there's no need to make a write(2) syscall nor
copy data in/out of the kernel.  We'll use the Ruby 2.3+ 'foo&.method'
calls in a few places to simplify code, as well.
2022-02-22 15:41:23 +11:00
Sam Saffron
5266fec597
Snapshot: remove unused `str' arg for .dump and .size 2022-02-22 15:40:03 +11:00
Sam Saffron
8b4d03eb76
use Check_Type for type-checking
Check_Type is less code and used throughout the Ruby ecosystem and
raises TypeError on incorrect argument types.  This is a minor behavior
change as it replaces some ArgumentError exceptions with TypeError, but
is more consistent with other Ruby libraries.
2022-02-22 15:38:50 +11:00
Yuji Hanamura
493e1bc1fc
Fix typo in CHANGELOG () 2022-02-18 20:50:56 +11:00
Sebastian Cohnen
79f1379ae2
removes travis-ci.org references since it's out of service since 2021-06-15 () 2022-02-14 18:17:28 +11:00
Sebastian Cohnen
15051f2298
Readme: Add note about V8 single threaded platform mode ()
* changes link to supported Rubies to "Ruby Maintenance Branches"

This pages lists the support status of different Ruby versions
alongside with a note on the respective EOLs.

* adds note to "Fork safety" about V8 single threaded platform mode
2022-02-14 17:50:02 +11:00
Sebastian Cohnen
38820e54fd
adds Troubleshooting section to the README () 2022-02-14 17:48:59 +11:00
Sam Saffron
b8638e8899
use C++11 atomics to check for RubyVM exit
There's no need to deal with pthread_rwlock for a single
variable since we already rely on C++11 atomics elsewhere in our
code.
2022-02-11 09:28:55 +11:00
Sam Saffron
4487f11202
avoid malloc in single-ref case of free_context
Triggering an allocation inside a `free' callback doesn't help
in low memory situations; so operate directly on the ContextInfo
being freed when possible instead of creating a short-lived copy
of it.

For the `isolate_info->refs() > 1' case, we'll leak slightly
less memory by freeing the short-lived allocation in case
pthread_create(3) fails.
2022-02-11 09:24:42 +11:00
Sam Saffron
9a409cf792
use IO#wait_readable in timeout implementation
IO.select creates more garbage and gets slower on high-numbered
FDs.  IO#wait_readable can use ppoll(2) to achieve consistent
performance regardless of FD value.
2022-02-11 09:22:41 +11:00
Sebastian Cohnen
746bfddfea
adds Ruby 3.1 to CI () 2022-01-21 17:54:40 +11:00
Petrik de Heus
2b7a7e97f5
Remove duplicate changelog entry () 2022-01-17 10:55:46 +11:00
Sam Saffron
6c36b85212
Version bump and changelog 2022-01-17 10:55:07 +11:00
Sam Saffron
12a8aa9d82
avoid memory leak on exceptions when running without GVL
rb_thread_call_without_gvl may raise exceptions and prevent free(3) from
firing.  Instead of relying on malloc(3) and free(3), rely on the Ruby
GC to recover memory on exceptions.

In most cases, alloca() is used and malloc/free are avoided entirely.
alloca(0) works with all compilers tested (clang 10..12, gcc 9.3), so
there's no need to create extra branches for the rare argc == 0 case.

RB_ALLOCV_N and RB_ALLOCV_END are documented in Ruby 3.1 public headers
(while functions those macros use internally are private).  They are
used by the standard 'etc', 'date', and 'openssl' C extensions and exist
in their current ("RB_"-prefixed) form since Ruby 2.3.  The non-prefixed
variants (ALLOCV_N, ALLOCV_END) have existed since Ruby 1.9.3.
2022-01-17 10:51:07 +11:00
Sam Saffron
87309e18b7
use PRIsVALUE for rb_raise string arguments
This guards against premature GC from intermediate strings while
reducing object size for exception code paths.
2022-01-17 10:49:42 +11:00
Sam Saffron
7bf8b670c7
replace (int)RSTRING_LEN(...) with RSTRING_LENINT(...)
Casting the result of RSTRING_LEN on 64-bit long systems with 32-bit
ints can lead to truncation errors when dealing with gigantic strings.
RSTRING_LENINT was introduced in Ruby 1.9.2 to avoid this problem, so
make use of it.  It's used by by several standard extensions (openssl,
zlib) and expected to remain part of the supported Ruby C API.
2022-01-17 10:48:18 +11:00
Sam Saffron
289587a087
Fix clang build for Ruby 2.6
While RUBY_METHOD_FUNC causes problems with newer Rubies, it's still
needed under Ruby 2.6 with clang.  We'll define our own macro to
make it a no-op under Ruby 2.7+.

Tested with clang 10.0.0-4ubuntu1, 11.0.0-2~ubuntu20.04.1, and
12.0.0-3ubuntu1~20.04.4 on Ubuntu 20.04.3 LTS (x86-64).

Fixes: 7a16ef8120 ("remove RUBY_METHOD_FUNC use")
Fixes: 
2022-01-17 10:45:29 +11:00
Sam Saffron
55f6b27cfc
FIX: handle MaybeLocal being IsEmpty due to timeout exception
When raising ScriptTerminatedError due to timeout, MaybeLocal
could be empty and would core dump upon calling .ToLocalChecked.
Avoid that by checking MaybeLocal::IsEmpty before calling
ToLocalChecked and clearing the evalRes.executed flag so we
enter the exception handling branch below.
2022-01-14 12:03:03 +11:00
Sam Saffron
8dcfd4992f
re-raise Ruby exception objects as-is
In order to support exception classes which take non-String #initialize
arguments, we must not blindly call rb_raise() to create a new exception
object.  Instead, we can use rb_exc_raise() to reuse the existing
exception object.

While rb_exc_raise() isn't documented in extension.rdoc of the Ruby
source tree, it is used by several standard extensions such as
"openssl", "json", "psych", "zlib", and therefore expected to remain
supported by Ruby core developers.

Fixes 
2022-01-12 17:40:54 +11:00
Sam Saffron
9420e3c7ac
Bump version and add Changelog 2022-01-10 17:48:20 +11:00
Sam Saffron
d968ee5857
FEATURE: re-add support for single threaded platform
Previously this was removed cause V8 was lagging. Now that we have latest
v8 we can use this feature.
2022-01-10 17:21:40 +11:00
Sam Saffron
2a7c5cccaa
Version bump 2021-12-31 11:04:53 +11:00
Sam Saffron
bdeaebd8e0
add -lstdc++ for clang for non-Darwin
Tested with clang 10, 11, and 12 with ruby 3.1.0dev (master 0b999bef29).
This allows tests to run without "_ZTVN10__cxxabiv117__class_type_infoE"
errors on Ubuntu 20.04.3 Linux x86_64
2021-12-30 11:41:06 +11:00
Sam Saffron
1bd82a9884
use CXXFLAGS for C++ compiler
A common mistake, the "CPP" in "CPPFLAGS" is for "C pre-processor"
and most of these options are intended for the (C++) compiler,
not the preprocessor.
2021-12-30 11:38:48 +11:00
Sam Saffron
8550bb33dc
drop rb_gc_force_recycle use
It's deprecated in Ruby 3.1, and is probably irrelevant compared
to all the existing allocation noise running other Ruby code.
2021-12-30 11:36:39 +11:00
Sam Saffron
feb8dc4cbf
DEV: test_concurrent_access causing segfaults
In Ruby <=2.7, SecureRandom.hex lazily defined `gen_random'.
While the method definition itself was protected by a mutex,
another thread calling `gen_random' did not take the mutex so
it would attempt to call the method while another method was
still defining it.

Ruby 3.0+ has commit 475c8701d74ebebe (Make SecureRandom support
Ractor, 2020-09-04) which also made it thread-safe in addition
to being Ractor-safe.
2021-12-10 15:28:37 +11:00
Marek de Heus
81f30046d7
Add most important change in 0.5.0 to changelog. () 2021-12-08 17:02:39 +11:00
Sam Saffron
0752264620
rb_heap_snapshot: fix memory leak from fdopen
The result of fdopen(3) must be matched with fclose(3) to
avoid memory leaks.  However, fclose(3) has the side-effect
of closing the underlying FD behind Ruby's back (which would
corrupt Ruby's internals and cause problems for the remainder
of the process lifetime).

While one could dup(fptr->fd) to fdopen+fclose the resulting fd,
it would cause problems on FD-constrained systems.  Since
GetChunkSize() is available and returns a reasonable value
(64K), the buffering of fwrite(3) is unnecessary and we can
safely use write(2) without performance loss.

So use unbuffered write(2) and perhaps prepare us for better
error reporting in a future change.

I've verified WriteAsciiChunk is indeed receiving the requested
64K (or close to it) in nearly all cases, so excessive syscalls
should not be a problem.
2021-12-08 16:17:36 +11:00
Sam Saffron
2725152c9d
ExternalFunction: convert from T_DATA to T_OBJECT
There's no need to rely on malloc for anything for class since
it doesn't store anything C-specific (everything is in ivars).
2021-12-08 16:14:05 +11:00
Sam Saffron
9fcb481f1b
Isolate: convert to TypedData
This is the least straightforward of the TypedData conversions
due to a possible bugfix in rb_context_create_isolate_value.

I believe the original call to Data_Wrap_Struct from
rb_context_create_isolate_value intentionally omitted the dmark
callback as a possible optimization.  It's no longer possible to
have a one-off definition with TypedData.  I also suspect there
were cases where the original code would be unsafe if the
original Isolate Ruby object died before the Context.

In any case, the performance cost of an extra GC mark call is
probably negligible, here; and the safest course of action is
to always mark a data type consistently.
2021-12-08 16:12:12 +11:00
Sam Saffron
23105286d0
Snapshot: convert to TypedData
Another straightforward conversion for memsize reporting,
type-safety, and reducing LoC in the alloc callback.
2021-12-08 16:07:00 +11:00
Sam Saffron
bae435c44f
Context: convert to TypedData
TypedData allows memsize reporting and adds some extra
type-safety checks.  Furthermore, TypedData_Make_Struct saves
us several lines of code in the allocate() function.
2021-12-08 16:02:44 +11:00
Sam Saffron
67c72acf7b
mark several C functions as static
These functions don't appear to be used outside of
mini_racer_extension.cc, so lets not pollute symbol tables or
confuse future readers with unnecessary visibility.
2021-12-08 15:54:06 +11:00
Sam Saffron
7a16ef8120
remove RUBY_METHOD_FUNC use
This was causing deprecation warnings from ANYARGS usage
and no longer necessary since Ruby 1.8+, at least.  It's
not used by any of the core *.c nor ext/ extensions in
the C ruby source tree, and I've rarely seen it used in
3rd-party C extensions.
2021-12-03 15:54:23 +11:00
Sam Saffron
e9b2adae10
extconf: add-fms-extensions for clang
The ruby/internal/attr/noreturn.h header of Ruby 3.0+ favors
using __has_declspec_attribute and __declspec(noreturn) over
other options (e.g. __attribute__((__noreturn__)) for gcc) i
available.

gcc (9.3.0) does not currently implement
__has_declspec_attribute and Ruby headers will use the
gcc-specific __attribute__((__noreturn__)).

clang (10.0.0) implements __has_declspec_attribute and Ruby
headers will favor use of __declspec, however __declspec itself
is only available via -fms-extensions or -fdeclspec in clang.

The -fms-extensions flag was chosen over -fdeclspec for
compatibility with gcc, as gcc only implements the former.
2021-12-03 15:53:30 +11:00
Sam Saffron
d9f890c928
Bump version 2021-11-11 17:45:18 +11:00
Sam Saffron
33e90ab36c
Avoid compile warnings
Prepare for pre-release
2021-11-03 15:03:47 +11:00
Loic Nageleisen
8bd860bde9
Update to use libv8-node 16.x ()
* Update to use libv8-node 16.3.0

Based on V8 9.0, his is the new LTS, node 15 now being unsupported. It
notably introduces single threaded mode.

Requiring c++14 is apparently the only change needed for this major. A
separate PR will add a more helpful install time check for compiler
requirements.

* Disable pointer compression

Node 16.4.0 introduced new cage flags for the experimental pointer
compression stuff. Unfortunately something fails and none of them are
set which causes the build to bail out because of the inconsistency.

* Update to use libv8-node 16.10.0
2021-10-31 22:01:08 +11:00
Sam Saffron
6c7abc4791
FIX: use rb_str_intern for symbol support
This avoids leaking symbols cause rb_inter_str never releases memory.
2021-08-18 16:42:46 +10:00
Sebastian Cohnen
05c27e8e54
DEV: bump required ruby version to >= 2.6 ()
* bump required ruby version to 2.6
* removes Ruby 2.5 from CI
2021-07-12 16:09:42 +10:00
hackmud-dtr
496f829f89
Fix sign-extension in Isolate Data ()
C++ will 'promote' a bitfield member that is narrower than an int into an int on arithmetic, leading to sign extension when converted back to a wider type.
2021-07-07 12:29:17 +10:00
seanmakesgames
50c36648b5
False positive on OOM error ()
gc callback can happen between init and set
this causes a confusing OOM crash because max mem is 0 at this point, so if the callback is hit, then the isolate will terminate no matter what.

Co-authored-by: nightpool <nightpool@users.noreply.github.com>
2021-07-06 14:13:12 +10:00
Olle Jonsson
7de7a90fa5
CI: Attempt to use rvm-installed Bundler, RubyGems ()
This is an attempt to make the CI configuration smaller, more confident. I am guessing that we are not relying on Bundler 1.x-specific behavior, so this commit is a try-out of that.
2021-06-04 17:32:16 +10:00
Olle Jonsson
dbf13aac04
gemspec: Drop configuration for executables ()
This gem exposes 0 executables.
2021-06-04 17:05:43 +10:00
Olle Jonsson
ecacd2054b
CI: Drop 2.4 from the build matrix ()
The error message in the build was: 

    mini_racer was resolved to 0.4.0, which depends on
      Ruby (>= 2.5)
2021-06-04 17:05:08 +10:00