mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make debug logging for tracing JS objects more informative.
This commit is contained in:
parent
835f443865
commit
293d465c59
6 changed files with 22 additions and 5 deletions
|
@ -38,6 +38,7 @@ use script_thread::STACK_ROOTS;
|
|||
use std::cell::UnsafeCell;
|
||||
use std::default::Default;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::intrinsics::type_name;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::ptr;
|
||||
|
@ -106,7 +107,16 @@ impl<T: Reflectable> Deref for JS<T> {
|
|||
|
||||
impl<T: Reflectable> JSTraceable for JS<T> {
|
||||
fn trace(&self, trc: *mut JSTracer) {
|
||||
trace_reflector(trc, "", unsafe { (**self.ptr).reflector() });
|
||||
#[cfg(debug_assertions)]
|
||||
let trace_str = format!("for {} on heap", unsafe { type_name::<T>() });
|
||||
#[cfg(debug_assertions)]
|
||||
let trace_info = &trace_str[..];
|
||||
#[cfg(not(debug_assertions))]
|
||||
let trace_info = "for DOM object on heap";
|
||||
|
||||
trace_reflector(trc,
|
||||
trace_info,
|
||||
unsafe { (**self.ptr).reflector() });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,11 +530,12 @@ impl RootCollection {
|
|||
|
||||
/// SM Callback that traces the rooted reflectors
|
||||
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
||||
debug!("tracing stack roots");
|
||||
STACK_ROOTS.with(|ref collection| {
|
||||
let RootCollectionPtr(collection) = collection.get().unwrap();
|
||||
let collection = &*(*collection).roots.get();
|
||||
for root in collection {
|
||||
trace_reflector(tracer, "reflector", &**root);
|
||||
trace_reflector(tracer, "on stack", &**root);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -201,13 +201,14 @@ impl LiveDOMReferences {
|
|||
/// A JSTraceDataOp for tracing reflectors held in LIVE_REFERENCES
|
||||
pub unsafe extern "C" fn trace_refcounted_objects(tracer: *mut JSTracer,
|
||||
_data: *mut os::raw::c_void) {
|
||||
debug!("tracing live refcounted references");
|
||||
LIVE_REFERENCES.with(|ref r| {
|
||||
let r = r.borrow();
|
||||
let live_references = r.as_ref().unwrap();
|
||||
let table = live_references.table.borrow();
|
||||
for obj in table.keys() {
|
||||
let reflectable = &*(*obj as *const Reflector);
|
||||
trace_reflector(tracer, "LIVE_REFERENCES", reflectable);
|
||||
trace_reflector(tracer, "refcounted", reflectable);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -171,14 +171,14 @@ impl JSTraceable for Heap<*mut JSObject> {
|
|||
if self.get().is_null() {
|
||||
return;
|
||||
}
|
||||
trace_object(trc, "object", self);
|
||||
trace_object(trc, "heap object", self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl JSTraceable for Heap<JSVal> {
|
||||
fn trace(&self, trc: *mut JSTracer) {
|
||||
trace_jsval(trc, "val", self);
|
||||
trace_jsval(trc, "heap value", self);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -552,6 +552,7 @@ impl<A: JSTraceable + Reflectable> FromIterator<Root<A>> for RootedVec<JS<A>> {
|
|||
|
||||
/// SM Callback that traces the rooted traceables
|
||||
pub unsafe fn trace_traceables(tracer: *mut JSTracer) {
|
||||
debug!("tracing stack-rooted traceables");
|
||||
ROOTED_TRACEABLES.with(|ref traceables| {
|
||||
let traceables = traceables.borrow();
|
||||
traceables.trace(tracer);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#![feature(peekable_is_empty)]
|
||||
#![feature(plugin)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![allow(non_snake_case)]
|
||||
|
|
|
@ -371,7 +371,9 @@ unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus,
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern fn trace_rust_roots(tr: *mut JSTracer, _data: *mut os::raw::c_void) {
|
||||
debug!("starting custom root handler");
|
||||
trace_thread(tr);
|
||||
trace_traceables(tr);
|
||||
trace_roots(tr);
|
||||
debug!("done custom root handler");
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ thread_local!(static SCRIPT_THREAD_ROOT: RefCell<Option<*const ScriptThread>> =
|
|||
pub unsafe fn trace_thread(tr: *mut JSTracer) {
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
if let Some(script_thread) = *root.borrow() {
|
||||
debug!("tracing fields of ScriptThread");
|
||||
(*script_thread).trace(tr);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue