Bug 847210 - Remove nsNodeInfo::sNodeInfoPool and use vanilla allocation for nsNodeInfo objects. r=smaug.

--HG--
extra : rebase_source : 667a818984e7ce6d22669861992a06e832755dfb
This commit is contained in:
Nicholas Nethercote 2013-02-28 18:53:49 -08:00
parent ba31d85ba5
commit f0c8853de6
11 changed files with 21 additions and 95 deletions

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

View File

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=79: */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -2032,7 +2032,7 @@ nsINode::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
// - mNodeInfo (Nb: allocated in nsNodeInfo.cpp with a nsFixedSizeAllocator)
// - mNodeInfo
// - mSlots
//
// The following members are not measured:

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -24,7 +25,6 @@
#include "nsReadableUtils.h"
#include "nsAutoPtr.h"
#include NEW_H
#include "nsFixedSizeAllocator.h"
#include "prprf.h"
#include "nsIDocument.h"
#include "nsGkAtoms.h"
@ -32,43 +32,6 @@
using namespace mozilla;
static const size_t kNodeInfoPoolSizes[] = {
sizeof(nsNodeInfo)
};
static const int32_t kNodeInfoPoolInitialSize = sizeof(nsNodeInfo) * 64;
// static
nsFixedSizeAllocator* nsNodeInfo::sNodeInfoPool = nullptr;
// static
nsNodeInfo*
nsNodeInfo::Create(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID,
uint16_t aNodeType, nsIAtom *aExtraName,
nsNodeInfoManager *aOwnerManager)
{
if (!sNodeInfoPool) {
sNodeInfoPool = new nsFixedSizeAllocator();
if (!sNodeInfoPool)
return nullptr;
nsresult rv = sNodeInfoPool->Init("NodeInfo Pool", kNodeInfoPoolSizes,
1, kNodeInfoPoolInitialSize);
if (NS_FAILED(rv)) {
delete sNodeInfoPool;
sNodeInfoPool = nullptr;
return nullptr;
}
}
// Create a new one
void* place = sNodeInfoPool->Alloc(sizeof(nsNodeInfo));
return place ?
new (place) nsNodeInfo(aName, aPrefix, aNamespaceID, aNodeType, aExtraName,
aOwnerManager) :
nullptr;
}
nsNodeInfo::~nsNodeInfo()
{
mOwnerManager->RemoveNodeInfo(this);
@ -234,28 +197,11 @@ nsNodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const
return nsINodeInfo::NamespaceEquals(nsid);
}
// static
void
nsNodeInfo::ClearCache()
{
// Clear our cache.
delete sNodeInfoPool;
sNodeInfoPool = nullptr;
}
void
nsNodeInfo::LastRelease()
{
nsRefPtr<nsNodeInfoManager> kungFuDeathGrip = mOwnerManager;
this->~nsNodeInfo();
// The refcount balancing and destructor re-entrancy protection
// code in Release() sets mRefCnt to 1 so we have to set it to 0
// here to prevent leaks
mRefCnt = 0;
NS_ASSERTION(sNodeInfoPool, "No NodeInfoPool when deleting NodeInfo!!!");
sNodeInfoPool->Free(this, sizeof(nsNodeInfo));
delete this;
}
bool

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -20,8 +21,6 @@
#include "nsIDOMNode.h"
#include "nsGkAtoms.h"
class nsFixedSizeAllocator;
class nsNodeInfo : public nsINodeInfo
{
public:
@ -33,39 +32,27 @@ public:
virtual bool NamespaceEquals(const nsAString& aNamespaceURI) const;
// nsNodeInfo
// Create objects with Create
public:
/*
* aName and aOwnerManager may not be null.
*/
static nsNodeInfo *Create(nsIAtom *aName, nsIAtom *aPrefix,
int32_t aNamespaceID, uint16_t aNodeType,
nsIAtom *aExtraName,
nsNodeInfoManager *aOwnerManager);
private:
nsNodeInfo(); // Unimplemented
nsNodeInfo(const nsNodeInfo& aOther); // Unimplemented
nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID,
uint16_t aNodeType, nsIAtom *aExtraName,
nsNodeInfoManager *aOwnerManager);
private:
nsNodeInfo(); // Unimplemented
nsNodeInfo(const nsNodeInfo& aOther); // Unimplemented
protected:
virtual ~nsNodeInfo();
public:
/**
* Call before shutdown to clear the cache and free memory for this class.
*/
static void ClearCache();
bool CanSkip();
private:
static nsFixedSizeAllocator* sNodeInfoPool;
/**
* This method gets called by Release() when it's time to delete
* this object, instead of always deleting the object we'll put the
* object in the cache unless the cache is already full.
* This method gets called by Release() when it's time to delete
* this object.
*/
void LastRelease();
};

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -220,10 +221,9 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
}
nsRefPtr<nsNodeInfo> newNodeInfo =
nsNodeInfo::Create(aName, aPrefix, aNamespaceID, aNodeType, aExtraName,
this);
new nsNodeInfo(aName, aPrefix, aNamespaceID, aNodeType, aExtraName, this);
NS_ENSURE_TRUE(newNodeInfo, nullptr);
PLHashEntry *he;
he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
NS_ENSURE_TRUE(he, nullptr);
@ -266,13 +266,11 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
return NS_OK;
}
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsNodeInfo> newNodeInfo =
nsNodeInfo::Create(nameAtom, aPrefix, aNamespaceID, aNodeType, nullptr,
this);
new nsNodeInfo(nameAtom, aPrefix, aNamespaceID, aNodeType, nullptr, this);
NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);
PLHashEntry *he;

View File

@ -7,7 +7,6 @@
#define nsContentSupportMap_h__
#include "pldhash.h"
#include "nsFixedSizeAllocator.h"
#include "nsTemplateMatch.h"
/**

View File

@ -8,7 +8,6 @@
#include "nscore.h"
#include "nsRuleNetwork.h"
#include "nsFixedSizeAllocator.h"
#include "nsIAtom.h"
#include "nsIDOMDocument.h"

View File

@ -7,7 +7,6 @@
#define nsRDFConInstanceTestNode_h__
#include "nscore.h"
#include "nsFixedSizeAllocator.h"
#include "nsRDFTestNode.h"
#include "nsIRDFResource.h"
#include "nsIRDFDataSource.h"

View File

@ -18,7 +18,6 @@
#include "nsICollation.h"
#include "nsCollationCID.h"
#include "nsFixedSizeAllocator.h"
#include "nsResourceSet.h"
#include "nsRuleNetwork.h"
#include "nsRDFQuery.h"

View File

@ -6,7 +6,6 @@
#ifndef nsXULTemplateResultSetRDF_h__
#define nsXULTemplateResultSetRDF_h__
#include "nsFixedSizeAllocator.h"
#include "nsISimpleEnumerator.h"
#include "nsRuleNetwork.h"
#include "nsRDFQuery.h"

View File

@ -330,7 +330,6 @@ nsLayoutStatics::Shutdown()
nsAttrValue::Shutdown();
nsContentUtils::Shutdown();
nsNodeInfo::ClearCache();
nsLayoutStylesheetCache::Shutdown();
NS_NameSpaceManagerShutdown();