[前][次][番号順一覧][スレッド一覧]

ruby-changes:68716

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:33 +0900 (JST)
Subject: [ruby-changes:68716] d528cf4fd5 (master): Added comments. Fixed compiler warning.

https://git.ruby-lang.org/ruby.git/commit/?id=d528cf4fd5

From d528cf4fd5551c323484c2ffb79b56af0c6f50c4 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Fri, 22 Jan 2021 12:22:34 -0500
Subject: Added comments. Fixed compiler warning.

---
 misc/ujit_disasm.rb | 15 ++++++++-------
 ujit_core.c         |  2 ++
 ujit_core.h         | 16 +++++++++++++---
 ujit_iface.c        | 26 ++++++--------------------
 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 @@ https://github.com/ruby/ruby/blob/trunk/misc/ujit_disasm.rb#L1
 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 https://github.com/ruby/ruby/blob/trunk/misc/ujit_disasm.rb#L33
     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 https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L95
 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 @@ https://github.com/ruby/ruby/blob/trunk/ujit_core.h#L23
 // 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 https://github.com/ruby/ruby/blob/trunk/ujit_core.h#L67
 // 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 https://github.com/ruby/ruby/blob/trunk/ujit_core.h#L95
 
 } 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) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L253
         // 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) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L316
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L338
     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) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L380
     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);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]