Objective-C runtime now caches resolved ISA information for increased efficiency

llvm-svn: 137612
This commit is contained in:
Enrico Granata 2011-08-15 15:56:02 +00:00
parent 3ec7910e10
commit d0b8505a64
2 changed files with 39 additions and 3 deletions

View File

@ -94,7 +94,9 @@ const char *AppleObjCRuntimeV2::g_objc_class_data_section_name = "__objc_data";
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 @@ AppleObjCRuntimeV2::GetActualTypeName(lldb_private::ObjCLanguageRuntime::ObjCISA
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 @@ AppleObjCRuntimeV2::GetActualTypeName(lldb_private::ObjCLanguageRuntime::ObjCISA
// 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 @@ AppleObjCRuntimeV2::GetParentClass(lldb_private::ObjCLanguageRuntime::ObjCISA is
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 @@ AppleObjCRuntimeV2::GetParentClass(lldb_private::ObjCLanguageRuntime::ObjCISA is
error);
if (error.Fail())
return 0;
m_isa_to_parent_cache[isa] = parent_isa;
return parent_isa;
}

View File

@ -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 @@ public:
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 @@ private:
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;