Avoid some unnecessary use of stl types.
May be a minor performance win but really done for libc++ as this removes a
dependency on a library function whose prototype includes a std::string.
Change-Id: Ifc07a9caef1206caf2a69a6e1b0bfc0ba56c8c62
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index 52abaab..5353592 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -15,8 +15,8 @@
*/
#include <algorithm>
-#include <fcntl.h>
#include <set>
+#include <fcntl.h>
#include <unistd.h>
#include "base/logging.h"
@@ -37,7 +37,7 @@
#include "scoped_thread_state_change.h"
#include "ScopedLocalRef.h"
#include "ScopedUtfChars.h"
-#include "toStringArray.h"
+#include "well_known_classes.h"
#include "zip_archive.h"
#ifdef HAVE_ANDROID_OS
@@ -196,19 +196,24 @@
}
static jobjectArray DexFile_getClassNameList(JNIEnv* env, jclass, jlong cookie) {
- const DexFile* dex_file;
- dex_file = toDexFile(cookie, env);
+ jobjectArray result = nullptr;
+ const DexFile* dex_file = toDexFile(cookie, env);
if (dex_file == nullptr) {
- return nullptr;
+ result = env->NewObjectArray(dex_file->NumClassDefs(), WellKnownClasses::java_lang_String,
+ nullptr);
+ if (result != nullptr) {
+ for (size_t i = 0; i < dex_file->NumClassDefs(); ++i) {
+ const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
+ const char* descriptor = dex_file->GetClassDescriptor(class_def);
+ ScopedLocalRef<jstring> jdescriptor(env, env->NewStringUTF(descriptor));
+ if (jdescriptor.get() == nullptr) {
+ return nullptr;
+ }
+ env->SetObjectArrayElement(result, i, jdescriptor.get());
+ }
+ }
}
-
- std::vector<std::string> class_names;
- for (size_t i = 0; i < dex_file->NumClassDefs(); ++i) {
- const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
- const char* descriptor = dex_file->GetClassDescriptor(class_def);
- class_names.push_back(DescriptorToDot(descriptor));
- }
- return toStringArray(env, class_names);
+ return result;
}
// Copy a profile file
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc
index 0b58af4..ceff206 100644
--- a/runtime/native/dalvik_system_VMDebug.cc
+++ b/runtime/native/dalvik_system_VMDebug.cc
@@ -28,21 +28,35 @@
#include "hprof/hprof.h"
#include "jni_internal.h"
#include "mirror/class.h"
+#include "ScopedLocalRef.h"
#include "ScopedUtfChars.h"
#include "scoped_fast_native_object_access.h"
-#include "toStringArray.h"
#include "trace.h"
+#include "well_known_classes.h"
namespace art {
static jobjectArray VMDebug_getVmFeatureList(JNIEnv* env, jclass) {
- std::vector<std::string> features;
- features.push_back("method-trace-profiling");
- features.push_back("method-trace-profiling-streaming");
- features.push_back("method-sample-profiling");
- features.push_back("hprof-heap-dump");
- features.push_back("hprof-heap-dump-streaming");
- return toStringArray(env, features);
+ static const char* features[] = {
+ "method-trace-profiling",
+ "method-trace-profiling-streaming",
+ "method-sample-profiling",
+ "hprof-heap-dump",
+ "hprof-heap-dump-streaming",
+ };
+ jobjectArray result = env->NewObjectArray(arraysize(features),
+ WellKnownClasses::java_lang_String,
+ nullptr);
+ if (result != nullptr) {
+ for (size_t i = 0; i < arraysize(features); ++i) {
+ ScopedLocalRef<jstring> jfeature(env, env->NewStringUTF(features[i]));
+ if (jfeature.get() == nullptr) {
+ return nullptr;
+ }
+ env->SetObjectArrayElement(result, i, jfeature.get());
+ }
+ }
+ return result;
}
static void VMDebug_startAllocCounting(JNIEnv*, jclass) {
diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc
index 546eb40..fdc6e3f 100644
--- a/runtime/well_known_classes.cc
+++ b/runtime/well_known_classes.cc
@@ -40,6 +40,7 @@
jclass WellKnownClasses::java_lang_reflect_Proxy;
jclass WellKnownClasses::java_lang_RuntimeException;
jclass WellKnownClasses::java_lang_StackOverflowError;
+jclass WellKnownClasses::java_lang_String;
jclass WellKnownClasses::java_lang_System;
jclass WellKnownClasses::java_lang_Thread;
jclass WellKnownClasses::java_lang_Thread$UncaughtExceptionHandler;
@@ -142,6 +143,7 @@
java_lang_reflect_Proxy = CacheClass(env, "java/lang/reflect/Proxy");
java_lang_RuntimeException = CacheClass(env, "java/lang/RuntimeException");
java_lang_StackOverflowError = CacheClass(env, "java/lang/StackOverflowError");
+ java_lang_String = CacheClass(env, "java/lang/String");
java_lang_System = CacheClass(env, "java/lang/System");
java_lang_Thread = CacheClass(env, "java/lang/Thread");
java_lang_Thread$UncaughtExceptionHandler = CacheClass(env, "java/lang/Thread$UncaughtExceptionHandler");
diff --git a/runtime/well_known_classes.h b/runtime/well_known_classes.h
index bc928d0..f6c2930 100644
--- a/runtime/well_known_classes.h
+++ b/runtime/well_known_classes.h
@@ -54,6 +54,7 @@
static jclass java_lang_reflect_Proxy;
static jclass java_lang_RuntimeException;
static jclass java_lang_StackOverflowError;
+ static jclass java_lang_String;
static jclass java_lang_System;
static jclass java_lang_Thread;
static jclass java_lang_ThreadGroup;