From 3c8680f273760d88ef15ae6c1cece94539753337 Mon Sep 17 00:00:00 2001 From: Sean Joseph Date: Thu, 26 Nov 2020 10:43:30 -0500 Subject: [PATCH 1/3] Add back code to identify JSObjects that should be counted in memory profiling --- components/script/init.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/script/init.rs b/components/script/init.rs index 823f045fad4..53d91fbdc66 100644 --- a/components/script/init.rs +++ b/components/script/init.rs @@ -3,8 +3,10 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::dom::bindings::codegen::RegisterBindings; +use crate::dom::bindings::conversions::is_dom_proxy; use crate::dom::bindings::proxyhandler; use crate::script_runtime::JSEngineSetup; +use js::jsapi::JSObject; #[cfg(target_os = "linux")] #[allow(unsafe_code)] @@ -49,6 +51,11 @@ fn perform_platform_specific_initialization() { #[cfg(not(target_os = "linux"))] fn perform_platform_specific_initialization() {} +#[allow(unsafe_code)] +unsafe extern "C" fn is_dom_object(obj: *mut JSObject) -> bool { + !obj.is_null() && is_dom_proxy(obj) +} + #[allow(unsafe_code)] pub fn init() -> JSEngineSetup { unsafe { @@ -57,6 +64,8 @@ pub fn init() -> JSEngineSetup { // Create the global vtables used by the (generated) DOM // bindings to implement JS proxies. RegisterBindings::RegisterProxyHandlers(); + + js::glue::InitializeMemoryReporter(Some(is_dom_object)); } perform_platform_specific_initialization(); From 823cca30d65f58eaa80085ff2e40e99ba7bcb8ba Mon Sep 17 00:00:00 2001 From: Sean Joseph Date: Thu, 26 Nov 2020 18:30:52 -0500 Subject: [PATCH 2/3] Added is_platform_obj_static --- .../dom/bindings/codegen/CodegenRust.py | 3 ++- components/script/dom/bindings/utils.rs | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 13c295ef1a2..7d2cfcdd31e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -6182,7 +6182,8 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'crate::dom::bindings::utils::get_property_on_prototype', 'crate::dom::bindings::utils::get_proto_or_iface_array', 'crate::dom::bindings::utils::has_property_on_prototype', - 'crate::dom::bindings::utils::is_platform_object', + 'crate::dom::bindings::utils::is_platform_object_dynamic', + 'crate::dom::bindings::utils::is_platform_object_static', 'crate::dom::bindings::utils::resolve_global', 'crate::dom::bindings::utils::set_dictionary_property', 'crate::dom::bindings::utils::trace_global', diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index be513aa0244..8ca51c2189d 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -19,7 +19,7 @@ use crate::script_runtime::JSContext as SafeJSContext; use js::conversions::{jsstr_to_string, ToJSValConvertible}; use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper}; use js::glue::{GetCrossCompartmentWrapper, JS_GetReservedSlot, WrapperNew}; -use js::glue::{UnwrapObjectDynamic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING}; +use js::glue::{UnwrapObjectDynamic, UnwrapObjectStatic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING}; use js::glue::{ RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID, }; @@ -251,9 +251,24 @@ pub unsafe fn find_enum_value<'a, T>( )) } -/// Returns wether `obj` is a platform object +/// Returns wether `obj` is a platform object using dynamic unwrap /// -pub fn is_platform_object(obj: *mut JSObject, cx: *mut JSContext) -> bool { +pub fn is_platform_object_dynamic(obj: *mut JSObject, cx: *mut JSContext) -> bool { + is_platform_object(obj, &|o| unsafe { + UnwrapObjectDynamic(o, cx, /* stopAtWindowProxy = */ 0) + }) +} + +/// Returns wether `obj` is a platform object using static unwrap +/// +pub fn is_platform_object_static(obj: *mut JSObject) -> bool { + is_platform_object(obj, &|o| unsafe { UnwrapObjectStatic(o) }) +} + +fn is_platform_object( + obj: *mut JSObject, + unwrap_obj: &dyn Fn(*mut JSObject) -> *mut JSObject, +) -> bool { unsafe { // Fast-path the common case let mut clasp = get_object_class(obj); @@ -262,7 +277,7 @@ pub fn is_platform_object(obj: *mut JSObject, cx: *mut JSContext) -> bool { } // Now for simplicity check for security wrappers before anything else if IsWrapper(obj) { - let unwrapped_obj = UnwrapObjectDynamic(obj, cx, /* stopAtWindowProxy = */ 0); + let unwrapped_obj = unwrap_obj(obj); if unwrapped_obj.is_null() { return false; } From 9e22804983ab7506f35929e88e59741b7dfb7973 Mon Sep 17 00:00:00 2001 From: Sean Joseph Date: Thu, 26 Nov 2020 18:40:41 -0500 Subject: [PATCH 3/3] Added is_platform_object_static check to is_dom_object --- components/script/init.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/script/init.rs b/components/script/init.rs index 53d91fbdc66..8fd59592f01 100644 --- a/components/script/init.rs +++ b/components/script/init.rs @@ -5,6 +5,7 @@ use crate::dom::bindings::codegen::RegisterBindings; use crate::dom::bindings::conversions::is_dom_proxy; use crate::dom::bindings::proxyhandler; +use crate::dom::bindings::utils::is_platform_object_static; use crate::script_runtime::JSEngineSetup; use js::jsapi::JSObject; @@ -53,7 +54,7 @@ fn perform_platform_specific_initialization() {} #[allow(unsafe_code)] unsafe extern "C" fn is_dom_object(obj: *mut JSObject) -> bool { - !obj.is_null() && is_dom_proxy(obj) + !obj.is_null() && (is_platform_object_static(obj) || is_dom_proxy(obj)) } #[allow(unsafe_code)]