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

ruby-changes:68602

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:10:27 +0900 (JST)
Subject: [ruby-changes:68602] 304adba717 (master): Add location hint to code block mmap call

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

From 304adba717b30df17b4db3c76993a649c3efec0e Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Mon, 21 Sep 2020 16:46:57 -0400
Subject: Add location hint to code block mmap call

---
 ujit_asm.c     | 10 ++++------
 ujit_compile.c | 30 ++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/ujit_asm.c b/ujit_asm.c
index 6e12abe513..c5e508fddb 100644
--- a/ujit_asm.c
+++ b/ujit_asm.c
@@ -117,7 +117,7 @@ void cb_init(codeblock_t* cb, size_t mem_size) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L117
 {
     // Map the memory as executable
     cb->mem_block = (uint8_t*)mmap(
-        NULL,
+        &cb_init,
         mem_size,
         PROT_READ | PROT_WRITE | PROT_EXEC,
         MAP_PRIVATE | MAP_ANON,
@@ -1083,15 +1083,13 @@ void jmp_rm(codeblock_t* cb, x86opnd_t opnd) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L1083
     cb_write_rm(cb, false, false, NO_OPND, opnd, 4, 1, 0xFF);
 }
 
-/*
-/// Opcode for direct jump with relative 8-bit offset
-const ubyte JMP_REL8_OPCODE = 0xEB;
-*/
-
 /*
 /// jmp - Jump with relative 8-bit offset
 void jmp8(CodeBlock cb, int8_t offset)
 {
+    /// Opcode for direct jump with relative 8-bit offset
+    const ubyte JMP_REL8_OPCODE = 0xEB;
+
     cb.writeASM("jmp", ((offset > 0)? "+":"-") ~ to!string(offset));
     cb.writeByte(JMP_REL8_OPCODE);
     cb.writeByte(offset);
diff --git a/ujit_compile.c b/ujit_compile.c
index 367fbf8ba9..bfe75d1b7b 100644
--- a/ujit_compile.c
+++ b/ujit_compile.c
@@ -170,6 +170,7 @@ ujit_compile_insn(rb_iseq_t *iseq, unsigned int insn_idx, unsigned int* next_uji https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L170
         st_data_t st_gen_fn;
         if (!rb_st_lookup(gen_fns, opcode, &st_gen_fn))
         {
+            //print_int(cb, imm_opnd(num_instrs));
             //print_str(cb, insn_name(opcode));
             break;
         }
@@ -200,8 +201,6 @@ ujit_compile_insn(rb_iseq_t *iseq, unsigned int insn_idx, unsigned int* next_uji https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L201
         return NULL;
     }
 
-    //print_int(cb, imm_opnd(num_instrs));
-
     // Write the adjusted SP back into the CFP
     if (ctx.stack_diff != 0)
     {
@@ -217,6 +216,33 @@ ujit_compile_insn(rb_iseq_t *iseq, unsigned int insn_idx, unsigned int* next_uji https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L216
     // Write the post call bytes
     ujit_instr_exit(cb);
 
+    /*
+    // Hack to patch a relative 32-bit jump to the instruction handler
+    int next_opcode = (int)*ctx.pc;
+    const void * const *table = rb_vm_get_insns_address_table();
+    VALUE encoded = (VALUE)table[next_opcode];
+    uint8_t* p_handler = (uint8_t*)encoded;
+
+    uint8_t* p_code = &cb->mem_block[cb->write_pos];
+    int64_t rel64 = ((int64_t)p_handler) - ((int64_t)p_code - 2 + 5);
+
+    //printf("p_handler: %lld\n", (int64_t)p_handler);
+    //printf("rel64: %lld\n", rel64);
+
+    uint8_t byte0 = cb->mem_block[cb->write_pos - 2];
+    uint8_t byte1 = cb->mem_block[cb->write_pos - 1];
+
+    //printf("cb_init: %lld\n", (int64_t)&cb_init);
+    //printf("%lld\n", rel64);
+
+    if (byte0 == 0xFF && byte1 == 0x20 && rel64 >= -2147483648 && rel64 <= 2147483647)
+    {
+        //printf("%02X %02X\n", (int)byte0, (int)byte1);
+        cb->write_pos -= 2;
+        jmp32(cb, (int32_t)rel64);
+    }
+    */
+
     addr2insn_bookkeeping(code_ptr, first_opcode);
 
     return code_ptr;
-- 
cgit v1.2.1


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

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