summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--misc/ujit_disasm.rb15
-rw-r--r--ujit_core.c2
-rw-r--r--ujit_core.h16
-rw-r--r--ujit_iface.c26
4 files changed, 29 insertions, 30 deletions
diff --git a/misc/ujit_disasm.rb b/misc/ujit_disasm.rb
index 0e54f952c9..38eb139c33 100644
--- a/misc/ujit_disasm.rb
+++ b/misc/ujit_disasm.rb
@@ -1,6 +1,12 @@
begin
-require "crabstone"
-require "stringio"
+ require "crabstone"
+ require "stringio"
+rescue LoadError => e
+ puts "Please install crabstone, which is needed by the disassembler:"
+ puts " $ brew install capstone"
+ puts " $ gem install capstone"
+ raise e
+end
module UJIT
def self.disasm(iseq)
@@ -27,8 +33,3 @@ module UJIT
io.string
end
end
-rescue
- puts "Please install crabstone like this:"
- puts " $ brew install capstone"
- puts " $ gem install capstone"
-end
diff --git a/ujit_core.c b/ujit_core.c
index 27340735db..70d2b30f28 100644
--- a/ujit_core.c
+++ b/ujit_core.c
@@ -95,6 +95,8 @@ Returns T_NONE if unknown
int
ctx_get_top_type(ctx_t* ctx)
{
+ RUBY_ASSERT(ctx->stack_size > 0);
+
if (ctx->stack_size > MAX_TEMP_TYPES)
return T_NONE;
diff --git a/ujit_core.h b/ujit_core.h
index 5438cd850e..be4c39dd2f 100644
--- a/ujit_core.h
+++ b/ujit_core.h
@@ -23,7 +23,10 @@
// Maximum number of temp value types we keep track of
#define MAX_TEMP_TYPES 8
-// Code generation context
+/**
+Code generation context
+Contains information we can use to optimize code
+*/
typedef struct CtxStruct
{
// Temporary variable types we keep track of
@@ -64,7 +67,10 @@ enum uint8_t
// Branch code generation function signature
typedef void (*branchgen_fn)(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t shape);
-// Store info about an outgoing branch in a code segment
+/**
+Store info about an outgoing branch in a code segment
+Note: care must be taken to minimize the size of branch_t objects
+*/
typedef struct BranchEntry
{
// Positions where the generated code starts and ends
@@ -89,7 +95,11 @@ typedef struct BranchEntry
} branch_t;
-// Basic block version
+/**
+Basic block version
+Represents a portion of an iseq compiled with a given context
+Note: care must be taken to minimize the size of block_t objects
+*/
typedef struct BlockVersion
{
// Bytecode sequence (iseq, idx) this is a version of
diff --git a/ujit_iface.c b/ujit_iface.c
index 412c3ace90..ea7445e4ed 100644
--- a/ujit_iface.c
+++ b/ujit_iface.c
@@ -253,23 +253,6 @@ rb_ujit_method_lookup_change(VALUE cme_or_cc)
// Invalidate all regions that depend on the cme or cc
for (int32_t i = 0; i < array->size; i++) {
block_t* block = array->data[i];
-
- /*
- struct compiled_region *region = &array->data[i];
- const struct rb_iseq_constant_body *body = region->iseq->body;
- RUBY_ASSERT((unsigned int)region->start_idx < body->iseq_size);
-
- // Restore region address to interpreter address in bytecode sequence
- if (body->iseq_encoded[region->start_idx] == (VALUE)region->code) {
- const void *const *code_threading_table = rb_vm_get_insns_address_table();
- int opcode = rb_vm_insn_addr2insn(region->code);
- body->iseq_encoded[region->start_idx] = (VALUE)code_threading_table[opcode];
- if (UJIT_DUMP_MODE > 0) {
- fprintf(stderr, "cc_or_cme=%p now out of date. Restored idx=%u in iseq=%p\n", (void *)cme_or_cc, (unsigned)region->start_idx, (void *)region->iseq);
- }
- }
- */
-
invalidate(block);
}
@@ -333,7 +316,7 @@ ujit_blocks_for(VALUE mod, VALUE rb_iseq)
}
static VALUE
-ujit_insert(VALUE mod, VALUE iseq)
+ujit_install_entry(VALUE mod, VALUE iseq)
{
rb_ujit_compile_iseq(rb_iseqw_to_iseq(iseq));
return iseq;
@@ -355,7 +338,10 @@ block_code(VALUE self)
block_t * block;
TypedData_Get_Struct(self, block_t, &ujit_block_type, block);
- return rb_str_new(cb->mem_block + block->start_pos, block->end_pos - block->start_pos);
+ return (VALUE)rb_str_new(
+ (const char*)cb->mem_block + block->start_pos,
+ block->end_pos - block->start_pos
+ );
}
/* Get the start index in the Instruction Sequence that corresponds to this
@@ -394,7 +380,7 @@ rb_ujit_init(void)
ujit_init_codegen();
VALUE mUjit = rb_define_module("UJIT");
- rb_define_module_function(mUjit, "install_entry", ujit_insert, 1);
+ rb_define_module_function(mUjit, "install_entry", ujit_install_entry, 1);
rb_define_module_function(mUjit, "blocks_for", ujit_blocks_for, 1);
cUjitBlock = rb_define_class_under(mUjit, "Block", rb_cObject);