xo-interpreter: refactor for explicit gc::GC* dep
This commit is contained in:
parent
760bb556b2
commit
2f2cb735f3
10 changed files with 89 additions and 32 deletions
|
|
@ -175,6 +175,8 @@ namespace xo {
|
|||
virtual void checkpoint() final override;
|
||||
virtual std::byte * alloc(std::size_t z) final override;
|
||||
|
||||
virtual bool check_owned(Object * src) const final override;
|
||||
|
||||
ArenaAlloc & operator=(const ArenaAlloc &) = delete;
|
||||
ArenaAlloc & operator=(ArenaAlloc &&) = delete;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace xo {
|
|||
/** required by Object i/face, but never called on Forwarding1 **/
|
||||
virtual Object * _shallow_copy(gc::IAlloc * mm) const final override;
|
||||
/** required by Object i/face, but never called on Forwarding1 **/
|
||||
virtual std::size_t _forward_children() final override;
|
||||
virtual std::size_t _forward_children(gc::GC * mm) final override;
|
||||
|
||||
private:
|
||||
/** the object that used to be located at this address (i.e. @c this)
|
||||
|
|
|
|||
|
|
@ -308,6 +308,15 @@ namespace xo {
|
|||
**/
|
||||
virtual void assign_member(Object * parent, Object ** lhs, Object* rhs) final override;
|
||||
|
||||
/** during GC check for source objects owned by GC.
|
||||
* See Object::_shallow_move.
|
||||
**/
|
||||
virtual bool check_owned(Object * src) const final override;
|
||||
/** queries during GC to determine if object at address @p src should move:
|
||||
* - full GC -> always
|
||||
* - incr GC -> if not tenured
|
||||
**/
|
||||
virtual bool check_move(Object * src) const final override;
|
||||
virtual std::byte * alloc(std::size_t z) final override;
|
||||
virtual std::byte * alloc_gc_copy(std::size_t z, const void * src) final override;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,12 @@ namespace xo {
|
|||
|
||||
namespace gc {
|
||||
/** @class IAllocator
|
||||
* @brief memory allocation interface with limited garbaga collector support
|
||||
* @brief memory allocation interface with limited garbage collector support
|
||||
*
|
||||
* Garbage collector support methods:
|
||||
* - checkpoint()
|
||||
* - assign_member()
|
||||
* - alloc_gc_copy()
|
||||
**/
|
||||
class IAlloc {
|
||||
public:
|
||||
|
|
@ -56,14 +61,28 @@ namespace xo {
|
|||
/** @return true iff debug logging enabled **/
|
||||
virtual bool debug_flag() const = 0;
|
||||
|
||||
/** reset allocator to empty state. **/
|
||||
virtual void clear() = 0;
|
||||
/** remember allocator state. All currently-allocated addresses xo
|
||||
* will satisfy is_before_checkpoint(x). Subsequent allocations x
|
||||
* will fail is_before_checkpoint(x), until checkpoint superseded
|
||||
* by @ref clear or another call to @ref checkpoint
|
||||
**/
|
||||
virtual void checkpoint() = 0;
|
||||
|
||||
/** allocate @p z bytes of memory. returns pointer to first address **/
|
||||
virtual std::byte * alloc(std::size_t z) = 0;
|
||||
/** reset allocator to empty state. **/
|
||||
virtual void clear() = 0;
|
||||
|
||||
// ----- GC-specific methods -----
|
||||
|
||||
/** true iff this allocator owns object at address @p src.
|
||||
* Use to assist Object::_shallow_move
|
||||
**/
|
||||
virtual bool check_owned(Object * src) const;
|
||||
/** true iff object at address @p src must move as part of
|
||||
* in-progress collection phase
|
||||
**/
|
||||
virtual bool check_move(Object * src) const;
|
||||
/** perform assignment
|
||||
* @code
|
||||
* *lhs = rhs
|
||||
|
|
@ -72,8 +91,6 @@ namespace xo {
|
|||
* Default implementation just does the assignment.
|
||||
**/
|
||||
virtual void assign_member(Object * parent, Object ** lhs, Object * rhs);
|
||||
/** allocate @p z bytes of memory. returns pointer to first address **/
|
||||
virtual std::byte * alloc(std::size_t z) = 0;
|
||||
/** allocate @p z bytes for copy of object at @p src.
|
||||
* Only used in @ref GC. Default implementation asserts and returns nullptr
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -122,15 +122,15 @@ namespace xo {
|
|||
static Object * _forward(Object * src, gc::GC * gc);
|
||||
|
||||
template <typename T>
|
||||
static void _forward_inplace(T ** src_addr) {
|
||||
Object * fwd = _forward(*src_addr, _gc());
|
||||
static void _forward_inplace(T ** src_addr, gc::GC * gc) {
|
||||
Object * fwd = _forward(*src_addr, gc);
|
||||
|
||||
*src_addr = reinterpret_cast<T *>(fwd);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void _forward_inplace(gp<T> & src) {
|
||||
_forward_inplace<T>(src.ptr_address());
|
||||
static void _forward_inplace(gp<T> & src, gc::GC * gc) {
|
||||
_forward_inplace<T>(src.ptr_address(), gc);
|
||||
}
|
||||
|
||||
/** primary workhorse for garbage collection.
|
||||
|
|
@ -156,10 +156,10 @@ namespace xo {
|
|||
**/
|
||||
static Object * _deep_move(Object * src, gc::GC * gc, gc::ObjectStatistics * stats);
|
||||
|
||||
/** copy @p src to to-space, and replace original with forwarding pointer to new location.
|
||||
/** copy @p src to to-space. Overwrite original with forwarding pointer to new location.
|
||||
* return the new location
|
||||
**/
|
||||
static Object * _shallow_move(Object * src, gc::GC * gc);
|
||||
static Object * _shallow_move(Object * src, gc::IAlloc * gc);
|
||||
|
||||
// Reflection support
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ namespace xo {
|
|||
*
|
||||
* Require: @ref mm is an instance of @ref gc::GC
|
||||
**/
|
||||
virtual Object * _shallow_copy(gc::IAlloc * mm) const = 0;
|
||||
virtual Object * _shallow_copy(gc::IAlloc * gc) const = 0;
|
||||
|
||||
/** update child pointers that refer to forwarding pointers,
|
||||
* replacing them with the correct destination.
|
||||
|
|
@ -243,7 +243,7 @@ namespace xo {
|
|||
* allocated by @ref _shallow_move
|
||||
*
|
||||
**/
|
||||
virtual std::size_t _forward_children() = 0;
|
||||
virtual std::size_t _forward_children(gc::GC * gc) = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue