Skip to content

Commit

Permalink
LibGC: Rename MarkedVector => RootVector
Browse files Browse the repository at this point in the history
Let's try to make it a bit more clear that this is a Vector of GC roots.
  • Loading branch information
awesomekling committed Dec 26, 2024
1 parent ada36e5 commit 3bfb053
Show file tree
Hide file tree
Showing 117 changed files with 281 additions and 281 deletions.
2 changes: 1 addition & 1 deletion Libraries/LibGC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set(SOURCES
ConservativeVector.cpp
ForeignCell.cpp
Root.cpp
RootVector.cpp
Heap.cpp
HeapBlock.cpp
MarkedVector.cpp
WeakContainer.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibGC/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ template<class T, size_t inline_capacity = 0>
class ConservativeVector;

template<class T, size_t inline_capacity = 0>
class MarkedVector;
class RootVector;

}
4 changes: 2 additions & 2 deletions Libraries/LibGC/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class GraphConstructorVisitor final : public Cell::Visitor {
case HeapRoot::Type::Root:
node.set("root"sv, ByteString::formatted("Root {} {}:{}", location->function_name(), location->filename(), location->line_number()));
break;
case HeapRoot::Type::MarkedVector:
node.set("root"sv, "MarkedVector");
case HeapRoot::Type::RootVector:
node.set("root"sv, "RootVector");
break;
case HeapRoot::Type::RegisterPointer:
node.set("root"sv, "RegisterPointer");
Expand Down
12 changes: 6 additions & 6 deletions Libraries/LibGC/Heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <LibGC/Forward.h>
#include <LibGC/HeapRoot.h>
#include <LibGC/Internals.h>
#include <LibGC/MarkedVector.h>
#include <LibGC/Root.h>
#include <LibGC/RootVector.h>
#include <LibGC/WeakContainer.h>

namespace GC {
Expand Down Expand Up @@ -61,8 +61,8 @@ class Heap : public HeapBase {
void did_create_root(Badge<RootImpl>, RootImpl&);
void did_destroy_root(Badge<RootImpl>, RootImpl&);

void did_create_marked_vector(Badge<MarkedVectorBase>, MarkedVectorBase&);
void did_destroy_marked_vector(Badge<MarkedVectorBase>, MarkedVectorBase&);
void did_create_marked_vector(Badge<RootVectorBase>, RootVectorBase&);
void did_destroy_marked_vector(Badge<RootVectorBase>, RootVectorBase&);

void did_create_conservative_vector(Badge<ConservativeVectorBase>, ConservativeVectorBase&);
void did_destroy_conservative_vector(Badge<ConservativeVectorBase>, ConservativeVectorBase&);
Expand Down Expand Up @@ -139,7 +139,7 @@ class Heap : public HeapBase {
CellAllocator::List m_all_cell_allocators;

RootImpl::List m_roots;
MarkedVectorBase::List m_marked_vectors;
RootVectorBase::List m_marked_vectors;
ConservativeVectorBase::List m_conservative_vectors;
WeakContainer::List m_weak_containers;

Expand All @@ -165,13 +165,13 @@ inline void Heap::did_destroy_root(Badge<RootImpl>, RootImpl& impl)
m_roots.remove(impl);
}

inline void Heap::did_create_marked_vector(Badge<MarkedVectorBase>, MarkedVectorBase& vector)
inline void Heap::did_create_marked_vector(Badge<RootVectorBase>, RootVectorBase& vector)
{
VERIFY(!m_marked_vectors.contains(vector));
m_marked_vectors.append(vector);
}

inline void Heap::did_destroy_marked_vector(Badge<MarkedVectorBase>, MarkedVectorBase& vector)
inline void Heap::did_destroy_marked_vector(Badge<RootVectorBase>, RootVectorBase& vector)
{
VERIFY(m_marked_vectors.contains(vector));
m_marked_vectors.remove(vector);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibGC/HeapRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct HeapRoot {
enum class Type {
HeapFunctionCapturedPointer,
Root,
MarkedVector,
RootVector,
ConservativeVector,
RegisterPointer,
StackPointer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
*/

#include <LibGC/Heap.h>
#include <LibGC/MarkedVector.h>
#include <LibGC/RootVector.h>

namespace GC {

MarkedVectorBase::MarkedVectorBase(Heap& heap)
RootVectorBase::RootVectorBase(Heap& heap)
: m_heap(&heap)
{
m_heap->did_create_marked_vector({}, *this);
}

MarkedVectorBase::~MarkedVectorBase()
RootVectorBase::~RootVectorBase()
{
m_heap->did_destroy_marked_vector({}, *this);
}

MarkedVectorBase& MarkedVectorBase::operator=(MarkedVectorBase const& other)
RootVectorBase& RootVectorBase::operator=(RootVectorBase const& other)
{
if (m_heap != other.m_heap) {
m_heap = other.m_heap;

// NOTE: IntrusiveList will remove this MarkedVectorBase from the old heap it was part of.
// NOTE: IntrusiveList will remove this RootVectorBase from the old heap it was part of.
m_heap->did_create_marked_vector({}, *this);
}

Expand Down
38 changes: 19 additions & 19 deletions Libraries/LibGC/MarkedVector.h → Libraries/LibGC/RootVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@

namespace GC {

class MarkedVectorBase {
class RootVectorBase {
public:
virtual void gather_roots(HashMap<Cell*, GC::HeapRoot>&) const = 0;

protected:
explicit MarkedVectorBase(Heap&);
~MarkedVectorBase();
explicit RootVectorBase(Heap&);
~RootVectorBase();

MarkedVectorBase& operator=(MarkedVectorBase const&);
RootVectorBase& operator=(RootVectorBase const&);

Heap* m_heap { nullptr };
IntrusiveListNode<MarkedVectorBase> m_list_node;
IntrusiveListNode<RootVectorBase> m_list_node;

public:
using List = IntrusiveList<&MarkedVectorBase::m_list_node>;
using List = IntrusiveList<&RootVectorBase::m_list_node>;
};

template<typename T, size_t inline_capacity>
class MarkedVector final
: public MarkedVectorBase
class RootVector final
: public RootVectorBase
, public Vector<T, inline_capacity> {

public:
explicit MarkedVector(Heap& heap)
: MarkedVectorBase(heap)
explicit RootVector(Heap& heap)
: RootVectorBase(heap)
{
}

virtual ~MarkedVector() = default;
virtual ~RootVector() = default;

MarkedVector(MarkedVector const& other)
: MarkedVectorBase(*other.m_heap)
RootVector(RootVector const& other)
: RootVectorBase(*other.m_heap)
, Vector<T, inline_capacity>(other)
{
}

MarkedVector(MarkedVector&& other)
: MarkedVectorBase(*other.m_heap)
RootVector(RootVector&& other)
: RootVectorBase(*other.m_heap)
, Vector<T, inline_capacity>(move(static_cast<Vector<T, inline_capacity>&>(other)))
{
}

MarkedVector& operator=(MarkedVector const& other)
RootVector& operator=(RootVector const& other)
{
Vector<T, inline_capacity>::operator=(other);
MarkedVectorBase::operator=(other);
RootVectorBase::operator=(other);
return *this;
}

Expand All @@ -70,9 +70,9 @@ class MarkedVector final
for (auto& value : *this) {
if constexpr (IsBaseOf<NanBoxedValue, T>) {
if (value.is_cell())
roots.set(&const_cast<T&>(value).as_cell(), HeapRoot { .type = HeapRoot::Type::MarkedVector });
roots.set(&const_cast<T&>(value).as_cell(), HeapRoot { .type = HeapRoot::Type::RootVector });
} else {
roots.set(value, HeapRoot { .type = HeapRoot::Type::MarkedVector });
roots.set(value, HeapRoot { .type = HeapRoot::Type::RootVector });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibIDL/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static size_t get_function_shortest_length(FunctionType& function)
}

enum class SequenceStorageType {
Vector, // Used to safely store non-JS values
MarkedVector, // Used to safely store JS::Value and anything that inherits JS::Cell, e.g. JS::Object
Vector, // Used to safely store non-JS values
RootVector, // Used to safely store JS::Value and anything that inherits JS::Cell, e.g. JS::Object
};

struct CppType {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibJS/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <AK/TemporaryChange.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibGC/ConservativeVector.h>
#include <LibGC/MarkedVector.h>
#include <LibGC/RootVector.h>
#include <LibJS/AST.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Accessor.h>
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibJS/Bytecode/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Generator {
NonnullOwnPtr<StringTable> m_string_table;
NonnullOwnPtr<IdentifierTable> m_identifier_table;
NonnullOwnPtr<RegexTable> m_regex_table;
GC::MarkedVector<Value> m_constants;
GC::RootVector<Value> m_constants;

mutable Optional<ScopedOperand> m_true_constant;
mutable Optional<ScopedOperand> m_false_constant;
Expand Down
6 changes: 3 additions & 3 deletions Libraries/LibJS/Bytecode/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,13 +1458,13 @@ inline Value new_regexp(VM& vm, ParsedRegex const& parsed_regex, ByteString cons
}

// 13.3.8.1 https://tc39.es/ecma262/#sec-runtime-semantics-argumentlistevaluation
inline GC::MarkedVector<Value> argument_list_evaluation(VM& vm, Value arguments)
inline GC::RootVector<Value> argument_list_evaluation(VM& vm, Value arguments)
{
// Note: Any spreading and actual evaluation is handled in preceding opcodes
// Note: The spec uses the concept of a list, while we create a temporary array
// in the preceding opcodes, so we have to convert in a manner that is not
// visible to the user
GC::MarkedVector<Value> argument_values { vm.heap() };
GC::RootVector<Value> argument_values { vm.heap() };

auto& argument_array = arguments.as_array();
auto array_length = argument_array.indexed_properties().array_like_size();
Expand Down Expand Up @@ -1541,7 +1541,7 @@ inline ThrowCompletionOr<GC::Ref<Object>> super_call_with_argument_array(VM& vm,
auto* func = get_super_constructor(vm);

// 4. Let argList be ? ArgumentListEvaluation of Arguments.
GC::MarkedVector<Value> arg_list { vm.heap() };
GC::RootVector<Value> arg_list { vm.heap() };
if (is_synthetic) {
VERIFY(argument_array.is_object() && is<Array>(argument_array.as_object()));
auto const& array_value = static_cast<Array const&>(argument_array.as_object());
Expand Down
Loading

0 comments on commit 3bfb053

Please sign in to comment.