ART: Move to libbase StringPrintf
Remove ART's StringPrintf implementation. Fix up clients. Add
missing includes where necessary.
Test: m test-art-host
Change-Id: I564038d5868595ac3bb88d641af1000cea940e5a
diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h
index 7d7c1d7..a5db0c0 100644
--- a/runtime/mirror/array-inl.h
+++ b/runtime/mirror/array-inl.h
@@ -19,10 +19,11 @@
#include "array.h"
+#include "android-base/stringprintf.h"
+
#include "base/bit_utils.h"
#include "base/casts.h"
#include "base/logging.h"
-#include "base/stringprintf.h"
#include "class-inl.h"
#include "gc/heap-inl.h"
#include "obj_ptr-inl.h"
@@ -167,9 +168,9 @@
#else
// 32-bit.
if (UNLIKELY(size == 0)) {
- self->ThrowOutOfMemoryError(StringPrintf("%s of length %d would overflow",
- array_class->PrettyDescriptor().c_str(),
- component_count).c_str());
+ self->ThrowOutOfMemoryError(android::base::StringPrintf("%s of length %d would overflow",
+ array_class->PrettyDescriptor().c_str(),
+ component_count).c_str());
return nullptr;
}
#endif
diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc
index 8afa4aa..cc548b9 100644
--- a/runtime/mirror/array.cc
+++ b/runtime/mirror/array.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "array.h"
+#include "array-inl.h"
#include "class.h"
#include "class-inl.h"
@@ -23,7 +23,6 @@
#include "dex_file-inl.h"
#include "gc/accounting/card_table-inl.h"
#include "object-inl.h"
-#include "object_array.h"
#include "object_array-inl.h"
#include "handle_scope-inl.h"
#include "thread.h"
@@ -32,6 +31,8 @@
namespace art {
namespace mirror {
+using android::base::StringPrintf;
+
// Create a multi-dimensional array of Objects or primitive types.
//
// We have to generate the names for X[], X[][], X[][][], and so on. The
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index a862c97..c1565df 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -16,6 +16,8 @@
#include "class.h"
+#include "android-base/stringprintf.h"
+
#include "art_field-inl.h"
#include "art_method-inl.h"
#include "class_ext.h"
@@ -40,6 +42,8 @@
namespace art {
namespace mirror {
+using android::base::StringPrintf;
+
GcRoot<Class> Class::java_lang_Class_;
void Class::SetClassClass(ObjPtr<Class> java_lang_Class) {
diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h
index 0fdf132..3e04bf6 100644
--- a/runtime/mirror/object_array-inl.h
+++ b/runtime/mirror/object_array-inl.h
@@ -17,12 +17,13 @@
#ifndef ART_RUNTIME_MIRROR_OBJECT_ARRAY_INL_H_
#define ART_RUNTIME_MIRROR_OBJECT_ARRAY_INL_H_
-#include <string>
-
#include "object_array.h"
+#include <string>
+
+#include "android-base/stringprintf.h"
+
#include "array-inl.h"
-#include "base/stringprintf.h"
#include "gc/heap.h"
#include "mirror/class.h"
#include "obj_ptr-inl.h"
@@ -330,13 +331,15 @@
std::string actualSrcType(mirror::Object::PrettyTypeOf(o));
std::string dstType(PrettyTypeOf());
Thread* self = Thread::Current();
+ std::string msg = android::base::StringPrintf(
+ "source[%d] of type %s cannot be stored in destination array of type %s",
+ src_pos + i,
+ actualSrcType.c_str(),
+ dstType.c_str());
if (throw_exception) {
- self->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;",
- "source[%d] of type %s cannot be stored in destination array of type %s",
- src_pos + i, actualSrcType.c_str(), dstType.c_str());
+ self->ThrowNewException("Ljava/lang/ArrayStoreException;", msg.c_str());
} else {
- LOG(FATAL) << StringPrintf("source[%d] of type %s cannot be stored in destination array of type %s",
- src_pos + i, actualSrcType.c_str(), dstType.c_str());
+ LOG(FATAL) << msg;
}
}
}
diff --git a/runtime/mirror/string-inl.h b/runtime/mirror/string-inl.h
index 95516ac..9b8445d 100644
--- a/runtime/mirror/string-inl.h
+++ b/runtime/mirror/string-inl.h
@@ -16,6 +16,10 @@
#ifndef ART_RUNTIME_MIRROR_STRING_INL_H_
#define ART_RUNTIME_MIRROR_STRING_INL_H_
+#include "string.h"
+
+#include "android-base/stringprintf.h"
+
#include "array.h"
#include "base/bit_utils.h"
#include "class.h"
@@ -24,7 +28,6 @@
#include "globals.h"
#include "intern_table.h"
#include "runtime.h"
-#include "string.h"
#include "thread.h"
#include "utf.h"
#include "utils.h"
@@ -228,9 +231,10 @@
"kObjectAlignment must be at least as big as Java char alignment");
const size_t max_length = RoundDown(max_alloc_length, kObjectAlignment / block_size);
if (UNLIKELY(length > max_length)) {
- self->ThrowOutOfMemoryError(StringPrintf("%s of length %d would overflow",
- Class::PrettyDescriptor(string_class).c_str(),
- static_cast<int>(length)).c_str());
+ self->ThrowOutOfMemoryError(
+ android::base::StringPrintf("%s of length %d would overflow",
+ Class::PrettyDescriptor(string_class).c_str(),
+ static_cast<int>(length)).c_str());
return nullptr;
}
diff --git a/runtime/mirror/throwable.cc b/runtime/mirror/throwable.cc
index ade4e87..e50409f 100644
--- a/runtime/mirror/throwable.cc
+++ b/runtime/mirror/throwable.cc
@@ -16,6 +16,8 @@
#include "throwable.h"
+#include "android-base/stringprintf.h"
+
#include "art_method-inl.h"
#include "base/enums.h"
#include "class-inl.h"
@@ -31,6 +33,8 @@
namespace art {
namespace mirror {
+using android::base::StringPrintf;
+
GcRoot<Class> Throwable::java_lang_Throwable_;
void Throwable::SetDetailMessage(ObjPtr<String> new_detail_message) {