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
15 changes: 8 additions & 7 deletions .gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ end

define print_lineno
set $cfp = $arg0
set $iseq = $cfp->iseq
set $iseq = rb_get_cfp_iseq($cfp)
set $pos = $cfp->pc - $iseq->body->iseq_encoded
if $pos != 0
set $pos = $pos - 1
Expand Down Expand Up @@ -1060,7 +1060,7 @@ define print_id
else
set $serial = (rb_id_serial_t)$id
end
if $serial && $serial <= ruby_global_symbols.last_id
if $serial && $serial < ruby_global_symbols.next_id
set $idx = $serial / ID_ENTRY_UNIT
set $ids = (struct RArray *)ruby_global_symbols.ids
set $flags = $ids->basic.flags
Expand All @@ -1083,7 +1083,7 @@ define print_id
set $aryptr = $ary->as.heap.ptr
set $arylen = $ary->as.heap.len
end
set $result = $aryptr[($serial % ID_ENTRY_UNIT) * ID_ENTRY_SIZE + $t]
set $result = $aryptr[($serial % ID_ENTRY_UNIT) + $t]
if $result != RUBY_Qnil
print_string $result
else
Expand Down Expand Up @@ -1117,16 +1117,17 @@ define rb_ps_thread
set $cfp = $ps_thread_th->ec->cfp
set $cfpend = (rb_control_frame_t *)($ps_thread_th->ec->vm_stack + $ps_thread_th->ec->vm_stack_size)-1
while $cfp < $cfpend
if $cfp->iseq
if !((VALUE)$cfp->iseq & RUBY_IMMEDIATE_MASK) && (((imemo_ifunc << RUBY_FL_USHIFT) | RUBY_T_IMEMO)==$cfp->iseq->flags & ((RUBY_IMEMO_MASK << RUBY_FL_USHIFT) | RUBY_T_MASK))
if $cfp->_iseq
set $iseq = rb_get_cfp_iseq($cfp)
if !((VALUE)$iseq & RUBY_IMMEDIATE_MASK) && (((imemo_ifunc << RUBY_FL_USHIFT) | RUBY_T_IMEMO)==$iseq->flags & ((RUBY_IMEMO_MASK << RUBY_FL_USHIFT) | RUBY_T_MASK))
printf "%d:ifunc ", $cfpend-$cfp
set print symbol-filename on
output/a $cfp->iseq.body
output/a $iseq.body
set print symbol-filename off
printf "\n"
else
if $cfp->pc
set $location = $cfp->iseq->body->location
set $location = $iseq->body->location
printf "%d:", $cfpend-$cfp
print_pathobj $location.pathobj
printf ":"
Expand Down
25 changes: 25 additions & 0 deletions benchmark/int_to_s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
prelude: |
# frozen_string_literal: true
N1 = 5
N2 = 42
N3 = 400
N5 = 12345
N10 = 1_234_567_890
N19 = 4_611_686_018_427_387_903
NEG = -1_234_567_890
BIG20 = 10 ** 19 + 12_345_678_901_234_567
BIG40 = 10 ** 39 + 123_456_789_012_345
BIG100 = 10 ** 99 + 42
benchmark:
fix_1digit: "N1.to_s"
fix_2digit: "N2.to_s"
fix_3digit: "N3.to_s"
fix_5digit: "N5.to_s"
fix_10digit: "N10.to_s"
fix_19digit: "N19.to_s"
fix_negative: "NEG.to_s"
big_20digit: "BIG20.to_s"
big_40digit: "BIG40.to_s"
big_100digit: "BIG100.to_s"
interp_id: '"id=#{N10}"'
interp_mixed: '"a=#{N2},b=#{N5},c=#{N10}"'
86 changes: 76 additions & 10 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ static const bool debug_integer_pack = (

const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";

/* Two-digit decimal lookup table. Offset 2*n holds the ASCII pair for
* n in the range 0..99. Used by both rb_fix2str in numeric.c and
* big2str_2bdigits below to emit two base-10 digits per iteration. */
const char ruby_decimal_digit_pairs[201] =
"00010203040506070809"
"10111213141516171819"
"20212223242526272829"
"30313233343536373839"
"40414243444546474849"
"50515253545556575859"
"60616263646566676869"
"70717273747576777879"
"80818283848586878889"
"90919293949596979899";

#ifndef SIZEOF_BDIGIT_DBL
# if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
# define SIZEOF_BDIGIT_DBL SIZEOF_LONG_LONG
Expand Down Expand Up @@ -4811,23 +4826,74 @@ big2str_2bdigits(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t tail
return;
p = buf;
j = sizeof(buf);
do {
BDIGIT_DBL idx = num % b2s->base;
num /= b2s->base;
p[--j] = ruby_digitmap[idx];
} while (num);
if (b2s->base == 10) {
/* Emit two decimal digits per iteration from ruby_decimal_digit_pairs.
* See the comment on the table in bignum.c near ruby_digitmap. */
while (num >= 100) {
BDIGIT_DBL idx = (num % 100) * 2;
num /= 100;
j -= 2;
p[j] = ruby_decimal_digit_pairs[idx];
p[j + 1] = ruby_decimal_digit_pairs[idx + 1];
}
if (num >= 10) {
BDIGIT_DBL idx = num * 2;
j -= 2;
p[j] = ruby_decimal_digit_pairs[idx];
p[j + 1] = ruby_decimal_digit_pairs[idx + 1];
}
else {
/* num is 1..9 here (0 was handled above) */
p[--j] = (char)('0' + num);
}
}
else {
do {
BDIGIT_DBL idx = num % b2s->base;
num /= b2s->base;
p[--j] = ruby_digitmap[idx];
} while (num);
}
len = sizeof(buf) - j;
big2str_alloc(b2s, len + taillen);
MEMCPY(b2s->ptr, buf + j, char, len);
}
else {
p = b2s->ptr;
j = b2s->hbase2_numdigits;
do {
BDIGIT_DBL idx = num % b2s->base;
num /= b2s->base;
p[--j] = ruby_digitmap[idx];
} while (j);
if (b2s->base == 10) {
/* Non-beginning chunks must emit EXACTLY hbase2_numdigits,
* zero-padded on the left. Consume num in 2-digit groups,
* handle the odd trailing digit, then memset remaining
* positions with '0'. */
while (num >= 100) {
BDIGIT_DBL idx = (num % 100) * 2;
num /= 100;
j -= 2;
p[j] = ruby_decimal_digit_pairs[idx];
p[j + 1] = ruby_decimal_digit_pairs[idx + 1];
}
if (num >= 10) {
BDIGIT_DBL idx = num * 2;
j -= 2;
p[j] = ruby_decimal_digit_pairs[idx];
p[j + 1] = ruby_decimal_digit_pairs[idx + 1];
}
else if (num > 0) {
p[--j] = (char)('0' + num);
}
if (j > 0) {
memset(p, '0', j);
j = 0;
}
}
else {
do {
BDIGIT_DBL idx = num % b2s->base;
num /= b2s->base;
p[--j] = ruby_digitmap[idx];
} while (j);
}
len = b2s->hbase2_numdigits;
}
b2s->ptr += len;
Expand Down
17 changes: 17 additions & 0 deletions depend
Original file line number Diff line number Diff line change
Expand Up @@ -4878,6 +4878,7 @@ enum.$(OBJEXT): {$(VPATH)}internal/core/rclass.h
enum.$(OBJEXT): {$(VPATH)}internal/core/rdata.h
enum.$(OBJEXT): {$(VPATH)}internal/core/rfile.h
enum.$(OBJEXT): {$(VPATH)}internal/core/rhash.h
enum.$(OBJEXT): {$(VPATH)}internal/core/rmatch.h
enum.$(OBJEXT): {$(VPATH)}internal/core/robject.h
enum.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h
enum.$(OBJEXT): {$(VPATH)}internal/core/rstring.h
Expand Down Expand Up @@ -4968,6 +4969,8 @@ enum.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
enum.$(OBJEXT): {$(VPATH)}missing.h
enum.$(OBJEXT): {$(VPATH)}onigmo.h
enum.$(OBJEXT): {$(VPATH)}oniguruma.h
enum.$(OBJEXT): {$(VPATH)}re.h
enum.$(OBJEXT): {$(VPATH)}regex.h
enum.$(OBJEXT): {$(VPATH)}ruby_assert.h
enum.$(OBJEXT): {$(VPATH)}shape.h
enum.$(OBJEXT): {$(VPATH)}st.h
Expand Down Expand Up @@ -8965,6 +8968,7 @@ marshal.$(OBJEXT): {$(VPATH)}internal/core/rclass.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/rdata.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/rfile.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/rhash.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/rmatch.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/robject.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h
marshal.$(OBJEXT): {$(VPATH)}internal/core/rstring.h
Expand Down Expand Up @@ -9060,6 +9064,8 @@ marshal.$(OBJEXT): {$(VPATH)}missing.h
marshal.$(OBJEXT): {$(VPATH)}node.h
marshal.$(OBJEXT): {$(VPATH)}onigmo.h
marshal.$(OBJEXT): {$(VPATH)}oniguruma.h
marshal.$(OBJEXT): {$(VPATH)}re.h
marshal.$(OBJEXT): {$(VPATH)}regex.h
marshal.$(OBJEXT): {$(VPATH)}ruby_assert.h
marshal.$(OBJEXT): {$(VPATH)}ruby_atomic.h
marshal.$(OBJEXT): {$(VPATH)}rubyparser.h
Expand Down Expand Up @@ -10952,6 +10958,7 @@ parse.$(OBJEXT): {$(VPATH)}internal/core/rclass.h
parse.$(OBJEXT): {$(VPATH)}internal/core/rdata.h
parse.$(OBJEXT): {$(VPATH)}internal/core/rfile.h
parse.$(OBJEXT): {$(VPATH)}internal/core/rhash.h
parse.$(OBJEXT): {$(VPATH)}internal/core/rmatch.h
parse.$(OBJEXT): {$(VPATH)}internal/core/robject.h
parse.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h
parse.$(OBJEXT): {$(VPATH)}internal/core/rstring.h
Expand Down Expand Up @@ -11054,6 +11061,7 @@ parse.$(OBJEXT): {$(VPATH)}parser_st.h
parse.$(OBJEXT): {$(VPATH)}probes.dmyh
parse.$(OBJEXT): {$(VPATH)}probes.h
parse.$(OBJEXT): {$(VPATH)}ractor.h
parse.$(OBJEXT): {$(VPATH)}re.h
parse.$(OBJEXT): {$(VPATH)}regenc.h
parse.$(OBJEXT): {$(VPATH)}regex.h
parse.$(OBJEXT): {$(VPATH)}ruby_assert.h
Expand Down Expand Up @@ -15946,6 +15954,7 @@ ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rclass.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rdata.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rfile.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rhash.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rmatch.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/robject.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h
ruby_parser.$(OBJEXT): {$(VPATH)}internal/core/rstring.h
Expand Down Expand Up @@ -16037,6 +16046,8 @@ ruby_parser.$(OBJEXT): {$(VPATH)}missing.h
ruby_parser.$(OBJEXT): {$(VPATH)}node.h
ruby_parser.$(OBJEXT): {$(VPATH)}onigmo.h
ruby_parser.$(OBJEXT): {$(VPATH)}oniguruma.h
ruby_parser.$(OBJEXT): {$(VPATH)}re.h
ruby_parser.$(OBJEXT): {$(VPATH)}regex.h
ruby_parser.$(OBJEXT): {$(VPATH)}ruby_assert.h
ruby_parser.$(OBJEXT): {$(VPATH)}ruby_parser.c
ruby_parser.$(OBJEXT): {$(VPATH)}rubyparser.h
Expand Down Expand Up @@ -19345,6 +19356,7 @@ variable.$(OBJEXT): {$(VPATH)}internal/core/rclass.h
variable.$(OBJEXT): {$(VPATH)}internal/core/rdata.h
variable.$(OBJEXT): {$(VPATH)}internal/core/rfile.h
variable.$(OBJEXT): {$(VPATH)}internal/core/rhash.h
variable.$(OBJEXT): {$(VPATH)}internal/core/rmatch.h
variable.$(OBJEXT): {$(VPATH)}internal/core/robject.h
variable.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h
variable.$(OBJEXT): {$(VPATH)}internal/core/rstring.h
Expand Down Expand Up @@ -19439,6 +19451,8 @@ variable.$(OBJEXT): {$(VPATH)}onigmo.h
variable.$(OBJEXT): {$(VPATH)}oniguruma.h
variable.$(OBJEXT): {$(VPATH)}ractor.h
variable.$(OBJEXT): {$(VPATH)}ractor_core.h
variable.$(OBJEXT): {$(VPATH)}re.h
variable.$(OBJEXT): {$(VPATH)}regex.h
variable.$(OBJEXT): {$(VPATH)}ruby_assert.h
variable.$(OBJEXT): {$(VPATH)}ruby_atomic.h
variable.$(OBJEXT): {$(VPATH)}rubyparser.h
Expand Down Expand Up @@ -19839,6 +19853,7 @@ vm.$(OBJEXT): {$(VPATH)}internal/core/rclass.h
vm.$(OBJEXT): {$(VPATH)}internal/core/rdata.h
vm.$(OBJEXT): {$(VPATH)}internal/core/rfile.h
vm.$(OBJEXT): {$(VPATH)}internal/core/rhash.h
vm.$(OBJEXT): {$(VPATH)}internal/core/rmatch.h
vm.$(OBJEXT): {$(VPATH)}internal/core/robject.h
vm.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h
vm.$(OBJEXT): {$(VPATH)}internal/core/rstring.h
Expand Down Expand Up @@ -19941,6 +19956,8 @@ vm.$(OBJEXT): {$(VPATH)}probes.h
vm.$(OBJEXT): {$(VPATH)}probes_helper.h
vm.$(OBJEXT): {$(VPATH)}ractor.h
vm.$(OBJEXT): {$(VPATH)}ractor_core.h
vm.$(OBJEXT): {$(VPATH)}re.h
vm.$(OBJEXT): {$(VPATH)}regex.h
vm.$(OBJEXT): {$(VPATH)}ruby_assert.h
vm.$(OBJEXT): {$(VPATH)}ruby_atomic.h
vm.$(OBJEXT): {$(VPATH)}rubyparser.h
Expand Down
2 changes: 2 additions & 0 deletions ext/ripper/depend
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ ripper.o: $(hdrdir)/ruby/internal/core/rclass.h
ripper.o: $(hdrdir)/ruby/internal/core/rdata.h
ripper.o: $(hdrdir)/ruby/internal/core/rfile.h
ripper.o: $(hdrdir)/ruby/internal/core/rhash.h
ripper.o: $(hdrdir)/ruby/internal/core/rmatch.h
ripper.o: $(hdrdir)/ruby/internal/core/robject.h
ripper.o: $(hdrdir)/ruby/internal/core/rregexp.h
ripper.o: $(hdrdir)/ruby/internal/core/rstring.h
Expand Down Expand Up @@ -566,6 +567,7 @@ ripper.o: $(hdrdir)/ruby/missing.h
ripper.o: $(hdrdir)/ruby/onigmo.h
ripper.o: $(hdrdir)/ruby/oniguruma.h
ripper.o: $(hdrdir)/ruby/ractor.h
ripper.o: $(hdrdir)/ruby/re.h
ripper.o: $(hdrdir)/ruby/regex.h
ripper.o: $(hdrdir)/ruby/ruby.h
ripper.o: $(hdrdir)/ruby/st.h
Expand Down
23 changes: 23 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,30 @@ rb_gc_event_hook(VALUE obj, rb_event_flag_t event)
rb_execution_context_t *ec = rb_gc_get_ec();
if (!ec->cfp) return;

#if USE_MODULAR_GC
bool gc_thread_p = false;
if (!GET_EC()) {
gc_thread_p = true;

# ifdef RB_THREAD_LOCAL_SPECIFIER
rb_current_ec_set(ec);
# else
native_tls_set(ruby_current_ec_key, ec);
# endif
}
#endif

EXEC_EVENT_HOOK(ec, event, ec->cfp->self, 0, 0, 0, obj);

#if USE_MODULAR_GC
if (gc_thread_p) {
# ifdef RB_THREAD_LOCAL_SPECIFIER
rb_current_ec_set(NULL);
# else
native_tls_set(ruby_current_ec_key, NULL);
# endif
}
#endif
}

