Bug 1359245 - Eliminate some XPCJSContext::Get() usage (r=mccr8)

XPCJSContext::Get() now does a TLS lookup, which is a little more expensive
than looking up a global variable. This patch removes as many of the TLS
lookups as possible.

MozReview-Commit-ID: GsqzJn55Lya
This commit is contained in:
Bill McCloskey 2017-04-24 14:40:24 -07:00
Родитель 3e774f9f8a
Коммит 133ed14a85
9 изменённых файлов: 30 добавлений и 28 удалений

Просмотреть файл

@ -1633,7 +1633,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
JS::MutableHandle<JS::PropertyDescriptor> desc)
{
if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
return LookupComponentsShim(cx, obj, aWin->AsInner(), desc);
}
@ -1641,7 +1641,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
// Note: We use |obj| rather than |aWin| to get the principal here, because
// this is called during Window setup when the Document isn't necessarily
// hooked up yet.
if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) &&
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) &&
!xpc::IsXrayWrapper(obj) &&
!nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)))
{

Просмотреть файл

@ -5058,11 +5058,11 @@ nsGlobalWindow::MayResolve(jsid aId)
return false;
}
if (aId == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
return true;
}
if (aId == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) {
if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) {
// We only resolve .controllers in release builds and on non-chrome windows,
// but let's not worry about any of that stuff.
return true;

Просмотреть файл

@ -487,7 +487,7 @@ sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
// Whenever JS_EnumerateStandardClasses is called, it defines the
// "undefined" property, even if it's already defined. We don't want to do
// anything in that case.
if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_UNDEFINED))
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_UNDEFINED))
return true;
// Avoid recursively triggering sandbox_addProperty in the

Просмотреть файл

@ -186,28 +186,28 @@ inline jsid
XPCCallContext::GetResolveName() const
{
CHECK_STATE(HAVE_CONTEXT);
return XPCJSContext::Get()->GetResolveName();
return GetContext()->GetResolveName();
}
inline jsid
XPCCallContext::SetResolveName(JS::HandleId name)
{
CHECK_STATE(HAVE_CONTEXT);
return XPCJSContext::Get()->SetResolveName(name);
return GetContext()->SetResolveName(name);
}
inline XPCWrappedNative*
XPCCallContext::GetResolvingWrapper() const
{
CHECK_STATE(HAVE_OBJECT);
return XPCJSContext::Get()->GetResolvingWrapper();
return GetContext()->GetResolvingWrapper();
}
inline XPCWrappedNative*
XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w)
{
CHECK_STATE(HAVE_OBJECT);
return XPCJSContext::Get()->SetResolvingWrapper(w);
return GetContext()->SetResolvingWrapper(w);
}
inline uint16_t
@ -522,8 +522,8 @@ xpc_ForcePropertyResolve(JSContext* cx, JS::HandleObject obj, jsid idArg)
inline jsid
GetJSIDByIndex(JSContext* cx, unsigned index)
{
XPCJSContext* xpcx = nsXPConnect::XPConnect()->GetContext();
return xpcx->GetStringID(index);
XPCJSRuntime* xpcrt = nsXPConnect::GetRuntimeInstance();
return xpcrt->GetStringID(index);
}
inline

Просмотреть файл

@ -844,7 +844,7 @@ XPCJSContext::BeforeProcessTask(bool aMightBlock)
// As we may be entering a nested event loop, we need to
// cancel any ongoing performance measurement.
js::ResetPerformanceMonitoring(Get()->Context());
js::ResetPerformanceMonitoring(Context());
CycleCollectedJSContext::BeforeProcessTask(aMightBlock);
}
@ -864,7 +864,7 @@ XPCJSContext::AfterProcessTask(uint32_t aNewRecursionDepth)
// Now that we are certain that the event is complete,
// we can flush any ongoing performance measurement.
js::FlushPerformanceMonitoring(Get()->Context());
js::FlushPerformanceMonitoring(Context());
mozilla::jsipc::AfterProcessTask();
}

Просмотреть файл

@ -781,7 +781,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
nsCOMPtr<nsIException> xpc_exception = aSyntheticException;
/* this one would be set by our error reporter */
XPCJSContext* xpccx = XPCJSContext::Get();
XPCJSContext* xpccx = ccx.GetContext();
// Get this right away in case we do something below to cause JS code
// to run.
@ -988,7 +988,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
AutoValueVector args(cx);
AutoScriptEvaluate scriptEval(cx);
XPCJSContext* xpccx = XPCJSContext::Get();
XPCJSContext* xpccx = ccx.GetContext();
AutoSavePendingResult apr(xpccx);
// XXX ASSUMES that retval is last arg. The xpidl compiler ensures this.
@ -1236,7 +1236,7 @@ pre_call_clean_up:
return CheckForException(ccx, aes, name, GetInterfaceName(),
syntheticException);
XPCJSContext::Get()->SetPendingException(nullptr); // XXX necessary?
xpccx->SetPendingException(nullptr); // XXX necessary?
// convert out args and result
// NOTE: this is the total number of native params, not just the args

Просмотреть файл

@ -1287,7 +1287,7 @@ CallMethodHelper::Call()
{
mCallContext.SetRetVal(JS::UndefinedValue());
XPCJSContext::Get()->SetPendingException(nullptr);
mCallContext.GetContext()->SetPendingException(nullptr);
if (mVTableIndex == 0) {
return QueryInterfaceFastPath();

Просмотреть файл

@ -398,7 +398,7 @@ nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info)
NS_IMETHODIMP
nsXPConnect::GarbageCollect(uint32_t reason)
{
GetContext()->GarbageCollect(reason);
mRuntime->GarbageCollect(reason);
return NS_OK;
}

Просмотреть файл

@ -75,6 +75,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/Maybe.h"
#include "mozilla/MemoryReporting.h"
@ -2494,24 +2495,25 @@ class MOZ_RAII AutoResolveName
{
public:
AutoResolveName(XPCCallContext& ccx, JS::HandleId name
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
mOld(ccx, XPCJSContext::Get()->SetResolveName(name))
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mContext(ccx.GetContext())
, mOld(ccx, mContext->SetResolveName(name))
#ifdef DEBUG
,mCheck(ccx, name)
, mCheck(ccx, name)
#endif
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
~AutoResolveName()
{
#ifdef DEBUG
jsid old =
#endif
XPCJSContext::Get()->SetResolveName(mOld);
MOZ_ASSERT(old == mCheck, "Bad Nesting!");
}
{
mozilla::DebugOnly<jsid> old =
mContext->SetResolveName(mOld);
MOZ_ASSERT(old == mCheck, "Bad Nesting!");
}
private:
XPCJSContext* mContext;
JS::RootedId mOld;
#ifdef DEBUG
JS::RootedId mCheck;