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/jni_internal.cc b/runtime/jni_internal.cc
index 305a7e8..8238f3a 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -110,7 +110,7 @@
bool return_errors)
REQUIRES_SHARED(Locks::mutator_lock_) {
LOG(return_errors ? ::android::base::ERROR : ::android::base::FATAL)
- << "Failed to register native method in " << PrettyDescriptor(c)
+ << "Failed to register native method in " << c->PrettyDescriptor()
<< " in " << c->GetDexCache()->GetLocation()->ToModifiedUtf8()
<< ": " << kind << " is null at index " << idx;
soa.Self()->ThrowNewExceptionF("Ljava/lang/NoSuchMethodError;",
@@ -241,7 +241,7 @@
static void ThrowAIOOBE(ScopedObjectAccess& soa, mirror::Array* array, jsize start,
jsize length, const char* identifier)
REQUIRES_SHARED(Locks::mutator_lock_) {
- std::string type(PrettyTypeOf(array));
+ std::string type(array->PrettyTypeOf());
soa.Self()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;",
"%s offset=%d length=%d %s.length=%d",
type.c_str(), start, length, identifier, array->GetLength());
@@ -283,7 +283,7 @@
if (mid == nullptr) {
ScopedObjectAccess soa(env);
LOG(ERROR) << "No <init>" << signature << " in "
- << PrettyClass(soa.Decode<mirror::Class>(exception_class));
+ << mirror::Class::PrettyClass(soa.Decode<mirror::Class>(exception_class));
return JNI_ERR;
}
@@ -486,11 +486,11 @@
jmethodID mid = env->GetMethodID(exception_class.get(), "printStackTrace", "()V");
if (mid == nullptr) {
LOG(WARNING) << "JNI WARNING: no printStackTrace()V in "
- << PrettyTypeOf(old_exception.Get());
+ << mirror::Object::PrettyTypeOf(old_exception.Get());
} else {
env->CallVoidMethod(exception.get(), mid);
if (soa.Self()->IsExceptionPending()) {
- LOG(WARNING) << "JNI WARNING: " << PrettyTypeOf(soa.Self()->GetException())
+ LOG(WARNING) << "JNI WARNING: " << mirror::Object::PrettyTypeOf(soa.Self()->GetException())
<< " thrown while calling printStackTrace";
soa.Self()->ClearException();
}
@@ -1841,7 +1841,7 @@
ScopedObjectAccess soa(env);
ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(java_array);
if (UNLIKELY(!obj->IsArrayInstance())) {
- soa.Vm()->JniAbortF("GetArrayLength", "not an array: %s", PrettyTypeOf(obj).c_str());
+ soa.Vm()->JniAbortF("GetArrayLength", "not an array: %s", obj->PrettyTypeOf().c_str());
return 0;
}
mirror::Array* array = obj->AsArray();
@@ -1910,7 +1910,7 @@
if (UNLIKELY(element_class->IsPrimitive())) {
soa.Vm()->JniAbortF("NewObjectArray",
"not an object type: %s",
- PrettyDescriptor(element_class).c_str());
+ element_class->PrettyDescriptor().c_str());
return nullptr;
}
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
@@ -1930,8 +1930,8 @@
if (UNLIKELY(!element_class->IsAssignableFrom(initial_object->GetClass()))) {
soa.Vm()->JniAbortF("NewObjectArray", "cannot assign object of type '%s' to array with "
"element type of '%s'",
- PrettyDescriptor(initial_object->GetClass()).c_str(),
- PrettyDescriptor(element_class).c_str());
+ mirror::Class::PrettyDescriptor(initial_object->GetClass()).c_str(),
+ element_class->PrettyDescriptor().c_str());
return nullptr;
} else {
for (jsize i = 0; i < length; ++i) {
@@ -1953,7 +1953,7 @@
ObjPtr<mirror::Array> array = soa.Decode<mirror::Array>(java_array);
if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) {
soa.Vm()->JniAbortF("GetPrimitiveArrayCritical", "expected primitive array, given %s",
- PrettyDescriptor(array->GetClass()).c_str());
+ array->GetClass()->PrettyDescriptor().c_str());
return nullptr;
}
gc::Heap* heap = Runtime::Current()->GetHeap();
@@ -1981,7 +1981,7 @@
ObjPtr<mirror::Array> array = soa.Decode<mirror::Array>(java_array);
if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) {
soa.Vm()->JniAbortF("ReleasePrimitiveArrayCritical", "expected primitive array, given %s",
- PrettyDescriptor(array->GetClass()).c_str());
+ array->GetClass()->PrettyDescriptor().c_str());
return;
}
const size_t component_size = array->GetClass()->GetComponentSize();
@@ -2162,7 +2162,7 @@
ObjPtr<mirror::Class> c = soa.Decode<mirror::Class>(java_class);
if (UNLIKELY(method_count == 0)) {
LOG(WARNING) << "JNI RegisterNativeMethods: attempt to register 0 native methods for "
- << PrettyDescriptor(c);
+ << mirror::Class::PrettyDescriptor(c);
return JNI_OK;
}
CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", methods, JNI_ERR);
@@ -2250,20 +2250,20 @@
mirror::Class::kDumpClassFullDetail);
LOG(return_errors ? ::android::base::ERROR : ::android::base::FATAL)
<< "Failed to register native method "
- << PrettyDescriptor(c) << "." << name << sig << " in "
+ << c->PrettyDescriptor() << "." << name << sig << " in "
<< c->GetDexCache()->GetLocation()->ToModifiedUtf8();
ThrowNoSuchMethodError(soa, c, name, sig, "static or non-static");
return JNI_ERR;
} else if (!m->IsNative()) {
LOG(return_errors ? ::android::base::ERROR : ::android::base::FATAL)
<< "Failed to register non-native method "
- << PrettyDescriptor(c) << "." << name << sig
+ << c->PrettyDescriptor() << "." << name << sig
<< " as native";
ThrowNoSuchMethodError(soa, c, name, sig, "native");
return JNI_ERR;
}
- VLOG(jni) << "[Registering JNI native method " << PrettyMethod(m) << "]";
+ VLOG(jni) << "[Registering JNI native method " << m->PrettyMethod() << "]";
is_fast = is_fast || m->IsFastNative(); // Merge with @FastNative state.
m->RegisterNative(fnPtr, is_fast);
@@ -2276,7 +2276,7 @@
ScopedObjectAccess soa(env);
ObjPtr<mirror::Class> c = soa.Decode<mirror::Class>(java_class);
- VLOG(jni) << "[Unregistering JNI native methods for " << PrettyClass(c) << "]";
+ VLOG(jni) << "[Unregistering JNI native methods for " << mirror::Class::PrettyClass(c) << "]";
size_t unregistered_count = 0;
auto pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
@@ -2289,7 +2289,7 @@
if (unregistered_count == 0) {
LOG(WARNING) << "JNI UnregisterNatives: attempt to unregister native methods of class '"
- << PrettyDescriptor(c) << "' that contains no native methods";
+ << mirror::Class::PrettyDescriptor(c) << "' that contains no native methods";
}
return JNI_OK;
}
@@ -2428,8 +2428,9 @@
soa.Vm()->JniAbortF(fn_name,
"attempt to %s %s primitive array elements with an object of type %s",
operation,
- PrettyDescriptor(ArtArrayT::GetArrayClass()->GetComponentType()).c_str(),
- PrettyDescriptor(array->GetClass()).c_str());
+ mirror::Class::PrettyDescriptor(
+ ArtArrayT::GetArrayClass()->GetComponentType()).c_str(),
+ mirror::Class::PrettyDescriptor(array->GetClass()).c_str());
return nullptr;
}
DCHECK_EQ(sizeof(ElementT), array->GetClass()->GetComponentSize());