Bug 1153978 - Part 1: Separate buildIdOp from AsmJSCacheOps. r=jandem,bz

This commit is contained in:
Tooru Fujisawa 2016-01-01 14:19:20 +09:00
parent d2fd3db0e7
commit a66bde4a5f
13 changed files with 48 additions and 36 deletions

View File

@ -12,6 +12,7 @@
#include "jsfriendapi.h"
#include "mozilla/Assertions.h"
#include "mozilla/CondVar.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/dom/asmjscache/PAsmJSCacheEntryChild.h"
#include "mozilla/dom/asmjscache/PAsmJSCacheEntryParent.h"
#include "mozilla/dom/ContentChild.h"
@ -34,7 +35,6 @@
#include "nsIRunnable.h"
#include "nsISimpleEnumerator.h"
#include "nsIThread.h"
#include "nsIXULAppInfo.h"
#include "nsJSPrincipals.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
@ -1709,29 +1709,6 @@ CloseEntryForWrite(size_t aSize,
}
}
bool
GetBuildId(JS::BuildIdCharVector* aBuildID)
{
nsCOMPtr<nsIXULAppInfo> info = do_GetService("@mozilla.org/xre/app-info;1");
if (!info) {
return false;
}
nsCString buildID;
nsresult rv = info->GetPlatformBuildID(buildID);
NS_ENSURE_SUCCESS(rv, false);
if (!aBuildID->resize(buildID.Length())) {
return false;
}
for (size_t i = 0; i < buildID.Length(); i++) {
(*aBuildID)[i] = buildID[i];
}
return true;
}
class Client : public quota::Client
{
~Client() {}

View File

@ -132,9 +132,6 @@ CloseEntryForWrite(size_t aSize,
uint8_t* aMemory,
intptr_t aHandle);
bool
GetBuildId(JS::BuildIdCharVector* aBuildId);
// Called from QuotaManager.cpp:
quota::Client*

View File

@ -2601,8 +2601,7 @@ nsJSContext::EnsureStatics()
AsmJSCacheOpenEntryForRead,
asmjscache::CloseEntryForRead,
AsmJSCacheOpenEntryForWrite,
asmjscache::CloseEntryForWrite,
asmjscache::GetBuildId
asmjscache::CloseEntryForWrite
};
JS::SetAsmJSCacheOps(sRuntime, &asmJSCacheOps);

View File

@ -793,8 +793,7 @@ CreateJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
AsmJSCacheOpenEntryForRead,
asmjscache::CloseEntryForRead,
AsmJSCacheOpenEntryForWrite,
asmjscache::CloseEntryForWrite,
asmjscache::GetBuildId
asmjscache::CloseEntryForWrite
};
JS::SetAsmJSCacheOps(aRuntime, &asmJSCacheOps);

View File

