ART: Faster PrettyMethod().
Rewrite DexFile::PrettyMethod() to avoid copying strings.
This improves the performance, especially when requesting
the signature.
Avoid code duplication in ArtMethod::PrettyMethod() and
delegate to DexFile::PrettyMethod().
10 million invocations of ArtMethod/DexFile::PrettyMethod()
for "void Main.main(java.lang.String[] args)" with (+) or
without (-) signature, time in ms:
host/32-bit host/64-bit angler/32-bit angler/64-bit
AM+: 10407-> 5020 6374-> 3302 32413->13140 17558->10003
DF+: 7280-> 4259 3881-> 2828 19287-> 9331 10343-> 7375
AM-: 2682-> 1599 2025-> 1186 7206-> 4271 7447-> 4166
DF-: 861-> 871 653-> 640 1574-> 1430 1828-> 1712
Test: m test-art-host-gtest
Test: testrunner.py --host
Change-Id: Ifb79abe1a7f4fc6adc10a34f5d49dc6681d06699
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 7d8deda..c11f1a7 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -777,26 +777,16 @@
}
std::string ArtMethod::PrettyMethod(bool with_signature) {
- ArtMethod* m = this;
- if (!m->IsRuntimeMethod()) {
- m = m->GetInterfaceMethodIfProxy(Runtime::Current()->GetClassLinker()->GetImagePointerSize());
+ if (UNLIKELY(IsRuntimeMethod())) {
+ std::string result = GetDeclaringClassDescriptor();
+ result += '.';
+ result += GetName();
+ // Do not add "<no signature>" even if `with_signature` is true.
+ return result;
}
- std::string result(PrettyDescriptor(m->GetDeclaringClassDescriptor()));
- result += '.';
- result += m->GetName();
- if (UNLIKELY(m->IsFastNative())) {
- result += "!";
- }
- if (with_signature) {
- const Signature signature = m->GetSignature();
- std::string sig_as_string(signature.ToString());
- if (signature == Signature::NoSignature()) {
- return result + sig_as_string;
- }
- result = PrettyReturnType(sig_as_string.c_str()) + " " + result +
- PrettyArguments(sig_as_string.c_str());
- }
- return result;
+ ArtMethod* m =
+ GetInterfaceMethodIfProxy(Runtime::Current()->GetClassLinker()->GetImagePointerSize());
+ return m->GetDexFile()->PrettyMethod(m->GetDexMethodIndex(), with_signature);
}
std::string ArtMethod::JniShortName() {