xo-alloc, xo-object: fix alloc,gc unit tests after gc improvements
This commit is contained in:
parent
daf729292e
commit
2febec3c8c
9 changed files with 44 additions and 17 deletions
|
|
@ -130,6 +130,7 @@ namespace xo {
|
|||
std::size_t reserved() const { return hi_ - lo_; };
|
||||
|
||||
std::size_t page_size() const { return page_z_; }
|
||||
std::size_t hugepage_z() const { return hugepage_z_; }
|
||||
std::byte * free_ptr() const { return free_ptr_; }
|
||||
void set_free_ptr(std::byte * x);
|
||||
|
||||
|
|
|
|||
|
|
@ -177,6 +177,8 @@ namespace xo {
|
|||
|
||||
/** @return pagesize (will be the same for {nursery, tenured} spaces) **/
|
||||
std::size_t pagesize() const;
|
||||
/** @return hugepage size (will be the same for {nursery, tenured} spaces) **/
|
||||
std::size_t hugepage_z() const;
|
||||
|
||||
/** @return allocation portion of Nursery to-space **/
|
||||
std::size_t nursery_to_allocated() const;
|
||||
|
|
|
|||
|
|
@ -16,12 +16,15 @@ namespace xo {
|
|||
|
||||
namespace gc {
|
||||
/** @class IAllocator
|
||||
* @brief memory allocation interface with limited garbage collector support
|
||||
* @brief arena allocation interface with limited garbage collector support
|
||||
*
|
||||
* Garbage collector support methods:
|
||||
* - checkpoint()
|
||||
* - assign_member()
|
||||
* - alloc_gc_copy()
|
||||
*
|
||||
* See class GC for copying incremental collector.
|
||||
* See class ArenaAlloc for arena allocator
|
||||
**/
|
||||
class IAlloc {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ namespace xo {
|
|||
/** page size used by underlying ArenaAlloc **/
|
||||
std::size_t page_size() const;
|
||||
|
||||
/** hugepage size used by underlying ArenaAlloc **/
|
||||
std::size_t hugepage_z() const;
|
||||
|
||||
/** reset to have at least @p z bytes of storage **/
|
||||
bool reset(std::size_t z);
|
||||
|
||||
|
|
|
|||
|
|
@ -233,6 +233,12 @@ namespace xo {
|
|||
return nursery_to()->page_size();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
GC::hugepage_z() const
|
||||
{
|
||||
return nursery_to()->hugepage_z();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
GC::nursery_from_allocated() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ namespace xo {
|
|||
return hd_->page_size();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
ListAlloc::hugepage_z() const {
|
||||
return hd_->hugepage_z();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
ListAlloc::size() const {
|
||||
return total_z_;
|
||||
|
|
@ -336,6 +341,7 @@ namespace xo {
|
|||
|
||||
std::unique_ptr<ArenaAlloc> new_alloc = ArenaAlloc::make(name,
|
||||
cz, debug_flag_);
|
||||
cz = new_alloc->size();
|
||||
|
||||
if (!new_alloc)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -13,17 +13,16 @@ namespace xo {
|
|||
|
||||
namespace {
|
||||
struct testcase_alloc {
|
||||
testcase_alloc(std::size_t rz, std::size_t z)
|
||||
explicit testcase_alloc(std::size_t z)
|
||||
:
|
||||
arena_z_{z} {}
|
||||
|
||||
std::size_t arena_z_;
|
||||
|
||||
};
|
||||
|
||||
std::vector<testcase_alloc>
|
||||
s_testcase_v = {
|
||||
testcase_alloc(0, 4096)
|
||||
testcase_alloc(4096)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -37,11 +36,12 @@ namespace xo {
|
|||
|
||||
auto alloc = ArenaAlloc::make("linearalloc",
|
||||
tc.arena_z_, c_debug_flag);
|
||||
alloc->expand(tc.arena_z_);
|
||||
|
||||
REQUIRE(alloc.get());
|
||||
REQUIRE(alloc->name() == "linearalloc");
|
||||
REQUIRE(alloc->size() == tc.arena_z_);
|
||||
REQUIRE(alloc->available() == tc.arena_z_);
|
||||
REQUIRE(alloc->size() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
REQUIRE(alloc->available() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
REQUIRE(alloc->allocated() == 0);
|
||||
REQUIRE(alloc->is_before_checkpoint(alloc->free_ptr()) == false);
|
||||
REQUIRE(alloc->before_checkpoint() == 0);
|
||||
|
|
@ -49,23 +49,23 @@ namespace xo {
|
|||
|
||||
auto free0 = alloc->free_ptr();
|
||||
|
||||
auto mem = alloc->alloc(tc.arena_z_);
|
||||
auto mem = alloc->alloc(std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
|
||||
REQUIRE(mem != nullptr);
|
||||
|
||||
REQUIRE(mem == free0);
|
||||
|
||||
REQUIRE(alloc->size() == tc.arena_z_);
|
||||
REQUIRE(alloc->size() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
REQUIRE(alloc->available() == 0);
|
||||
REQUIRE(alloc->allocated() == tc.arena_z_);
|
||||
REQUIRE(alloc->allocated() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
REQUIRE(alloc->is_before_checkpoint(mem) == false);
|
||||
REQUIRE(alloc->before_checkpoint() == 0);
|
||||
REQUIRE(alloc->after_checkpoint() == tc.arena_z_);
|
||||
REQUIRE(alloc->after_checkpoint() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
|
||||
alloc->clear();
|
||||
|
||||
REQUIRE(alloc->free_ptr() == free0);
|
||||
REQUIRE(alloc->available() == tc.arena_z_);
|
||||
REQUIRE(alloc->available() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
REQUIRE(alloc->allocated() == 0);
|
||||
REQUIRE(alloc->is_before_checkpoint(free0) == false);
|
||||
REQUIRE(alloc->before_checkpoint() == 0);
|
||||
|
|
@ -74,8 +74,8 @@ namespace xo {
|
|||
mem = alloc->alloc(1);
|
||||
|
||||
auto used = sizeof(void*);
|
||||
REQUIRE(alloc->size() == tc.arena_z_);
|
||||
REQUIRE(alloc->available() == tc.arena_z_ - used);
|
||||
REQUIRE(alloc->size() == std::max(tc.arena_z_, alloc->hugepage_z()));
|
||||
REQUIRE(alloc->available() == std::max(tc.arena_z_, alloc->hugepage_z()) - used);
|
||||
REQUIRE(alloc->allocated() == used);
|
||||
REQUIRE(alloc->is_before_checkpoint(free0) == false);
|
||||
REQUIRE(alloc->before_checkpoint() == 0);
|
||||
|
|
|
|||
|
|
@ -26,8 +26,11 @@ namespace xo {
|
|||
|
||||
std::vector<testcase_gc>
|
||||
s_testcase_v = {
|
||||
// n_gct: nursery gc threshold
|
||||
// t_gct: tenured gc threshold
|
||||
//
|
||||
// nz tz n_gct t_gct
|
||||
testcase_gc(1024, 4096, 1024, 4096)
|
||||
testcase_gc(1024, 4096, 1024, 1024)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -49,9 +52,9 @@ namespace xo {
|
|||
REQUIRE(gc->nursery_to_allocated() == 0);
|
||||
REQUIRE(gc->nursery_to_committed() >= tc.nursery_z_);
|
||||
REQUIRE(gc->nursery_to_reserved() >= tc.nursery_z_);
|
||||
REQUIRE(gc->nursery_to_reserved() < tc.nursery_z_ + gc->pagesize());
|
||||
REQUIRE(gc->nursery_to_reserved() < tc.nursery_z_ + gc->hugepage_z());
|
||||
REQUIRE(gc->size() >= tc.nursery_z_ + tc.tenured_z_);
|
||||
REQUIRE(gc->size() < tc.nursery_z_ + gc->pagesize() + tc.tenured_z_ + gc->pagesize());
|
||||
REQUIRE(gc->size() < tc.nursery_z_ + gc->hugepage_z() + tc.tenured_z_ + gc->hugepage_z());
|
||||
REQUIRE(gc->allocated() == 0);
|
||||
REQUIRE(gc->available() == gc->nursery_to_reserved());
|
||||
REQUIRE(gc->before_checkpoint() == 0);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ namespace xo {
|
|||
using xo::gc::ListAlloc;
|
||||
|
||||
namespace ut {
|
||||
#ifdef NOT_USING // ListAlloc probably permanently retired. Not maintaining
|
||||
|
||||
TEST_CASE("ListAlloc", "[alloc][gc]")
|
||||
{
|
||||
/** teeny weeny allocator.
|
||||
|
|
@ -27,7 +29,7 @@ namespace xo {
|
|||
std::byte * mem1 = alloc->alloc(20);
|
||||
|
||||
REQUIRE(mem1);
|
||||
REQUIRE(alloc->size() == alloc->page_size());
|
||||
REQUIRE(alloc->size() == std::max(alloc->page_size(), alloc->hugepage_z()));
|
||||
/* round up to multiple of 8 */
|
||||
REQUIRE(alloc->before_checkpoint() == 24);
|
||||
REQUIRE(alloc->after_checkpoint() == 0);
|
||||
|
|
@ -54,6 +56,7 @@ namespace xo {
|
|||
REQUIRE(alloc->is_before_checkpoint(mem2) == false);
|
||||
REQUIRE(alloc->is_before_checkpoint(mem3) == false);
|
||||
}
|
||||
#endif
|
||||
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue