summaryrefslogtreecommitdiffstats
path: root/runtime/native/dalvik_system_VMRuntime.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/native/dalvik_system_VMRuntime.cc')
-rw-r--r--runtime/native/dalvik_system_VMRuntime.cc25
1 files changed, 16 insertions, 9 deletions
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index 6e3f1bc913..760038a1dc 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -248,13 +248,20 @@ static void VMRuntime_runHeapTasks(JNIEnv* env, jobject) {
typedef std::map<std::string, mirror::String*> StringTable;
-static void PreloadDexCachesStringsCallback(mirror::Object** root, void* arg,
- const RootInfo& /*root_info*/)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- StringTable& table = *reinterpret_cast<StringTable*>(arg);
- mirror::String* string = const_cast<mirror::Object*>(*root)->AsString();
- table[string->ToModifiedUtf8()] = string;
-}
+class PreloadDexCachesStringsVisitor : public SingleRootVisitor {
+ public:
+ explicit PreloadDexCachesStringsVisitor(StringTable* table) : table_(table) {
+ }
+
+ void VisitRoot(mirror::Object* root, const RootInfo& info ATTRIBUTE_UNUSED)
+ OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ mirror::String* string = root->AsString();
+ table_->operator[](string->ToModifiedUtf8()) = string;
+ }
+
+ private:
+ StringTable* const table_;
+};
// Based on ClassLinker::ResolveString.
static void PreloadDexCachesResolveString(Handle<mirror::DexCache> dex_cache, uint32_t string_idx,
@@ -469,8 +476,8 @@ static void VMRuntime_preloadDexCaches(JNIEnv* env, jobject) {
// We use a std::map to avoid heap allocating StringObjects to lookup in gDvm.literalStrings
StringTable strings;
if (kPreloadDexCachesStrings) {
- runtime->GetInternTable()->VisitRoots(PreloadDexCachesStringsCallback, &strings,
- kVisitRootFlagAllRoots);
+ PreloadDexCachesStringsVisitor visitor(&strings);
+ runtime->GetInternTable()->VisitRoots(&visitor, kVisitRootFlagAllRoots);
}
const std::vector<const DexFile*>& boot_class_path = linker->GetBootClassPath();