Skip to content

Commit

Permalink
[wip] address CRs
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Jan 9, 2025
1 parent ef481b6 commit b47b927
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 146 deletions.
5 changes: 2 additions & 3 deletions src/snmalloc/backend_helpers/buddy.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "../ds/ds.h"
#include "snmalloc/proxy/algorithm.h"

namespace snmalloc
{
Expand All @@ -24,7 +23,7 @@ namespace snmalloc
RBTree<Rep> tree{};
};

proxy::Array<Entry, MAX_SIZE_BITS - MIN_SIZE_BITS> entries{};
stl::Array<Entry, MAX_SIZE_BITS - MIN_SIZE_BITS> entries{};
// All RBtrees at or above this index should be empty.
size_t empty_at_or_above{0};

Expand Down Expand Up @@ -168,7 +167,7 @@ namespace snmalloc
{
if (Rep::equal(Rep::null, addr) || Rep::compare(e, addr))
{
addr = proxy::exchange(e, addr);
addr = stl::exchange(e, addr);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/snmalloc/ds_core/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ namespace snmalloc
}

/**
* Implementation of `proxy::min`
* Implementation of `std::min`
*
* `proxy::min` is in `<algorithm>`, so pulls in a lot of unneccessary code
* `bits::min` is in `<algorithm>`, so pulls in a lot of unneccessary code
* We write our own to reduce the code that potentially needs reviewing.
*/
template<typename T>
Expand All @@ -383,9 +383,9 @@ namespace snmalloc
}

/**
* Implementation of `proxy::max`
* Implementation of `std::max`
*
* `proxy::max` is in `<algorithm>`, so pulls in a lot of unneccessary code
* `bits::max` is in `<algorithm>`, so pulls in a lot of unneccessary code
* We write our own to reduce the code that potentially needs reviewing.
*/
template<typename T>
Expand Down
10 changes: 5 additions & 5 deletions src/snmalloc/ds_core/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace snmalloc
};

static constexpr size_t rlength = bits::next_pow2_const(length);
proxy::Array<TWrap, rlength> array;
stl::Array<TWrap, rlength> array;

public:
constexpr const T& operator[](const size_t i) const
Expand All @@ -65,7 +65,7 @@ namespace snmalloc
};
#else
template<size_t length, typename T>
using ModArray = proxy::Array<T, length>;
using ModArray = stl::Array<T, length>;
#endif

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace snmalloc
/**
* The buffer that is used to store the formatted output.
*/
proxy::Array<char, BufferSize> buffer;
stl::Array<char, BufferSize> buffer;

/**
* Space in the buffer, excluding a trailing null terminator.
Expand Down Expand Up @@ -254,7 +254,7 @@ namespace snmalloc
append_char('-');
s = 0 - s;
}
proxy::Array<char, 20> buf{{0}};
stl::Array<char, 20> buf{{0}};
const char digits[] = "0123456789";
for (long i = static_cast<long>(buf.size() - 1); i >= 0; i--)
{
Expand Down Expand Up @@ -284,7 +284,7 @@ namespace snmalloc
{
append_char('0');
append_char('x');
proxy::Array<char, 16> buf{{0}};
stl::Array<char, 16> buf{{0}};
const char hexdigits[] = "0123456789abcdef";
// Length of string including null terminator
static_assert(sizeof(hexdigits) == 0x11);
Expand Down
42 changes: 16 additions & 26 deletions src/snmalloc/ds_core/redblacktree.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "snmalloc/proxy/array.h"
#include "snmalloc/stl/array.h"

#include <stddef.h>
#include <stdint.h>
Expand All @@ -18,9 +18,9 @@ namespace snmalloc
*/
template<typename Rep>
concept RBRepTypes = requires() {
typename Rep::Handle;
typename Rep::Contents;
};
typename Rep::Handle;
typename Rep::Contents;
};

/**
* The representation must define operations on the holder and contents
Expand All @@ -41,29 +41,17 @@ namespace snmalloc
template<typename Rep>
concept RBRepMethods =
requires(typename Rep::Handle hp, typename Rep::Contents k, bool b) {
{
Rep::get(hp)
} -> ConceptSame<typename Rep::Contents>;
{
Rep::set(hp, k)
} -> ConceptSame<void>;
{
Rep::is_red(k)
} -> ConceptSame<bool>;
{
Rep::set_red(k, b)
} -> ConceptSame<void>;
{
Rep::ref(b, k)
} -> ConceptSame<typename Rep::Handle>;
{
Rep::null
} -> ConceptSameModRef<const typename Rep::Contents>;
{ Rep::get(hp) } -> ConceptSame<typename Rep::Contents>;
{ Rep::set(hp, k) } -> ConceptSame<void>;
{ Rep::is_red(k) } -> ConceptSame<bool>;
{ Rep::set_red(k, b) } -> ConceptSame<void>;
{ Rep::ref(b, k) } -> ConceptSame<typename Rep::Handle>;
{ Rep::null } -> ConceptSameModRef<const typename Rep::Contents>;
{
typename Rep::Handle{const_cast<
stl::remove_const_t<stl::remove_reference_t<decltype(Rep::root)>>*>(
&Rep::root)}
} -> ConceptSame<typename Rep::Handle>;
} -> ConceptSame<typename Rep::Handle>;
};

template<typename Rep>
Expand Down Expand Up @@ -260,7 +248,7 @@ namespace snmalloc
{
friend class RBTree;

proxy::Array<RBStep, 128> path;
stl::Array<RBStep, 128> path;
size_t length = 0;

RBPath(typename Rep::Handle root)
Expand Down Expand Up @@ -496,7 +484,8 @@ namespace snmalloc
*/
path.move(true);
while (path.move(false))
{}
{
}

