Bug 1438688, part 2b - Eliminate XPTHeader data structure. r=njn
☠☠ backed out by 70400746eb53 ☠ ☠
authorAndrew McCreight <continuation@gmail.com>
Tue, 27 Mar 2018 14:04:01 -0700
changeset 411395 4da0e1839353bcfbd378ecf842b102a2641682c6
parent 411394 186f916dcc7aabfea7981702c47c666338fcf869
child 411396 2f243bca1af344ee781aaa616147016b26d74693
push id101643
push userdluca@mozilla.com
push dateTue, 03 Apr 2018 04:25:27 +0000
treeherdermozilla-inbound@ac667545d8aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1438688
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1438688, part 2b - Eliminate XPTHeader data structure. r=njn Now that there is only one XPTHeader, we can devolve the fields in it to avoid some indirection. The biggest part here is getting rid of the mHeader field on xptiTypelibGuts. The array is [] instead of * to avoid a relocation, by ensuring that XPTHeader::kInterfaceDirectory as well as the data it points to cannot be changed. MozReview-Commit-ID: AzvNTNZKkfi
xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
xpcom/reflect/xptinfo/xptiprivate.h
xpcom/typelib/xpt/xpt_struct.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -76,21 +76,21 @@ XPTInterfaceInfoManager::FreeInterfaceIn
 {
     gInterfaceInfoManager = nullptr;
 }
 
 XPTInterfaceInfoManager::XPTInterfaceInfoManager()
     :   mWorkingSet(),
         mResolveLock("XPTInterfaceInfoManager.mResolveLock")
 {
-    xptiTypelibGuts* typelib = xptiTypelibGuts::Create(&XPTHeader::kHeader);
+    xptiTypelibGuts* typelib = xptiTypelibGuts::Create();
 
     ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
-    for (uint16_t k = 0; k < XPTHeader::kHeader.mNumInterfaces; k++) {
-        VerifyAndAddEntryIfNew(XPTHeader::kHeader.mInterfaceDirectory + k, k, typelib);
+    for (uint16_t k = 0; k < XPTHeader::kNumInterfaces; k++) {
+        VerifyAndAddEntryIfNew(XPTHeader::kInterfaceDirectory + k, k, typelib);
     }
 }
 
 XPTInterfaceInfoManager::~XPTInterfaceInfoManager()
 {
     // We only do this on shutdown of the service.
     mWorkingSet.InvalidateInterfaceInfos();
 
--- a/xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
+++ b/xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
@@ -15,41 +15,39 @@ using namespace mozilla;
 template <class T>
 class MOZ_NEEDS_NO_VTABLE_TYPE CheckNoVTable
 {
 };
 CheckNoVTable<xptiTypelibGuts> gChecker;
 
 // static
 xptiTypelibGuts*
-xptiTypelibGuts::Create(const XPTHeader* aHeader)
+xptiTypelibGuts::Create()
 {
-    NS_ASSERTION(aHeader, "bad param");
     size_t n = sizeof(xptiTypelibGuts) +
-               sizeof(xptiInterfaceEntry*) * (aHeader->mNumInterfaces - 1);
+               sizeof(xptiInterfaceEntry*) * (XPTHeader::kNumInterfaces - 1);
     void* place = XPT_CALLOC8(gXPTIStructArena, n);
     if (!place)
         return nullptr;
-    return new(place) xptiTypelibGuts(aHeader);
+    return new(place) xptiTypelibGuts();
 }
 
 xptiInterfaceEntry*
 xptiTypelibGuts::GetEntryAt(uint16_t i)
 {
     static const nsID zeroIID =
         { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
 
-    NS_ASSERTION(mHeader, "bad state");
     NS_ASSERTION(i < GetEntryCount(), "bad index");
 
     xptiInterfaceEntry* r = mEntryArray[i];
     if (r)
         return r;
 
-    const XPTInterfaceDirectoryEntry* iface = mHeader->mInterfaceDirectory + i;
+    const XPTInterfaceDirectoryEntry* iface = XPTHeader::kInterfaceDirectory + i;
 
     XPTInterfaceInfoManager::xptiWorkingSet& set =
         XPTInterfaceInfoManager::GetSingleton()->mWorkingSet;
 
     {
         ReentrantMonitorAutoEnter monitor(set.mTableReentrantMonitor);
         if (iface->mIID.Equals(zeroIID))
             r = set.mNameTable.Get(iface->Name());
@@ -61,15 +59,14 @@ xptiTypelibGuts::GetEntryAt(uint16_t i)
         SetEntryAt(i, r);
 
     return r;
 }
 
 const char*
 xptiTypelibGuts::GetEntryNameAt(uint16_t i)
 {
-    NS_ASSERTION(mHeader, "bad state");
     NS_ASSERTION(i < GetEntryCount(), "bad index");
 
-    const XPTInterfaceDirectoryEntry* iface = mHeader->mInterfaceDirectory + i;
+    const XPTInterfaceDirectoryEntry* iface = XPTHeader::kInterfaceDirectory + i;
 
     return iface->Name();
 }
--- a/xpcom/reflect/xptinfo/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/xptiprivate.h
@@ -70,38 +70,34 @@ extern XPTArena* gXPTIStructArena;
 
 // No virtuals.
 // These are always constructed in the struct arena using placement new.
 // dtor need not be called.
 
 class xptiTypelibGuts
 {
 public:
-    static xptiTypelibGuts* Create(const XPTHeader* aHeader);
+    static xptiTypelibGuts* Create();
 
-    uint16_t GetEntryCount() const {return mHeader->mNumInterfaces;}
+    uint16_t GetEntryCount() const { return XPTHeader::kNumInterfaces; }
 
     void                SetEntryAt(uint16_t i, xptiInterfaceEntry* ptr)
     {
-        NS_ASSERTION(mHeader,"bad state!");
         NS_ASSERTION(i < GetEntryCount(),"bad param!");
         mEntryArray[i] = ptr;
     }
 
     xptiInterfaceEntry* GetEntryAt(uint16_t i);
     const char* GetEntryNameAt(uint16_t i);
 
 private:
-    explicit xptiTypelibGuts(const XPTHeader* aHeader)
-        : mHeader(aHeader)
-    { }
+    xptiTypelibGuts() = default;
     ~xptiTypelibGuts();
 
 private:
-    const XPTHeader*     mHeader;        // hold pointer into arena
     xptiInterfaceEntry*  mEntryArray[1]; // Always last. Sized to fit.
 };
 
 /***************************************************************************/
 
 /***************************************************************************/
 
 // This class exists to help xptiInterfaceInfo store a 4-state (2 bit) value
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -20,20 +20,18 @@ struct XPTInterfaceDirectoryEntry;
 struct XPTInterfaceDescriptor;
 struct XPTConstDescriptor;
 struct XPTMethodDescriptor;
 struct XPTParamDescriptor;
 struct XPTTypeDescriptor;
 struct XPTTypeDescriptorPrefix;
 
 struct XPTHeader {
-  uint16_t mNumInterfaces;
-  const XPTInterfaceDirectoryEntry* mInterfaceDirectory;
-
-  static const XPTHeader kHeader;
+  static const uint16_t kNumInterfaces;
+  static const XPTInterfaceDirectoryEntry kInterfaceDirectory[];
 };
 
 /*
  * An array of directory entries is used to quickly locate an interface
  * description using its IID. No interface should appear more than once in the
  * array.
  */
 struct XPTInterfaceDirectoryEntry {