Bug 664898 - Cleanup startup cache api, r=taras
authorMichael Wu <mwu@mozilla.com>
Wed, 20 Jul 2011 00:39:09 -0700
changeset 73835 a9f847216e1f22297a3f263a6382f455914203bf
parent 73834 2c4ddbb3baf213155fbc9d80e725d691e53cadf3
child 73836 892099d1694ddf985b2adf941693235aae1a0fb7
child 73840 faa1737443dd084c2595fc7fd583ae1e602c365b
push id235
push userbzbarsky@mozilla.com
push dateTue, 27 Sep 2011 17:13:04 +0000
treeherdermozilla-beta@2d1e082d176a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs664898
milestone8.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 664898 - Cleanup startup cache api, r=taras
content/xul/document/src/nsXULPrototypeCache.cpp
js/src/xpconnect/loader/mozJSComponentLoader.cpp
js/src/xpconnect/loader/mozJSComponentLoader.h
js/src/xpconnect/loader/mozJSLoaderUtils.cpp
js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
startupcache/StartupCacheUtils.cpp
startupcache/StartupCacheUtils.h
startupcache/test/TestStartupCache.cpp
--- a/content/xul/document/src/nsXULPrototypeCache.cpp
+++ b/content/xul/document/src/nsXULPrototypeCache.cpp
@@ -452,31 +452,31 @@ nsXULPrototypeCache::WritePrototype(nsXU
     FinishOutputStream(protoURI);
     return NS_FAILED(rv) ? rv : rv2;
 }
 
 nsresult
 nsXULPrototypeCache::GetInputStream(nsIURI* uri, nsIObjectInputStream** stream) 
 {
     nsCAutoString spec(kXULCachePrefix);
-    nsresult rv = NS_PathifyURI(uri, spec);
+    nsresult rv = PathifyURI(uri, spec);
     if (NS_FAILED(rv)) 
         return NS_ERROR_NOT_AVAILABLE;
     
     nsAutoArrayPtr<char> buf;
     PRUint32 len;
     nsCOMPtr<nsIObjectInputStream> ois;
     if (!gStartupCache)
         return NS_ERROR_NOT_AVAILABLE;
     
     rv = gStartupCache->GetBuffer(spec.get(), getter_Transfers(buf), &len);
     if (NS_FAILED(rv)) 
         return NS_ERROR_NOT_AVAILABLE;
 
-    rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
+    rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
     NS_ENSURE_SUCCESS(rv, rv);
     buf.forget();
 
     mInputStreamTable.Put(uri, ois);
     
     NS_ADDREF(*stream = ois);
     return NS_OK;
 }
@@ -496,19 +496,19 @@ nsXULPrototypeCache::GetOutputStream(nsI
     PRBool found = mOutputStreamTable.Get(uri, getter_AddRefs(storageStream));
     if (found) {
         objectOutput = do_CreateInstance("mozilla.org/binaryoutputstream;1");
         if (!objectOutput) return NS_ERROR_OUT_OF_MEMORY;
         nsCOMPtr<nsIOutputStream> outputStream
             = do_QueryInterface(storageStream);
         objectOutput->SetOutputStream(outputStream);
     } else {
-        rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput), 
-                                                    getter_AddRefs(storageStream),
-                                                    false);
+        rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput), 
+                                                 getter_AddRefs(storageStream),
+                                                 false);
         NS_ENSURE_SUCCESS(rv, rv);
         mOutputStreamTable.Put(uri, storageStream);
     }
     NS_ADDREF(*stream = objectOutput);
     return NS_OK;
 }
 
 nsresult
@@ -523,22 +523,22 @@ nsXULPrototypeCache::FinishOutputStream(
     if (!found)
         return NS_ERROR_UNEXPECTED;
     nsCOMPtr<nsIOutputStream> outputStream
         = do_QueryInterface(storageStream);
     outputStream->Close();
     
     nsAutoArrayPtr<char> buf;
     PRUint32 len;
-    rv = NS_NewBufferFromStorageStream(storageStream, getter_Transfers(buf), 
-                                       &len);
+    rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf), 
+                                    &len);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCAutoString spec(kXULCachePrefix);
-    rv = NS_PathifyURI(uri, spec);
+    rv = PathifyURI(uri, spec);
     if (NS_FAILED(rv))
         return NS_ERROR_NOT_AVAILABLE;
     rv = gStartupCache->PutBuffer(spec.get(), buf, len);
     if (NS_SUCCEEDED(rv))
         mOutputStreamTable.Remove(uri);
     
     return rv;
 }
