[proxy](4/n) use customised placement-new (#719)
* [proxy](4/n) use customized placement-new * fix
This commit is contained in:
committed by
GitHub
parent
046c5ac766
commit
d1c65c2852
@@ -6,6 +6,7 @@
|
|||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "remotecache.h"
|
#include "remotecache.h"
|
||||||
#include "sizeclasstable.h"
|
#include "sizeclasstable.h"
|
||||||
|
#include "snmalloc/stl/new.h"
|
||||||
#include "ticker.h"
|
#include "ticker.h"
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
@@ -1128,7 +1129,8 @@ namespace snmalloc
|
|||||||
capptr::Alloc<void> spare_start = pointer_offset(raw, round_sizeof);
|
capptr::Alloc<void> spare_start = pointer_offset(raw, round_sizeof);
|
||||||
Range<capptr::bounds::Alloc> r{spare_start, spare};
|
Range<capptr::bounds::Alloc> r{spare_start, spare};
|
||||||
|
|
||||||
auto p = capptr::Alloc<CA>::unsafe_from(new (raw.unsafe_ptr()) CA(r));
|
auto p = capptr::Alloc<CA>::unsafe_from(
|
||||||
|
new (raw.unsafe_ptr(), placement_token) CA(r));
|
||||||
|
|
||||||
// Remove excess from the bounds.
|
// Remove excess from the bounds.
|
||||||
p = Aal::capptr_bound<CA, capptr::bounds::Alloc>(p, round_sizeof);
|
p = Aal::capptr_bound<CA, capptr::bounds::Alloc>(p, round_sizeof);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "../ds/ds.h"
|
#include "../ds/ds.h"
|
||||||
#include "entropy.h"
|
#include "entropy.h"
|
||||||
|
#include "snmalloc/stl/new.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -265,7 +266,7 @@ namespace snmalloc
|
|||||||
static BHeadPtr<BView, BQueue> make(CapPtr<void, BView> p)
|
static BHeadPtr<BView, BQueue> make(CapPtr<void, BView> p)
|
||||||
{
|
{
|
||||||
return CapPtr<Object::T<BQueue>, BView>::unsafe_from(
|
return CapPtr<Object::T<BQueue>, BView>::unsafe_from(
|
||||||
new (p.unsafe_ptr()) Object::T());
|
new (p.unsafe_ptr(), placement_token) Object::T());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "../ds/ds.h"
|
#include "../ds/ds.h"
|
||||||
#include "freelist.h"
|
#include "freelist.h"
|
||||||
#include "sizeclasstable.h"
|
#include "sizeclasstable.h"
|
||||||
|
#include "snmalloc/stl/new.h"
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
@@ -466,7 +467,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
large_ = false;
|
large_ = false;
|
||||||
|
|
||||||
new (&client_meta_)
|
new (&client_meta_, placement_token)
|
||||||
typename ClientMeta::StorageType[get_client_storage_count(sizeclass)];
|
typename ClientMeta::StorageType[get_client_storage_count(sizeclass)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +487,7 @@ namespace snmalloc
|
|||||||
// Jump to slow path on first deallocation.
|
// Jump to slow path on first deallocation.
|
||||||
needed() = 1;
|
needed() = 1;
|
||||||
|
|
||||||
new (&client_meta_) typename ClientMeta::StorageType();
|
new (&client_meta_, placement_token) typename ClientMeta::StorageType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
#include "../ds/ds.h"
|
#include "../ds/ds.h"
|
||||||
#include "pooled.h"
|
#include "pooled.h"
|
||||||
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "freelist_queue.h"
|
#include "freelist_queue.h"
|
||||||
|
#include "snmalloc/stl/new.h"
|
||||||
#include <new>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
@@ -43,7 +42,7 @@ namespace snmalloc
|
|||||||
static auto emplace_in_alloc(capptr::Alloc<void> alloc)
|
static auto emplace_in_alloc(capptr::Alloc<void> alloc)
|
||||||
{
|
{
|
||||||
return CapPtr<BatchedRemoteMessage, capptr::bounds::Alloc>::unsafe_from(
|
return CapPtr<BatchedRemoteMessage, capptr::bounds::Alloc>::unsafe_from(
|
||||||
new (alloc.unsafe_ptr()) BatchedRemoteMessage());
|
new (alloc.unsafe_ptr(), placement_token) BatchedRemoteMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto mk_from_freelist_builder(
|
static auto mk_from_freelist_builder(
|
||||||
@@ -67,7 +66,7 @@ namespace snmalloc
|
|||||||
auto last_prev = last->prev;
|
auto last_prev = last->prev;
|
||||||
auto self =
|
auto self =
|
||||||
CapPtr<BatchedRemoteMessage, capptr::bounds::Alloc>::unsafe_from(
|
CapPtr<BatchedRemoteMessage, capptr::bounds::Alloc>::unsafe_from(
|
||||||
new (last.unsafe_ptr()) BatchedRemoteMessage());
|
new (last.unsafe_ptr(), placement_token) BatchedRemoteMessage());
|
||||||
self->free_ring.prev = last_prev;
|
self->free_ring.prev = last_prev;
|
||||||
|
|
||||||
// XXX On CHERI, we could do a fair bit better if we had a primitive for
|
// XXX On CHERI, we could do a fair bit better if we had a primitive for
|
||||||
@@ -222,7 +221,7 @@ namespace snmalloc
|
|||||||
static auto emplace_in_alloc(capptr::Alloc<void> alloc)
|
static auto emplace_in_alloc(capptr::Alloc<void> alloc)
|
||||||
{
|
{
|
||||||
return CapPtr<SingletonRemoteMessage, capptr::bounds::Alloc>::unsafe_from(
|
return CapPtr<SingletonRemoteMessage, capptr::bounds::Alloc>::unsafe_from(
|
||||||
new (alloc.unsafe_ptr()) SingletonRemoteMessage());
|
new (alloc.unsafe_ptr(), placement_token) SingletonRemoteMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
static freelist::HeadPtr
|
static freelist::HeadPtr
|
||||||
|
|||||||
35
src/snmalloc/stl/new.h
Normal file
35
src/snmalloc/stl/new.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "snmalloc/ds_core/defines.h"
|
||||||
|
|
||||||
|
namespace snmalloc
|
||||||
|
{
|
||||||
|
|
||||||
|
// This is used in both vendored and non-vendored mode.
|
||||||
|
struct PlacementToken
|
||||||
|
{};
|
||||||
|
|
||||||
|
inline constexpr PlacementToken placement_token{};
|
||||||
|
} // namespace snmalloc
|
||||||
|
|
||||||
|
SNMALLOC_FAST_PATH_INLINE void*
|
||||||
|
operator new(size_t, void* ptr, snmalloc::PlacementToken) noexcept
|
||||||
|
{
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNMALLOC_FAST_PATH_INLINE void*
|
||||||
|
operator new[](size_t, void* ptr, snmalloc::PlacementToken) noexcept
|
||||||
|
{
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The following is not really needed, but windows expects that new/delete
|
||||||
|
// definitions are paired.
|
||||||
|
SNMALLOC_FAST_PATH_INLINE void
|
||||||
|
operator delete(void*, void*, snmalloc::PlacementToken) noexcept
|
||||||
|
{}
|
||||||
|
|
||||||
|
SNMALLOC_FAST_PATH_INLINE void
|
||||||
|
operator delete[](void*, void*, snmalloc::PlacementToken) noexcept
|
||||||
|
{}
|
||||||
Reference in New Issue
Block a user