void *
Expand Down
31 changes: 28 additions & 3 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
#include <sys/sysctl.h>
#endif

#ifndef VM_CHECK_MODE
# define VM_CHECK_MODE RUBY_DEBUG
#endif

// From ractor_core.h
#ifndef RACTOR_CHECK_MODE
# define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
#endif

#if RACTOR_CHECK_MODE
# define RVALUE_SUFFIX_SIZE sizeof(VALUE)
void rb_ractor_setup_belonging(VALUE obj);
#else
# define RVALUE_SUFFIX_SIZE 0
#endif

struct objspace {
bool measure_gc_time;
bool gc_stress;
Expand Down Expand Up @@ -557,7 +573,11 @@ void *
rb_gc_impl_objspace_alloc(void)
{
MMTk_Builder *builder = rb_mmtk_builder_init();
mmtk_init_binding(builder, NULL, &ruby_upcalls);
MMTk_RubyBindingOptions binding_options = {
.ractor_check_mode = RACTOR_CHECK_MODE != 0,
.suffix_size = RVALUE_SUFFIX_SIZE,
};
mmtk_init_binding(builder, &binding_options, &ruby_upcalls);

return calloc(1, sizeof(struct objspace));
}
Expand Down Expand Up @@ -885,15 +905,16 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
mmtk_handle_user_collection_request(ractor_cache, false, false);
}

alloc_size += sizeof(VALUE);
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RVALUE_SUFFIX_SIZE)]
alloc_size += sizeof(VALUE) + RVALUE_SUFFIX_SIZE;

VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size);
if (!alloc_obj) {
alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
}

alloc_obj++;
alloc_obj[-1] = alloc_size - sizeof(VALUE);
alloc_obj[-1] = alloc_size - sizeof(VALUE) - RVALUE_SUFFIX_SIZE;
alloc_obj[0] = flags;
alloc_obj[1] = klass;

Expand All @@ -905,6 +926,10 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags

objspace->total_allocated_objects++;

#if RACTOR_CHECK_MODE
rb_ractor_setup_belonging((VALUE)alloc_obj);
#endif

return (VALUE)alloc_obj;
}

Expand Down
Loading