Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ jit:
- any-glob-to-any-file:
# JIT sources (Rust + C + Ruby)
- 'jit/**'
- 'yjit/**'
- 'zjit/**'
# All of {y,z}jit/ except the generated cruby_bindings.inc.rs files.
# `!(...)` can't span a `/`, so each pair splits the tree into
# non-Rust files and Rust files not named cruby_bindings.inc.rs;
# their union is everything but the bindings file.
- 'yjit/**/!(*.rs)'
- 'yjit/**/!(cruby_bindings.inc).rs'
- 'zjit/**/!(*.rs)'
- 'zjit/**/!(cruby_bindings.inc).rs'
- 'jit.c'
- 'jit_hook.rb'
- 'jit_undef.rb'
Expand Down
33 changes: 19 additions & 14 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct objspace {

uintptr_t vo_bit_log_region_size;
uintptr_t vo_bit_base_addr;
size_t max_non_los_default_alloc_bytes;
};

#define OBJ_FREE_BUF_CAPACITY 128
Expand Down Expand Up @@ -110,6 +111,7 @@ RB_THREAD_LOCAL_SPECIFIER VALUE marking_parent_object;
#include <pthread.h>

#define MMTK_ALLOCATION_SEMANTICS_DEFAULT 0
#define MMTK_ALLOCATION_SEMANTICS_LOS 2

static inline VALUE rb_mmtk_call_object_closure(VALUE obj, bool pin);

Expand Down Expand Up @@ -604,6 +606,7 @@ rb_gc_impl_objspace_init(void *objspace_ptr)

objspace->vo_bit_log_region_size = mmtk_get_vo_bit_log_region_size();
objspace->vo_bit_base_addr = mmtk_get_vo_bit_base_addr();
objspace->max_non_los_default_alloc_bytes = mmtk_max_non_los_default_alloc_bytes();
}

void
Expand Down Expand Up @@ -670,8 +673,6 @@ void rb_gc_impl_set_params(void *objspace_ptr) { }

static VALUE gc_verify_internal_consistency(VALUE self) { return Qnil; }

#define MMTK_MAX_OBJ_SIZE 1024

static inline size_t
rb_mmtk_align_obj_size(size_t object_size)
{
Expand All @@ -685,12 +686,12 @@ rb_gc_impl_zjit_new_obj_fastpath(void *objspace_ptr, size_t alloc_size, VALUE fl
#if USE_ZJIT && RB_GC_OBJ_SUFFIX_SIZE == 0
struct objspace *objspace = objspace_ptr;

if (alloc_size > MMTK_MAX_OBJ_SIZE) return false;

size_t total_size = rb_mmtk_align_obj_size(alloc_size + sizeof(VALUE) + RB_GC_OBJ_SUFFIX_SIZE);
size_t object_size = total_size - sizeof(VALUE) - RB_GC_OBJ_SUFFIX_SIZE;
size_t value_size_shift = sizeof(VALUE) == 8 ? 3 : 2;

if (total_size > objspace->max_non_los_default_alloc_bytes) return false;

struct rb_gc_zjit_mmtk_new_obj_fastpath mmtk_fastpath = {
objspace,
offsetof(struct objspace, total_allocated_objects),
Expand Down Expand Up @@ -730,7 +731,6 @@ rb_gc_impl_init(void)
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_SIZE")), SIZET2NUM(sizeof(struct RBasic) + sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX])));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RBASIC_SIZE")), SIZET2NUM(sizeof(struct RBasic)));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_OVERHEAD")), INT2NUM(0));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVARGC_MAX_ALLOCATE_SIZE")), LONG2FIX(MMTK_MAX_OBJ_SIZE));
// TODO: correctly set RVALUE_OLD_AGE when we have generational GC support
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_OLD_AGE")), INT2FIX(0));
OBJ_FREEZE(gc_constants);
Expand Down Expand Up @@ -960,22 +960,27 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
struct objspace *objspace = objspace_ptr;
struct MMTk_ractor_cache *ractor_cache = cache_ptr;

if (alloc_size == 0 || alloc_size > MMTK_MAX_OBJ_SIZE) {
rb_bug("rb_gc_impl_new_obj: allocation size too large (size=%"PRIuSIZE")", alloc_size);
if (alloc_size == 0) {
rb_bug("rb_gc_impl_new_obj: allocation size out of range (size=%"PRIuSIZE")", alloc_size);
}

// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RB_GC_OBJ_SUFFIX_SIZE)]
size_t total_size = rb_mmtk_align_obj_size(alloc_size + sizeof(VALUE) + RB_GC_OBJ_SUFFIX_SIZE);
size_t object_size = total_size - sizeof(VALUE) - RB_GC_OBJ_SUFFIX_SIZE;
MMTk_AllocationSemantics semantics = total_size > objspace->max_non_los_default_alloc_bytes
? MMTK_ALLOCATION_SEMANTICS_LOS
: MMTK_ALLOCATION_SEMANTICS_DEFAULT;
*actual_alloc_size = object_size;

if (objspace->gc_stress) {
mmtk_handle_user_collection_request(ractor_cache, false, false);
}

VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, total_size, MMTk_MIN_OBJ_ALIGN);
VALUE *alloc_obj = semantics == MMTK_ALLOCATION_SEMANTICS_DEFAULT
? (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, total_size, MMTk_MIN_OBJ_ALIGN)
: NULL;
if (!alloc_obj) {
alloc_obj = mmtk_alloc(ractor_cache->mutator, total_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
alloc_obj = mmtk_alloc(ractor_cache->mutator, total_size, MMTk_MIN_OBJ_ALIGN, 0, semantics);

// On heap exhaustion raise NoMemoryError.
if (RB_UNLIKELY(alloc_obj == NULL)) {
Expand All @@ -988,8 +993,8 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
alloc_obj[0] = flags;
alloc_obj[1] = klass;

if (ractor_cache->bump_pointer == NULL) {
mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, object_size, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
if (semantics == MMTK_ALLOCATION_SEMANTICS_LOS || ractor_cache->bump_pointer == NULL) {
mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, total_size, semantics);
}
else {
// We can use the post alloc fast path if we're using Immix bump pointer allocator
Expand All @@ -1013,7 +1018,7 @@ rb_gc_impl_obj_slot_size(VALUE obj)
size_t
rb_gc_impl_size_slot_size(void *objspace_ptr, size_t size)
{
if (size == 0 || size > MMTK_MAX_OBJ_SIZE) {
if (size == 0) {
rb_bug("rb_gc_impl_size_slot_size: size too large (size=%"PRIuSIZE")", size);
}

Expand All @@ -1023,13 +1028,13 @@ rb_gc_impl_size_slot_size(void *objspace_ptr, size_t size)
bool
rb_gc_impl_size_allocatable_p(size_t size)
{
return size <= MMTK_MAX_OBJ_SIZE;
return true;
}

size_t
rb_gc_impl_max_allocation_size(void)
{
return MMTK_MAX_OBJ_SIZE;
return SIZE_MAX;
}

// Malloc
Expand Down
2 changes: 2 additions & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void mmtk_set_gc_enabled(bool enable);

bool mmtk_gc_enabled_p(void);

size_t mmtk_max_non_los_default_alloc_bytes(void);

MMTk_Address mmtk_alloc(MMTk_Mutator *mutator,
size_t size,
size_t align,
Expand Down
8 changes: 8 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ pub extern "C" fn mmtk_gc_enabled_p() -> bool {

// =============== Object allocation ===============

#[no_mangle]
pub extern "C" fn mmtk_max_non_los_default_alloc_bytes() -> usize {
mmtk()
.get_plan()
.constraints()
.max_non_los_default_alloc_bytes
}

#[no_mangle]
pub unsafe extern "C" fn mmtk_alloc(
mutator: *mut RubyMutator,
Expand Down
7 changes: 7 additions & 0 deletions id_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ rb_managed_id_table_dup(VALUE old_table)
struct rb_id_table *old_tbl = managed_id_table_ptr(old_table);
rb_id_table_init(new_tbl, old_tbl->num + 1);
rb_id_table_foreach(old_tbl, managed_id_table_dup_i, new_tbl);
/* The table body is embedded (RUBY_TYPED_EMBEDDABLE), so old_tbl is an
* interior pointer. Keep old_table live in case dup_i triggers a GC. */
RB_GC_GUARD(old_table);
return obj;
}

Expand All @@ -422,12 +425,16 @@ void
rb_managed_id_table_foreach(VALUE table, rb_id_table_foreach_func_t *func, void *data)
{
rb_id_table_foreach(managed_id_table_ptr(table), func, data);
/* The table body is embedded (RUBY_TYPED_EMBEDDABLE), so the pointer above
* is interior. Keep table live in case func triggers a GC. */
RB_GC_GUARD(table);
}

void
rb_managed_id_table_foreach_values(VALUE table, rb_id_table_foreach_values_func_t *func, void *data)
{
rb_id_table_foreach_values(managed_id_table_ptr(table), func, data);
RB_GC_GUARD(table);
}

int
Expand Down
4 changes: 1 addition & 3 deletions lib/bundler/cli/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def run
Bundler.settings.set_command_option_if_given :path, options[:path]

definition = Bundler.definition
definition.ensure_equivalent_gemfile_and_lockfile
definition.validate_runtime!

begin
Expand All @@ -28,9 +29,6 @@ def run
not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" }
Bundler.ui.warn "Install missing gems with `bundle install`"
exit 1
elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle?
Bundler.ui.error "This bundle has been frozen, but there is no #{SharedHelpers.relative_lockfile_path} present"
exit 1
else
definition.lock(true) unless options[:"dry-run"]
Bundler.ui.info "The Gemfile's dependencies are satisfied"
Expand Down
12 changes: 0 additions & 12 deletions prism/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -17459,18 +17459,6 @@ parse_pattern_primitive(pm_parser_t *parser, pm_constant_id_list_t *captures, pm

return UP(pm_pinned_variable_node_create(parser, &operator, variable));
}
case PM_TOKEN_NUMBERED_REFERENCE: {
parser_lex(parser);
pm_node_t *variable = UP(pm_numbered_reference_read_node_create(parser, &parser->previous));

return UP(pm_pinned_variable_node_create(parser, &operator, variable));
}
case PM_TOKEN_BACK_REFERENCE: {
parser_lex(parser);
pm_node_t *variable = UP(pm_back_reference_read_node_create(parser, &parser->previous));

return UP(pm_pinned_variable_node_create(parser, &operator, variable));
}
case PM_TOKEN_PARENTHESIS_LEFT: {
bool previous_pattern_matching_newlines = parser->pattern_matching_newlines;
parser->pattern_matching_newlines = false;
Expand Down
52 changes: 52 additions & 0 deletions spec/bundler/commands/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,58 @@

bundle :check, raise_on_error: false
expect(last_command).to be_failure
expect(err).to include("Frozen mode is set, but there's no lockfile")
end

it "fails when frozen is set and the lockfile is missing a CHECKSUMS entry" do
system_gems "myrack-1.0.0", path: default_bundle_path

gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G

lockfile <<-L
GEM
remote: https://gem.repo1/
specs:
myrack (1.0.0)

PLATFORMS
#{lockfile_platforms}

DEPENDENCIES
myrack

CHECKSUMS

BUNDLED WITH
#{Bundler::VERSION}
L

bundle :check, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false
expect(exitstatus).to eq(16)
expect(err).to include("Your lockfile is missing a CHECKSUMS entry for \"myrack\", but can't be updated because frozen mode is set")
expect(out).not_to include("The Gemfile's dependencies are satisfied")
end

it "fails when frozen is set and the Gemfile has changed" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G

gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "rails"
G

bundle :check, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false
expect(exitstatus).to eq(16)
expect(err).to include("frozen mode is set")
expect(err).to include("* rails")
expect(out).not_to include("The Gemfile's dependencies are satisfied")
end

describe "when locked" do
Expand Down
1 change: 1 addition & 0 deletions test/.excludes-mmtk/TestStruct/SubStruct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude(:test_larger_than_largest_pool, "depends on max slot size")
1 change: 1 addition & 0 deletions test/.excludes-mmtk/TestStruct/TopStruct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude(:test_larger_than_largest_pool, "depends on max slot size")
7 changes: 7 additions & 0 deletions test/.excludes-mmtk/Test_StringCapacity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exclude(:test_capacity_embedded, "depends on max slot size")
exclude(:test_capacity_frozen, "depends on max slot size")
exclude(:test_capacity_fstring, "depends on max slot size")
exclude(:test_capacity_normal, "depends on max slot size")
exclude(:test_io_read, "depends on max slot size")
exclude(:test_literal_capacity, "depends on max slot size")
exclude(:test_s_new_capacity, "depends on max slot size")
4 changes: 4 additions & 0 deletions test/prism/errors/pinned_back_reference.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 in ^$&
^ expected a pattern expression after the `^` pin operator
^~ unexpected back reference, expecting end-of-input

4 changes: 4 additions & 0 deletions test/prism/errors/pinned_numbered_reference.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 in ^$1
^ expected a pattern expression after the `^` pin operator
^~ unexpected numbered reference, expecting end-of-input

13 changes: 10 additions & 3 deletions win32/rm.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if "%1" == "-n" (shift & set "dryrun=%1" & goto :optloop)
if "%1" == "-r" (shift & set "recursive=%1" & goto :optloop)
if "%1" == "--debug" (shift & set "debug=%1" & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop)
:begin
if "%1" == "" goto :EOF
if "%1" == "" exit /b %error%
set p=%1
shift
set p=%p:/=\%
Expand Down Expand Up @@ -58,7 +58,7 @@ goto :remove_end
rd /q "%p%" 2> nul && goto :remove_end

::- If matching files and directory exist, remove the files only first.
del /q "%p%" 2> nul
del /f /q "%p%" 2> nul

::- `del` exits with 0 even when nothing matched, so its result cannot
::- tell whether directories remain; check if matching entries still
Expand All @@ -73,7 +73,14 @@ goto :remove_end

::- Remove remained directories recursively.
for /D %%I in (%p%) do (
rd /s /q %%I 2> nul || call set error=%%ERRORLEVEL%%
rd /s /q %%I 2> nul
)

::- `rd /s` does not set ERRORLEVEL on failure; check what remains
::- instead. `if exist "dir\*"` is true even for an empty directory,
::- so check remaining files and directories separately.
if not exist "%p%" goto :remove_end
for %%I in (%p%) do if not exist "%%I\" set error=1
for /D %%I in (%p%) do if exist "%%I\" set error=1
:remove_end
endlocal & set "error=%error%" & goto :EOF
Loading