Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
do not trace pending parsers
  • Loading branch information
gterzian committed Jun 17, 2020
1 parent 581ade5 commit 558a55c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -42,6 +42,7 @@ use crate::dom::htmlimageelement::SourceSet;
use crate::dom::htmlmediaelement::{HTMLMediaElementFetchContext, MediaFrameRenderer};
use crate::dom::identityhub::Identities;
use crate::script_runtime::StreamConsumer;
use crate::script_thread::IncompleteParserContexts;
use crate::task::TaskBox;
use app_units::Au;
use canvas_traits::canvas::{
Expand Down Expand Up @@ -183,6 +184,8 @@ pub unsafe trait JSTraceable {

unsafe_no_jsmanaged_fields!(Box<dyn TaskBox>, Box<dyn EventLoopWaker>);

unsafe_no_jsmanaged_fields!(IncompleteParserContexts);

unsafe_no_jsmanaged_fields!(MessagePortImpl);
unsafe_no_jsmanaged_fields!(MessagePortId);
unsafe_no_jsmanaged_fields!(MessagePortRouterId);
Expand Down
1 change: 0 additions & 1 deletion components/script/dom/servoparser/mod.rs
Expand Up @@ -689,7 +689,6 @@ impl Tokenizer {

/// The context required for asynchronously fetching a document
/// and parsing it progressively.
#[derive(JSTraceable)]
pub struct ParserContext {
/// The parser that initiated the request.
parser: Option<Trusted<ServoParser>>,
Expand Down
14 changes: 8 additions & 6 deletions components/script/script_thread.rs
Expand Up @@ -500,7 +500,7 @@ impl<'a> Iterator for DocumentsIter<'a> {
// which can trigger GC, and so we can end up tracing the script
// thread during parsing. For this reason, we don't trace the
// incomplete parser contexts during GC.
type IncompleteParserContexts = Vec<(PipelineId, ParserContext)>;
pub struct IncompleteParserContexts(RefCell<Vec<(PipelineId, ParserContext)>>);

unsafe_no_jsmanaged_fields!(TaskQueue<MainThreadScriptMsg>);
unsafe_no_jsmanaged_fields!(dyn BackgroundHangMonitorRegister);
Expand All @@ -518,7 +518,7 @@ pub struct ScriptThread {
/// A list of data pertaining to loads that have not yet received a network response
incomplete_loads: DomRefCell<Vec<InProgressLoad>>,
/// A vector containing parser contexts which have not yet been fully processed
incomplete_parser_contexts: RefCell<IncompleteParserContexts>,
incomplete_parser_contexts: IncompleteParserContexts,
/// Image cache for this script thread.
image_cache: Arc<dyn ImageCache>,
/// A handle to the resource thread. This is an `Arc` to avoid running out of file descriptors if
Expand Down Expand Up @@ -1257,7 +1257,7 @@ impl ScriptThread {
documents: DomRefCell::new(Documents::new()),
window_proxies: DomRefCell::new(HashMap::new()),
incomplete_loads: DomRefCell::new(vec![]),
incomplete_parser_contexts: RefCell::new(vec![]),
incomplete_parser_contexts: IncompleteParserContexts(RefCell::new(vec![])),

image_cache: state.image_cache.clone(),
image_cache_channel: image_cache_channel,
Expand Down Expand Up @@ -3686,6 +3686,7 @@ impl ScriptThread {

let context = ParserContext::new(id, load_data.url);
self.incomplete_parser_contexts
.0
.borrow_mut()
.push((id, context));

Expand All @@ -3712,7 +3713,7 @@ impl ScriptThread {
},
};

let mut incomplete_parser_contexts = self.incomplete_parser_contexts.borrow_mut();
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.0.borrow_mut();
let parser = incomplete_parser_contexts
.iter_mut()
.find(|&&mut (pipeline_id, _)| pipeline_id == id);
Expand All @@ -3722,7 +3723,7 @@ impl ScriptThread {
}

fn handle_fetch_chunk(&self, id: PipelineId, chunk: Vec<u8>) {
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.borrow_mut();
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.0.borrow_mut();
let parser = incomplete_parser_contexts
.iter_mut()
.find(|&&mut (pipeline_id, _)| pipeline_id == id);
Expand All @@ -3734,12 +3735,13 @@ impl ScriptThread {
fn handle_fetch_eof(&self, id: PipelineId, eof: Result<ResourceFetchTiming, NetworkError>) {
let idx = self
.incomplete_parser_contexts
.0
.borrow()
.iter()
.position(|&(pipeline_id, _)| pipeline_id == id);

if let Some(idx) = idx {
let (_, mut ctxt) = self.incomplete_parser_contexts.borrow_mut().remove(idx);
let (_, mut ctxt) = self.incomplete_parser_contexts.0.borrow_mut().remove(idx);
ctxt.process_response_eof(eof);
}
}
Expand Down

0 comments on commit 558a55c

Please sign in to comment.