K curr = path.curr();

Expand Down Expand Up @@ -747,7 +736,8 @@ namespace snmalloc

auto path = get_root_path();
while (path.move(true))
{}
{
}

K result = path.curr();

Expand Down
3 changes: 1 addition & 2 deletions src/snmalloc/global/memcpy.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "bounds_checks.h"
#include "snmalloc/proxy/algorithm.h"

namespace snmalloc
{
Expand Down Expand Up @@ -157,7 +156,7 @@ namespace snmalloc
*/
SNMALLOC_UNUSED_FUNCTION
static constexpr size_t LargestRegisterSize =
proxy::max(sizeof(uint64_t), sizeof(void*));
bits::max(sizeof(uint64_t), sizeof(void*));

/**
* Hook for architecture-specific optimisations.
Expand Down
3 changes: 1 addition & 2 deletions src/snmalloc/mem/corealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "pool.h"
#include "remotecache.h"
#include "sizeclasstable.h"
#include "snmalloc/stl/algorithm.h"
#include "snmalloc/stl/new.h"
#include "ticker.h"

Expand Down Expand Up @@ -223,7 +222,7 @@ namespace snmalloc
pointer_offset(curr, rsize).template as_static<PreAllocObject>())
{
size_t insert_index = entropy.sample(count);
curr->next = proxy::exchange(
curr->next = stl::exchange(
pointer_offset(bumpptr, insert_index * rsize)
.template as_static<PreAllocObject>()
->next,
Expand Down
6 changes: 3 additions & 3 deletions src/snmalloc/mem/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,11 @@ namespace snmalloc
*/

// Pointer to the first element.
proxy::Array<void*, LENGTH> head{nullptr};
stl::Array<void*, LENGTH> head{nullptr};
// Pointer to the reference to the last element.
// In the empty case end[i] == &head[i]
// This enables branch free enqueuing.
proxy::Array<void**, LENGTH> end{nullptr};
stl::Array<void**, LENGTH> end{nullptr};

[[nodiscard]] Object::BQueuePtr<BQueue>* cast_end(uint32_t ix) const
{
Expand All @@ -724,7 +724,7 @@ namespace snmalloc
}

SNMALLOC_NO_UNIQUE_ADDRESS
proxy::Array<uint16_t, RANDOM ? 2 : (TRACK_LENGTH ? 1 : 0)> length{};
stl::Array<uint16_t, RANDOM ? 2 : (TRACK_LENGTH ? 1 : 0)> length{};

public:
constexpr Builder() = default;
Expand Down
6 changes: 3 additions & 3 deletions src/snmalloc/mem/remotecache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace snmalloc
{
static_assert(RINGS > 0);

proxy::Array<freelist::Builder<false, true>, RINGS> open_builder;
proxy::Array<address_t, RINGS> open_meta = {0};
stl::Array<freelist::Builder<false, true>, RINGS> open_builder;
stl::Array<address_t, RINGS> open_meta = {0};

SNMALLOC_FAST_PATH size_t
ring_set(typename Config::PagemapEntry::SlabMetadata* meta)
Expand Down Expand Up @@ -190,7 +190,7 @@ namespace snmalloc
template<typename Config>
struct RemoteDeallocCache
{
proxy::Array<freelist::Builder<false>, REMOTE_SLOTS> list;
stl::Array<freelist::Builder<false>, REMOTE_SLOTS> list;

RemoteDeallocCacheBatchingImpl<Config> batching;

Expand Down
6 changes: 3 additions & 3 deletions src/snmalloc/pal/pal_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#if defined(__linux__)
# include "../ds_core/ds_core.h"
# include "pal_posix.h"
# include "snmalloc/proxy/array.h"
# include "snmalloc/stl/array.h"

# include <string.h>
# include <sys/mman.h>
Expand Down Expand Up @@ -184,8 +184,8 @@ namespace snmalloc
// protected routine.
if (false == syscall_not_working.load(stl::memory_order_relaxed))
{
auto current = proxy::begin(buffer);
auto target = proxy::end(buffer);
auto current = stl::begin(buffer);
auto target = stl::end(buffer);
while (auto length = target - current)
{
// Reading data via syscall from system entropy pool.
Expand Down
4 changes: 2 additions & 2 deletions src/snmalloc/pal/pal_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ namespace snmalloc
auto fd = open("/dev/urandom", flags, 0);
if (fd > 0)
{
auto current = proxy::begin(buffer);
auto target = proxy::end(buffer);
auto current = stl::begin(buffer);
auto target = stl::end(buffer);
while (auto length = static_cast<size_t>(target - current))
{
ret = read(fd, current, length);
Expand Down
9 changes: 9 additions & 0 deletions src/snmalloc/stl/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "snmalloc/stl/common.h"

#if SNMALLOC_USE_SELF_VENDORED_STL
# include "snmalloc/stl/gnu/array.h"
#else
# include "snmalloc/stl/cxx/array.h"
#endif
15 changes: 15 additions & 0 deletions src/snmalloc/stl/cxx/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <array>

namespace snmalloc
{
namespace proxy
{
template<typename T, size_t N>
using Array = std::array<T, N>;

using std::begin;
using std::end;
} // namespace proxy
} // namespace snmalloc
1 change: 1 addition & 0 deletions src/snmalloc/stl/cxx/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace snmalloc
namespace stl
{
using std::declval;
using std::exchange;
using std::forward;
using std::move;
template<class T1, class T2>
Expand Down
53 changes: 0 additions & 53 deletions src/snmalloc/stl/gnu/algorithm.h

This file was deleted.

Loading

0 comments on commit b47b927

Please sign in to comment.