зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1292892 part 1 - Stop using JSRuntime outside SpiderMonkey. r=bz,terrence,fitzgen,kanru
This commit is contained in:
Родитель
9e5cf920d2
Коммит
0ad12515f4
|
@ -76,7 +76,7 @@ using namespace mozilla::dom;
|
||||||
|
|
||||||
nsIIOService *nsScriptSecurityManager::sIOService = nullptr;
|
nsIIOService *nsScriptSecurityManager::sIOService = nullptr;
|
||||||
nsIStringBundle *nsScriptSecurityManager::sStrBundle = nullptr;
|
nsIStringBundle *nsScriptSecurityManager::sStrBundle = nullptr;
|
||||||
JSRuntime *nsScriptSecurityManager::sRuntime = 0;
|
JSContext *nsScriptSecurityManager::sContext = nullptr;
|
||||||
bool nsScriptSecurityManager::sStrictFileOriginPolicy = true;
|
bool nsScriptSecurityManager::sStrictFileOriginPolicy = true;
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
|
@ -1413,19 +1413,18 @@ nsresult nsScriptSecurityManager::Init()
|
||||||
|
|
||||||
//-- Register security check callback in the JS engine
|
//-- Register security check callback in the JS engine
|
||||||
// Currently this is used to control access to function.caller
|
// Currently this is used to control access to function.caller
|
||||||
sRuntime = xpc::GetJSRuntime();
|
sContext = danger::GetJSContext();
|
||||||
|
|
||||||
static const JSSecurityCallbacks securityCallbacks = {
|
static const JSSecurityCallbacks securityCallbacks = {
|
||||||
ContentSecurityPolicyPermitsJSAction,
|
ContentSecurityPolicyPermitsJSAction,
|
||||||
JSPrincipalsSubsume,
|
JSPrincipalsSubsume,
|
||||||
};
|
};
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(sRuntime);
|
MOZ_ASSERT(!JS_GetSecurityCallbacks(sContext));
|
||||||
MOZ_ASSERT(!JS_GetSecurityCallbacks(cx));
|
JS_SetSecurityCallbacks(sContext, &securityCallbacks);
|
||||||
JS_SetSecurityCallbacks(cx, &securityCallbacks);
|
JS_InitDestroyPrincipalsCallback(sContext, nsJSPrincipals::Destroy);
|
||||||
JS_InitDestroyPrincipalsCallback(cx, nsJSPrincipals::Destroy);
|
|
||||||
|
|
||||||
JS_SetTrustedPrincipals(cx, system);
|
JS_SetTrustedPrincipals(sContext, system);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -1448,10 +1447,10 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void)
|
||||||
void
|
void
|
||||||
nsScriptSecurityManager::Shutdown()
|
nsScriptSecurityManager::Shutdown()
|
||||||
{
|
{
|
||||||
if (sRuntime) {
|
if (sContext) {
|
||||||
JS_SetSecurityCallbacks(JS_GetContext(sRuntime), nullptr);
|
JS_SetSecurityCallbacks(sContext, nullptr);
|
||||||
JS_SetTrustedPrincipals(JS_GetContext(sRuntime), nullptr);
|
JS_SetTrustedPrincipals(sContext, nullptr);
|
||||||
sRuntime = nullptr;
|
sContext = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IF_RELEASE(sIOService);
|
NS_IF_RELEASE(sIOService);
|
||||||
|
|
|
@ -148,7 +148,7 @@ private:
|
||||||
|
|
||||||
static nsIIOService *sIOService;
|
static nsIIOService *sIOService;
|
||||||
static nsIStringBundle *sStrBundle;
|
static nsIStringBundle *sStrBundle;
|
||||||
static JSRuntime *sRuntime;
|
static JSContext *sContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
|
@ -29,7 +29,6 @@ using namespace testing;
|
||||||
// GTest fixture class that all of our tests derive from.
|
// GTest fixture class that all of our tests derive from.
|
||||||
struct DevTools : public ::testing::Test {
|
struct DevTools : public ::testing::Test {
|
||||||
bool _initialized;
|
bool _initialized;
|
||||||
JSRuntime* rt;
|
|
||||||
JSContext* cx;
|
JSContext* cx;
|
||||||
JSCompartment* compartment;
|
JSCompartment* compartment;
|
||||||
JS::Zone* zone;
|
JS::Zone* zone;
|
||||||
|
@ -37,23 +36,19 @@ struct DevTools : public ::testing::Test {
|
||||||
|
|
||||||
DevTools()
|
DevTools()
|
||||||
: _initialized(false),
|
: _initialized(false),
|
||||||
rt(nullptr),
|
|
||||||
cx(nullptr)
|
cx(nullptr)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
MOZ_ASSERT(!_initialized);
|
MOZ_ASSERT(!_initialized);
|
||||||
|
|
||||||
rt = getRuntime();
|
cx = getContext();
|
||||||
if (!rt)
|
if (!cx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MOZ_RELEASE_ASSERT(!cx);
|
|
||||||
cx = JS_GetContext(rt);
|
|
||||||
|
|
||||||
JS_BeginRequest(cx);
|
JS_BeginRequest(cx);
|
||||||
|
|
||||||
global.init(rt, createGlobal());
|
global.init(cx, createGlobal());
|
||||||
if (!global)
|
if (!global)
|
||||||
return;
|
return;
|
||||||
JS_EnterCompartment(cx, global);
|
JS_EnterCompartment(cx, global);
|
||||||
|
@ -64,8 +59,8 @@ struct DevTools : public ::testing::Test {
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSRuntime* getRuntime() {
|
JSContext* getContext() {
|
||||||
return CycleCollectedJSRuntime::Get()->Runtime();
|
return CycleCollectedJSRuntime::Get()->Context();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reportError(JSContext* cx, const char* message, JSErrorReport* report) {
|
static void reportError(JSContext* cx, const char* message, JSErrorReport* report) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ using mozilla::dom::DOMRequestService;
|
||||||
using mozilla::dom::DOMCursor;
|
using mozilla::dom::DOMCursor;
|
||||||
using mozilla::dom::Promise;
|
using mozilla::dom::Promise;
|
||||||
using mozilla::dom::AutoJSAPI;
|
using mozilla::dom::AutoJSAPI;
|
||||||
using mozilla::dom::GetJSRuntime;
|
using mozilla::dom::RootingCx;
|
||||||
|
|
||||||
DOMRequest::DOMRequest(nsPIDOMWindowInner* aWindow)
|
DOMRequest::DOMRequest(nsPIDOMWindowInner* aWindow)
|
||||||
: DOMEventTargetHelper(aWindow)
|
: DOMEventTargetHelper(aWindow)
|
||||||
|
@ -302,7 +302,7 @@ class FireSuccessAsyncTask : public mozilla::Runnable
|
||||||
FireSuccessAsyncTask(DOMRequest* aRequest,
|
FireSuccessAsyncTask(DOMRequest* aRequest,
|
||||||
const JS::Value& aResult) :
|
const JS::Value& aResult) :
|
||||||
mReq(aRequest),
|
mReq(aRequest),
|
||||||
mResult(GetJSRuntime(), aResult)
|
mResult(RootingCx(), aResult)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,10 +293,10 @@ GetJSContext()
|
||||||
}
|
}
|
||||||
} // namespace danger
|
} // namespace danger
|
||||||
|
|
||||||
JSRuntime*
|
js::RootingContext*
|
||||||
GetJSRuntime()
|
RootingCx()
|
||||||
{
|
{
|
||||||
return CycleCollectedJSRuntime::Get()->Runtime();
|
return CycleCollectedJSRuntime::Get()->RootingCx();
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoJSAPI::AutoJSAPI()
|
AutoJSAPI::AutoJSAPI()
|
||||||
|
@ -590,7 +590,7 @@ AutoJSAPI::ReportException()
|
||||||
nsContentUtils::IsCallerChrome(),
|
nsContentUtils::IsCallerChrome(),
|
||||||
inner ? inner->WindowID() : 0);
|
inner ? inner->WindowID() : 0);
|
||||||
if (inner && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) {
|
if (inner && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) {
|
||||||
DispatchScriptErrorEvent(inner, JS_GetRuntime(cx()), xpcReport, exn);
|
DispatchScriptErrorEvent(inner, cx(), xpcReport, exn);
|
||||||
} else {
|
} else {
|
||||||
JS::Rooted<JSObject*> stack(cx(),
|
JS::Rooted<JSObject*> stack(cx(),
|
||||||
xpc::FindExceptionStackForConsoleReport(inner, exn));
|
xpc::FindExceptionStackForConsoleReport(inner, exn));
|
||||||
|
|
|
@ -136,7 +136,7 @@ JSContext* GetJSContext();
|
||||||
|
|
||||||
} // namespace danger
|
} // namespace danger
|
||||||
|
|
||||||
JSRuntime* GetJSRuntime();
|
js::RootingContext* RootingCx();
|
||||||
|
|
||||||
class ScriptSettingsStack;
|
class ScriptSettingsStack;
|
||||||
class ScriptSettingsStackEntry {
|
class ScriptSettingsStackEntry {
|
||||||
|
|
|
@ -2790,7 +2790,10 @@ nsIPrincipal*
|
||||||
nsContentUtils::ObjectPrincipal(JSObject* aObj)
|
nsContentUtils::ObjectPrincipal(JSObject* aObj)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
MOZ_ASSERT(JS_GetObjectRuntime(aObj) == CycleCollectedJSRuntime::Get()->Runtime());
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
JS::AssertObjectBelongsToCurrentThread(aObj);
|
||||||
|
#endif
|
||||||
|
|
||||||
// This is duplicated from nsScriptSecurityManager. We don't call through there
|
// This is duplicated from nsScriptSecurityManager. We don't call through there
|
||||||
// because the API unnecessarily requires a JSContext for historical reasons.
|
// because the API unnecessarily requires a JSContext for historical reasons.
|
||||||
|
|
|
@ -1711,8 +1711,8 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSRuntime* rt = CycleCollectedJSRuntime::Get()->Runtime();
|
js::RootingContext* rcx = RootingCx();
|
||||||
JS::Rooted<JSScript*> script(rt);
|
JS::Rooted<JSScript*> script(rcx);
|
||||||
|
|
||||||
nsMessageManagerScriptHolder* holder = sCachedScripts->Get(aURL);
|
nsMessageManagerScriptHolder* holder = sCachedScripts->Get(aURL);
|
||||||
if (holder && holder->WillRunInGlobalScope() == aRunInGlobalScope) {
|
if (holder && holder->WillRunInGlobalScope() == aRunInGlobalScope) {
|
||||||
|
@ -1725,7 +1725,7 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
|
||||||
shouldCache, &script);
|
shouldCache, &script);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Rooted<JSObject*> global(rt, mGlobal->GetJSObject());
|
JS::Rooted<JSObject*> global(rcx, mGlobal->GetJSObject());
|
||||||
if (global) {
|
if (global) {
|
||||||
AutoEntryScript aes(global, "message manager script load");
|
AutoEntryScript aes(global, "message manager script load");
|
||||||
JSContext* cx = aes.cx();
|
JSContext* cx = aes.cx();
|
||||||
|
|
|
@ -12209,7 +12209,7 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
|
||||||
// Hold strong ref to ourselves while we call the callback.
|
// Hold strong ref to ourselves while we call the callback.
|
||||||
nsCOMPtr<nsISupports> me(static_cast<nsIDOMWindow *>(this));
|
nsCOMPtr<nsISupports> me(static_cast<nsIDOMWindow *>(this));
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
JS::Rooted<JS::Value> ignoredVal(CycleCollectedJSRuntime::Get()->Runtime());
|
JS::Rooted<JS::Value> ignoredVal(RootingCx());
|
||||||
callback->Call(me, handler->GetArgs(), &ignoredVal, rv, reason);
|
callback->Call(me, handler->GetArgs(), &ignoredVal, rv, reason);
|
||||||
if (rv.IsUncatchableException()) {
|
if (rv.IsUncatchableException()) {
|
||||||
abortIntervalHandler = true;
|
abortIntervalHandler = true;
|
||||||
|
|
|
@ -1531,8 +1531,7 @@ static nsresult
|
||||||
CheckForOutdatedParent(nsINode* aParent, nsINode* aNode)
|
CheckForOutdatedParent(nsINode* aParent, nsINode* aNode)
|
||||||
{
|
{
|
||||||
if (JSObject* existingObjUnrooted = aNode->GetWrapper()) {
|
if (JSObject* existingObjUnrooted = aNode->GetWrapper()) {
|
||||||
JSRuntime* runtime = JS_GetObjectRuntime(existingObjUnrooted);
|
JS::Rooted<JSObject*> existingObj(RootingCx(), existingObjUnrooted);
|
||||||
JS::Rooted<JSObject*> existingObj(runtime, existingObjUnrooted);
|
|
||||||
|
|
||||||
AutoJSContext cx;
|
AutoJSContext cx;
|
||||||
nsIGlobalObject* global = aParent->OwnerDoc()->GetScopeObject();
|
nsIGlobalObject* global = aParent->OwnerDoc()->GetScopeObject();
|
||||||
|
|
|
@ -188,7 +188,6 @@ static nsScriptNameSpaceManager *gNameSpaceManager;
|
||||||
|
|
||||||
static PRTime sFirstCollectionTime;
|
static PRTime sFirstCollectionTime;
|
||||||
|
|
||||||
static JSRuntime* sRuntime;
|
|
||||||
static JSContext* sContext;
|
static JSContext* sContext;
|
||||||
|
|
||||||
static bool sIsInitialized;
|
static bool sIsInitialized;
|
||||||
|
@ -246,8 +245,8 @@ FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSRuntime* rt = GetJSRuntime();
|
js::RootingContext* rcx = RootingCx();
|
||||||
JS::RootedObject exceptionObject(rt, &exceptionValue.toObject());
|
JS::RootedObject exceptionObject(rcx, &exceptionValue.toObject());
|
||||||
JSObject* stackObject = ExceptionStackOrNull(exceptionObject);
|
JSObject* stackObject = ExceptionStackOrNull(exceptionObject);
|
||||||
if (stackObject) {
|
if (stackObject) {
|
||||||
return stackObject;
|
return stackObject;
|
||||||
|
@ -268,7 +267,7 @@ FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
|
||||||
if (!stack) {
|
if (!stack) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
JS::RootedValue value(rt);
|
JS::RootedValue value(rcx);
|
||||||
stack->GetNativeSavedFrame(&value);
|
stack->GetNativeSavedFrame(&value);
|
||||||
if (value.isObject()) {
|
if (value.isObject()) {
|
||||||
return &value.toObject();
|
return &value.toObject();
|
||||||
|
@ -422,12 +421,12 @@ class ScriptErrorEvent : public Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScriptErrorEvent(nsPIDOMWindowInner* aWindow,
|
ScriptErrorEvent(nsPIDOMWindowInner* aWindow,
|
||||||
JSRuntime* aRuntime,
|
JSContext* aContext,
|
||||||
xpc::ErrorReport* aReport,
|
xpc::ErrorReport* aReport,
|
||||||
JS::Handle<JS::Value> aError)
|
JS::Handle<JS::Value> aError)
|
||||||
: mWindow(aWindow)
|
: mWindow(aWindow)
|
||||||
, mReport(aReport)
|
, mReport(aReport)
|
||||||
, mError(aRuntime, aError)
|
, mError(aContext, aError)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
NS_IMETHOD Run() override
|
NS_IMETHOD Run() override
|
||||||
|
@ -496,10 +495,10 @@ bool ScriptErrorEvent::sHandlingScriptError = false;
|
||||||
namespace xpc {
|
namespace xpc {
|
||||||
|
|
||||||
void
|
void
|
||||||
DispatchScriptErrorEvent(nsPIDOMWindowInner *win, JSRuntime *rt, xpc::ErrorReport *xpcReport,
|
DispatchScriptErrorEvent(nsPIDOMWindowInner *win, JSContext *cx, xpc::ErrorReport *xpcReport,
|
||||||
JS::Handle<JS::Value> exception)
|
JS::Handle<JS::Value> exception)
|
||||||
{
|
{
|
||||||
nsContentUtils::AddScriptRunner(new ScriptErrorEvent(win, rt, xpcReport, exception));
|
nsContentUtils::AddScriptRunner(new ScriptErrorEvent(win, cx, xpcReport, exception));
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace xpc */
|
} /* namespace xpc */
|
||||||
|
@ -1196,7 +1195,7 @@ nsJSContext::GarbageCollectNow(JS::gcreason::Reason aReason,
|
||||||
sPendingLoadCount = 0;
|
sPendingLoadCount = 0;
|
||||||
sLoadingInProgress = false;
|
sLoadingInProgress = false;
|
||||||
|
|
||||||
if (!nsContentUtils::XPConnect() || !sRuntime) {
|
if (!nsContentUtils::XPConnect() || !sContext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2234,7 +2233,6 @@ mozilla::dom::StartupJSEnvironment()
|
||||||
sNeedsFullGC = false;
|
sNeedsFullGC = false;
|
||||||
sNeedsGCAfterCC = false;
|
sNeedsGCAfterCC = false;
|
||||||
gNameSpaceManager = nullptr;
|
gNameSpaceManager = nullptr;
|
||||||
sRuntime = nullptr;
|
|
||||||
sContext = nullptr;
|
sContext = nullptr;
|
||||||
sIsInitialized = false;
|
sIsInitialized = false;
|
||||||
sDidShutdown = false;
|
sDidShutdown = false;
|
||||||
|
@ -2378,13 +2376,11 @@ nsJSContext::EnsureStatics()
|
||||||
MOZ_CRASH();
|
MOZ_CRASH();
|
||||||
}
|
}
|
||||||
|
|
||||||
sRuntime = xpc::GetJSRuntime();
|
sContext = danger::GetJSContext();
|
||||||
if (!sRuntime) {
|
if (!sContext) {
|
||||||
MOZ_CRASH();
|
MOZ_CRASH();
|
||||||
}
|
}
|
||||||
|
|
||||||
sContext = JS_GetContext(sRuntime);
|
|
||||||
|
|
||||||
// Let's make sure that our main thread is the same as the xpcom main thread.
|
// Let's make sure that our main thread is the same as the xpcom main thread.
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ nsScriptLoadRequest::MaybeCancelOffThreadScript()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(xpc::GetJSRuntime());
|
JSContext* cx = danger::GetJSContext();
|
||||||
JS::CancelOffThreadScript(cx, mOffThreadToken);
|
JS::CancelOffThreadScript(cx, mOffThreadToken);
|
||||||
mOffThreadToken = nullptr;
|
mOffThreadToken = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2448,7 +2448,7 @@ ConstructJSImplementation(const char* aContractId,
|
||||||
do_QueryInterface(implISupports);
|
do_QueryInterface(implISupports);
|
||||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
|
||||||
if (gpi) {
|
if (gpi) {
|
||||||
JS::Rooted<JS::Value> initReturn(GetJSRuntime());
|
JS::Rooted<JS::Value> initReturn(RootingCx());
|
||||||
rv = gpi->Init(window, &initReturn);
|
rv = gpi->Init(window, &initReturn);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
aRv.Throw(rv);
|
aRv.Throw(rv);
|
||||||
|
|
|
@ -489,8 +489,8 @@ struct VerifyTraceProtoAndIfaceCacheCalledTracer : public JS::CallbackTracer
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
explicit VerifyTraceProtoAndIfaceCacheCalledTracer(JSRuntime *rt)
|
explicit VerifyTraceProtoAndIfaceCacheCalledTracer(JSContext* cx)
|
||||||
: JS::CallbackTracer(rt), ok(false)
|
: JS::CallbackTracer(cx), ok(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void onChild(const JS::GCCellPtr&) override {
|
void onChild(const JS::GCCellPtr&) override {
|
||||||
|
@ -3243,8 +3243,7 @@ WrappedJSToDictionary(nsISupports* aObject, T& aDictionary)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(aObject);
|
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(aObject);
|
||||||
NS_ENSURE_TRUE(wrappedObj, false);
|
NS_ENSURE_TRUE(wrappedObj, false);
|
||||||
JS::Rooted<JSObject*> obj(CycleCollectedJSRuntime::Get()->Runtime(),
|
JS::Rooted<JSObject*> obj(RootingCx(), wrappedObj->GetJSObject());
|
||||||
wrappedObj->GetJSObject());
|
|
||||||
NS_ENSURE_TRUE(obj, false);
|
NS_ENSURE_TRUE(obj, false);
|
||||||
|
|
||||||
nsIGlobalObject* global = xpc::NativeGlobal(obj);
|
nsIGlobalObject* global = xpc::NativeGlobal(obj);
|
||||||
|
|
|
@ -3977,7 +3977,7 @@ DeviceStorageRequestManager::Resolve(uint32_t aId, uint64_t aValue,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::RootedValue value(GetJSRuntime(), JS_NumberValue((double)aValue));
|
JS::RootedValue value(RootingCx(), JS_NumberValue((double)aValue));
|
||||||
return ResolveInternal(i, value);
|
return ResolveInternal(i, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ JSEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
||||||
columnNumber.Construct();
|
columnNumber.Construct();
|
||||||
columnNumber.Value() = scriptEvent->Colno();
|
columnNumber.Value() = scriptEvent->Colno();
|
||||||
|
|
||||||
error.Construct(GetJSRuntime());
|
error.Construct(RootingCx());
|
||||||
scriptEvent->GetError(&error.Value());
|
scriptEvent->GetError(&error.Value());
|
||||||
} else {
|
} else {
|
||||||
msgOrEvent.SetAsEvent() = aEvent->InternalDOMEvent();
|
msgOrEvent.SetAsEvent() = aEvent->InternalDOMEvent();
|
||||||
|
@ -210,7 +210,7 @@ JSEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
||||||
MOZ_ASSERT(mTypedHandler.Type() == TypedEventHandler::eNormal);
|
MOZ_ASSERT(mTypedHandler.Type() == TypedEventHandler::eNormal);
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
RefPtr<EventHandlerNonNull> handler = mTypedHandler.NormalEventHandler();
|
RefPtr<EventHandlerNonNull> handler = mTypedHandler.NormalEventHandler();
|
||||||
JS::Rooted<JS::Value> retval(CycleCollectedJSRuntime::Get()->Runtime());
|
JS::Rooted<JS::Value> retval(RootingCx());
|
||||||
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), &retval, rv);
|
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), &retval, rv);
|
||||||
if (rv.Failed()) {
|
if (rv.Failed()) {
|
||||||
return rv.StealNSResult();
|
return rv.StealNSResult();
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace dom {
|
||||||
PJavaScriptChild*
|
PJavaScriptChild*
|
||||||
nsIContentChild::AllocPJavaScriptChild()
|
nsIContentChild::AllocPJavaScriptChild()
|
||||||
{
|
{
|
||||||
return NewJavaScriptChild(xpc::GetJSRuntime());
|
return NewJavaScriptChild(danger::GetJSContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -58,7 +58,7 @@ nsIContentParent::AsContentBridgeParent()
|
||||||
PJavaScriptParent*
|
PJavaScriptParent*
|
||||||
nsIContentParent::AllocPJavaScriptParent()
|
nsIContentParent::AllocPJavaScriptParent()
|
||||||
{
|
{
|
||||||
return NewJavaScriptParent(xpc::GetJSRuntime());
|
return NewJavaScriptParent(danger::GetJSContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -336,7 +336,7 @@ RegisterGCCallbacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register a callback to trace wrapped JSObjects.
|
// Register a callback to trace wrapped JSObjects.
|
||||||
JSContext* cx = JS_GetContext(xpc::GetJSRuntime());
|
JSContext* cx = dom::danger::GetJSContext();
|
||||||
if (!JS_AddExtraGCRootsTracer(cx, TraceJSObjWrappers, nullptr)) {
|
if (!JS_AddExtraGCRootsTracer(cx, TraceJSObjWrappers, nullptr)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ UnregisterGCCallbacks()
|
||||||
MOZ_ASSERT(sCallbackIsRegistered);
|
MOZ_ASSERT(sCallbackIsRegistered);
|
||||||
|
|
||||||
// Remove tracing callback.
|
// Remove tracing callback.
|
||||||
JSContext* cx = JS_GetContext(xpc::GetJSRuntime());
|
JSContext* cx = dom::danger::GetJSContext();
|
||||||
JS_RemoveExtraGCRootsTracer(cx, TraceJSObjWrappers, nullptr);
|
JS_RemoveExtraGCRootsTracer(cx, TraceJSObjWrappers, nullptr);
|
||||||
|
|
||||||
// Remove delayed destruction callback.
|
// Remove delayed destruction callback.
|
||||||
|
|
|
@ -743,8 +743,8 @@ private:
|
||||||
operator=(const WorkerThreadContextPrivate&) = delete;
|
operator=(const WorkerThreadContextPrivate&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
JSContext*
|
bool
|
||||||
InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
|
InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSContext* aWorkerCx)
|
||||||
{
|
{
|
||||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||||
NS_ASSERTION(!aWorkerPrivate->GetJSContext(), "Already has a context!");
|
NS_ASSERTION(!aWorkerPrivate->GetJSContext(), "Already has a context!");
|
||||||
|
@ -752,9 +752,7 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
|
||||||
JSSettings settings;
|
JSSettings settings;
|
||||||
aWorkerPrivate->CopyJSSettings(settings);
|
aWorkerPrivate->CopyJSSettings(settings);
|
||||||
|
|
||||||
JSContext* workerCx = JS_GetContext(aRuntime);
|
JS::ContextOptionsRef(aWorkerCx) = settings.contextOptions;
|
||||||
|
|
||||||
JS::ContextOptionsRef(workerCx) = settings.contextOptions;
|
|
||||||
|
|
||||||
JSSettings::JSGCSettingsArray& gcSettings = settings.gcSettings;
|
JSSettings::JSGCSettingsArray& gcSettings = settings.gcSettings;
|
||||||
|
|
||||||
|
@ -763,17 +761,17 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
|
||||||
const JSSettings::JSGCSetting& setting = gcSettings[index];
|
const JSSettings::JSGCSetting& setting = gcSettings[index];
|
||||||
if (setting.IsSet()) {
|
if (setting.IsSet()) {
|
||||||
NS_ASSERTION(setting.value, "Can't handle 0 values!");
|
NS_ASSERTION(setting.value, "Can't handle 0 values!");
|
||||||
JS_SetGCParameter(workerCx, setting.key, setting.value);
|
JS_SetGCParameter(aWorkerCx, setting.key, setting.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_SetNativeStackQuota(workerCx, WORKER_CONTEXT_NATIVE_STACK_LIMIT);
|
JS_SetNativeStackQuota(aWorkerCx, WORKER_CONTEXT_NATIVE_STACK_LIMIT);
|
||||||
|
|
||||||
// Security policy:
|
// Security policy:
|
||||||
static const JSSecurityCallbacks securityCallbacks = {
|
static const JSSecurityCallbacks securityCallbacks = {
|
||||||
ContentSecurityPolicyAllows
|
ContentSecurityPolicyAllows
|
||||||
};
|
};
|
||||||
JS_SetSecurityCallbacks(workerCx, &securityCallbacks);
|
JS_SetSecurityCallbacks(aWorkerCx, &securityCallbacks);
|
||||||
|
|
||||||
// Set up the asm.js cache callbacks
|
// Set up the asm.js cache callbacks
|
||||||
static const JS::AsmJSCacheOps asmJSCacheOps = {
|
static const JS::AsmJSCacheOps asmJSCacheOps = {
|
||||||
|
@ -782,22 +780,22 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
|
||||||
AsmJSCacheOpenEntryForWrite,
|
AsmJSCacheOpenEntryForWrite,
|
||||||
asmjscache::CloseEntryForWrite
|
asmjscache::CloseEntryForWrite
|
||||||
};
|
};
|
||||||
JS::SetAsmJSCacheOps(workerCx, &asmJSCacheOps);
|
JS::SetAsmJSCacheOps(aWorkerCx, &asmJSCacheOps);
|
||||||
|
|
||||||
if (!JS::InitSelfHostedCode(workerCx)) {
|
if (!JS::InitSelfHostedCode(aWorkerCx)) {
|
||||||
NS_WARNING("Could not init self-hosted code!");
|
NS_WARNING("Could not init self-hosted code!");
|
||||||
return nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_SetInterruptCallback(workerCx, InterruptCallback);
|
JS_SetInterruptCallback(aWorkerCx, InterruptCallback);
|
||||||
|
|
||||||
js::SetCTypesActivityCallback(workerCx, CTypesActivityCallback);
|
js::SetCTypesActivityCallback(aWorkerCx, CTypesActivityCallback);
|
||||||
|
|
||||||
#ifdef JS_GC_ZEAL
|
#ifdef JS_GC_ZEAL
|
||||||
JS_SetGCZeal(workerCx, settings.gcZeal, settings.gcZealFrequency);
|
JS_SetGCZeal(aWorkerCx, settings.gcZeal, settings.gcZealFrequency);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return workerCx;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -851,12 +849,11 @@ public:
|
||||||
|
|
||||||
~WorkerJSRuntime()
|
~WorkerJSRuntime()
|
||||||
{
|
{
|
||||||
JSRuntime* rt = MaybeRuntime();
|
JSContext* cx = MaybeContext();
|
||||||
if (!rt) {
|
if (!cx) {
|
||||||
return; // Initialize() must have failed
|
return; // Initialize() must have failed
|
||||||
}
|
}
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(rt);
|
|
||||||
delete static_cast<WorkerThreadContextPrivate*>(JS_GetContextPrivate(cx));
|
delete static_cast<WorkerThreadContextPrivate*>(JS_GetContextPrivate(cx));
|
||||||
JS_SetContextPrivate(cx, nullptr);
|
JS_SetContextPrivate(cx, nullptr);
|
||||||
|
|
||||||
|
@ -2552,10 +2549,9 @@ WorkerThreadPrimaryRunnable::Run()
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSRuntime* rt = runtime.Runtime();
|
JSContext* cx = runtime.Context();
|
||||||
|
|
||||||
JSContext* cx = InitJSContextForWorker(mWorkerPrivate, rt);
|
if (!InitJSContextForWorker(mWorkerPrivate, cx)) {
|
||||||
if (!cx) {
|
|
||||||
// XXX need to fire an error at parent.
|
// XXX need to fire an error at parent.
|
||||||
NS_ERROR("Failed to create runtime and context!");
|
NS_ERROR("Failed to create runtime and context!");
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -2565,7 +2561,7 @@ WorkerThreadPrimaryRunnable::Run()
|
||||||
#ifdef MOZ_ENABLE_PROFILER_SPS
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
||||||
PseudoStack* stack = mozilla_get_pseudo_stack();
|
PseudoStack* stack = mozilla_get_pseudo_stack();
|
||||||
if (stack) {
|
if (stack) {
|
||||||
stack->sampleRuntime(rt);
|
stack->sampleContext(cx);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2583,7 +2579,7 @@ WorkerThreadPrimaryRunnable::Run()
|
||||||
|
|
||||||
#ifdef MOZ_ENABLE_PROFILER_SPS
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
||||||
if (stack) {
|
if (stack) {
|
||||||
stack->sampleRuntime(nullptr);
|
stack->sampleContext(nullptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,7 @@ public:
|
||||||
mReadyState(0), mUploadEvent(aUploadEvent), mProgressEvent(true),
|
mReadyState(0), mUploadEvent(aUploadEvent), mProgressEvent(true),
|
||||||
mLengthComputable(aLengthComputable), mUseCachedArrayBufferResponse(false),
|
mLengthComputable(aLengthComputable), mUseCachedArrayBufferResponse(false),
|
||||||
mResponseTextResult(NS_OK), mStatusResult(NS_OK), mResponseResult(NS_OK),
|
mResponseTextResult(NS_OK), mStatusResult(NS_OK), mResponseResult(NS_OK),
|
||||||
mScopeObj(GetJSRuntime(), aScopeObj)
|
mScopeObj(RootingCx(), aScopeObj)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
EventRunnable(Proxy* aProxy, bool aUploadEvent, const nsString& aType,
|
EventRunnable(Proxy* aProxy, bool aUploadEvent, const nsString& aType,
|
||||||
|
@ -521,7 +521,7 @@ public:
|
||||||
mUploadEvent(aUploadEvent), mProgressEvent(false), mLengthComputable(0),
|
mUploadEvent(aUploadEvent), mProgressEvent(false), mLengthComputable(0),
|
||||||
mUseCachedArrayBufferResponse(false), mResponseTextResult(NS_OK),
|
mUseCachedArrayBufferResponse(false), mResponseTextResult(NS_OK),
|
||||||
mStatusResult(NS_OK), mResponseResult(NS_OK),
|
mStatusResult(NS_OK), mResponseResult(NS_OK),
|
||||||
mScopeObj(GetJSRuntime(), aScopeObj)
|
mScopeObj(RootingCx(), aScopeObj)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -384,7 +384,7 @@ txXPCOMExtensionFunctionCall::evaluate(txIEvalContext* aContext,
|
||||||
uint8_t paramCount = methodInfo->GetParamCount();
|
uint8_t paramCount = methodInfo->GetParamCount();
|
||||||
uint8_t inArgs = paramCount - 1;
|
uint8_t inArgs = paramCount - 1;
|
||||||
|
|
||||||
JS::Rooted<txParamArrayHolder> invokeParams(mozilla::dom::GetJSRuntime());
|
JS::Rooted<txParamArrayHolder> invokeParams(mozilla::dom::RootingCx());
|
||||||
if (!invokeParams.get().Init(paramCount)) {
|
if (!invokeParams.get().Init(paramCount)) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -480,16 +480,10 @@ XPCShellEnvironment::Init()
|
||||||
// is unbuffered by default
|
// is unbuffered by default
|
||||||
setbuf(stdout, 0);
|
setbuf(stdout, 0);
|
||||||
|
|
||||||
JSRuntime *rt = xpc::GetJSRuntime();
|
|
||||||
if (!rt) {
|
|
||||||
NS_ERROR("failed to get JSRuntime from nsJSRuntimeService!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mGlobalHolder.init(rt);
|
|
||||||
|
|
||||||
AutoSafeJSContext cx;
|
AutoSafeJSContext cx;
|
||||||
|
|
||||||
|
mGlobalHolder.init(cx);
|
||||||
|
|
||||||
nsCOMPtr<nsIXPConnect> xpc =
|
nsCOMPtr<nsIXPConnect> xpc =
|
||||||
do_GetService(nsIXPConnect::GetCID());
|
do_GetService(nsIXPConnect::GetCID());
|
||||||
if (!xpc) {
|
if (!xpc) {
|
||||||
|
|
|
@ -78,13 +78,13 @@ void
|
||||||
GetWrappedCPOWTag(JSObject* obj, nsACString& out);
|
GetWrappedCPOWTag(JSObject* obj, nsACString& out);
|
||||||
|
|
||||||
PJavaScriptParent*
|
PJavaScriptParent*
|
||||||
NewJavaScriptParent(JSRuntime* rt);
|
NewJavaScriptParent(JSContext* cx);
|
||||||
|
|
||||||
void
|
void
|
||||||
ReleaseJavaScriptParent(PJavaScriptParent* parent);
|
ReleaseJavaScriptParent(PJavaScriptParent* parent);
|
||||||
|
|
||||||
PJavaScriptChild*
|
PJavaScriptChild*
|
||||||
NewJavaScriptChild(JSRuntime* rt);
|
NewJavaScriptChild(JSContext* cx);
|
||||||
|
|
||||||
void
|
void
|
||||||
ReleaseJavaScriptChild(PJavaScriptChild* child);
|
ReleaseJavaScriptChild(PJavaScriptChild* child);
|
||||||
|
|
|
@ -22,10 +22,10 @@ class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base
|
||||||
typedef WrapperAnswer Answer;
|
typedef WrapperAnswer Answer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit JavaScriptBase(JSRuntime* rt)
|
explicit JavaScriptBase(JSContext* cx)
|
||||||
: JavaScriptShared(rt),
|
: JavaScriptShared(cx),
|
||||||
WrapperOwner(rt),
|
WrapperOwner(cx),
|
||||||
WrapperAnswer(rt)
|
WrapperAnswer(cx)
|
||||||
{}
|
{}
|
||||||
virtual ~JavaScriptBase() {}
|
virtual ~JavaScriptBase() {}
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,15 @@ UpdateChildWeakPointersBeforeSweepingZoneGroup(JSContext* cx, void* data)
|
||||||
static_cast<JavaScriptChild*>(data)->updateWeakPointers();
|
static_cast<JavaScriptChild*>(data)->updateWeakPointers();
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaScriptChild::JavaScriptChild(JSRuntime* rt)
|
JavaScriptChild::JavaScriptChild(JSContext* cx)
|
||||||
: JavaScriptShared(rt),
|
: JavaScriptShared(cx),
|
||||||
JavaScriptBase<PJavaScriptChild>(rt)
|
JavaScriptBase<PJavaScriptChild>(cx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaScriptChild::~JavaScriptChild()
|
JavaScriptChild::~JavaScriptChild()
|
||||||
{
|
{
|
||||||
JSContext* cx = JS_GetContext(rt_);
|
JS_RemoveWeakPointerZoneGroupCallback(cx_, UpdateChildWeakPointersBeforeSweepingZoneGroup);
|
||||||
JS_RemoveWeakPointerZoneGroupCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -46,8 +45,7 @@ JavaScriptChild::init()
|
||||||
if (!WrapperAnswer::init())
|
if (!WrapperAnswer::init())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(rt_);
|
JS_AddWeakPointerZoneGroupCallback(cx_, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
|
||||||
JS_AddWeakPointerZoneGroupCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +66,9 @@ JavaScriptChild::scopeForTargetObjects()
|
||||||
}
|
}
|
||||||
|
|
||||||
PJavaScriptChild*
|
PJavaScriptChild*
|
||||||
mozilla::jsipc::NewJavaScriptChild(JSRuntime* rt)
|
mozilla::jsipc::NewJavaScriptChild(JSContext* cx)
|
||||||
{
|
{
|
||||||
JavaScriptChild* child = new JavaScriptChild(rt);
|
JavaScriptChild* child = new JavaScriptChild(cx);
|
||||||
if (!child->init()) {
|
if (!child->init()) {
|
||||||
delete child;
|
delete child;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace jsipc {
|
||||||
class JavaScriptChild : public JavaScriptBase<PJavaScriptChild>
|
class JavaScriptChild : public JavaScriptBase<PJavaScriptChild>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit JavaScriptChild(JSRuntime* rt);
|
explicit JavaScriptChild(JSContext* cx);
|
||||||
virtual ~JavaScriptChild();
|
virtual ~JavaScriptChild();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
|
|
@ -30,15 +30,15 @@ TraceParent(JSTracer* trc, void* data)
|
||||||
static_cast<JavaScriptParent*>(data)->trace(trc);
|
static_cast<JavaScriptParent*>(data)->trace(trc);
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaScriptParent::JavaScriptParent(JSRuntime* rt)
|
JavaScriptParent::JavaScriptParent(JSContext* cx)
|
||||||
: JavaScriptShared(rt),
|
: JavaScriptShared(cx),
|
||||||
JavaScriptBase<PJavaScriptParent>(rt)
|
JavaScriptBase<PJavaScriptParent>(cx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaScriptParent::~JavaScriptParent()
|
JavaScriptParent::~JavaScriptParent()
|
||||||
{
|
{
|
||||||
JS_RemoveExtraGCRootsTracer(JS_GetContext(rt_), TraceParent, this);
|
JS_RemoveExtraGCRootsTracer(cx_, TraceParent, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -47,7 +47,7 @@ JavaScriptParent::init()
|
||||||
if (!WrapperOwner::init())
|
if (!WrapperOwner::init())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
JS_AddExtraGCRootsTracer(JS_GetContext(rt_), TraceParent, this);
|
JS_AddExtraGCRootsTracer(cx_, TraceParent, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,9 +190,9 @@ JavaScriptParent::CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
PJavaScriptParent*
|
PJavaScriptParent*
|
||||||
mozilla::jsipc::NewJavaScriptParent(JSRuntime* rt)
|
mozilla::jsipc::NewJavaScriptParent(JSContext* cx)
|
||||||
{
|
{
|
||||||
JavaScriptParent* parent = new JavaScriptParent(rt);
|
JavaScriptParent* parent = new JavaScriptParent(cx);
|
||||||
if (!parent->init()) {
|
if (!parent->init()) {
|
||||||
delete parent;
|
delete parent;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace jsipc {
|
||||||
class JavaScriptParent : public JavaScriptBase<PJavaScriptParent>
|
class JavaScriptParent : public JavaScriptBase<PJavaScriptParent>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit JavaScriptParent(JSRuntime* rt);
|
explicit JavaScriptParent(JSContext* cx);
|
||||||
virtual ~JavaScriptParent();
|
virtual ~JavaScriptParent();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
|
|
@ -132,8 +132,8 @@ bool JavaScriptShared::sLoggingInitialized;
|
||||||
bool JavaScriptShared::sLoggingEnabled;
|
bool JavaScriptShared::sLoggingEnabled;
|
||||||
bool JavaScriptShared::sStackLoggingEnabled;
|
bool JavaScriptShared::sStackLoggingEnabled;
|
||||||
|
|
||||||
JavaScriptShared::JavaScriptShared(JSRuntime* rt)
|
JavaScriptShared::JavaScriptShared(JSContext* cx)
|
||||||
: rt_(rt),
|
: cx_(cx),
|
||||||
refcount_(1),
|
refcount_(1),
|
||||||
nextSerialNumber_(1)
|
nextSerialNumber_(1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,7 +130,7 @@ class Logging;
|
||||||
class JavaScriptShared : public CPOWManager
|
class JavaScriptShared : public CPOWManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit JavaScriptShared(JSRuntime* rt);
|
explicit JavaScriptShared(JSContext* cx);
|
||||||
virtual ~JavaScriptShared();
|
virtual ~JavaScriptShared();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
@ -183,7 +183,7 @@ class JavaScriptShared : public CPOWManager
|
||||||
virtual JSObject* scopeForTargetObjects() = 0;
|
virtual JSObject* scopeForTargetObjects() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JSRuntime* rt_;
|
JSContext* cx_;
|
||||||
uintptr_t refcount_;
|
uintptr_t refcount_;
|
||||||
|
|
||||||
IdToObjectMap objects_;
|
IdToObjectMap objects_;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace jsipc {
|
||||||
class WrapperAnswer : public virtual JavaScriptShared
|
class WrapperAnswer : public virtual JavaScriptShared
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit WrapperAnswer(JSRuntime* rt) : JavaScriptShared(rt) {}
|
explicit WrapperAnswer(JSContext* cx) : JavaScriptShared(cx) {}
|
||||||
|
|
||||||
bool RecvPreventExtensions(const ObjectId& objId, ReturnStatus* rs);
|
bool RecvPreventExtensions(const ObjectId& objId, ReturnStatus* rs);
|
||||||
bool RecvGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,
|
bool RecvGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,
|
||||||
|
|
|
@ -50,8 +50,8 @@ struct AuxCPOWData
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
WrapperOwner::WrapperOwner(JSRuntime* rt)
|
WrapperOwner::WrapperOwner(JSContext* cx)
|
||||||
: JavaScriptShared(rt),
|
: JavaScriptShared(cx),
|
||||||
inactive_(false)
|
inactive_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class WrapperOwner : public virtual JavaScriptShared
|
||||||
mozilla::ipc::IProtocol>::ActorDestroyReason
|
mozilla::ipc::IProtocol>::ActorDestroyReason
|
||||||
ActorDestroyReason;
|
ActorDestroyReason;
|
||||||
|
|
||||||
explicit WrapperOwner(JSRuntime* rt);
|
explicit WrapperOwner(JSContext* cx);
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
// Standard internal methods.
|
// Standard internal methods.
|
||||||
|
|
|
@ -886,13 +886,13 @@ extern JS_PUBLIC_API(bool)
|
||||||
CollectRuntimeStats(JSContext* cx, RuntimeStats* rtStats, ObjectPrivateVisitor* opv, bool anonymize);
|
CollectRuntimeStats(JSContext* cx, RuntimeStats* rtStats, ObjectPrivateVisitor* opv, bool anonymize);
|
||||||
|
|
||||||
extern JS_PUBLIC_API(size_t)
|
extern JS_PUBLIC_API(size_t)
|
||||||
SystemCompartmentCount(JSRuntime* rt);
|
SystemCompartmentCount(JSContext* cx);
|
||||||
|
|
||||||
extern JS_PUBLIC_API(size_t)
|
extern JS_PUBLIC_API(size_t)
|
||||||
UserCompartmentCount(JSRuntime* rt);
|
UserCompartmentCount(JSContext* cx);
|
||||||
|
|
||||||
extern JS_PUBLIC_API(size_t)
|
extern JS_PUBLIC_API(size_t)
|
||||||
PeakSizeOfTemporary(const JSRuntime* rt);
|
PeakSizeOfTemporary(const JSContext* cx);
|
||||||
|
|
||||||
extern JS_PUBLIC_API(bool)
|
extern JS_PUBLIC_API(bool)
|
||||||
AddSizeOfTab(JSContext* cx, JS::HandleObject obj, mozilla::MallocSizeOf mallocSizeOf,
|
AddSizeOfTab(JSContext* cx, JS::HandleObject obj, mozilla::MallocSizeOf mallocSizeOf,
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
#include "js/Utility.h"
|
#include "js/Utility.h"
|
||||||
|
|
||||||
|
struct JSContext;
|
||||||
struct JSRuntime;
|
struct JSRuntime;
|
||||||
class JSScript;
|
class JSScript;
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
|
||||||
void* lr;
|
void* lr;
|
||||||
};
|
};
|
||||||
|
|
||||||
ProfilingFrameIterator(JSRuntime* rt, const RegisterState& state,
|
ProfilingFrameIterator(JSContext* cx, const RegisterState& state,
|
||||||
uint32_t sampleBufferGen = UINT32_MAX);
|
uint32_t sampleBufferGen = UINT32_MAX);
|
||||||
~ProfilingFrameIterator();
|
~ProfilingFrameIterator();
|
||||||
void operator++();
|
void operator++();
|
||||||
|
@ -135,7 +136,7 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
|
||||||
};
|
};
|
||||||
|
|
||||||
JS_FRIEND_API(bool)
|
JS_FRIEND_API(bool)
|
||||||
IsProfilingEnabledForRuntime(JSRuntime* runtime);
|
IsProfilingEnabledForContext(JSContext* cx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After each sample run, this method should be called with the latest sample
|
* After each sample run, this method should be called with the latest sample
|
||||||
|
@ -146,7 +147,7 @@ IsProfilingEnabledForRuntime(JSRuntime* runtime);
|
||||||
* JSRuntime for documentation about what these values are used for.
|
* JSRuntime for documentation about what these values are used for.
|
||||||
*/
|
*/
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
UpdateJSRuntimeProfilerSampleBufferGen(JSRuntime* runtime, uint32_t generation,
|
UpdateJSContextProfilerSampleBufferGen(JSContext* cx, uint32_t generation,
|
||||||
uint32_t lapCount);
|
uint32_t lapCount);
|
||||||
|
|
||||||
struct ForEachProfiledFrameOp
|
struct ForEachProfiledFrameOp
|
||||||
|
@ -155,7 +156,7 @@ struct ForEachProfiledFrameOp
|
||||||
// lookups on JitcodeGlobalTable.
|
// lookups on JitcodeGlobalTable.
|
||||||
class MOZ_STACK_CLASS FrameHandle
|
class MOZ_STACK_CLASS FrameHandle
|
||||||
{
|
{
|
||||||
friend JS_PUBLIC_API(void) ForEachProfiledFrame(JSRuntime* rt, void* addr,
|
friend JS_PUBLIC_API(void) ForEachProfiledFrame(JSContext* cx, void* addr,
|
||||||
ForEachProfiledFrameOp& op);
|
ForEachProfiledFrameOp& op);
|
||||||
|
|
||||||
JSRuntime* rt_;
|
JSRuntime* rt_;
|
||||||
|
@ -188,7 +189,7 @@ struct ForEachProfiledFrameOp
|
||||||
};
|
};
|
||||||
|
|
||||||
JS_PUBLIC_API(void)
|
JS_PUBLIC_API(void)
|
||||||
ForEachProfiledFrame(JSRuntime* rt, void* addr, ForEachProfiledFrameOp& op);
|
ForEachProfiledFrame(JSContext* cx, void* addr, ForEachProfiledFrameOp& op);
|
||||||
|
|
||||||
} // namespace JS
|
} // namespace JS
|
||||||
|
|
||||||
|
|
|
@ -188,17 +188,17 @@ class ProfileEntry
|
||||||
};
|
};
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
SetRuntimeProfilingStack(JSRuntime* rt, ProfileEntry* stack, uint32_t* size,
|
SetContextProfilingStack(JSContext* cx, ProfileEntry* stack, uint32_t* size,
|
||||||
uint32_t max);
|
uint32_t max);
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
EnableRuntimeProfilingStack(JSRuntime* rt, bool enabled);
|
EnableContextProfilingStack(JSContext* cx, bool enabled);
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
RegisterRuntimeProfilingEventMarker(JSRuntime* rt, void (*fn)(const char*));
|
RegisterContextProfilingEventMarker(JSContext* cx, void (*fn)(const char*));
|
||||||
|
|
||||||
JS_FRIEND_API(jsbytecode*)
|
JS_FRIEND_API(jsbytecode*)
|
||||||
ProfilingGetPC(JSRuntime* rt, JSScript* script, void* ip);
|
ProfilingGetPC(JSContext* cx, JSScript* script, void* ip);
|
||||||
|
|
||||||
} // namespace js
|
} // namespace js
|
||||||
|
|
||||||
|
|
|
@ -660,7 +660,7 @@ class MOZ_RAII Rooted : public js::RootedBase<T>
|
||||||
*stack = reinterpret_cast<Rooted<void*>*>(this);
|
*stack = reinterpret_cast<Rooted<void*>*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline js::RootedListHeads& rootLists(js::ContextFriendFields* cx) {
|
inline js::RootedListHeads& rootLists(js::RootingContext* cx) {
|
||||||
return rootLists(reinterpret_cast<JSContext*>(cx));
|
return rootLists(reinterpret_cast<JSContext*>(cx));
|
||||||
}
|
}
|
||||||
inline js::RootedListHeads& rootLists(JSContext* cx) {
|
inline js::RootedListHeads& rootLists(JSContext* cx) {
|
||||||
|
@ -992,7 +992,7 @@ class PersistentRooted : public js::PersistentRootedBase<T>,
|
||||||
return js::PerThreadDataFriendFields::getMainThread(rt)->roots;
|
return js::PerThreadDataFriendFields::getMainThread(rt)->roots;
|
||||||
}
|
}
|
||||||
js::RootLists& rootLists(JSContext* cx) { return rootLists(js::GetRuntime(cx)); }
|
js::RootLists& rootLists(JSContext* cx) { return rootLists(js::GetRuntime(cx)); }
|
||||||
js::RootLists& rootLists(js::ContextFriendFields* cx) {
|
js::RootLists& rootLists(js::RootingContext* cx) {
|
||||||
return rootLists(reinterpret_cast<JSContext*>(cx));
|
return rootLists(reinterpret_cast<JSContext*>(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1095,6 +1095,7 @@ class JS_PUBLIC_API(ObjectPtr)
|
||||||
~ObjectPtr() { MOZ_ASSERT(!value); }
|
~ObjectPtr() { MOZ_ASSERT(!value); }
|
||||||
|
|
||||||
void finalize(JSRuntime* rt);
|
void finalize(JSRuntime* rt);
|
||||||
|
void finalize(JSContext* cx);
|
||||||
|
|
||||||
void init(JSObject* obj) { value = obj; }
|
void init(JSObject* obj) { value = obj; }
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ class JS_PUBLIC_API(CallbackTracer) : public JSTracer
|
||||||
: JSTracer(rt, JSTracer::TracerKindTag::Callback, weakTraceKind),
|
: JSTracer(rt, JSTracer::TracerKindTag::Callback, weakTraceKind),
|
||||||
contextName_(nullptr), contextIndex_(InvalidIndex), contextFunctor_(nullptr)
|
contextName_(nullptr), contextIndex_(InvalidIndex), contextFunctor_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
CallbackTracer(JSContext* cx, WeakMapTraceKind weakTraceKind = TraceWeakMapValues);
|
||||||
|
|
||||||
// Override these methods to receive notification when an edge is visited
|
// Override these methods to receive notification when an edge is visited
|
||||||
// with the type contained in the callback. The default implementation
|
// with the type contained in the callback. The default implementation
|
||||||
|
|
|
@ -1655,7 +1655,7 @@ ReadSPSProfilingStack(JSContext* cx, unsigned argc, Value* vp)
|
||||||
JS::ProfilingFrameIterator::RegisterState state;
|
JS::ProfilingFrameIterator::RegisterState state;
|
||||||
uint32_t physicalFrameNo = 0;
|
uint32_t physicalFrameNo = 0;
|
||||||
const unsigned propAttrs = JSPROP_ENUMERATE;
|
const unsigned propAttrs = JSPROP_ENUMERATE;
|
||||||
for (JS::ProfilingFrameIterator i(cx->runtime(), state); !i.done(); ++i, ++physicalFrameNo) {
|
for (JS::ProfilingFrameIterator i(cx, state); !i.done(); ++i, ++physicalFrameNo) {
|
||||||
MOZ_ASSERT(i.stackAddress() != nullptr);
|
MOZ_ASSERT(i.stackAddress() != nullptr);
|
||||||
|
|
||||||
// Array holding all inline frames in a single physical jit stack frame.
|
// Array holding all inline frames in a single physical jit stack frame.
|
||||||
|
|
|
@ -7325,7 +7325,7 @@ CClosure::Create(JSContext* cx,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClosureInfo* cinfo = cx->new_<ClosureInfo>(JS_GetRuntime(cx));
|
ClosureInfo* cinfo = cx->new_<ClosureInfo>(cx);
|
||||||
if (!cinfo) {
|
if (!cinfo) {
|
||||||
JS_ReportOutOfMemory(cx);
|
JS_ReportOutOfMemory(cx);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -7403,10 +7403,9 @@ CClosure::ClosureStub(ffi_cif* cif, void* result, void** args, void* userData)
|
||||||
|
|
||||||
// Retrieve the essentials from our closure object.
|
// Retrieve the essentials from our closure object.
|
||||||
ArgClosure argClosure(cif, result, args, static_cast<ClosureInfo*>(userData));
|
ArgClosure argClosure(cif, result, args, static_cast<ClosureInfo*>(userData));
|
||||||
JSRuntime* rt = argClosure.cinfo->rt;
|
JSContext* cx = argClosure.cinfo->cx;
|
||||||
RootedObject fun(rt, argClosure.cinfo->jsfnObj);
|
RootedObject fun(cx, argClosure.cinfo->jsfnObj);
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(rt);
|
|
||||||
js::PrepareScriptEnvironmentAndInvoke(cx, fun, argClosure);
|
js::PrepareScriptEnvironmentAndInvoke(cx, fun, argClosure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,7 @@ struct FunctionInfo
|
||||||
// Parameters necessary for invoking a JS function from a C closure.
|
// Parameters necessary for invoking a JS function from a C closure.
|
||||||
struct ClosureInfo
|
struct ClosureInfo
|
||||||
{
|
{
|
||||||
JSRuntime* rt;
|
JSContext* cx;
|
||||||
JS::Heap<JSObject*> closureObj; // CClosure object
|
JS::Heap<JSObject*> closureObj; // CClosure object
|
||||||
JS::Heap<JSObject*> typeObj; // FunctionType describing the C function
|
JS::Heap<JSObject*> typeObj; // FunctionType describing the C function
|
||||||
JS::Heap<JSObject*> thisObj; // 'this' object to use for the JS function call
|
JS::Heap<JSObject*> thisObj; // 'this' object to use for the JS function call
|
||||||
|
@ -327,8 +327,8 @@ struct ClosureInfo
|
||||||
|
|
||||||
// Anything conditionally freed in the destructor should be initialized to
|
// Anything conditionally freed in the destructor should be initialized to
|
||||||
// nullptr here.
|
// nullptr here.
|
||||||
explicit ClosureInfo(JSRuntime* runtime)
|
explicit ClosureInfo(JSContext* context)
|
||||||
: rt(runtime)
|
: cx(context)
|
||||||
, errResult(nullptr)
|
, errResult(nullptr)
|
||||||
, closure(nullptr)
|
, closure(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "jscntxt.h"
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
|
|
||||||
#include "vm/Runtime.h"
|
#include "vm/Runtime.h"
|
||||||
|
@ -27,9 +28,9 @@ MemProfiler::GetGCHeapProfiler(JSRuntime* runtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
MemProfiler*
|
MemProfiler*
|
||||||
MemProfiler::GetMemProfiler(JSRuntime* runtime)
|
MemProfiler::GetMemProfiler(JSContext* context)
|
||||||
{
|
{
|
||||||
return &runtime->gc.mMemProfiler;
|
return &context->gc.mMemProfiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -435,3 +435,7 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing,
|
||||||
}
|
}
|
||||||
buf[bufsize - 1] = '\0';
|
buf[bufsize - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS::CallbackTracer::CallbackTracer(JSContext* cx, WeakMapTraceKind weakTraceKind)
|
||||||
|
: CallbackTracer(cx->runtime(), weakTraceKind)
|
||||||
|
{}
|
||||||
|
|
|
@ -1642,17 +1642,17 @@ JS::ForEachProfiledFrameOp::FrameHandle::frameKind() const
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(void)
|
JS_PUBLIC_API(void)
|
||||||
JS::ForEachProfiledFrame(JSRuntime* rt, void* addr, ForEachProfiledFrameOp& op)
|
JS::ForEachProfiledFrame(JSContext* cx, void* addr, ForEachProfiledFrameOp& op)
|
||||||
{
|
{
|
||||||
js::jit::JitcodeGlobalTable* table = rt->jitRuntime()->getJitcodeGlobalTable();
|
js::jit::JitcodeGlobalTable* table = cx->jitRuntime()->getJitcodeGlobalTable();
|
||||||
js::jit::JitcodeGlobalEntry& entry = table->lookupInfallible(addr);
|
js::jit::JitcodeGlobalEntry& entry = table->lookupInfallible(addr);
|
||||||
|
|
||||||
// Extract the stack for the entry. Assume maximum inlining depth is <64
|
// Extract the stack for the entry. Assume maximum inlining depth is <64
|
||||||
const char* labels[64];
|
const char* labels[64];
|
||||||
uint32_t depth = entry.callStackAtAddr(rt, addr, labels, 64);
|
uint32_t depth = entry.callStackAtAddr(cx, addr, labels, 64);
|
||||||
MOZ_ASSERT(depth < 64);
|
MOZ_ASSERT(depth < 64);
|
||||||
for (uint32_t i = depth; i != 0; i--) {
|
for (uint32_t i = depth; i != 0; i--) {
|
||||||
JS::ForEachProfiledFrameOp::FrameHandle handle(rt, entry, addr, labels[i - 1], i - 1);
|
JS::ForEachProfiledFrameOp::FrameHandle handle(cx, entry, addr, labels[i - 1], i - 1);
|
||||||
op(handle);
|
op(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class CCWTestTracer : public JS::CallbackTracer {
|
||||||
JS::TraceKind expectedKind;
|
JS::TraceKind expectedKind;
|
||||||
|
|
||||||
CCWTestTracer(JSContext* cx, void** expectedThingp, JS::TraceKind expectedKind)
|
CCWTestTracer(JSContext* cx, void** expectedThingp, JS::TraceKind expectedKind)
|
||||||
: JS::CallbackTracer(JS_GetRuntime(cx)),
|
: JS::CallbackTracer(cx),
|
||||||
okay(true),
|
okay(true),
|
||||||
numberOfThingsTraced(0),
|
numberOfThingsTraced(0),
|
||||||
expectedThingp(expectedThingp),
|
expectedThingp(expectedThingp),
|
||||||
|
|
|
@ -23,7 +23,7 @@ class TestTracer : public JS::CallbackTracer
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
explicit TestTracer(JSContext* cx)
|
explicit TestTracer(JSContext* cx)
|
||||||
: JS::CallbackTracer(JS_GetRuntime(cx)),
|
: JS::CallbackTracer(cx),
|
||||||
found(false)
|
found(false)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,9 +20,9 @@ reset(JSContext* cx)
|
||||||
{
|
{
|
||||||
psize = max_stack = 0;
|
psize = max_stack = 0;
|
||||||
memset(pstack, 0, sizeof(pstack));
|
memset(pstack, 0, sizeof(pstack));
|
||||||
cx->runtime()->spsProfiler.stringsReset();
|
cx->spsProfiler.stringsReset();
|
||||||
cx->runtime()->spsProfiler.enableSlowAssertions(true);
|
cx->spsProfiler.enableSlowAssertions(true);
|
||||||
js::EnableRuntimeProfilingStack(cx->runtime(), true);
|
js::EnableContextProfilingStack(cx, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JSClass ptestClass = {
|
static const JSClass ptestClass = {
|
||||||
|
@ -47,14 +47,14 @@ test_fn2(JSContext* cx, unsigned argc, JS::Value* vp)
|
||||||
static bool
|
static bool
|
||||||
enable(JSContext* cx, unsigned argc, JS::Value* vp)
|
enable(JSContext* cx, unsigned argc, JS::Value* vp)
|
||||||
{
|
{
|
||||||
js::EnableRuntimeProfilingStack(cx->runtime(), true);
|
js::EnableContextProfilingStack(cx, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
disable(JSContext* cx, unsigned argc, JS::Value* vp)
|
disable(JSContext* cx, unsigned argc, JS::Value* vp)
|
||||||
{
|
{
|
||||||
js::EnableRuntimeProfilingStack(cx->runtime(), false);
|
js::EnableContextProfilingStack(cx, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ static const JSFunctionSpec ptestFunctions[] = {
|
||||||
static JSObject*
|
static JSObject*
|
||||||
initialize(JSContext* cx)
|
initialize(JSContext* cx)
|
||||||
{
|
{
|
||||||
js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 10);
|
js::SetContextProfilingStack(cx, pstack, &psize, 10);
|
||||||
JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
|
JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
|
||||||
return JS_InitClass(cx, global, nullptr, &ptestClass, Prof, 0,
|
return JS_InitClass(cx, global, nullptr, &ptestClass, Prof, 0,
|
||||||
nullptr, ptestFunctions, nullptr, nullptr);
|
nullptr, ptestFunctions, nullptr, nullptr);
|
||||||
|
@ -126,8 +126,8 @@ BEGIN_TEST(testProfileStrings_isCalledWithInterpreter)
|
||||||
CHECK(max_stack >= 6);
|
CHECK(max_stack >= 6);
|
||||||
CHECK(psize == 0);
|
CHECK(psize == 0);
|
||||||
}
|
}
|
||||||
js::EnableRuntimeProfilingStack(cx->runtime(), false);
|
js::EnableContextProfilingStack(cx, false);
|
||||||
js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 3);
|
js::SetContextProfilingStack(cx, pstack, &psize, 3);
|
||||||
reset(cx);
|
reset(cx);
|
||||||
{
|
{
|
||||||
JS::RootedValue rval(cx);
|
JS::RootedValue rval(cx);
|
||||||
|
@ -177,8 +177,8 @@ BEGIN_TEST(testProfileStrings_isCalledWithJIT)
|
||||||
CHECK(max_stack >= 8);
|
CHECK(max_stack >= 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
js::EnableRuntimeProfilingStack(cx->runtime(), false);
|
js::EnableContextProfilingStack(cx, false);
|
||||||
js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 3);
|
js::SetContextProfilingStack(cx, pstack, &psize, 3);
|
||||||
reset(cx);
|
reset(cx);
|
||||||
{
|
{
|
||||||
/* Limit the size of the stack and make sure we don't overflow */
|
/* Limit the size of the stack and make sure we don't overflow */
|
||||||
|
@ -227,7 +227,7 @@ BEGIN_TEST(testProfileStrings_worksWhenEnabledOnTheFly)
|
||||||
EXEC("function b(p) { p.test_fn(); }");
|
EXEC("function b(p) { p.test_fn(); }");
|
||||||
EXEC("function a() { var p = new Prof(); p.enable(); b(p); }");
|
EXEC("function a() { var p = new Prof(); p.enable(); b(p); }");
|
||||||
reset(cx);
|
reset(cx);
|
||||||
js::EnableRuntimeProfilingStack(cx->runtime(), false);
|
js::EnableContextProfilingStack(cx, false);
|
||||||
{
|
{
|
||||||
/* enable it in the middle of JS and make sure things check out */
|
/* enable it in the middle of JS and make sure things check out */
|
||||||
JS::RootedValue rval(cx);
|
JS::RootedValue rval(cx);
|
||||||
|
|
|
@ -559,18 +559,6 @@ JS_EndRequest(JSContext* cx)
|
||||||
StopRequest(cx);
|
StopRequest(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(JSRuntime*)
|
|
||||||
JS_GetRuntime(JSContext* cx)
|
|
||||||
{
|
|
||||||
return cx->runtime();
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_PUBLIC_API(JSContext*)
|
|
||||||
JS_GetContext(JSRuntime* rt)
|
|
||||||
{
|
|
||||||
return rt->contextFromMainThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_PUBLIC_API(JSContext*)
|
JS_PUBLIC_API(JSContext*)
|
||||||
JS_GetParentContext(JSContext* cx)
|
JS_GetParentContext(JSContext* cx)
|
||||||
{
|
{
|
||||||
|
@ -1942,10 +1930,11 @@ JS_IsNative(JSObject* obj)
|
||||||
return obj->isNative();
|
return obj->isNative();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(JSRuntime*)
|
JS_PUBLIC_API(void)
|
||||||
JS_GetObjectRuntime(JSObject* obj)
|
JS::AssertObjectBelongsToCurrentThread(JSObject* obj)
|
||||||
{
|
{
|
||||||
return obj->compartment()->runtimeFromMainThread();
|
JSRuntime* rt = obj->compartment()->runtimeFromAnyThread();
|
||||||
|
MOZ_RELEASE_ASSERT(CurrentThreadCanAccessRuntime(rt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -998,9 +998,6 @@ JS_GetContextPrivate(JSContext* cx);
|
||||||
JS_PUBLIC_API(void)
|
JS_PUBLIC_API(void)
|
||||||
JS_SetContextPrivate(JSContext* cx, void* data);
|
JS_SetContextPrivate(JSContext* cx, void* data);
|
||||||
|
|
||||||
extern JS_PUBLIC_API(JSRuntime*)
|
|
||||||
JS_GetRuntime(JSContext* cx);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API(JSContext*)
|
extern JS_PUBLIC_API(JSContext*)
|
||||||
JS_GetParentContext(JSContext* cx);
|
JS_GetParentContext(JSContext* cx);
|
||||||
|
|
||||||
|
@ -1045,16 +1042,6 @@ class MOZ_RAII JSAutoRequest
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern JS_PUBLIC_API(JSRuntime*)
|
|
||||||
JS_GetRuntime(JSContext* cx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the runtime's JSContext. The plan is to expose a single type to the
|
|
||||||
* API, so this function will likely be removed soon.
|
|
||||||
*/
|
|
||||||
extern JS_PUBLIC_API(JSContext*)
|
|
||||||
JS_GetContext(JSRuntime* rt);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API(JSVersion)
|
extern JS_PUBLIC_API(JSVersion)
|
||||||
JS_GetVersion(JSContext* cx);
|
JS_GetVersion(JSContext* cx);
|
||||||
|
|
||||||
|
@ -1245,6 +1232,13 @@ ContextOptionsRef(JSContext* cx);
|
||||||
JS_PUBLIC_API(bool)
|
JS_PUBLIC_API(bool)
|
||||||
InitSelfHostedCode(JSContext* cx);
|
InitSelfHostedCode(JSContext* cx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts (in debug and release builds) that `obj` belongs to the current
|
||||||
|
* thread's context.
|
||||||
|
*/
|
||||||
|
JS_PUBLIC_API(void)
|
||||||
|
AssertObjectBelongsToCurrentThread(JSObject* obj);
|
||||||
|
|
||||||
} /* namespace JS */
|
} /* namespace JS */
|
||||||
|
|
||||||
extern JS_PUBLIC_API(const char*)
|
extern JS_PUBLIC_API(const char*)
|
||||||
|
@ -2456,9 +2450,6 @@ JS_NewObject(JSContext* cx, const JSClass* clasp);
|
||||||
extern JS_PUBLIC_API(bool)
|
extern JS_PUBLIC_API(bool)
|
||||||
JS_IsNative(JSObject* obj);
|
JS_IsNative(JSObject* obj);
|
||||||
|
|
||||||
extern JS_PUBLIC_API(JSRuntime*)
|
|
||||||
JS_GetObjectRuntime(JSObject* obj);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
|
* Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
|
||||||
* proto. If proto is nullptr, the JS object will have `null` as [[Prototype]].
|
* proto. If proto is nullptr, the JS object will have `null` as [[Prototype]].
|
||||||
|
|
|
@ -1028,9 +1028,9 @@ struct DumpHeapTracer : public JS::CallbackTracer, public WeakMapTracer
|
||||||
const char* prefix;
|
const char* prefix;
|
||||||
FILE* output;
|
FILE* output;
|
||||||
|
|
||||||
DumpHeapTracer(FILE* fp, JSRuntime* rt)
|
DumpHeapTracer(FILE* fp, JSContext* cx)
|
||||||
: JS::CallbackTracer(rt, DoNotTraceWeakMaps),
|
: JS::CallbackTracer(cx, DoNotTraceWeakMaps),
|
||||||
js::WeakMapTracer(rt), prefix(""), output(fp)
|
js::WeakMapTracer(cx), prefix(""), output(fp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1167,6 +1167,12 @@ JS::ObjectPtr::finalize(JSRuntime* rt)
|
||||||
value = nullptr;
|
value = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
JS::ObjectPtr::finalize(JSContext* cx)
|
||||||
|
{
|
||||||
|
finalize(cx->runtime());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
JS::ObjectPtr::updateWeakPointerAfterGC()
|
JS::ObjectPtr::updateWeakPointerAfterGC()
|
||||||
{
|
{
|
||||||
|
|
|
@ -493,9 +493,9 @@ IsAtomsZone(JS::Zone* zone);
|
||||||
|
|
||||||
struct WeakMapTracer
|
struct WeakMapTracer
|
||||||
{
|
{
|
||||||
JSRuntime* runtime;
|
JSContext* context;
|
||||||
|
|
||||||
explicit WeakMapTracer(JSRuntime* rt) : runtime(rt) {}
|
explicit WeakMapTracer(JSContext* cx) : context(cx) {}
|
||||||
|
|
||||||
// Weak map tracer callback, called once for every binding of every
|
// Weak map tracer callback, called once for every binding of every
|
||||||
// weak map that was live at the time of the last garbage collection.
|
// weak map that was live at the time of the last garbage collection.
|
||||||
|
@ -2982,7 +2982,7 @@ class MemProfiler
|
||||||
return sActiveProfilerCount > 0;
|
return sActiveProfilerCount > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MemProfiler* GetMemProfiler(JSRuntime* runtime);
|
static MemProfiler* GetMemProfiler(JSContext* context);
|
||||||
|
|
||||||
static void SetNativeProfiler(NativeProfiler* aProfiler) {
|
static void SetNativeProfiler(NativeProfiler* aProfiler) {
|
||||||
sNativeProfiler = aProfiler;
|
sNativeProfiler = aProfiler;
|
||||||
|
|
|
@ -321,7 +321,12 @@ class RootLists
|
||||||
void finishPersistentRoots();
|
void finishPersistentRoots();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ContextFriendFields
|
struct RootingContext
|
||||||
|
{
|
||||||
|
RootLists roots;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ContextFriendFields : public RootingContext
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
JSRuntime* const runtime_;
|
JSRuntime* const runtime_;
|
||||||
|
@ -333,9 +338,6 @@ struct ContextFriendFields
|
||||||
JS::Zone* zone_;
|
JS::Zone* zone_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Rooting structures. */
|
|
||||||
RootLists roots;
|
|
||||||
|
|
||||||
explicit ContextFriendFields(JSRuntime* rt)
|
explicit ContextFriendFields(JSRuntime* rt)
|
||||||
: runtime_(rt), compartment_(nullptr), zone_(nullptr)
|
: runtime_(rt), compartment_(nullptr), zone_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -225,7 +225,7 @@ WatchpointMap::sweep()
|
||||||
void
|
void
|
||||||
WatchpointMap::traceAll(WeakMapTracer* trc)
|
WatchpointMap::traceAll(WeakMapTracer* trc)
|
||||||
{
|
{
|
||||||
JSRuntime* rt = trc->runtime;
|
JSRuntime* rt = trc->context;
|
||||||
for (CompartmentsIter comp(rt, SkipAtoms); !comp.done(); comp.next()) {
|
for (CompartmentsIter comp(rt, SkipAtoms); !comp.done(); comp.next()) {
|
||||||
if (WatchpointMap* wpmap = comp->watchpointMap)
|
if (WatchpointMap* wpmap = comp->watchpointMap)
|
||||||
wpmap->trace(trc);
|
wpmap->trace(trc);
|
||||||
|
|
|
@ -97,7 +97,7 @@ WeakMapBase::sweepZone(JS::Zone* zone)
|
||||||
void
|
void
|
||||||
WeakMapBase::traceAllMappings(WeakMapTracer* tracer)
|
WeakMapBase::traceAllMappings(WeakMapTracer* tracer)
|
||||||
{
|
{
|
||||||
JSRuntime* rt = tracer->runtime;
|
JSRuntime* rt = tracer->context;
|
||||||
for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) {
|
for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) {
|
||||||
for (WeakMapBase* m : zone->gcWeakMapList) {
|
for (WeakMapBase* m : zone->gcWeakMapList) {
|
||||||
// The WeakMapTracer callback is not allowed to GC.
|
// The WeakMapTracer callback is not allowed to GC.
|
||||||
|
|
|
@ -4525,7 +4525,7 @@ PrintProfilerEvents(JSContext* cx, unsigned argc, Value* vp)
|
||||||
{
|
{
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
if (cx->runtime()->spsProfiler.enabled())
|
if (cx->runtime()->spsProfiler.enabled())
|
||||||
js::RegisterRuntimeProfilingEventMarker(cx->runtime(), &PrintProfilerEvents_Callback);
|
js::RegisterContextProfilingEventMarker(cx, &PrintProfilerEvents_Callback);
|
||||||
args.rval().setUndefined();
|
args.rval().setUndefined();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4537,10 +4537,10 @@ Vector<StackChars, 0, SystemAllocPolicy> stacks;
|
||||||
static void
|
static void
|
||||||
SingleStepCallback(void* arg, jit::Simulator* sim, void* pc)
|
SingleStepCallback(void* arg, jit::Simulator* sim, void* pc)
|
||||||
{
|
{
|
||||||
JSRuntime* rt = reinterpret_cast<JSRuntime*>(arg);
|
JSContext* cx = reinterpret_cast<JSContext*>(arg);
|
||||||
|
|
||||||
// If profiling is not enabled, don't do anything.
|
// If profiling is not enabled, don't do anything.
|
||||||
if (!rt->spsProfiler.enabled())
|
if (!cx->spsProfiler.enabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JS::ProfilingFrameIterator::RegisterState state;
|
JS::ProfilingFrameIterator::RegisterState state;
|
||||||
|
@ -4557,7 +4557,7 @@ SingleStepCallback(void* arg, jit::Simulator* sim, void* pc)
|
||||||
StackChars stack;
|
StackChars stack;
|
||||||
uint32_t frameNo = 0;
|
uint32_t frameNo = 0;
|
||||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||||
for (JS::ProfilingFrameIterator i(rt, state); !i.done(); ++i) {
|
for (JS::ProfilingFrameIterator i(cx, state); !i.done(); ++i) {
|
||||||
MOZ_ASSERT(i.stackAddress() != nullptr);
|
MOZ_ASSERT(i.stackAddress() != nullptr);
|
||||||
MOZ_ASSERT(lastStackAddress <= i.stackAddress());
|
MOZ_ASSERT(lastStackAddress <= i.stackAddress());
|
||||||
lastStackAddress = i.stackAddress();
|
lastStackAddress = i.stackAddress();
|
||||||
|
@ -4592,7 +4592,7 @@ EnableSingleStepProfiling(JSContext* cx, unsigned argc, Value* vp)
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
|
||||||
jit::Simulator* sim = cx->runtime()->simulator();
|
jit::Simulator* sim = cx->runtime()->simulator();
|
||||||
sim->enable_single_stepping(SingleStepCallback, cx->runtime());
|
sim->enable_single_stepping(SingleStepCallback, cx);
|
||||||
|
|
||||||
args.rval().setUndefined();
|
args.rval().setUndefined();
|
||||||
return true;
|
return true;
|
||||||
|
@ -4650,13 +4650,13 @@ EnableSPSProfiling(JSContext* cx, unsigned argc, Value* vp)
|
||||||
ShellContext* sc = GetShellContext(cx);
|
ShellContext* sc = GetShellContext(cx);
|
||||||
|
|
||||||
// Disable before re-enabling; see the assertion in |SPSProfiler::setProfilingStack|.
|
// Disable before re-enabling; see the assertion in |SPSProfiler::setProfilingStack|.
|
||||||
if (cx->runtime()->spsProfiler.installed())
|
if (cx->spsProfiler.installed())
|
||||||
cx->runtime()->spsProfiler.enable(false);
|
cx->spsProfiler.enable(false);
|
||||||
|
|
||||||
SetRuntimeProfilingStack(cx->runtime(), sc->spsProfilingStack, &sc->spsProfilingStackSize,
|
SetContextProfilingStack(cx, sc->spsProfilingStack, &sc->spsProfilingStackSize,
|
||||||
ShellContext::SpsProfilingMaxStackSize);
|
ShellContext::SpsProfilingMaxStackSize);
|
||||||
cx->runtime()->spsProfiler.enableSlowAssertions(false);
|
cx->spsProfiler.enableSlowAssertions(false);
|
||||||
cx->runtime()->spsProfiler.enable(true);
|
cx->spsProfiler.enable(true);
|
||||||
|
|
||||||
args.rval().setUndefined();
|
args.rval().setUndefined();
|
||||||
return true;
|
return true;
|
||||||
|
@ -4670,25 +4670,25 @@ EnableSPSProfilingWithSlowAssertions(JSContext* cx, unsigned argc, Value* vp)
|
||||||
|
|
||||||
ShellContext* sc = GetShellContext(cx);
|
ShellContext* sc = GetShellContext(cx);
|
||||||
|
|
||||||
if (cx->runtime()->spsProfiler.enabled()) {
|
if (cx->spsProfiler.enabled()) {
|
||||||
// If profiling already enabled with slow assertions disabled,
|
// If profiling already enabled with slow assertions disabled,
|
||||||
// this is a no-op.
|
// this is a no-op.
|
||||||
if (cx->runtime()->spsProfiler.slowAssertionsEnabled())
|
if (cx->spsProfiler.slowAssertionsEnabled())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Slow assertions are off. Disable profiling before re-enabling
|
// Slow assertions are off. Disable profiling before re-enabling
|
||||||
// with slow assertions on.
|
// with slow assertions on.
|
||||||
cx->runtime()->spsProfiler.enable(false);
|
cx->spsProfiler.enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable before re-enabling; see the assertion in |SPSProfiler::setProfilingStack|.
|
// Disable before re-enabling; see the assertion in |SPSProfiler::setProfilingStack|.
|
||||||
if (cx->runtime()->spsProfiler.installed())
|
if (cx->spsProfiler.installed())
|
||||||
cx->runtime()->spsProfiler.enable(false);
|
cx->spsProfiler.enable(false);
|
||||||
|
|
||||||
SetRuntimeProfilingStack(cx->runtime(), sc->spsProfilingStack, &sc->spsProfilingStackSize,
|
SetContextProfilingStack(cx, sc->spsProfilingStack, &sc->spsProfilingStackSize,
|
||||||
ShellContext::SpsProfilingMaxStackSize);
|
ShellContext::SpsProfilingMaxStackSize);
|
||||||
cx->runtime()->spsProfiler.enableSlowAssertions(true);
|
cx->spsProfiler.enableSlowAssertions(true);
|
||||||
cx->runtime()->spsProfiler.enable(true);
|
cx->spsProfiler.enable(true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -876,10 +876,10 @@ JS::CollectRuntimeStats(JSContext* cx, RuntimeStats *rtStats, ObjectPrivateVisit
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(size_t)
|
JS_PUBLIC_API(size_t)
|
||||||
JS::SystemCompartmentCount(JSRuntime* rt)
|
JS::SystemCompartmentCount(JSContext* cx)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
for (CompartmentsIter comp(rt, WithAtoms); !comp.done(); comp.next()) {
|
for (CompartmentsIter comp(cx, WithAtoms); !comp.done(); comp.next()) {
|
||||||
if (comp->isSystem())
|
if (comp->isSystem())
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
@ -887,10 +887,10 @@ JS::SystemCompartmentCount(JSRuntime* rt)
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(size_t)
|
JS_PUBLIC_API(size_t)
|
||||||
JS::UserCompartmentCount(JSRuntime* rt)
|
JS::UserCompartmentCount(JSContext* cx)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
for (CompartmentsIter comp(rt, WithAtoms); !comp.done(); comp.next()) {
|
for (CompartmentsIter comp(cx, WithAtoms); !comp.done(); comp.next()) {
|
||||||
if (!comp->isSystem())
|
if (!comp->isSystem())
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
@ -898,9 +898,9 @@ JS::UserCompartmentCount(JSRuntime* rt)
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(size_t)
|
JS_PUBLIC_API(size_t)
|
||||||
JS::PeakSizeOfTemporary(const JSRuntime* rt)
|
JS::PeakSizeOfTemporary(const JSContext* cx)
|
||||||
{
|
{
|
||||||
return rt->tempLifoAlloc.peakSizeOfExcludingThis();
|
return cx->JSRuntime::tempLifoAlloc.peakSizeOfExcludingThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
|
@ -887,25 +887,25 @@ js::CurrentThreadCanAccessZone(Zone* zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
JS::UpdateJSRuntimeProfilerSampleBufferGen(JSRuntime* runtime, uint32_t generation,
|
JS::UpdateJSContextProfilerSampleBufferGen(JSContext* cx, uint32_t generation,
|
||||||
uint32_t lapCount)
|
uint32_t lapCount)
|
||||||
{
|
{
|
||||||
runtime->setProfilerSampleBufferGen(generation);
|
cx->setProfilerSampleBufferGen(generation);
|
||||||
runtime->updateProfilerSampleBufferLapCount(lapCount);
|
cx->updateProfilerSampleBufferLapCount(lapCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(bool)
|
JS_FRIEND_API(bool)
|
||||||
JS::IsProfilingEnabledForRuntime(JSRuntime* runtime)
|
JS::IsProfilingEnabledForContext(JSContext* cx)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(runtime);
|
MOZ_ASSERT(cx);
|
||||||
return runtime->spsProfiler.enabled();
|
return cx->spsProfiler.enabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSRuntime::IonBuilderList&
|
JSRuntime::IonBuilderList&
|
||||||
JSRuntime::ionLazyLinkList()
|
JSRuntime::ionLazyLinkList()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(TlsPerThreadData.get()->runtimeFromMainThread(),
|
MOZ_ASSERT(TlsPerThreadData.get()->runtimeFromMainThread(),
|
||||||
"Should only be mutated by the main thread.");
|
"Should only be mutated by the main thread.");
|
||||||
return ionLazyLinkList_;
|
return ionLazyLinkList_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -508,28 +508,28 @@ ProfileEntry::setPC(jsbytecode* pc) volatile
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
js::SetRuntimeProfilingStack(JSRuntime* rt, ProfileEntry* stack, uint32_t* size, uint32_t max)
|
js::SetContextProfilingStack(JSContext* cx, ProfileEntry* stack, uint32_t* size, uint32_t max)
|
||||||
{
|
{
|
||||||
rt->spsProfiler.setProfilingStack(stack, size, max);
|
cx->spsProfiler.setProfilingStack(stack, size, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
js::EnableRuntimeProfilingStack(JSRuntime* rt, bool enabled)
|
js::EnableContextProfilingStack(JSContext* cx, bool enabled)
|
||||||
{
|
{
|
||||||
rt->spsProfiler.enable(enabled);
|
cx->spsProfiler.enable(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(void)
|
JS_FRIEND_API(void)
|
||||||
js::RegisterRuntimeProfilingEventMarker(JSRuntime* rt, void (*fn)(const char*))
|
js::RegisterContextProfilingEventMarker(JSContext* cx, void (*fn)(const char*))
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(rt->spsProfiler.enabled());
|
MOZ_ASSERT(cx->spsProfiler.enabled());
|
||||||
rt->spsProfiler.setEventMarker(fn);
|
cx->spsProfiler.setEventMarker(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(jsbytecode*)
|
JS_FRIEND_API(jsbytecode*)
|
||||||
js::ProfilingGetPC(JSRuntime* rt, JSScript* script, void* ip)
|
js::ProfilingGetPC(JSContext* cx, JSScript* script, void* ip)
|
||||||
{
|
{
|
||||||
return rt->spsProfiler.ipToPC(script, size_t(ip));
|
return cx->spsProfiler.ipToPC(script, size_t(ip));
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoSuppressProfilerSampling::AutoSuppressProfilerSampling(JSContext* cx
|
AutoSuppressProfilerSampling::AutoSuppressProfilerSampling(JSContext* cx
|
||||||
|
|
|
@ -1719,24 +1719,24 @@ ActivationIterator::settle()
|
||||||
activation_ = activation_->prev();
|
activation_ = activation_->prev();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::ProfilingFrameIterator::ProfilingFrameIterator(JSRuntime* rt, const RegisterState& state,
|
JS::ProfilingFrameIterator::ProfilingFrameIterator(JSContext* cx, const RegisterState& state,
|
||||||
uint32_t sampleBufferGen)
|
uint32_t sampleBufferGen)
|
||||||
: rt_(rt),
|
: rt_(cx),
|
||||||
sampleBufferGen_(sampleBufferGen),
|
sampleBufferGen_(sampleBufferGen),
|
||||||
activation_(nullptr),
|
activation_(nullptr),
|
||||||
savedPrevJitTop_(nullptr)
|
savedPrevJitTop_(nullptr)
|
||||||
{
|
{
|
||||||
if (!rt->spsProfiler.enabled())
|
if (!cx->spsProfiler.enabled())
|
||||||
MOZ_CRASH("ProfilingFrameIterator called when spsProfiler not enabled for runtime.");
|
MOZ_CRASH("ProfilingFrameIterator called when spsProfiler not enabled for runtime.");
|
||||||
|
|
||||||
if (!rt->profilingActivation())
|
if (!cx->profilingActivation())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If profiler sampling is not enabled, skip.
|
// If profiler sampling is not enabled, skip.
|
||||||
if (!rt_->isProfilerSamplingEnabled())
|
if (!cx->isProfilerSamplingEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
activation_ = rt->profilingActivation();
|
activation_ = cx->profilingActivation();
|
||||||
|
|
||||||
MOZ_ASSERT(activation_->isProfiling());
|
MOZ_ASSERT(activation_->isProfiling());
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ModuleEntry(JSContext* aCx)
|
explicit ModuleEntry(JSContext* aCx)
|
||||||
: mozilla::Module(), obj(JS_GetRuntime(aCx)), thisObjectKey(JS_GetRuntime(aCx))
|
: mozilla::Module(), obj(aCx), thisObjectKey(aCx)
|
||||||
{
|
{
|
||||||
mVersion = mozilla::Module::kVersion;
|
mVersion = mozilla::Module::kVersion;
|
||||||
mCIDs = nullptr;
|
mCIDs = nullptr;
|
||||||
|
|
|
@ -2614,7 +2614,7 @@ nsXPCComponents_Utils::ClearMaxCCTime()
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXPCComponents_Utils::ForceShrinkingGC()
|
nsXPCComponents_Utils::ForceShrinkingGC()
|
||||||
{
|
{
|
||||||
JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context();
|
JSContext* cx = dom::danger::GetJSContext();
|
||||||
PrepareForFullGC(cx);
|
PrepareForFullGC(cx);
|
||||||
GCForReason(cx, GC_SHRINK, gcreason::COMPONENT_UTILS);
|
GCForReason(cx, GC_SHRINK, gcreason::COMPONENT_UTILS);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -2628,9 +2628,7 @@ class PreciseGCRunnable : public Runnable
|
||||||
|
|
||||||
NS_IMETHOD Run() override
|
NS_IMETHOD Run() override
|
||||||
{
|
{
|
||||||
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
|
JSContext* cx = dom::danger::GetJSContext();
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(rt);
|
|
||||||
if (JS_IsRunning(cx))
|
if (JS_IsRunning(cx))
|
||||||
return NS_DispatchToMainThread(this);
|
return NS_DispatchToMainThread(this);
|
||||||
|
|
||||||
|
|
|
@ -1628,8 +1628,8 @@ ReloadPrefsCallback(const char* pref, void* data)
|
||||||
XPCJSRuntime::~XPCJSRuntime()
|
XPCJSRuntime::~XPCJSRuntime()
|
||||||
{
|
{
|
||||||
// Elsewhere we abort immediately if XPCJSRuntime initialization fails.
|
// Elsewhere we abort immediately if XPCJSRuntime initialization fails.
|
||||||
// Therefore the runtime must be non-null.
|
// Therefore the context must be non-null.
|
||||||
MOZ_ASSERT(MaybeRuntime());
|
MOZ_ASSERT(MaybeContext());
|
||||||
|
|
||||||
// This destructor runs before ~CycleCollectedJSRuntime, which does the
|
// This destructor runs before ~CycleCollectedJSRuntime, which does the
|
||||||
// actual JS_DestroyRuntime() call. But destroying the runtime triggers
|
// actual JS_DestroyRuntime() call. But destroying the runtime triggers
|
||||||
|
@ -1690,7 +1690,7 @@ XPCJSRuntime::~XPCJSRuntime()
|
||||||
#ifdef MOZ_ENABLE_PROFILER_SPS
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
||||||
// Tell the profiler that the runtime is gone
|
// Tell the profiler that the runtime is gone
|
||||||
if (PseudoStack* stack = mozilla_get_pseudo_stack())
|
if (PseudoStack* stack = mozilla_get_pseudo_stack())
|
||||||
stack->sampleRuntime(nullptr);
|
stack->sampleContext(nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Preferences::UnregisterCallback(ReloadPrefsCallback, JS_OPTIONS_DOT_STR, this);
|
Preferences::UnregisterCallback(ReloadPrefsCallback, JS_OPTIONS_DOT_STR, this);
|
||||||
|
@ -1790,12 +1790,6 @@ xpc::GetCurrentCompartmentName(JSContext* cx, nsCString& name)
|
||||||
GetCompartmentName(compartment, name, &anonymizeID, false);
|
GetCompartmentName(compartment, name, &anonymizeID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSRuntime*
|
|
||||||
xpc::GetJSRuntime()
|
|
||||||
{
|
|
||||||
return XPCJSRuntime::Get()->Runtime();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
xpc::AddGCCallback(xpcGCCallback cb)
|
xpc::AddGCCallback(xpcGCCallback cb)
|
||||||
{
|
{
|
||||||
|
@ -1811,7 +1805,7 @@ xpc::RemoveGCCallback(xpcGCCallback cb)
|
||||||
static int64_t
|
static int64_t
|
||||||
JSMainRuntimeGCHeapDistinguishedAmount()
|
JSMainRuntimeGCHeapDistinguishedAmount()
|
||||||
{
|
{
|
||||||
JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context();
|
JSContext* cx = danger::GetJSContext();
|
||||||
return int64_t(JS_GetGCParameter(cx, JSGC_TOTAL_CHUNKS)) *
|
return int64_t(JS_GetGCParameter(cx, JSGC_TOTAL_CHUNKS)) *
|
||||||
js::gc::ChunkSize;
|
js::gc::ChunkSize;
|
||||||
}
|
}
|
||||||
|
@ -1819,22 +1813,22 @@ JSMainRuntimeGCHeapDistinguishedAmount()
|
||||||
static int64_t
|
static int64_t
|
||||||
JSMainRuntimeTemporaryPeakDistinguishedAmount()
|
JSMainRuntimeTemporaryPeakDistinguishedAmount()
|
||||||
{
|
{
|
||||||
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
|
JSContext* cx = danger::GetJSContext();
|
||||||
return JS::PeakSizeOfTemporary(rt);
|
return JS::PeakSizeOfTemporary(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t
|
static int64_t
|
||||||
JSMainRuntimeCompartmentsSystemDistinguishedAmount()
|
JSMainRuntimeCompartmentsSystemDistinguishedAmount()
|
||||||
{
|
{
|
||||||
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
|
JSContext* cx = danger::GetJSContext();
|
||||||
return JS::SystemCompartmentCount(rt);
|
return JS::SystemCompartmentCount(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t
|
static int64_t
|
||||||
JSMainRuntimeCompartmentsUserDistinguishedAmount()
|
JSMainRuntimeCompartmentsUserDistinguishedAmount()
|
||||||
{
|
{
|
||||||
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
|
JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context();
|
||||||
return JS::UserCompartmentCount(rt);
|
return JS::UserCompartmentCount(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSMainRuntimeTemporaryPeakReporter final : public nsIMemoryReporter
|
class JSMainRuntimeTemporaryPeakReporter final : public nsIMemoryReporter
|
||||||
|
@ -3442,14 +3436,12 @@ XPCJSRuntime::Initialize()
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(Runtime());
|
MOZ_ASSERT(Context());
|
||||||
JSRuntime* runtime = Runtime();
|
JSContext* cx = Context();
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(runtime);
|
mUnprivilegedJunkScope.init(cx, nullptr);
|
||||||
|
mPrivilegedJunkScope.init(cx, nullptr);
|
||||||
mUnprivilegedJunkScope.init(runtime, nullptr);
|
mCompilationScope.init(cx, nullptr);
|
||||||
mPrivilegedJunkScope.init(runtime, nullptr);
|
|
||||||
mCompilationScope.init(runtime, nullptr);
|
|
||||||
|
|
||||||
// these jsids filled in later when we have a JSContext to work with.
|
// these jsids filled in later when we have a JSContext to work with.
|
||||||
mStrIDs[0] = JSID_VOID;
|
mStrIDs[0] = JSID_VOID;
|
||||||
|
@ -3554,7 +3546,7 @@ XPCJSRuntime::Initialize()
|
||||||
js::SetPreserveWrapperCallback(cx, PreserveWrapper);
|
js::SetPreserveWrapperCallback(cx, PreserveWrapper);
|
||||||
#ifdef MOZ_ENABLE_PROFILER_SPS
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
||||||
if (PseudoStack* stack = mozilla_get_pseudo_stack())
|
if (PseudoStack* stack = mozilla_get_pseudo_stack())
|
||||||
stack->sampleRuntime(runtime);
|
stack->sampleContext(cx);
|
||||||
#endif
|
#endif
|
||||||
JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback);
|
JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback);
|
||||||
js::SetActivityCallback(cx, ActivityCallback, this);
|
js::SetActivityCallback(cx, ActivityCallback, this);
|
||||||
|
@ -3618,7 +3610,7 @@ XPCJSRuntime::newXPCJSRuntime()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->Runtime() &&
|
if (self->Context() &&
|
||||||
self->GetMultiCompartmentWrappedJSMap() &&
|
self->GetMultiCompartmentWrappedJSMap() &&
|
||||||
self->GetWrappedJSClassMap() &&
|
self->GetWrappedJSClassMap() &&
|
||||||
self->GetIID2NativeInterfaceMap() &&
|
self->GetIID2NativeInterfaceMap() &&
|
||||||
|
@ -3761,7 +3753,6 @@ XPCJSRuntime::DebugDump(int16_t depth)
|
||||||
depth--;
|
depth--;
|
||||||
XPC_LOG_ALWAYS(("XPCJSRuntime @ %x", this));
|
XPC_LOG_ALWAYS(("XPCJSRuntime @ %x", this));
|
||||||
XPC_LOG_INDENT();
|
XPC_LOG_INDENT();
|
||||||
XPC_LOG_ALWAYS(("mJSRuntime @ %x", Runtime()));
|
|
||||||
XPC_LOG_ALWAYS(("mJSContext @ %x", Context()));
|
XPC_LOG_ALWAYS(("mJSContext @ %x", Context()));
|
||||||
|
|
||||||
XPC_LOG_ALWAYS(("mWrappedJSClassMap @ %x with %d wrapperclasses(s)",
|
XPC_LOG_ALWAYS(("mWrappedJSClassMap @ %x with %d wrapperclasses(s)",
|
||||||
|
|
|
@ -1247,7 +1247,6 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aShellData);
|
MOZ_ASSERT(aShellData);
|
||||||
|
|
||||||
JSRuntime* rt;
|
|
||||||
JSContext* cx;
|
JSContext* cx;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
@ -1412,21 +1411,15 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rt = xpc::GetJSRuntime();
|
AutoJSAPI jsapi;
|
||||||
if (!rt) {
|
jsapi.Init();
|
||||||
printf("failed to get JSRuntime from XPConnect!\n");
|
cx = jsapi.cx();
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override the default XPConnect interrupt callback. We could store the
|
// Override the default XPConnect interrupt callback. We could store the
|
||||||
// old one and restore it before shutting down, but there's not really a
|
// old one and restore it before shutting down, but there's not really a
|
||||||
// reason to bother.
|
// reason to bother.
|
||||||
sScriptedInterruptCallback = new PersistentRootedValue;
|
sScriptedInterruptCallback = new PersistentRootedValue;
|
||||||
sScriptedInterruptCallback->init(rt, UndefinedValue());
|
sScriptedInterruptCallback->init(cx, UndefinedValue());
|
||||||
|
|
||||||
AutoJSAPI jsapi;
|
|
||||||
jsapi.Init();
|
|
||||||
cx = jsapi.cx();
|
|
||||||
|
|
||||||
JS_SetInterruptCallback(cx, XPCShellInterruptCallback);
|
JS_SetInterruptCallback(cx, XPCShellInterruptCallback);
|
||||||
|
|
||||||
|
|
|
@ -474,11 +474,11 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
|
||||||
if (mXrayExpandos.initialized())
|
if (mXrayExpandos.initialized())
|
||||||
mXrayExpandos.destroy();
|
mXrayExpandos.destroy();
|
||||||
|
|
||||||
JSRuntime* rt = XPCJSRuntime::Get()->Runtime();
|
JSContext* cx = dom::danger::GetJSContext();
|
||||||
mContentXBLScope.finalize(rt);
|
mContentXBLScope.finalize(cx);
|
||||||
for (size_t i = 0; i < mAddonScopes.Length(); i++)
|
for (size_t i = 0; i < mAddonScopes.Length(); i++)
|
||||||
mAddonScopes[i].finalize(rt);
|
mAddonScopes[i].finalize(cx);
|
||||||
mGlobalJSObject.finalize(rt);
|
mGlobalJSObject.finalize(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -408,7 +408,7 @@ CreateGlobalObject(JSContext* cx, const JSClass* clasp, nsIPrincipal* principal,
|
||||||
// TraceProtoAndIfaceCache unless that flag is set.
|
// TraceProtoAndIfaceCache unless that flag is set.
|
||||||
if (!((const js::Class*)clasp)->isWrappedNative())
|
if (!((const js::Class*)clasp)->isWrappedNative())
|
||||||
{
|
{
|
||||||
VerifyTraceProtoAndIfaceCacheCalledTracer trc(JS_GetRuntime(cx));
|
VerifyTraceProtoAndIfaceCacheCalledTracer trc(cx);
|
||||||
TraceChildren(&trc, GCCellPtr(global.get()));
|
TraceChildren(&trc, GCCellPtr(global.get()));
|
||||||
MOZ_ASSERT(trc.ok, "Trace hook on global needs to call TraceXPCGlobal for XPConnect compartments.");
|
MOZ_ASSERT(trc.ok, "Trace hook on global needs to call TraceXPCGlobal for XPConnect compartments.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -561,7 +561,7 @@ class ErrorReport {
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
DispatchScriptErrorEvent(nsPIDOMWindowInner* win, JSRuntime* rt, xpc::ErrorReport* xpcReport,
|
DispatchScriptErrorEvent(nsPIDOMWindowInner* win, JSContext* cx, xpc::ErrorReport* xpcReport,
|
||||||
JS::Handle<JS::Value> exception);
|
JS::Handle<JS::Value> exception);
|
||||||
|
|
||||||
// Get a stack of the sort that can be passed to
|
// Get a stack of the sort that can be passed to
|
||||||
|
@ -585,9 +585,6 @@ FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
|
||||||
extern void
|
extern void
|
||||||
GetCurrentCompartmentName(JSContext*, nsCString& name);
|
GetCurrentCompartmentName(JSContext*, nsCString& name);
|
||||||
|
|
||||||
JSRuntime*
|
|
||||||
GetJSRuntime();
|
|
||||||
|
|
||||||
void AddGCCallback(xpcGCCallback cb);
|
void AddGCCallback(xpcGCCallback cb);
|
||||||
void RemoveGCCallback(xpcGCCallback cb);
|
void RemoveGCCallback(xpcGCCallback cb);
|
||||||
|
|
||||||
|
|
|
@ -125,13 +125,13 @@ CompartmentName(JSContext* cx, JS::Handle<JSObject*> global, nsAString& name) {
|
||||||
* Generate a unique-to-the-application identifier for a group.
|
* Generate a unique-to-the-application identifier for a group.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
GenerateUniqueGroupId(const JSRuntime* rt, uint64_t uid, uint64_t processId, nsAString& groupId) {
|
GenerateUniqueGroupId(const JSContext* cx, uint64_t uid, uint64_t processId, nsAString& groupId) {
|
||||||
uint64_t runtimeId = reinterpret_cast<uintptr_t>(rt);
|
uint64_t contextId = reinterpret_cast<uintptr_t>(cx);
|
||||||
|
|
||||||
groupId.AssignLiteral("process: ");
|
groupId.AssignLiteral("process: ");
|
||||||
groupId.AppendInt(processId);
|
groupId.AppendInt(processId);
|
||||||
groupId.AppendLiteral(", thread: ");
|
groupId.AppendLiteral(", thread: ");
|
||||||
groupId.AppendInt(runtimeId);
|
groupId.AppendInt(contextId);
|
||||||
groupId.AppendLiteral(", group: ");
|
groupId.AppendLiteral(", group: ");
|
||||||
groupId.AppendInt(uid);
|
groupId.AppendInt(uid);
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
NS_DECL_NSITIMERCALLBACK
|
NS_DECL_NSITIMERCALLBACK
|
||||||
|
|
||||||
PendingAlertsCollector(JSRuntime* runtime, nsPerformanceStatsService* service)
|
explicit PendingAlertsCollector(nsPerformanceStatsService* service)
|
||||||
: mService(service)
|
: mService(service)
|
||||||
, mPending(false)
|
, mPending(false)
|
||||||
{ }
|
{ }
|
||||||
|
@ -651,9 +651,9 @@ nsPerformanceStatsService::nsPerformanceStatsService()
|
||||||
#else
|
#else
|
||||||
, mProcessId(getpid())
|
, mProcessId(getpid())
|
||||||
#endif
|
#endif
|
||||||
, mRuntime(xpc::GetJSRuntime())
|
, mContext(mozilla::dom::danger::GetJSContext())
|
||||||
, mUIdCounter(0)
|
, mUIdCounter(0)
|
||||||
, mTopGroup(nsPerformanceGroup::Make(mRuntime,
|
, mTopGroup(nsPerformanceGroup::Make(mContext,
|
||||||
this,
|
this,
|
||||||
NS_LITERAL_STRING("<process>"), // name
|
NS_LITERAL_STRING("<process>"), // name
|
||||||
NS_LITERAL_STRING(""), // addonid
|
NS_LITERAL_STRING(""), // addonid
|
||||||
|
@ -672,11 +672,11 @@ nsPerformanceStatsService::nsPerformanceStatsService()
|
||||||
, mJankLevelVisibilityThreshold(/* 2 ^ */ 8 /* ms */)
|
, mJankLevelVisibilityThreshold(/* 2 ^ */ 8 /* ms */)
|
||||||
, mMaxExpectedDurationOfInteractionUS(150 * 1000)
|
, mMaxExpectedDurationOfInteractionUS(150 * 1000)
|
||||||
{
|
{
|
||||||
mPendingAlertsCollector = new PendingAlertsCollector(mRuntime, this);
|
mPendingAlertsCollector = new PendingAlertsCollector(this);
|
||||||
|
|
||||||
// Attach some artificial group information to the universal listeners, to aid with debugging.
|
// Attach some artificial group information to the universal listeners, to aid with debugging.
|
||||||
nsString groupIdForAddons;
|
nsString groupIdForAddons;
|
||||||
GenerateUniqueGroupId(mRuntime, GetNextId(), mProcessId, groupIdForAddons);
|
GenerateUniqueGroupId(mContext, GetNextId(), mProcessId, groupIdForAddons);
|
||||||
mUniversalTargets.mAddons->
|
mUniversalTargets.mAddons->
|
||||||
SetTarget(new nsPerformanceGroupDetails(NS_LITERAL_STRING("<universal add-on listener>"),
|
SetTarget(new nsPerformanceGroupDetails(NS_LITERAL_STRING("<universal add-on listener>"),
|
||||||
groupIdForAddons,
|
groupIdForAddons,
|
||||||
|
@ -687,7 +687,7 @@ nsPerformanceStatsService::nsPerformanceStatsService()
|
||||||
|
|
||||||
|
|
||||||
nsString groupIdForWindows;
|
nsString groupIdForWindows;
|
||||||
GenerateUniqueGroupId(mRuntime, GetNextId(), mProcessId, groupIdForWindows);
|
GenerateUniqueGroupId(mContext, GetNextId(), mProcessId, groupIdForWindows);
|
||||||
mUniversalTargets.mWindows->
|
mUniversalTargets.mWindows->
|
||||||
SetTarget(new nsPerformanceGroupDetails(NS_LITERAL_STRING("<universal window listener>"),
|
SetTarget(new nsPerformanceGroupDetails(NS_LITERAL_STRING("<universal window listener>"),
|
||||||
groupIdForWindows,
|
groupIdForWindows,
|
||||||
|
@ -728,7 +728,7 @@ nsPerformanceStatsService::Dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear up and disconnect from JSAPI.
|
// Clear up and disconnect from JSAPI.
|
||||||
JSContext* cx = JS_GetContext(mRuntime);
|
JSContext* cx = mContext;
|
||||||
js::DisposePerformanceMonitoring(cx);
|
js::DisposePerformanceMonitoring(cx);
|
||||||
|
|
||||||
mozilla::Unused << js::SetStopwatchIsMonitoringCPOW(cx, false);
|
mozilla::Unused << js::SetStopwatchIsMonitoringCPOW(cx, false);
|
||||||
|
@ -800,7 +800,7 @@ nsPerformanceStatsService::InitInternal()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to JSAPI.
|
// Connect to JSAPI.
|
||||||
JSContext* cx = JS_GetContext(mRuntime);
|
JSContext* cx = mContext;
|
||||||
if (!js::SetStopwatchStartCallback(cx, StopwatchStartCallback, this)) {
|
if (!js::SetStopwatchStartCallback(cx, StopwatchStartCallback, this)) {
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
@ -1067,7 +1067,7 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx,
|
||||||
addonName.Append(addonId);
|
addonName.Append(addonId);
|
||||||
addonName.AppendLiteral(")");
|
addonName.AppendLiteral(")");
|
||||||
entry->
|
entry->
|
||||||
SetGroup(nsPerformanceGroup::Make(mRuntime, this,
|
SetGroup(nsPerformanceGroup::Make(mContext, this,
|
||||||
addonName, addonId, 0,
|
addonName, addonId, 0,
|
||||||
mProcessId, isSystem,
|
mProcessId, isSystem,
|
||||||
nsPerformanceGroup::GroupScope::ADDON)
|
nsPerformanceGroup::GroupScope::ADDON)
|
||||||
|
@ -1091,7 +1091,7 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx,
|
||||||
windowName.AppendInt(windowId);
|
windowName.AppendInt(windowId);
|
||||||
windowName.AppendLiteral(")");
|
windowName.AppendLiteral(")");
|
||||||
entry->
|
entry->
|
||||||
SetGroup(nsPerformanceGroup::Make(mRuntime, this,
|
SetGroup(nsPerformanceGroup::Make(mContext, this,
|
||||||
windowName, EmptyString(), windowId,
|
windowName, EmptyString(), windowId,
|
||||||
mProcessId, isSystem,
|
mProcessId, isSystem,
|
||||||
nsPerformanceGroup::GroupScope::WINDOW)
|
nsPerformanceGroup::GroupScope::WINDOW)
|
||||||
|
@ -1105,7 +1105,7 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx,
|
||||||
|
|
||||||
// All compartments have their own group.
|
// All compartments have their own group.
|
||||||
auto group =
|
auto group =
|
||||||
nsPerformanceGroup::Make(mRuntime, this,
|
nsPerformanceGroup::Make(mContext, this,
|
||||||
name, addonId, windowId,
|
name, addonId, windowId,
|
||||||
mProcessId, isSystem,
|
mProcessId, isSystem,
|
||||||
nsPerformanceGroup::GroupScope::COMPARTMENT);
|
nsPerformanceGroup::GroupScope::COMPARTMENT);
|
||||||
|
@ -1469,7 +1469,7 @@ nsPerformanceStatsService::UniversalTargets::UniversalTargets()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*static*/ nsPerformanceGroup*
|
/*static*/ nsPerformanceGroup*
|
||||||
nsPerformanceGroup::Make(JSRuntime* rt,
|
nsPerformanceGroup::Make(JSContext* cx,
|
||||||
nsPerformanceStatsService* service,
|
nsPerformanceStatsService* service,
|
||||||
const nsAString& name,
|
const nsAString& name,
|
||||||
const nsAString& addonId,
|
const nsAString& addonId,
|
||||||
|
@ -1479,7 +1479,7 @@ nsPerformanceGroup::Make(JSRuntime* rt,
|
||||||
GroupScope scope)
|
GroupScope scope)
|
||||||
{
|
{
|
||||||
nsString groupId;
|
nsString groupId;
|
||||||
::GenerateUniqueGroupId(rt, service->GetNextId(), processId, groupId);
|
::GenerateUniqueGroupId(cx, service->GetNextId(), processId, groupId);
|
||||||
return new nsPerformanceGroup(service, name, groupId, addonId, windowId, processId, isSystem, scope);
|
return new nsPerformanceGroup(service, name, groupId, addonId, windowId, processId, isSystem, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,9 +154,9 @@ protected:
|
||||||
const uint64_t mProcessId;
|
const uint64_t mProcessId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The JS Runtime for the main thread.
|
* The JS Context for the main thread.
|
||||||
*/
|
*/
|
||||||
JSRuntime* const mRuntime;
|
JSContext* const mContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate unique identifiers.
|
* Generate unique identifiers.
|
||||||
|
@ -630,7 +630,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Construct a performance group.
|
* Construct a performance group.
|
||||||
*
|
*
|
||||||
* @param rt The container runtime. Used to generate a unique identifier.
|
* @param cx The container context. Used to generate a unique identifier.
|
||||||
* @param service The performance service. Used during destruction to
|
* @param service The performance service. Used during destruction to
|
||||||
* cleanup the hash tables.
|
* cleanup the hash tables.
|
||||||
* @param name A name for the group, designed mostly for debugging purposes,
|
* @param name A name for the group, designed mostly for debugging purposes,
|
||||||
|
@ -645,7 +645,7 @@ public:
|
||||||
* @param scope the scope of this group.
|
* @param scope the scope of this group.
|
||||||
*/
|
*/
|
||||||
static nsPerformanceGroup*
|
static nsPerformanceGroup*
|
||||||
Make(JSRuntime* rt,
|
Make(JSContext* cx,
|
||||||
nsPerformanceStatsService* service,
|
nsPerformanceStatsService* service,
|
||||||
const nsAString& name,
|
const nsAString& name,
|
||||||
const nsAString& addonId,
|
const nsAString& addonId,
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
#include "SpecialSystemDirectory.h"
|
#include "SpecialSystemDirectory.h"
|
||||||
|
|
||||||
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
|
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
#include "mozilla/Omnijar.h"
|
#include "mozilla/Omnijar.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
|
@ -1219,9 +1221,8 @@ nsXREDirProvider::DoShutdown()
|
||||||
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
|
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
|
||||||
// resources which are about to go away in "profile-before-change" are destroyed first.
|
// resources which are about to go away in "profile-before-change" are destroyed first.
|
||||||
|
|
||||||
JSRuntime *rt = xpc::GetJSRuntime();
|
if (JSContext* cx = dom::danger::GetJSContext()) {
|
||||||
if (rt) {
|
JS_GC(cx);
|
||||||
JS_GC(JS_GetContext(rt));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase 3: Notify observers of a profile change
|
// Phase 3: Notify observers of a profile change
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
#include "prtime.h"
|
#include "prtime.h"
|
||||||
#include "xpcprivate.h"
|
#include "xpcprivate.h"
|
||||||
|
|
||||||
struct JSRuntime;
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
#define MEMORY_PROFILER_SAMPLE_SIZE 65536
|
#define MEMORY_PROFILER_SAMPLE_SIZE 65536
|
||||||
|
@ -77,9 +75,9 @@ ProfilerImpl::AddBytesSampled(uint32_t aBytes)
|
||||||
NS_IMPL_ISUPPORTS(MemoryProfiler, nsIMemoryProfiler)
|
NS_IMPL_ISUPPORTS(MemoryProfiler, nsIMemoryProfiler)
|
||||||
|
|
||||||
PRLock* MemoryProfiler::sLock;
|
PRLock* MemoryProfiler::sLock;
|
||||||
uint32_t MemoryProfiler::sProfileRuntimeCount;
|
uint32_t MemoryProfiler::sProfileContextCount;
|
||||||
StaticAutoPtr<NativeProfilerImpl> MemoryProfiler::sNativeProfiler;
|
StaticAutoPtr<NativeProfilerImpl> MemoryProfiler::sNativeProfiler;
|
||||||
StaticAutoPtr<JSRuntimeProfilerMap> MemoryProfiler::sJSRuntimeProfilerMap;
|
StaticAutoPtr<JSContextProfilerMap> MemoryProfiler::sJSContextProfilerMap;
|
||||||
TimeStamp MemoryProfiler::sStartTime;
|
TimeStamp MemoryProfiler::sStartTime;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -92,9 +90,9 @@ MemoryProfiler::InitOnce()
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
MallocHook::Initialize();
|
MallocHook::Initialize();
|
||||||
sLock = PR_NewLock();
|
sLock = PR_NewLock();
|
||||||
sProfileRuntimeCount = 0;
|
sProfileContextCount = 0;
|
||||||
sJSRuntimeProfilerMap = new JSRuntimeProfilerMap();
|
sJSContextProfilerMap = new JSContextProfilerMap();
|
||||||
ClearOnShutdown(&sJSRuntimeProfilerMap);
|
ClearOnShutdown(&sJSContextProfilerMap);
|
||||||
ClearOnShutdown(&sNativeProfiler);
|
ClearOnShutdown(&sNativeProfiler);
|
||||||
std::srand(PR_Now());
|
std::srand(PR_Now());
|
||||||
bool ignored;
|
bool ignored;
|
||||||
|
@ -109,12 +107,12 @@ MemoryProfiler::StartProfiler()
|
||||||
InitOnce();
|
InitOnce();
|
||||||
AutoUseUncensoredAllocator ua;
|
AutoUseUncensoredAllocator ua;
|
||||||
AutoMPLock lock(sLock);
|
AutoMPLock lock(sLock);
|
||||||
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
|
JSContext* context = XPCJSRuntime::Get()->Context();
|
||||||
ProfilerForJSRuntime profiler;
|
ProfilerForJSContext profiler;
|
||||||
if (!sJSRuntimeProfilerMap->Get(runtime, &profiler) ||
|
if (!sJSContextProfilerMap->Get(context, &profiler) ||
|
||||||
!profiler.mEnabled) {
|
!profiler.mEnabled) {
|
||||||
if (sProfileRuntimeCount == 0) {
|
if (sProfileContextCount == 0) {
|
||||||
js::EnableRuntimeProfilingStack(runtime, true);
|
js::EnableContextProfilingStack(context, true);
|
||||||
if (!sNativeProfiler) {
|
if (!sNativeProfiler) {
|
||||||
sNativeProfiler = new NativeProfilerImpl();
|
sNativeProfiler = new NativeProfilerImpl();
|
||||||
}
|
}
|
||||||
|
@ -123,12 +121,12 @@ MemoryProfiler::StartProfiler()
|
||||||
GCHeapProfilerImpl* gp = new GCHeapProfilerImpl();
|
GCHeapProfilerImpl* gp = new GCHeapProfilerImpl();
|
||||||
profiler.mEnabled = true;
|
profiler.mEnabled = true;
|
||||||
profiler.mProfiler = gp;
|
profiler.mProfiler = gp;
|
||||||
sJSRuntimeProfilerMap->Put(runtime, profiler);
|
sJSContextProfilerMap->Put(context, profiler);
|
||||||
MemProfiler::GetMemProfiler(runtime)->start(gp);
|
MemProfiler::GetMemProfiler(context)->start(gp);
|
||||||
if (sProfileRuntimeCount == 0) {
|
if (sProfileContextCount == 0) {
|
||||||
MallocHook::Enable(sNativeProfiler);
|
MallocHook::Enable(sNativeProfiler);
|
||||||
}
|
}
|
||||||
sProfileRuntimeCount++;
|
sProfileContextCount++;
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -139,18 +137,18 @@ MemoryProfiler::StopProfiler()
|
||||||
InitOnce();
|
InitOnce();
|
||||||
AutoUseUncensoredAllocator ua;
|
AutoUseUncensoredAllocator ua;
|
||||||
AutoMPLock lock(sLock);
|
AutoMPLock lock(sLock);
|
||||||
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
|
JSContext* context = XPCJSRuntime::Get()->Context();
|
||||||
ProfilerForJSRuntime profiler;
|
ProfilerForJSContext profiler;
|
||||||
if (sJSRuntimeProfilerMap->Get(runtime, &profiler) &&
|
if (sJSContextProfilerMap->Get(context, &profiler) &&
|
||||||
profiler.mEnabled) {
|
profiler.mEnabled) {
|
||||||
MemProfiler::GetMemProfiler(runtime)->stop();
|
MemProfiler::GetMemProfiler(context)->stop();
|
||||||
if (--sProfileRuntimeCount == 0) {
|
if (--sProfileContextCount == 0) {
|
||||||
MallocHook::Disable();
|
MallocHook::Disable();
|
||||||
MemProfiler::SetNativeProfiler(nullptr);
|
MemProfiler::SetNativeProfiler(nullptr);
|
||||||
js::EnableRuntimeProfilingStack(runtime, false);
|
js::EnableContextProfilingStack(context, false);
|
||||||
}
|
}
|
||||||
profiler.mEnabled = false;
|
profiler.mEnabled = false;
|
||||||
sJSRuntimeProfilerMap->Put(runtime, profiler);
|
sJSContextProfilerMap->Put(context, profiler);
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -161,15 +159,15 @@ MemoryProfiler::ResetProfiler()
|
||||||
InitOnce();
|
InitOnce();
|
||||||
AutoUseUncensoredAllocator ua;
|
AutoUseUncensoredAllocator ua;
|
||||||
AutoMPLock lock(sLock);
|
AutoMPLock lock(sLock);
|
||||||
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
|
JSContext* context = XPCJSRuntime::Get()->Context();
|
||||||
ProfilerForJSRuntime profiler;
|
ProfilerForJSContext profiler;
|
||||||
if (!sJSRuntimeProfilerMap->Get(runtime, &profiler) ||
|
if (!sJSContextProfilerMap->Get(context, &profiler) ||
|
||||||
!profiler.mEnabled) {
|
!profiler.mEnabled) {
|
||||||
delete profiler.mProfiler;
|
delete profiler.mProfiler;
|
||||||
profiler.mProfiler = nullptr;
|
profiler.mProfiler = nullptr;
|
||||||
sJSRuntimeProfilerMap->Put(runtime, profiler);
|
sJSContextProfilerMap->Put(context, profiler);
|
||||||
}
|
}
|
||||||
if (sProfileRuntimeCount == 0) {
|
if (sProfileContextCount == 0) {
|
||||||
sNativeProfiler = nullptr;
|
sNativeProfiler = nullptr;
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -251,18 +249,18 @@ MemoryProfiler::GetResults(JSContext* cx, JS::MutableHandle<JS::Value> aResult)
|
||||||
InitOnce();
|
InitOnce();
|
||||||
AutoUseUncensoredAllocator ua;
|
AutoUseUncensoredAllocator ua;
|
||||||
AutoMPLock lock(sLock);
|
AutoMPLock lock(sLock);
|
||||||
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
|
JSContext* context = XPCJSRuntime::Get()->Context();
|
||||||
// Getting results when the profiler is running is not allowed.
|
// Getting results when the profiler is running is not allowed.
|
||||||
if (sProfileRuntimeCount > 0) {
|
if (sProfileContextCount > 0) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
// Return immediately when native profiler does not exist.
|
// Return immediately when native profiler does not exist.
|
||||||
if (!sNativeProfiler) {
|
if (!sNativeProfiler) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
// Return immediately when there's no result in current runtime.
|
// Return immediately when there's no result in current context.
|
||||||
ProfilerForJSRuntime profiler;
|
ProfilerForJSContext profiler;
|
||||||
if (!sJSRuntimeProfilerMap->Get(runtime, &profiler) ||
|
if (!sJSContextProfilerMap->Get(context, &profiler) ||
|
||||||
!profiler.mProfiler) {
|
!profiler.mProfiler) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
#define MEMORY_PROFILER_CONTRACT_ID "@mozilla.org/tools/memory-profiler;1"
|
#define MEMORY_PROFILER_CONTRACT_ID "@mozilla.org/tools/memory-profiler;1"
|
||||||
|
|
||||||
struct JSRuntime;
|
|
||||||
struct PRLock;
|
struct PRLock;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
@ -30,17 +29,17 @@ namespace mozilla {
|
||||||
class NativeProfilerImpl;
|
class NativeProfilerImpl;
|
||||||
class GCHeapProfilerImpl;
|
class GCHeapProfilerImpl;
|
||||||
|
|
||||||
struct ProfilerForJSRuntime
|
struct ProfilerForJSContext
|
||||||
{
|
{
|
||||||
ProfilerForJSRuntime()
|
ProfilerForJSContext()
|
||||||
: mProfiler(nullptr)
|
: mProfiler(nullptr)
|
||||||
, mEnabled(false)
|
, mEnabled(false)
|
||||||
{}
|
{}
|
||||||
GCHeapProfilerImpl* mProfiler;
|
GCHeapProfilerImpl* mProfiler;
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
};
|
};
|
||||||
using JSRuntimeProfilerMap =
|
using JSContextProfilerMap =
|
||||||
nsDataHashtable<nsClearingPtrHashKey<JSRuntime>, ProfilerForJSRuntime>;
|
nsDataHashtable<nsClearingPtrHashKey<JSContext>, ProfilerForJSContext>;
|
||||||
|
|
||||||
class MemoryProfiler final : public nsIMemoryProfiler
|
class MemoryProfiler final : public nsIMemoryProfiler
|
||||||
{
|
{
|
||||||
|
@ -53,12 +52,12 @@ private:
|
||||||
~MemoryProfiler() {}
|
~MemoryProfiler() {}
|
||||||
|
|
||||||
// The accesses to other static member are guarded by sLock and
|
// The accesses to other static member are guarded by sLock and
|
||||||
// sProfileRuntimeCount.
|
// sProfileContextCount.
|
||||||
static PRLock* sLock;
|
static PRLock* sLock;
|
||||||
static uint32_t sProfileRuntimeCount;
|
static uint32_t sProfileContextCount;
|
||||||
|
|
||||||
static StaticAutoPtr<NativeProfilerImpl> sNativeProfiler;
|
static StaticAutoPtr<NativeProfilerImpl> sNativeProfiler;
|
||||||
static StaticAutoPtr<JSRuntimeProfilerMap> sJSRuntimeProfilerMap;
|
static StaticAutoPtr<JSContextProfilerMap> sJSContextProfilerMap;
|
||||||
static TimeStamp sStartTime;
|
static TimeStamp sStartTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -582,7 +582,7 @@ void GeckoSampler::StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime)
|
||||||
aWriter.End();
|
aWriter.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoSampler::FlushOnJSShutdown(JSRuntime* aRuntime)
|
void GeckoSampler::FlushOnJSShutdown(JSContext* aContext)
|
||||||
{
|
{
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
SetPaused(true);
|
SetPaused(true);
|
||||||
|
@ -597,8 +597,8 @@ void GeckoSampler::FlushOnJSShutdown(JSRuntime* aRuntime)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thread not profiling the runtime that's going away, skip it.
|
// Thread not profiling the context that's going away, skip it.
|
||||||
if (sRegisteredThreads->at(i)->Profile()->GetPseudoStack()->mRuntime != aRuntime) {
|
if (sRegisteredThreads->at(i)->Profile()->GetPseudoStack()->mContext != aContext) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,10 +614,10 @@ void GeckoSampler::FlushOnJSShutdown(JSRuntime* aRuntime)
|
||||||
void PseudoStack::flushSamplerOnJSShutdown()
|
void PseudoStack::flushSamplerOnJSShutdown()
|
||||||
{
|
{
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
MOZ_ASSERT(mRuntime);
|
MOZ_ASSERT(mContext);
|
||||||
GeckoSampler* t = tlsTicker.get();
|
GeckoSampler* t = tlsTicker.get();
|
||||||
if (t) {
|
if (t) {
|
||||||
t->FlushOnJSShutdown(mRuntime);
|
t->FlushOnJSShutdown(mContext);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -671,7 +671,7 @@ void addPseudoEntry(volatile StackEntry &entry, ThreadProfile &aProfile,
|
||||||
MOZ_ASSERT(&entry == &stack->mStack[stack->stackSize() - 1]);
|
MOZ_ASSERT(&entry == &stack->mStack[stack->stackSize() - 1]);
|
||||||
// If stack-walking was disabled, then that's just unfortunate
|
// If stack-walking was disabled, then that's just unfortunate
|
||||||
if (lastpc) {
|
if (lastpc) {
|
||||||
jsbytecode *jspc = js::ProfilingGetPC(stack->mRuntime, entry.script(),
|
jsbytecode *jspc = js::ProfilingGetPC(stack->mContext, entry.script(),
|
||||||
lastpc);
|
lastpc);
|
||||||
if (jspc) {
|
if (jspc) {
|
||||||
lineno = JS_PCToLineNumber(entry.script(), jspc);
|
lineno = JS_PCToLineNumber(entry.script(), jspc);
|
||||||
|
@ -755,7 +755,7 @@ void mergeStacksIntoProfile(ThreadProfile& aProfile, TickSample* aSample, Native
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
JS::ProfilingFrameIterator::Frame jsFrames[1000];
|
JS::ProfilingFrameIterator::Frame jsFrames[1000];
|
||||||
// Only walk jit stack if profiling frame iterator is turned on.
|
// Only walk jit stack if profiling frame iterator is turned on.
|
||||||
if (pseudoStack->mRuntime && JS::IsProfilingEnabledForRuntime(pseudoStack->mRuntime)) {
|
if (pseudoStack->mContext && JS::IsProfilingEnabledForContext(pseudoStack->mContext)) {
|
||||||
AutoWalkJSStack autoWalkJSStack;
|
AutoWalkJSStack autoWalkJSStack;
|
||||||
const uint32_t maxFrames = mozilla::ArrayLength(jsFrames);
|
const uint32_t maxFrames = mozilla::ArrayLength(jsFrames);
|
||||||
|
|
||||||
|
@ -767,7 +767,7 @@ void mergeStacksIntoProfile(ThreadProfile& aProfile, TickSample* aSample, Native
|
||||||
registerState.lr = aSample->lr;
|
registerState.lr = aSample->lr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JS::ProfilingFrameIterator jsIter(pseudoStack->mRuntime,
|
JS::ProfilingFrameIterator jsIter(pseudoStack->mContext,
|
||||||
registerState,
|
registerState,
|
||||||
startBufferGen);
|
startBufferGen);
|
||||||
for (; jsCount < maxFrames && !jsIter.done(); ++jsIter) {
|
for (; jsCount < maxFrames && !jsIter.done(); ++jsIter) {
|
||||||
|
@ -916,14 +916,14 @@ void mergeStacksIntoProfile(ThreadProfile& aProfile, TickSample* aSample, Native
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
// Update the JS runtime with the current profile sample buffer generation.
|
// Update the JS context with the current profile sample buffer generation.
|
||||||
//
|
//
|
||||||
// Do not do this for synchronous sampling, which create their own
|
// Do not do this for synchronous sampling, which create their own
|
||||||
// ProfileBuffers.
|
// ProfileBuffers.
|
||||||
if (!aSample->isSamplingCurrentThread && pseudoStack->mRuntime) {
|
if (!aSample->isSamplingCurrentThread && pseudoStack->mContext) {
|
||||||
MOZ_ASSERT(aProfile.bufferGeneration() >= startBufferGen);
|
MOZ_ASSERT(aProfile.bufferGeneration() >= startBufferGen);
|
||||||
uint32_t lapCount = aProfile.bufferGeneration() - startBufferGen;
|
uint32_t lapCount = aProfile.bufferGeneration() - startBufferGen;
|
||||||
JS::UpdateJSRuntimeProfilerSampleBufferGen(pseudoStack->mRuntime,
|
JS::UpdateJSContextProfilerSampleBufferGen(pseudoStack->mContext,
|
||||||
aProfile.bufferGeneration(),
|
aProfile.bufferGeneration(),
|
||||||
lapCount);
|
lapCount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ class GeckoSampler: public Sampler {
|
||||||
virtual void ToJSObjectAsync(double aSinceTime = 0, mozilla::dom::Promise* aPromise = 0);
|
virtual void ToJSObjectAsync(double aSinceTime = 0, mozilla::dom::Promise* aPromise = 0);
|
||||||
void StreamMetaJSCustomObject(SpliceableJSONWriter& aWriter);
|
void StreamMetaJSCustomObject(SpliceableJSONWriter& aWriter);
|
||||||
void StreamTaskTracer(SpliceableJSONWriter& aWriter);
|
void StreamTaskTracer(SpliceableJSONWriter& aWriter);
|
||||||
void FlushOnJSShutdown(JSRuntime* aRuntime);
|
void FlushOnJSShutdown(JSContext* aContext);
|
||||||
bool ProfileJS() const { return mProfileJS; }
|
bool ProfileJS() const { return mProfileJS; }
|
||||||
bool ProfileJava() const { return mProfileJava; }
|
bool ProfileJava() const { return mProfileJava; }
|
||||||
bool ProfileGPU() const { return mProfileGPU; }
|
bool ProfileGPU() const { return mProfileGPU; }
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
void addTag(const ProfileEntry& aTag);
|
void addTag(const ProfileEntry& aTag);
|
||||||
void StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
|
void StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
|
||||||
JSRuntime* rt, UniqueStacks& aUniqueStacks);
|
JSContext* cx, UniqueStacks& aUniqueStacks);
|
||||||
void StreamMarkersToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
|
void StreamMarkersToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
|
||||||
UniqueStacks& aUniqueStacks);
|
UniqueStacks& aUniqueStacks);
|
||||||
void DuplicateLastSample(int aThreadId);
|
void DuplicateLastSample(int aThreadId);
|
||||||
|
|
|
@ -385,8 +385,8 @@ UniqueStacks::Stack UniqueStacks::BeginStack(const OnStackFrameKey& aRoot)
|
||||||
return Stack(*this, aRoot);
|
return Stack(*this, aRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniqueStacks::UniqueStacks(JSRuntime* aRuntime)
|
UniqueStacks::UniqueStacks(JSContext* aContext)
|
||||||
: mRuntime(aRuntime)
|
: mContext(aContext)
|
||||||
, mFrameCount(0)
|
, mFrameCount(0)
|
||||||
{
|
{
|
||||||
mFrameTableWriter.StartBareList();
|
mFrameTableWriter.StartBareList();
|
||||||
|
@ -568,7 +568,7 @@ void UniqueStacks::StreamFrame(const OnStackFrameKey& aFrame)
|
||||||
}
|
}
|
||||||
mFrameTableWriter.EndArray();
|
mFrameTableWriter.EndArray();
|
||||||
|
|
||||||
JS::Rooted<JSScript*> script(mRuntime);
|
JS::Rooted<JSScript*> script(mContext);
|
||||||
jsbytecode* pc;
|
jsbytecode* pc;
|
||||||
mFrameTableWriter.StartObjectProperty("attempts");
|
mFrameTableWriter.StartObjectProperty("attempts");
|
||||||
{
|
{
|
||||||
|
@ -657,7 +657,7 @@ static void WriteSample(SpliceableJSONWriter& aWriter, ProfileSample& aSample)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
|
void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
|
||||||
double aSinceTime, JSRuntime* aRuntime,
|
double aSinceTime, JSContext* aContext,
|
||||||
UniqueStacks& aUniqueStacks)
|
UniqueStacks& aUniqueStacks)
|
||||||
{
|
{
|
||||||
Maybe<ProfileSample> sample;
|
Maybe<ProfileSample> sample;
|
||||||
|
@ -775,7 +775,7 @@ void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThre
|
||||||
unsigned depth = aUniqueStacks.LookupJITFrameDepth(pc);
|
unsigned depth = aUniqueStacks.LookupJITFrameDepth(pc);
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
StreamJSFramesOp framesOp(pc, stack);
|
StreamJSFramesOp framesOp(pc, stack);
|
||||||
JS::ForEachProfiledFrame(aRuntime, pc, framesOp);
|
JS::ForEachProfiledFrame(aContext, pc, framesOp);
|
||||||
aUniqueStacks.AddJITFrameDepth(pc, framesOp.depth());
|
aUniqueStacks.AddJITFrameDepth(pc, framesOp.depth());
|
||||||
} else {
|
} else {
|
||||||
for (unsigned i = 0; i < depth; i++) {
|
for (unsigned i = 0; i < depth; i++) {
|
||||||
|
|
|
@ -265,7 +265,7 @@ public:
|
||||||
StackKey mStack;
|
StackKey mStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit UniqueStacks(JSRuntime* aRuntime);
|
explicit UniqueStacks(JSContext* aContext);
|
||||||
|
|
||||||
Stack BeginStack(const OnStackFrameKey& aRoot);
|
Stack BeginStack(const OnStackFrameKey& aRoot);
|
||||||
uint32_t LookupJITFrameDepth(void* aAddr);
|
uint32_t LookupJITFrameDepth(void* aAddr);
|
||||||
|
@ -283,7 +283,7 @@ public:
|
||||||
UniqueJSONStrings mUniqueStrings;
|
UniqueJSONStrings mUniqueStrings;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JSRuntime* mRuntime;
|
JSContext* mContext;
|
||||||
|
|
||||||
// To avoid incurring JitcodeGlobalTable lookup costs for every JIT frame,
|
// To avoid incurring JitcodeGlobalTable lookup costs for every JIT frame,
|
||||||
// we cache the depth of frames keyed by JIT code address. If an address a
|
// we cache the depth of frames keyed by JIT code address. If an address a
|
||||||
|
|
|
@ -48,7 +48,7 @@ void ThreadProfile::StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime)
|
||||||
// mUniqueStacks may already be emplaced from FlushSamplesAndMarkers.
|
// mUniqueStacks may already be emplaced from FlushSamplesAndMarkers.
|
||||||
if (!mUniqueStacks.isSome()) {
|
if (!mUniqueStacks.isSome()) {
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
mUniqueStacks.emplace(mPseudoStack->mRuntime);
|
mUniqueStacks.emplace(mPseudoStack->mContext);
|
||||||
#else
|
#else
|
||||||
mUniqueStacks.emplace(nullptr);
|
mUniqueStacks.emplace(nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
@ -150,7 +150,7 @@ void ThreadProfile::StreamSamplesAndMarkers(SpliceableJSONWriter& aWriter, doubl
|
||||||
}
|
}
|
||||||
mBuffer->StreamSamplesToJSON(aWriter, mThreadId, aSinceTime,
|
mBuffer->StreamSamplesToJSON(aWriter, mThreadId, aSinceTime,
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
mPseudoStack->mRuntime,
|
mPseudoStack->mContext,
|
||||||
#else
|
#else
|
||||||
nullptr,
|
nullptr,
|
||||||
#endif
|
#endif
|
||||||
|
@ -186,8 +186,8 @@ void ThreadProfile::StreamSamplesAndMarkers(SpliceableJSONWriter& aWriter, doubl
|
||||||
void ThreadProfile::FlushSamplesAndMarkers()
|
void ThreadProfile::FlushSamplesAndMarkers()
|
||||||
{
|
{
|
||||||
// This function is used to serialize the current buffer just before
|
// This function is used to serialize the current buffer just before
|
||||||
// JSRuntime destruction.
|
// JSContext destruction.
|
||||||
MOZ_ASSERT(mPseudoStack->mRuntime);
|
MOZ_ASSERT(mPseudoStack->mContext);
|
||||||
|
|
||||||
// Unlike StreamJSObject, do not surround the samples in brackets by calling
|
// Unlike StreamJSObject, do not surround the samples in brackets by calling
|
||||||
// aWriter.{Start,End}BareList. The result string will be a comma-separated
|
// aWriter.{Start,End}BareList. The result string will be a comma-separated
|
||||||
|
@ -197,7 +197,7 @@ void ThreadProfile::FlushSamplesAndMarkers()
|
||||||
// Note that the UniqueStacks instance is persisted so that the frame-index
|
// Note that the UniqueStacks instance is persisted so that the frame-index
|
||||||
// mapping is stable across JS shutdown.
|
// mapping is stable across JS shutdown.
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
mUniqueStacks.emplace(mPseudoStack->mRuntime);
|
mUniqueStacks.emplace(mPseudoStack->mContext);
|
||||||
#else
|
#else
|
||||||
mUniqueStacks.emplace(nullptr);
|
mUniqueStacks.emplace(nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
@ -208,7 +208,7 @@ void ThreadProfile::FlushSamplesAndMarkers()
|
||||||
{
|
{
|
||||||
mBuffer->StreamSamplesToJSON(b, mThreadId, /* aSinceTime = */ 0,
|
mBuffer->StreamSamplesToJSON(b, mThreadId, /* aSinceTime = */ 0,
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
mPseudoStack->mRuntime,
|
mPseudoStack->mContext,
|
||||||
#else
|
#else
|
||||||
nullptr,
|
nullptr,
|
||||||
#endif
|
#endif
|
||||||
|
@ -228,7 +228,7 @@ void ThreadProfile::FlushSamplesAndMarkers()
|
||||||
mSavedStreamedMarkers = b.WriteFunc()->CopyData();
|
mSavedStreamedMarkers = b.WriteFunc()->CopyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the buffer. Attempting to symbolicate JS samples after mRuntime has
|
// Reset the buffer. Attempting to symbolicate JS samples after mContext has
|
||||||
// gone away will crash.
|
// gone away will crash.
|
||||||
mBuffer->reset();
|
mBuffer->reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,23 +315,23 @@ public:
|
||||||
return sMin(mStackPointer, mozilla::sig_safe_t(mozilla::ArrayLength(mStack)));
|
return sMin(mStackPointer, mozilla::sig_safe_t(mozilla::ArrayLength(mStack)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void sampleRuntime(JSRuntime* runtime) {
|
void sampleContext(JSContext* context) {
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
if (mRuntime && !runtime) {
|
if (mContext && !context) {
|
||||||
// On JS shut down, flush the current buffer as stringifying JIT samples
|
// On JS shut down, flush the current buffer as stringifying JIT samples
|
||||||
// requires a live JSRuntime.
|
// requires a live JSContext.
|
||||||
flushSamplerOnJSShutdown();
|
flushSamplerOnJSShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
mRuntime = runtime;
|
mContext = context;
|
||||||
|
|
||||||
if (!runtime) {
|
if (!context) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(sizeof(mStack[0]) == sizeof(js::ProfileEntry),
|
static_assert(sizeof(mStack[0]) == sizeof(js::ProfileEntry),
|
||||||
"mStack must be binary compatible with js::ProfileEntry.");
|
"mStack must be binary compatible with js::ProfileEntry.");
|
||||||
js::SetRuntimeProfilingStack(runtime,
|
js::SetContextProfilingStack(context,
|
||||||
(js::ProfileEntry*) mStack,
|
(js::ProfileEntry*) mStack,
|
||||||
(uint32_t*) &mStackPointer,
|
(uint32_t*) &mStackPointer,
|
||||||
(uint32_t) mozilla::ArrayLength(mStack));
|
(uint32_t) mozilla::ArrayLength(mStack));
|
||||||
|
@ -341,9 +341,9 @@ public:
|
||||||
}
|
}
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
void enableJSSampling() {
|
void enableJSSampling() {
|
||||||
if (mRuntime) {
|
if (mContext) {
|
||||||
js::EnableRuntimeProfilingStack(mRuntime, true);
|
js::EnableContextProfilingStack(mContext, true);
|
||||||
js::RegisterRuntimeProfilingEventMarker(mRuntime, &ProfilerJSEventMarker);
|
js::RegisterContextProfilingEventMarker(mContext, &ProfilerJSEventMarker);
|
||||||
mStartJSSampling = false;
|
mStartJSSampling = false;
|
||||||
} else {
|
} else {
|
||||||
mStartJSSampling = true;
|
mStartJSSampling = true;
|
||||||
|
@ -355,8 +355,8 @@ public:
|
||||||
}
|
}
|
||||||
void disableJSSampling() {
|
void disableJSSampling() {
|
||||||
mStartJSSampling = false;
|
mStartJSSampling = false;
|
||||||
if (mRuntime)
|
if (mContext)
|
||||||
js::EnableRuntimeProfilingStack(mRuntime, false);
|
js::EnableContextProfilingStack(mContext, false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ public:
|
||||||
, mSleeping(false)
|
, mSleeping(false)
|
||||||
, mRefCnt(1)
|
, mRefCnt(1)
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
, mRuntime(nullptr)
|
, mContext(nullptr)
|
||||||
#endif
|
#endif
|
||||||
, mStartJSSampling(false)
|
, mStartJSSampling(false)
|
||||||
, mPrivacyMode(false)
|
, mPrivacyMode(false)
|
||||||
|
@ -414,8 +414,8 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifndef SPS_STANDALONE
|
#ifndef SPS_STANDALONE
|
||||||
// The runtime which is being sampled
|
// The context which is being sampled
|
||||||
JSRuntime *mRuntime;
|
JSContext *mContext;
|
||||||
#endif
|
#endif
|
||||||
// Start JS Profiling when possible
|
// Start JS Profiling when possible
|
||||||
bool mStartJSSampling;
|
bool mStartJSSampling;
|
||||||
|
|
|
@ -128,9 +128,9 @@ public:
|
||||||
|
|
||||||
struct NoteWeakMapChildrenTracer : public JS::CallbackTracer
|
struct NoteWeakMapChildrenTracer : public JS::CallbackTracer
|
||||||
{
|
{
|
||||||
NoteWeakMapChildrenTracer(JSRuntime* aRt,
|
NoteWeakMapChildrenTracer(JSContext* aCx,
|
||||||
nsCycleCollectionNoteRootCallback& aCb)
|
nsCycleCollectionNoteRootCallback& aCb)
|
||||||
: JS::CallbackTracer(aRt), mCb(aCb), mTracedAny(false), mMap(nullptr),
|
: JS::CallbackTracer(aCx), mCb(aCb), mTracedAny(false), mMap(nullptr),
|
||||||
mKey(nullptr), mKeyDelegate(nullptr)
|
mKey(nullptr), mKeyDelegate(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -163,8 +163,8 @@ NoteWeakMapChildrenTracer::onChild(const JS::GCCellPtr& aThing)
|
||||||
|
|
||||||
struct NoteWeakMapsTracer : public js::WeakMapTracer
|
struct NoteWeakMapsTracer : public js::WeakMapTracer
|
||||||
{
|
{
|
||||||
NoteWeakMapsTracer(JSRuntime* aRt, nsCycleCollectionNoteRootCallback& aCccb)
|
NoteWeakMapsTracer(JSContext* aCx, nsCycleCollectionNoteRootCallback& aCccb)
|
||||||
: js::WeakMapTracer(aRt), mCb(aCccb), mChildTracer(aRt, aCccb)
|
: js::WeakMapTracer(aCx), mCb(aCccb), mChildTracer(aCx, aCccb)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void trace(JSObject* aMap, JS::GCCellPtr aKey, JS::GCCellPtr aValue) override;
|
void trace(JSObject* aMap, JS::GCCellPtr aKey, JS::GCCellPtr aValue) override;
|
||||||
|
@ -227,8 +227,8 @@ NoteWeakMapsTracer::trace(JSObject* aMap, JS::GCCellPtr aKey,
|
||||||
// This is based on the logic in FixWeakMappingGrayBitsTracer::trace.
|
// This is based on the logic in FixWeakMappingGrayBitsTracer::trace.
|
||||||
struct FixWeakMappingGrayBitsTracer : public js::WeakMapTracer
|
struct FixWeakMappingGrayBitsTracer : public js::WeakMapTracer
|
||||||
{
|
{
|
||||||
explicit FixWeakMappingGrayBitsTracer(JSRuntime* aRt)
|
explicit FixWeakMappingGrayBitsTracer(JSContext* aCx)
|
||||||
: js::WeakMapTracer(aRt)
|
: js::WeakMapTracer(aCx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +325,8 @@ JSZoneParticipant::Traverse(void* aPtr, nsCycleCollectionTraversalCallback& aCb)
|
||||||
|
|
||||||
struct TraversalTracer : public JS::CallbackTracer
|
struct TraversalTracer : public JS::CallbackTracer
|
||||||
{
|
{
|
||||||
TraversalTracer(JSRuntime* aRt, nsCycleCollectionTraversalCallback& aCb)
|
TraversalTracer(JSContext* aCx, nsCycleCollectionTraversalCallback& aCb)
|
||||||
: JS::CallbackTracer(aRt, DoNotTraceWeakMaps), mCb(aCb)
|
: JS::CallbackTracer(aCx, DoNotTraceWeakMaps), mCb(aCb)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void onChild(const JS::GCCellPtr& aThing) override;
|
void onChild(const JS::GCCellPtr& aThing) override;
|
||||||
|
@ -437,7 +437,6 @@ mozilla::GetBuildId(JS::BuildIdCharVector* aBuildID)
|
||||||
CycleCollectedJSRuntime::CycleCollectedJSRuntime()
|
CycleCollectedJSRuntime::CycleCollectedJSRuntime()
|
||||||
: mGCThingCycleCollectorGlobal(sGCThingCycleCollectorGlobal)
|
: mGCThingCycleCollectorGlobal(sGCThingCycleCollectorGlobal)
|
||||||
, mJSZoneCycleCollectorGlobal(sJSZoneCycleCollectorGlobal)
|
, mJSZoneCycleCollectorGlobal(sJSZoneCycleCollectorGlobal)
|
||||||
, mJSRuntime(nullptr)
|
|
||||||
, mJSContext(nullptr)
|
, mJSContext(nullptr)
|
||||||
, mPrevGCSliceCallback(nullptr)
|
, mPrevGCSliceCallback(nullptr)
|
||||||
, mPrevGCNurseryCollectionCallback(nullptr)
|
, mPrevGCNurseryCollectionCallback(nullptr)
|
||||||
|
@ -454,7 +453,7 @@ CycleCollectedJSRuntime::CycleCollectedJSRuntime()
|
||||||
CycleCollectedJSRuntime::~CycleCollectedJSRuntime()
|
CycleCollectedJSRuntime::~CycleCollectedJSRuntime()
|
||||||
{
|
{
|
||||||
// If the allocation failed, here we are.
|
// If the allocation failed, here we are.
|
||||||
if (!mJSRuntime) {
|
if (!mJSContext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,7 +478,6 @@ CycleCollectedJSRuntime::~CycleCollectedJSRuntime()
|
||||||
#endif // SPIDERMONKEY_PROMISE
|
#endif // SPIDERMONKEY_PROMISE
|
||||||
|
|
||||||
JS_DestroyContext(mJSContext);
|
JS_DestroyContext(mJSContext);
|
||||||
mJSRuntime = nullptr;
|
|
||||||
mJSContext = nullptr;
|
mJSContext = nullptr;
|
||||||
nsCycleCollector_forgetJSRuntime();
|
nsCycleCollector_forgetJSRuntime();
|
||||||
|
|
||||||
|
@ -511,7 +509,6 @@ CycleCollectedJSRuntime::Initialize(JSContext* aParentContext,
|
||||||
if (!mJSContext) {
|
if (!mJSContext) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
mJSRuntime = JS_GetRuntime(mJSContext);
|
|
||||||
|
|
||||||
if (!JS_AddExtraGCRootsTracer(mJSContext, TraceBlackJS, this)) {
|
if (!JS_AddExtraGCRootsTracer(mJSContext, TraceBlackJS, this)) {
|
||||||
MOZ_CRASH("JS_AddExtraGCRootsTracer failed");
|
MOZ_CRASH("JS_AddExtraGCRootsTracer failed");
|
||||||
|
@ -552,8 +549,8 @@ CycleCollectedJSRuntime::Initialize(JSContext* aParentContext,
|
||||||
#ifdef SPIDERMONKEY_PROMISE
|
#ifdef SPIDERMONKEY_PROMISE
|
||||||
JS::SetEnqueuePromiseJobCallback(mJSContext, EnqueuePromiseJobCallback, this);
|
JS::SetEnqueuePromiseJobCallback(mJSContext, EnqueuePromiseJobCallback, this);
|
||||||
JS::SetPromiseRejectionTrackerCallback(mJSContext, PromiseRejectionTrackerCallback, this);
|
JS::SetPromiseRejectionTrackerCallback(mJSContext, PromiseRejectionTrackerCallback, this);
|
||||||
mUncaughtRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
|
mUncaughtRejections.init(mJSContext, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
|
||||||
mConsumedRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
|
mConsumedRejections.init(mJSContext, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
|
||||||
#endif // SPIDERMONKEY_PROMISE
|
#endif // SPIDERMONKEY_PROMISE
|
||||||
|
|
||||||
JS::dbg::SetDebuggerMallocSizeOf(mJSContext, moz_malloc_size_of);
|
JS::dbg::SetDebuggerMallocSizeOf(mJSContext, moz_malloc_size_of);
|
||||||
|
@ -631,8 +628,8 @@ void
|
||||||
CycleCollectedJSRuntime::NoteGCThingJSChildren(JS::GCCellPtr aThing,
|
CycleCollectedJSRuntime::NoteGCThingJSChildren(JS::GCCellPtr aThing,
|
||||||
nsCycleCollectionTraversalCallback& aCb) const
|
nsCycleCollectionTraversalCallback& aCb) const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
TraversalTracer trc(mJSRuntime, aCb);
|
TraversalTracer trc(mJSContext, aCb);
|
||||||
JS::TraceChildren(&trc, aThing);
|
JS::TraceChildren(&trc, aThing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +707,7 @@ void
|
||||||
CycleCollectedJSRuntime::TraverseZone(JS::Zone* aZone,
|
CycleCollectedJSRuntime::TraverseZone(JS::Zone* aZone,
|
||||||
nsCycleCollectionTraversalCallback& aCb)
|
nsCycleCollectionTraversalCallback& aCb)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We treat the zone as being gray. We handle non-gray GCthings in the
|
* We treat the zone as being gray. We handle non-gray GCthings in the
|
||||||
|
@ -732,7 +729,7 @@ CycleCollectedJSRuntime::TraverseZone(JS::Zone* aZone,
|
||||||
* iterate over. Edges between compartments in the same zone will add
|
* iterate over. Edges between compartments in the same zone will add
|
||||||
* unnecessary loop edges to the graph (bug 842137).
|
* unnecessary loop edges to the graph (bug 842137).
|
||||||
*/
|
*/
|
||||||
TraversalTracer trc(mJSRuntime, aCb);
|
TraversalTracer trc(mJSContext, aCb);
|
||||||
js::VisitGrayWrapperTargets(aZone, NoteJSChildGrayWrapperShim, &trc);
|
js::VisitGrayWrapperTargets(aZone, NoteJSChildGrayWrapperShim, &trc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -906,7 +903,7 @@ CycleCollectedJSRuntime::OutOfMemoryCallback(JSContext* aContext,
|
||||||
{
|
{
|
||||||
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
||||||
|
|
||||||
MOZ_ASSERT(JS_GetRuntime(aContext) == self->Runtime());
|
MOZ_ASSERT(aContext == self->Context());
|
||||||
|
|
||||||
self->OnOutOfMemory();
|
self->OnOutOfMemory();
|
||||||
}
|
}
|
||||||
|
@ -967,7 +964,7 @@ CycleCollectedJSRuntime::EnqueuePromiseJobCallback(JSContext* aCx,
|
||||||
void* aData)
|
void* aData)
|
||||||
{
|
{
|
||||||
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
||||||
MOZ_ASSERT(JS_GetRuntime(aCx) == self->Runtime());
|
MOZ_ASSERT(aCx == self->Context());
|
||||||
MOZ_ASSERT(Get() == self);
|
MOZ_ASSERT(Get() == self);
|
||||||
|
|
||||||
nsIGlobalObject* global = nullptr;
|
nsIGlobalObject* global = nullptr;
|
||||||
|
@ -990,7 +987,7 @@ CycleCollectedJSRuntime::PromiseRejectionTrackerCallback(JSContext* aCx,
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
MOZ_ASSERT(JS_GetRuntime(aCx) == self->Runtime());
|
MOZ_ASSERT(aCx == self->Context());
|
||||||
MOZ_ASSERT(Get() == self);
|
MOZ_ASSERT(Get() == self);
|
||||||
|
|
||||||
if (state == PromiseRejectionHandlingState::Unhandled) {
|
if (state == PromiseRejectionHandlingState::Unhandled) {
|
||||||
|
@ -1056,7 +1053,7 @@ mozilla::TraceScriptHolder(nsISupports* aHolder, JSTracer* aTracer)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::TraceNativeGrayRoots(JSTracer* aTracer)
|
CycleCollectedJSRuntime::TraceNativeGrayRoots(JSTracer* aTracer)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
// NB: This is here just to preserve the existing XPConnect order. I doubt it
|
// NB: This is here just to preserve the existing XPConnect order. I doubt it
|
||||||
// would hurt to do this after the JS holders.
|
// would hurt to do this after the JS holders.
|
||||||
|
@ -1072,7 +1069,7 @@ CycleCollectedJSRuntime::TraceNativeGrayRoots(JSTracer* aTracer)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
|
CycleCollectedJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
mJSHolders.Put(aHolder, aTracer);
|
mJSHolders.Put(aHolder, aTracer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1123,7 +1120,7 @@ struct ClearJSHolder : public TraceCallbacks
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::RemoveJSHolder(void* aHolder)
|
CycleCollectedJSRuntime::RemoveJSHolder(void* aHolder)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
nsScriptObjectTracer* tracer = mJSHolders.Get(aHolder);
|
nsScriptObjectTracer* tracer = mJSHolders.Get(aHolder);
|
||||||
if (!tracer) {
|
if (!tracer) {
|
||||||
|
@ -1137,7 +1134,7 @@ CycleCollectedJSRuntime::RemoveJSHolder(void* aHolder)
|
||||||
bool
|
bool
|
||||||
CycleCollectedJSRuntime::IsJSHolder(void* aHolder)
|
CycleCollectedJSRuntime::IsJSHolder(void* aHolder)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
return mJSHolders.Get(aHolder, nullptr);
|
return mJSHolders.Get(aHolder, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1150,7 +1147,7 @@ AssertNoGcThing(JS::GCCellPtr aGCThing, const char* aName, void* aClosure)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::AssertNoObjectsToTrace(void* aPossibleJSHolder)
|
CycleCollectedJSRuntime::AssertNoObjectsToTrace(void* aPossibleJSHolder)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
nsScriptObjectTracer* tracer = mJSHolders.Get(aPossibleJSHolder);
|
nsScriptObjectTracer* tracer = mJSHolders.Get(aPossibleJSHolder);
|
||||||
if (tracer) {
|
if (tracer) {
|
||||||
|
@ -1162,7 +1159,7 @@ CycleCollectedJSRuntime::AssertNoObjectsToTrace(void* aPossibleJSHolder)
|
||||||
already_AddRefed<nsIException>
|
already_AddRefed<nsIException>
|
||||||
CycleCollectedJSRuntime::GetPendingException() const
|
CycleCollectedJSRuntime::GetPendingException() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
nsCOMPtr<nsIException> out = mPendingException;
|
nsCOMPtr<nsIException> out = mPendingException;
|
||||||
return out.forget();
|
return out.forget();
|
||||||
|
@ -1171,46 +1168,46 @@ CycleCollectedJSRuntime::GetPendingException() const
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::SetPendingException(nsIException* aException)
|
CycleCollectedJSRuntime::SetPendingException(nsIException* aException)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
mPendingException = aException;
|
mPendingException = aException;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::queue<nsCOMPtr<nsIRunnable>>&
|
std::queue<nsCOMPtr<nsIRunnable>>&
|
||||||
CycleCollectedJSRuntime::GetPromiseMicroTaskQueue()
|
CycleCollectedJSRuntime::GetPromiseMicroTaskQueue()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
return mPromiseMicroTaskQueue;
|
return mPromiseMicroTaskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::queue<nsCOMPtr<nsIRunnable>>&
|
std::queue<nsCOMPtr<nsIRunnable>>&
|
||||||
CycleCollectedJSRuntime::GetDebuggerPromiseMicroTaskQueue()
|
CycleCollectedJSRuntime::GetDebuggerPromiseMicroTaskQueue()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
return mDebuggerPromiseMicroTaskQueue;
|
return mDebuggerPromiseMicroTaskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCycleCollectionParticipant*
|
nsCycleCollectionParticipant*
|
||||||
CycleCollectedJSRuntime::GCThingParticipant()
|
CycleCollectedJSRuntime::GCThingParticipant()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
return &mGCThingCycleCollectorGlobal;
|
return &mGCThingCycleCollectorGlobal;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCycleCollectionParticipant*
|
nsCycleCollectionParticipant*
|
||||||
CycleCollectedJSRuntime::ZoneParticipant()
|
CycleCollectedJSRuntime::ZoneParticipant()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
return &mJSZoneCycleCollectorGlobal;
|
return &mJSZoneCycleCollectorGlobal;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
CycleCollectedJSRuntime::TraverseRoots(nsCycleCollectionNoteRootCallback& aCb)
|
CycleCollectedJSRuntime::TraverseRoots(nsCycleCollectionNoteRootCallback& aCb)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
TraverseNativeRoots(aCb);
|
TraverseNativeRoots(aCb);
|
||||||
|
|
||||||
NoteWeakMapsTracer trc(mJSRuntime, aCb);
|
NoteWeakMapsTracer trc(mJSContext, aCb);
|
||||||
js::TraceWeakMaps(&trc);
|
js::TraceWeakMaps(&trc);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -1225,10 +1222,10 @@ CycleCollectedJSRuntime::UsefulToMergeZones() const
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::FixWeakMappingGrayBits() const
|
CycleCollectedJSRuntime::FixWeakMappingGrayBits() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
MOZ_ASSERT(!JS::IsIncrementalGCInProgress(mJSContext),
|
MOZ_ASSERT(!JS::IsIncrementalGCInProgress(mJSContext),
|
||||||
"Don't call FixWeakMappingGrayBits during a GC.");
|
"Don't call FixWeakMappingGrayBits during a GC.");
|
||||||
FixWeakMappingGrayBitsTracer fixer(mJSRuntime);
|
FixWeakMappingGrayBitsTracer fixer(mJSContext);
|
||||||
fixer.FixAll();
|
fixer.FixAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,7 +1239,7 @@ CycleCollectedJSRuntime::AreGCGrayBitsValid() const
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::GarbageCollect(uint32_t aReason) const
|
CycleCollectedJSRuntime::GarbageCollect(uint32_t aReason) const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
MOZ_ASSERT(aReason < JS::gcreason::NUM_REASONS);
|
MOZ_ASSERT(aReason < JS::gcreason::NUM_REASONS);
|
||||||
JS::gcreason::Reason gcreason = static_cast<JS::gcreason::Reason>(aReason);
|
JS::gcreason::Reason gcreason = static_cast<JS::gcreason::Reason>(aReason);
|
||||||
|
@ -1254,7 +1251,7 @@ CycleCollectedJSRuntime::GarbageCollect(uint32_t aReason) const
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::JSObjectsTenured()
|
CycleCollectedJSRuntime::JSObjectsTenured()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
for (auto iter = mNurseryObjects.Iter(); !iter.Done(); iter.Next()) {
|
for (auto iter = mNurseryObjects.Iter(); !iter.Done(); iter.Next()) {
|
||||||
nsWrapperCache* cache = iter.Get();
|
nsWrapperCache* cache = iter.Get();
|
||||||
|
@ -1280,7 +1277,7 @@ for (auto iter = mPreservedNurseryObjects.Iter(); !iter.Done(); iter.Next()) {
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::NurseryWrapperAdded(nsWrapperCache* aCache)
|
CycleCollectedJSRuntime::NurseryWrapperAdded(nsWrapperCache* aCache)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
MOZ_ASSERT(aCache);
|
MOZ_ASSERT(aCache);
|
||||||
MOZ_ASSERT(aCache->GetWrapperPreserveColor());
|
MOZ_ASSERT(aCache->GetWrapperPreserveColor());
|
||||||
MOZ_ASSERT(!JS::ObjectIsTenured(aCache->GetWrapperPreserveColor()));
|
MOZ_ASSERT(!JS::ObjectIsTenured(aCache->GetWrapperPreserveColor()));
|
||||||
|
@ -1290,10 +1287,10 @@ CycleCollectedJSRuntime::NurseryWrapperAdded(nsWrapperCache* aCache)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::NurseryWrapperPreserved(JSObject* aWrapper)
|
CycleCollectedJSRuntime::NurseryWrapperPreserved(JSObject* aWrapper)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
mPreservedNurseryObjects.InfallibleAppend(
|
mPreservedNurseryObjects.InfallibleAppend(
|
||||||
JS::PersistentRooted<JSObject*>(mJSRuntime, aWrapper));
|
JS::PersistentRooted<JSObject*>(mJSContext, aWrapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1301,7 +1298,7 @@ CycleCollectedJSRuntime::DeferredFinalize(DeferredFinalizeAppendFunction aAppend
|
||||||
DeferredFinalizeFunction aFunc,
|
DeferredFinalizeFunction aFunc,
|
||||||
void* aThing)
|
void* aThing)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
void* thingArray = nullptr;
|
void* thingArray = nullptr;
|
||||||
bool hadThingArray = mDeferredFinalizerTable.Get(aFunc, &thingArray);
|
bool hadThingArray = mDeferredFinalizerTable.Get(aFunc, &thingArray);
|
||||||
|
@ -1315,7 +1312,7 @@ CycleCollectedJSRuntime::DeferredFinalize(DeferredFinalizeAppendFunction aAppend
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::DeferredFinalize(nsISupports* aSupports)
|
CycleCollectedJSRuntime::DeferredFinalize(nsISupports* aSupports)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
typedef DeferredFinalizerImpl<nsISupports> Impl;
|
typedef DeferredFinalizerImpl<nsISupports> Impl;
|
||||||
DeferredFinalize(Impl::AppendDeferredFinalizePointer, Impl::DeferredFinalize,
|
DeferredFinalize(Impl::AppendDeferredFinalizePointer, Impl::DeferredFinalize,
|
||||||
|
@ -1331,7 +1328,7 @@ CycleCollectedJSRuntime::DumpJSHeap(FILE* aFile)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::ProcessStableStateQueue()
|
CycleCollectedJSRuntime::ProcessStableStateQueue()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
MOZ_RELEASE_ASSERT(!mDoingStableStates);
|
MOZ_RELEASE_ASSERT(!mDoingStableStates);
|
||||||
mDoingStableStates = true;
|
mDoingStableStates = true;
|
||||||
|
|
||||||
|
@ -1347,7 +1344,7 @@ CycleCollectedJSRuntime::ProcessStableStateQueue()
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::ProcessMetastableStateQueue(uint32_t aRecursionDepth)
|
CycleCollectedJSRuntime::ProcessMetastableStateQueue(uint32_t aRecursionDepth)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
MOZ_RELEASE_ASSERT(!mDoingStableStates);
|
MOZ_RELEASE_ASSERT(!mDoingStableStates);
|
||||||
mDoingStableStates = true;
|
mDoingStableStates = true;
|
||||||
|
|
||||||
|
@ -1378,7 +1375,7 @@ CycleCollectedJSRuntime::ProcessMetastableStateQueue(uint32_t aRecursionDepth)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::AfterProcessTask(uint32_t aRecursionDepth)
|
CycleCollectedJSRuntime::AfterProcessTask(uint32_t aRecursionDepth)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
// See HTML 6.1.4.2 Processing model
|
// See HTML 6.1.4.2 Processing model
|
||||||
|
|
||||||
|
@ -1401,14 +1398,14 @@ CycleCollectedJSRuntime::AfterProcessTask(uint32_t aRecursionDepth)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::AfterProcessMicrotask()
|
CycleCollectedJSRuntime::AfterProcessMicrotask()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
AfterProcessMicrotask(RecursionDepth());
|
AfterProcessMicrotask(RecursionDepth());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::AfterProcessMicrotask(uint32_t aRecursionDepth)
|
CycleCollectedJSRuntime::AfterProcessMicrotask(uint32_t aRecursionDepth)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
// Between microtasks, execute any events that were waiting for a microtask
|
// Between microtasks, execute any events that were waiting for a microtask
|
||||||
// to complete.
|
// to complete.
|
||||||
|
@ -1424,14 +1421,14 @@ CycleCollectedJSRuntime::RecursionDepth()
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::RunInStableState(already_AddRefed<nsIRunnable>&& aRunnable)
|
CycleCollectedJSRuntime::RunInStableState(already_AddRefed<nsIRunnable>&& aRunnable)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
mStableStateEvents.AppendElement(Move(aRunnable));
|
mStableStateEvents.AppendElement(Move(aRunnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::RunInMetastableState(already_AddRefed<nsIRunnable>&& aRunnable)
|
CycleCollectedJSRuntime::RunInMetastableState(already_AddRefed<nsIRunnable>&& aRunnable)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
RunInMetastableStateData data;
|
RunInMetastableStateData data;
|
||||||
data.mRunnable = aRunnable;
|
data.mRunnable = aRunnable;
|
||||||
|
@ -1558,7 +1555,7 @@ IncrementalFinalizeRunnable::Run()
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::FinalizeDeferredThings(DeferredFinalizeType aType)
|
CycleCollectedJSRuntime::FinalizeDeferredThings(DeferredFinalizeType aType)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the previous GC created a runnable to finalize objects
|
* If the previous GC created a runnable to finalize objects
|
||||||
|
@ -1598,7 +1595,7 @@ void
|
||||||
CycleCollectedJSRuntime::AnnotateAndSetOutOfMemory(OOMState* aStatePtr,
|
CycleCollectedJSRuntime::AnnotateAndSetOutOfMemory(OOMState* aStatePtr,
|
||||||
OOMState aNewState)
|
OOMState aNewState)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
*aStatePtr = aNewState;
|
*aStatePtr = aNewState;
|
||||||
#ifdef MOZ_CRASHREPORTER
|
#ifdef MOZ_CRASHREPORTER
|
||||||
|
@ -1616,7 +1613,7 @@ CycleCollectedJSRuntime::AnnotateAndSetOutOfMemory(OOMState* aStatePtr,
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
|
CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
switch (aStatus) {
|
switch (aStatus) {
|
||||||
case JSGC_BEGIN:
|
case JSGC_BEGIN:
|
||||||
|
@ -1648,7 +1645,7 @@ CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::OnOutOfMemory()
|
CycleCollectedJSRuntime::OnOutOfMemory()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
AnnotateAndSetOutOfMemory(&mOutOfMemoryState, OOMState::Reporting);
|
AnnotateAndSetOutOfMemory(&mOutOfMemoryState, OOMState::Reporting);
|
||||||
CustomOutOfMemoryCallback();
|
CustomOutOfMemoryCallback();
|
||||||
|
@ -1658,7 +1655,7 @@ CycleCollectedJSRuntime::OnOutOfMemory()
|
||||||
void
|
void
|
||||||
CycleCollectedJSRuntime::OnLargeAllocationFailure()
|
CycleCollectedJSRuntime::OnLargeAllocationFailure()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSRuntime);
|
MOZ_ASSERT(mJSContext);
|
||||||
|
|
||||||
AnnotateAndSetOutOfMemory(&mLargeAllocationFailureState, OOMState::Reporting);
|
AnnotateAndSetOutOfMemory(&mLargeAllocationFailureState, OOMState::Reporting);
|
||||||
CustomLargeAllocationFailureCallback();
|
CustomLargeAllocationFailureCallback();
|
||||||
|
|
|
@ -324,20 +324,20 @@ public:
|
||||||
virtual void EndCycleCollectionCallback(CycleCollectorResults& aResults) = 0;
|
virtual void EndCycleCollectionCallback(CycleCollectorResults& aResults) = 0;
|
||||||
virtual void DispatchDeferredDeletion(bool aContinuation, bool aPurge = false) = 0;
|
virtual void DispatchDeferredDeletion(bool aContinuation, bool aPurge = false) = 0;
|
||||||
|
|
||||||
JSRuntime* Runtime() const
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(mJSRuntime);
|
|
||||||
return mJSRuntime;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSContext* Context() const
|
JSContext* Context() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mJSContext);
|
MOZ_ASSERT(mJSContext);
|
||||||
return mJSContext;
|
return mJSContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
js::RootingContext* RootingCx() const
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(mJSContext);
|
||||||
|
return js::ContextFriendFields::get(mJSContext);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JSRuntime* MaybeRuntime() const { return mJSRuntime; }
|
JSContext* MaybeContext() const { return mJSContext; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// nsThread entrypoints
|
// nsThread entrypoints
|
||||||
|
@ -401,7 +401,6 @@ private:
|
||||||
|
|
||||||
JSZoneParticipant mJSZoneCycleCollectorGlobal;
|
JSZoneParticipant mJSZoneCycleCollectorGlobal;
|
||||||
|
|
||||||
JSRuntime* mJSRuntime;
|
|
||||||
JSContext* mJSContext;
|
JSContext* mJSContext;
|
||||||
|
|
||||||
JS::GCSliceCallback mPrevGCSliceCallback;
|
JS::GCSliceCallback mPrevGCSliceCallback;
|
||||||
|
|
|
@ -999,7 +999,7 @@ ShutdownXPCOM(nsIServiceManager* aServMgr)
|
||||||
// duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that
|
// duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that
|
||||||
// never fired.
|
// never fired.
|
||||||
if (PseudoStack* stack = mozilla_get_pseudo_stack()) {
|
if (PseudoStack* stack = mozilla_get_pseudo_stack()) {
|
||||||
stack->sampleRuntime(nullptr);
|
stack->sampleContext(nullptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -129,10 +129,8 @@ CreateGlobalAndRunTest(JSContext* cx)
|
||||||
TEST(GCPostBarriers, nsTArray) {
|
TEST(GCPostBarriers, nsTArray) {
|
||||||
CycleCollectedJSRuntime* ccrt = CycleCollectedJSRuntime::Get();
|
CycleCollectedJSRuntime* ccrt = CycleCollectedJSRuntime::Get();
|
||||||
ASSERT_TRUE(ccrt != nullptr);
|
ASSERT_TRUE(ccrt != nullptr);
|
||||||
JSRuntime* rt = ccrt->Runtime();
|
JSContext* cx = ccrt->Context();
|
||||||
ASSERT_TRUE(rt != nullptr);
|
ASSERT_TRUE(cx != nullptr);
|
||||||
|
|
||||||
JSContext* cx = JS_GetContext(rt);
|
|
||||||
|
|
||||||
JS_BeginRequest(cx);
|
JS_BeginRequest(cx);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче