diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/public/shadow | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/public/shadow/Function.h | 48 | ||||
-rw-r--r-- | js/public/shadow/Object.h | 67 | ||||
-rw-r--r-- | js/public/shadow/ObjectGroup.h | 33 | ||||
-rw-r--r-- | js/public/shadow/Realm.h | 38 | ||||
-rw-r--r-- | js/public/shadow/Shape.h | 46 | ||||
-rw-r--r-- | js/public/shadow/String.h | 120 | ||||
-rw-r--r-- | js/public/shadow/Symbol.h | 38 | ||||
-rw-r--r-- | js/public/shadow/Zone.h | 97 |
8 files changed, 487 insertions, 0 deletions
diff --git a/js/public/shadow/Function.h b/js/public/shadow/Function.h new file mode 100644 index 0000000000..0b9d4ac214 --- /dev/null +++ b/js/public/shadow/Function.h @@ -0,0 +1,48 @@ +/* -*- 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 + +class JS_PUBLIC_API JSFunction; +class JSJitInfo; + +namespace JS { + +namespace shadow { + +struct Function { + shadow::Object base; + uint16_t nargs; + uint16_t flags; + /* Used only for natives */ + JSNative native; + const JSJitInfo* jitinfo; + void* _1; +}; + +inline Function* AsShadowFunction(JSFunction* fun) { + return reinterpret_cast<Function*>(fun); +} + +inline const Function* AsShadowFunction(const JSFunction* fun) { + return reinterpret_cast<const Function*>(fun); +} + +} // 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..68badf9b2b --- /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 { + +struct ObjectGroup; + +/** + * This layout is shared by all native objects. For non-native objects, the + * group may always be accessed safely, and other members may be as well, + * depending on the object's specific layout. + */ +struct Object { + shadow::ObjectGroup* group; + shadow::Shape* shape; + 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/ObjectGroup.h b/js/public/shadow/ObjectGroup.h new file mode 100644 index 0000000000..f95f60ced1 --- /dev/null +++ b/js/public/shadow/ObjectGroup.h @@ -0,0 +1,33 @@ +/* -*- 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::ObjectGroup| innards. Do not use this directly! */ + +#ifndef js_shadow_ObjectGroup_h +#define js_shadow_ObjectGroup_h + +#include "jstypes.h" // JS_PUBLIC_API + +struct JSClass; +class JS_PUBLIC_API JSObject; + +namespace JS { + +class JS_PUBLIC_API Realm; + +namespace shadow { + +struct ObjectGroup { + const JSClass* clasp; + JSObject* proto; + JS::Realm* realm; +}; + +} // namespace shadow + +} // namespace JS + +#endif // js_shadow_ObjectGroup_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..754f465162 --- /dev/null +++ b/js/public/shadow/Shape.h @@ -0,0 +1,46 @@ +/* -*- 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_; +}; + +class Shape { + public: + shadow::BaseShape* base; + JS::PropertyKey _1; + uint32_t immutableFlags; + + static constexpr uint32_t FIXED_SLOTS_SHIFT = 24; + static constexpr uint32_t FIXED_SLOTS_MASK = 0x1f << FIXED_SLOTS_SHIFT; +}; + +} // 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..a8d9c70dc4 --- /dev/null +++ b/js/public/shadow/Zone.h @@ -0,0 +1,97 @@ +/* -*- 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 <stdint.h> // uint8_t, uint32_t + +#include "jspubtd.h" // js::CurrentThreadCanAccessRuntime + +struct JS_PUBLIC_API JSRuntime; +class JS_PUBLIC_API JSTracer; + +namespace JS { + +namespace shadow { + +struct Zone { + enum GCState : uint8_t { + NoGC, + Prepare, + MarkBlackOnly, + MarkBlackAndGray, + Sweep, + Finished, + Compact + }; + + enum Kind : uint8_t { NormalZone, AtomsZone, SelfHostingZone, SystemZone }; + + protected: + JSRuntime* const runtime_; + JSTracer* const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|. + uint32_t needsIncrementalBarrier_ = 0; + GCState gcState_ = NoGC; + const Kind kind_; + + Zone(JSRuntime* runtime, JSTracer* barrierTracerArg, Kind kind) + : runtime_(runtime), barrierTracer_(barrierTracerArg), kind_(kind) {} + + 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_; } + 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 isGCMarkingBlackOnly() || isGCMarkingBlackAndGray(); + } + bool isGCMarkingOrSweeping() const { + return gcState_ >= MarkBlackOnly && gcState_ <= Sweep; + } + bool isGCSweepingOrCompacting() const { + return gcState_ == Sweep || gcState_ == Compact; + } + + bool isAtomsZone() const { return kind_ == AtomsZone; } + bool isSelfHostingZone() const { return kind_ == SelfHostingZone; } + bool isSystemZone() const { return kind_ == SystemZone; } + + static shadow::Zone* from(JS::Zone* zone) { + return reinterpret_cast<shadow::Zone*>(zone); + } +}; + +} // namespace shadow + +} // namespace JS + +#endif // js_shadow_Zone_h |