summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit/insn_compiler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-03-04 00:01:30 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 23:28:59 -0800
commitc587666f68bc3cd21d8dde9b759ef19574c50ca3 (patch)
treeaa5726afe4edc657d995534bd898951cc8fe51c4 /lib/ruby_vm/mjit/insn_compiler.rb
parent9ee724408c1da10c7323c07405d5e01182aeb0bd (diff)
Optimize Thread.current
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib/ruby_vm/mjit/insn_compiler.rb')
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index f1367b9ce6..0ec4d1d908 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -2271,6 +2271,25 @@ module RubyVM::MJIT
true
end
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def jit_thread_s_current(jit, ctx, asm, argc, _known_recv_class)
+ return false if argc != 0
+ asm.comment('Thread.current')
+ ctx.stack_pop(1)
+
+ # ec->thread_ptr
+ asm.mov(:rax, [EC, C.rb_execution_context_t.offsetof(:thread_ptr)])
+
+ # thread->self
+ asm.mov(:rax, [:rax, C.rb_thread_struct.offsetof(:self)])
+
+ stack_ret = ctx.stack_push
+ asm.mov(stack_ret, :rax)
+ true
+ end
+
#
# Helpers
#
@@ -2311,7 +2330,7 @@ module RubyVM::MJIT
#register_cfunc_method(Kernel, :block_given?, :jit_rb_f_block_given_p)
# Thread.current
- #register_cfunc_method(rb_singleton_class(rb_cThread), :current, :jit_thread_s_current)
+ register_cfunc_method(C.rb_singleton_class(Thread), :current, :jit_thread_s_current)
#---
register_cfunc_method(Array, :<<, :jit_rb_ary_push)