Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into Ractor-Local-GC-v…
Browse files Browse the repository at this point in the history
…ersion-3
  • Loading branch information
rm155 committed Oct 23, 2024
2 parents 4f8ee4e + 5460d5b commit cd17499
Show file tree
Hide file tree
Showing 34 changed files with 462 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup/directories/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ runs:
path: ${{ inputs.srcdir }}
fetch-depth: ${{ inputs.fetch-depth }}

- uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
- uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ${{ inputs.srcdir }}/.downloaded-cache
key: downloaded-cache
Expand Down
17 changes: 9 additions & 8 deletions .github/actions/setup/macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ runs:
- name: Set ENV
shell: bash
run: |
for lib in gmp; do
ruby_configure_args="${ruby_configure_args:+$ruby_configure_args }--with-${lib%@*}-dir=$(brew --prefix $lib)"
done
for lib in openssl@3; do
CONFIGURE_ARGS="${CONFIGURE_ARGS:+$CONFIGURE_ARGS }--with-${lib%@*}-dir=$(brew --prefix $lib)"
done
echo ruby_configure_args="${ruby_configure_args}" >> $GITHUB_ENV
echo CONFIGURE_ARGS="${CONFIGURE_ARGS}" >> $GITHUB_ENV
dir_config() {
local args=() lib var="$1"; shift
for lib in "$@"; do
args+="--with-${lib%@*}-dir=$(brew --prefix $lib)"
done
echo "$var=${args[*]}" >> $GITHUB_ENV
}
dir_config ruby_configure_args gmp
dir_config CONFIGURE_ARGS openssl@3
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ jobs:
run: sudo rm /usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb

- name: Initialize CodeQL
uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
category: '/language:${{ matrix.language }}'
upload: False
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
continue-on-error: true

- name: Upload SARIF
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
sarif_file: sarif-results/${{ matrix.language }}.sarif
continue-on-error: true
5 changes: 4 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
include:
- test_task: check
os: macos-14
- test_task: check
os: macos-14
configure_args: '--with-gcc=gcc-14'
- test_task: test-all
test_opts: --repeat-count=2
os: macos-14
Expand Down Expand Up @@ -89,7 +92,7 @@ jobs:
continue-on-error: true

- name: Run configure
run: ../src/configure -C --disable-install-doc ${ruby_configure_args}
run: ../src/configure -C --disable-install-doc ${ruby_configure_args} ${{ matrix.configure_args }}

