xo-alloc: doc improvements

This commit is contained in:
Roland Conybeare 2025-11-15 12:25:03 -05:00
commit 954921c641
5 changed files with 52 additions and 42 deletions

View file

@ -24,7 +24,7 @@ Install
One-step Install One-step Install
---------------- ----------------
Install along with the reset of *XO* from `xo-umbrella2 source`_ Install along with the rest of *XO* from `xo-umbrella2 source`_
.. _xo-umbrella2 source: https://github.com/rconybea/xo-umbrella2 .. _xo-umbrella2 source: https://github.com/rconybea/xo-umbrella2

View file

@ -11,16 +11,41 @@
namespace xo { namespace xo {
namespace gc { namespace gc {
/** @class ArenaAlloc /** @class ArenaAlloc
* @brief Bump allocator with fixed capacity * @brief Bump allocator with fixed capacity with dynamic virtual memory commitment.
* *
* @text * @text
* *
* <-----allocated----> <--------free-------> * allocation order:
* XXXXXXXXXXXXXXXXXXXX______________________ * ----------------------->
* ^ ^ ^ *
* lo free hi * <----------------- .size() ------------------>
* limit * <----------------- .committed() --------------->
*
* <-------allocated------><--------free--------> <---uncommitted---->
* XXXXXXXXXXXXXXXXXXXXXXXX______________________ ....................
* ^ ^ ^ ^ ^
* lo checkpoint free limit hi
*
* +- .alloc() ->
* +-- .expand() -->
* > < .before_checkpoint()
* > < .after_checkpoint()
*
* @endtext * @endtext
*
* Design Notes:
* - non-copyable, non-moveable
* - always heap-allocated
* - @ref lo_ <= @ref checkpoint_ <= @ref free_ <= @ref limit_ <= @ref hi_
* - memory obtained from mmap(), not heap
* - memory addresses are stable. Expand storage by committing VM pages.
* - @ref lo_ is aligned on VM page size (guaranteed by mmap())
* - @ref lo_ + @ref committed_z_ <= @ref hi_
* - @ref limit_ <= @ref lO_ + @ref committed_z_
* - @ref committed_z_ is always a multiple of VM page size
* - @ref limit_ is not guaranteed to be aligned with VM page size.
* - @ref expand increases @ref limit_ and @ref committed_z_ as needed.
*
**/ **/
class ArenaAlloc : public IAlloc { class ArenaAlloc : public IAlloc {
public: public:
@ -57,11 +82,14 @@ namespace xo {
/** Reset to empty state; provision at least @p need_z bytes of (committed) space **/ /** Reset to empty state; provision at least @p need_z bytes of (committed) space **/
void reset(std::size_t need_z); void reset(std::size_t need_z);
/** gc support: If used for storing xo::Object instances, scan allocated memory
* to populate @p *p_dest.
**/
void capture_object_statistics(capture_phase phase, void capture_object_statistics(capture_phase phase,
ObjectStatistics * p_dest) const; ObjectStatistics * p_dest) const;
/** expand available (i.e. committed) space to size at least @p z /** expand available (i.e. committed) space to size at least @p z
* In practice will round up to a multiple of @ref page_z_ * In practice will round up to a multiple of @ref page_z_.
**/ **/
bool expand(std::size_t z); bool expand(std::size_t z);
@ -98,7 +126,7 @@ namespace xo {
/** optional instance name, for diagnostics **/ /** optional instance name, for diagnostics **/
std::string name_; std::string name_;
/** size of a VM page **/ /** size of a VM page (from getpagesize()) **/
std::size_t page_z_; std::size_t page_z_;
/** allocator owns memory in range [@ref lo_, @ref hi_) **/ /** allocator owns memory in range [@ref lo_, @ref hi_) **/

View file

@ -1,28 +0,0 @@
/* Forwarding.hpp
*
* author: Roland Conybeare, Jul 2025
*/
#pragma once
#include "Object.hpp"
namespace xo {
namespace gc {
class Forwarding : public Object {
public:
Forwarding() = default;
// inherited from Object..
#ifdef NOT_USING
virtual bool _is_forwarded() const override final { return true; }
#endif
virtual Object * _destination() override final { return destination_.ptr(); }
private:
gp<Object> destination_;
};
} /*namespace gc*/
} /*namespace xo*/
/* end Forwarding.hpp */

View file

@ -7,6 +7,16 @@
namespace xo { namespace xo {
namespace obj { namespace obj {
/** @class Forwarding1
* @brief forwarding pointer for garbage collector.
*
* Used internally by garbage collector (see @ref GC).
* During evacuate phase overwrite from-space objects in-place
* with an instance of this class.
*
* This class suitable only for singly-inheriting objects,
* i.e. those that have exactly one vtable.
**/
class Forwarding1 : public Object { class Forwarding1 : public Object {
public: public:
explicit Forwarding1(gp<Object> dest); explicit Forwarding1(gp<Object> dest);
@ -17,11 +27,11 @@ namespace xo {
virtual bool _is_forwarded() const final override { return true; } virtual bool _is_forwarded() const final override { return true; }
virtual Object * _offset_destination(Object * src) const final override; virtual Object * _offset_destination(Object * src) const final override;
virtual Object * _destination() final override; virtual Object * _destination() final override;
/** never called on Forwarding1 **/ /** required by Object i/face, but never called on Forwarding1 **/
virtual std::size_t _shallow_size() const final override; virtual std::size_t _shallow_size() const final override;
/** never called on Forwarding1 **/ /** required by Object i/face, but never called on Forwarding1 **/
virtual Object * _shallow_copy() const final override; virtual Object * _shallow_copy() const final override;
/** never called on Forwarding1 **/ /** required by Object i/face, but never called on Forwarding1 **/
virtual std::size_t _forward_children() final override; virtual std::size_t _forward_children() final override;
private: private:

View file

@ -75,8 +75,8 @@ namespace xo {
* for a type appear directly in that type's vtable, and at specific locations. * for a type appear directly in that type's vtable, and at specific locations.
* This implies one level of indirection when GC traverses an instance. * This implies one level of indirection when GC traverses an instance.
* *
* Would be feasible to relax the must-inherit-from-Object constraint, * Would be feasible to relax the must-inherit-from-Object constraint
* but cost would be an extra layer of indirection * by having GC use its own wrapper, at cost of an extra layer of indirection
**/ **/
class Object { class Object {
public: public: