From 34fdf6eb970687b69de137e3532076ed0b789683 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Mon, 15 Nov 2021 14:07:58 -0800 Subject: simpleperf: fix check_trampoline_after_art_jni_methods test. Loose the test and IsArtEntry() function to allow using art_quick_generic_jni_trampoline. (cherry picked from commit 41677a6ed702e6394912af43483b5b785562a79b) Bug: 260538122 Test: run simpleperf_unit_test Change-Id: Ia554c4186ce804601138160e1320421ee7ede3d0 --- simpleperf/cmd_record_test.cpp | 4 +++- simpleperf/cmd_report_sample.cpp | 2 +- simpleperf/report_utils.cpp | 16 +++++----------- simpleperf/report_utils_test.cpp | 3 ++- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 350a24f8..c4d347fa 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -880,7 +880,9 @@ TEST(record_cmd, check_trampoline_after_art_jni_methods) { std::string sym_name = get_symbol_name(thread, ips[i]); if (android::base::StartsWith(sym_name, "art::Method_invoke") && i + 1 < ips.size()) { has_check = true; - if (get_symbol_name(thread, ips[i + 1]) != "art_jni_trampoline") { + std::string name = get_symbol_name(thread, ips[i + 1]); + if (!android::base::EndsWith(name, "jni_trampoline")) { + GTEST_LOG_(ERROR) << "unexpected symbol after art::Method_invoke: " << name; return false; } } diff --git a/simpleperf/cmd_report_sample.cpp b/simpleperf/cmd_report_sample.cpp index b547d3c9..bc70040f 100644 --- a/simpleperf/cmd_report_sample.cpp +++ b/simpleperf/cmd_report_sample.cpp @@ -776,7 +776,7 @@ bool ReportSampleCommand::PrintSampleRecord(const SampleRecord& r, FprintIndented(report_fp_, 2, "file: %s\n", entries[i].dso->GetReportPath().data()); FprintIndented(report_fp_, 2, "symbol: %s\n", entries[i].symbol->DemangledName()); if (show_execution_type_) { - FprintIndented(report_fp_, 1, "execution_type: %s\n", + FprintIndented(report_fp_, 2, "execution_type: %s\n", ProtoExecutionTypeToString(ToProtoExecutionType(entries[i].execution_type))); } } diff --git a/simpleperf/report_utils.cpp b/simpleperf/report_utils.cpp index a9468006..d037cedb 100644 --- a/simpleperf/report_utils.cpp +++ b/simpleperf/report_utils.cpp @@ -25,17 +25,11 @@ namespace simpleperf { static bool IsArtEntry(const CallChainReportEntry& entry, bool* is_jni_trampoline) { if (entry.execution_type == CallChainExecutionType::NATIVE_METHOD) { - if (android::base::EndsWith(entry.dso->Path(), "/libart.so") || - android::base::EndsWith(entry.dso->Path(), "/libartd.so")) { - *is_jni_trampoline = false; - return true; - } - if (strcmp(entry.symbol->Name(), "art_jni_trampoline") == 0) { - // art_jni_trampoline is a trampoline used to call jni methods in art runtime. - // We want to hide it when hiding art frames. - *is_jni_trampoline = true; - return true; - } + // art_jni_trampoline/art_quick_generic_jni_trampoline are trampolines used to call jni + // methods in art runtime. We want to hide them when hiding art frames. + *is_jni_trampoline = android::base::EndsWith(entry.symbol->Name(), "jni_trampoline"); + return *is_jni_trampoline || android::base::EndsWith(entry.dso->Path(), "/libart.so") || + android::base::EndsWith(entry.dso->Path(), "/libartd.so"); } return false; }; diff --git a/simpleperf/report_utils_test.cpp b/simpleperf/report_utils_test.cpp index cc246357..5a15d719 100644 --- a/simpleperf/report_utils_test.cpp +++ b/simpleperf/report_utils_test.cpp @@ -53,6 +53,7 @@ class CallChainReportBuilderTest : public testing::Test { Symbol("art_func1", 0x0, 0x100), Symbol("art_func2", 0x100, 0x100), Symbol("_ZN3artL13Method_invokeEP7_JNIEnvP8_jobjectS3_P13_jobjectArray", 0x200, 0x100), + Symbol("art_quick_generic_jni_trampoline", 0x300, 0x100), }; thread_tree.AddDsoInfo(file); @@ -243,7 +244,7 @@ TEST_F(CallChainReportBuilderTest, keep_art_jni_method) { 0x100, // art_jni_trampoline 0x2000, // java_method1 in dex file 0x1200, // art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) - 0x100, // art_jni_trampoline + 0x1300, // art_quick_generic_jni_trampoline }; CallChainReportBuilder builder(thread_tree); std::vector entries = builder.Build(thread, fake_ips, 0); -- cgit v1.2.3