Backed out 3 changesets (bug 1752209, bug 1752212) for causing build bustages on nsXULPrototypeCache.cpp. CLOSED TREE

Backed out changeset 8f10b666008a (bug 1752209)
Backed out changeset 557c428fb6bc (bug 1752212)
Backed out changeset e38fbd381ed3 (bug 1752212)
This commit is contained in:
criss 2022-04-13 16:09:50 +03:00
parent 7bad40793b
commit 1d40b54278
9 changed files with 59 additions and 139 deletions

View File

@ -69,7 +69,6 @@
#include "mozilla/dom/MessageManagerCallback.h"
#include "mozilla/dom/ipc/SharedMap.h"
#include "mozilla/dom/ipc/StructuredCloneData.h"
#include "mozilla/scache/StartupCacheUtils.h"
#include "nsASCIIMask.h"
#include "nsBaseHashtable.h"
#include "nsCOMPtr.h"
@ -131,8 +130,6 @@ using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::ipc;
#define CACHE_PREFIX(type) "mm/" type
nsFrameMessageManager::nsFrameMessageManager(MessageManagerCallback* aCallback,
MessageManagerFlags aFlags)
: mChrome(aFlags & MessageManagerFlags::MM_CHROME),
@ -1275,14 +1272,10 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
RefPtr<JS::Stencil> stencil;
if (useScriptPreloader) {
nsAutoCString cachePath;
rv = scache::PathifyURI(CACHE_PREFIX("script"), uri, cachePath);
NS_ENSURE_SUCCESS(rv, nullptr);
JS::DecodeOptions decodeOptions;
ScriptPreloader::FillDecodeOptionsForCachedStencil(decodeOptions);
stencil = ScriptPreloader::GetChildSingleton().GetCachedStencil(
cx, decodeOptions, cachePath);
cx, decodeOptions, url);
}
if (!stencil) {
@ -1357,10 +1350,7 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
MOZ_ASSERT(stencil);
if (useScriptPreloader) {
nsAutoCString cachePath;
rv = scache::PathifyURI(CACHE_PREFIX("script"), uri, cachePath);
NS_ENSURE_SUCCESS(rv, nullptr);
ScriptPreloader::GetChildSingleton().NoteStencil(url, cachePath, stencil,
ScriptPreloader::GetChildSingleton().NoteStencil(url, url, stencil,
isRunOnce);
}

View File

@ -671,8 +671,7 @@ nsresult PrototypeDocumentContentSink::DoneWalking() {
if (IsChromeURI(mDocumentURI) &&
nsXULPrototypeCache::GetInstance()->IsEnabled()) {
bool isCachedOnDisk;
nsXULPrototypeCache::GetInstance()->HasPrototype(mDocumentURI,
&isCachedOnDisk);
nsXULPrototypeCache::GetInstance()->HasData(mDocumentURI, &isCachedOnDisk);
if (!isCachedOnDisk) {
nsXULPrototypeCache::GetInstance()->WritePrototype(mCurrentPrototype);
}

View File

@ -1670,7 +1670,7 @@ nsresult nsXULPrototypeScript::SerializeOutOfLine(
NS_ASSERTION(cache->IsEnabled(),
"writing to the cache file, but the XUL cache is off?");
bool exists;
cache->HasScript(mSrcURI, &exists);
cache->HasData(mSrcURI, &exists);
/* return will be NS_OK from GetAsciiSpec.
* that makes no sense.
@ -1680,14 +1680,14 @@ nsresult nsXULPrototypeScript::SerializeOutOfLine(
if (exists) return NS_OK;
nsCOMPtr<nsIObjectOutputStream> oos;
nsresult rv = cache->GetScriptOutputStream(mSrcURI, getter_AddRefs(oos));
nsresult rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos));
NS_ENSURE_SUCCESS(rv, rv);
nsresult tmp = Serialize(oos, aProtoDoc, nullptr);
if (NS_FAILED(tmp)) {
rv = tmp;
}
tmp = cache->FinishScriptOutputStream(mSrcURI);
tmp = cache->FinishOutputStream(mSrcURI);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -1754,7 +1754,7 @@ nsresult nsXULPrototypeScript::DeserializeOutOfLine(
if (!mStencil) {
if (mSrcURI) {
rv = cache->GetScriptInputStream(mSrcURI, getter_AddRefs(objectInput));
rv = cache->GetInputStream(mSrcURI, getter_AddRefs(objectInput));
}
// If !mSrcURI, we have an inline script. We shouldn't have
// to do anything else in that case, I think.
@ -1772,7 +1772,7 @@ nsresult nsXULPrototypeScript::DeserializeOutOfLine(
if (useXULCache && mSrcURI && mSrcURI->SchemeIs("chrome")) {
cache->PutStencil(mSrcURI, GetStencil());
}
cache->FinishScriptInputStream(mSrcURI);
cache->FinishInputStream(mSrcURI);
} else {
// If mSrcURI is not in the cache,
// rv will be NS_ERROR_NOT_AVAILABLE and we'll try to

View File

@ -37,7 +37,7 @@ using namespace mozilla::scache;
using mozilla::intl::LocaleService;
static const char kXULCacheInfoKey[] = "nsXULPrototypeCache.startupCache";
#define CACHE_PREFIX(aCompilationTarget) "xulcache/" aCompilationTarget
static const char kXULCachePrefix[] = "xulcache";
static void DisableXULCacheChangedCallback(const char* aPref, void* aClosure) {
if (nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance()) {
@ -110,7 +110,7 @@ nsXULPrototypeDocument* nsXULPrototypeCache::GetPrototype(nsIURI* aURI) {
// No prototype in XUL memory cache. Spin up the cache Service.
nsCOMPtr<nsIObjectInputStream> ois;
rv = GetPrototypeInputStream(aURI, getter_AddRefs(ois));
rv = GetInputStream(aURI, getter_AddRefs(ois));
if (NS_FAILED(rv)) {
return nullptr;
}
@ -197,29 +197,19 @@ nsresult nsXULPrototypeCache::WritePrototype(
nsCOMPtr<nsIURI> protoURI = aPrototypeDocument->GetURI();
nsCOMPtr<nsIObjectOutputStream> oos;
rv = GetPrototypeOutputStream(protoURI, getter_AddRefs(oos));
rv = GetOutputStream(protoURI, getter_AddRefs(oos));
NS_ENSURE_SUCCESS(rv, rv);
rv = aPrototypeDocument->Write(oos);
NS_ENSURE_SUCCESS(rv, rv);
FinishPrototypeOutputStream(protoURI);
FinishOutputStream(protoURI);
return NS_FAILED(rv) ? rv : rv2;
}
static nsresult PathifyURIForType(nsXULPrototypeCache::CacheType cacheType,
nsIURI* in, nsACString& out) {
switch (cacheType) {
case nsXULPrototypeCache::CacheType::Prototype:
return PathifyURI(CACHE_PREFIX("proto"), in, out);
case nsXULPrototypeCache::CacheType::Script:
return PathifyURI(CACHE_PREFIX("script"), in, out);
}
}
nsresult nsXULPrototypeCache::GetInputStream(CacheType cacheType, nsIURI* uri,
nsresult nsXULPrototypeCache::GetInputStream(nsIURI* uri,
nsIObjectInputStream** stream) {
nsAutoCString spec;
nsresult rv = PathifyURIForType(cacheType, uri, spec);
nsAutoCString spec(kXULCachePrefix);
nsresult rv = PathifyURI(uri, spec);
if (NS_FAILED(rv)) return NS_ERROR_NOT_AVAILABLE;
const char* buf;
@ -271,8 +261,7 @@ nsresult nsXULPrototypeCache::GetOutputStream(nsIURI* uri,
return NS_OK;
}
nsresult nsXULPrototypeCache::FinishOutputStream(CacheType cacheType,
nsIURI* uri) {
nsresult nsXULPrototypeCache::FinishOutputStream(nsIURI* uri) {
nsresult rv;
StartupCache* sc = StartupCache::GetSingleton();
if (!sc) return NS_ERROR_NOT_AVAILABLE;
@ -289,8 +278,8 @@ nsresult nsXULPrototypeCache::FinishOutputStream(CacheType cacheType,
NS_ENSURE_SUCCESS(rv, rv);
if (!mStartupCacheURITable.GetEntry(uri)) {
nsAutoCString spec;
rv = PathifyURIForType(cacheType, uri, spec);
nsAutoCString spec(kXULCachePrefix);
rv = PathifyURI(uri, spec);
if (NS_FAILED(rv)) return NS_ERROR_NOT_AVAILABLE;
rv = sc->PutBuffer(spec.get(), std::move(buf), len);
if (NS_SUCCEEDED(rv)) {
@ -304,14 +293,13 @@ nsresult nsXULPrototypeCache::FinishOutputStream(CacheType cacheType,
// We have data if we're in the middle of writing it or we already
// have it in the cache.
nsresult nsXULPrototypeCache::HasData(CacheType cacheType, nsIURI* uri,
bool* exists) {
nsresult nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists) {
if (mOutputStreamTable.Get(uri, nullptr)) {
*exists = true;
return NS_OK;
}
nsAutoCString spec;
nsresult rv = PathifyURIForType(cacheType, uri, spec);
nsAutoCString spec(kXULCachePrefix);
nsresult rv = PathifyURI(uri, spec);
if (NS_FAILED(rv)) {
*exists = false;
return NS_OK;

View File

@ -34,8 +34,6 @@ class StyleSheet;
*/
class nsXULPrototypeCache : public nsIObserver {
public:
enum class CacheType { Prototype, Script };
// nsISupports
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
@ -73,52 +71,12 @@ class nsXULPrototypeCache : public nsIObserver {
* This interface allows partial reads and writes from the buffers in the
* startupCache.
*/
inline nsresult GetPrototypeInputStream(nsIURI* aURI,
nsIObjectInputStream** objectInput) {
return GetInputStream(CacheType::Prototype, aURI, objectInput);
}
inline nsresult GetScriptInputStream(nsIURI* aURI,
nsIObjectInputStream** objectInput) {
return GetInputStream(CacheType::Script, aURI, objectInput);
}
inline nsresult FinishScriptInputStream(nsIURI* aURI) {
return FinishInputStream(aURI);
}
inline nsresult GetPrototypeOutputStream(
nsIURI* aURI, nsIObjectOutputStream** objectOutput) {
return GetOutputStream(aURI, objectOutput);
}
inline nsresult GetScriptOutputStream(nsIURI* aURI,
nsIObjectOutputStream** objectOutput) {
return GetOutputStream(aURI, objectOutput);
}
inline nsresult FinishPrototypeOutputStream(nsIURI* aURI) {
return FinishOutputStream(CacheType::Prototype, aURI);
}
inline nsresult FinishScriptOutputStream(nsIURI* aURI) {
return FinishOutputStream(CacheType::Script, aURI);
}
inline nsresult HasPrototype(nsIURI* aURI, bool* exists) {
return HasData(CacheType::Prototype, aURI, exists);
}
inline nsresult HasScript(nsIURI* aURI, bool* exists) {
return HasData(CacheType::Script, aURI, exists);
}
private:
nsresult GetInputStream(CacheType cacheType, nsIURI* uri,
nsIObjectInputStream** stream);
nsresult GetInputStream(nsIURI* aURI, nsIObjectInputStream** objectInput);
nsresult FinishInputStream(nsIURI* aURI);
nsresult GetOutputStream(nsIURI* aURI, nsIObjectOutputStream** objectOutput);
nsresult FinishOutputStream(CacheType cacheType, nsIURI* aURI);
nsresult HasData(CacheType cacheType, nsIURI* aURI, bool* exists);
nsresult FinishOutputStream(nsIURI* aURI);
nsresult HasData(nsIURI* aURI, bool* exists);
public:
static nsXULPrototypeCache* GetInstance();
static nsXULPrototypeCache* MaybeGetInstance() { return sInstance; }

View File

@ -75,8 +75,7 @@ using namespace mozilla::loader;
using namespace xpc;
using namespace JS;
#define JS_CACHE_PREFIX(aScopeType, aCompilationTarget) \
"jsloader/" aScopeType "/" aCompilationTarget
#define JS_CACHE_PREFIX(aType) "jsloader/" aType
/**
* Buffer sizes for serialization and deserialization of scripts.
@ -748,9 +747,8 @@ nsresult mozJSComponentLoader::ObjectForLocation(
aInfo.EnsureResolvedURI();
nsAutoCString cachePath;
rv = PathifyURI(JS_CACHE_PREFIX("non-syntactic", "script"),
aInfo.ResolvedURI(), cachePath);
nsAutoCString cachePath(JS_CACHE_PREFIX("non-syntactic"));
rv = PathifyURI(aInfo.ResolvedURI(), cachePath);
NS_ENSURE_SUCCESS(rv, rv);
JS::DecodeOptions decodeOptions;

View File

@ -81,8 +81,7 @@ mozJSSubScriptLoader::~mozJSSubScriptLoader() = default;
NS_IMPL_ISUPPORTS(mozJSSubScriptLoader, mozIJSSubScriptLoader)
#define JSSUB_CACHE_PREFIX(aScopeType, aCompilationTarget) \
"jssubloader/" aScopeType "/" aCompilationTarget
#define JSSUB_CACHE_PREFIX(aType) "jssubloader/" aType
static void SubscriptCachePath(JSContext* cx, nsIURI* uri,
JS::HandleObject targetObj,
@ -90,10 +89,11 @@ static void SubscriptCachePath(JSContext* cx, nsIURI* uri,
// StartupCache must distinguish between non-syntactic vs global when
// computing the cache key.
if (!JS_IsGlobalObject(targetObj)) {
PathifyURI(JSSUB_CACHE_PREFIX("non-syntactic", "script"), uri, cachePath);
cachePath.AssignLiteral(JSSUB_CACHE_PREFIX("non-syntactic"));
} else {
PathifyURI(JSSUB_CACHE_PREFIX("global", "script"), uri, cachePath);
cachePath.AssignLiteral(JSSUB_CACHE_PREFIX("global"));
}
PathifyURI(uri, cachePath);
}
static void ReportError(JSContext* cx, const nsACString& msg) {

View File

@ -166,7 +166,32 @@ nsresult ResolveURI(nsIURI* in, nsIURI** out) {
return NS_OK;
}
static nsresult PathifyURIImpl(nsIURI* in, nsACString& out) {
/**
* PathifyURI transforms uris into useful zip paths
* to make it easier to manipulate startup cache entries
* using standard zip tools.
* Transformations applied:
* * resource:// URIs are resolved to their corresponding file/jar URI to
* canonicalize resources URIs other than gre and app.
* * Paths under GRE or APP directory have their base path replaced with
* resource/gre or resource/app to avoid depending on install location.
* * jar:file:///path/to/file.jar!/sub/path urls are replaced with
* /path/to/file.jar/sub/path
*
* The result is appended to the string passed in. Adding a prefix before
* calling is recommended to avoid colliding with other cache users.
*
* For example, in the js loader (string is prefixed with jsloader by caller):
* resource://gre/modules/XPCOMUtils.jsm or
* file://$GRE_DIR/modules/XPCOMUtils.jsm or
* 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
*/
nsresult PathifyURI(nsIURI* in, nsACString& out) {
nsCOMPtr<nsIURI> uri;
nsresult rv = ResolveURI(in, getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
@ -194,7 +219,7 @@ static nsresult PathifyURIImpl(nsIURI* in, nsACString& out) {
rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = PathifyURIImpl(jarFileURI, out);
rv = PathifyURI(jarFileURI, out);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString path;
@ -213,12 +238,5 @@ static nsresult PathifyURIImpl(nsIURI* in, nsACString& out) {
return NS_OK;
}
nsresult PathifyURI(const char* loaderType, size_t loaderTypeLength, nsIURI* in,
nsACString& out) {
out.AssignASCII(loaderType, loaderTypeLength);
return PathifyURIImpl(in, out);
}
} // namespace scache
} // namespace mozilla

View File

@ -37,38 +37,7 @@ nsresult NewBufferFromStorageStream(nsIStorageStream* storageStream,
nsresult ResolveURI(nsIURI* in, nsIURI** out);
// PathifyURI transforms uris into useful zip paths
// to make it easier to manipulate startup cache entries
// using standard zip tools.
//
// Transformations applied:
// * resource:// URIs are resolved to their corresponding file/jar URI to
// canonicalize resources URIs other than gre and app.
// * Paths under GRE or APP directory have their base path replaced with
// resource/gre or resource/app to avoid depending on install location.
// * jar:file:///path/to/file.jar!/sub/path urls are replaced with
// /path/to/file.jar/sub/path
//
// The result is concatenated with loaderType and stored into the string
// passed in.
//
// For example, in the js loader (loaderType = "jsloader"):
// resource://gre/modules/XPCOMUtils.jsm or
// file://$GRE_DIR/modules/XPCOMUtils.jsm or
// 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
nsresult PathifyURI(const char* loaderType, size_t loaderTypeLength, nsIURI* in,
nsACString& out);
template <int N>
nsresult PathifyURI(const char (&loaderType)[N], nsIURI* in, nsACString& out) {
return PathifyURI(loaderType, N - 1, in, out);
}
nsresult PathifyURI(nsIURI* in, nsACString& out);
} // namespace scache
} // namespace mozilla