summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-03-23 15:19:48 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-03-24 10:03:51 -0400
commit5f10bd634fb6ae8f74a4ea730176233b0ca96954 (patch)
tree170c1c81ea63184290c9e021cc45bffbfc3f4f41 /iseq.c
parent04591e1be7618f64bd3bed8c53c0fcde5fcbddb8 (diff)
Add ISEQ_BODY macro
Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using this macro will make it easier for us to change the allocation strategy of rb_iseq_constant_body when using Variable Width Allocation.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5698
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c104
1 files changed, 52 insertions, 52 deletions
diff --git a/iseq.c b/iseq.c
index d0afe535ca..ffbe9859c3 100644
--- a/iseq.c
+++ b/iseq.c
@@ -107,8 +107,8 @@ rb_iseq_free(const rb_iseq_t *iseq)
{
RUBY_FREE_ENTER("iseq");
- if (iseq && iseq->body) {
- struct rb_iseq_constant_body *const body = iseq->body;
+ if (iseq && ISEQ_BODY(iseq)) {
+ struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
mjit_free_iseq(iseq); /* Notify MJIT */
rb_yjit_iseq_free(body);
ruby_xfree((void *)body->iseq_encoded);
@@ -240,7 +240,7 @@ rb_iseq_each_value(const rb_iseq_t *iseq, iseq_value_itr_t * func, void *data)
(FL_TEST((VALUE)iseq, ISEQ_TRANSLATED)) ? rb_vm_insn_addr2insn2 :
#endif
rb_vm_insn_null_translator;
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
size = body->iseq_size;
code = body->iseq_encoded;
@@ -259,8 +259,8 @@ update_each_insn_value(void *ctx, VALUE obj)
void
rb_iseq_update_references(rb_iseq_t *iseq)
{
- if (iseq->body) {
- struct rb_iseq_constant_body *body = iseq->body;
+ if (ISEQ_BODY(iseq)) {
+ struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
body->variable.coverage = rb_gc_location(body->variable.coverage);
body->variable.pc2branchindex = rb_gc_location(body->variable.pc2branchindex);
@@ -343,8 +343,8 @@ rb_iseq_mark(const rb_iseq_t *iseq)
RUBY_MARK_UNLESS_NULL(iseq->wrapper);
- if (iseq->body) {
- const struct rb_iseq_constant_body *const body = iseq->body;
+ if (ISEQ_BODY(iseq)) {
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
if (FL_TEST((VALUE)iseq, ISEQ_MARKABLE_ISEQ)) {
rb_iseq_each_value(iseq, each_insn_value, NULL);
@@ -458,7 +458,7 @@ size_t
rb_iseq_memsize(const rb_iseq_t *iseq)
{
size_t size = 0; /* struct already counted as RVALUE size */
- const struct rb_iseq_constant_body *body = iseq->body;
+ const struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
const struct iseq_compile_data *compile_data;
/* TODO: should we count original_iseq? */
@@ -510,7 +510,7 @@ static rb_iseq_t *
iseq_alloc(void)
{
rb_iseq_t *iseq = iseq_imemo_alloc();
- iseq->body = rb_iseq_constant_body_alloc();
+ ISEQ_BODY(iseq) = rb_iseq_constant_body_alloc();
return iseq;
}
@@ -536,14 +536,14 @@ rb_iseq_pathobj_new(VALUE path, VALUE realpath)
void
rb_iseq_pathobj_set(const rb_iseq_t *iseq, VALUE path, VALUE realpath)
{
- RB_OBJ_WRITE(iseq, &iseq->body->location.pathobj,
+ RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->location.pathobj,
rb_iseq_pathobj_new(path, realpath));
}
static rb_iseq_location_t *
iseq_location_setup(rb_iseq_t *iseq, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_code_location_t *code_location, const int node_id)
{
- rb_iseq_location_t *loc = &iseq->body->location;
+ rb_iseq_location_t *loc = &ISEQ_BODY(iseq)->location;
rb_iseq_pathobj_set(iseq, path, realpath);
RB_OBJ_WRITE(iseq, &loc->label, name);
@@ -566,7 +566,7 @@ iseq_location_setup(rb_iseq_t *iseq, VALUE name, VALUE path, VALUE realpath, VAL
static void
set_relation(rb_iseq_t *iseq, const rb_iseq_t *piseq)
{
- struct rb_iseq_constant_body *const body = iseq->body;
+ struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
const VALUE type = body->type;
/* set class nest stack */
@@ -577,7 +577,7 @@ set_relation(rb_iseq_t *iseq, const rb_iseq_t *piseq)
body->local_iseq = iseq;
}
else if (piseq) {
- body->local_iseq = piseq->body->local_iseq;
+ body->local_iseq = ISEQ_BODY(piseq)->local_iseq;
}
if (piseq) {
@@ -612,7 +612,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
{
VALUE coverage = Qfalse;
VALUE err_info = Qnil;
- struct rb_iseq_constant_body *const body = iseq->body;
+ struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
if (parent && (type == ISEQ_TYPE_MAIN || type == ISEQ_TYPE_TOP))
err_info = Qfalse;
@@ -623,7 +623,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
name = rb_fstring(name);
iseq_location_setup(iseq, name, path, realpath, first_lineno, code_location, node_id);
if (iseq != body->local_iseq) {
- RB_OBJ_WRITE(iseq, &body->location.base_label, body->local_iseq->body->location.label);
+ RB_OBJ_WRITE(iseq, &body->location.base_label, ISEQ_BODY(body->local_iseq)->location.label);
}
ISEQ_COVERAGE_SET(iseq, Qnil);
ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
@@ -671,7 +671,7 @@ rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq)
{
#if VM_INSN_INFO_TABLE_IMPL == 2
/* create succ_index_table */
- struct rb_iseq_constant_body *const body = iseq->body;
+ struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
int size = body->insns_info.size;
int max_pos = body->iseq_size;
int *data = (int *)body->insns_info.positions;
@@ -708,7 +708,7 @@ static VALUE
finish_iseq_build(rb_iseq_t *iseq)
{
struct iseq_compile_data *data = ISEQ_COMPILE_DATA(iseq);
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE err = data->err_info;
ISEQ_COMPILE_DATA_CLEAR(iseq);
compile_data_free(data);
@@ -725,7 +725,7 @@ finish_iseq_build(rb_iseq_t *iseq)
}
RB_DEBUG_COUNTER_INC(iseq_num);
- RB_DEBUG_COUNTER_ADD(iseq_cd_num, iseq->body->ci_size);
+ RB_DEBUG_COUNTER_ADD(iseq_cd_num, ISEQ_BODY(iseq)->ci_size);
rb_iseq_init_trace(iseq);
return Qtrue;
@@ -920,7 +920,7 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea
script_lines = ast->script_lines;
}
else if (parent) {
- script_lines = parent->body->variable.script_lines;
+ script_lines = ISEQ_BODY(parent)->variable.script_lines;
}
prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, node ? nd_node_id(node) : -1,
@@ -1036,7 +1036,7 @@ iseq_load(VALUE data, const rb_iseq_t *parent, VALUE opt)
exception = CHECK_ARRAY(rb_ary_entry(data, i++));
body = CHECK_ARRAY(rb_ary_entry(data, i++));
- iseq->body->local_iseq = iseq;
+ ISEQ_BODY(iseq)->local_iseq = iseq;
iseq_type = iseq_type_from_sym(type);
if (iseq_type == (enum iseq_type)-1) {
@@ -1134,13 +1134,13 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, V
VALUE
rb_iseq_path(const rb_iseq_t *iseq)
{
- return pathobj_path(iseq->body->location.pathobj);
+ return pathobj_path(ISEQ_BODY(iseq)->location.pathobj);
}
VALUE
rb_iseq_realpath(const rb_iseq_t *iseq)
{
- return pathobj_realpath(iseq->body->location.pathobj);
+ return pathobj_realpath(ISEQ_BODY(iseq)->location.pathobj);
}
VALUE
@@ -1158,25 +1158,25 @@ rb_iseq_from_eval_p(const rb_iseq_t *iseq)
VALUE
rb_iseq_label(const rb_iseq_t *iseq)
{
- return iseq->body->location.label;
+ return ISEQ_BODY(iseq)->location.label;
}
VALUE
rb_iseq_base_label(const rb_iseq_t *iseq)
{
- return iseq->body->location.base_label;
+ return ISEQ_BODY(iseq)->location.base_label;
}
VALUE
rb_iseq_first_lineno(const rb_iseq_t *iseq)
{
- return iseq->body->location.first_lineno;
+ return ISEQ_BODY(iseq)->location.first_lineno;
}
VALUE
rb_iseq_method_name(const rb_iseq_t *iseq)
{
- struct rb_iseq_constant_body *const body = iseq->body->local_iseq->body;
+ struct rb_iseq_constant_body *const body = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq);
if (body->type == ISEQ_TYPE_METHOD) {
return body->location.base_label;
@@ -1189,7 +1189,7 @@ rb_iseq_method_name(const rb_iseq_t *iseq)
void
rb_iseq_code_location(const rb_iseq_t *iseq, int *beg_pos_lineno, int *beg_pos_column, int *end_pos_lineno, int *end_pos_column)
{
- const rb_code_location_t *loc = &iseq->body->location.code_location;
+ const rb_code_location_t *loc = &ISEQ_BODY(iseq)->location.code_location;
if (beg_pos_lineno) *beg_pos_lineno = loc->beg_pos.lineno;
if (beg_pos_column) *beg_pos_column = loc->beg_pos.column;
if (end_pos_lineno) *end_pos_lineno = loc->end_pos.lineno;
@@ -1201,7 +1201,7 @@ static ID iseq_type_id(enum iseq_type type);
VALUE
rb_iseq_type(const rb_iseq_t *iseq)
{
- return ID2SYM(iseq_type_id(iseq->body->type));
+ return ID2SYM(iseq_type_id(ISEQ_BODY(iseq)->type));
}
VALUE
@@ -1458,11 +1458,11 @@ iseqw_check(VALUE iseqw)
{
rb_iseq_t *iseq = DATA_PTR(iseqw);
- if (!iseq->body) {
+ if (!ISEQ_BODY(iseq)) {
rb_ibf_load_iseq_complete(iseq);
}
- if (!iseq->body->location.label) {
+ if (!ISEQ_BODY(iseq)->location.label) {
rb_raise(rb_eTypeError, "uninitialized InstructionSequence");
}
return iseq;
@@ -1496,7 +1496,7 @@ static VALUE
iseqw_inspect(VALUE self)
{
const rb_iseq_t *iseq = iseqw_check(self);
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE klass = rb_class_name(rb_obj_class(self));
if (!body->location.label) {
@@ -1726,7 +1726,7 @@ iseqw_to_a(VALUE self)
static const struct iseq_insn_info_entry *
get_insn_info_binary_search(const rb_iseq_t *iseq, size_t pos)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
size_t size = body->insns_info.size;
const struct iseq_insn_info_entry *insns_info = body->insns_info.body;
const unsigned int *positions = body->insns_info.positions;
@@ -1779,7 +1779,7 @@ get_insn_info(const rb_iseq_t *iseq, size_t pos)
static const struct iseq_insn_info_entry *
get_insn_info_succinct_bitvector(const rb_iseq_t *iseq, size_t pos)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
size_t size = body->insns_info.size;
const struct iseq_insn_info_entry *insns_info = body->insns_info.body;
const int debug = 0;
@@ -1822,7 +1822,7 @@ get_insn_info(const rb_iseq_t *iseq, size_t pos)
static const struct iseq_insn_info_entry *
get_insn_info_linear_search(const rb_iseq_t *iseq, size_t pos)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
size_t i = 0, size = body->insns_info.size;
const struct iseq_insn_info_entry *insns_info = body->insns_info.body;
const unsigned int *positions = body->insns_info.positions;
@@ -1869,7 +1869,7 @@ get_insn_info(const rb_iseq_t *iseq, size_t pos)
static void
validate_get_insn_info(const rb_iseq_t *iseq)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
size_t i;
for (i = 0; i < body->iseq_size; i++) {
if (get_insn_info_linear_search(iseq, i) != get_insn_info(iseq, i)) {
@@ -1941,10 +1941,10 @@ local_var_name(const rb_iseq_t *diseq, VALUE level, VALUE op)
int idx;
for (i = 0; i < level; i++) {
- diseq = diseq->body->parent_iseq;
+ diseq = ISEQ_BODY(diseq)->parent_iseq;
}
- idx = diseq->body->local_table_size - (int)op - 1;
- lid = diseq->body->local_table[idx];
+ idx = ISEQ_BODY(diseq)->local_table_size - (int)op - 1;
+ lid = ISEQ_BODY(diseq)->local_table[idx];
name = rb_id2str(lid);
if (!name) {
name = rb_str_new_cstr("?");
@@ -2048,7 +2048,7 @@ rb_insn_operand_intern(const rb_iseq_t *iseq,
{
if (op) {
const rb_iseq_t *iseq = rb_iseq_check((rb_iseq_t *)op);
- ret = iseq->body->location.label;
+ ret = ISEQ_BODY(iseq)->location.label;
if (child) {
rb_ary_push(child, (VALUE)iseq);
}
@@ -2063,7 +2063,7 @@ rb_insn_operand_intern(const rb_iseq_t *iseq,
case TS_IVC:
case TS_ICVARC:
case TS_ISE:
- ret = rb_sprintf("<is:%"PRIdPTRDIFF">", (union iseq_inline_storage_entry *)op - iseq->body->is_entries);
+ ret = rb_sprintf("<is:%"PRIdPTRDIFF">", (union iseq_inline_storage_entry *)op - ISEQ_BODY(iseq)->is_entries);
break;
case TS_CALLDATA:
@@ -2248,7 +2248,7 @@ catch_type(int type)
static VALUE
iseq_inspect(const rb_iseq_t *iseq)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
if (!body->location.label) {
return rb_sprintf("#<ISeq: uninitialized>");
}
@@ -2273,7 +2273,7 @@ static const rb_data_type_t tmp_set = {
static VALUE
rb_iseq_disasm_recursive(const rb_iseq_t *iseq, VALUE indent)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE *code;
VALUE str = rb_str_new(0, 0);
VALUE child = rb_ary_tmp_new(3);
@@ -2446,7 +2446,7 @@ iseq_iterate_children(const rb_iseq_t *iseq, void (*iter_func)(const rb_iseq_t *
{
unsigned int i;
VALUE *code = rb_iseq_original_iseq(iseq);
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
const rb_iseq_t *child;
VALUE all_children = rb_obj_hide(rb_ident_hash_new());
@@ -2538,7 +2538,7 @@ static VALUE
iseqw_trace_points(VALUE self)
{
const rb_iseq_t *iseq = iseqw_check(self);
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
unsigned int i;
VALUE ary = rb_ary_new();
@@ -2768,7 +2768,7 @@ iseq_data_to_ary(const rb_iseq_t *iseq)
{
unsigned int i;
long l;
- const struct rb_iseq_constant_body *const iseq_body = iseq->body;
+ const struct rb_iseq_constant_body *const iseq_body = ISEQ_BODY(iseq);
const struct iseq_insn_info_entry *prev_insn_info;
unsigned int pos;
int last_line = 0;
@@ -3091,7 +3091,7 @@ VALUE
rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
{
int i, r;
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
const struct rb_iseq_param_keyword *const keyword = body->param.keyword;
VALUE a, args = rb_ary_new2(body->param.size);
ID req, opt, rest, block, key, keyrest;
@@ -3294,7 +3294,7 @@ rb_vm_insn_addr2opcode(const void *addr)
rb_bug("rb_vm_insn_addr2opcode: invalid insn address: %p", addr);
}
-// Decode `iseq->body->iseq_encoded[i]` to an insn.
+// Decode `ISEQ_BODY(iseq)->iseq_encoded[i]` to an insn.
int
rb_vm_insn_decode(const VALUE encoded)
{
@@ -3327,7 +3327,7 @@ encoded_iseq_trace_instrument(VALUE *iseq_encoded_insn, rb_event_flag_t turnon,
void
rb_iseq_trace_flag_cleared(const rb_iseq_t *iseq, size_t pos)
{
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE *iseq_encoded = (VALUE *)body->iseq_encoded;
encoded_iseq_trace_instrument(&iseq_encoded[pos], 0, false);
}
@@ -3354,7 +3354,7 @@ iseq_add_local_tracepoint(const rb_iseq_t *iseq, rb_event_flag_t turnon_events,
{
unsigned int pc;
int n = 0;
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE *iseq_encoded = (VALUE *)body->iseq_encoded;
VM_ASSERT(ISEQ_EXECUTABLE_P(iseq));
@@ -3428,7 +3428,7 @@ iseq_remove_local_tracepoint(const rb_iseq_t *iseq, VALUE tpval)
if (iseq->aux.exec.local_hooks) {
unsigned int pc;
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE *iseq_encoded = (VALUE *)body->iseq_encoded;
rb_event_flag_t local_events = 0;
@@ -3486,7 +3486,7 @@ rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
}
else {
unsigned int pc;
- const struct rb_iseq_constant_body *const body = iseq->body;
+ const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
VALUE *iseq_encoded = (VALUE *)body->iseq_encoded;
rb_event_flag_t enabled_events;
rb_event_flag_t local_events = iseq->aux.exec.local_hooks ? iseq->aux.exec.local_hooks->events : 0;
@@ -3767,7 +3767,7 @@ static VALUE
iseqw_script_lines(VALUE self)
{
const rb_iseq_t *iseq = iseqw_check(self);
- return iseq->body->variable.script_lines;
+ return ISEQ_BODY(iseq)->variable.script_lines;
}
/*