Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass new method in CollectServoSizes to get size of ObjectPrivateVisitor #20430

Merged
merged 1 commit into from Mar 28, 2018

Conversation

@aeweston98
Copy link
Contributor

aeweston98 commented Mar 26, 2018

These changes are the servo changes to allow the measurement of DOM objects with the ObjectPrivateVisitor API. Two new functions have been added MemoryReporter and get_size, which are passed as function pointers to two updated mozjs functions. Currently these changes rely on a branch version of mozjs, which has an open pull request.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #7084 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Mar 26, 2018

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @nox (or someone else) soon.

@highfive
Copy link

highfive commented Mar 26, 2018

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/lib.rs, components/script/Cargo.toml, components/script/script_thread.rs, components/script/script_runtime.rs
  • @fitzgen: components/script/lib.rs, components/script/Cargo.toml, components/script/script_thread.rs, components/script/script_runtime.rs
  • @KiChjang: components/script/lib.rs, components/script/Cargo.toml, components/script/script_thread.rs, components/script/script_runtime.rs
@highfive
Copy link

highfive commented Mar 26, 2018

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
Copy link
Member

jdm left a comment

Please squash these commits as well.

@@ -199,6 +202,21 @@ pub fn init_service_workers(sw_senders: SWManagerSenders) {
ServiceWorkerManager::spawn_manager(sw_senders);
}

#[no_mangle]
#[allow(unsafe_code)]
pub unsafe extern "C" fn MemoryReporter(obj: *mut JSObject) -> bool {

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

Let's call this is_dom_object.

if obj.is_null() {
return false;
}
if is_platform_object(obj) || is_dom_proxy(obj) {

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

This can be simplified to:

pub unsafe extern "C" fn MemoryReporter(obj: *mut JSObject) -> bool {
    !obj.is_null() && (is_platform_object(obj) || is_dom_proxy(obj))
}
@@ -207,6 +225,8 @@ pub fn init() {
// Create the global vtables used by the (generated) DOM
// bindings to implement JS proxies.
RegisterBindings::RegisterProxyHandlers();

js::glue::InitializeMemoryReporter(serde::export::Some(MemoryReporter));

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

There should be no need for serde::export:: here.

#[no_mangle]
#[allow(unsafe_code)]
pub unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize {
let dom_class_opt = get_dom_class(obj);

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

This function looks like it's over-indented by 4 spaces.

pub unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize {
let dom_class_opt = get_dom_class(obj);

match dom_class_opt {

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

We should be able to do match get_dom_class(obj) {.


match dom_class_opt {
Ok(v) => {
let pass_ptr = private_from_object(obj) as *const c_void;

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

Let's call this dom_object.

match dom_class_opt {
Ok(v) => {
let pass_ptr = private_from_object(obj) as *const c_void;
if !(pass_ptr.is_null()) {

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

Let's write this as:

if dom_object.is_null() {
    return 0;
}
let mut ops = ...;
let pass_ptr = private_from_object(obj) as *const c_void;
if !(pass_ptr.is_null()) {
let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None);
let _result = (v.malloc_size_of)(&mut ops, pass_ptr);

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

We can return this directly instead of storing it in a local variable.

#[allow(unsafe_code)]
pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec<Report> {
let mut reports = vec![];

unsafe {
let rt = JS_GetRuntime(cx);
let mut stats = ::std::mem::zeroed();
if CollectServoSizes(rt, &mut stats) {
if CollectServoSizes(rt, &mut stats, serde::export::Some(get_size)) {

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

We should be able to remove the serde::export::.

// malloc_enclosing_size_of function.
let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None);

for (_, document) in self.documents.borrow().iter() {

This comment has been minimized.

@jdm

jdm Mar 26, 2018

Member

Let's keep the code that modifies path_seg.

@jdm
Copy link
Member

jdm commented Mar 26, 2018

I'm excited to see these changes almost ready!

@jdm jdm assigned jdm and unassigned nox Mar 26, 2018
@aeweston98 aeweston98 force-pushed the aeweston98:aew-issue7084 branch from c55908c to 4d64a7d Mar 27, 2018
@aeweston98
Copy link
Contributor Author

aeweston98 commented Mar 27, 2018

@jdm I rebased from the latest changes in master, updated according to your comments and squashed the commits. I saw one flag in the change view of cargo.toml which says no newline at end of file, is this something I need to change?

@jdm
Copy link
Member

jdm commented Mar 27, 2018

No, that should be fine.

@@ -312,14 +315,33 @@ pub unsafe fn new_rt_and_cx() -> Runtime {
Runtime(runtime)
}

#[no_mangle]
#[allow(unsafe_code)]
pub unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize {

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

nit: no need for pub.

@@ -1581,30 +1579,11 @@ impl ScriptThread {

fn collect_reports(&self, reports_chan: ReportsChan) {
let mut path_seg = String::from("url(");
let mut dom_tree_size = 0;
let mut reports = vec![];

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

This is unused now.

This comment has been minimized.

@aeweston98

aeweston98 Mar 27, 2018

Author Contributor

I am interpreting this to mean that since we don't add any dom-tree entries to the reports vector anymore we can use the return of get_reports directly. ie. reports_chan.send(get_reports(self.get_cx(), path_seg)); Is that what you meant?

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

Oh, my mistake. I was skimming the changes and didn't look closely enough. You can ignore this comment.

dom_tree_size += malloc_size_of_including_self(&mut ops, document.window());

if reports.len() > 0 {
path_seg.push_str(", ");

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

We're missing the joining , now. Let's do the following instead of this loop:

let documents = self.documents.borrow();
let urls = itertools::join(documents.values().map(|d| d.url().as_str()), ", ")
let path_seg = format!("url({})", urls);

(you'll need to add an extern crate itertools to script/lib.rs and add itertools to script/Cargo.toml, too)

This comment has been minimized.

@aeweston98

aeweston98 Mar 27, 2018

Author Contributor

This change results in a compilation error no method named values found for type std::cell::Ref<'_, script_thread::Documents>. I looked at the impl for Documents, but was not able to fix the problem. I will continue working on it tomorrow.

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

Oh, I made the wrong assumption about the type of self.documents. You can use documents.iter().map(|(_, d)| d.url().as_str()) instead.

This comment has been minimized.

@aeweston98

aeweston98 Mar 27, 2018

Author Contributor

When I put this in as is, it results in a compilation error on d.url() borrowed value does not live long enough (see attached screenshot for details). I think this is caused by as_str() returning a &str. I replaced as_str() with to_string() and it compiled and I tested it and the colon separated list of urls shows up. Please let me know if that change is ok.

screen shot 2018-03-27 at 6 28 10 pm

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

Looks good to me!

@@ -200,6 +202,12 @@ pub fn init_service_workers(sw_senders: SWManagerSenders) {
ServiceWorkerManager::spawn_manager(sw_senders);
}

#[no_mangle]
#[allow(unsafe_code)]
pub unsafe extern "C" fn is_dom_object(obj: *mut JSObject) -> bool {

This comment has been minimized.

@jdm

jdm Mar 27, 2018

Member

nit: no need for pub.

@jdm
Copy link
Member

jdm commented Mar 28, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Mar 28, 2018

📌 Commit 60dfd66 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Mar 28, 2018

Testing commit 60dfd66 with merge 4efeda6...

bors-servo added a commit that referenced this pull request Mar 28, 2018
Pass new method in CollectServoSizes to get size of ObjectPrivateVisitor

<!-- Please describe your changes on the following line: -->
These changes are the servo changes to allow the measurement of DOM objects with the ObjectPrivateVisitor API. Two new functions have been added MemoryReporter and get_size, which are passed as function pointers to two updated mozjs functions. Currently these changes rely on a branch version of mozjs, which has an [open pull request](servo/rust-mozjs#409).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7084 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20430)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 28, 2018

💔 Test failed - linux-dev

@aeweston98 aeweston98 force-pushed the aeweston98:aew-issue7084 branch from 60dfd66 to 093ee24 Mar 28, 2018
@aeweston98 aeweston98 force-pushed the aeweston98:aew-issue7084 branch from 093ee24 to 7f7fc91 Mar 28, 2018
@aeweston98
Copy link
Contributor Author

aeweston98 commented Mar 28, 2018

@jdm It was the lack of EOF in Cargo.toml which caused test-tidy to fail, fixed now. Also updated to latest changes in master.

@jdm
Copy link
Member

jdm commented Mar 28, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Mar 28, 2018

📌 Commit 7f7fc91 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Mar 28, 2018

Testing commit 7f7fc91 with merge 339146a...

bors-servo added a commit that referenced this pull request Mar 28, 2018
Pass new method in CollectServoSizes to get size of ObjectPrivateVisitor

<!-- Please describe your changes on the following line: -->
These changes are the servo changes to allow the measurement of DOM objects with the ObjectPrivateVisitor API. Two new functions have been added MemoryReporter and get_size, which are passed as function pointers to two updated mozjs functions. Currently these changes rely on a branch version of mozjs, which has an [open pull request](servo/rust-mozjs#409).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7084 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20430)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 28, 2018

@bors-servo bors-servo mentioned this pull request Mar 28, 2018
4 of 5 tasks complete
@bors-servo bors-servo merged commit 7f7fc91 into servo:master Mar 28, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
This was referenced Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.