@@ -548,17 +548,17 @@ nsXULPrototypeCache::FinishOutputStream(
 nsresult
 nsXULPrototypeCache::HasData(nsIURI* uri, PRBool* exists)
 {
     if (mOutputStreamTable.Get(uri, nsnull)) {
         *exists = PR_TRUE;
         return NS_OK;
     }
     nsCAutoString spec(kXULCachePrefix);
-    nsresult rv = NS_PathifyURI(uri, spec);
+    nsresult rv = PathifyURI(uri, spec);
     if (NS_FAILED(rv)) {
         *exists = PR_FALSE;
         return NS_OK;
     }
     nsAutoArrayPtr<char> buf;
     PRUint32 len;
     if (gStartupCache)
         rv = gStartupCache->GetBuffer(spec.get(), getter_Transfers(buf), 
@@ -663,17 +663,17 @@ nsXULPrototypeCache::BeginCaching(nsIURI
     
     nsAutoArrayPtr<char> buf;
     PRUint32 len, amtRead;
     nsCOMPtr<nsIObjectInputStream> objectInput;
 
     rv = startupCache->GetBuffer(kXULCacheInfoKey, getter_Transfers(buf), 
                                  &len);
     if (NS_SUCCEEDED(rv))
-        rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(objectInput));
+        rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(objectInput));
     
     if (NS_SUCCEEDED(rv)) {
         buf.forget();
         rv = objectInput->ReadCString(fileLocale);
         rv |= objectInput->ReadCString(fileChromePath);
         if (NS_FAILED(rv) ||
             (!fileChromePath.Equals(chromePath) ||
              !fileLocale.Equals(locale))) {
@@ -687,19 +687,19 @@ nsXULPrototypeCache::BeginCaching(nsIURI
         // NS_ERROR_NOT_AVAILABLE is normal, usually if there's no cachefile.
         return rv;
 
     if (NS_FAILED(rv)) {
         // Either the cache entry was invalid or it didn't exist, so write it now.
         nsCOMPtr<nsIObjectOutputStream> objectOutput;
         nsCOMPtr<nsIInputStream> inputStream;
         nsCOMPtr<nsIStorageStream> storageStream;
-        rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
-                                                    getter_AddRefs(storageStream),
-                                                    false);
+        rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
+                                                 getter_AddRefs(storageStream),
+                                                 false);
         if (NS_SUCCEEDED(rv)) {
             rv = objectOutput->WriteStringZ(locale.get());
             rv |= objectOutput->WriteStringZ(chromePath.get());
             rv |= objectOutput->Close();
             rv |= storageStream->NewInputStream(0, getter_AddRefs(inputStream));
         }
         if (NS_SUCCEEDED(rv))
             rv = inputStream->Available(&len);
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -91,16 +91,18 @@
 #include "mozilla/scache/StartupCache.h"
 #include "mozilla/scache/StartupCacheUtils.h"
 #include "mozilla/Omnijar.h"
 
 #include "jsdbgapi.h"
 
 #include "mozilla/FunctionTimer.h"
 
+using namespace mozilla::scache;
+
 static const char kJSRuntimeServiceContractID[] = "@mozilla.org/js/xpc/RuntimeService;1";
 static const char kXPConnectServiceContractID[] = "@mozilla.org/js/xpc/XPConnect;1";
 static const char kObserverServiceContractID[] = "@mozilla.org/observer-service;1";
 static const char kJSCachePrefix[] = "jsloader";
 
 /* Some platforms don't have an implementation of PR_MemMap(). */
 #ifndef XP_OS2
 #define HAVE_PR_MEMMAP
@@ -850,17 +852,17 @@ mozJSComponentLoader::GlobalForLocation(
     // Before compiling the script, first check to see if we have it in
     // the startupcache.  Note: as a rule, startupcache errors are not fatal
     // to loading the script, since we can always slow-load.
     
     PRBool writeToCache = PR_FALSE;
     StartupCache* cache = StartupCache::GetSingleton();
 
     nsCAutoString cachePath(kJSCachePrefix);
-    rv = NS_PathifyURI(aURI, cachePath);
+    rv = PathifyURI(aURI, cachePath);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (cache) {
         rv = ReadCachedScript(cache, cachePath, cx, &scriptObj);
         if (NS_SUCCEEDED(rv)) {
             LOG(("Successfully loaded %s from startupcache\n", nativePath.get()));
         } else {
             // This is ok, it just means the script is not yet in the
--- a/js/src/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.h
@@ -51,18 +51,16 @@
 #include "nsITimer.h"
 #include "nsIObserver.h"
 #include "xpcIJSModuleLoader.h"
 #include "nsClassHashtable.h"
 #include "nsDataHashtable.h"
 #include "nsIPrincipal.h"
 #include "mozilla/scache/StartupCache.h"
 
-using namespace mozilla::scache;
-
 #include "xpcIJSGetFactory.h"
 
 /* 6bd13476-1dd2-11b2-bbef-f0ccb5fa64b6 (thanks, mozbot) */
 
 #define MOZJSCOMPONENTLOADER_CID \
   {0x6bd13476, 0x1dd2, 0x11b2, \
     { 0xbb, 0xef, 0xf0, 0xcc, 0xb5, 0xfa, 0x64, 0xb6 }}
 #define MOZJSCOMPONENTLOADER_CONTRACTID "@mozilla.org/moz/jsloader;1"
--- a/js/src/xpconnect/loader/mozJSLoaderUtils.cpp
+++ b/js/src/xpconnect/loader/mozJSLoaderUtils.cpp
@@ -155,42 +155,41 @@ ReadCachedScript(StartupCache* cache, ns
     PRUint32 len;
     rv = cache->GetBuffer(PromiseFlatCString(uri).get(), getter_Transfers(buf),
                           &len);
     if (NS_FAILED(rv)) {
         return rv; // don't warn since NOT_AVAILABLE is an ok error
     }
 
     nsCOMPtr<nsIObjectInputStream> ois;
-    rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
+    rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
     NS_ENSURE_SUCCESS(rv, rv);
     buf.forget();
 
     return ReadScriptFromStream(cx, ois, scriptObj);
 }
 
 nsresult
 WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject *scriptObj)
 {
     nsresult rv;
 
     nsCOMPtr<nsIObjectOutputStream> oos;
     nsCOMPtr<nsIStorageStream> storageStream;
-    rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(oos),
-                                                getter_AddRefs(storageStream),
-                                                true);
+    rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(oos),
+                                             getter_AddRefs(storageStream),
+                                             true);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = WriteScriptToStream(cx, scriptObj, oos);
     oos->Close();
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoArrayPtr<char> buf;
     PRUint32 len;
-    rv = NS_NewBufferFromStorageStream(storageStream, getter_Transfers(buf),
-                                       &len);
+    rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf), &len);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = cache->PutBuffer(PromiseFlatCString(uri).get(), buf, len);
     return rv;
 }
 
 #endif /* XPCONNECT_STANDALONE */
--- a/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -380,17 +380,17 @@ mozJSSubScriptLoader::LoadSubScript (con
         uriStr = tmp;
     }
 
     bool writeScript = false;
     JSObject *scriptObj = nsnull;
     JSVersion version = cx->findVersion();
     nsCAutoString cachePath;
     cachePath.AppendPrintf("jssubloader/%d", version);
-    NS_PathifyURI(uri, cachePath);
+    PathifyURI(uri, cachePath);
 
     if (cache)
         rv = ReadCachedScript(cache, cachePath, cx, &scriptObj);
     if (!scriptObj) {
         rv = ReadScript(uri, cx, target_obj, charset, (char *)uriStr.get(), serv, &scriptObj);
         writeScript = true;
     }
 
--- a/startupcache/StartupCacheUtils.cpp
+++ b/startupcache/StartupCacheUtils.cpp
@@ -48,35 +48,35 @@
 #include "StartupCacheUtils.h"
 #include "mozilla/scache/StartupCache.h"
 #include "mozilla/Omnijar.h"
 
 namespace mozilla {
 namespace scache {
 
 NS_EXPORT nsresult
-NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
-                                  nsIObjectInputStream** stream)
+NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
+                               nsIObjectInputStream** stream)
 {
   nsCOMPtr<nsIStringInputStream> stringStream
     = do_CreateInstance("@mozilla.org/io/string-input-stream;1");
   nsCOMPtr<nsIObjectInputStream> objectInput 
     = do_CreateInstance("@mozilla.org/binaryinputstream;1");
   
   stringStream->AdoptData(buffer, len);
   objectInput->SetInputStream(stringStream);
   
   objectInput.forget(stream);
   return NS_OK;
 }
 
 NS_EXPORT nsresult
-NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
-                                       nsIStorageStream** stream,
-                                       PRBool wantDebugStream)
+NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
+                                    nsIStorageStream** stream,
+                                    PRBool wantDebugStream)
 {
   nsCOMPtr<nsIStorageStream> storageStream;
 
   nsresult rv = NS_NewStorageStream(256, PR_UINT32_MAX, getter_AddRefs(storageStream));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIObjectOutputStream> objectOutput
     = do_CreateInstance("@mozilla.org/binaryoutputstream;1");
@@ -101,18 +101,18 @@ NS_NewObjectOutputWrappedStorageStream(n
   objectOutput.forget(wrapperStream);
 #endif
   
   storageStream.forget(stream);
   return NS_OK;
 }
 
 NS_EXPORT nsresult
-NS_NewBufferFromStorageStream(nsIStorageStream *storageStream, 
-                              char** buffer, PRUint32* len) 
+NewBufferFromStorageStream(nsIStorageStream *storageStream, 
+                           char** buffer, PRUint32* len) 
 {
   nsresult rv;
   nsCOMPtr<nsIInputStream> inputStream;
   rv = storageStream->NewInputStream(0, getter_AddRefs(inputStream));
   NS_ENSURE_SUCCESS(rv, rv);
   
   PRUint32 avail, read;
   rv = inputStream->Available(&avail);
@@ -175,17 +175,17 @@ canonicalizeBase(nsCAutoString &spec,
  *  jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm becomes
  *     jsloader/resource/gre/modules/XPCOMUtils.jsm
  *  file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
  *     jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js
  *  jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
  *     jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
  */
 NS_EXPORT nsresult
-NS_PathifyURI(nsIURI *in, nsACString &out)
+PathifyURI(nsIURI *in, nsACString &out)
 {
     PRBool equals;
     nsresult rv;
     nsCOMPtr<nsIURI> uri = in;
     nsCAutoString spec;
 
     // Resolve resource:// URIs. At the end of this if/else block, we
     // have both spec and uri variables identifying the same URI.
@@ -235,17 +235,17 @@ NS_PathifyURI(nsIURI *in, nsACString &ou
         } else if (NS_SUCCEEDED(uri->SchemeIs("jar", &equals)) && equals) {
             nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsCOMPtr<nsIURI> jarFileURI;
             rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
             NS_ENSURE_SUCCESS(rv, rv);
 
-            rv = NS_PathifyURI(jarFileURI, out);
+            rv = PathifyURI(jarFileURI, out);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsCAutoString path;
             rv = jarURI->GetJAREntry(path);
             NS_ENSURE_SUCCESS(rv, rv);
             out.Append("/");
             out.Append(path);
         } else { // Very unlikely
--- a/startupcache/StartupCacheUtils.h
+++ b/startupcache/StartupCacheUtils.h
@@ -41,31 +41,31 @@
 #include "nsIStorageStream.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 
 namespace mozilla {
 namespace scache {
 
 NS_EXPORT nsresult
-NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
-                                  nsIObjectInputStream** stream);
+NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
+                               nsIObjectInputStream** stream);
 
 // We can't retrieve the wrapped stream from the objectOutputStream later,
 // so we return it here. We give callers in debug builds the option 
 // to wrap the outputstream in a debug stream, which will detect if
 // non-singleton objects are written out multiple times during a serialization.
 // This could cause them to be deserialized incorrectly (as multiple copies
 // instead of references).
 NS_EXPORT nsresult
-NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
-                                       nsIStorageStream** stream,
-                                       PRBool wantDebugStream);
+NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
+                                    nsIStorageStream** stream,
+                                    PRBool wantDebugStream);
 
 NS_EXPORT nsresult
-NS_NewBufferFromStorageStream(nsIStorageStream *storageStream, 
-                              char** buffer, PRUint32* len);
+NewBufferFromStorageStream(nsIStorageStream *storageStream, 
+                           char** buffer, PRUint32* len);
 
 NS_EXPORT nsresult
-NS_PathifyURI(nsIURI *in, nsACString &out);
+PathifyURI(nsIURI *in, nsACString &out);
 }
 }
 #endif //nsStartupCacheUtils_h_
--- a/startupcache/test/TestStartupCache.cpp
+++ b/startupcache/test/TestStartupCache.cpp
@@ -51,28 +51,28 @@
 #include "nsIObjectOutputStream.h"
 #include "nsIURI.h"
 #include "nsStringAPI.h"
 
 namespace mozilla {
 namespace scache {
 
 NS_IMPORT nsresult
-NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
-                                  nsIObjectInputStream** stream);
+NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
+                               nsIObjectInputStream** stream);
 
 // We can't retrieve the wrapped stream from the objectOutputStream later,
 // so we return it here.
 NS_IMPORT nsresult
-NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
-                                       nsIStorageStream** stream);
+NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
+                                    nsIStorageStream** stream);
 
 NS_IMPORT nsresult
