From e7c80151beff507e2550209482e1e85d7cdc429e Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 15 Apr 2024 16:41:37 +0200 Subject: [PATCH 1/2] Use Primitive.interop_execute instead of .call in posix.rb * Avoids an extra 2 calls. * Avoids a IndirectCallNode because CachedCallSignatureNode does not ReportPolymorphism yet (will be fixed). --- src/main/ruby/truffleruby/core/posix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/ruby/truffleruby/core/posix.rb b/src/main/ruby/truffleruby/core/posix.rb index f3b332bcf9f9..d3e70dafeb49 100644 --- a/src/main/ruby/truffleruby/core/posix.rb +++ b/src/main/ruby/truffleruby/core/posix.rb @@ -140,7 +140,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type, result = Primitive.thread_run_blocking_nfi_system_call(bound_func, args) end while Primitive.is_a?(result, Integer) and result == -1 and Errno.errno == EINTR else - result = bound_func.call(*args) + result = Primitive.interop_execute(bound_func, args) end if return_type == :string From 1c5f31416b3a76df5542a214bacda91931f25638 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 15 Apr 2024 16:42:56 +0200 Subject: [PATCH 2/2] Use copy_captured_locals for Truffle::POSIX * This way all the local variables outside the lambda are replaced by constants in the AST, making the compilation graph smaller and faster. --- src/main/ruby/truffleruby/core/posix.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/ruby/truffleruby/core/posix.rb b/src/main/ruby/truffleruby/core/posix.rb index d3e70dafeb49..0f4edb30e01f 100644 --- a/src/main/ruby/truffleruby/core/posix.rb +++ b/src/main/ruby/truffleruby/core/posix.rb @@ -128,7 +128,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type, parsed_sig = Primitive.interop_eval_nfi "(#{nfi_args_types.join(',')}):#{nfi_return_type}" bound_func = parsed_sig.bind(func) - on.define_singleton_method method_name, -> *args do + method_body = Truffle::Graal.copy_captured_locals -> *args do string_args.each do |i| str = args.fetch(i) # TODO CS 14-Nov-17 this involves copying to a Java byte[], and then NFI will copy it again! @@ -164,6 +164,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type, result end + on.define_singleton_method method_name, method_body else on.define_singleton_method method_name, -> * do raise NotImplementedError, "#{native_name} is not available"