
This patch adds two macros to declare per-type allocators: - JS_DECLARE_ALLOCATOR(TypeName) - JS_DEFINE_ALLOCATOR(TypeName) When used, they add a type-specific CellAllocator that the Heap will delegate allocation requests to. The result of this is that GC objects of the same type always end up within the same HeapBlock, drastically reducing the ability to perform type confusion attacks. It also improves HeapBlock utilization, since each block now has cells sized exactly to the type used within that block. (Previously we only had a handful of block sizes available, and most GC allocations ended up with a large amount of slack in their tails.) There is a small performance hit from this, but I'm sure we can make up for it elsewhere. Note that the old size-based allocators still exist, and we fall back to them for any type that doesn't have its own CellAllocator.
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/DeprecatedFlyString.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibJS/Heap/CellAllocator.h>
|
|
|
|
namespace JS {
|
|
|
|
struct PrivateName {
|
|
PrivateName() = default;
|
|
PrivateName(u64 unique_id, DeprecatedFlyString description)
|
|
: unique_id(unique_id)
|
|
, description(move(description))
|
|
{
|
|
}
|
|
|
|
u64 unique_id { 0 };
|
|
DeprecatedFlyString description;
|
|
|
|
bool operator==(PrivateName const& rhs) const;
|
|
};
|
|
|
|
class PrivateEnvironment : public Cell {
|
|
JS_CELL(PrivateEnvironment, Cell);
|
|
JS_DECLARE_ALLOCATOR(PrivateEnvironment);
|
|
|
|
public:
|
|
PrivateName resolve_private_identifier(DeprecatedFlyString const& identifier) const;
|
|
|
|
void add_private_name(Badge<ClassExpression>, DeprecatedFlyString description);
|
|
|
|
private:
|
|
explicit PrivateEnvironment(PrivateEnvironment* parent);
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
auto find_private_name(DeprecatedFlyString const& description) const
|
|
{
|
|
return m_private_names.find_if([&](PrivateName const& private_name) {
|
|
return private_name.description == description;
|
|
});
|
|
}
|
|
|
|
static u64 s_next_id;
|
|
|
|
GCPtr<PrivateEnvironment> m_outer_environment; // [[OuterEnv]]
|
|
Vector<PrivateName> m_private_names; // [[Names]]
|
|
u64 m_unique_id;
|
|
};
|
|
|
|
}
|