summaryrefslogtreecommitdiffstats
path: root/js/src/jit/JitZone.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit/JitZone.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit/JitZone.h')
-rw-r--r--js/src/jit/JitZone.h208
1 files changed, 208 insertions, 0 deletions
diff --git a/js/src/jit/JitZone.h b/js/src/jit/JitZone.h
new file mode 100644
index 0000000000..7489eca256
--- /dev/null
+++ b/js/src/jit/JitZone.h
@@ -0,0 +1,208 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef jit_JitZone_h
+#define jit_JitZone_h
+
+#include "mozilla/Assertions.h"
+#include "mozilla/HashFunctions.h"
+#include "mozilla/Maybe.h"
+#include "mozilla/MemoryReporting.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <utility>
+
+#include "gc/Barrier.h"
+#include "jit/ExecutableAllocator.h"
+#include "jit/ICStubSpace.h"
+#include "jit/Invalidation.h"
+#include "js/AllocPolicy.h"
+#include "js/GCHashTable.h"
+#include "js/HashTable.h"
+#include "js/TracingAPI.h"
+#include "js/TypeDecls.h"
+#include "js/UniquePtr.h"
+#include "js/Utility.h"
+#include "threading/ProtectedData.h"
+
+namespace JS {
+struct CodeSizes;
+}
+
+namespace js {
+namespace jit {
+
+enum class CacheKind : uint8_t;
+class CacheIRStubInfo;
+class JitCode;
+
+enum class ICStubEngine : uint8_t {
+ // Baseline IC, see BaselineIC.h.
+ Baseline = 0,
+
+ // Ion IC, see IonIC.h.
+ IonIC
+};
+
+struct CacheIRStubKey : public DefaultHasher<CacheIRStubKey> {
+ struct Lookup {
+ CacheKind kind;
+ ICStubEngine engine;
+ const uint8_t* code;
+ uint32_t length;
+
+ Lookup(CacheKind kind, ICStubEngine engine, const uint8_t* code,
+ uint32_t length)
+ : kind(kind), engine(engine), code(code), length(length) {}
+ };
+
+ static HashNumber hash(const Lookup& l);
+ static bool match(const CacheIRStubKey& entry, const Lookup& l);
+
+ UniquePtr<CacheIRStubInfo, JS::FreePolicy> stubInfo;
+
+ explicit CacheIRStubKey(CacheIRStubInfo* info) : stubInfo(info) {}
+ CacheIRStubKey(CacheIRStubKey&& other)
+ : stubInfo(std::move(other.stubInfo)) {}
+
+ void operator=(CacheIRStubKey&& other) {
+ stubInfo = std::move(other.stubInfo);
+ }
+};
+
+struct BaselineCacheIRStubCodeMapGCPolicy {
+ static bool traceWeak(JSTracer* trc, CacheIRStubKey*,
+ WeakHeapPtr<JitCode*>* value) {
+ return TraceWeakEdge(trc, value, "traceWeak");
+ }
+};
+
+class JitZone {
+ // Allocated space for optimized baseline stubs.
+ OptimizedICStubSpace optimizedStubSpace_;
+
+ // Set of CacheIRStubInfo instances used by Ion stubs in this Zone.
+ using IonCacheIRStubInfoSet =
+ HashSet<CacheIRStubKey, CacheIRStubKey, SystemAllocPolicy>;
+ IonCacheIRStubInfoSet ionCacheIRStubInfoSet_;
+
+ // Map CacheIRStubKey to shared JitCode objects.
+ using BaselineCacheIRStubCodeMap =
+ GCHashMap<CacheIRStubKey, WeakHeapPtr<JitCode*>, CacheIRStubKey,
+ SystemAllocPolicy, BaselineCacheIRStubCodeMapGCPolicy>;
+ BaselineCacheIRStubCodeMap baselineCacheIRStubCodes_;
+
+ // Executable allocator for all code except wasm code.
+ MainThreadData<ExecutableAllocator> execAlloc_;
+
+ // HashMap that maps scripts to compilations inlining those scripts.
+ using InlinedScriptMap =
+ GCHashMap<WeakHeapPtr<BaseScript*>, RecompileInfoVector,
+ StableCellHasher<WeakHeapPtr<BaseScript*>>, SystemAllocPolicy>;
+ InlinedScriptMap inlinedCompilations_;
+
+ // The following two fields are a pair of associated scripts. If they are
+ // non-null, the child has been inlined into the parent, and we have bailed
+ // out due to a MonomorphicInlinedStubFolding bailout. If it wasn't
+ // trial-inlined, we need to track for the parent if we attach a new case to
+ // the corresponding folded stub which belongs to the child.
+ WeakHeapPtr<JSScript*> lastStubFoldingBailoutChild_;
+ WeakHeapPtr<JSScript*> lastStubFoldingBailoutParent_;
+
+ mozilla::Maybe<IonCompilationId> currentCompilationId_;
+ bool keepJitScripts_ = false;
+
+ public:
+ ~JitZone() { MOZ_ASSERT(!keepJitScripts_); }
+
+ void traceWeak(JSTracer* trc);
+
+ void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
+ JS::CodeSizes* code, size_t* jitZone,
+ size_t* baselineStubsOptimized) const;
+
+ OptimizedICStubSpace* optimizedStubSpace() { return &optimizedStubSpace_; }
+
+ JitCode* getBaselineCacheIRStubCode(const CacheIRStubKey::Lookup& key,
+ CacheIRStubInfo** stubInfo) {
+ auto p = baselineCacheIRStubCodes_.lookup(key);
+ if (p) {
+ *stubInfo = p->key().stubInfo.get();
+ return p->value();
+ }
+ *stubInfo = nullptr;
+ return nullptr;
+ }
+ [[nodiscard]] bool putBaselineCacheIRStubCode(
+ const CacheIRStubKey::Lookup& lookup, CacheIRStubKey& key,
+ JitCode* stubCode) {
+ auto p = baselineCacheIRStubCodes_.lookupForAdd(lookup);
+ MOZ_ASSERT(!p);
+ return baselineCacheIRStubCodes_.add(p, std::move(key), stubCode);
+ }
+
+ CacheIRStubInfo* getIonCacheIRStubInfo(const CacheIRStubKey::Lookup& key) {
+ IonCacheIRStubInfoSet::Ptr p = ionCacheIRStubInfoSet_.lookup(key);
+ return p ? p->stubInfo.get() : nullptr;
+ }
+ [[nodiscard]] bool putIonCacheIRStubInfo(const CacheIRStubKey::Lookup& lookup,
+ CacheIRStubKey& key) {
+ IonCacheIRStubInfoSet::AddPtr p =
+ ionCacheIRStubInfoSet_.lookupForAdd(lookup);
+ MOZ_ASSERT(!p);
+ return ionCacheIRStubInfoSet_.add(p, std::move(key));
+ }
+ void purgeIonCacheIRStubInfo() { ionCacheIRStubInfoSet_.clearAndCompact(); }
+
+ ExecutableAllocator& execAlloc() { return execAlloc_.ref(); }
+ const ExecutableAllocator& execAlloc() const { return execAlloc_.ref(); }
+
+ [[nodiscard]] bool addInlinedCompilation(const RecompileInfo& info,
+ JSScript* inlined);
+
+ RecompileInfoVector* maybeInlinedCompilations(JSScript* inlined) {
+ auto p = inlinedCompilations_.lookup(inlined);
+ return p ? &p->value() : nullptr;
+ }
+
+ void removeInlinedCompilations(JSScript* inlined) {
+ inlinedCompilations_.remove(inlined);
+ }
+
+ void noteStubFoldingBailout(JSScript* child, JSScript* parent) {
+ lastStubFoldingBailoutChild_ = child;
+ lastStubFoldingBailoutParent_ = parent;
+ }
+ bool hasStubFoldingBailoutData(JSScript* child) const {
+ return lastStubFoldingBailoutChild_ &&
+ lastStubFoldingBailoutChild_.get() == child &&
+ lastStubFoldingBailoutParent_;
+ }
+ JSScript* stubFoldingBailoutParent() const {
+ MOZ_ASSERT(lastStubFoldingBailoutChild_);
+ return lastStubFoldingBailoutParent_.get();
+ }
+ void clearStubFoldingBailoutData() {
+ lastStubFoldingBailoutChild_ = nullptr;
+ lastStubFoldingBailoutParent_ = nullptr;
+ }
+
+ bool keepJitScripts() const { return keepJitScripts_; }
+ void setKeepJitScripts(bool keep) { keepJitScripts_ = keep; }
+
+ mozilla::Maybe<IonCompilationId> currentCompilationId() const {
+ return currentCompilationId_;
+ }
+ mozilla::Maybe<IonCompilationId>& currentCompilationIdRef() {
+ return currentCompilationId_;
+ }
+};
+
+} // namespace jit
+} // namespace js
+
+#endif /* jit_JitZone_h */