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
23 changes: 11 additions & 12 deletions cont.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ typedef struct rb_context_struct {
enum context_type type;
int argc;
int kw_splat;
bool root;
VALUE self;
VALUE value;

Expand Down Expand Up @@ -282,7 +281,7 @@ rb_free_shared_fiber_pool(void)
struct fiber_pool_allocation *allocations = shared_fiber_pool.allocations;
while (allocations) {
struct fiber_pool_allocation *next = allocations->next;
xfree(allocations);
SIZED_FREE(allocations);
allocations = next;
}
}
Expand Down Expand Up @@ -658,7 +657,7 @@ fiber_pool_allocation_free(struct fiber_pool_allocation * allocation)

allocation->pool->count -= allocation->count;

ruby_xfree(allocation);
SIZED_FREE(allocation);
}
#endif

Expand Down Expand Up @@ -1089,7 +1088,7 @@ cont_free(void *ptr)
RUBY_FREE_ENTER("cont");

if (cont->type == CONTINUATION_CONTEXT) {
ruby_xfree(cont->saved_ec.vm_stack);
SIZED_FREE_N(cont->saved_ec.vm_stack, cont->saved_ec.vm_stack_size);
RUBY_FREE_UNLESS_NULL(cont->machine.stack);
}
else {
Expand All @@ -1103,11 +1102,11 @@ cont_free(void *ptr)
VM_ASSERT(cont->jit_cont != NULL);
jit_cont_free(cont->jit_cont);
/* free rb_cont_t or rb_fiber_t */
if (cont->root) {
ruby_mimfree(ptr);
if (cont->type == CONTINUATION_CONTEXT) {
SIZED_FREE(cont);
}
else {
ruby_xfree(ptr);
SIZED_FREE((rb_fiber_t *)cont);
}
RUBY_FREE_LEAVE("cont");
}
Expand Down Expand Up @@ -1221,6 +1220,7 @@ rb_obj_is_fiber(VALUE obj)
static void
cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont)
{
const size_t old_stack_size = cont->machine.stack_size;
size_t size;

SET_MACHINE_STACK_END(&th->ec->machine.stack_end);
Expand All @@ -1235,10 +1235,10 @@ cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont)
}

if (cont->machine.stack) {
REALLOC_N(cont->machine.stack, VALUE, size);
SIZED_REALLOC_N(cont->machine.stack, VALUE, cont->machine.stack_size, old_stack_size);
}
else {
cont->machine.stack = ALLOC_N(VALUE, size);
cont->machine.stack = ALLOC_N(VALUE, cont->machine.stack_size);
}

FLUSH_REGISTER_WINDOWS;
Expand Down Expand Up @@ -2574,13 +2574,12 @@ rb_fiber_start(rb_fiber_t *fiber)
void
rb_threadptr_root_fiber_setup(rb_thread_t *th)
{
rb_fiber_t *fiber = ruby_mimcalloc(1, sizeof(rb_fiber_t));
rb_fiber_t *fiber = ZALLOC(rb_fiber_t);
if (!fiber) {
rb_bug("%s", strerror(errno)); /* ... is it possible to call rb_bug here? */
}

fiber->cont.type = FIBER_CONTEXT;
fiber->cont.root = true;
fiber->cont.saved_ec.fiber_ptr = fiber;
fiber->cont.saved_ec.serial = next_ec_serial(th->ractor);
fiber->cont.saved_ec.thread_ptr = th;
Expand Down Expand Up @@ -3407,7 +3406,7 @@ fiber_pool_free(void *ptr)
RUBY_FREE_ENTER("fiber_pool");

fiber_pool_allocation_free(fiber_pool->allocations);
ruby_xfree(fiber_pool);
SIZED_FREE(fiber_pool);

RUBY_FREE_LEAVE("fiber_pool");
}
Expand Down
2 changes: 1 addition & 1 deletion doc/_timezones.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Certain +Time+ methods accept arguments that specify timezones:
The value given with any of these must be one of the following
(each detailed below):

