← All issues

JSC realm-less objects infrastructure

7d45839

Source/JavaScriptCore/runtime/JSObject.h

+ JSGlobalObject* realmMayBeNull() const;
+ JSGlobalObject* realm() const;
- JSGlobalObject* globalObject() const;

JSC에서 모든 JSObjectStructure는 해당 객체가 생성된 JSGlobalObject(realm)를 가리키는 포인터를 보유합니다. 이로 인해 type identity가 realm identity와 긴밀하게 결합됩니다. 예를 들어 RTT가 동일하더라도 realm이 다른 두 Wasm GC struct는 별도의 Structure가 필요했습니다. 결과적으로 StructureID 기반 type check가 불가능했고, 각 객체는 빠른 비교를 위해 중복된 RTT 포인터를 별도로 보유해야 했습니다. Wasm GC spec은 이러한 객체가 property와 prototype을 갖지 않도록 규정합니다. realm을 연결하는 방식은 spec 의도에 어긋날 뿐 아니라 객체 크기도 불필요하게 늘립니다.

이 commit은 Wasm GC 타입에 한해 StructureJSGlobalObject의 결합을 끊습니다. 코드베이스 전반(~300개 이상의 파일)에서 Structure::globalObject() / JSObject::globalObject()realm()으로 변경했습니다. null을 허용해야 하는 호출 지점에는 realmMayBeNull()이 추가되었으며, realm()에는 RELEASE_ASSERT가 삽입되어 realm이 없는 객체에서 실수로 호출하면 즉시 crash가 발생합니다. 이제 Wasm GC struct와 array는 realm 포인터를 보유하지 않습니다.

Before:
  WasmGC struct (Realm A)        WasmGC struct (Realm B)
  [holds RTT* for type check]    [holds RTT* for type check]
       │                               │
  Structure_A (realm=A)          Structure_B (realm=B)

After (this patch):
  WasmGC struct (any realm)      WasmGC struct (any realm)
       │                               │
       └──────► Structure_X (realm=nullptr) ◄──────┘

이 commit은 Wasm GC 객체 크기를 줄이기 위한 기반을 마련합니다. Structure를 realm-less로 만들고 VM 전체에 Structure-to-RTT 1:1 불변성을 확립하는 것이 핵심이며, 실제 RTT 포인터 제거와 StructureID 기반 type check 최적화는 후속 patch에서 진행될 예정입니다. nullable-realm 불변성 변경은 LLInt부터 FTL/B3까지 JSC의 모든 계층과 WebCore binding layer 전체에 걸쳐 영향을 미칩니다.

🔒

New nullable-realm invariant touches hundreds of call sites across JIT, DOM bindings, and IC paths — audit directions included.

더 확인하려면 구독해 주세요