Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing wrapper_heap alignment problems #3007

Merged
merged 2 commits into from Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions hpx/runtime/components/server/wrapper_heap.hpp
Expand Up @@ -76,6 +76,7 @@ namespace hpx { namespace components { namespace detail
typedef one_size_heap_allocators::fixed_mallocator allocator_type;
typedef hpx::lcos::local::spinlock mutex_type;
typedef std::unique_lock<mutex_type> scoped_lock;
typedef wrapper_heap_base::heap_parameters heap_parameters;

#if HPX_DEBUG_WRAPPER_HEAP != 0
enum guard_value
Expand All @@ -87,7 +88,7 @@ namespace hpx { namespace components { namespace detail

public:
explicit wrapper_heap(char const* class_name, std::size_t count,
std::size_t heap_size, std::size_t step);
heap_parameters parameters);

wrapper_heap();
~wrapper_heap() override;
Expand Down Expand Up @@ -120,10 +121,9 @@ namespace hpx { namespace components { namespace detail
void tidy();

protected:
void* pool_;
void* first_free_;
std::size_t step_;
std::size_t size_;
char* pool_;
char* first_free_;
heap_parameters const parameters_;
std::size_t free_size_;

// these values are used for AGAS registration of all elements of this
Expand All @@ -140,8 +140,6 @@ namespace hpx { namespace components { namespace detail
std::size_t heap_count_;
#endif

std::size_t const element_size_; // size of one element in the heap

// make sure the ABI of this is stable across configurations
#if defined(HPX_DEBUG)
std::size_t heap_count() const override { return heap_count_; }
Expand All @@ -161,13 +159,14 @@ namespace hpx { namespace components { namespace detail
{
private:
typedef wrapper_heap base_type;
typedef base_type::heap_parameters heap_parameters;

public:
typedef T value_type;

explicit fixed_wrapper_heap(char const* class_name,
std::size_t count, std::size_t step, std::size_t element_size)
: base_type(class_name, count, step, element_size)
std::size_t count, heap_parameters parameters)
: base_type(class_name, count, parameters)
{}
};
}}} // namespace hpx::components::detail
Expand Down
17 changes: 12 additions & 5 deletions hpx/runtime/components/server/wrapper_heap_list.hpp
Expand Up @@ -26,19 +26,26 @@ namespace hpx { namespace components { namespace detail
typedef util::one_size_heap_list base_type;
typedef typename Heap::value_type value_type;

typedef typename std::aligned_storage<
sizeof(value_type), std::alignment_of<value_type>::value
>::type storage_type;

enum
{
heap_step = 0xFFF, // default initial number of elements
// default initial number of elements
heap_capacity = 0xFFF,
// Alignment of one element
heap_element_alignment = std::alignment_of<value_type>::value,
// size of one element in the heap
heap_element_size = sizeof(storage_type)
};

public:
wrapper_heap_list()
: base_type(get_component_type_name(
get_component_type<typename value_type::wrapped_type>()),
heap_step, sizeof(typename std::aligned_storage<
sizeof(value_type), std::alignment_of<value_type>::value
>::type),
(Heap*) nullptr)
base_type::heap_parameters{heap_capacity, heap_element_alignment,
heap_element_size}, (Heap*) nullptr)
, type_(get_component_type<typename value_type::wrapped_type>())
{}

Expand Down
27 changes: 12 additions & 15 deletions hpx/util/one_size_heap_list.hpp
Expand Up @@ -34,16 +34,17 @@ namespace hpx { namespace util

typedef std::unique_lock<mutex_type> unique_lock_type;

typedef wrapper_heap_base::heap_parameters heap_parameters;

private:
template <typename Heap>
static std::shared_ptr<util::wrapper_heap_base> create_heap(
char const* name, std::size_t counter, std::size_t step,
std::size_t heap_size)
char const* name, std::size_t counter, heap_parameters parameters)
{
#if defined(HPX_DEBUG)
return std::make_shared<Heap>(name, counter, step, heap_size);
return std::make_shared<Heap>(name, counter, parameters);
#else
return std::make_shared<Heap>(name, 0, step, heap_size);
return std::make_shared<Heap>(name, 0, parameters);
#endif
}

Expand All @@ -57,15 +58,14 @@ namespace hpx { namespace util
, max_alloc_count_(0)
#endif
, create_heap_(nullptr)
, heap_step_(0)
, heap_size_(0)
, parameters_({0, 0, 0})
{
HPX_ASSERT(false); // shouldn't ever be called
}

template <typename Heap>
explicit one_size_heap_list(char const* class_name,
std::size_t heap_step, std::size_t heap_size, Heap* = nullptr)
heap_parameters parameters, Heap* = nullptr)
: class_name_(class_name)
#if defined(HPX_DEBUG)
, alloc_count_(0L)
Expand All @@ -74,13 +74,12 @@ namespace hpx { namespace util
, max_alloc_count_(0L)
#endif
, create_heap_(&one_size_heap_list::create_heap<Heap>)
, heap_step_(heap_step)
, heap_size_(heap_size)
, parameters_(parameters)
{}

template <typename Heap>
explicit one_size_heap_list(std::string const& class_name,
std::size_t heap_step, std::size_t heap_size, Heap* = nullptr)
heap_parameters parameters, Heap* = nullptr)
: class_name_(class_name)
#if defined(HPX_DEBUG)
, alloc_count_(0L)
Expand All @@ -89,8 +88,7 @@ namespace hpx { namespace util
, max_alloc_count_(0L)
#endif
, create_heap_(&one_size_heap_list::create_heap<Heap>)
, heap_step_(heap_step)
, heap_size_(heap_size)
, parameters_(parameters)
{}

~one_size_heap_list() noexcept;
Expand Down Expand Up @@ -122,10 +120,9 @@ namespace hpx { namespace util
std::size_t max_alloc_count_;
#endif
std::shared_ptr<util::wrapper_heap_base> (*create_heap_)(
char const*, std::size_t, std::size_t, std::size_t);
char const*, std::size_t, heap_parameters);

std::size_t const heap_step_; // default grow step
std::size_t const heap_size_; // size of the object
heap_parameters const parameters_;
};
}}

Expand Down
7 changes: 7 additions & 0 deletions hpx/util/wrapper_heap_base.hpp
Expand Up @@ -17,6 +17,13 @@ namespace hpx { namespace util
{
struct wrapper_heap_base
{
struct heap_parameters
{
std::size_t capacity;
std::size_t element_alignment;
std::size_t element_size;
};

virtual ~wrapper_heap_base() {}

virtual bool alloc(void** result, std::size_t count = 1) = 0;
Expand Down