- run: make prepare-gems
if: ${{ matrix.test_task == 'test-bundled-gems' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: 'Upload to code-scanning'
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
sarif_file: results.sarif
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4076,7 +4076,8 @@ AS_CASE(["$target_os"],
RUBY_APPEND_OPTION(CFLAGS, -pipe)
],
[darwin*], [
RUBY_APPEND_OPTION(CFLAGS, -pipe)
RUBY_TRY_CFLAGS(-pipe, [pipe_opt=yes], [pipe_opt=no])
AS_IF([test $pipe_opt = yes], [RUBY_APPEND_OPTION(CFLAGS, -pipe)])
AC_MSG_CHECKING([whether Security framework is needed])
AC_COMPILE_IFELSE([
AC_LANG_BOOL_COMPILE_TRY([
Expand Down
76 changes: 58 additions & 18 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ typedef struct gc_function_map {
unsigned long long (*get_total_time)(void *objspace_ptr);
size_t (*gc_count)(void *objspace_ptr);
VALUE (*latest_gc_info)(void *objspace_ptr, VALUE key);
size_t (*stat)(void *objspace_ptr, VALUE hash_or_sym);
size_t (*stat_heap)(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym);
VALUE (*stat)(void *objspace_ptr, VALUE hash_or_sym);
VALUE (*stat_heap)(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym);
// Miscellaneous
void *(*ractor_of_objspace)(void *objspace_ptr);
void *(*local_gate_of_objspace)(void *objspace_ptr);
Expand Down Expand Up @@ -3661,7 +3661,17 @@ gc_count(rb_execution_context_t *ec, VALUE self)
VALUE
rb_gc_latest_gc_info(VALUE key)
{
return rb_gc_impl_latest_gc_info(rb_gc_get_objspace(), key);
if (!SYMBOL_P(key) && !RB_TYPE_P(key, T_HASH)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}

VALUE val = rb_gc_impl_latest_gc_info(rb_gc_get_objspace(), key);

if (val == Qundef) {
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
}

return val;
}

static VALUE
Expand All @@ -3670,25 +3680,40 @@ gc_stat(rb_execution_context_t *ec, VALUE self, VALUE arg) // arg is (nil || has
if (NIL_P(arg)) {
arg = rb_hash_new();
}
else if (!RB_TYPE_P(arg, T_HASH) && !SYMBOL_P(arg)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}

size_t val = rb_gc_impl_stat(rb_gc_get_objspace(), arg);
VALUE ret = rb_gc_impl_stat(rb_gc_get_objspace(), arg);

if (SYMBOL_P(arg)) {
return SIZET2NUM(val);
}
else {
return arg;
if (ret == Qundef) {
GC_ASSERT(SYMBOL_P(arg));

rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(arg));
}

return ret;
}

size_t
rb_gc_stat(VALUE key)
rb_gc_stat(VALUE arg)
{
if (SYMBOL_P(key)) {
return rb_gc_impl_stat(rb_gc_get_objspace(), key);
if (!RB_TYPE_P(arg, T_HASH) && !SYMBOL_P(arg)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}

VALUE ret = rb_gc_impl_stat(rb_gc_get_objspace(), arg);

if (ret == Qundef) {
GC_ASSERT(SYMBOL_P(arg));

rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(arg));
}

if (SYMBOL_P(arg)) {
return NUM2SIZET(ret);
}
else {
rb_gc_impl_stat(rb_gc_get_objspace(), key);
return 0;
}
}
Expand All @@ -3700,14 +3725,29 @@ gc_stat_heap(rb_execution_context_t *ec, VALUE self, VALUE heap_name, VALUE arg)
arg = rb_hash_new();
}

size_t val = rb_gc_impl_stat_heap(rb_gc_get_objspace(), heap_name, arg);

if (SYMBOL_P(arg)) {
return SIZET2NUM(val);
if (NIL_P(heap_name)) {
if (!RB_TYPE_P(arg, T_HASH)) {
rb_raise(rb_eTypeError, "non-hash given");
}
}
else if (FIXNUM_P(heap_name)) {
if (!SYMBOL_P(arg) && !RB_TYPE_P(arg, T_HASH)) {
rb_raise(rb_eTypeError, "non-hash or symbol given");
}
}
else {
return arg;
rb_raise(rb_eTypeError, "heap_name must be nil or an Integer");
}

VALUE ret = rb_gc_impl_stat_heap(rb_gc_get_objspace(), heap_name, arg);

if (ret == Qundef) {
GC_ASSERT(SYMBOL_P(arg));

rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(arg));
}

return ret;
}

static VALUE
Expand Down
41 changes: 22 additions & 19 deletions gc/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -8200,7 +8200,7 @@ gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const unsigned
hash = hash_or_key;
}
else {
rb_raise(rb_eTypeError, "non-hash or symbol given");
rb_bug("gc_info_decode: non-hash or symbol given");
}

if (NIL_P(sym_major_by)) {
Expand Down Expand Up @@ -8288,8 +8288,9 @@ gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const unsigned
SET(retained_weak_references_count, LONG2FIX(objspace->profile.retained_weak_references_count));
#undef SET

if (!NIL_P(key)) {/* matched key should return above */
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
if (!NIL_P(key)) {
// Matched key should return above
return Qundef;
}

return hash;
Expand Down Expand Up @@ -8415,7 +8416,7 @@ ns_to_ms(uint64_t ns)
return ns / (1000 * 1000);
}

size_t
VALUE
rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
{
rb_objspace_t *objspace = objspace_ptr;
Expand All @@ -8430,7 +8431,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
key = hash_or_sym;
}
else {
rb_raise(rb_eTypeError, "non-hash or symbol given");
rb_bug("non-hash or symbol given");
}

rb_objspace_coordinator_t *objspace_coordinator = rb_get_objspace_coordinator();
Expand All @@ -8442,7 +8443,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)

#define SET(name, attr) \
if (key == gc_stat_symbols[gc_stat_sym_##name]) \
return attr; \
return SIZET2NUM(attr); \
else if (hash != Qnil) \
rb_hash_aset(hash, gc_stat_symbols[gc_stat_sym_##name], SIZET2NUM(attr));

Expand Down Expand Up @@ -8496,8 +8497,9 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
#endif /* RGENGC_PROFILE */
#undef SET

if (!NIL_P(key)) { /* matched key should return above */
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
if (!NIL_P(key)) {
// Matched key should return above
return Qundef;
}

#if defined(RGENGC_PROFILE) && RGENGC_PROFILE >= 2
Expand All @@ -8511,7 +8513,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
}
#endif

return 0;
return hash;
}

enum gc_stat_heap_sym {
Expand Down Expand Up @@ -8545,12 +8547,12 @@ setup_gc_stat_heap_symbols(void)
}
}

static size_t
static VALUE
stat_one_heap(rb_heap_t *heap, VALUE hash, VALUE key)
{
#define SET(name, attr) \
if (key == gc_stat_heap_symbols[gc_stat_heap_sym_##name]) \
return attr; \
return SIZET2NUM(attr); \
else if (hash != Qnil) \
rb_hash_aset(hash, gc_stat_heap_symbols[gc_stat_heap_sym_##name], SIZET2NUM(attr));

Expand All @@ -8564,14 +8566,15 @@ stat_one_heap(rb_heap_t *heap, VALUE hash, VALUE key)
SET(total_freed_objects, heap->total_freed_objects);
#undef SET

if (!NIL_P(key)) { /* matched key should return above */
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
if (!NIL_P(key)) {
// Matched key should return above
return Qundef;
}

return 0;
return hash;
}

size_t
VALUE
rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym)
{
rb_objspace_t *objspace = objspace_ptr;
Expand All @@ -8580,7 +8583,7 @@ rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym)

if (NIL_P(heap_name)) {
if (!RB_TYPE_P(hash_or_sym, T_HASH)) {
rb_raise(rb_eTypeError, "non-hash given");
rb_bug("non-hash given");
}

for (int i = 0; i < HEAP_COUNT; i++) {
Expand Down Expand Up @@ -8614,14 +8617,14 @@ rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym)
return stat_one_heap(heap, hash_or_sym, Qnil);
}
else {
rb_raise(rb_eTypeError, "non-hash or symbol given");
rb_bug("non-hash or symbol given");
}
}
else {
rb_raise(rb_eTypeError, "heap_name must be nil or an Integer");
rb_bug("heap_name must be nil or an Integer");
}

return 0;
return hash_or_sym;
}

/* I could include internal.h for this, but doing so undefines some Array macros
Expand Down
4 changes: 2 additions & 2 deletions gc/gc_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ GC_IMPL_FN bool rb_gc_impl_get_measure_total_time(void *objspace_ptr);
GC_IMPL_FN unsigned long long rb_gc_impl_get_total_time(void *objspace_ptr);
GC_IMPL_FN size_t rb_gc_impl_gc_count(void *objspace_ptr);
GC_IMPL_FN VALUE rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE key);
GC_IMPL_FN size_t rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym);
GC_IMPL_FN size_t rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym);
GC_IMPL_FN VALUE rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym);
GC_IMPL_FN VALUE rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym);
// Miscellaneous
GC_IMPL_FN void *rb_gc_impl_ractor_of_objspace(void *objspace_ptr);
GC_IMPL_FN void *rb_gc_impl_local_gate_of_objspace(void *objspace_ptr);
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/internal/special_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ RBIMPL_ATTR_ARTIFICIAL()
static inline bool
RB_SPECIAL_CONST_P(VALUE obj)
{
return RB_IMMEDIATE_P(obj) || obj == RUBY_Qfalse;
return (obj == RUBY_Qfalse) || RB_IMMEDIATE_P(obj);
}

RBIMPL_ATTR_CONST()
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def use_system_gems?
end

def mkdir_p(path)
SharedHelpers.filesystem_access(path, :write) do |p|
SharedHelpers.filesystem_access(path, :create) do |p|
FileUtils.mkdir_p(p)
end
end
Expand Down
Loading

0 comments on commit cd17499

Please sign in to comment.