- {Hours/minutes offset}[rdoc-ref:Time@Hours-2FMinutes+Offsets].
- {Hours/minutes offset}[rdoc-ref:Time@HoursMinutes+Offsets].
- {Single-letter offset}[rdoc-ref:Time@Single-Letter+Offsets].
- {Integer offset}[rdoc-ref:Time@Integer+Offsets].
- {Timezone object}[rdoc-ref:Time@Timezone+Objects].
Expand Down
2 changes: 1 addition & 1 deletion doc/contributing/documentation_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Alternatives:
will not be honored:
- Example {source}[https://github.com/ruby/ruby/blob/34d802f32f00df1ac0220b62f72605827c16bad8/file.c#L6570-L6596].
- Corresponding {output}[rdoc-ref:File@Read-2FWrite+Mode].
- Corresponding {output}[rdoc-ref:File@ReadWrite+Mode].
- (Markdown format only): A {Github Flavored Markdown (GFM) table}[https://github.github.com/gfm/#tables-extension-],
using special formatting for the text:
Expand Down
15 changes: 15 additions & 0 deletions doc/jit/zjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ A file called `zjit_exits_{pid}.dump` will be created in the same directory as `
stackprof path/to/zjit_exits_{pid}.dump
```

### Viewing HIR as text

The compiled ZJIT HIR can be viewed as text using the `--zjit-dump-hir` option. However, HIR will only be generated if the call threshold is reached (default 30). By setting the threshold to 1 you can easily view the HIR for code snippets such as `1 + 1`:

```bash
./miniruby --zjit --zjit-dump-hir --zjit-call-threshold=1 -e "1 + 1"
```

Note that this disables profiling. To inject interpreter profiles into ZJIT, consider running your sample code 30 times:

```bash
./miniruby --zjit --zjit-dump-hir -e "30.times { 1 + 1 }"
```
```

### Viewing HIR in Iongraph

Using `--zjit-dump-hir-iongraph` will dump all compiled functions into a directory named `/tmp/zjit-iongraph-{PROCESS_PID}`. Each file will be named `func_{ZJIT_FUNC_NAME}.json`. In order to use them in the Iongraph viewer, you'll need to use `jq` to collate them to a single file. An example invocation of `jq` is shown below for reference.
Expand Down
2 changes: 1 addition & 1 deletion doc/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
# Here, class +String+ provides methods that are useful for:
#
# - {Creating a \String}[rdoc-ref:String@Creating+a+String].
# - {Freezing/Unfreezing a \String}[rdoc-ref:String@Freezing-2FUnfreezing].
# - {Freezing/Unfreezing a \String}[rdoc-ref:String@FreezingUnfreezing].
# - {Querying a \String}[rdoc-ref:String@Querying].
# - {Comparing Strings}[rdoc-ref:String@Comparing].
# - {Modifying a \String}[rdoc-ref:String@Modifying].
Expand Down
2 changes: 1 addition & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6866,7 +6866,7 @@ const char ruby_null_device[] =
* Methods File.new and File.open each may take string argument +mode+, which:
*
* - Begins with a 1- or 2-character
* {read/write mode}[rdoc-ref:File@Read-2FWrite+Mode].
* {read/write mode}[rdoc-ref:File@ReadWrite+Mode].
* - May also contain a 1-character {data mode}[rdoc-ref:File@Data+Mode].
* - May also contain a 1-character
* {file-create mode}[rdoc-ref:File@File-Create+Mode].
Expand Down
2 changes: 1 addition & 1 deletion hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Hash
#
# Initializes the values of Hash#default and Hash#default_proc,
# which determine the behavior when a given key is not found;
# see {Key Not Found?}[rdoc-ref:Hash@Key+Not+Found-3F].
# see {Key Not Found?}[rdoc-ref:Hash@Key+Not+Found].
#
# By default, a hash has +nil+ values for both +default+ and +default_proc+:
#
Expand Down
15 changes: 9 additions & 6 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ static enum rb_id_table_iterator_result
free_const_entry_i(VALUE value, void *data)
{
rb_const_entry_t *ce = (rb_const_entry_t *)value;
xfree(ce);
SIZED_FREE(ce);
return ID_TABLE_CONTINUE;
}

Expand All @@ -565,11 +565,12 @@ static inline void
imemo_fields_free(struct rb_fields *fields)
{
if (FL_TEST_RAW((VALUE)fields, OBJ_FIELD_HEAP)) {
if (rb_shape_obj_too_complex_p((VALUE)fields)) {
shape_id_t shape_id = RBASIC_SHAPE_ID((VALUE)fields);
if (rb_shape_too_complex_p(shape_id)) {
st_free_table(fields->as.complex.table);
}
else {
xfree(fields->as.external.ptr);
SIZED_FREE_N(fields->as.external.ptr, RSHAPE_CAPACITY(shape_id));
}
}
}
Expand All @@ -587,7 +588,9 @@ rb_imemo_free(VALUE obj)

if (ci->kwarg) {
((struct rb_callinfo_kwarg *)ci->kwarg)->references--;
if (ci->kwarg->references == 0) xfree((void *)ci->kwarg);
if (ci->kwarg->references == 0) {
ruby_sized_xfree((void *)ci->kwarg, rb_callinfo_kwarg_bytes(ci->kwarg->keyword_len));
}
}
RB_DEBUG_COUNTER_INC(obj_imemo_callinfo);

Expand All @@ -605,7 +608,7 @@ rb_imemo_free(VALUE obj)
rb_env_t *env = (rb_env_t *)obj;

RUBY_ASSERT(VM_ENV_ESCAPED_P(env->ep));
xfree((VALUE *)env->env);
SIZED_FREE_N(env->env, env->env_size);
RB_DEBUG_COUNTER_INC(obj_imemo_env);

break;
Expand Down Expand Up @@ -636,7 +639,7 @@ rb_imemo_free(VALUE obj)

break;
case imemo_tmpbuf:
xfree(((rb_imemo_tmpbuf_t *)obj)->ptr);
ruby_sized_xfree(((rb_imemo_tmpbuf_t *)obj)->ptr, ((rb_imemo_tmpbuf_t *)obj)->size);
RB_DEBUG_COUNTER_INC(obj_imemo_tmpbuf);

break;
Expand Down
2 changes: 1 addition & 1 deletion internal/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ ruby_sized_xfree_inlined(void *ptr, size_t size)
((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))

# define SIZED_FREE(v) ruby_sized_xfree((void *)(v), sizeof(*(v)))
# define SIZED_FREE_N(v, n) ruby_sized_xfree((void *)(v), sizeof(*(v)) * n)
# define SIZED_FREE_N(v, n) ruby_sized_xfree((void *)(v), sizeof(*(v)) * (n))

static inline void *
ruby_sized_realloc_n(void *ptr, size_t new_count, size_t element_size, size_t old_count)
Expand Down
6 changes: 2 additions & 4 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -14954,9 +14954,7 @@ set_LAST_READ_LINE(VALUE val, ID _x, VALUE *_y)
* ["ARGV", ["-"]]
* ["ARGF.read", "Open the pod bay doors, Hal.\n"]
*
* When no character <tt>'-'</tt> is given, stream <tt>$stdin</tt> is ignored
* (exception:
* see {Specifying $stdin in ARGV}[rdoc-ref:ARGF@Specifying+stdin+in+ARGV]):
* When no character <tt>'-'</tt> is given, stream <tt>$stdin</tt> is ignored.
*
* - Command and output:
*
Expand Down Expand Up @@ -15071,7 +15069,7 @@ set_LAST_READ_LINE(VALUE val, ID _x, VALUE *_y)
* Like a File stream, an \IO stream has:
*
* - A read/write mode, which may be read-only, write-only, or read/write;
* see {Read/Write Mode}[rdoc-ref:File@Read-2FWrite+Mode].
* see {Read/Write Mode}[rdoc-ref:File@ReadWrite+Mode].
* - A data mode, which may be text-only or binary;
* see {Data Mode}[rdoc-ref:File@Data+Mode].
* - Internal and external encodings;
Expand Down
50 changes: 27 additions & 23 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ free_arena(struct iseq_compile_data_storage *cur)

while (cur) {
next = cur->next;
ruby_xfree(cur);
ruby_sized_xfree(cur, offsetof(struct iseq_compile_data_storage, buff) + cur->size * sizeof(char));
cur = next;
}
}
Expand All @@ -102,7 +102,7 @@ compile_data_free(struct iseq_compile_data *compile_data)
if (compile_data->ivar_cache_table) {
rb_id_table_free(compile_data->ivar_cache_table);
}
ruby_xfree(compile_data);
SIZED_FREE(compile_data);
}
}

Expand Down Expand Up @@ -152,13 +152,14 @@ iseq_clear_ic_references(const rb_iseq_t *iseq)
if (segments == NULL)
continue;

for (int i = 0; segments[i]; i++) {
int i;
for (i = 0; segments[i]; i++) {
ID id = segments[i];
if (id == idNULL) continue;
remove_from_constant_cache(id, ic);
}

ruby_xfree((void *)segments);
SIZED_FREE_N(segments, i + 1);
}
}

Expand Down Expand Up @@ -198,38 +199,41 @@ rb_iseq_free(const rb_iseq_t *iseq)
#if USE_ZJIT
rb_zjit_iseq_free(iseq);
#endif
ruby_xfree((void *)body->iseq_encoded);
ruby_xfree((void *)body->insns_info.body);
ruby_xfree((void *)body->insns_info.positions);
SIZED_FREE_N(body->iseq_encoded, body->iseq_size);
SIZED_FREE_N(body->insns_info.body, body->insns_info.size);
SIZED_FREE_N(body->insns_info.positions, body->insns_info.size);
#if VM_INSN_INFO_TABLE_IMPL == 2
ruby_xfree(body->insns_info.succ_index_table);
#endif
ruby_xfree((void *)body->is_entries);
ruby_xfree(body->call_data);
ruby_xfree((void *)body->catch_table);
ruby_xfree((void *)body->param.opt_table);
SIZED_FREE_N(body->is_entries, ISEQ_IS_SIZE(body));
SIZED_FREE_N(body->call_data, body->ci_size);
if (body->catch_table) {
ruby_sized_xfree(body->catch_table, iseq_catch_table_bytes(body->catch_table->size));
}
SIZED_FREE_N(body->param.opt_table, body->param.opt_num + 1);
if (ISEQ_MBITS_BUFLEN(body->iseq_size) > 1 && body->mark_bits.list) {
ruby_xfree((void *)body->mark_bits.list);
SIZED_FREE_N(body->mark_bits.list, ISEQ_MBITS_BUFLEN(body->iseq_size));
}

ruby_xfree(body->variable.original_iseq);
ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);

if (body->param.keyword != NULL) {
if (body->param.keyword->table != &body->local_table[body->param.keyword->bits_start - body->param.keyword->num])
ruby_xfree((void *)body->param.keyword->table);
if (body->param.keyword->default_values) {
ruby_xfree((void *)body->param.keyword->default_values);
struct rb_iseq_param_keyword *pkw = (struct rb_iseq_param_keyword *)body->param.keyword;
if (pkw != NULL) {
if (pkw->table != &body->local_table[pkw->bits_start - pkw->num])
SIZED_FREE_N(pkw->table, pkw->required_num);
if (pkw->default_values) {
SIZED_FREE_N(pkw->default_values, pkw->num - pkw->required_num);
}
ruby_xfree((void *)body->param.keyword);
SIZED_FREE(pkw);
}
if (LIKELY(body->local_table != rb_iseq_shared_exc_local_tbl)) {
ruby_xfree((void *)body->local_table);
SIZED_FREE_N(body->local_table, body->local_table_size);
}
ruby_xfree((void *)body->lvar_states);
SIZED_FREE_N(body->lvar_states, body->local_table_size);

compile_data_free(ISEQ_COMPILE_DATA(iseq));
if (body->outer_variables) rb_id_table_free(body->outer_variables);
ruby_xfree(body);
SIZED_FREE(body);
}

RUBY_FREE_LEAVE("iseq");
Expand Down Expand Up @@ -758,7 +762,7 @@ rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq)
if (body->insns_info.succ_index_table) ruby_xfree(body->insns_info.succ_index_table);
body->insns_info.succ_index_table = succ_index_table_create(max_pos, data, size);
#if VM_CHECK_MODE == 0
ruby_xfree(body->insns_info.positions);
SIZED_FREE_N(body->insns_info.positions, body->insns_info.size);
body->insns_info.positions = NULL;
#endif
#endif
Expand Down
8 changes: 5 additions & 3 deletions iseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
static inline void
ISEQ_ORIGINAL_ISEQ_CLEAR(const rb_iseq_t *iseq)
{
void *ptr = ISEQ_BODY(iseq)->variable.original_iseq;
ISEQ_BODY(iseq)->variable.original_iseq = NULL;
ruby_xfree(ptr);
VALUE *ptr = (VALUE *)ISEQ_BODY(iseq)->variable.original_iseq;
if (ptr) {
ISEQ_BODY(iseq)->variable.original_iseq = NULL;
SIZED_FREE_N(ptr, ISEQ_BODY(iseq)->iseq_size);
}
}

static inline VALUE *
Expand Down
Loading