Expand description
The Constellation, Servo’s Grand Central Station
The constellation tracks all information kept globally by the browser engine, which includes:
-
The set of all
EventLoopobjects. Each event loop is the constellation’s view of a script thread. The constellation interacts with a script thread by message-passing. -
The set of all
Pipelineobjects. Each pipeline gives the constellation’s view of aWindow, with its script thread and layout. Pipelines may share script threads. -
The set of all
BrowsingContextobjects. Each browsing context gives the constellation’s view of aWindowProxy. Each browsing context stores an independent session history, created by navigation. The session history can be traversed, for example by the back and forwards UI, so each session history maintains a list of past and future pipelines, as well as the current active pipeline.
There are two kinds of browsing context: top-level ones (for
example tabs in a browser UI), and nested ones (typically caused
by iframe elements). Browsing contexts have a hierarchy
(typically caused by iframes containing iframes), giving rise
to a forest whose roots are top-level browsing context. The logical
relationship between these types is:
+------------+ +------------+ +---------+
| Browsing | ------parent?------> | Pipeline | --event_loop--> | Event |
| Context | ------current------> | | | Loop |
| | ------prev*--------> | | <---pipeline*-- | |
| | ------next*--------> | | +---------+
| | | |
| | <-top_level--------- | |
| | <-browsing_context-- | |
+------------+ +------------+The constellation also maintains channels to other parts of Servo, including:
- The script thread.
- The
Paintsubsystem, which runs in the same thread as theServoinstance. - The font cache, image cache, and resource manager, which load and cache shared fonts, images, or other resources.
- The service worker manager.
- The devtools and webdriver servers.
The constellation passes messages between the threads, and updates its state to track the evolving state of the browsing context tree.
The constellation acts as a logger, tracking any warn! messages from threads,
and converting any error! or panic! into a crash report.
Since there is only one constellation, and its responsibilities include crash reporting, it is very important that it does not panic.
It’s also important that the constellation not deadlock. In particular, we need
to be careful that we don’t introduce any cycles in the can-block-on relation.
Blocking is typically introduced by receiver.recv(), which blocks waiting for the
sender to send some data. Servo tries to achieve deadlock-freedom by using the following
can-block-on relation:
- Constellation can block on
Paint - Constellation can block on embedder
- Script can block on anything (other than script)
- Blocking is transitive (if T1 can block on T2 and T2 can block on T3 then T1 can block on T3)
- Nothing can block on itself!
There is a complexity intoduced by IPC channels, since they do not support
non-blocking send. This means that as well as receiver.recv() blocking,
sender.send(data) can also block when the IPC buffer is full. For this reason it is
very important that all IPC receivers where we depend on non-blocking send
use a router to route IPC messages to an mpsc channel. The reason why that solves
the problem is that under the hood, the router uses a dedicated thread to forward
messages, and:
- Anything (other than a routing thread) can block on a routing thread
Structs§
- Browsing
Context 🔒Group - A browsing context group.
- Constellation
- The
Constellationitself. In the servo browser, there is one constellation, which maintains all of the browser global data. In embedded applications, there may be more than one constellation, which are independent of each other. - Initial
Constellation State - State needed to construct a constellation.
- Message
Port 🔒Info - Info related to a message-port tracked by the constellation.
- Pending
Approval 🔒Navigation - Screenshot
Readiness 🔒Request - WebRenderWGPU 🔒
- WebRender related objects required by WebGPU threads
Enums§
- Exit
Pipeline 🔒Mode - When we are exiting a pipeline, we can either force exiting or not. A normal exit
waits for
Paintto update its state before exiting, and delegates layout exit to script. A forced exit does not notifyPaint, and exits layout without involving script. - Screenshot
Request 🔒State - When a
ScreenshotReadinessRequestis received from the renderer, theConstellationgo through a variety of states to process them. This data structure represents those states. - Transfer
State 🔒 - The state used by MessagePortInfo to represent the various states the port can be in.
Constants§
- WARNINGS_
BUFFER_ 🔒SIZE - The number of warnings to include in each crash report.