-NS_NewBufferFromStorageStream(nsIStorageStream *storageStream, 
-                              char** buffer, PRUint32* len);
+NewBufferFromStorageStream(nsIStorageStream *storageStream, 
+                           char** buffer, PRUint32* len);
 }
 }
 
 using namespace mozilla::scache;
 
 #define NS_ENSURE_STR_MATCH(str1, str2, testname)  \
 PR_BEGIN_MACRO                                     \
 if (0 != strcmp(str1, str2)) {                     \
@@ -183,17 +183,17 @@ TestWriteObject() {
   }
   NS_NAMED_LITERAL_CSTRING(spec, "http://www.mozilla.org");
   obj->SetSpec(spec);
   nsCOMPtr<nsIStartupCache> sc = do_GetService("@mozilla.org/startupcache/cache;1", &rv);
 
   sc->InvalidateCache();
   
   // Create an object stream. Usually this is done with
-  // NS_NewObjectOutputWrappedStorageStream, but that uses
+  // NewObjectOutputWrappedStorageStream, but that uses
   // StartupCache::GetSingleton in debug builds, and we
   // don't have access to that here. Obviously.
   char* id = "id";
   nsCOMPtr<nsIStorageStream> storageStream
     = do_CreateInstance("@mozilla.org/storagestream;1");
   NS_ENSURE_ARG_POINTER(storageStream);
   
   rv = storageStream->Init(256, (PRUint32) -1, nsnull);
@@ -218,17 +218,17 @@ TestWriteObject() {
   if (NS_FAILED(rv)) {
     fail("failed to write object");
     return rv;
   }
 
   char* bufPtr = NULL;
   nsAutoArrayPtr<char> buf;
   PRUint32 len;
-  NS_NewBufferFromStorageStream(storageStream, &bufPtr, &len);
+  NewBufferFromStorageStream(storageStream, &bufPtr, &len);
   buf = bufPtr;
 
   // Since this is a post-startup write, it should be written and
   // available.
   rv = sc->PutBuffer(id, buf, len);
   if (NS_FAILED(rv)) {
     fail("failed to insert input stream");
     return rv;
@@ -240,17 +240,17 @@ TestWriteObject() {
   nsCOMPtr<nsIObjectInputStream> objectInput;
   rv = sc->GetBuffer(id, &buf2Ptr, &len2);
   if (NS_FAILED(rv)) {
     fail("failed to retrieve buffer");
     return rv;
   }
   buf2 = buf2Ptr;
 
-  rv = NS_NewObjectInputStreamFromBuffer(buf2, len2, getter_AddRefs(objectInput));
+  rv = NewObjectInputStreamFromBuffer(buf2, len2, getter_AddRefs(objectInput));
   if (NS_FAILED(rv)) {
     fail("failed to created input stream");
     return rv;
   }  
   buf2.forget();
 
   nsCOMPtr<nsISupports> deserialized;
   rv = objectInput->ReadObject(PR_TRUE, getter_AddRefs(deserialized));