#include"gc/Barrier.h" #include"js/shadow/Zone.h"// for BarrierState #include"js/Stack.h"// JS::NativeStackLimit #include"js/TypeDecls.h" #include"vm/SharedMem.h" #include"wasm/WasmExprType.h"// for ResultType #include"wasm/WasmLog.h"// for PrintCallback #include"wasm/WasmModuleTypes.h" #include"wasm/WasmShareable.h"// for SeenSet #include"wasm/WasmTypeDecls.h" #include"wasm/WasmValue.h"
namespace js {
class SharedArrayRawBuffer; class WasmBreakpointSite;
class WasmGcObject; class WasmStructObject; class WasmArrayObject;
struct AllocationMetadataBuilder;
namespace gc { class StoreBuffer;
} // namespace gc
// Instance represents a wasm instance and provides all the support for runtime // execution of code in the instance. Instances share various immutable data // structures with the Module from which they were instantiated and other // instances instantiated from the same Module. However, an Instance has no // direct reference to its source Module which allows a Module to be destroyed // while it still has live Instances. // // The instance's code may be shared among multiple instances. // // An Instance is also known as a 'TlsData'. They used to be separate objects, // but have now been unified. Extant references to 'TlsData' will be cleaned // up over time. class alignas(16) Instance { // NOTE: The first fields of Instance are reserved for commonly accessed data // from the JIT, such that they have as small an offset as possible. See the // next note for the end of this region.
// Pointer to the base of memory 0 (or null if there is no memories). This is // always in sync with the MemoryInstanceData for memory 0.
uint8_t* memory0Base_;
// Bounds check limit in bytes for memory 0. If there is no memory 0, this // value will be zero. // // This is 64 bits on 64-bit systems so as to allow for heap lengths up to and // beyond 4GB, and 32 bits on 32-bit systems, where memories are limited to // 2GB. // // See "Linear memory addresses and bounds checking" in WasmMemory.cpp.
uintptr_t memory0BoundsCheckLimit_;
// Null or a pointer to a per-module builtin stub that will invoke the Debug // Trap Handler. void* debugStub_;
// The containing JS::Realm.
JS::Realm* realm_;
// The containing JSContext.
JSContext* cx_;
// The pending exception that was found during stack unwinding after a throw. // // - Only non-null while unwinding the control stack from a wasm-exit stub. // until the nearest enclosing Wasm try-catch or try-delegate block. // - Set by wasm::HandleThrow, unset by Instance::consumePendingException. // - If the unwind target is a `try-delegate`, it is unset by the delegated // try-catch block or function body block.
GCPtr<AnyRef> pendingException_; // The tag object of the pending exception.
GCPtr<AnyRef> pendingExceptionTag_;
// Set to 1 when wasm should call CheckForInterrupt.
mozilla::Atomic<uint32_t, mozilla::Relaxed> interrupt_;
// The address of the realm()->zone()->needsMarkingBarrier(). This is // specific to this instance and not a process wide field, and so it cannot // be linked into code. const JS::shadow::Zone::BarrierState* addressOfNeedsMarkingBarrier_;
// An array of AllocSites allocated for Wasm GC operations such as struct.new, // array.new, etc.
js::gc::AllocSite* allocSites_;
public: // NOTE: All fields commonly accessed by the JIT must be above this method, // and this method adapted for the last field present. This method is used // to assert that we can use compact offsets on x86(-64) for these fields. // We cannot have the assertion here, due to C++ 'offsetof' rules. static constexpr size_t offsetOfLastCommonJitField() { return offsetof(Instance, allocSites_);
}
// The number of baseline scratch storage words available. static constexpr size_t N_BASELINE_SCRATCH_WORDS = 8;
// The size and offset of baselineScratchWords_. static constexpr size_t sizeofBaselineScratchWords() { returnsizeof(baselineScratchWords_);
} static constexpr size_t offsetofBaselineScratchWords() { return offsetof(Instance, baselineScratchWords_);
}
private: // When compiling with tiering, the jumpTable has one entry for each // baseline-compiled function. void** jumpTable_;
// 8 words of scratch storage for the baseline compiler, which can't always // use the stack for this.
uintptr_t baselineScratchWords_[N_BASELINE_SCRATCH_WORDS];
// The class_ of WasmValueBox, this is a per-process value. We could patch // this into code, but the only use-sites are register restricted and cannot // easily use a symbolic address. const JSClass* valueBoxClass_;
// Address of the JitRuntime's exception handler trampoline void* jsJitExceptionHandler_;
// Address of the JitRuntime's object prebarrier trampoline void* preBarrierCode_;
// Address of the store buffer for this instance
gc::StoreBuffer* storeBuffer_;
// Weak pointer to WasmInstanceObject that owns this instance
WeakHeapPtr<WasmInstanceObject*> object_;
// The wasm::Code for this instance const SharedCode code_;
// The tables for this instance, if any const SharedTableVector tables_;
// Passive data segments for use with bulk memory instructions
DataSegmentVector passiveDataSegments_;
// Passive elem segments for use with tables
InstanceElemSegmentVector passiveElemSegments_;
// The wasm::DebugState for this instance, if any const UniqueDebugState maybeDebug_;
// If debugging, this is a per-funcIndex bit table denoting whether debugging // is currently enabled for the function within the instance. The flag is set // if any breakpoint or function entry or exit point needs to be visited. It // is OK to conservatively set this flag, but there is very significant // overhead to taking a breakpoint trap, so managing it precisely is // worthwhile.
uint32_t* debugFilter_;
// A pointer to an array of metrics for all the call_ref's in this instance. // This is only used with lazy tiering for collecting speculative inlining // information.
CallRefMetrics* callRefMetrics_;
// The exclusive maximum index of a global that has been initialized so far.
uint32_t maxInitializedGlobalsIndexPlus1_;
// Pointer that should be freed (due to padding before the Instance). void* allocatedBase_;
// Fields from the JS context for memory allocation, stashed on the instance // so it can be accessed from JIT code efficiently. constvoid* addressOfNurseryPosition_; #ifdef JS_GC_ZEAL constvoid* addressOfGCZealModeBits_; #endif const js::AllocationMetadataBuilder* allocationMetadataBuilder_;
// A copy of the runtime's addressOfLastBufferedWholeCell, used for whole-cell // store buffer entries. constvoid* addressOfLastBufferedWholeCell_;
// Pointer to a per-module builtin stub that will request tier-up for the // wasm function that calls it. void* requestTierUpStub_ = nullptr;
// Pointer to a per-module builtin stub that does the OOL component of a // call-ref metrics update. void* updateCallRefMetricsStub_ = nullptr;
// The data must be the last field. Globals for the module start here // and are inline in this structure. 16-byte alignment is required for SIMD // data.
alignas(16) char data_;
// Trace any GC roots on the stack, for the frame associated with |wfi|, // whose next instruction to execute is |nextPC|. // // For consistency checking of StackMap sizes in debug builds, this also // takes |highestByteVisitedInPrevFrame|, which is the address of the // highest byte scanned in the frame below this one on the stack, and in // turn it returns the address of the highest byte scanned in this frame. // // The method does not assert RootMarkingPhase since it can be used to trace // suspended stacks.
uintptr_t traceFrame(JSTracer* trc, const wasm::WasmFrameIter& wfi,
uint8_t* nextPC,
uintptr_t highestByteVisitedInPrevFrame); void updateFrameForMovingGC(const wasm::WasmFrameIter& wfi, uint8_t* nextPC,
Nursery& nursery);
// This method returns a pointer to the GC object that owns this Instance. // Instances may be reached via weak edges (e.g., Realm::instances_) // so this perform a read-barrier on the returned object unless the barrier // is explicitly waived.
// Called to apply a single ElemSegment at a given offset, assuming // that all bounds validation has already been performed.
[[nodiscard]] bool initElems(JSContext* cx, uint32_t tableIndex, const ModuleElemSegment& seg,
uint32_t dstOffset);
// Iterates through elements of a ModuleElemSegment containing functions. // Unlike iterElemsAnyrefs, this method can get function data (instance and // code pointers) without creating intermediate JSFunctions. // // NOTE: This method only works for element segments that use the index // encoding. If the expression encoding is used, you must use // iterElemsAnyrefs. // // Signature for onFunc: // // (uint32_t index, void* code, Instance* instance) -> bool // template <typename F>
[[nodiscard]] bool iterElemsFunctions(const ModuleElemSegment& seg, const F& onFunc);
// Iterates through elements of a ModuleElemSegment. This method works for any // type of wasm ref and both element segment encodings. As required by AnyRef, // any functions will be wrapped in JSFunction - if possible, you should use // iterElemsFunctions to avoid this. // // Signature for onAnyRef: // // (uint32_t index, AnyRef ref) -> bool // template <typename F>
[[nodiscard]] bool iterElemsAnyrefs(JSContext* cx, const ModuleElemSegment& seg, const F& onAnyRef);
// Report an error to `cx` and mark it as a 'trap' so that it cannot be caught // by wasm exception handlers. void ReportTrapError(JSContext* cx, unsigned errorNumber);
// Mark an already reported error as a 'trap' so that it cannot be caught by // wasm exception handlers. void MarkPendingExceptionAsTrap(JSContext* cx);
// Instance is not a GC thing itself but contains GC thing pointers. Ensure they // are traced appropriately. void TraceInstanceEdge(JSTracer* trc, Instance* instance, constchar* name);
} // namespace wasm
} // namespace js
#endif// wasm_instance_h
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-09-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.