[Lldb-commits] [lldb] r137612 - in /lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime: AppleObjCRuntimeV2.cpp AppleObjCRuntimeV2.h

Enrico Granata granata.enrico at gmail.com
Mon Aug 15 08:56:02 PDT 2011


Author: enrico
Date: Mon Aug 15 10:56:02 2011
New Revision: 137612

URL: http://llvm.org/viewvc/llvm-project?rev=137612&view=rev
Log:
Objective-C runtime now caches resolved ISA information for increased efficiency

Modified:
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=137612&r1=137611&r2=137612&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Mon Aug 15 10:56:02 2011
@@ -94,7 +94,9 @@
 AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, ModuleSP &objc_module_sp) : 
     lldb_private::AppleObjCRuntime (process),
     m_get_class_name_args(LLDB_INVALID_ADDRESS),
-    m_get_class_name_args_mutex(Mutex::eMutexTypeNormal)
+    m_get_class_name_args_mutex(Mutex::eMutexTypeNormal),
+    m_isa_to_name_cache(),
+    m_isa_to_parent_cache()
 {
     m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(ConstString("gdb_object_getClass")) != NULL);
 }
@@ -637,6 +639,12 @@
     if (isa == g_objc_Tagged_ISA)
         return ConstString("_lldb_Tagged_ObjC_ISA");
     
+    ISAToNameIterator found = m_isa_to_name_cache.find(isa);
+    ISAToNameIterator end = m_isa_to_name_cache.end();
+    
+    if (found != end)
+        return found->second;
+    
     uint8_t pointer_size = m_process->GetAddressByteSize();
     Error error;
     lldb::addr_t rw_pointer = isa + (4 * pointer_size);
@@ -682,10 +690,16 @@
             // will return the swizzled class instead of the actual one
             // this swizzled class is a descendant of the real class, so just
             // return the parent type and all should be fine
-            return GetActualTypeName(GetParentClass(isa));
+            ConstString class_name = GetActualTypeName(GetParentClass(isa));
+            m_isa_to_name_cache[isa] = class_name;
+            return class_name;
         }
         else
-            return ConstString(cstr);
+        {
+            ConstString class_name = ConstString(cstr);
+            m_isa_to_name_cache[isa] = class_name;
+            return class_name;
+        }
     }
     else
         return ConstString("unknown");
@@ -700,6 +714,12 @@
     if (isa == g_objc_Tagged_ISA)
         return 0;
     
+    ISAToParentIterator found = m_isa_to_parent_cache.find(isa);
+    ISAToParentIterator end = m_isa_to_parent_cache.end();
+    
+    if (found != end)
+        return found->second;
+    
     uint8_t pointer_size = m_process->GetAddressByteSize();
     Error error;
     lldb::addr_t parent_pointer = isa + pointer_size;
@@ -711,6 +731,9 @@
                                                                     error);
     if (error.Fail())
         return 0;
+    
+    m_isa_to_parent_cache[isa] = parent_isa;
+    
     return parent_isa;
 }
 

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h?rev=137612&r1=137611&r2=137612&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Mon Aug 15 10:56:02 2011
@@ -12,6 +12,9 @@
 
 // C Includes
 // C++ Includes
+
+#include <map>
+
 // Other libraries and framework includes
 // Project includes
 #include "lldb/lldb-private.h"
@@ -100,6 +103,13 @@
 protected:
     
 private:
+    
+    typedef std::map<ObjCISA,ConstString> ISAToNameCache;
+    typedef std::map<ObjCISA,ObjCISA> ISAToParentCache;
+    
+    typedef ISAToNameCache::iterator ISAToNameIterator;
+    typedef ISAToParentCache::iterator ISAToParentIterator;
+    
     AppleObjCRuntimeV2(Process *process, ModuleSP &objc_module_sp);
     
     bool
@@ -113,6 +123,9 @@
     lldb::addr_t                        m_get_class_name_args;
     Mutex                               m_get_class_name_args_mutex;
     
+    ISAToNameCache                      m_isa_to_name_cache;
+    ISAToParentCache                    m_isa_to_parent_cache;
+    
     static const char *g_find_class_name_function_name;
     static const char *g_find_class_name_function_body;
     static const char *g_objc_class_symbol_prefix;





More information about the lldb-commits mailing list