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

Sean Callanan scallanan at apple.com
Tue Oct 9 14:21:35 PDT 2012


Author: spyffe
Date: Tue Oct  9 16:21:35 2012
New Revision: 165549

URL: http://llvm.org/viewvc/llvm-project?rev=165549&view=rev
Log:
Cleanup in the AppleObjCRuntimeV2 to make descriptors
lighter-weight so that the cache can be populated
faster.

- I Added a ProcessWP to the runtime so I can
  take it out of the individual descriptors, saving
  space;
- I made the constructors for the descriptors
  private so that only the runtime can invoke them; 
  and
- I removed the constructor that takes a ValueObject
  since the logic for using a ValueObject is in the
  runtime.

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=165549&r1=165548&r2=165549&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Tue Oct  9 16:21:35 2012
@@ -107,7 +107,8 @@
                                         const ModuleSP &objc_module_sp) : 
     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_process_wp (process->shared_from_this())
 {
     static const ConstString g_gdb_object_getClass("gdb_object_getClass");
     m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, eSymbolTypeCode) != NULL);
@@ -973,28 +974,12 @@
 class ClassDescriptorV2 : public ObjCLanguageRuntime::ClassDescriptor
 {
 public:
-    ClassDescriptorV2 (ObjCLanguageRuntime &runtime, ValueObject &ptr_to_object) :
-        m_runtime (runtime),
-        m_valid (false),
-        m_objc_class_ptr (0),
-        m_objc_class (),
-        m_name (),
-        m_instance_size (0),
-        m_realized (eLazyBoolCalculate),
-        m_process_wp ()
-    {
-        lldb::addr_t object_ptr = ptr_to_object.GetValueAsUnsigned(0);
-        lldb::ProcessSP process_sp = ptr_to_object.GetProcessSP();
-        
-        Error error;
-        ObjCLanguageRuntime::ObjCISA isa = process_sp->ReadPointerFromMemory(object_ptr,
-                                                                             error);
-        
-        if (isa != LLDB_INVALID_ADDRESS)
-            Initialize (isa, process_sp);
-    }
+    friend class lldb_private::AppleObjCRuntimeV2;
     
-    ClassDescriptorV2 (ObjCLanguageRuntime &runtime, ObjCLanguageRuntime::ObjCISA isa, lldb::ProcessSP process_sp) :
+private:
+    // The constructor should only be invoked by the runtime as it builds its caches
+    // or populates them.  A ClassDescriptorV2 should only ever exist in a cache.
+    ClassDescriptorV2 (AppleObjCRuntimeV2 &runtime, ObjCLanguageRuntime::ObjCISA isa) :
         m_runtime (runtime),
         m_valid (false),
         m_objc_class_ptr (0),
@@ -1004,9 +989,10 @@
         m_realized (eLazyBoolCalculate),
         m_process_wp ()
     {
-        Initialize (isa, process_sp);
+        Initialize (isa, m_runtime.GetProcessSP());
     }
     
+public:
     virtual ConstString
     GetClassName ()
     {
@@ -1062,7 +1048,7 @@
         if (!m_valid)
             return ObjCLanguageRuntime::ClassDescriptorSP();
         
-        return m_runtime.GetClassDescriptor(m_objc_class.m_superclass);
+        return m_runtime.ObjCLanguageRuntime::GetClassDescriptor(m_objc_class.m_superclass);
     }
     
     virtual bool
@@ -1178,7 +1164,7 @@
         
         if (class_method_func)
         {
-            ObjCLanguageRuntime::ClassDescriptorSP metaclass = m_runtime.GetClassDescriptor(m_objc_class.m_isa);
+            ObjCLanguageRuntime::ClassDescriptorSP metaclass = m_runtime.ObjCLanguageRuntime::GetClassDescriptor(m_objc_class.m_isa);
             
             // We don't care about the metaclass's superclass, or its class methods.  Its instance methods are
             // our class methods.
@@ -1590,7 +1576,7 @@
         }
     };
 
-    ObjCLanguageRuntime &m_runtime;         // The runtime, so we can read our metaclass.
+    AppleObjCRuntimeV2 &m_runtime;          // The runtime, so we can read our metaclass.
     bool                m_valid;            // Gates whether we trust anything here at all.
     lldb::addr_t        m_objc_class_ptr;   // The address of the objc_class_t.
     objc_class_t        m_objc_class;
@@ -1800,7 +1786,7 @@
 {
     ClassDescriptorSP objc_class_sp;
     if (isa != 0)
-        objc_class_sp.reset (new ClassDescriptorV2(*this, isa, m_process->CalculateProcess()));
+        objc_class_sp.reset (new ClassDescriptorV2(*this, isa));
     return objc_class_sp;
 }
 
@@ -1904,7 +1890,7 @@
             if (m_isa_to_descriptor_cache.count(elt.second))
                 continue;
             
-            ClassDescriptorSP descriptor_sp = ClassDescriptorSP(new ClassDescriptorV2(*this, elt.second, process_sp));
+            ClassDescriptorSP descriptor_sp = ClassDescriptorSP(new ClassDescriptorV2(*this, elt.second));
             
             if (log && log->GetVerbose())
                 log->Printf("AppleObjCRuntimeV2 added (ObjCISA)0x%llx (%s) from dynamic table to isa->descriptor cache", elt.second, elt.first.AsCString());
@@ -1950,7 +1936,7 @@
             if (m_isa_to_descriptor_cache.count(objc_isa))
                 continue;
             
-            ClassDescriptorSP descriptor_sp = ClassDescriptorSP(new ClassDescriptorV2(*this, objc_isa, process_sp));
+            ClassDescriptorSP descriptor_sp = ClassDescriptorSP(new ClassDescriptorV2(*this, objc_isa));
             
             if (log && log->GetVerbose())
                 log->Printf("AppleObjCRuntimeV2 added (ObjCISA)0x%llx (%s) from static table to isa->descriptor cache", objc_isa, descriptor_sp->GetClassName().AsCString());

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=165549&r1=165548&r2=165549&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Tue Oct  9 16:21:35 2012
@@ -110,6 +110,12 @@
     virtual TypeVendor *
     GetTypeVendor();
     
+    lldb::ProcessSP
+    GetProcessSP ()
+    {
+        return m_process_wp.lock();
+    }
+    
 protected:
     virtual lldb::BreakpointResolverSP
     CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp);
@@ -131,6 +137,7 @@
     Mutex                               m_get_class_name_args_mutex;
     
     std::auto_ptr<TypeVendor>           m_type_vendor_ap;
+    lldb::ProcessWP                     m_process_wp; // used by class descriptors to lazily fill their own data
     
     static const char *g_find_class_name_function_name;
     static const char *g_find_class_name_function_body;





More information about the lldb-commits mailing list