summaryrefslogtreecommitdiff
path: root/vm_core.h
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 13:58:50 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 13:58:50 (GMT)
commit3dbb390180a0e9f98623b6db0d71b0213359c541 (patch)
treead18953723a41185b127a340386427b3c86d6904 /vm_core.h
parent8f620b9b17ccbaae1e3eb9a1b9b5d528f4d5f900 (diff)
* introduce new ISeq binary format serializer/de-serializer
and a pre-compilation/runtime loader sample. [Feature #11788] * iseq.c: add new methods: * RubyVM::InstructionSequence#to_binary_format(extra_data = nil) * RubyVM::InstructionSequence.from_binary_format(binary) * RubyVM::InstructionSequence.from_binary_format_extra_data(binary) * compile.c: implement body of this new feature. * load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq): call RubyVM::InstructionSequence.load_iseq(fname) with loading script name if this method is defined. We can return any ISeq object as a result value. Otherwise loading will be continue as usual. This interface is not matured and is not extensible. So that we don't guarantee the future compatibility of this method. Basically, you should'nt use this method. * iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions) from iseq.c. * encoding.c (rb_data_is_encoding), internal.h: added. * vm_core.h: add several supports for lazy load. * add USE_LAZY_LOAD macro to specify enable or disable of this feature. * add several fields to rb_iseq_t. * introduce new macro rb_iseq_check(). * insns.def: some check for lazy loading feature. * vm_insnhelper.c: ditto. * proc.c: ditto. * vm.c: ditto. * test/lib/iseq_loader_checker.rb: enabled iff suitable environment variables are provided. * test/runner.rb: enable lib/iseq_loader_checker.rb. * sample/iseq_loader.rb: add sample compiler and loader. $ ruby sample/iseq_loader.rb [dir] will compile all ruby scripts in [dir]. With default setting, this compile creates *.rb.yarb files in same directory of target .rb scripts. $ ruby -r sample/iseq_loader.rb [app] will run with enable to load compiled binary data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_core.h')
-rw-r--r--vm_core.h46
1 files changed, 37 insertions, 9 deletions
diff --git a/vm_core.h b/vm_core.h
index aecbe61..8c6456a 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -257,10 +257,10 @@ struct rb_call_cache {
#endif
typedef struct rb_iseq_location_struct {
- const VALUE path;
- const VALUE absolute_path;
- const VALUE base_label;
- const VALUE label;
+ VALUE path;
+ VALUE absolute_path;
+ VALUE base_label;
+ VALUE label;
VALUE first_lineno; /* TODO: may be unsigned short */
} rb_iseq_location_t;
@@ -376,7 +376,7 @@ struct rb_iseq_constant_body {
*/
struct rb_call_cache *cc_entries; /* size is ci_size = ci_kw_size */
- const VALUE mark_ary; /* Array: includes operands which should be GC marked */
+ VALUE mark_ary; /* Array: includes operands which should be GC marked */
unsigned int local_table_size;
unsigned int is_size;
@@ -389,12 +389,40 @@ struct rb_iseq_constant_body {
/* typedef rb_iseq_t is in method.h */
struct rb_iseq_struct {
VALUE flags;
- struct iseq_compile_data *compile_data_; /* used at compile time */
- struct rb_iseq_constant_body *body;
VALUE reserved1;
- VALUE reserved2;
+ struct rb_iseq_constant_body *body;
+
+ union { /* 4, 5 words */
+ struct iseq_compile_data *compile_data; /* used at compile time */
+
+ struct {
+ VALUE obj;
+ int index;
+ } loader;
+ } aux;
};
+#define USE_LAZY_LOAD 0
+
+#ifndef USE_LAZY_LOAD
+#define USE_LAZY_LOAD
+#endif
+
+#if USE_LAZY_LOAD
+const rb_iseq_t *rb_iseq_complete(const rb_iseq_t *iseq);
+
+static inline const rb_iseq_t *
+rb_iseq_check(const rb_iseq_t *iseq)
+{
+ if (iseq->body == NULL) {
+ rb_iseq_complete((rb_iseq_t *)iseq);
+ }
+ return iseq;
+}
+#else
+#define rb_iseq_check(iseq) iseq
+#endif
+
enum ruby_special_exceptions {
ruby_error_reenter,
ruby_error_nomemory,
@@ -962,7 +990,7 @@ rb_block_t *rb_vm_control_frame_block_ptr(const rb_control_frame_t *cfp);
(!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
#define RUBY_VM_IFUNC_P(ptr) (RB_TYPE_P((VALUE)(ptr), T_IMEMO) && imemo_type((VALUE)ptr) == imemo_ifunc)
-#define RUBY_VM_NORMAL_ISEQ_P(ptr) (RB_TYPE_P((VALUE)(ptr), T_IMEMO) && imemo_type((VALUE)ptr) == imemo_iseq)
+#define RUBY_VM_NORMAL_ISEQ_P(ptr) (RB_TYPE_P((VALUE)(ptr), T_IMEMO) && imemo_type((VALUE)ptr) == imemo_iseq && rb_iseq_check((rb_iseq_t *)ptr))
#define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
#define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \