/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Base class for JS engine allocation policies. This provides default // implementations of some methods that may be overridden. // // See mfbt/AllocPolicy.h for more details about allocation policies. class AllocPolicyBase { public: // Report allocation overflow. The default behaviour is to ignore it. void reportAllocOverflow() const {}
// Used to trigger OOMs deterministically during testing. The default // behaviour is to support this feature. bool checkSimulatedOOM() const { return !js::oom::ShouldFailWithOOM(); }
// For allocation policies that support allocating GCed memory, update // information about their owning GC thing. For policies that use malloc, this // is a no-op. void updateOwningGCThing(gc::Cell* maybeOwner) {}
// For allocation policies that support allocating GCed memory, trace an // allocation. For policies that use malloc, this is a no-op. template <typename T> void traceOwnedAlloc(JSTracer* trc, T** ptrp, constchar* name) {}
// For memory reporting, get the size of an allocation made with this policy. // The parameter |mallocSizeOf| is only used for policies that use malloc.
size_t getAllocSize(void* ptr, mozilla::MallocSizeOf mallocSizeOf) { return mallocSizeOf(ptr);
}
};
// Trace all owned allocations used by a container by calling the alloc // policy's traceOwnedAlloc method for each on them, and update alloc policy // information about the owning GC thing. // // Requires the following methods on the container: // - allocPolicy -- gets the AllocPolicy // - traceOwnedAllocs -- calls the passed closure on all allocations template <typename Container> void TraceOwnedAllocs(JSTracer* trc, gc::Cell* maybeOwner, Container& container, constchar* name) { auto& allocPolicy = container.allocPolicy();
allocPolicy.updateOwningGCThing(maybeOwner);
container.traceOwnedAllocs(
[&](auto** ptrp) { allocPolicy.traceOwnedAlloc(trc, ptrp, name); });
}
// For containers implementing |traceOwnedAllocs| get the total size of owned // allocations. template <typename Container>
size_t SizeOfOwnedAllocs(Container& container,
mozilla::MallocSizeOf mallocSizeOf) {
size_t size = 0; auto& allocPolicy = container.allocPolicy();
container.traceOwnedAllocs([&](auto** ptrp) {
size += allocPolicy.getAllocSize(*ptrp, mallocSizeOf);
}); return size;
}
// An out of memory condition which is easily user generatable and should // be specially handled to try and avoid a tab crash.
MOZ_COLD JS_PUBLIC_API void ReportLargeOutOfMemory(JSContext* cx);
/* *Allocationpolicythatcallsthesystemmemoryfunctionsandreportserrors *tothecontext.SincetheJSContextgivenonconstructionisstoredfor *thelifetimeofthecontainer,thispolicymayonlybeusedforcontainers *whoselifetimeisashorterthanthegivenJSContext. * *FIXMEbug647103-rewritethisintermsoftemporaryallocationfunctions, *notthesystemones.
*/ class JS_PUBLIC_API TempAllocPolicy : public MallocAllocPolicyBase { // Type tag for context_bits_ static constexpr uintptr_t JsContextTag = 0x1;
// Either a JSContext* (if JsContextTag is set), or FrontendContext*
uintptr_t const context_bits_;
bool checkSimulatedOOM() const { if (js::oom::ShouldFailWithOOM()) { if (hasJSContext()) {
ReportOutOfMemory(cx());
} else {
ReportOutOfMemory(fc());
} returnfalse;
}
returntrue;
}
};
/* *Areplacementformozilla::MallocAllocPolicythatallocatesintheJSheap *andaddsnoextrabehaviours. * *Thisiscurrentlyusedforallocatingsourcebuffersforparsing.Sincethese *aretemporaryandwillnotbefreedbyGC,thememoryisnottrackedbythe *usualaccounting.
*/ class MallocAllocPolicy : public MallocAllocPolicyBase { public: // Simulated OOM is not supported.
[[nodiscard]] bool checkSimulatedOOM() const { returntrue; }
};
} /* namespace js */
class MOZ_EMPTY_BASES JSInfallibleAllocPolicy : public js::AllocPolicyBase, public ::InfallibleAllocPolicy { public: using ::InfallibleAllocPolicy::reportAllocOverflow; // Simulated OOM is not supported. using ::InfallibleAllocPolicy::checkSimulatedOOM;
};
#endif/* js_AllocPolicy_h */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-08-22)
¤
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.