Remove mirror:: and ArtMethod deps in utils.{h,cc}
The latest chapter in the ongoing saga of attempting to dump a DEX
file without having to start a whole runtime instance. This episode
finds us removing references to ArtMethod/ArtField/mirror.
One aspect of this change that I would like to call out specfically
is that the utils versions of the "Pretty*" functions all were written
to accept nullptr as an argument. I have split these functions up as
follows:
1) an instance method, such as PrettyClass that obviously requires
this != nullptr.
2) a static method, that behaves the same way as the util method, but
calls the instance method if p != nullptr.
This requires using a full class qualifier for the static methods,
which isn't exactly beautiful. I have tried to remove as many cases
as possible where it was clear p != nullptr.
Bug: 22322814
Test: test-art-host
Change-Id: I21adee3614aa697aa580cd1b86b72d9206e1cb24
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 937dcee..3065f68 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -276,7 +276,7 @@
if (LIKELY(have_quick_code)) {
if (kLogInvocationStartAndReturn) {
LOG(INFO) << StringPrintf(
- "Invoking '%s' quick code=%p static=%d", PrettyMethod(this).c_str(),
+ "Invoking '%s' quick code=%p static=%d", PrettyMethod().c_str(),
GetEntryPointFromQuickCompiledCode(), static_cast<int>(IsStatic() ? 1 : 0));
}
@@ -287,7 +287,7 @@
? nullptr
: GetOatMethodQuickCode(runtime->GetClassLinker()->GetImagePointerSize());
CHECK(oat_quick_code == nullptr || oat_quick_code != GetEntryPointFromQuickCompiledCode())
- << "Don't call compiled code when -Xint " << PrettyMethod(this);
+ << "Don't call compiled code when -Xint " << PrettyMethod();
}
if (!IsStatic()) {
@@ -302,11 +302,11 @@
self->DeoptimizeWithDeoptimizationException(result);
}
if (kLogInvocationStartAndReturn) {
- LOG(INFO) << StringPrintf("Returned '%s' quick code=%p", PrettyMethod(this).c_str(),
+ LOG(INFO) << StringPrintf("Returned '%s' quick code=%p", PrettyMethod().c_str(),
GetEntryPointFromQuickCompiledCode());
}
} else {
- LOG(INFO) << "Not invoking '" << PrettyMethod(this) << "' code=null";
+ LOG(INFO) << "Not invoking '" << PrettyMethod() << "' code=null";
if (result != nullptr) {
result->SetJ(0);
}
@@ -318,9 +318,9 @@
}
void ArtMethod::RegisterNative(const void* native_method, bool is_fast) {
- CHECK(IsNative()) << PrettyMethod(this);
- CHECK(!IsFastNative()) << PrettyMethod(this);
- CHECK(native_method != nullptr) << PrettyMethod(this);
+ CHECK(IsNative()) << PrettyMethod();
+ CHECK(!IsFastNative()) << PrettyMethod();
+ CHECK(native_method != nullptr) << PrettyMethod();
if (is_fast) {
SetAccessFlags(GetAccessFlags() | kAccFastNative);
}
@@ -328,7 +328,7 @@
}
void ArtMethod::UnregisterNative() {
- CHECK(IsNative() && !IsFastNative()) << PrettyMethod(this);
+ CHECK(IsNative() && !IsFastNative()) << PrettyMethod();
// restore stub to lookup native pointer via dlsym
RegisterNative(GetJniDlsymLookupStub(), false);
}
@@ -421,7 +421,7 @@
oat_method_index++;
}
CHECK(found_virtual) << "Didn't find oat method index for virtual method: "
- << PrettyMethod(method);
+ << method->PrettyMethod();
}
DCHECK_EQ(oat_method_index,
GetOatMethodIndexFromMethodIndex(*declaring_class->GetDexCache()->GetDexFile(),
@@ -482,7 +482,7 @@
Runtime* runtime = Runtime::Current();
const void* existing_entry_point = GetEntryPointFromQuickCompiledCode();
- CHECK(existing_entry_point != nullptr) << PrettyMethod(this) << "@" << this;
+ CHECK(existing_entry_point != nullptr) << PrettyMethod() << "@" << this;
ClassLinker* class_linker = runtime->GetClassLinker();
if (class_linker->IsQuickGenericJniStub(existing_entry_point)) {
@@ -517,7 +517,7 @@
return method_header;
} else {
DCHECK(!code_cache->ContainsPc(reinterpret_cast<const void*>(pc)))
- << PrettyMethod(this)
+ << PrettyMethod()
<< ", pc=" << std::hex << pc
<< ", entry_point=" << std::hex << reinterpret_cast<uintptr_t>(existing_entry_point)
<< ", copy=" << std::boolalpha << IsCopied()
@@ -549,7 +549,7 @@
}
const void* oat_entry_point = oat_method.GetQuickCode();
if (oat_entry_point == nullptr || class_linker->IsQuickGenericJniStub(oat_entry_point)) {
- DCHECK(IsNative()) << PrettyMethod(this);
+ DCHECK(IsNative()) << PrettyMethod();
return nullptr;
}
@@ -561,7 +561,7 @@
}
DCHECK(method_header->Contains(pc))
- << PrettyMethod(this)
+ << PrettyMethod()
<< " " << std::hex << pc << " " << oat_entry_point
<< " " << (uintptr_t)(method_header->code_ + method_header->code_size_);
return method_header;
@@ -637,4 +637,66 @@
return runtime->GetClassLinker()->GetImagePointerSize() == pointer_size;
}
+std::string ArtMethod::PrettyMethod(ArtMethod* m, bool with_signature) {
+ if (m == nullptr) {
+ return "null";
+ }
+ return m->PrettyMethod(with_signature);
+}
+
+std::string ArtMethod::PrettyMethod(bool with_signature) {
+ ArtMethod* m = this;
+ if (!m->IsRuntimeMethod()) {
+ m = m->GetInterfaceMethodIfProxy(Runtime::Current()->GetClassLinker()->GetImagePointerSize());
+ }
+ 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;
+}
+
+std::string ArtMethod::JniShortName() {
+ std::string class_name(GetDeclaringClassDescriptor());
+ // Remove the leading 'L' and trailing ';'...
+ CHECK_EQ(class_name[0], 'L') << class_name;
+ CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
+ class_name.erase(0, 1);
+ class_name.erase(class_name.size() - 1, 1);
+
+ std::string method_name(GetName());
+
+ std::string short_name;
+ short_name += "Java_";
+ short_name += MangleForJni(class_name);
+ short_name += "_";
+ short_name += MangleForJni(method_name);
+ return short_name;
+}
+
+std::string ArtMethod::JniLongName() {
+ std::string long_name;
+ long_name += JniShortName();
+ long_name += "__";
+
+ std::string signature(GetSignature().ToString());
+ signature.erase(0, 1);
+ signature.erase(signature.begin() + signature.find(')'), signature.end());
+
+ long_name += MangleForJni(signature);
+
+ return long_name;
+}
+
} // namespace art