dart-sdk/runtime
Daco Harkes e16bb210d2 [vm/ffi] Optimize @Native calls
This CL removes static fields for storing the `@Native`'s function
addresses. Instead, the function addresses are stored in the object
pool for all archs except for ia32. ia32 has no AOT and no AppJit
snapshots, so the addresses are directly embedded in the code.

This CL removes the closure wrapping for `@Native`s. Instead of
`pointer.asFunctionInternal()()` where `asFunction` returns a closure
which contains the trampoline, the function is compiled to a body
which contains the trampoline `Native()`. This is possible for
`@Native`s because the dylib and symbol names are known statically.

Doing the compilation in kernel_to_il instead of a CFE transform
enables supporting static linking later. (The alternative would have
been to transform in the cfe to a `@pragma('vm:cachable-idempotent')`
instead of constructing the IL in kernel_to_il.

To enable running resolution in ia32 in kernel_to_il.cc, the
resolution function has been made available via
`runtime/lib/ffi_dynamic_library.h`.

Because the new calls are simply static calls, the TFA can figure
out const arguments flowing to these calls. This leads to constant
locations in the parameters to FfiCalls. So, this CL also introduces
logic to move constants into `NativeLocation`s.

TEST=runtime/vm/compiler/backend/il_test.cc
TEST=tests/ffi/function_*_native_(leaf_)test.dart
TEST=pkg/vm/testcases/transformations/ffi/ffinative_compound_return.dart

Closes: https://github.com/dart-lang/sdk/issues/47625
Closes: https://github.com/dart-lang/sdk/issues/51618
Change-Id: Ic5d017005dedcedea40c455c4d24dbe774f91603
CoreLibraryReviewExempt: Internal FFI implementation changes
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284300
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-11-02 16:00:53 +00:00
..
bin [test] Cleanup building Fuchsia packages/components. 2023-10-31 17:11:51 +00:00
docs [vm/ffi] Optimize @Native calls 2023-11-02 16:00:53 +00:00
include [ffi] Update some FfiNative docs to Native 2023-10-30 18:43:14 +00:00
lib [vm/ffi] Optimize @Native calls 2023-11-02 16:00:53 +00:00
observatory [observatory] Avoid deprecated UnmodifiableUint8ListView 2023-10-26 01:31:29 +00:00
platform [platform] Fix Utils::IsInt on unsigned values. 2023-10-31 19:39:51 +00:00
tests [test] More systematically mark GC stress tests as slow. 2023-11-01 22:57:09 +00:00
third_party Roll double-conversion to 032fa6a7d2c319b20d3928f5d762648fa4029acf. 2023-09-13 14:54:27 +00:00
tools Stop using deprecated 'element2' that will be removed. 2023-10-25 14:21:42 +00:00
vm [vm/ffi] Optimize @Native calls 2023-11-02 16:00:53 +00:00
.clang-tidy
.gitignore
BUILD.gn [vm] Fix build for gcc 13.2.0. 2023-10-25 08:38:28 +00:00
codereview.settings
configs.gni [Runtime] Add extra_product_deps and extra_nonproduct_deps params to "library_for_all_configs_with_compiler" template 2023-04-14 19:51:40 +00:00
CPPLINT.cfg [cpplint] Disable runtime/references lint 2023-01-23 18:21:48 +00:00
OWNERS [infra] Add OWNERS to the Dart SDK 2022-02-14 14:06:34 +00:00
PRESUBMIT.py Reland "Reland "[VM] Begin supporting Perfetto file recorder"" 2023-04-18 19:39:05 +00:00
runtime_args.gni Add a GN flag for the non-debug optimization level 2023-07-15 14:14:59 +00:00
vm-jit.shard.cml [test] Cleanup building Fuchsia packages/components. 2023-10-31 17:11:51 +00:00
vm.shard.cml [test] Cleanup building Fuchsia packages/components. 2023-10-31 17:11:51 +00:00