[vm][ffi] Add function name to FFI Trampolines.

This change will append the name of the associated function
to the name of FFI trampolines.
Previously the name of all FFI trampolines was "FfiTrampoline",
which made them difficult to keep track of when there was
more than one trampoline (i.e. more than one FFI function).

TEST=Existing
Change-Id: I7b5efa25dc9064d5615309331e2cfeaa01e4c9f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242100
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
This commit is contained in:
Clement Skau 2022-04-22 09:48:39 +00:00 committed by Commit Bot
parent a5a7b4c801
commit 44a4cfc2d7
3 changed files with 10 additions and 4 deletions

View file

@ -16,10 +16,13 @@ namespace ffi {
// TODO(dartbug.com/36607): Cache the trampolines.
FunctionPtr TrampolineFunction(const FunctionType& dart_signature,
const FunctionType& c_signature,
bool is_leaf) {
bool is_leaf,
const String& function_name) {
Thread* thread = Thread::Current();
Zone* zone = thread->zone();
String& name = String::Handle(zone, Symbols::New(thread, "FfiTrampoline"));
String& name =
String::Handle(zone, Symbols::NewFormatted(thread, "FfiTrampoline_%s",
function_name.ToCString()));
const Library& lib = Library::Handle(zone, Library::FfiLibrary());
const Class& owner_class = Class::Handle(zone, lib.toplevel_class());
FunctionType& signature = FunctionType::Handle(zone, FunctionType::New());

View file

@ -21,7 +21,8 @@ namespace ffi {
FunctionPtr TrampolineFunction(const FunctionType& dart_signature,
const FunctionType& c_signature,
bool is_leaf);
bool is_leaf,
const String& function_name);
} // namespace ffi

View file

@ -1028,8 +1028,10 @@ Fragment BaseFlowGraphBuilder::BuildFfiAsFunctionInternalCall(
Report::LongJump(language_error);
}
const auto& name =
String::Handle(parsed_function_->function().UserVisibleName());
const Function& target = Function::ZoneHandle(
compiler::ffi::TrampolineFunction(dart_type, native_type, is_leaf));
compiler::ffi::TrampolineFunction(dart_type, native_type, is_leaf, name));
Fragment code;
// Store the pointer in the context, we cannot load the untagged address