mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 11:45:37 +00:00
7a404f001b
This patch splits up the "wrapped-js" table by compartment in order to allow us to visit the miminal number of wrapped-js in each GC sweeping slice, instead of visiting the entire table repeatedly. This dramatically reduces our sweeping overhead, reducing the number of GC slices, and making them more likely to fall within budget. --HG-- extra : rebase_source : 1bb2b53f0cc51715e4e9c55caafdacd404278a04
84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
* vim: set ts=4 sw=4 et tw=80:
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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/. */
|
|
|
|
#include "JavaScriptChild.h"
|
|
#include "mozilla/dom/ContentChild.h"
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
#include "mozilla/ipc/MessageChannel.h"
|
|
#include "nsContentUtils.h"
|
|
#include "xpcprivate.h"
|
|
#include "jsfriendapi.h"
|
|
#include "AccessCheck.h"
|
|
|
|
using namespace JS;
|
|
using namespace mozilla;
|
|
using namespace mozilla::jsipc;
|
|
|
|
using mozilla::AutoSafeJSContext;
|
|
|
|
static void
|
|
UpdateChildWeakPointersBeforeSweepingZoneGroup(JSRuntime* rt, void* data)
|
|
{
|
|
static_cast<JavaScriptChild*>(data)->updateWeakPointers();
|
|
}
|
|
|
|
JavaScriptChild::JavaScriptChild(JSRuntime* rt)
|
|
: JavaScriptShared(rt),
|
|
JavaScriptBase<PJavaScriptChild>(rt)
|
|
{
|
|
}
|
|
|
|
JavaScriptChild::~JavaScriptChild()
|
|
{
|
|
JS_RemoveWeakPointerZoneGroupCallback(rt_, UpdateChildWeakPointersBeforeSweepingZoneGroup);
|
|
}
|
|
|
|
bool
|
|
JavaScriptChild::init()
|
|
{
|
|
if (!WrapperOwner::init())
|
|
return false;
|
|
if (!WrapperAnswer::init())
|
|
return false;
|
|
|
|
JS_AddWeakPointerZoneGroupCallback(rt_, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
|
|
return true;
|
|
}
|
|
|
|
void
|
|
JavaScriptChild::updateWeakPointers()
|
|
{
|
|
objects_.sweep();
|
|
unwaivedObjectIds_.sweep();
|
|
waivedObjectIds_.sweep();
|
|
}
|
|
|
|
JSObject*
|
|
JavaScriptChild::scopeForTargetObjects()
|
|
{
|
|
// CPOWs from the parent need to point into the child's privileged junk
|
|
// scope so that they can benefit from XrayWrappers in the child.
|
|
return xpc::PrivilegedJunkScope();
|
|
}
|
|
|
|
PJavaScriptChild*
|
|
mozilla::jsipc::NewJavaScriptChild(JSRuntime* rt)
|
|
{
|
|
JavaScriptChild* child = new JavaScriptChild(rt);
|
|
if (!child->init()) {
|
|
delete child;
|
|
return nullptr;
|
|
}
|
|
return child;
|
|
}
|
|
|
|
void
|
|
mozilla::jsipc::ReleaseJavaScriptChild(PJavaScriptChild* child)
|
|
{
|
|
static_cast<JavaScriptChild*>(child)->decref();
|
|
}
|