Bug 798158 - Part 1: Use a pointer-sized type to store refcounts internally; r=bsmedberg
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 27 Mar 2014 16:38:33 -0400
changeset 175813 ad7d8b0efb321de10f2ac7191e32ff6e278c84f9
parent 175812 be95c2506ad8e0a0d142729abcd5af2aa4f3fdbe
child 175814 7cad4bd4bfe5d83bfdbf165c0a3d70f14b1cb6d5
push id26500
push userkwierso@gmail.com
push dateFri, 28 Mar 2014 23:16:18 +0000
treeherdermozilla-central@88ae1bfaaf3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs798158
milestone31.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 798158 - Part 1: Use a pointer-sized type to store refcounts internally; r=bsmedberg
accessible/src/base/NotificationController.h
caps/include/nsPrincipal.h
caps/src/nsNullPrincipal.cpp
caps/src/nsPrincipal.cpp
caps/src/nsSystemPrincipal.cpp
content/base/src/Comment.cpp
content/base/src/DocumentFragment.cpp
content/base/src/Element.cpp
content/base/src/nsDocument.cpp
content/base/src/nsTextNode.cpp
content/media/SharedThreadPool.cpp
content/media/SharedThreadPool.h
content/media/webaudio/AudioNode.cpp
content/media/webaudio/AudioParam.cpp
content/media/webaudio/AudioParam.h
content/xml/content/src/CDATASection.cpp
content/xml/content/src/ProcessingInstruction.cpp
content/xul/templates/src/nsXMLBinding.h
dom/asmjscache/AsmJSCache.cpp
dom/devicestorage/DeviceStorageRequestParent.h
dom/file/FileHelper.h
dom/file/FileService.h
dom/indexedDB/AsyncConnectionHelper.cpp
dom/indexedDB/Client.h
dom/indexedDB/IDBTransaction.cpp
dom/indexedDB/IDBTransaction.h
dom/network/src/TCPServerSocketChild.cpp
dom/network/src/TCPServerSocketChild.h
dom/network/src/TCPSocketChild.cpp
dom/network/src/TCPSocketChild.h
dom/network/src/TCPSocketParent.cpp
dom/network/src/TCPSocketParent.h
dom/network/src/UDPSocketChild.cpp
dom/network/src/UDPSocketChild.h
dom/quota/AcquireListener.h
dom/quota/Client.h
dom/smil/nsSMILAnimationController.h
dom/src/storage/DOMStorageCache.h
dom/src/storage/DOMStorageIPC.cpp
dom/src/storage/DOMStorageIPC.h
dom/xslt/xslt/txStylesheetCompiler.h
editor/txmgr/src/nsTransactionItem.h
embedding/components/printingui/src/win/nsPrintProgress.cpp
intl/unicharutil/src/nsCaseConversionImp2.cpp
intl/unicharutil/src/nsCategoryImp.cpp
ipc/testshell/XPCShellEnvironment.cpp
js/xpconnect/idl/nsIXPCScriptable.idl
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCShellImpl.cpp
js/xpconnect/src/XPCWrappedJS.cpp
layout/base/nsRefreshDriver.h
layout/style/nsDOMCSSDeclaration.h
media/mtransport/nr_socket_prsock.h
mfbt/RefCountType.h
modules/libjar/nsJAR.cpp
modules/libjar/nsZipArchive.h
netwerk/base/src/nsSocketTransport2.cpp
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache2/CacheFileChunk.cpp
netwerk/cache2/CacheFileIOManager.cpp
netwerk/cache2/CacheFileInputStream.cpp
netwerk/cache2/CacheFileOutputStream.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/nsHttpConnectionMgr.cpp
netwerk/protocol/http/nsHttpTransaction.cpp
netwerk/protocol/websocket/BaseWebSocketChannel.h
netwerk/protocol/websocket/WebSocketChannelChild.cpp
parser/html/nsHtml5Atom.cpp
storage/src/mozStorageAsyncStatement.cpp
storage/src/mozStorageAsyncStatementJSHelper.cpp
storage/src/mozStorageConnection.cpp
storage/src/mozStorageStatement.cpp
storage/src/mozStorageStatementJSHelper.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsXREDirProvider.cpp
toolkit/xre/nsXREDirProvider.h
view/src/nsView.cpp
xpcom/base/nsAgg.h
xpcom/base/nsDebugImpl.cpp
xpcom/base/nsISupportsBase.h
xpcom/base/nsMemoryImpl.cpp
xpcom/base/nsMemoryImpl.h
xpcom/base/nsTraceRefcnt.cpp
xpcom/components/nsCategoryManager.cpp
xpcom/ds/nsAtomTable.cpp
xpcom/ds/nsExpirationTracker.h
xpcom/glue/nsClassInfoImpl.cpp
xpcom/glue/nsEnumeratorUtils.cpp
xpcom/glue/nsISupportsImpl.h
xpcom/io/nsPipe3.cpp
xpcom/io/nsUnicharInputStream.cpp
xpcom/reflect/xptcall/src/xptcall.cpp
xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
xpcom/tests/TestCOMArray.cpp
xpcom/tests/TestCOMPtr.cpp
xpcom/tests/TestHarness.h
xpcom/tests/TestHashtables.cpp
xpcom/tests/TestRefPtr.cpp
xpcom/tests/windows/TestCOM.cpp
xpcom/threads/LazyIdleThread.cpp
xpcom/threads/nsThread.cpp
xpcom/threads/nsThreadManager.cpp
xpcom/threads/nsTimerImpl.cpp
--- a/accessible/src/base/NotificationController.h
+++ b/accessible/src/base/NotificationController.h
@@ -84,18 +84,18 @@ private:
  */
 class NotificationController : public EventQueue,
                                public nsARefreshObserver
 {
 public:
   NotificationController(DocAccessible* aDocument, nsIPresShell* aPresShell);
   virtual ~NotificationController();
 
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
 
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(NotificationController)
 
   /**
    * Shutdown the notification controller.
    */
   void Shutdown();
 
--- a/caps/include/nsPrincipal.h
+++ b/caps/include/nsPrincipal.h
@@ -23,18 +23,18 @@ class nsBasePrincipal : public nsJSPrinc
 {
 public:
   nsBasePrincipal();
 
 protected:
   virtual ~nsBasePrincipal();
 
 public:
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
   NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
   NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
 public:
 
   static const char sInvalid[];
 
 protected:
 
--- a/caps/src/nsNullPrincipal.cpp
+++ b/caps/src/nsNullPrincipal.cpp
@@ -30,26 +30,26 @@ NS_IMPL_CLASSINFO(nsNullPrincipal, nullp
                   NS_NULLPRINCIPAL_CID)
 NS_IMPL_QUERY_INTERFACE2_CI(nsNullPrincipal,
                             nsIPrincipal,
                             nsISerializable)
 NS_IMPL_CI_INTERFACE_GETTER2(nsNullPrincipal,
                              nsIPrincipal,
                              nsISerializable)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsNullPrincipal::AddRef()
 {
   NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
   nsrefcnt count = ++refcount;
   NS_LOG_ADDREF(this, count, "nsNullPrincipal", sizeof(*this));
   return count;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsNullPrincipal::Release()
 {
   NS_PRECONDITION(0 != refcount, "dup release");
   nsrefcnt count = --refcount;
   NS_LOG_RELEASE(this, count, "nsNullPrincipal");
   if (count == 0) {
     delete this;
   }
--- a/caps/src/nsPrincipal.cpp
+++ b/caps/src/nsPrincipal.cpp
@@ -41,27 +41,27 @@ static bool URIIsImmutable(nsIURI* aURI)
     mutableObj &&
     NS_SUCCEEDED(mutableObj->GetMutable(&isMutable)) &&
     !isMutable;
 }
 
 // Static member variables
 const char nsBasePrincipal::sInvalid[] = "Invalid";
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsBasePrincipal::AddRef()
 {
   NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
   // XXXcaa does this need to be threadsafe?  See bug 143559.
   nsrefcnt count = ++refcount;
   NS_LOG_ADDREF(this, count, "nsBasePrincipal", sizeof(*this));
   return count;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsBasePrincipal::Release()
 {
   NS_PRECONDITION(0 != refcount, "dup release");
   nsrefcnt count = --refcount;
   NS_LOG_RELEASE(this, count, "nsBasePrincipal");
   if (count == 0) {
     delete this;
   }
--- a/caps/src/nsSystemPrincipal.cpp
+++ b/caps/src/nsSystemPrincipal.cpp
@@ -24,26 +24,26 @@ NS_IMPL_CLASSINFO(nsSystemPrincipal, nul
                   NS_SYSTEMPRINCIPAL_CID)
 NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal,
                             nsIPrincipal,
                             nsISerializable)
 NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal,
                              nsIPrincipal,
                              nsISerializable)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsSystemPrincipal::AddRef()
 {
   NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
   nsrefcnt count = ++refcount;
   NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
   return count;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsSystemPrincipal::Release()
 {
   NS_PRECONDITION(0 != refcount, "dup release");
   nsrefcnt count = --refcount;
   NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
   if (count == 0) {
     delete this;
   }
--- a/content/base/src/Comment.cpp
+++ b/content/base/src/Comment.cpp
@@ -5,16 +5,17 @@
 
 /*
  * Implementations of DOM Core's nsIDOMComment node.
  */
 
 #include "nsCOMPtr.h"
 #include "mozilla/dom/Comment.h"
 #include "mozilla/dom/CommentBinding.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 using namespace mozilla;
 using namespace dom;
 
 namespace mozilla {
 namespace dom {
 
 Comment::~Comment()
@@ -44,17 +45,17 @@ Comment::CloneDataNode(nsINodeInfo *aNod
 
 #ifdef DEBUG
 void
 Comment::List(FILE* out, int32_t aIndent) const
 {
   int32_t indx;
   for (indx = aIndent; --indx >= 0; ) fputs("  ", out);
 
-  fprintf(out, "Comment@%p refcount=%d<!--", (void*)this, mRefCnt.get());
+  fprintf(out, "Comment@%p refcount=%" PRIuPTR "<!--", (void*)this, mRefCnt.get());
 
   nsAutoString tmp;
   ToCString(tmp, 0, mText.GetLength());
   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
 
   fputs("-->\n", out);
 }
 #endif
--- a/content/base/src/DocumentFragment.cpp
+++ b/content/base/src/DocumentFragment.cpp
@@ -13,16 +13,17 @@
 #include "nsNodeInfoManager.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsDOMString.h"
 #include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
 #include "mozilla/dom/DocumentFragmentBinding.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocument.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 namespace mozilla {
 namespace dom {
 
 JSObject*
 DocumentFragment::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return DocumentFragmentBinding::Wrap(aCx, aScope, this);
@@ -67,17 +68,17 @@ DocumentFragment::List(FILE* out, int32_
   int32_t indent;
   for (indent = aIndent; --indent >= 0; ) {
     fputs("  ", out);
   }
 
   fprintf(out, "DocumentFragment@%p", (void *)this);
 
   fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
-  fprintf(out, " refcount=%d<", mRefCnt.get());
+  fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
 
   nsIContent* child = GetFirstChild();
   if (child) {
     fputs("\n", out);
 
     for (; child; child = child->GetNextSibling()) {
       child->List(out, aIndent + 1);
     }
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -123,16 +123,17 @@
 #include "mozilla/CORSMode.h"
 #include "mozilla/dom/ShadowRoot.h"
 
 #include "nsStyledElement.h"
 #include "nsXBLService.h"
 #include "nsITextControlElement.h"
 #include "nsISupportsImpl.h"
 #include "mozilla/dom/DocumentFragment.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMETHODIMP
 Element::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
   NS_ASSERTION(aInstancePtr,
@@ -2194,17 +2195,17 @@ Element::List(FILE* out, int32_t aIndent
           static_cast<unsigned long long>(State().GetInternalValue()));
   fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
   if (IsCommonAncestorForRangeInSelection()) {
     nsRange::RangeHashTable* ranges =
       static_cast<nsRange::RangeHashTable*>(GetProperty(nsGkAtoms::range));
     fprintf(out, " ranges:%d", ranges ? ranges->Count() : 0);
   }
   fprintf(out, " primaryframe=%p", static_cast<void*>(GetPrimaryFrame()));
-  fprintf(out, " refcount=%d<", mRefCnt.get());
+  fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
 
   nsIContent* child = GetFirstChild();
   if (child) {
     fputs("\n", out);
     
     for (; child; child = child->GetNextSibling()) {
       child->List(out, aIndent + 1);
     }
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1778,17 +1778,17 @@ NS_INTERFACE_TABLE_HEAD(nsDocument)
   NS_INTERFACE_TABLE_END
   NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDocument)
   NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver,
                                  new nsNode3Tearoff(this))
 NS_INTERFACE_MAP_END
 
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDocument)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsDocument::Release()
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   NS_ASSERT_OWNINGTHREAD(nsDocument);
   nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(nsDocument)::Upcast(this);
   bool shouldDelete = false;
   nsrefcnt count = mRefCnt.decr(base, &shouldDelete);
   NS_LOG_RELEASE(this, count, "nsDocument");
--- a/content/base/src/nsTextNode.cpp
+++ b/content/base/src/nsTextNode.cpp
@@ -11,16 +11,17 @@
 #include "mozilla/dom/TextBinding.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsIDocument.h"
 #include "nsThreadUtils.h"
 #include "nsStubMutationObserver.h"
+#include "mozilla/IntegerPrintfMacros.h"
 #ifdef DEBUG
 #include "nsRange.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 /**
@@ -164,17 +165,17 @@ nsTextNode::List(FILE* out, int32_t aInd
   fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
   if (IsCommonAncestorForRangeInSelection()) {
     typedef nsTHashtable<nsPtrHashKey<nsRange> > RangeHashTable;
     RangeHashTable* ranges =
       static_cast<RangeHashTable*>(GetProperty(nsGkAtoms::range));
     fprintf(out, " ranges:%d", ranges ? ranges->Count() : 0);
   }
   fprintf(out, " primaryframe=%p", static_cast<void*>(GetPrimaryFrame()));
-  fprintf(out, " refcount=%d<", mRefCnt.get());
+  fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
 
   nsAutoString tmp;
   ToCString(tmp, 0, mText.GetLength());
   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
 
   fputs(">\n", out);
 }
 
--- a/content/media/SharedThreadPool.cpp
+++ b/content/media/SharedThreadPool.cpp
@@ -113,27 +113,27 @@ SharedThreadPool::Get(const nsCString& a
     NS_WARNING("Failed to set limits on thread pool");
   }
 
   MOZ_ASSERT(pool);
   RefPtr<SharedThreadPool> instance(pool);
   return instance.forget();
 }
 
-NS_IMETHODIMP_(nsrefcnt) SharedThreadPool::AddRef(void)
+NS_IMETHODIMP_(MozExternalRefCountType) SharedThreadPool::AddRef(void)
 {
   MOZ_ASSERT(sMonitor);
   ReentrantMonitorAutoEnter mon(*sMonitor);
   MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
   nsrefcnt count = ++mRefCnt;
   NS_LOG_ADDREF(this, count, "SharedThreadPool", sizeof(*this));
   return count;
 }
 
-NS_IMETHODIMP_(nsrefcnt) SharedThreadPool::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) SharedThreadPool::Release(void)
 {
   MOZ_ASSERT(sMonitor);
   bool dispatchShutdownEvent;
   {
     ReentrantMonitorAutoEnter mon(*sMonitor);
     nsrefcnt count = --mRefCnt;
     NS_LOG_RELEASE(this, count, "SharedThreadPool");
     if (count) {
--- a/content/media/SharedThreadPool.h
+++ b/content/media/SharedThreadPool.h
@@ -39,18 +39,18 @@ public:
   // *Must* be called on the main thread.
   static void SpinUntilShutdown();
 
   // We implement custom threadsafe AddRef/Release pair, that destroys the
   // the shared pool singleton when the refcount drops to 0. The addref/release
   // are implemented using locking, so it's not recommended that you use them
   // in a tight loop.
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
 
   // Forward behaviour to wrapped thread pool implementation.
   NS_FORWARD_SAFE_NSITHREADPOOL(mPool);
   NS_FORWARD_SAFE_NSIEVENTTARGET(GetEventTarget());
 
   nsIEventTarget* GetEventTarget() {
     return mEventTarget;
   }
@@ -82,9 +82,9 @@ private:
 
   // mPool QI'd to nsIEventTarget. We cache this, so that we can use
   // NS_FORWARD_SAFE_NSIEVENTTARGET above.
   nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 } // namespace mozilla
 
-#endif // SharedThreadPool_h_
\ No newline at end of file
+#endif // SharedThreadPool_h_
--- a/content/media/webaudio/AudioNode.cpp
+++ b/content/media/webaudio/AudioNode.cpp
@@ -27,17 +27,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AudioNode, nsDOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContext)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputNodes)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputParams)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(AudioNode, nsDOMEventTargetHelper)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 AudioNode::Release()
 {
   if (mRefCnt.get() == 1) {
     // We are about to be deleted, disconnect the object from the graph before
     // the derived type is destroyed.
     DisconnectFromGraph();
   }
   nsrefcnt r = nsDOMEventTargetHelper::Release();
--- a/content/media/webaudio/AudioParam.cpp
+++ b/content/media/webaudio/AudioParam.cpp
@@ -24,17 +24,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNode)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(AudioParam)
 
 NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(AudioParam)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 AudioParam::Release()
 {
   if (mRefCnt.get() == 1) {
     // We are about to be deleted, disconnect the object from the graph before
     // the derived type is destroyed.
     DisconnectFromGraphAndDestroyStream();
   }
   NS_IMPL_CC_NATIVE_RELEASE_BODY(AudioParam)
--- a/content/media/webaudio/AudioParam.h
+++ b/content/media/webaudio/AudioParam.h
@@ -26,18 +26,18 @@ class AudioParam MOZ_FINAL : public nsWr
 public:
   typedef void (*CallbackType)(AudioNode*);
 
   AudioParam(AudioNode* aNode,
              CallbackType aCallback,
              float aDefaultValue);
   virtual ~AudioParam();
 
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioParam)
 
   AudioContext* GetParentObject() const
   {
     return mNode->Context();
   }
 
   double DOMTimeToStreamTime(double aTime) const
--- a/content/xml/content/src/CDATASection.cpp
+++ b/content/xml/content/src/CDATASection.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "mozilla/dom/CDATASection.h"
 #include "mozilla/dom/CDATASectionBinding.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 namespace mozilla {
 namespace dom {
 
 CDATASection::~CDATASection()
 {
 }
 
@@ -43,17 +44,17 @@ CDATASection::CloneDataNode(nsINodeInfo 
 
 #ifdef DEBUG
 void
 CDATASection::List(FILE* out, int32_t aIndent) const
 {
   int32_t index;
   for (index = aIndent; --index >= 0; ) fputs("  ", out);
 
-  fprintf(out, "CDATASection refcount=%d<", mRefCnt.get());
+  fprintf(out, "CDATASection refcount=%" PRIuPTR "<", mRefCnt.get());
 
   nsAutoString tmp;
   ToCString(tmp, 0, mText.GetLength());
   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
 
   fputs(">\n", out);
 }
 
--- a/content/xml/content/src/ProcessingInstruction.cpp
+++ b/content/xml/content/src/ProcessingInstruction.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 #include "nsGkAtoms.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/dom/ProcessingInstruction.h"
 #include "mozilla/dom/ProcessingInstructionBinding.h"
 #include "mozilla/dom/XMLStylesheetProcessingInstruction.h"
+#include "mozilla/IntegerPrintfMacros.h"
 #include "nsContentUtils.h"
 
 already_AddRefed<mozilla::dom::ProcessingInstruction>
 NS_NewXMLProcessingInstruction(nsNodeInfoManager *aNodeInfoManager,
                                const nsAString& aTarget,
                                const nsAString& aData)
 {
   using mozilla::dom::ProcessingInstruction;
@@ -106,17 +107,17 @@ ProcessingInstruction::CloneDataNode(nsI
 
 #ifdef DEBUG
 void
 ProcessingInstruction::List(FILE* out, int32_t aIndent) const
 {
   int32_t index;
   for (index = aIndent; --index >= 0; ) fputs("  ", out);
 
-  fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());
+  fprintf(out, "Processing instruction refcount=%" PRIuPTR "<", mRefCnt.get());
 
   nsAutoString tmp;
   ToCString(tmp, 0, mText.GetLength());
   tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
 
   fputs(">\n", out);
 }
--- a/content/xul/templates/src/nsXMLBinding.h
+++ b/content/xul/templates/src/nsXMLBinding.h
@@ -51,18 +51,18 @@ public:
   // nsXMLBindingValues fields
   nsCycleCollectingAutoRefCnt mRefCnt;
 
   // pointer to the first binding in a linked list
   nsAutoPtr<nsXMLBinding> mFirst;
 
 public:
 
-  NS_METHOD_(nsrefcnt) AddRef();
-  NS_METHOD_(nsrefcnt) Release();
+  NS_METHOD_(MozExternalRefCountType) AddRef();
+  NS_METHOD_(MozExternalRefCountType) Release();
   NS_DECL_OWNINGTHREAD
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXMLBindingSet)
 
   /**
    * Add a binding to the set
    */
   nsresult
   AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr);
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -1721,20 +1721,20 @@ GetBuildId(JS::BuildIdCharVector* aBuild
   }
 
   return true;
 }
 
 class Client : public quota::Client
 {
 public:
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   AddRef() MOZ_OVERRIDE;
 
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   Release() MOZ_OVERRIDE;
 
   virtual Type
   GetType() MOZ_OVERRIDE
   {
     return ASMJS;
   }
 
--- a/dom/devicestorage/DeviceStorageRequestParent.h
+++ b/dom/devicestorage/DeviceStorageRequestParent.h
@@ -19,18 +19,18 @@ namespace mozilla {
 namespace dom {
 namespace devicestorage {
 
 class DeviceStorageRequestParent : public PDeviceStorageRequestParent
 {
 public:
   DeviceStorageRequestParent(const DeviceStorageParams& aParams);
 
-  NS_IMETHOD_(nsrefcnt) AddRef();
-  NS_IMETHOD_(nsrefcnt) Release();
+  NS_IMETHOD_(MozExternalRefCountType) AddRef();
+  NS_IMETHOD_(MozExternalRefCountType) Release();
 
   bool EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent);
   void Dispatch();
 
   virtual void ActorDestroy(ActorDestroyReason);
 
 protected:
   ~DeviceStorageRequestParent();
--- a/dom/file/FileHelper.h
+++ b/dom/file/FileHelper.h
@@ -18,20 +18,20 @@ BEGIN_FILE_NAMESPACE
 class FileHelper;
 class FileRequest;
 class FileOutputStreamWrapper;
 class LockedFile;
 
 class FileHelperListener
 {
 public:
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   AddRef() = 0;
 
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   Release() = 0;
 
   virtual void
   OnFileHelperComplete(FileHelper* aFileHelper) = 0;
 };
 
 /**
  * Must be subclassed. The subclass must implement DoAsyncRun. It may then
--- a/dom/file/FileService.h
+++ b/dom/file/FileService.h
@@ -64,20 +64,20 @@ public:
   }
 
 private:
   class LockedFileQueue MOZ_FINAL : public FileHelperListener
   {
     friend class FileService;
 
   public:
-    NS_IMETHOD_(nsrefcnt)
+    NS_IMETHOD_(MozExternalRefCountType)
     AddRef() MOZ_OVERRIDE;
 
-    NS_IMETHOD_(nsrefcnt)
+    NS_IMETHOD_(MozExternalRefCountType)
     Release() MOZ_OVERRIDE;
 
     inline nsresult
     Enqueue(FileHelper* aFileHelper);
 
     virtual void
     OnFileHelperComplete(FileHelper* aFileHelper) MOZ_OVERRIDE;
 
--- a/dom/indexedDB/AsyncConnectionHelper.cpp
+++ b/dom/indexedDB/AsyncConnectionHelper.cpp
@@ -625,24 +625,24 @@ AsyncConnectionHelper::ConvertToArrayAnd
   for (uint32_t index = 0; index < aReadInfos.Length(); index++) {
     aReadInfos[index].mCloneBuffer.clear();
   }
   aReadInfos.Clear();
 
   return rv;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 StackBasedEventTarget::AddRef()
 {
   NS_NOTREACHED("Don't call me!");
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 StackBasedEventTarget::Release()
 {
   NS_NOTREACHED("Don't call me!");
   return 1;
 }
 
 NS_IMETHODIMP
 StackBasedEventTarget::QueryInterface(REFNSIID aIID,
--- a/dom/indexedDB/Client.h
+++ b/dom/indexedDB/Client.h
@@ -17,20 +17,20 @@ BEGIN_INDEXEDDB_NAMESPACE
 
 class Client : public mozilla::dom::quota::Client
 {
   typedef mozilla::dom::quota::OriginOrPatternString OriginOrPatternString;
   typedef mozilla::dom::quota::PersistenceType PersistenceType;
   typedef mozilla::dom::quota::UsageInfo UsageInfo;
 
 public:
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   AddRef() MOZ_OVERRIDE;
 
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   Release() MOZ_OVERRIDE;
 
   virtual Type
   GetType() MOZ_OVERRIDE
   {
     return IDB;
   }
 
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -70,22 +70,22 @@ public:
   NS_IMETHOD Run()
   {
     // NOP
     return NS_OK;
   }
 };
 
 // Could really use those NS_REFCOUNTING_HAHA_YEAH_RIGHT macros here.
-NS_IMETHODIMP_(nsrefcnt) StartTransactionRunnable::AddRef()
+NS_IMETHODIMP_(MozExternalRefCountType) StartTransactionRunnable::AddRef()
 {
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt) StartTransactionRunnable::Release()
+NS_IMETHODIMP_(MozExternalRefCountType) StartTransactionRunnable::Release()
 {
   return 1;
 }
 
 NS_IMPL_QUERY_INTERFACE1(StartTransactionRunnable, nsIRunnable)
 
 } // anonymous namespace
 
--- a/dom/indexedDB/IDBTransaction.h
+++ b/dom/indexedDB/IDBTransaction.h
@@ -44,18 +44,18 @@ class IndexedDBTransactionChild;
 class IndexedDBTransactionParent;
 struct ObjectStoreInfo;
 class TransactionThreadPool;
 class UpdateRefcountFunction;
 
 class IDBTransactionListener
 {
 public:
-  NS_IMETHOD_(nsrefcnt) AddRef() = 0;
-  NS_IMETHOD_(nsrefcnt) Release() = 0;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
+  NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
 
   // Called just before dispatching the final events on the transaction.
   virtual nsresult NotifyTransactionPreComplete(IDBTransaction* aTransaction) = 0;
   // Called just after dispatching the final events on the transaction.
   virtual nsresult NotifyTransactionPostComplete(IDBTransaction* aTransaction) = 0;
 };
 
 class IDBTransaction : public IDBWrapperCache,
--- a/dom/network/src/TCPServerSocketChild.cpp
+++ b/dom/network/src/TCPServerSocketChild.cpp
@@ -29,17 +29,17 @@ TCPServerSocketChildBase::TCPServerSocke
 : mIPCOpen(false)
 {
 }
 
 TCPServerSocketChildBase::~TCPServerSocketChildBase()
 {
 }
 
-NS_IMETHODIMP_(nsrefcnt) TCPServerSocketChild::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void)
 {
   nsrefcnt refcnt = TCPServerSocketChildBase::Release();
   if (refcnt == 1 && mIPCOpen) {
     PTCPServerSocketChild::SendRequestDelete();
     return 1;
   }
   return refcnt;
 }
--- a/dom/network/src/TCPServerSocketChild.h
+++ b/dom/network/src/TCPServerSocketChild.h
@@ -31,17 +31,17 @@ protected:
   bool mIPCOpen;
 };
 
 class TCPServerSocketChild : public mozilla::net::PTCPServerSocketChild
                            , public TCPServerSocketChildBase
 {
 public:
   NS_DECL_NSITCPSERVERSOCKETCHILD
-  NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
+  NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
 
   TCPServerSocketChild();
   ~TCPServerSocketChild();
 
   virtual bool RecvCallbackAccept(PTCPSocketChild *socket)  MOZ_OVERRIDE;
   virtual bool RecvCallbackError(const nsString& aMessage,
                                  const nsString& aFilename,
                                  const uint32_t& aLineNumber,
--- a/dom/network/src/TCPSocketChild.cpp
+++ b/dom/network/src/TCPSocketChild.cpp
@@ -56,17 +56,17 @@ TCPSocketChildBase::TCPSocketChildBase()
 : mIPCOpen(false)
 {
 }
 
 TCPSocketChildBase::~TCPSocketChildBase()
 {
 }
 
-NS_IMETHODIMP_(nsrefcnt) TCPSocketChild::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) TCPSocketChild::Release(void)
 {
   nsrefcnt refcnt = TCPSocketChildBase::Release();
   if (refcnt == 1 && mIPCOpen) {
     PTCPSocketChild::SendRequestDelete();
     return 1;
   }
   return refcnt;
 }
--- a/dom/network/src/TCPSocketChild.h
+++ b/dom/network/src/TCPSocketChild.h
@@ -35,17 +35,17 @@ protected:
   bool mIPCOpen;
 };
 
 class TCPSocketChild : public mozilla::net::PTCPSocketChild
                      , public TCPSocketChildBase
 {
 public:
   NS_DECL_NSITCPSOCKETCHILD
-  NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
+  NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
 
   TCPSocketChild();
   ~TCPSocketChild();
 
   virtual bool RecvCallback(const nsString& aType,
                             const CallbackData& aData,
                             const nsString& aReadyState) MOZ_OVERRIDE;
   virtual bool RecvRequestDelete() MOZ_OVERRIDE;
--- a/dom/network/src/TCPSocketParent.cpp
+++ b/dom/network/src/TCPSocketParent.cpp
@@ -67,17 +67,17 @@ TCPSocketParentBase::ReleaseIPDLReferenc
 void
 TCPSocketParentBase::AddIPDLReference()
 {
   MOZ_ASSERT(!mIPCOpen);
   mIPCOpen = true;
   this->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt) TCPSocketParent::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) TCPSocketParent::Release(void)
 {
   nsrefcnt refcnt = TCPSocketParentBase::Release();
   if (refcnt == 1 && mIPCOpen) {
     mozilla::unused << PTCPSocketParent::SendRequestDelete();
     return 1;
   }
   return refcnt;
 }
--- a/dom/network/src/TCPSocketParent.h
+++ b/dom/network/src/TCPSocketParent.h
@@ -38,17 +38,17 @@ protected:
   bool mIPCOpen;
 };
 
 class TCPSocketParent : public mozilla::net::PTCPSocketParent
                       , public TCPSocketParentBase
 {
 public:
   NS_DECL_NSITCPSOCKETPARENT
-  NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
+  NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
 
   TCPSocketParent() : mIntermediaryObj(nullptr) {}
 
   virtual bool RecvOpen(const nsString& aHost, const uint16_t& aPort,
                         const bool& useSSL, const nsString& aBinaryType);
 
   virtual bool RecvStartTLS() MOZ_OVERRIDE;
   virtual bool RecvSuspend() MOZ_OVERRIDE;
--- a/dom/network/src/UDPSocketChild.cpp
+++ b/dom/network/src/UDPSocketChild.cpp
@@ -32,17 +32,17 @@ UDPSocketChildBase::ReleaseIPDLReference
 void
 UDPSocketChildBase::AddIPDLReference()
 {
   MOZ_ASSERT(!mIPCOpen);
   mIPCOpen = true;
   this->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt) UDPSocketChild::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) UDPSocketChild::Release(void)
 {
   nsrefcnt refcnt = UDPSocketChildBase::Release();
   if (refcnt == 1 && mIPCOpen) {
     PUDPSocketChild::SendRequestDelete();
     return 1;
   }
   return refcnt;
 }
--- a/dom/network/src/UDPSocketChild.h
+++ b/dom/network/src/UDPSocketChild.h
@@ -30,17 +30,17 @@ protected:
   bool mIPCOpen;
 };
 
 class UDPSocketChild : public mozilla::net::PUDPSocketChild
                      , public UDPSocketChildBase
 {
 public:
   NS_DECL_NSIUDPSOCKETCHILD
-  NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
+  NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
 
   UDPSocketChild();
   virtual ~UDPSocketChild();
 
   virtual bool RecvCallback(const nsCString& aType,
                             const UDPCallbackData& aData,
                             const nsCString& aState) MOZ_OVERRIDE;
 private:
--- a/dom/quota/AcquireListener.h
+++ b/dom/quota/AcquireListener.h
@@ -9,20 +9,20 @@
 
 #include "mozilla/dom/quota/QuotaCommon.h"
 
 BEGIN_QUOTA_NAMESPACE
 
 class AcquireListener
 {
 public:
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   AddRef() = 0;
 
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   Release() = 0;
 
   virtual nsresult
   OnExclusiveAccessAcquired() = 0;
 };
 
 END_QUOTA_NAMESPACE
 
--- a/dom/quota/Client.h
+++ b/dom/quota/Client.h
@@ -23,20 +23,20 @@ class OriginOrPatternString;
 class UsageInfo;
 
 // An abstract interface for quota manager clients.
 // Each storage API must provide an implementation of this interface in order
 // to participate in centralized quota and storage handling.
 class Client
 {
 public:
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   AddRef() = 0;
 
-  NS_IMETHOD_(nsrefcnt)
+  NS_IMETHOD_(MozExternalRefCountType)
   Release() = 0;
 
   enum Type {
     IDB = 0,
     //LS,
     //APPCACHE,
     ASMJS,
     TYPE_MAX
--- a/dom/smil/nsSMILAnimationController.h
+++ b/dom/smil/nsSMILAnimationController.h
@@ -51,18 +51,18 @@ public:
   void Disconnect();
 
   // nsSMILContainer
   virtual void Pause(uint32_t aType) MOZ_OVERRIDE;
   virtual void Resume(uint32_t aType) MOZ_OVERRIDE;
   virtual nsSMILTime GetParentTime() const MOZ_OVERRIDE;
 
   // nsARefreshObserver
-  NS_IMETHOD_(nsrefcnt) AddRef() MOZ_OVERRIDE;
-  NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE;
+  NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
 
   virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;
 
   // Methods for registering and enumerating animation elements
   void RegisterAnimationElement(mozilla::dom::SVGAnimationElement* aAnimationElement);
   void UnregisterAnimationElement(mozilla::dom::SVGAnimationElement* aAnimationElement);
 
   // Methods for resampling all animations
--- a/dom/src/storage/DOMStorageCache.h
+++ b/dom/src/storage/DOMStorageCache.h
@@ -24,17 +24,17 @@ class DOMStorageUsage;
 class DOMStorageManager;
 class DOMStorageDBBridge;
 
 // Interface class on which only the database or IPC may call.
 // Used to populate the cache with DB data.
 class DOMStorageCacheBridge
 {
 public:
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
   NS_IMETHOD_(void) Release(void);
 
   virtual ~DOMStorageCacheBridge() {}
 
   // The scope (origin) in the database usage format (reversed)
   virtual const nsCString& Scope() const = 0;
 
   // Whether the cache is already fully loaded
--- a/dom/src/storage/DOMStorageIPC.cpp
+++ b/dom/src/storage/DOMStorageIPC.cpp
@@ -17,17 +17,17 @@ namespace mozilla {
 namespace dom {
 
 // ----------------------------------------------------------------------------
 // Child
 // ----------------------------------------------------------------------------
 
 NS_IMPL_ADDREF(DOMStorageDBChild)
 
-NS_IMETHODIMP_(nsrefcnt) DOMStorageDBChild::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) DOMStorageDBChild::Release(void)
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "DOMStorageDBChild");
   if (count == 1 && mIPCOpen) {
     Send__delete__(this);
     return 0;
   }
--- a/dom/src/storage/DOMStorageIPC.h
+++ b/dom/src/storage/DOMStorageIPC.h
@@ -24,18 +24,18 @@ class DOMLocalStorageManager;
 // forwarded back to consumers on the child process.
 class DOMStorageDBChild MOZ_FINAL : public DOMStorageDBBridge
                                   , public PStorageChild
 {
 public:
   DOMStorageDBChild(DOMLocalStorageManager* aManager);
   virtual ~DOMStorageDBChild();
 
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
 
   void AddIPDLReference();
   void ReleaseIPDLReference();
 
   virtual nsresult Init();
   virtual nsresult Shutdown();
 
   virtual void AsyncPreload(DOMStorageCacheBridge* aCache, bool aPriority = false);
@@ -111,18 +111,18 @@ class DOMStorageDBParent MOZ_FINAL : pub
 public:
   DOMStorageDBParent();
   virtual ~DOMStorageDBParent();
 
   virtual mozilla::ipc::IProtocol*
   CloneProtocol(Channel* aChannel,
                 mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
 
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
 
   void AddIPDLReference();
   void ReleaseIPDLReference();
 
   bool IPCOpen() { return mIPCOpen; }
 
 public:
   // Fake cache class receiving async callbacks from DB thread, sending
--- a/dom/xslt/xslt/txStylesheetCompiler.h
+++ b/dom/xslt/xslt/txStylesheetCompiler.h
@@ -40,18 +40,18 @@ public:
     nsRefPtr<txNamespaceMap> mMappings;
     nsTArray<int32_t> mInstructionNamespaces;
     int32_t mDepth;
 };
 
 class txACompileObserver
 {
 public:
-    NS_IMETHOD_(nsrefcnt) AddRef() = 0;
-    NS_IMETHOD_(nsrefcnt) Release() = 0;
+    NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
+    NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
 
     virtual nsresult loadURI(const nsAString& aUri,
                              const nsAString& aReferrerUri,
                              txStylesheetCompiler* aCompiler) = 0;
     virtual void onDoneCompiling(txStylesheetCompiler* aCompiler,
                                  nsresult aResult,
                                  const char16_t *aErrorText = nullptr,
                                  const char16_t *aParam = nullptr) = 0;
--- a/editor/txmgr/src/nsTransactionItem.h
+++ b/editor/txmgr/src/nsTransactionItem.h
@@ -22,18 +22,18 @@ class nsTransactionItem
   nsCOMPtr<nsITransaction> mTransaction;
   nsTransactionStack      *mUndoStack;
   nsTransactionStack      *mRedoStack;
 
 public:
 
   nsTransactionItem(nsITransaction *aTransaction);
   virtual ~nsTransactionItem();
-  NS_METHOD_(nsrefcnt) AddRef();
-  NS_METHOD_(nsrefcnt) Release();
+  NS_METHOD_(MozExternalRefCountType) AddRef();
+  NS_METHOD_(MozExternalRefCountType) Release();
 
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsTransactionItem)
 
   virtual nsresult AddChild(nsTransactionItem *aTransactionItem);
   already_AddRefed<nsITransaction> GetTransaction();
   virtual nsresult GetIsBatch(bool *aIsBatch);
   virtual nsresult GetNumberOfChildren(int32_t *aNumChildren);
   virtual nsresult GetChild(int32_t aIndex, nsTransactionItem **aChild);
--- a/embedding/components/printingui/src/win/nsPrintProgress.cpp
+++ b/embedding/components/printingui/src/win/nsPrintProgress.cpp
@@ -11,26 +11,26 @@
 #include "nsISupportsPrimitives.h"
 #include "nsIComponentManager.h"
 #include "nsIServiceManager.h"
 
 #if 0
 NS_IMPL_ADDREF(nsPrintProgress)
 NS_IMPL_RELEASE(nsPrintProgress)
 #else
-NS_IMETHODIMP_(nsrefcnt) nsPrintProgress::AddRef(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsPrintProgress::AddRef(void)
 {
   NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
   nsrefcnt count;
   count = ++mRefCnt;
   //NS_LOG_ADDREF(this, count, "nsPrintProgress", sizeof(*this));
   return count;
 }
 
-NS_IMETHODIMP_(nsrefcnt) nsPrintProgress::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsPrintProgress::Release(void)
 {
   nsrefcnt count;
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   count = --mRefCnt;
   //NS_LOG_RELEASE(this, count, "nsPrintProgress");
   if (0 == count) {
     mRefCnt = 1; /* stabilize */
     /* enable this to find non-threadsafe destructors: */
--- a/intl/unicharutil/src/nsCaseConversionImp2.cpp
+++ b/intl/unicharutil/src/nsCaseConversionImp2.cpp
@@ -1,24 +1,24 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsCaseConversionImp2.h"
 #include "nsUnicharUtils.h"
 
-NS_IMETHODIMP_(nsrefcnt) nsCaseConversionImp2::AddRef(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsCaseConversionImp2::AddRef(void)
 {
-  return (nsrefcnt)1;
+  return (MozExternalRefCountType)1;
 }
 
-NS_IMETHODIMP_(nsrefcnt) nsCaseConversionImp2::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsCaseConversionImp2::Release(void)
 {
-  return (nsrefcnt)1;
+  return (MozExternalRefCountType)1;
 }
 
 NS_IMPL_QUERY_INTERFACE1(nsCaseConversionImp2, nsICaseConversion)
 
 NS_IMETHODIMP nsCaseConversionImp2::ToUpper(char16_t aChar, char16_t* aReturn)
 {
   *aReturn = ToUpperCase(aChar);
   return NS_OK;
--- a/intl/unicharutil/src/nsCategoryImp.cpp
+++ b/intl/unicharutil/src/nsCategoryImp.cpp
@@ -5,24 +5,24 @@
 
 #include "nscore.h"
 #include "nsISupports.h"
 #include "nsCategoryImp.h"
 #include "nsUnicodeProperties.h"
 
 NS_IMPL_QUERY_INTERFACE1(nsCategoryImp, nsIUGenCategory)
 
-NS_IMETHODIMP_(nsrefcnt) nsCategoryImp::AddRef(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsCategoryImp::AddRef(void)
 {
-  return nsrefcnt(1);
+  return MozExternalRefCountType(1);
 }
 
-NS_IMETHODIMP_(nsrefcnt) nsCategoryImp::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsCategoryImp::Release(void)
 {
-  return nsrefcnt(1);
+  return MozExternalRefCountType(1);
 }
 
 nsCategoryImp* nsCategoryImp::GetInstance()
 {
   static nsCategoryImp categoryImp;
   return &categoryImp;
 }
 
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -393,23 +393,23 @@ XPCShellEnvironment::ProcessFile(JSConte
                     ok = false;
             }
         }
     } while (!hitEOF && !env->IsQuitting());
 
     fprintf(stdout, "\n");
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 XPCShellDirProvider::AddRef()
 {
     return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 XPCShellDirProvider::Release()
 {
     return 1;
 }
 
 NS_IMPL_QUERY_INTERFACE1(XPCShellDirProvider, nsIDirectoryServiceProvider)
 
 bool
--- a/js/xpconnect/idl/nsIXPCScriptable.idl
+++ b/js/xpconnect/idl/nsIXPCScriptable.idl
@@ -155,18 +155,18 @@ interface nsIXPCScriptable : nsISupports
  { 0xb7, 0xd7, 0x29, 0x68, 0xa5, 0x70, 0x4b, 0xd8 } }
 
 class NS_NO_VTABLE nsXPCClassInfo : public nsIClassInfo,
                                     public nsIXPCScriptable
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_XPCCLASSINFO_IID)
 
-  NS_IMETHOD_(nsrefcnt) AddRef() = 0;
-  NS_IMETHOD_(nsrefcnt) Release() = 0;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
+  NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
 
   virtual void PreserveWrapper(nsISupports *aNative) = 0;
 
   virtual uint32_t GetInterfacesBitmap() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsXPCClassInfo, NS_XPCCLASSINFO_IID)
 
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3784,18 +3784,18 @@ public:
 
 private:
     static ComponentsSH singleton;
 };
 
 ComponentsSH ComponentsSH::singleton(0);
 
 // Singleton refcounting.
-NS_IMETHODIMP_(nsrefcnt) ComponentsSH::AddRef(void) { return 1; }
-NS_IMETHODIMP_(nsrefcnt) ComponentsSH::Release(void) { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) ComponentsSH::AddRef(void) { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) ComponentsSH::Release(void) { return 1; }
 
 NS_INTERFACE_MAP_BEGIN(ComponentsSH)
   NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 #define NSXPCCOMPONENTSBASE_CID \
 { 0xc62998e5, 0x95f1, 0x4058, \
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1649,23 +1649,23 @@ XPCShellDirProvider::SetAppDir(nsIFile* 
 }
 
 void
 XPCShellDirProvider::SetPluginDir(nsIFile* pluginDir)
 {
     mPluginDir = pluginDir;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 XPCShellDirProvider::AddRef()
 {
     return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 XPCShellDirProvider::Release()
 {
     return 1;
 }
 
 NS_IMPL_QUERY_INTERFACE2(XPCShellDirProvider,
                          nsIDirectoryServiceProvider,
                          nsIDirectoryServiceProvider2)
--- a/js/xpconnect/src/XPCWrappedJS.cpp
+++ b/js/xpconnect/src/XPCWrappedJS.cpp
@@ -213,17 +213,17 @@ nsXPCWrappedJS::QueryInterface(REFNSIID 
 
     return mClass->DelegatedQueryInterface(this, aIID, aInstancePtr);
 }
 
 
 // For a description of nsXPCWrappedJS lifetime and reference counting, see
 // the comment at the top of this file.
 
-nsrefcnt
+MozExternalRefCountType
 nsXPCWrappedJS::AddRef(void)
 {
     if (!MOZ_LIKELY(NS_IsMainThread()))
         MOZ_CRASH();
 
     MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
     nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Upcast(this);
     nsrefcnt cnt = mRefCnt.incr(base);
@@ -232,17 +232,17 @@ nsXPCWrappedJS::AddRef(void)
     if (2 == cnt && IsValid()) {
         GetJSObject(); // Unmark gray JSObject.
         mClass->GetRuntime()->AddWrappedJSRoot(this);
     }
 
     return cnt;
 }
 
-nsrefcnt
+MozExternalRefCountType
 nsXPCWrappedJS::Release(void)
 {
     if (!MOZ_LIKELY(NS_IsMainThread()))
         MOZ_CRASH();
     MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
     NS_ASSERT_OWNINGTHREAD(nsXPCWrappedJS);
 
     bool shouldDelete = false;
--- a/layout/base/nsRefreshDriver.h
+++ b/layout/base/nsRefreshDriver.h
@@ -40,18 +40,18 @@ class RefreshDriverTimer;
 class nsARefreshObserver {
 public:
   // AddRef and Release signatures that match nsISupports.  Implementors
   // must implement reference counting, and those that do implement
   // nsISupports will already have methods with the correct signature.
   //
   // The refresh driver does NOT hold references to refresh observers
   // except while it is notifying them.
-  NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
-  NS_IMETHOD_(nsrefcnt) Release(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
 
   virtual void WillRefresh(mozilla::TimeStamp aTime) = 0;
 };
 
 /**
  * An abstract base class to be implemented by callers wanting to be notified
  * that a refresh has occurred. Callers must ensure an observer is removed
  * before it is destroyed.
--- a/layout/style/nsDOMCSSDeclaration.h
+++ b/layout/style/nsDOMCSSDeclaration.h
@@ -31,18 +31,18 @@ class nsDOMCSSDeclaration : public nsICS
 public:
   // Only implement QueryInterface; subclasses have the responsibility
   // of implementing AddRef/Release.
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE;
 
   // Declare addref and release so they can be called on us, but don't
   // implement them.  Our subclasses must handle their own
   // refcounting.
-  NS_IMETHOD_(nsrefcnt) AddRef() MOZ_OVERRIDE = 0;
-  NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE = 0;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE = 0;
+  NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE = 0;
 
   NS_DECL_NSICSSDECLARATION
   using nsICSSDeclaration::GetLength;
 
   // Require subclasses to implement |GetParentRule|.
   //NS_DECL_NSIDOMCSSSTYLEDECLARATION
   NS_IMETHOD GetCssText(nsAString & aCssText) MOZ_OVERRIDE;
   NS_IMETHOD SetCssText(const nsAString & aCssText) MOZ_OVERRIDE;
--- a/media/mtransport/nr_socket_prsock.h
+++ b/media/mtransport/nr_socket_prsock.h
@@ -96,18 +96,18 @@ public:
   virtual int read(void* buf, size_t maxlen, size_t *len) = 0;
 
    // Implementations of the async_event APIs
   virtual int async_wait(int how, NR_async_cb cb, void *cb_arg,
                          char *function, int line);
   virtual int cancel(int how);
 
   // nsISupport reference counted interface
-  NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
-  NS_IMETHOD_(nsrefcnt) Release(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
 
   uint32_t poll_flags() {
     return poll_flags_;
   }
 
   virtual nr_socket_vtbl *vtbl();  // To access in test classes.
 
 protected:
--- a/mfbt/RefCountType.h
+++ b/mfbt/RefCountType.h
@@ -2,31 +2,36 @@
 /* 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/. */
 
 #ifndef mozilla_RefCountType_h
 #define mozilla_RefCountType_h
 
+#include <stdint.h>
+
 /**
  * MozRefCountType is Mozilla's reference count type.
  *
- * This is the return type for AddRef() and Release() in nsISupports.
- * IUnknown of COM returns an unsigned long from equivalent functions.
- *
  * We use the same type to represent the refcount of RefCounted objects
  * as well, in order to be able to use the leak detection facilities
  * that are implemented by XPCOM.
  *
- * The following ifdef exists to maintain binary compatibility with
- * IUnknown, the base interface in Microsoft COM.
- *
  * Note that this type is not in the mozilla namespace so that it is
  * usable for both C and C++ code.
  */
+typedef uintptr_t MozRefCountType;
+
+/*
+ * This is the return type for AddRef() and Release() in nsISupports.
+ * IUnknown of COM returns an unsigned long from equivalent functions.
+ *
+ * The following ifdef exists to maintain binary compatibility with
+ * IUnknown, the base interface in Microsoft COM.
+ */
 #ifdef XP_WIN
-typedef unsigned long MozRefCountType;
+typedef unsigned long MozExternalRefCountType;
 #else
-typedef uint32_t MozRefCountType;
+typedef uint32_t MozExternalRefCountType;
 #endif
 
 #endif
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -90,17 +90,17 @@ nsJAR::~nsJAR()
 {
   Close();
 }
 
 NS_IMPL_QUERY_INTERFACE1(nsJAR, nsIZipReader)
 NS_IMPL_ADDREF(nsJAR)
 
 // Custom Release method works with nsZipReaderCache...
-nsrefcnt nsJAR::Release(void)
+MozExternalRefCountType nsJAR::Release(void)
 {
   nsrefcnt count;
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "nsJAR");
   if (0 == count) {
     mRefCnt = 1; /* stabilize */
     /* enable this to find non-threadsafe destructors: */
--- a/modules/libjar/nsZipArchive.h
+++ b/modules/libjar/nsZipArchive.h
@@ -191,18 +191,18 @@ public:
    * Gets the amount of memory taken up by the archive's mapping.
    * @return the size
    */
   int64_t SizeOfMapping();
 
   /*
    * Refcounting
    */
-  NS_METHOD_(nsrefcnt) AddRef(void);
-  NS_METHOD_(nsrefcnt) Release(void);
+  NS_METHOD_(MozExternalRefCountType) AddRef(void);
+  NS_METHOD_(MozExternalRefCountType) Release(void);
 
 private:
   //--- private members ---
   mozilla::ThreadSafeAutoRefCnt mRefCnt; /* ref count */
   NS_DECL_OWNINGTHREAD
 
   nsZipItem*    mFiles[ZIP_TABSIZE];
   PLArenaPool   mArena;
@@ -373,18 +373,18 @@ class nsZipHandle {
 friend class nsZipArchive;
 friend class mozilla::FileLocation;
 public:
   static nsresult Init(nsIFile *file, nsZipHandle **ret,
                        PRFileDesc **aFd = nullptr);
   static nsresult Init(nsZipArchive *zip, const char *entry,
                        nsZipHandle **ret);
 
-  NS_METHOD_(nsrefcnt) AddRef(void);
-  NS_METHOD_(nsrefcnt) Release(void);
+  NS_METHOD_(MozExternalRefCountType) AddRef(void);
+  NS_METHOD_(MozExternalRefCountType) Release(void);
 
   int64_t SizeOfMapping();
 
 protected:
   const uint8_t * mFileData; /* pointer to mmaped file */
   uint32_t        mLen;      /* length of file and memory mapped area */
   mozilla::FileLocation mFile; /* source file if any, for logging */
 
--- a/netwerk/base/src/nsSocketTransport2.cpp
+++ b/netwerk/base/src/nsSocketTransport2.cpp
@@ -305,24 +305,24 @@ nsSocketInputStream::OnSocketReady(nsres
     if (callback)
         callback->OnInputStreamReady(this);
 }
 
 NS_IMPL_QUERY_INTERFACE2(nsSocketInputStream,
                          nsIInputStream,
                          nsIAsyncInputStream)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsSocketInputStream::AddRef()
 {
     ++mReaderRefCnt;
     return mTransport->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsSocketInputStream::Release()
 {
     if (--mReaderRefCnt == 0)
         Close();
     return mTransport->Release();
 }
 
 NS_IMETHODIMP
@@ -568,24 +568,24 @@ nsSocketOutputStream::OnSocketReady(nsre
     if (callback)
         callback->OnOutputStreamReady(this);
 }
 
 NS_IMPL_QUERY_INTERFACE2(nsSocketOutputStream,
                          nsIOutputStream,
                          nsIAsyncOutputStream)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsSocketOutputStream::AddRef()
 {
     ++mWriterRefCnt;
     return mTransport->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsSocketOutputStream::Release()
 {
     if (--mWriterRefCnt == 0)
         Close();
     return mTransport->Release();
 }
 
 NS_IMETHODIMP
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -650,17 +650,17 @@ nsCacheEntryDescriptor::VisitMetaData(ns
 
 
 /******************************************************************************
  * nsCacheInputStream - a wrapper for nsIInputStream keeps the cache entry
  *                      open while referenced.
  ******************************************************************************/
 
 NS_IMPL_ADDREF(nsCacheEntryDescriptor::nsInputStreamWrapper)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsCacheEntryDescriptor::nsInputStreamWrapper::Release()
 {
     // Holding a reference to descriptor ensures that cache service won't go
     // away. Do not grab cache service lock if there is no descriptor.
     nsRefPtr<nsCacheEntryDescriptor> desc;
 
     {
         mozilla::MutexAutoLock lock(mLock);
@@ -842,17 +842,17 @@ nsInputStreamWrapper::IsNonBlocking(bool
 }
 
 
 /******************************************************************************
  * nsDecompressInputStreamWrapper - an input stream wrapper that decompresses
  ******************************************************************************/
 
 NS_IMPL_ADDREF(nsCacheEntryDescriptor::nsDecompressInputStreamWrapper)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsCacheEntryDescriptor::nsDecompressInputStreamWrapper::Release()
 {
     // Holding a reference to descriptor ensures that cache service won't go
     // away. Do not grab cache service lock if there is no descriptor.
     nsRefPtr<nsCacheEntryDescriptor> desc;
 
     {
         mozilla::MutexAutoLock lock(mLock);
@@ -1032,17 +1032,17 @@ nsDecompressInputStreamWrapper::EndZstre
 
 /******************************************************************************
  * nsOutputStreamWrapper - a wrapper for nsIOutputstream to track the amount of
  *                         data written to a cache entry.
  *                       - also keeps the cache entry open while referenced.
  ******************************************************************************/
 
 NS_IMPL_ADDREF(nsCacheEntryDescriptor::nsOutputStreamWrapper)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsCacheEntryDescriptor::nsOutputStreamWrapper::Release()
 {
     // Holding a reference to descriptor ensures that cache service won't go
     // away. Do not grab cache service lock if there is no descriptor.
     nsRefPtr<nsCacheEntryDescriptor> desc;
 
     {
         mozilla::MutexAutoLock lock(mLock);
@@ -1262,17 +1262,17 @@ nsOutputStreamWrapper::IsNonBlocking(boo
 
 
 /******************************************************************************
  * nsCompressOutputStreamWrapper - an output stream wrapper that compresses
  *   data before it is written
  ******************************************************************************/
 
 NS_IMPL_ADDREF(nsCacheEntryDescriptor::nsCompressOutputStreamWrapper)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsCacheEntryDescriptor::nsCompressOutputStreamWrapper::Release()
 {
     // Holding a reference to descriptor ensures that cache service won't go
     // away. Do not grab cache service lock if there is no descriptor.
     nsRefPtr<nsCacheEntryDescriptor> desc;
 
     {
         mozilla::MutexAutoLock lock(mLock);
--- a/netwerk/cache2/CacheFileChunk.cpp
+++ b/netwerk/cache2/CacheFileChunk.cpp
@@ -93,17 +93,17 @@ public:
 
 private:
   uint32_t mOffset;
   uint32_t mLen;
 };
 
 
 NS_IMPL_ADDREF(CacheFileChunk)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 CacheFileChunk::Release()
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "CacheFileChunk");
 
   if (0 == count) {
     mRefCnt = 1;
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -53,28 +53,28 @@ CacheFileHandle::DispatchRelease()
     return false;
   }
 
   nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
   if (!ioTarget) {
     return false;
   }
 
-  nsRefPtr<nsRunnableMethod<CacheFileHandle, nsrefcnt, false> > event =
+  nsRefPtr<nsRunnableMethod<CacheFileHandle, MozExternalRefCountType, false> > event =
     NS_NewNonOwningRunnableMethod(this, &CacheFileHandle::Release);
   nsresult rv = ioTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
   if (NS_FAILED(rv)) {
     return false;
   }
 
   return true;
 }
 
 NS_IMPL_ADDREF(CacheFileHandle)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 CacheFileHandle::Release()
 {
   nsrefcnt count = mRefCnt - 1;
   if (DispatchRelease()) {
     // Redispatched to the IO thread.
     return count;
   }
 
--- a/netwerk/cache2/CacheFileInputStream.cpp
+++ b/netwerk/cache2/CacheFileInputStream.cpp
@@ -9,17 +9,17 @@
 #include "nsStreamUtils.h"
 #include "nsThreadUtils.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ADDREF(CacheFileInputStream)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 CacheFileInputStream::Release()
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "CacheFileInputStream");
 
   if (0 == count) {
     mRefCnt = 1;
--- a/netwerk/cache2/CacheFileOutputStream.cpp
+++ b/netwerk/cache2/CacheFileOutputStream.cpp
@@ -11,17 +11,17 @@
 #include "nsThreadUtils.h"
 #include "mozilla/DebugOnly.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ADDREF(CacheFileOutputStream)
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 CacheFileOutputStream::Release()
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "CacheFileOutputStream");
 
   if (0 == count) {
     mRefCnt = 1;
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -61,17 +61,17 @@ HttpChannelChild::~HttpChannelChild()
 
 //-----------------------------------------------------------------------------
 // HttpChannelChild::nsISupports
 //-----------------------------------------------------------------------------
 
 // Override nsHashPropertyBag's AddRef: we don't need thread-safe refcnt
 NS_IMPL_ADDREF(HttpChannelChild)
 
-NS_IMETHODIMP_(nsrefcnt) HttpChannelChild::Release()
+NS_IMETHODIMP_(MozExternalRefCountType) HttpChannelChild::Release()
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   NS_ASSERT_OWNINGTHREAD(HttpChannelChild);
   --mRefCnt;
   NS_LOG_RELEASE(this, mRefCnt, "HttpChannelChild");
 
   // Normally we Send_delete in OnStopRequest, but when we need to retain the
   // remote channel for security info IPDL itself holds 1 reference, so we
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -341,18 +341,18 @@ nsHttpConnectionMgr::DoShiftReloadConnec
 class SpeculativeConnectArgs
 {
 public:
     SpeculativeConnectArgs() { mOverridesOK = false; }
     virtual ~SpeculativeConnectArgs() {}
 
     // Added manually so we can use nsRefPtr without inheriting from
     // nsISupports
-    NS_IMETHOD_(nsrefcnt) AddRef(void);
-    NS_IMETHOD_(nsrefcnt) Release(void);
+    NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+    NS_IMETHOD_(MozExternalRefCountType) Release(void);
 
 public: // intentional!
     nsRefPtr<NullHttpTransaction> mTrans;
 
     bool mOverridesOK;
     uint32_t mParallelSpeculativeConnectLimit;
     bool mIgnoreIdle;
     bool mIgnorePossibleSpdyConnections;
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -1836,17 +1836,17 @@ nsHttpTransaction::CancelPacing(nsresult
 }
 
 //-----------------------------------------------------------------------------
 // nsHttpTransaction::nsISupports
 //-----------------------------------------------------------------------------
 
 NS_IMPL_ADDREF(nsHttpTransaction)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsHttpTransaction::Release()
 {
     nsrefcnt count;
     NS_PRECONDITION(0 != mRefCnt, "dup release");
     count = --mRefCnt;
     NS_LOG_RELEASE(this, count, "nsHttpTransaction");
     if (0 == count) {
         mRefCnt = 1; /* stablize */
--- a/netwerk/protocol/websocket/BaseWebSocketChannel.h
+++ b/netwerk/protocol/websocket/BaseWebSocketChannel.h
@@ -23,18 +23,18 @@ class BaseWebSocketChannel : public nsIW
                              public nsIProtocolHandler
 {
  public:
   BaseWebSocketChannel();
 
   NS_DECL_NSIPROTOCOLHANDLER
 
   NS_IMETHOD QueryInterface(const nsIID & uuid, void **result) = 0;
-  NS_IMETHOD_(nsrefcnt ) AddRef(void) = 0;
-  NS_IMETHOD_(nsrefcnt ) Release(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType ) AddRef(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType ) Release(void) = 0;
 
   // Partial implementation of nsIWebSocketChannel
   //
   NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI);
   NS_IMETHOD GetURI(nsIURI **aURI);
   NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aNotificationCallbacks);
   NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aNotificationCallbacks);
   NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup);
--- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp
@@ -18,17 +18,17 @@
 
 using namespace mozilla::ipc;
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ADDREF(WebSocketChannelChild)
 
-NS_IMETHODIMP_(nsrefcnt) WebSocketChannelChild::Release()
+NS_IMETHODIMP_(MozExternalRefCountType) WebSocketChannelChild::Release()
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   NS_ASSERT_OWNINGTHREAD(WebSocketChannelChild);
   --mRefCnt;
   NS_LOG_RELEASE(this, mRefCnt, "WebSocketChannelChild");
 
   if (mRefCnt == 1 && mIPCOpen) {
     SendDeleteSelf();
--- a/parser/html/nsHtml5Atom.cpp
+++ b/parser/html/nsHtml5Atom.cpp
@@ -28,24 +28,24 @@ nsHtml5Atom::nsHtml5Atom(const nsAString
   mozilla::unused << buf.forget();
 }
 
 nsHtml5Atom::~nsHtml5Atom()
 {
   nsStringBuffer::FromData(mString)->Release();
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsHtml5Atom::AddRef()
 {
   NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom.");
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsHtml5Atom::Release()
 {
   NS_NOTREACHED("Attempt to Release an nsHtml5Atom.");
   return 1;
 }
 
 NS_IMETHODIMP
 nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
--- a/storage/src/mozStorageAsyncStatement.cpp
+++ b/storage/src/mozStorageAsyncStatement.cpp
@@ -109,18 +109,18 @@ public:
 
   NS_IMETHODIMP
   GetClassIDNoAlloc(nsCID *_cid)
   {
     return NS_ERROR_NOT_AVAILABLE;
   }
 };
 
-NS_IMETHODIMP_(nsrefcnt) AsyncStatementClassInfo::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) AsyncStatementClassInfo::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) AsyncStatementClassInfo::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) AsyncStatementClassInfo::Release() { return 1; }
 NS_IMPL_QUERY_INTERFACE1(AsyncStatementClassInfo, nsIClassInfo)
 
 static AsyncStatementClassInfo sAsyncStatementClassInfo;
 
 ////////////////////////////////////////////////////////////////////////////////
 //// AsyncStatement
 
 AsyncStatement::AsyncStatement()
--- a/storage/src/mozStorageAsyncStatementJSHelper.cpp
+++ b/storage/src/mozStorageAsyncStatementJSHelper.cpp
@@ -59,18 +59,18 @@ AsyncStatementJSHelper::getParams(AsyncS
   JS::Rooted<JSObject*> obj(aCtx);
   obj = aStatement->mStatementParamsHolder->GetJSObject();
   NS_ENSURE_STATE(obj);
 
   *_params = OBJECT_TO_JSVAL(obj);
   return NS_OK;
 }
 
-NS_IMETHODIMP_(nsrefcnt) AsyncStatementJSHelper::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) AsyncStatementJSHelper::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) AsyncStatementJSHelper::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) AsyncStatementJSHelper::Release() { return 1; }
 NS_INTERFACE_MAP_BEGIN(AsyncStatementJSHelper)
   NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsIXPCScriptable
 
--- a/storage/src/mozStorageConnection.cpp
+++ b/storage/src/mozStorageConnection.cpp
@@ -493,17 +493,17 @@ NS_INTERFACE_MAP_BEGIN(Connection)
   NS_INTERFACE_MAP_ENTRY(mozIStorageAsyncConnection)
   NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(mozIStorageConnection, !mAsyncOnly)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozIStorageConnection)
 NS_INTERFACE_MAP_END
 
 // This is identical to what NS_IMPL_RELEASE provides, but with the
 // extra |1 == count| case.
-NS_IMETHODIMP_(nsrefcnt) Connection::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) Connection::Release(void)
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "Connection");
   if (1 == count) {
     // If the refcount is 1, the single reference must be from
     // gService->mConnections (in class |Service|).  Which means we can
     // unregister it safely.
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -111,18 +111,18 @@ public:
 
   NS_IMETHODIMP
   GetClassIDNoAlloc(nsCID *_cid)
   {
     return NS_ERROR_NOT_AVAILABLE;
   }
 };
 
-NS_IMETHODIMP_(nsrefcnt) StatementClassInfo::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) StatementClassInfo::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) StatementClassInfo::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) StatementClassInfo::Release() { return 1; }
 NS_IMPL_QUERY_INTERFACE1(StatementClassInfo, nsIClassInfo)
 
 static StatementClassInfo sStatementClassInfo;
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Statement
 
 Statement::Statement()
--- a/storage/src/mozStorageStatementJSHelper.cpp
+++ b/storage/src/mozStorageStatementJSHelper.cpp
@@ -152,18 +152,18 @@ StatementJSHelper::getParams(Statement *
   JS::Rooted<JSObject*> obj(aCtx);
   obj = aStatement->mStatementParamsHolder->GetJSObject();
   NS_ENSURE_STATE(obj);
 
   *_params = OBJECT_TO_JSVAL(obj);
   return NS_OK;
 }
 
-NS_IMETHODIMP_(nsrefcnt) StatementJSHelper::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) StatementJSHelper::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) StatementJSHelper::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) StatementJSHelper::Release() { return 1; }
 NS_INTERFACE_MAP_BEGIN(StatementJSHelper)
   NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsIXPCScriptable
 
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -612,23 +612,23 @@ NS_INTERFACE_MAP_BEGIN(nsXULAppInfo)
 #endif
 #ifdef MOZ_CRASHREPORTER
   NS_INTERFACE_MAP_ENTRY(nsICrashReporter)
 #endif
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData || 
                                      XRE_GetProcessType() == GeckoProcessType_Content)
 NS_INTERFACE_MAP_END
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsXULAppInfo::AddRef()
 {
   return 1;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsXULAppInfo::Release()
 {
   return 1;
 }
 
 NS_IMETHODIMP
 nsXULAppInfo::GetVendor(nsACString& aResult)
 {
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -159,23 +159,23 @@ nsXREDirProvider::SetProfile(nsIFile* aD
   return NS_OK;
 }
 
 NS_IMPL_QUERY_INTERFACE3(nsXREDirProvider,
                          nsIDirectoryServiceProvider,
                          nsIDirectoryServiceProvider2,
                          nsIProfileStartup)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsXREDirProvider::AddRef()
 {
   return 1;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsXREDirProvider::Release()
 {
   return 0;
 }
 
 nsresult
 nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult,
                                          const nsACString* aProfileName,
--- a/toolkit/xre/nsXREDirProvider.h
+++ b/toolkit/xre/nsXREDirProvider.h
@@ -15,18 +15,18 @@
 #include "mozilla/Attributes.h"
 
 class nsXREDirProvider MOZ_FINAL : public nsIDirectoryServiceProvider2,
                                    public nsIProfileStartup
 {
 public:
   // we use a custom isupports implementation (no refcount)
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);
 
   NS_DECL_NSIDIRECTORYSERVICEPROVIDER
   NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
   NS_DECL_NSIPROFILESTARTUP
 
   nsXREDirProvider();
 
   // if aXULAppDir is null, use gArgv[0]
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 #include "nsView.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/DebugOnly.h"
+#include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Poison.h"
 #include "nsIWidget.h"
 #include "nsViewManager.h"
 #include "nsIFrame.h"
 #include "nsPresArena.h"
 #include "nsXULPopupManager.h"
 #include "nsIWidgetListener.h"
@@ -782,17 +783,17 @@ void nsView::List(FILE* out, int32_t aIn
     nsIntRect rect;
     mWindow->GetClientBounds(rect);
     nsRect windowBounds = rect.ToAppUnits(p2a);
     mWindow->GetBounds(rect);
     nsRect nonclientBounds = rect.ToAppUnits(p2a);
     nsrefcnt widgetRefCnt = mWindow->AddRef() - 1;
     mWindow->Release();
     int32_t Z = mWindow->GetZIndex();
-    fprintf(out, "(widget=%p[%d] z=%d pos={%d,%d,%d,%d}) ",
+    fprintf(out, "(widget=%p[%" PRIuPTR "] z=%d pos={%d,%d,%d,%d}) ",
             (void*)mWindow, widgetRefCnt, Z,
             nonclientBounds.x, nonclientBounds.y,
             windowBounds.width, windowBounds.height);
   }
   nsRect brect = GetBounds();
   fprintf(out, "{%d,%d,%d,%d}",
           brect.x, brect.y, brect.width, brect.height);
   fprintf(out, " z=%d vis=%d frame=%p <\n",
--- a/xpcom/base/nsAgg.h
+++ b/xpcom/base/nsAgg.h
@@ -49,18 +49,18 @@ private:                                
     AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr);       \
                                                                             \
     class Internal : public nsISupports {                                   \
     public:                                                                 \
                                                                             \
         Internal() {}                                                       \
                                                                             \
         NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);  \
-        NS_IMETHOD_(nsrefcnt) AddRef(void);                                 \
-        NS_IMETHOD_(nsrefcnt) Release(void);                                \
+        NS_IMETHOD_(MozExternalRefCountType) AddRef(void);                  \
+        NS_IMETHOD_(MozExternalRefCountType) Release(void);                 \
                                                                             \
         NS_DECL_OWNINGTHREAD                                                \
     };                                                                      \
                                                                             \
     friend class Internal;                                                  \
                                                                             \
     nsISupports*        fOuter;                                             \
     Internal            fAggregated;                                        \
@@ -102,28 +102,28 @@ static NS_CYCLE_COLLECTION_INNERCLASS NS
   PR_END_MACRO
 
 
 // Put this in your class's implementation file:
 #define NS_IMPL_AGGREGATED(_class)                                          \
                                                                             \
 NS_IMPL_AGGREGATED_HELPER(_class)                                           \
                                                                             \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
+NS_IMETHODIMP_(MozExternalRefCountType)                                     \
 _class::Internal::AddRef(void)                                              \
 {                                                                           \
     _class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
     MOZ_ASSERT(int32_t(agg->mRefCnt) >= 0, "illegal refcnt");               \
     NS_ASSERT_OWNINGTHREAD(_class);                                         \
     ++agg->mRefCnt;                                                         \
     NS_LOG_ADDREF(this, agg->mRefCnt, #_class, sizeof(*this));              \
     return agg->mRefCnt;                                                    \
 }                                                                           \
                                                                             \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
+NS_IMETHODIMP_(MozExternalRefCountType)                                     \
 _class::Internal::Release(void)                                             \
 {                                                                           \
     _class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
     MOZ_ASSERT(int32_t(agg->mRefCnt) > 0, "dup release");                   \
     NS_ASSERT_OWNINGTHREAD(_class);                                         \
     --agg->mRefCnt;                                                         \
     NS_LOG_RELEASE(this, agg->mRefCnt, #_class);                            \
     if (agg->mRefCnt == 0) {                                                \
@@ -133,27 +133,27 @@ NS_IMETHODIMP_(nsrefcnt)                
     }                                                                       \
     return agg->mRefCnt;                                                    \
 }                                                                           \
 
 #define NS_IMPL_CYCLE_COLLECTING_AGGREGATED(_class)                         \
                                                                             \
 NS_IMPL_AGGREGATED_HELPER(_class)                                           \
                                                                             \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
+NS_IMETHODIMP_(MozExternalRefCountType)                                     \
 _class::Internal::AddRef(void)                                              \
 {                                                                           \
     _class* agg = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Downcast(this);    \
     MOZ_ASSERT(int32_t(agg->mRefCnt) >= 0, "illegal refcnt");               \
     NS_ASSERT_OWNINGTHREAD_AGGREGATE(agg, _class);                          \
     nsrefcnt count = agg->mRefCnt.incr(this);                               \
     NS_LOG_ADDREF(this, count, #_class, sizeof(*agg));                      \
     return count;                                                           \
 }                                                                           \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
+NS_IMETHODIMP_(MozExternalRefCountType)                                     \
 _class::Internal::Release(void)                                             \
 {                                                                           \
     _class* agg = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Downcast(this);    \
     MOZ_ASSERT(int32_t(agg->mRefCnt) > 0, "dup release");                   \
     NS_ASSERT_OWNINGTHREAD_AGGREGATE(agg, _class);                          \
     nsrefcnt count = agg->mRefCnt.decr(this);                               \
     NS_LOG_RELEASE(this, count, #_class);                                   \
     return count;                                                           \
@@ -166,23 +166,23 @@ NS_IMETHODIMP_(void)                    
 
 #define NS_IMPL_AGGREGATED_HELPER(_class)                                   \
 NS_IMETHODIMP                                                               \
 _class::QueryInterface(const nsIID& aIID, void** aInstancePtr)              \
 {                                                                           \
     return fOuter->QueryInterface(aIID, aInstancePtr);                      \
 }                                                                           \
                                                                             \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
+NS_IMETHODIMP_(MozExternalRefCountType)                                     \
 _class::AddRef(void)                                                        \
 {                                                                           \
     return fOuter->AddRef();                                                \
 }                                                                           \
                                                                             \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
+NS_IMETHODIMP_(MozExternalRefCountType)                                     \
 _class::Release(void)                                                       \
 {                                                                           \
     return fOuter->Release();                                               \
 }                                                                           \
                                                                             \
 NS_IMETHODIMP                                                               \
 _class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr)    \
 {                                                                           \
--- a/xpcom/base/nsDebugImpl.cpp
+++ b/xpcom/base/nsDebugImpl.cpp
@@ -72,23 +72,23 @@ Break(const char *aMsg);
 using namespace mozilla;
 
 static const char *sMultiprocessDescription = nullptr;
 
 static Atomic<int32_t> gAssertionCount;
 
 NS_IMPL_QUERY_INTERFACE2(nsDebugImpl, nsIDebug, nsIDebug2)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsDebugImpl::AddRef()
 {
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsDebugImpl::Release()
 {
   return 1;
 }
 
 NS_IMETHODIMP
 nsDebugImpl::Assertion(const char *aStr, const char *aExpr,
                        const char *aFile, int32_t aLine)
--- a/xpcom/base/nsISupportsBase.h
+++ b/xpcom/base/nsISupportsBase.h
@@ -56,26 +56,26 @@ public:
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) = 0;
   /**
    * Increases the reference count for this interface.
    * The associated instance will not be deleted unless
    * the reference count is returned to zero.
    *
    * @return The resulting reference count.
    */
-  NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
 
   /**
    * Decreases the reference count for this interface.
    * Generally, if the reference count returns to zero,
    * the associated instance is deleted.
    *
    * @return The resulting reference count.
    */
-  NS_IMETHOD_(nsrefcnt) Release(void) = 0;
+  NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
 
   //@}
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsISupports, NS_ISUPPORTS_IID)
 
 /*@}*/
 
--- a/xpcom/base/nsMemoryImpl.cpp
+++ b/xpcom/base/nsMemoryImpl.cpp
@@ -168,18 +168,18 @@ nsMemoryImpl::RunFlushers(const char16_t
         }
     }
 
     sIsFlushing = false;
     return NS_OK;
 }
 
 // XXX need NS_IMPL_STATIC_ADDREF/RELEASE
-NS_IMETHODIMP_(nsrefcnt) nsMemoryImpl::FlushEvent::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) nsMemoryImpl::FlushEvent::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsMemoryImpl::FlushEvent::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsMemoryImpl::FlushEvent::Release() { return 1; }
 NS_IMPL_QUERY_INTERFACE1(nsMemoryImpl::FlushEvent, nsIRunnable)
 
 NS_IMETHODIMP
 nsMemoryImpl::FlushEvent::Run()
 {
     sGlobalMemory.RunFlushers(mReason);
     return NS_OK;
 }
--- a/xpcom/base/nsMemoryImpl.h
+++ b/xpcom/base/nsMemoryImpl.h
@@ -15,18 +15,18 @@
 // a constructor/destructor or any instance members. Please don't add
 // instance member variables, only static member variables.
 
 class nsMemoryImpl : public nsIMemory
 {
 public:
     // We don't use the generic macros because we are a special static object
     NS_IMETHOD QueryInterface(REFNSIID aIID, void** aResult);
-    NS_IMETHOD_(nsrefcnt) AddRef(void) { return 1; }
-    NS_IMETHOD_(nsrefcnt) Release(void) { return 1; }
+    NS_IMETHOD_(MozExternalRefCountType) AddRef(void) { return 1; }
+    NS_IMETHOD_(MozExternalRefCountType) Release(void) { return 1; }
 
     NS_DECL_NSIMEMORY
 
     static nsresult Create(nsISupports* outer,
                            const nsIID& aIID, void **aResult);
 
     NS_HIDDEN_(nsresult) FlushMemory(const char16_t* aReason, bool aImmediate);
     NS_HIDDEN_(nsresult) RunFlushers(const char16_t* aReason);
--- a/xpcom/base/nsTraceRefcnt.cpp
+++ b/xpcom/base/nsTraceRefcnt.cpp
@@ -1006,17 +1006,17 @@ NS_LogAddRef(void* aPtr, nsrefcnt aRefcn
 
     if (gRefcntsLog && loggingThisType && loggingThisObject) {
       if (gLogToLeaky) {
         (*leakyLogAddRef)(aPtr, aRefcnt - 1, aRefcnt);
       }
       else {
           // Can't use PR_LOG(), b/c it truncates the line
           fprintf(gRefcntsLog,
-                  "\n<%s> 0x%08X %" PRIdPTR " AddRef %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
+                  "\n<%s> 0x%08X %" PRIuPTR " AddRef %" PRIuPTR "\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
           nsTraceRefcnt::WalkTheStack(gRefcntsLog);
           fflush(gRefcntsLog);
       }
     }
     UNLOCK_TRACELOG();
   }
 #endif
 }
@@ -1054,17 +1054,17 @@ NS_LogRelease(void* aPtr, nsrefcnt aRefc
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
     if (gRefcntsLog && loggingThisType && loggingThisObject) {
       if (gLogToLeaky) {
         (*leakyLogRelease)(aPtr, aRefcnt + 1, aRefcnt);
       }
       else {
           // Can't use PR_LOG(), b/c it truncates the line
           fprintf(gRefcntsLog,
-                  "\n<%s> 0x%08X %" PRIdPTR " Release %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
+                  "\n<%s> 0x%08X %" PRIuPTR " Release %" PRIuPTR "\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
           nsTraceRefcnt::WalkTheStack(gRefcntsLog);
           fflush(gRefcntsLog);
       }
     }
 
     // Here's the case where MOZ_COUNT_DTOR was not used,
     // yet we still want to see deletion information:
 
--- a/xpcom/components/nsCategoryManager.cpp
+++ b/xpcom/components/nsCategoryManager.cpp
@@ -397,23 +397,23 @@ CategoryEnumerator::enumfunc_createenume
 
 
 //
 // nsCategoryManager implementations
 //
 
 NS_IMPL_QUERY_INTERFACE2(nsCategoryManager, nsICategoryManager, nsIMemoryReporter)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsCategoryManager::AddRef()
 {
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsCategoryManager::Release()
 {
   return 1;
 }
 
 nsCategoryManager* nsCategoryManager::gCategoryManager;
 
 /* static */ nsCategoryManager*
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -118,18 +118,18 @@ public:
   PermanentAtomImpl(nsStringBuffer* aData, uint32_t aLength,
                     PLDHashNumber aKeyHash)
     : AtomImpl(aData, aLength, aKeyHash)
   {}
   PermanentAtomImpl()
   {}
 
   ~PermanentAtomImpl();
-  NS_IMETHOD_(nsrefcnt) AddRef();
-  NS_IMETHOD_(nsrefcnt) Release();
+  NS_IMETHOD_(MozExternalRefCountType) AddRef();
+  NS_IMETHOD_(MozExternalRefCountType) Release();
 
   virtual bool IsPermanent();
 
   // SizeOfIncludingThis() isn't needed -- the one inherited from AtomImpl is
   // good enough, because PermanentAtomImpl doesn't add any new data members.
 
   void* operator new(size_t size, AtomImpl* aAtom) CPP_THROW_NEW;
   void* operator new(size_t size) CPP_THROW_NEW
@@ -388,23 +388,23 @@ AtomImpl::~AtomImpl()
 NS_IMPL_ISUPPORTS1(AtomImpl, nsIAtom)
 
 PermanentAtomImpl::~PermanentAtomImpl()
 {
   // So we can tell if we were permanent while running the base class dtor.
   mRefCnt = REFCNT_PERMANENT_SENTINEL;
 }
 
-NS_IMETHODIMP_(nsrefcnt) PermanentAtomImpl::AddRef()
+NS_IMETHODIMP_(MozExternalRefCountType) PermanentAtomImpl::AddRef()
 {
   MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt) PermanentAtomImpl::Release()
+NS_IMETHODIMP_(MozExternalRefCountType) PermanentAtomImpl::Release()
 {
   MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
   return 1;
 }
 
 /* virtual */ bool
 AtomImpl::IsPermanent()
 {
--- a/xpcom/ds/nsExpirationTracker.h
+++ b/xpcom/ds/nsExpirationTracker.h
@@ -336,28 +336,28 @@ nsExpirationTracker<T, K>::ExpirationTra
                                                               const char16_t *aData)
 {
   if (!strcmp(aTopic, "memory-pressure") && mOwner)
     mOwner->AgeAllGenerations();
   return NS_OK;
 }
 
 template <class T, uint32_t K>
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsExpirationTracker<T,K>::ExpirationTrackerObserver::AddRef(void)
 {
   MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
   NS_ASSERT_OWNINGTHREAD(ExpirationTrackerObserver);
   ++mRefCnt;
   NS_LOG_ADDREF(this, mRefCnt, "ExpirationTrackerObserver", sizeof(*this));
   return mRefCnt;
 }
 
 template <class T, uint32_t K>
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsExpirationTracker<T,K>::ExpirationTrackerObserver::Release(void)
 {
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
   NS_ASSERT_OWNINGTHREAD(ExpirationTrackerObserver);
   --mRefCnt;
   NS_LOG_RELEASE(this, mRefCnt, "ExpirationTrackerObserver");
   if (mRefCnt == 0) {
     NS_ASSERT_OWNINGTHREAD(ExpirationTrackerObserver);
--- a/xpcom/glue/nsClassInfoImpl.cpp
+++ b/xpcom/glue/nsClassInfoImpl.cpp
@@ -1,22 +1,22 @@
 /* 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/. */
 
 #include "nsIClassInfoImpl.h"
 #include "nsIProgrammingLanguage.h"
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 GenericClassInfo::AddRef()
 {
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 GenericClassInfo::Release()
 {
   return 1;
 }
 
 NS_IMPL_QUERY_INTERFACE1(GenericClassInfo, nsIClassInfo)
 
 NS_IMETHODIMP
--- a/xpcom/glue/nsEnumeratorUtils.cpp
+++ b/xpcom/glue/nsEnumeratorUtils.cpp
@@ -30,22 +30,22 @@ public:
 
     static EmptyEnumeratorImpl* GetInstance() {
       static const EmptyEnumeratorImpl kInstance;
       return const_cast<EmptyEnumeratorImpl*>(&kInstance);
     }
 };
 
 // nsISupports interface
-NS_IMETHODIMP_(nsrefcnt) EmptyEnumeratorImpl::AddRef(void)
+NS_IMETHODIMP_(MozExternalRefCountType) EmptyEnumeratorImpl::AddRef(void)
 {
     return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt) EmptyEnumeratorImpl::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) EmptyEnumeratorImpl::Release(void)
 {
     return 1;
 }
 
 NS_IMPL_QUERY_INTERFACE3(EmptyEnumeratorImpl, nsISimpleEnumerator,
                          nsIUTF8StringEnumerator, nsIStringEnumerator)
 
 // nsISimpleEnumerator interface
--- a/xpcom/glue/nsISupportsImpl.h
+++ b/xpcom/glue/nsISupportsImpl.h
@@ -278,40 +278,40 @@ class ThreadSafeAutoRefCnt {
  * Declare the reference count variable and the implementations of the
  * AddRef and QueryInterface methods.
  */
 
 #define NS_DECL_ISUPPORTS                                                     \
 public:                                                                       \
   NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
                             void** aInstancePtr);                             \
-  NS_IMETHOD_(nsrefcnt) AddRef(void);                                         \
-  NS_IMETHOD_(nsrefcnt) Release(void);                                        \
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);                          \
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);                         \
 protected:                                                                    \
   nsAutoRefCnt mRefCnt;                                                       \
   NS_DECL_OWNINGTHREAD                                                        \
 public:
 
 #define NS_DECL_THREADSAFE_ISUPPORTS                                          \
 public:                                                                       \
   NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
                             void** aInstancePtr);                             \
-  NS_IMETHOD_(nsrefcnt) AddRef(void);                                         \
-  NS_IMETHOD_(nsrefcnt) Release(void);                                        \
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);                          \
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);                         \
 protected:                                                                    \
   ::mozilla::ThreadSafeAutoRefCnt mRefCnt;                                    \
   NS_DECL_OWNINGTHREAD                                                        \
 public:
 
 #define NS_DECL_CYCLE_COLLECTING_ISUPPORTS                                    \
 public:                                                                       \
   NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
                             void** aInstancePtr);                             \
-  NS_IMETHOD_(nsrefcnt) AddRef(void);                                         \
-  NS_IMETHOD_(nsrefcnt) Release(void);                                        \
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);                          \
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);                         \
   NS_IMETHOD_(void) DeleteCycleCollectable(void);                             \
 protected:                                                                    \
   nsCycleCollectingAutoRefCnt mRefCnt;                                        \
   NS_DECL_OWNINGTHREAD                                                        \
 public:
 
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -335,23 +335,23 @@ public:
     NS_ASSERT_OWNINGTHREAD(_class);                                           \
     nsrefcnt count =                                                          \
       mRefCnt.decr(static_cast<void*>(this),                                  \
                    _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
     NS_LOG_RELEASE(this, count, #_class);                                     \
     return count;
 
 #define NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(_class)                        \
-NS_METHOD_(nsrefcnt) _class::AddRef(void)                                     \
+NS_METHOD_(MozExternalRefCountType) _class::AddRef(void)                      \
 {                                                                             \
   NS_IMPL_CC_NATIVE_ADDREF_BODY(_class)                                       \
 }
 
 #define NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE_WITH_LAST_RELEASE(_class, _last) \
-NS_METHOD_(nsrefcnt) _class::Release(void)                                       \
+NS_METHOD_(MozExternalRefCountType) _class::Release(void)                        \
 {                                                                                \
     MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                             \
     NS_ASSERT_OWNINGTHREAD(_class);                                              \
     bool shouldDelete = false;                                                   \
     nsrefcnt count =                                                             \
       mRefCnt.decr(static_cast<void*>(this),                                     \
                    _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant(),     \
                    &shouldDelete);                                               \
@@ -366,27 +366,27 @@ NS_METHOD_(nsrefcnt) _class::Release(voi
             mRefCnt.stabilizeForDeletion();                                      \
             DeleteCycleCollectable();                                            \
         }                                                                        \
     }                                                                            \
     return count;                                                                \
 }
 
 #define NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE(_class)                       \
-NS_METHOD_(nsrefcnt) _class::Release(void)                                    \
+NS_METHOD_(MozExternalRefCountType) _class::Release(void)                     \
 {                                                                             \
   NS_IMPL_CC_NATIVE_RELEASE_BODY(_class)                                      \
 }
 
 #define NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(_class)            \
 public:                                                                       \
-  NS_METHOD_(nsrefcnt) AddRef(void) {                                         \
+  NS_METHOD_(MozExternalRefCountType) AddRef(void) {                          \
     NS_IMPL_CC_NATIVE_ADDREF_BODY(_class)                                     \
   }                                                                           \
-  NS_METHOD_(nsrefcnt) Release(void) {                                        \
+  NS_METHOD_(MozExternalRefCountType) Release(void) {                         \
     NS_IMPL_CC_NATIVE_RELEASE_BODY(_class)                                    \
   }                                                                           \
 protected:                                                                    \
   nsCycleCollectingAutoRefCnt mRefCnt;                                        \
   NS_DECL_OWNINGTHREAD                                                        \
 public:
 
 
@@ -402,24 +402,24 @@ public:
 /**
  * Use this macro to declare and implement the AddRef & Release methods for a
  * given non-XPCOM <i>_class</i>.
  *
  * @param _class The name of the class implementing the method
  */
 #define NS_INLINE_DECL_REFCOUNTING(_class)                                    \
 public:                                                                       \
-  NS_METHOD_(nsrefcnt) AddRef(void) {                                         \
+  NS_METHOD_(MozExternalRefCountType) AddRef(void) {                          \
     MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                      \
     NS_ASSERT_OWNINGTHREAD(_class);                                           \
     ++mRefCnt;                                                                \
     NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this));                     \
     return mRefCnt;                                                           \
   }                                                                           \
-  NS_METHOD_(nsrefcnt) Release(void) {                                        \
+  NS_METHOD_(MozExternalRefCountType) Release(void) {                         \
     MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                          \
     NS_ASSERT_OWNINGTHREAD(_class);                                           \
     --mRefCnt;                                                                \
     NS_LOG_RELEASE(this, mRefCnt, #_class);                                   \
     if (mRefCnt == 0) {                                                       \
       NS_ASSERT_OWNINGTHREAD(_class);                                         \
       mRefCnt = 1; /* stabilize */                                            \
       delete this;                                                            \
@@ -437,23 +437,23 @@ public:
  * given non-XPCOM <i>_class</i> in a threadsafe manner.
  *
  * DOES NOT DO REFCOUNT STABILIZATION!
  *
  * @param _class The name of the class implementing the method
  */
 #define NS_INLINE_DECL_THREADSAFE_REFCOUNTING(_class)                         \
 public:                                                                       \
-  NS_METHOD_(nsrefcnt) AddRef(void) {                                         \
+  NS_METHOD_(MozExternalRefCountType) AddRef(void) {                          \
     MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                      \
     nsrefcnt count = ++mRefCnt;                                               \
     NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                       \
     return (nsrefcnt) count;                                                  \
   }                                                                           \
-  NS_METHOD_(nsrefcnt) Release(void) {                                        \
+  NS_METHOD_(MozExternalRefCountType) Release(void) {                         \
     MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                          \
     nsrefcnt count = --mRefCnt;                                               \
     NS_LOG_RELEASE(this, count, #_class);                                     \
     if (count == 0) {                                                         \
       delete (this);                                                          \
       return 0;                                                               \
     }                                                                         \
     return count;                                                             \
@@ -462,17 +462,17 @@ protected:                              
   ::mozilla::ThreadSafeAutoRefCnt mRefCnt;                                    \
 public:
 
 /**
  * Use this macro to implement the AddRef method for a given <i>_class</i>
  * @param _class The name of the class implementing the method
  */
 #define NS_IMPL_ADDREF(_class)                                                \
-NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void)                                 \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
 {                                                                             \
   MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
   if (!mRefCnt.isThreadSafe)                                                  \
     NS_ASSERT_OWNINGTHREAD(_class);                                           \
   nsrefcnt count = ++mRefCnt;                                                 \
   NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                         \
   return count;                                                               \
 }
@@ -480,17 +480,17 @@ NS_IMETHODIMP_(nsrefcnt) _class::AddRef(
 /**
  * Use this macro to implement the AddRef method for a given <i>_class</i>
  * implemented as a wholly owned aggregated object intended to implement
  * interface(s) for its owner
  * @param _class The name of the class implementing the method
  * @param _aggregator the owning/containing object
  */
 #define NS_IMPL_ADDREF_USING_AGGREGATOR(_class, _aggregator)                  \
-NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void)                                 \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
 {                                                                             \
   NS_PRECONDITION(_aggregator, "null aggregator");                            \
   return (_aggregator)->AddRef();                                             \
 }
 
 /**
  * Use this macro to implement the Release method for a given
  * <i>_class</i>.
@@ -506,17 +506,17 @@ NS_IMETHODIMP_(nsrefcnt) _class::AddRef(
  *
  *   Destroy(this);
  *
  * to be invoked when the object's refcount drops to zero. This
  * allows for arbitrary teardown activity to occur (e.g., deallocation
  * of object allocated with placement new).
  */
 #define NS_IMPL_RELEASE_WITH_DESTROY(_class, _destroy)                        \
-NS_IMETHODIMP_(nsrefcnt) _class::Release(void)                                \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
 {                                                                             \
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
   if (!mRefCnt.isThreadSafe)                                                  \
     NS_ASSERT_OWNINGTHREAD(_class);                                           \
   nsrefcnt count = --mRefCnt;                                                 \
   NS_LOG_RELEASE(this, count, #_class);                                       \
   if (count == 0) {                                                           \
     if (!mRefCnt.isThreadSafe)                                                \
@@ -547,36 +547,36 @@ NS_IMETHODIMP_(nsrefcnt) _class::Release
 /**
  * Use this macro to implement the Release method for a given <i>_class</i>
  * implemented as a wholly owned aggregated object intended to implement
  * interface(s) for its owner
  * @param _class The name of the class implementing the method
  * @param _aggregator the owning/containing object
  */
 #define NS_IMPL_RELEASE_USING_AGGREGATOR(_class, _aggregator)                 \
-NS_IMETHODIMP_(nsrefcnt) _class::Release(void)                                \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
 {                                                                             \
   NS_PRECONDITION(_aggregator, "null aggregator");                            \
   return (_aggregator)->Release();                                            \
 }
 
 
 #define NS_IMPL_CYCLE_COLLECTING_ADDREF(_class)                               \
-NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void)                                 \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
 {                                                                             \
   MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
   NS_ASSERT_OWNINGTHREAD(_class);                                             \
   nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
   nsrefcnt count = mRefCnt.incr(base);                                        \
   NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                         \
   return count;                                                               \
 }
 
 #define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, _destroy)       \
-NS_IMETHODIMP_(nsrefcnt) _class::Release(void)                                \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
 {                                                                             \
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
   NS_ASSERT_OWNINGTHREAD(_class);                                             \
   nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
   nsrefcnt count = mRefCnt.decr(base);                                        \
   NS_LOG_RELEASE(this, count, #_class);                                       \
   return count;                                                               \
 }                                                                             \
@@ -586,17 +586,17 @@ NS_IMETHODIMP_(void) _class::DeleteCycle
 }
 
 #define NS_IMPL_CYCLE_COLLECTING_RELEASE(_class)                              \
   NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, delete (this))
 
 // _LAST_RELEASE can be useful when certain resources should be released
 // as soon as we know the object will be deleted.
 #define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(_class, _last)     \
-NS_IMETHODIMP_(nsrefcnt) _class::Release(void)                                \
+NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
 {                                                                             \
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
   NS_ASSERT_OWNINGTHREAD(_class);                                             \
   bool shouldDelete = false;                                                  \
   nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
   nsrefcnt count = mRefCnt.decr(base, &shouldDelete);                         \
   NS_LOG_RELEASE(this, count, #_class);                                       \
   if (count == 0) {                                                           \
@@ -1048,55 +1048,55 @@ NS_IMETHODIMP _class::QueryInterface(REF
  *   NS_DECL_ISUPPORTS_INHERITED
  *   ...other nsIBar and Bar methods...
  * };
  */
 #define NS_DECL_ISUPPORTS_INHERITED                                           \
 public:                                                                       \
   NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
                             void** aInstancePtr);                             \
-  NS_IMETHOD_(nsrefcnt) AddRef(void);                                         \
-  NS_IMETHOD_(nsrefcnt) Release(void);                                        \
+  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);                          \
+  NS_IMETHOD_(MozExternalRefCountType) Release(void);                         \
 
 /**
  * These macros can be used in conjunction with NS_DECL_ISUPPORTS_INHERITED
  * to implement the nsISupports methods, forwarding the invocations to a
  * superclass that already implements nsISupports.
  *
  * Note that I didn't make these inlined because they're virtual methods.
  */
 
 #define NS_IMPL_ADDREF_INHERITED(Class, Super)                                \
-NS_IMETHODIMP_(nsrefcnt) Class::AddRef(void)                                  \
+NS_IMETHODIMP_(MozExternalRefCountType) Class::AddRef(void)                   \
 {                                                                             \
   nsrefcnt r = Super::AddRef();                                               \
   NS_LOG_ADDREF(this, r, #Class, sizeof(*this));                              \
   return r;                                                                   \
 }
 
 #define NS_IMPL_RELEASE_INHERITED(Class, Super)                               \
-NS_IMETHODIMP_(nsrefcnt) Class::Release(void)                                 \
+NS_IMETHODIMP_(MozExternalRefCountType) Class::Release(void)                  \
 {                                                                             \
   nsrefcnt r = Super::Release();                                              \
   NS_LOG_RELEASE(this, r, #Class);                                            \
   return r;                                                                   \
 }
 
 /**
  * As above but not logging the addref/release; needed if the base
  * class might be aggregated.
  */
 #define NS_IMPL_NONLOGGING_ADDREF_INHERITED(Class, Super)                     \
-NS_IMETHODIMP_(nsrefcnt) Class::AddRef(void)                                  \
+NS_IMETHODIMP_(MozExternalRefCountType) Class::AddRef(void)                   \
 {                                                                             \
   return Super::AddRef();                                                     \
 }
 
 #define NS_IMPL_NONLOGGING_RELEASE_INHERITED(Class, Super)                    \
-NS_IMETHODIMP_(nsrefcnt) Class::Release(void)                                 \
+NS_IMETHODIMP_(MozExternalRefCountType) Class::Release(void)                  \
 {                                                                             \
   return Super::Release();                                                    \
 }
 
 #define NS_INTERFACE_TABLE_INHERITED0(Class) /* Nothing to do here */
 
 #define NS_INTERFACE_TABLE_INHERITED1(Class, i1)                              \
   NS_INTERFACE_TABLE_BEGIN                                                    \
--- a/xpcom/io/nsPipe3.cpp
+++ b/xpcom/io/nsPipe3.cpp
@@ -677,24 +677,24 @@ nsPipeInputStream::OnInputException(nsre
         mCallbackFlags = 0;
     }
     else if (mBlocked)
         result = true;
 
     return result;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsPipeInputStream::AddRef(void)
 {
     ++mReaderRefCnt;
     return mPipe->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsPipeInputStream::Release(void)
 {
     if (--mReaderRefCnt == 0)
         Close();
     return mPipe->Release();
 }
 
 NS_IMETHODIMP
@@ -1032,24 +1032,24 @@ nsPipeOutputStream::OnOutputException(ns
     }
     else if (mBlocked)
         result = true;
 
     return result;
 }
 
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsPipeOutputStream::AddRef()
 {
     ++mWriterRefCnt;
     return mPipe->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsPipeOutputStream::Release()
 {
     if (--mWriterRefCnt == 0)
         Close();
     return mPipe->Release();
 }
 
 NS_IMETHODIMP
--- a/xpcom/io/nsUnicharInputStream.cpp
+++ b/xpcom/io/nsUnicharInputStream.cpp
@@ -368,18 +368,18 @@ UTF8InputStream::CountValidUTF8Bytes(con
   aValidUTF8bytes = c - aBuffer;
   aValidUTF16CodeUnits = utf16length;
 }
 
 NS_IMPL_QUERY_INTERFACE2(nsSimpleUnicharStreamFactory,
                          nsIFactory,
                          nsISimpleUnicharStreamFactory)
 
-NS_IMETHODIMP_(nsrefcnt) nsSimpleUnicharStreamFactory::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) nsSimpleUnicharStreamFactory::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsSimpleUnicharStreamFactory::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsSimpleUnicharStreamFactory::Release() { return 1; }
 
 NS_IMETHODIMP
 nsSimpleUnicharStreamFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
                                             void **aResult)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
--- a/xpcom/reflect/xptcall/src/xptcall.cpp
+++ b/xpcom/reflect/xptcall/src/xptcall.cpp
@@ -19,23 +19,23 @@ nsXPTCStubBase::QueryInterface(REFNSIID 
         NS_ADDREF_THIS();
         *aInstancePtr = static_cast<nsISupports*>(this);
         return NS_OK;
     }
 
     return mOuter->QueryInterface(aIID, aInstancePtr);
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsXPTCStubBase::AddRef()
 {
     return mOuter->AddRef();
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 nsXPTCStubBase::Release()
 {
     return mOuter->Release();
 }
 
 EXPORT_XPCOM_API(nsresult)
 NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
                   nsISomeInterface* *aResult)
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
@@ -586,25 +586,25 @@ xptiInterfaceInfo::xptiInterfaceInfo(xpt
 
 xptiInterfaceInfo::~xptiInterfaceInfo() 
 {
     LOG_INFO_DESTROY(this);
     NS_IF_RELEASE(mParent); 
     NS_ASSERTION(!mEntry, "bad state in dtor");
 }
 
-nsrefcnt
+MozExternalRefCountType
 xptiInterfaceInfo::AddRef(void)
 {
     nsrefcnt cnt = ++mRefCnt;
     NS_LOG_ADDREF(this, cnt, "xptiInterfaceInfo", sizeof(*this));
     return cnt;
 }
 
-nsrefcnt
+MozExternalRefCountType
 xptiInterfaceInfo::Release(void)
 {
     xptiInterfaceEntry* entry = mEntry;
     nsrefcnt cnt = --mRefCnt;
     NS_LOG_RELEASE(this, cnt, "xptiInterfaceInfo");
     if(!cnt)
     {
         mozilla::ReentrantMonitorAutoEnter monitor(XPTInterfaceInfoManager::
--- a/xpcom/tests/TestCOMArray.cpp
+++ b/xpcom/tests/TestCOMArray.cpp
@@ -13,33 +13,33 @@
   {0x9e70a320, 0xbe02, 0x11d1,    \
     {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
 
 class IFoo : public nsISupports {
 public:
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
 
-  NS_IMETHOD_(nsrefcnt) RefCnt() = 0;
+  NS_IMETHOD_(MozExternalRefCountType) RefCnt() = 0;
   NS_IMETHOD_(int32_t) ID() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(IFoo, NS_IFOO_IID)
 
 class Foo MOZ_FINAL : public IFoo {
 public:
 
   Foo(int32_t aID);
   ~Foo();
 
   // nsISupports implementation
   NS_DECL_ISUPPORTS
 
   // IFoo implementation
-  NS_IMETHOD_(nsrefcnt) RefCnt() { return mRefCnt; }
+  NS_IMETHOD_(MozExternalRefCountType) RefCnt() { return mRefCnt; }
   NS_IMETHOD_(int32_t) ID() { return mID; }
 
   static int32_t gCount;
 
   int32_t mID;
 };
 
 int32_t Foo::gCount = 0;
@@ -103,17 +103,17 @@ Bar::~Bar()
   if (mArray.RemoveObject(this)) {
     fail("We should never manage to remove the object here");
   }
 }
 
 NS_IMPL_ADDREF(Bar)
 NS_IMPL_QUERY_INTERFACE1(Bar, IBar)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 Bar::Release(void)
 {
   ++Bar::sReleaseCalled;
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
   NS_ASSERT_OWNINGTHREAD(_class);
   --mRefCnt;
   NS_LOG_RELEASE(this, mRefCnt, "Bar");
   if (mRefCnt == 0) {
--- a/xpcom/tests/TestCOMPtr.cpp
+++ b/xpcom/tests/TestCOMPtr.cpp
@@ -17,18 +17,18 @@ class IFoo : public nsISupports
 		public:
 			NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
 
 		public:
       IFoo();
       // virtual dtor because IBar uses our Release()
       virtual ~IFoo();
 
-      NS_IMETHOD_(nsrefcnt) AddRef();
-      NS_IMETHOD_(nsrefcnt) Release();
+      NS_IMETHOD_(MozExternalRefCountType) AddRef();
+      NS_IMETHOD_(MozExternalRefCountType) Release();
       NS_IMETHOD QueryInterface( const nsIID&, void** );
 
       static void print_totals();
 
     private:
       unsigned int refcount_;
 
       static unsigned int total_constructions_;
@@ -96,26 +96,26 @@ IFoo::IFoo()
 
 IFoo::~IFoo()
   {
     ++total_destructions_;
     printf("IFoo@%p::~IFoo() [#%d]\n",
            static_cast<void*>(this), total_destructions_);
   }
 
-nsrefcnt
+MozExternalRefCountType
 IFoo::AddRef()
   {
     ++refcount_;
     printf("IFoo@%p::AddRef(), refcount --> %d\n", 
            static_cast<void*>(this), refcount_);
     return refcount_;
   }
 
-nsrefcnt
+MozExternalRefCountType
 IFoo::Release()
   {
     int newcount = --refcount_;
     if ( newcount == 0 )
       printf(">>");
 
     printf("IFoo@%p::Release(), refcount --> %d\n",
            static_cast<void*>(this), refcount_);
--- a/xpcom/tests/TestHarness.h
+++ b/xpcom/tests/TestHarness.h
@@ -264,21 +264,21 @@ class ScopedXPCOM : public nsIDirectoryS
 };
 
 NS_IMPL_QUERY_INTERFACE2(
   ScopedXPCOM,
   nsIDirectoryServiceProvider,
   nsIDirectoryServiceProvider2
 )
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 ScopedXPCOM::AddRef()
 {
   return 2;
 }
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 ScopedXPCOM::Release()
 {
   return 1;
 }
 
 #endif  // TestHarness_h__
--- a/xpcom/tests/TestHashtables.cpp
+++ b/xpcom/tests/TestHashtables.cpp
@@ -194,18 +194,18 @@ nsCEnum(const nsACString& aKey, nsAutoPt
 
 class IFoo MOZ_FINAL : public nsISupports
   {
     public:
       NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
 
       IFoo();
 
-      NS_IMETHOD_(nsrefcnt) AddRef();
-      NS_IMETHOD_(nsrefcnt) Release();
+      NS_IMETHOD_(MozExternalRefCountType) AddRef();
+      NS_IMETHOD_(MozExternalRefCountType) Release();
       NS_IMETHOD QueryInterface( const nsIID&, void** );
 
       NS_IMETHOD SetString(const nsACString& /*in*/ aString);
       NS_IMETHOD GetString(nsACString& /*out*/ aString);
 
       static void print_totals();
 
     private:
@@ -240,26 +240,26 @@ IFoo::IFoo()
 
 IFoo::~IFoo()
   {
     ++total_destructions_;
     printf("IFoo@%p::~IFoo() [#%d]\n",
            static_cast<void*>(this), total_destructions_);
   }
 
-nsrefcnt
+MozExternalRefCountType
 IFoo::AddRef()
   {
     ++refcount_;
     printf("IFoo@%p::AddRef(), refcount --> %d\n", 
            static_cast<void*>(this), refcount_);
     return refcount_;
   }
 
-nsrefcnt
+MozExternalRefCountType
 IFoo::Release()
   {
     int newcount = --refcount_;
     if ( newcount == 0 )
       printf(">>");
 
     printf("IFoo@%p::Release(), refcount --> %d\n",
            static_cast<void*>(this), refcount_);
--- a/xpcom/tests/TestRefPtr.cpp
+++ b/xpcom/tests/TestRefPtr.cpp
@@ -18,18 +18,18 @@ class Foo : public nsISupports
 		public:
 			NS_DECLARE_STATIC_IID_ACCESSOR(NS_FOO_IID)
 
 		public:
       Foo();
       // virtual dtor because Bar uses our Release()
       virtual ~Foo();
 
-      NS_IMETHOD_(nsrefcnt) AddRef();
-      NS_IMETHOD_(nsrefcnt) Release();
+      NS_IMETHOD_(MozExternalRefCountType) AddRef();
+      NS_IMETHOD_(MozExternalRefCountType) Release();
       NS_IMETHOD QueryInterface( const nsIID&, void** );
 
       static void print_totals();
 
     private:
       unsigned int refcount_;
 
       static unsigned int total_constructions_;
@@ -97,26 +97,26 @@ Foo::Foo()
 
 Foo::~Foo()
   {
     ++total_destructions_;
     printf("Foo@%p::~Foo() [#%d]\n",
            static_cast<void*>(this), total_destructions_);
   }
 
-nsrefcnt
+MozExternalRefCountType
 Foo::AddRef()
   {
     ++refcount_;
     printf("Foo@%p::AddRef(), refcount --> %d\n",
            static_cast<void*>(this), refcount_);
     return refcount_;
   }
 
-nsrefcnt
+MozExternalRefCountType
 Foo::Release()
   {
     int newcount = --refcount_;
     if ( newcount == 0 )
       printf(">>");
 
     printf("Foo@%p::Release(), refcount --> %d\n",
            static_cast<void*>(this), refcount_);
--- a/xpcom/tests/windows/TestCOM.cpp
+++ b/xpcom/tests/windows/TestCOM.cpp
@@ -45,25 +45,25 @@ public:
 private:
   ~nsTestCom() {
     printf("nsTestCom instance successfully deleted\n");
   }
 };
 
 NS_IMPL_QUERY_INTERFACE1(nsTestCom, nsITestCom)
 
-nsrefcnt nsTestCom::AddRef() 
+MozExternalRefCountType nsTestCom::AddRef()
 {
   nsrefcnt res = ++mRefCnt;
   NS_LOG_ADDREF(this, mRefCnt, "nsTestCom", sizeof(*this));
   printf("nsTestCom: Adding ref = %d\n", res);
   return res;
 }
 
-nsrefcnt nsTestCom::Release() 
+MozExternalRefCountType nsTestCom::Release()
 {
   nsrefcnt res = --mRefCnt;
   NS_LOG_RELEASE(this, mRefCnt, "nsTestCom");
   printf("nsTestCom: Releasing = %d\n", res);
   if (res == 0) {
     delete this;
   }
   return res;
--- a/xpcom/threads/LazyIdleThread.cpp
+++ b/xpcom/threads/LazyIdleThread.cpp
@@ -339,17 +339,17 @@ void
 LazyIdleThread::SelfDestruct()
 {
   MOZ_ASSERT(mRefCnt == 1, "Bad refcount!");
   delete this;
 }
 
 NS_IMPL_ADDREF(LazyIdleThread)
 
-NS_IMETHODIMP_(nsrefcnt)
+NS_IMETHODIMP_(MozExternalRefCountType)
 LazyIdleThread::Release()
 {
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "LazyIdleThread");
 
   if (!count) {
     // Stabilize refcount.
     mRefCnt = 1;
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -86,18 +86,18 @@ nsIThreadObserver* nsThread::sMainThread
 class nsThreadClassInfo : public nsIClassInfo {
 public:
   NS_DECL_ISUPPORTS_INHERITED  // no mRefCnt
   NS_DECL_NSICLASSINFO
 
   nsThreadClassInfo() {}
 };
 
-NS_IMETHODIMP_(nsrefcnt) nsThreadClassInfo::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) nsThreadClassInfo::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsThreadClassInfo::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsThreadClassInfo::Release() { return 1; }
 NS_IMPL_QUERY_INTERFACE1(nsThreadClassInfo, nsIClassInfo)
 
 NS_IMETHODIMP
 nsThreadClassInfo::GetInterfaces(uint32_t *count, nsIID ***array)
 {
   return NS_CI_INTERFACE_GETTER_NAME(nsThread)(count, array);
 }
 
--- a/xpcom/threads/nsThreadManager.cpp
+++ b/xpcom/threads/nsThreadManager.cpp
@@ -38,18 +38,18 @@ static PLDHashOperator
 AppendAndRemoveThread(PRThread *key, nsRefPtr<nsThread> &thread, void *arg)
 {
   nsThreadArray *threads = static_cast<nsThreadArray *>(arg);
   threads->AppendElement(thread);
   return PL_DHASH_REMOVE;
 }
 
 // statically allocated instance
-NS_IMETHODIMP_(nsrefcnt) nsThreadManager::AddRef() { return 2; }
-NS_IMETHODIMP_(nsrefcnt) nsThreadManager::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsThreadManager::AddRef() { return 2; }
+NS_IMETHODIMP_(MozExternalRefCountType) nsThreadManager::Release() { return 1; }
 NS_IMPL_CLASSINFO(nsThreadManager, nullptr,
                   nsIClassInfo::THREADSAFE | nsIClassInfo::SINGLETON,
                   NS_THREADMANAGER_CID)
 NS_IMPL_QUERY_INTERFACE1_CI(nsThreadManager, nsIThreadManager)
 NS_IMPL_CI_INTERFACE_GETTER1(nsThreadManager, nsIThreadManager)
 
 //-----------------------------------------------------------------------------
 
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -189,17 +189,17 @@ void TimerEventAllocator::Free(void* aPt
   mFirstFree = entry;
 }
 
 } // anonymous namespace
 
 NS_IMPL_QUERY_INTERFACE1(nsTimerImpl, nsITimer)
 NS_IMPL_ADDREF(nsTimerImpl)
 
-NS_IMETHODIMP_(nsrefcnt) nsTimerImpl::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType) nsTimerImpl::Release(void)
 {
   nsrefcnt count;
 
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
   count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "nsTimerImpl");
   if (count == 0) {
     mRefCnt = 1; /* stabilize */