mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ea4c97904e
running "ruby -rpp -e 'pp GC.stat'", a reduction in malloc usage is shown: before: :malloc_increase=>118784, :oldmalloc_increase=>1178736, after: :malloc_increase=>99832, :oldmalloc_increase=>1031976, For "ruby -e exit", valgrind reports over 300K reduction in overall allocations (and unnecessary memory copies). before: total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated after: total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated (numbers from x86-64) v2 changes based on ko1 recommendations [ruby-core:64883]: - squashed in-place direct thread translation to avoid alloc+copy - renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq, cache new iseq->iseq_original field. * compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy (rb_vm_addr2insn): new function for debug (rb_iseq_original_iseq): ditto (iseq_set_sequence): assign iseq_encoded directly [Feature #10185] * vm_core (rb_iseq_t): move original ->iseq to bottom * iseq.c (iseq_free, iseq_free): adjust for new layout (rb_iseq_disasm): use original iseq for dump (iseq_data_to_ary): ditto (rb_iseq_line_trace_each): ditto (rb_iseq_build_for_ruby2cext): use iseq_encoded directly * vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
157 lines
4.1 KiB
C
157 lines
4.1 KiB
C
/**********************************************************************
|
|
|
|
iseq.h -
|
|
|
|
$Author$
|
|
created at: 04/01/01 23:36:57 JST
|
|
|
|
Copyright (C) 2004-2008 Koichi Sasada
|
|
|
|
**********************************************************************/
|
|
|
|
#ifndef RUBY_COMPILE_H
|
|
#define RUBY_COMPILE_H
|
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
|
|
/* compile.c */
|
|
VALUE rb_iseq_compile_node(VALUE self, NODE *node);
|
|
int rb_iseq_translate_threaded_code(rb_iseq_t *iseq);
|
|
VALUE *rb_iseq_original_iseq(rb_iseq_t *iseq);
|
|
VALUE rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
|
|
VALUE exception, VALUE body);
|
|
|
|
/* iseq.c */
|
|
void rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj);
|
|
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
|
|
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
|
|
struct st_table *ruby_insn_make_insn_table(void);
|
|
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos);
|
|
|
|
int rb_iseq_line_trace_each(VALUE iseqval, int (*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data);
|
|
VALUE rb_iseq_line_trace_all(VALUE iseqval);
|
|
VALUE rb_iseq_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set);
|
|
|
|
/* proc.c */
|
|
rb_iseq_t *rb_method_get_iseq(VALUE body);
|
|
rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
|
|
|
|
struct rb_compile_option_struct {
|
|
int inline_const_cache;
|
|
int peephole_optimization;
|
|
int tailcall_optimization;
|
|
int specialized_instruction;
|
|
int operands_unification;
|
|
int instructions_unification;
|
|
int stack_caching;
|
|
int trace_instruction;
|
|
int debug_level;
|
|
};
|
|
|
|
struct iseq_line_info_entry {
|
|
unsigned int position;
|
|
unsigned int line_no;
|
|
};
|
|
|
|
struct iseq_catch_table_entry {
|
|
enum catch_type {
|
|
CATCH_TYPE_RESCUE = INT2FIX(1),
|
|
CATCH_TYPE_ENSURE = INT2FIX(2),
|
|
CATCH_TYPE_RETRY = INT2FIX(3),
|
|
CATCH_TYPE_BREAK = INT2FIX(4),
|
|
CATCH_TYPE_REDO = INT2FIX(5),
|
|
CATCH_TYPE_NEXT = INT2FIX(6)
|
|
} type;
|
|
VALUE iseq;
|
|
unsigned int start;
|
|
unsigned int end;
|
|
unsigned int cont;
|
|
unsigned int sp;
|
|
};
|
|
|
|
PACKED_STRUCT_UNALIGNED(struct iseq_catch_table {
|
|
int size;
|
|
struct iseq_catch_table_entry entries[1]; /* flexible array */
|
|
});
|
|
|
|
static inline int
|
|
iseq_catch_table_bytes(int n)
|
|
{
|
|
enum {
|
|
catch_table_entries_max = (INT_MAX - sizeof(struct iseq_catch_table)) / sizeof(struct iseq_catch_table_entry)
|
|
};
|
|
if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
|
|
return (int)(sizeof(struct iseq_catch_table) +
|
|
(n - 1) * sizeof(struct iseq_catch_table_entry));
|
|
}
|
|
|
|
#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
|
|
|
|
struct iseq_compile_data_storage {
|
|
struct iseq_compile_data_storage *next;
|
|
unsigned int pos;
|
|
unsigned int size;
|
|
char buff[1]; /* flexible array */
|
|
};
|
|
|
|
/* account for flexible array */
|
|
#define SIZEOF_ISEQ_COMPILE_DATA_STORAGE \
|
|
(sizeof(struct iseq_compile_data_storage) - 1)
|
|
|
|
struct iseq_compile_data {
|
|
/* GC is needed */
|
|
const VALUE err_info;
|
|
VALUE mark_ary;
|
|
const VALUE catch_table_ary; /* Array */
|
|
|
|
/* GC is not needed */
|
|
struct iseq_label_data *start_label;
|
|
struct iseq_label_data *end_label;
|
|
struct iseq_label_data *redo_label;
|
|
VALUE current_block;
|
|
VALUE ensure_node;
|
|
VALUE for_iseq;
|
|
struct iseq_compile_data_ensure_node_stack *ensure_node_stack;
|
|
int loopval_popped; /* used by NODE_BREAK */
|
|
int cached_const;
|
|
struct iseq_compile_data_storage *storage_head;
|
|
struct iseq_compile_data_storage *storage_current;
|
|
int last_line;
|
|
int last_coverable_line;
|
|
int label_no;
|
|
int node_level;
|
|
const rb_compile_option_t *option;
|
|
#if SUPPORT_JOKE
|
|
st_table *labels_table;
|
|
#endif
|
|
};
|
|
|
|
/* defined? */
|
|
|
|
enum defined_type {
|
|
DEFINED_NIL = 1,
|
|
DEFINED_IVAR,
|
|
DEFINED_LVAR,
|
|
DEFINED_GVAR,
|
|
DEFINED_CVAR,
|
|
DEFINED_CONST,
|
|
DEFINED_METHOD,
|
|
DEFINED_YIELD,
|
|
DEFINED_ZSUPER,
|
|
DEFINED_SELF,
|
|
DEFINED_TRUE,
|
|
DEFINED_FALSE,
|
|
DEFINED_ASGN,
|
|
DEFINED_EXPR,
|
|
DEFINED_IVAR2,
|
|
DEFINED_REF,
|
|
DEFINED_FUNC
|
|
};
|
|
|
|
VALUE rb_iseq_defined_string(enum defined_type type);
|
|
|
|
#define DEFAULT_SPECIAL_VAR_COUNT 2
|
|
|
|
RUBY_SYMBOL_EXPORT_END
|
|
|
|
#endif /* RUBY_COMPILE_H */
|