servo: Merge #11372 - Pass a parent JS runtime when creating DOM Worker runtimes (from tschneidereit:parent-js-runtime-for-workers); r=nox

This enables sharing data with the parent runtime, decreasing memory usage and startup time. Also contains an update to current rust-mozjs, because that's required for this to work.

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] These changes don't fix a github issue

Either:
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because the changes don't change any observable behavior

Source-Repo: https://github.com/servo/servo
Source-Revision: 5a81470c4db563fce4f84949507b25206b0dbedb
This commit is contained in:
Till Schneidereit 2016-05-26 00:08:42 -05:00
parent 1c5c58f3e6
commit 12e19131ff
7 changed files with 22 additions and 13 deletions

View File

@ -213,7 +213,8 @@ impl DedicatedWorkerGlobalScope {
worker_url: Url,
id: PipelineId,
from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>,
main_thread_rt: Arc<Mutex<Option<SharedRt>>>,
parent_rt: SharedRt,
worker_rt_for_mainthread: Arc<Mutex<Option<SharedRt>>>,
worker: TrustedWorkerAddress,
parent_sender: Box<ScriptChan + Send>,
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
@ -240,8 +241,8 @@ impl DedicatedWorkerGlobalScope {
}
};
let runtime = unsafe { new_rt_and_cx() };
*main_thread_rt.lock().unwrap() = Some(SharedRt::new(&runtime));
let runtime = unsafe { new_rt_and_cx(parent_rt.rt()) };
*worker_rt_for_mainthread.lock().unwrap() = Some(SharedRt::new(&runtime));
let (devtools_mpsc_chan, devtools_mpsc_port) = channel();
ROUTER.route_ipc_receiver_to_mpsc_sender(from_devtools_receiver, devtools_mpsc_chan);

View File

@ -22,7 +22,7 @@ use dom::messageevent::MessageEvent;
use dom::workerglobalscope::WorkerGlobalScopeInit;
use ipc_channel::ipc;
use js::jsapi::{HandleValue, JSContext, JSRuntime, RootedValue};
use js::jsapi::{JSAutoCompartment, JS_RequestInterruptCallback};
use js::jsapi::{JSAutoCompartment, JS_GetRuntime, JS_RequestInterruptCallback};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
@ -91,6 +91,7 @@ impl Worker {
}
// https://html.spec.whatwg.org/multipage/#dom-worker
#[allow(unsafe_code)]
pub fn Constructor(global: GlobalRef, script_url: DOMString) -> Fallible<Root<Worker>> {
// Step 2-4.
let worker_url = match global.api_base_url().join(&script_url) {
@ -145,8 +146,10 @@ impl Worker {
closing: closing,
};
let shared_rt = SharedRt { rt: unsafe { JS_GetRuntime(global.get_cx()) } };
DedicatedWorkerGlobalScope::run_worker_scope(
init, worker_url, global.pipeline(), devtools_receiver, worker.runtime.clone(), worker_ref,
init, worker_url, global.pipeline(), devtools_receiver, shared_rt, worker.runtime.clone(), worker_ref,
global.script_chan(), sender, receiver, worker_load_origin);
Ok(worker)
@ -309,6 +312,10 @@ impl SharedRt {
JS_RequestInterruptCallback(self.rt);
}
}
pub fn rt(&self) -> *mut JSRuntime {
self.rt
}
}
#[allow(unsafe_code)]

View File

@ -95,9 +95,9 @@ impl<'a> Drop for StackRootTLS<'a> {
}
#[allow(unsafe_code)]
pub unsafe fn new_rt_and_cx() -> Runtime {
pub unsafe fn new_rt_and_cx(parent_rt: *mut JSRuntime) -> Runtime {
LiveDOMReferences::initialize();
let runtime = Runtime::new();
let runtime = Runtime::new(parent_rt);
JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_rust_roots), ptr::null_mut());
JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_refcounted_objects), ptr::null_mut());

View File

@ -87,6 +87,7 @@ use std::borrow::ToOwned;
use std::cell::{Cell, RefCell};
use std::collections::HashSet;
use std::option::Option;
use std::ptr;
use std::rc::Rc;
use std::result::Result;
use std::sync::atomic::{Ordering, AtomicBool};
@ -443,8 +444,8 @@ impl ScriptThreadFactory for ScriptThread {
let mem_profiler_chan = state.mem_profiler_chan.clone();
let window_size = state.window_size;
let script_thread = ScriptThread::new(state,
script_port,
script_chan.clone());
script_port,
script_chan.clone());
SCRIPT_THREAD_ROOT.with(|root| {
*root.borrow_mut() = Some(&script_thread as *const _);
@ -519,7 +520,7 @@ impl ScriptThread {
port: Receiver<MainThreadScriptMsg>,
chan: Sender<MainThreadScriptMsg>)
-> ScriptThread {
let runtime = unsafe { new_rt_and_cx() };
let runtime = unsafe { new_rt_and_cx(ptr::null_mut()) };
unsafe {
JS_SetWrapObjectCallbacks(runtime.rt(),

View File

@ -1069,7 +1069,7 @@ dependencies = [
[[package]]
name = "js"
version = "0.1.3"
source = "git+https://github.com/servo/rust-mozjs#3352139c1dedbdff5fe1078152f46522cd04b2f3"
source = "git+https://github.com/servo/rust-mozjs#fae7efd0adf42c0dde517382b83734525e11c6cc"
dependencies = [
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -981,7 +981,7 @@ dependencies = [
[[package]]
name = "js"
version = "0.1.3"
source = "git+https://github.com/servo/rust-mozjs#3352139c1dedbdff5fe1078152f46522cd04b2f3"
source = "git+https://github.com/servo/rust-mozjs#fae7efd0adf42c0dde517382b83734525e11c6cc"
dependencies = [
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -969,7 +969,7 @@ dependencies = [
[[package]]
name = "js"
version = "0.1.3"
source = "git+https://github.com/servo/rust-mozjs#3352139c1dedbdff5fe1078152f46522cd04b2f3"
source = "git+https://github.com/servo/rust-mozjs#fae7efd0adf42c0dde517382b83734525e11c6cc"
dependencies = [
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",