Skip to content

Instantly share code, notes, and snippets.

@jdm jdm/try.diff

Created Mar 25, 2016
Embed
What would you like to do?
diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs
index 04466ea..a2ba6bd 100644
--- a/components/script/dom/bindings/reflector.rs
+++ b/components/script/dom/bindings/reflector.rs
@@ -6,17 +6,22 @@
use dom::bindings::global::{GlobalRef, GlobalRoot, global_root_from_reflector};
use dom::bindings::js::Root;
-use js::jsapi::{HandleObject, JSContext, JSObject};
+use heapsize::HeapSizeOf;
+use js::jsapi::{HandleObject, JSContext, JSObject, JS_updateMallocCounter};
use std::cell::UnsafeCell;
use std::ptr;
/// Create the reflector for a new DOM object and yield ownership to the
/// reflector.
-pub fn reflect_dom_object<T: Reflectable>(obj: Box<T>,
- global: GlobalRef,
- wrap_fn: fn(*mut JSContext, GlobalRef, Box<T>) -> Root<T>)
- -> Root<T> {
- wrap_fn(global.get_cx(), global, obj)
+pub fn reflect_dom_object<T>(obj: Box<T>,
+ global: GlobalRef,
+ wrap_fn: fn(*mut JSContext, GlobalRef, Box<T>) -> Root<T>)
+ -> Root<T> where T: Reflectable + HeapSizeOf {
+ let cx = global.get_cx();
+ unsafe {
+ JS_updateMallocCounter(cx, obj.heap_size_of_children());
+ }
+ wrap_fn(cx, global, obj)
}
/// A struct to store a reference to the reflector of a DOM object.
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index fed47bb..e0d2c6b 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -1285,7 +1285,7 @@ pub enum CloneChildrenFlag {
fn as_uintptr<T>(t: &T) -> uintptr_t { t as *const T as uintptr_t }
impl Node {
- pub fn reflect_node<N: DerivedFrom<Node> + Reflectable>
+ pub fn reflect_node<N: DerivedFrom<Node> + Reflectable + HeapSizeOf>
(node: Box<N>,
document: &Document,
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<N>) -> Root<N>)
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 9cfc262..24ce2ef 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -56,7 +56,7 @@ use js::jsapi::{DOMProxyShadowsResult, HandleId, HandleObject, RootedValue};
use js::jsapi::{DisableIncrementalGC, JS_AddExtraGCRootsTracer, JS_SetWrapObjectCallbacks};
use js::jsapi::{GCDescription, GCProgress, JSGCInvocationKind, SetGCSliceCallback};
use js::jsapi::{JSAutoRequest, JSGCStatus, JS_GetRuntime, JS_SetGCCallback, SetDOMCallbacks};
-use js::jsapi::{JSContext, JSRuntime, JSTracer};
+use js::jsapi::{JSContext, JSRuntime, JSTracer, JS_SetGCParameter, JSGCParamKey};
use js::jsapi::{JSObject, SetPreserveWrapperCallback};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
@@ -718,6 +718,31 @@ impl ScriptThread {
unsafe {
JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_rust_roots), ptr::null_mut());
JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_refcounted_objects), ptr::null_mut());
+
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MAX_MALLOC_BYTES,
+ 128 * 1024 * 1024);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT,
+ 1000);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH,
+ 150);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN,
+ 150);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX,
+ 300);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_LOW_LIMIT,
+ 100);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT,
+ 500);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_ALLOCATION_THRESHOLD,
+ 30);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_DECOMMIT_THRESHOLD,
+ 32);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT,
+ 1);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT,
+ 30);
+ JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_COMPACTING_ENABLED,
+ true as u32);
}
// Needed for debug assertions about whether GC is running.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.