@ -274,9 +274,9 @@ class MachineId
public:
bool extractCurrentState(ExclusiveContext* cx) {
if (!cx->asmJSCacheOps().buildId)
if (!cx->buildIdOp())
return false;
if (!cx->asmJSCacheOps().buildId(&buildId_))
if (!cx->buildIdOp()(&buildId_))
return false;
if (!GetCPUID(&cpuId_))
return false;

View File

@ -6192,6 +6192,12 @@ JS_DecodeInterpretedFunction(JSContext* cx, const void* data, uint32_t length)
return funobj;
}
JS_PUBLIC_API(void)
JS::SetBuildIdOp(JSRuntime* rt, JS::BuildIdOp buildIdOp)
{
rt->buildIdOp = buildIdOp;
}
JS_PUBLIC_API(void)
JS::SetAsmJSCacheOps(JSRuntime* rt, const JS::AsmJSCacheOps* ops)
{

View File

@ -5551,12 +5551,14 @@ struct AsmJSCacheOps
CloseAsmJSCacheEntryForReadOp closeEntryForRead;
OpenAsmJSCacheEntryForWriteOp openEntryForWrite;
CloseAsmJSCacheEntryForWriteOp closeEntryForWrite;
BuildIdOp buildId;
};
extern JS_PUBLIC_API(void)
SetAsmJSCacheOps(JSRuntime* rt, const AsmJSCacheOps* callbacks);
extern JS_PUBLIC_API(void)
SetBuildIdOp(JSRuntime* rt, BuildIdOp buildIdOp);
/**
* Convenience class for imitating a JS level for-of loop. Typical usage:
*

View File

@ -190,6 +190,7 @@ class ExclusiveContext : public ContextFriendFields,
bool isPermanentAtomsInitialized() { return !!runtime_->permanentAtoms; }
FrozenAtomSet& permanentAtoms() { return *runtime_->permanentAtoms; }
WellKnownSymbols& wellKnownSymbols() { return *runtime_->wellKnownSymbols; }
JS::BuildIdOp buildIdOp() { return runtime_->buildIdOp; }
const JS::AsmJSCacheOps& asmJSCacheOps() { return runtime_->asmJSCacheOps; }
PropertyName* emptyString() { return runtime_->emptyString; }
FreeOp* defaultFreeOp() { return runtime_->defaultFreeOp(); }

View File

@ -6371,8 +6371,7 @@ static const JS::AsmJSCacheOps asmJSCacheOps = {
ShellOpenAsmJSCacheEntryForRead,
ShellCloseAsmJSCacheEntryForRead,
ShellOpenAsmJSCacheEntryForWrite,
ShellCloseAsmJSCacheEntryForWrite,
ShellBuildId
ShellCloseAsmJSCacheEntryForWrite
};
static JSContext*
@ -7268,6 +7267,7 @@ main(int argc, char** argv, char** envp)
JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy);
JS_SetInterruptCallback(rt, ShellInterruptCallback);
JS::SetBuildIdOp(rt, ShellBuildId);
JS::SetAsmJSCacheOps(rt, &asmJSCacheOps);
JS_SetNativeStackQuota(rt, gMaxStackSize);

View File

@ -210,6 +210,7 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime)
destroyPrincipals(nullptr),
readPrincipals(nullptr),
errorReporter(nullptr),
buildIdOp(nullptr),
propertyRemovals(0),
#if !EXPOSE_INTL_API
thousandsSeparator(0),

View File

@ -1239,6 +1239,8 @@ struct JSRuntime : public JS::shadow::Runtime,
/* Optional error reporter. */
JSErrorReporter errorReporter;
JS::BuildIdOp buildIdOp;
/* AsmJSCache callbacks are runtime-wide. */
JS::AsmJSCacheOps asmJSCacheOps;

View File

@ -85,6 +85,7 @@
#endif
#include "nsIException.h"
#include "nsIPlatformInfo.h"
#include "nsThread.h"
#include "nsThreadUtils.h"
#include "xpcpublic.h"
@ -409,6 +410,29 @@ void JSObjectsTenuredCb(JSRuntime* aRuntime, void* aData)
static_cast<CycleCollectedJSRuntime*>(aData)->JSObjectsTenured();
}
bool
mozilla::GetBuildId(JS::BuildIdCharVector* aBuildID)
{
nsCOMPtr<nsIPlatformInfo> info = do_GetService("@mozilla.org/xre/app-info;1");
if (!info) {
return false;
}
nsCString buildID;
nsresult rv = info->GetPlatformBuildID(buildID);
NS_ENSURE_SUCCESS(rv, false);
if (!aBuildID->resize(buildID.Length())) {
return false;
}
for (size_t i = 0; i < buildID.Length(); i++) {
(*aBuildID)[i] = buildID[i];
}
return true;
}
CycleCollectedJSRuntime::CycleCollectedJSRuntime()
: mGCThingCycleCollectorGlobal(sGCThingCycleCollectorGlobal)
, mJSZoneCycleCollectorGlobal(sJSZoneCycleCollectorGlobal)
@ -503,6 +527,7 @@ CycleCollectedJSRuntime::Initialize(JSRuntime* aParentRuntime,
JS_SetContextCallback(mJSRuntime, ContextCallback, this);
JS_SetDestroyZoneCallback(mJSRuntime, XPCStringConvert::FreeZoneCache);
JS_SetSweepZoneCallback(mJSRuntime, XPCStringConvert::ClearZoneCache);
JS::SetBuildIdOp(mJSRuntime, GetBuildId);
// XPCJSRuntime currently overrides this because we don't
// TakeOwnershipOfErrorReporting everwhere on the main thread yet.
JS_SetErrorReporter(mJSRuntime, MozCrashErrorReporter);

View File

@ -417,6 +417,9 @@ inline bool AddToCCKind(JS::TraceKind aKind)
return aKind == JS::TraceKind::Object || aKind == JS::TraceKind::Script;
}
bool
GetBuildId(JS::BuildIdCharVector* aBuildID);
} // namespace mozilla
#endif // mozilla_CycleCollectedJSRuntime_h__