From abb5f8b703ab46eefceade8267670bd4cebbac37 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Fri, 26 Oct 2001 00:09:22 +0000 Subject: [PATCH] Freeze nsIMemory interface bug 99151 r=rpotts@netscape.com, sr=brendan@netscape.com --- content/xbl/src/nsXBLService.cpp | 4 +- intl/strres/src/nsStringBundle.cpp | 4 +- modules/libjar/nsJAR.cpp | 4 +- xpcom/base/nsIAllocator.h | 2 +- xpcom/base/nsIMemory.idl | 74 ++++++++++-------------------- xpcom/base/nsMemoryImpl.cpp | 10 ++-- xpcom/base/nsMemoryImpl.h | 2 + 7 files changed, 38 insertions(+), 62 deletions(-) diff --git a/content/xbl/src/nsXBLService.cpp b/content/xbl/src/nsXBLService.cpp index 6b253bbfda6..11f7089c1cf 100644 --- a/content/xbl/src/nsXBLService.cpp +++ b/content/xbl/src/nsXBLService.cpp @@ -904,7 +904,7 @@ nsXBLService::AttachGlobalDragHandler(nsIDOMEventReceiver* aReceiver) NS_IMETHODIMP nsXBLService::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData) { - if (nsCRT::strcmp(aTopic, NS_MEMORY_PRESSURE_TOPIC) == 0) + if (nsCRT::strcmp(aTopic, "memory-pressure") == 0) FlushMemory(); return NS_OK; @@ -1506,7 +1506,7 @@ NS_NewXBLService(nsIXBLService** aResult) // so it can flush the LRU list in low-memory situations. nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); if (os) - os->AddObserver(result, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE); + os->AddObserver(result, "memory-pressure", PR_TRUE); return NS_OK; } diff --git a/intl/strres/src/nsStringBundle.cpp b/intl/strres/src/nsStringBundle.cpp index 29c8ea89dc7..eaeae01a0f3 100644 --- a/intl/strres/src/nsStringBundle.cpp +++ b/intl/strres/src/nsStringBundle.cpp @@ -797,7 +797,7 @@ nsStringBundleService::Init() { nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); if (os) - os->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE); + os->AddObserver(this, "memory-pressure", PR_TRUE); return NS_OK; } @@ -807,7 +807,7 @@ nsStringBundleService::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData) { - if (nsCRT::strcmp(NS_MEMORY_PRESSURE_TOPIC, aTopic) == 0) + if (nsCRT::strcmp("memory-pressure", aTopic) == 0) flushBundleCache(); return NS_OK; } diff --git a/modules/libjar/nsJAR.cpp b/modules/libjar/nsJAR.cpp index 6cae4bd9385..79f26c2fa08 100644 --- a/modules/libjar/nsJAR.cpp +++ b/modules/libjar/nsJAR.cpp @@ -1146,7 +1146,7 @@ nsZipReaderCache::Init(PRUint32 cacheSize) do_GetService("@mozilla.org/observer-service;1", &rv); if (NS_SUCCEEDED(rv)) { - rv = os->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE); + rv = os->AddObserver(this, "memory-pressure", PR_TRUE); } // ignore failure of the observer registration. @@ -1359,7 +1359,7 @@ nsZipReaderCache::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aSomeData) { - if (nsCRT::strcmp(aTopic, NS_MEMORY_PRESSURE_TOPIC) == 0) { + if (nsCRT::strcmp(aTopic, "memory-pressure") == 0) { nsAutoLock lock(mLock); while (PR_TRUE) { nsHashKey* flushable = nsnull; diff --git a/xpcom/base/nsIAllocator.h b/xpcom/base/nsIAllocator.h index f31fcd0904d..3c25e87eba1 100644 --- a/xpcom/base/nsIAllocator.h +++ b/xpcom/base/nsIAllocator.h @@ -49,7 +49,7 @@ #define GetGlobalAllocator GetGlobalMemoryService #define NS_IALLOCATOR_IID NS_GET_IID(nsIMemory) -#define NS_ALLOCATOR_CONTRACTID NS_MEMORY_CONTRACTID +#define NS_ALLOCATOR_CONTRACTID NS_MEMORY_CONTRACTID #define NS_ALLOCATOR_CLASSNAME NS_MEMORY_CLASSNAME #define NS_ALLOCATOR_CID NS_MEMORY_CID diff --git a/xpcom/base/nsIMemory.idl b/xpcom/base/nsIMemory.idl index b4db044283b..6575387e28d 100644 --- a/xpcom/base/nsIMemory.idl +++ b/xpcom/base/nsIMemory.idl @@ -35,31 +35,38 @@ * * ***** END LICENSE BLOCK ***** */ -/** - * W A R N I N G - *

This API is currently under review in preparation for making it an - * officially supported part of the mozilla platform. Please submit comments - * to porkjockeys@mozilla.org before 6/15/00. Until that time, it is not - * advised to base commercial products on this API because it is subject to - * change. Use at your own risk! - * - * - * @status UNDER_REVIEW - */ - #include "nsISupports.idl" /** + * * nsIMemory: interface to allocate and deallocate memory. Also provides * for notifications in low-memory situations. * * A client that wishes to be notified of low memory situations (for * example, because the client maintains a large memory cache that - * could be released when memory is tight) may register with the - * observer service (see nsIObserverService) using the - * NS_MEMORY_PRESSURE_TOPIC ("memory-pressure") as the topic for - * observation. + * could be released when memory is tight) should register with the + * observer service (see nsIObserverService) using the topic + * "memory-pressure". There are three specific types of notications + * that can occur. These types will be passed as the |aData| + * parameter of the of the "memory-pressure" notification: + * + * "low-memory" + * This will be passed as the extra data when the pressure + * observer is being asked to flush for low-memory conditions. + * + * "heap-minimize" + * This will be passed as the extra data when the pressure + * observer is being asked to flush because of a heap minimize + * call. + * + * "alloc-failure" + * This will be passed as the extra data when the pressure + * observer has been asked to flush because a malloc() or + * realloc() has failed. + * + * @status FROZEN */ + [scriptable, uuid(59e7e77a-38e4-11d4-8cf5-0060b0fc14a3)] interface nsIMemory : nsISupports { @@ -112,41 +119,8 @@ interface nsIMemory : nsISupports /** * This predicate can be used to determine if we're in a low-memory * situation (what constitutes low-memory is platform dependent). This - * can be used to trigger the memory flushers. + * can be used to trigger the memory pressure observers. */ boolean isLowMemory(); }; -%{C++ -/** - * This is the topic that a memory pressure observer - * should use with the observer service. - */ -#define NS_MEMORY_PRESSURE_TOPIC "memory-pressure" - -/** - * This will be passed as the extra data when the flusher - * is being asked to flush for low-memory conditions. - */ -#define NS_MEMORY_PRESSURE_LOW_MEMORY "low-memory" - -/** - * This will be passed as the extra data when the flusher - * is being asked to flush because of a heap minimize call. - */ -#define NS_MEMORY_PRESSURE_HEAP_MINIMIZE "heap-minimize" - -/** - * This will be passed as the extra data when the flusher - * has been asked to flush because a malloc() or realloc() - * has failed. - */ -#define NS_MEMORY_PRESSURE_ALLOC_FAILURE "alloc-failure" -%} - -%{C++ -/** - * ContractID for the global memory service: - */ -#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1" -%} diff --git a/xpcom/base/nsMemoryImpl.cpp b/xpcom/base/nsMemoryImpl.cpp index c2ffb8f3b1d..efd6ba5b147 100644 --- a/xpcom/base/nsMemoryImpl.cpp +++ b/xpcom/base/nsMemoryImpl.cpp @@ -189,7 +189,7 @@ MemoryFlusher::Run() #endif if (isLowMemory) { - mMemoryImpl->FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_LOW_MEMORY).get(), PR_FALSE); + mMemoryImpl->FlushMemory(NS_LITERAL_STRING("low-memory").get(), PR_FALSE); } } @@ -320,7 +320,7 @@ nsMemoryImpl::Alloc(PRSize size) void* result = MALLOC1(size); if (! result) { // Request an asynchronous flush - FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_ALLOC_FAILURE).get(), PR_FALSE); + FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE); } return result; } @@ -331,7 +331,7 @@ nsMemoryImpl::Realloc(void * ptr, PRSize size) void* result = REALLOC1(ptr, size); if (! result) { // Request an asynchronous flush - FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_ALLOC_FAILURE).get(), PR_FALSE); + FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE); } return result; } @@ -345,7 +345,7 @@ nsMemoryImpl::Free(void * ptr) NS_IMETHODIMP nsMemoryImpl::HeapMinimize(PRBool aImmediate) { - return FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_HEAP_MINIMIZE).get(), aImmediate); + return FlushMemory(NS_LITERAL_STRING("heap-minimize").get(), aImmediate); } NS_IMETHODIMP @@ -457,7 +457,7 @@ nsMemoryImpl::RunFlushers(nsMemoryImpl* aSelf, const PRUnichar* aReason) { nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); if (os) { - os->NotifyObservers(aSelf, NS_MEMORY_PRESSURE_TOPIC, aReason); + os->NotifyObservers(aSelf, "memory-pressure", aReason); } { diff --git a/xpcom/base/nsMemoryImpl.h b/xpcom/base/nsMemoryImpl.h index f1625734f1b..c5c27fc659d 100644 --- a/xpcom/base/nsMemoryImpl.h +++ b/xpcom/base/nsMemoryImpl.h @@ -45,6 +45,8 @@ #include "nsCOMPtr.h" #include "plevent.h" +#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1" + struct PRLock; class MemoryFlusher;