summaryrefslogtreecommitdiffstats
path: root/js/public/shadow
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/public/shadow
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/public/shadow')
-rw-r--r--js/public/shadow/Function.h51
-rw-r--r--js/public/shadow/Object.h67
-rw-r--r--js/public/shadow/Realm.h38
-rw-r--r--js/public/shadow/Shape.h65
-rw-r--r--js/public/shadow/String.h120
-rw-r--r--js/public/shadow/Symbol.h38
-rw-r--r--js/public/shadow/Zone.h126
7 files changed, 505 insertions, 0 deletions
diff --git a/js/public/shadow/Function.h b/js/public/shadow/Function.h
new file mode 100644
index 0000000000..a2c4dcec67
--- /dev/null
+++ b/js/public/shadow/Function.h
@@ -0,0 +1,51 @@
+/* -*- 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/. */
+
+/* Shadow definition of |JSFunction| innards. Do not use this directly! */
+
+#ifndef js_shadow_Function_h
+#define js_shadow_Function_h
+
+#include <stdint.h> // uint16_t
+
+#include "jstypes.h" // JS_PUBLIC_API
+
+#include "js/CallArgs.h" // JSNative
+#include "js/shadow/Object.h" // JS::shadow::Object
+#include "js/Value.h" // JS::Value
+
+class JS_PUBLIC_API JSFunction;
+class JSJitInfo;
+
+namespace JS {
+
+namespace shadow {
+
+struct Function : shadow::Object {
+ enum {
+ FlagsAndArgCountSlot,
+ NativeFuncOrInterpretedEnvSlot,
+ NativeJitInfoOrInterpretedScriptSlot,
+ AtomSlot
+ };
+ uint32_t flagsAndArgCount() const {
+ return fixedSlots()[FlagsAndArgCountSlot].toPrivateUint32();
+ }
+
+ void* jitInfoOrScript() const {
+ return fixedSlots()[NativeJitInfoOrInterpretedScriptSlot].toPrivate();
+ }
+
+ void setJitInfoOrScript(void* ptr) {
+ fixedSlots()[NativeJitInfoOrInterpretedScriptSlot] = JS::PrivateValue(ptr);
+ }
+};
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_Function_h
diff --git a/js/public/shadow/Object.h b/js/public/shadow/Object.h
new file mode 100644
index 0000000000..6f77de71ba
--- /dev/null
+++ b/js/public/shadow/Object.h
@@ -0,0 +1,67 @@
+/* -*- 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/. */
+
+/*
+ * Shadow definition of |JSObject| innards. (|js::NativeObject| is more
+ * accurate, but portions can sometimes be used in some non-native objects.) Do
+ * not use this directly!
+ */
+
+#ifndef js_shadow_Object_h
+#define js_shadow_Object_h
+
+#include <stddef.h> // size_t
+
+#include "js/shadow/Shape.h" // JS::shadow::Shape
+#include "js/Value.h" // JS::Value
+
+class JS_PUBLIC_API JSObject;
+
+namespace JS {
+
+class JS_PUBLIC_API Value;
+
+namespace shadow {
+
+/**
+ * This layout is shared by all native objects. For non-native objects, the
+ * shape may always be accessed safely, and other members may be as well,
+ * depending on the object's specific layout.
+ */
+struct Object {
+ shadow::Shape* shape;
+#ifndef JS_64BIT
+ uint32_t padding_;
+#endif
+ Value* slots;
+ void* _1;
+
+ static constexpr size_t MAX_FIXED_SLOTS = 16;
+
+ size_t numFixedSlots() const {
+ return (shape->immutableFlags & shadow::Shape::FIXED_SLOTS_MASK) >>
+ shadow::Shape::FIXED_SLOTS_SHIFT;
+ }
+
+ Value* fixedSlots() const {
+ auto address = reinterpret_cast<uintptr_t>(this);
+ return reinterpret_cast<JS::Value*>(address + sizeof(shadow::Object));
+ }
+
+ Value& slotRef(size_t slot) const {
+ size_t nfixed = numFixedSlots();
+ if (slot < nfixed) {
+ return fixedSlots()[slot];
+ }
+ return slots[slot - nfixed];
+ }
+};
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_Object_h
diff --git a/js/public/shadow/Realm.h b/js/public/shadow/Realm.h
new file mode 100644
index 0000000000..e3243d3483
--- /dev/null
+++ b/js/public/shadow/Realm.h
@@ -0,0 +1,38 @@
+/* -*- 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/. */
+
+/* Shadow definition of |JS::Realm| innards. Do not use this directly! */
+
+#ifndef js_shadow_Realm_h
+#define js_shadow_Realm_h
+
+#include "jstypes.h" // JS_PUBLIC_API
+
+namespace JS {
+
+class JS_PUBLIC_API Compartment;
+class JS_PUBLIC_API Realm;
+
+namespace shadow {
+
+class Realm {
+ protected:
+ JS::Compartment* compartment_;
+
+ explicit Realm(JS::Compartment* comp) : compartment_(comp) {}
+
+ public:
+ JS::Compartment* compartment() { return compartment_; }
+ static shadow::Realm* get(JS::Realm* realm) {
+ return reinterpret_cast<shadow::Realm*>(realm);
+ }
+};
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_Realm_h
diff --git a/js/public/shadow/Shape.h b/js/public/shadow/Shape.h
new file mode 100644
index 0000000000..c83d320bf2
--- /dev/null
+++ b/js/public/shadow/Shape.h
@@ -0,0 +1,65 @@
+/* -*- 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/. */
+
+/*
+ * Shadow definition of |js::BaseShape| and |js::Shape| innards. Do not use
+ * this directly!
+ */
+
+#ifndef js_shadow_Shape_h
+#define js_shadow_Shape_h
+
+#include <stdint.h> // uint32_t
+
+#include "jstypes.h" // JS_PUBLIC_API
+
+#include "js/Id.h" // JS::PropertyKey
+
+struct JSClass;
+class JS_PUBLIC_API JSObject;
+
+namespace JS {
+
+namespace shadow {
+
+struct BaseShape {
+ const JSClass* clasp;
+ JS::Realm* realm;
+};
+
+class Shape {
+ public:
+ shadow::BaseShape* base;
+ uint32_t immutableFlags;
+
+ enum class Kind : uint8_t {
+ // SharedShape or DictionaryShape for NativeObject.
+ // (Only) these two kinds must have the low bit set, to allow for fast
+ // is-native checking.
+ Shared = 1,
+ Dictionary = 3,
+ // ProxyShape for ProxyObject.
+ Proxy = 0,
+ // WasmGCShape for WasmGCObject.
+ WasmGC = 2,
+ };
+
+ static constexpr uint32_t KIND_SHIFT = 4;
+ static constexpr uint32_t KIND_MASK = 0b11;
+
+ static constexpr uint32_t FIXED_SLOTS_SHIFT = 6;
+ static constexpr uint32_t FIXED_SLOTS_MASK = 0x1f << FIXED_SLOTS_SHIFT;
+
+ bool isProxy() const {
+ return Kind((immutableFlags >> KIND_SHIFT) & KIND_MASK) == Kind::Proxy;
+ }
+};
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_Shape_h
diff --git a/js/public/shadow/String.h b/js/public/shadow/String.h
new file mode 100644
index 0000000000..570c9f189b
--- /dev/null
+++ b/js/public/shadow/String.h
@@ -0,0 +1,120 @@
+/* -*- 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/. */
+
+/* Shadow definition of |JSString| innards. Don't use this directly! */
+
+#ifndef js_shadow_String_h
+#define js_shadow_String_h
+
+#include <stdint.h> // uint32_t, uintptr_t
+
+#include "jstypes.h" // JS_PUBLIC_API, js::Bit, js::BitMask, JS_BITS_PER_WORD
+
+#include "js/TypeDecls.h" // JS::Latin1Char
+
+class JS_PUBLIC_API JSAtom;
+struct JSExternalStringCallbacks;
+class JSLinearString;
+class JS_PUBLIC_API JSString;
+
+namespace js {
+namespace gc {
+struct Cell;
+} // namespace gc
+} // namespace js
+
+namespace JS {
+
+namespace shadow {
+
+struct String {
+ static constexpr uint32_t ATOM_BIT = js::Bit(3);
+ static constexpr uint32_t LINEAR_BIT = js::Bit(4);
+ static constexpr uint32_t INLINE_CHARS_BIT = js::Bit(6);
+ static constexpr uint32_t LATIN1_CHARS_BIT = js::Bit(9);
+ static constexpr uint32_t EXTERNAL_FLAGS = LINEAR_BIT | js::Bit(8);
+ static constexpr uint32_t TYPE_FLAGS_MASK = js::BitMask(9) - js::BitMask(3);
+ static constexpr uint32_t PERMANENT_ATOM_MASK = ATOM_BIT | js::Bit(8);
+
+ uintptr_t flags_;
+#if JS_BITS_PER_WORD == 32
+ uint32_t length_;
+#endif
+
+ union {
+ const JS::Latin1Char* nonInlineCharsLatin1;
+ const char16_t* nonInlineCharsTwoByte;
+ JS::Latin1Char inlineStorageLatin1[1];
+ char16_t inlineStorageTwoByte[1];
+ };
+ const JSExternalStringCallbacks* externalCallbacks;
+
+ uint32_t flags() const { return static_cast<uint32_t>(flags_); }
+ uint32_t length() const {
+#if JS_BITS_PER_WORD == 32
+ return length_;
+#else
+ return static_cast<uint32_t>(flags_ >> 32);
+#endif
+ }
+
+ static bool isPermanentAtom(const js::gc::Cell* cell) {
+ uint32_t flags = reinterpret_cast<const String*>(cell)->flags();
+ return (flags & PERMANENT_ATOM_MASK) == PERMANENT_ATOM_MASK;
+ }
+
+ bool isLinear() const { return flags() & LINEAR_BIT; }
+ bool hasLatin1Chars() const { return flags() & LATIN1_CHARS_BIT; }
+
+ // For hot code, prefer other type queries.
+ bool isExternal() const {
+ return (flags() & TYPE_FLAGS_MASK) == EXTERNAL_FLAGS;
+ }
+
+ const JS::Latin1Char* latin1LinearChars() const {
+ MOZ_ASSERT(isLinear());
+ MOZ_ASSERT(hasLatin1Chars());
+ return (flags() & String::INLINE_CHARS_BIT) ? inlineStorageLatin1
+ : nonInlineCharsLatin1;
+ }
+
+ const char16_t* twoByteLinearChars() const {
+ MOZ_ASSERT(isLinear());
+ MOZ_ASSERT(!hasLatin1Chars());
+ return (flags() & String::INLINE_CHARS_BIT) ? inlineStorageTwoByte
+ : nonInlineCharsTwoByte;
+ }
+};
+
+inline const String* AsShadowString(const JSString* str) {
+ return reinterpret_cast<const String*>(str);
+}
+
+inline String* AsShadowString(JSString* str) {
+ return reinterpret_cast<String*>(str);
+}
+
+inline const String* AsShadowString(const JSLinearString* str) {
+ return reinterpret_cast<const String*>(str);
+}
+
+inline String* AsShadowString(JSLinearString* str) {
+ return reinterpret_cast<String*>(str);
+}
+
+inline const String* AsShadowString(const JSAtom* str) {
+ return reinterpret_cast<const String*>(str);
+}
+
+inline String* AsShadowString(JSAtom* str) {
+ return reinterpret_cast<String*>(str);
+}
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_String_h
diff --git a/js/public/shadow/Symbol.h b/js/public/shadow/Symbol.h
new file mode 100644
index 0000000000..a4b40139cc
--- /dev/null
+++ b/js/public/shadow/Symbol.h
@@ -0,0 +1,38 @@
+/* -*- 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/. */
+
+/* Shadow definition of |JS::Symbol| innards. Do not use this directly! */
+
+#ifndef js_shadow_Symbol_h
+#define js_shadow_Symbol_h
+
+#include <stdint.h> // uint32_t
+
+namespace js {
+namespace gc {
+struct Cell;
+} // namespace gc
+} // namespace js
+
+namespace JS {
+
+namespace shadow {
+
+struct Symbol {
+ void* _1;
+ uint32_t code_;
+ static constexpr uint32_t WellKnownAPILimit = 0x80000000;
+
+ static bool isWellKnownSymbol(const js::gc::Cell* cell) {
+ return reinterpret_cast<const Symbol*>(cell)->code_ < WellKnownAPILimit;
+ }
+};
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_Symbol_h
diff --git a/js/public/shadow/Zone.h b/js/public/shadow/Zone.h
new file mode 100644
index 0000000000..02cd57a14b
--- /dev/null
+++ b/js/public/shadow/Zone.h
@@ -0,0 +1,126 @@
+/* -*- 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/. */
+
+/* Shadow definition of |JS::Zone| innards. Do not use this directly! */
+
+#ifndef js_shadow_Zone_h
+#define js_shadow_Zone_h
+
+#include "mozilla/Assertions.h" // MOZ_ASSERT
+#include "mozilla/Atomics.h"
+
+#include <stdint.h> // uint8_t, uint32_t
+
+#include "jspubtd.h" // js::CurrentThreadCanAccessRuntime
+#include "jstypes.h" // js::Bit
+
+struct JS_PUBLIC_API JSRuntime;
+class JS_PUBLIC_API JSTracer;
+
+namespace JS {
+
+namespace shadow {
+
+struct Zone {
+ enum GCState : uint32_t {
+ NoGC = 0,
+ Prepare,
+ MarkBlackOnly,
+ MarkBlackAndGray,
+ Sweep,
+ Finished,
+ Compact,
+ VerifyPreBarriers,
+
+ Limit
+ };
+
+ using BarrierState = mozilla::Atomic<uint32_t, mozilla::Relaxed>;
+
+ enum Kind : uint8_t { NormalZone, AtomsZone, SystemZone };
+
+ protected:
+ JSRuntime* const runtime_;
+ JSTracer* const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|.
+ BarrierState needsIncrementalBarrier_;
+ GCState gcState_ = NoGC;
+ const Kind kind_;
+
+ Zone(JSRuntime* runtime, JSTracer* barrierTracerArg, Kind kind)
+ : runtime_(runtime), barrierTracer_(barrierTracerArg), kind_(kind) {
+ MOZ_ASSERT(!needsIncrementalBarrier());
+ }
+
+ public:
+ bool needsIncrementalBarrier() const { return needsIncrementalBarrier_; }
+
+ JSTracer* barrierTracer() {
+ MOZ_ASSERT(needsIncrementalBarrier_);
+ MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
+ return barrierTracer_;
+ }
+
+ JSRuntime* runtimeFromMainThread() const {
+ MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
+ return runtime_;
+ }
+
+ // Note: Unrestricted access to the zone's runtime from an arbitrary
+ // thread can easily lead to races. Use this method very carefully.
+ JSRuntime* runtimeFromAnyThread() const { return runtime_; }
+
+ GCState gcState() const { return GCState(uint32_t(gcState_)); }
+
+ static constexpr uint32_t gcStateMask(GCState state) {
+ static_assert(uint32_t(Limit) < 32);
+ return js::Bit(state);
+ }
+
+ bool hasAnyGCState(uint32_t stateMask) const {
+ return js::Bit(gcState_) & stateMask;
+ }
+
+ bool wasGCStarted() const { return gcState() != NoGC; }
+ bool isGCPreparing() const { return gcState() == Prepare; }
+ bool isGCMarkingBlackOnly() const { return gcState() == MarkBlackOnly; }
+ bool isGCMarkingBlackAndGray() const { return gcState() == MarkBlackAndGray; }
+ bool isGCSweeping() const { return gcState() == Sweep; }
+ bool isGCFinished() const { return gcState() == Finished; }
+ bool isGCCompacting() const { return gcState() == Compact; }
+ bool isGCMarking() const {
+ return hasAnyGCState(gcStateMask(MarkBlackOnly) |
+ gcStateMask(MarkBlackAndGray));
+ }
+ bool isGCMarkingOrSweeping() const {
+ return hasAnyGCState(gcStateMask(MarkBlackOnly) |
+ gcStateMask(MarkBlackAndGray) | gcStateMask(Sweep));
+ }
+ bool isGCMarkingOrVerifyingPreBarriers() const {
+ return hasAnyGCState(gcStateMask(MarkBlackOnly) |
+ gcStateMask(MarkBlackAndGray) |
+ gcStateMask(VerifyPreBarriers));
+ }
+ bool isGCSweepingOrCompacting() const {
+ return hasAnyGCState(gcStateMask(Sweep) | gcStateMask(Compact));
+ }
+ bool isVerifyingPreBarriers() const { return gcState() == VerifyPreBarriers; }
+
+ bool isAtomsZone() const { return kind_ == AtomsZone; }
+ bool isSystemZone() const { return kind_ == SystemZone; }
+
+ static shadow::Zone* from(JS::Zone* zone) {
+ return reinterpret_cast<shadow::Zone*>(zone);
+ }
+ static const shadow::Zone* from(const JS::Zone* zone) {
+ return reinterpret_cast<const shadow::Zone*>(zone);
+ }
+};
+
+} // namespace shadow
+
+} // namespace JS
+
+#endif // js_shadow_Zone_h