Skip to content

Commit db6d0df

Browse files
authored
Clarify and explain agents and agent clusters
* Explain the agent ↔ thread and agent cluster ↔ process boundary connection. See the most recent example of the editors explaining this to folks in #3766. * Fix misleading note about how agents map to worklets. * Add an example showing that two same-origin, but unrelated, Windows are in different agent clusters. * Tidy up and rearrange some of the introductory material to each section.
1 parent 0ba1d47 commit db6d0df

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

source

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88378,19 +88378,26 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8837888378

8837988379
<h5>Integration with the JavaScript agent formalism</h5>
8838088380

88381-
<p>JavaScript defines the concept of an <span>agent</span>. Until such a time that this standard
88382-
has a better handle on lifetimes, we define five types of <span data-x="agent">agents</span> that
88383-
user agents must allocate at the appropriate time.</p>
88384-
88385-
<p class="note">In the future, when this specification has a better handle on lifetimes, we hope
88386-
to define exactly when <span data-x="agent">agents</span> and <span data-x="agent cluster">agent
88387-
clusters</span> are created.</p>
88381+
<p>JavaScript defines the concept of an <span>agent</span>. This section gives the mapping of that
88382+
language-level concept on to the web platform.</p>
8838888383

8838988384
<p class="&#x0058;&#x0058;&#x0058;">JavaScript is expected to define <span
8839088385
data-x="agent">agents</span> in more detail; in particular that they hold a set of <span
8839188386
data-x="concept-global-object-realm">realms</span>: <a
8839288387
href="https://github.com/tc39/ecma262/issues/882">tc39/ecma262 issue #882</a>.</p>
8839388388

88389+
<p class="note">Conceptually, the <span>agent</span> concept is an architecture-independent,
88390+
idealized "thread" in which JavaScript code runs. Such code can involve multiple globals/<span
88391+
data-x="concept-global-object-realm">realms</span> that can synchronously access each other, and
88392+
thus need to run in a single execution thread.</p>
88393+
88394+
<p>Until such a time that this standard has a better handle on lifetimes, it defines five types of
88395+
<span data-x="agent">agents</span> that user agents must allocate at the appropriate time.</p>
88396+
88397+
<p class="note">In the future, this standard hopes to define exactly when <span
88398+
data-x="agent">agents</span> and <span data-x="agent cluster">agent clusters</span> are
88399+
created.</p>
88400+
8839488401
<dl>
8839588402
<dt><dfn data-export="">Similar-origin window agent</dfn></dt>
8839688403
<dd>
@@ -88427,16 +88434,30 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8842788434
data-x="JavaScript realm">realms</span> consists of a single <code>WorkletGlobalScope</code>
8842888435
object's <span data-x="concept-global-object-realm">Realm</span>.</p>
8842988436

88430-
<p class="note">While conceptually it might be cleaner for worklets that end up with multiple
88431-
realms to put all those in the same agent, it is not observable in practice.</p>
88437+
<p class="note">Although a given worklet can have multiple realms, each such realm needs its own
88438+
agent, as each realm can be executing code independently and at the same time as the others.</p>
8843288439
</dd>
8843388440
</dl>
8843488441

8843588442
<h5>Integration with the JavaScript agent cluster formalism</h5>
8843688443

88437-
<p><dfn>Can share memory with</dfn> defines an equivalence relation. An <span>agent cluster</span>
88438-
consists of all <span data-x="agent">agents</span> in the same equivalence class with respect to
88439-
the <span>can share memory with</span> equivalence relation.</p>
88444+
<p>JavaScript also defines the concept of an <span>agent cluster</span>, which this standard maps
88445+
to the web platform using the <dfn>can share memory with</dfn> equivalence relation detailed
88446+
below. On the web platform, an <span>agent cluster</span> consists of all <span
88447+
data-x="agent">agents</span> in the same equivalence class with respect to the <span>can share
88448+
memory with</span> equivalence relation.</p>
88449+
88450+
<p>The <span>agent cluster</span> concept is crucial for defining the JavaScript memory model, and
88451+
in particular among which <span data-x="agent">agents</span> the backing data of
88452+
<code>SharedArrayBuffer</code> objects can be shared.</p>
88453+
88454+
<p class="note">Conceptually, the <span>agent cluster</span> concept is an
88455+
architecture-independent, idealized "process boundary" that groups together multiple "threads"
88456+
(<span data-x="agent">agents</span>). The <span data-x="agent cluster">agent clusters</span>
88457+
defined by the specification are generally more restrictive than the actual process boundaries
88458+
implemented in user agents. By enforcing these idealized divisions at the specification level, we
88459+
ensure that web developers see interoperable behavior with regard to shared memory, even in the
88460+
face of varying and changing user agent process models.</p>
8844088461

8844188462
<p>A <span>similar-origin window agent</span>, <span>dedicated worker agent</span>, <span>shared
8844288463
worker agent</span>, or <span>service worker agent</span>, <var>agent</var>, <span>can share
@@ -88445,8 +88466,8 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8844588466
set</span> contains an item whose <span data-x="concept-relevant-realm">relevant Realm</span>
8844688467
belongs to <var>agent</var>.</p>
8844788468

88448-
<p class="note">We use item above as an <span>owner set</span> can contain <code>Document</code>
88449-
objects.</p>
88469+
<p class="note">"Item" is used above as an <span>owner set</span> can contain
88470+
<code>Document</code> objects.</p>
8845088471

8845188472
<p class="&#x0058;&#x0058;&#x0058;">A <span>worklet agent</span> &hellip; currently worklets have
8845288473
no clearly defined owner, see: <a
@@ -88466,10 +88487,6 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8846688487
<span>can share memory with</span> <var>B</var>.</li>
8846788488
</ul>
8846888489

88469-
<p>The <span>agent cluster</span> concept is crucial for defining the JavaScript memory model, and
88470-
in particular among which <span data-x="agent">agents</span> the backing data of
88471-
<code>SharedArrayBuffer</code> objects can be shared.</p>
88472-
8847388490
<div class="example">
8847488491
<p>The following pairs of global objects are each within the same <span>agent cluster</span>, and
8847588492
thus can use <code>SharedArrayBuffer</code> instances to share memory with each other:</p>
@@ -88500,6 +88517,11 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8850088517
<li>A <code>Window</code> object <var></var> and the <code>Window</code> object of an
8850188518
<code>iframe</code> element that <var>A</var> created that cannot be <span>same
8850288519
origin-domain</span> with <var>A</var>.</li>
88520+
88521+
<li>Any two <code>Window</code> objects whose <span data-x="browsing context">browsing
88522+
contexts</span> do not have an <span data-x="opener browsing context">opener</span> or <span
88523+
data-x="ancestor browsing context">ancestor</span> relationship. This holds even if the two
88524+
<code>Window</code> objects are <span>same origin</span>.</li>
8850388525
</ul>
8850488526
</div>
8850588527

0 commit comments

Comments
 (0)