Skip to content

Commit

Permalink
Update the pointer handled by collector to const
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Mar 20, 2024
1 parent 98163b2 commit 71598d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.148_amd64.deb
sudo apt install build/meevax_0.5.149_amd64.deb
```

or
Expand Down Expand Up @@ -123,9 +123,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.148.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.149.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.148_amd64.deb`
| `package` | Generate debian package `meevax_0.5.149_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.148
0.5.149
24 changes: 12 additions & 12 deletions include/meevax/memory/collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ inline namespace memory

virtual ~tag() = default;

auto lower_address() const noexcept
auto begin() const
{
return address;
return mutators.lower_bound(reinterpret_cast<mutator const*>(address));
}

auto upper_address() const noexcept
auto end() const
{
return address + size;
return mutators.lower_bound(reinterpret_cast<mutator const*>(address + size));
}

auto contains(void const* const data) const noexcept
{
return reinterpret_cast<void const*>(lower_address()) <= data and data < reinterpret_cast<void const*>(upper_address());
return reinterpret_cast<void const*>(address) <= data and data < reinterpret_cast<void const*>(address + size);
}
};

Expand Down Expand Up @@ -180,11 +180,11 @@ inline namespace memory
friend class collector;

protected:
tag * object = nullptr;
tag const* object = nullptr;

constexpr mutator() = default;

explicit mutator(tag * object) noexcept
explicit mutator(tag const* object) noexcept
: object { object }
{
if (object)
Expand All @@ -201,7 +201,7 @@ inline namespace memory
}
}

auto reset(tag * after = nullptr) noexcept -> void
auto reset(tag const* after = nullptr) noexcept -> void
{
if (auto before = std::exchange(object, after); not before and after)
{
Expand All @@ -213,7 +213,7 @@ inline namespace memory
}
}

static auto locate(void * const data) noexcept -> tag *
static auto locate(void const* const data) noexcept -> tag const*
{
if (not data)
{
Expand All @@ -223,7 +223,7 @@ inline namespace memory
{
return cache;
}
else if (auto iter = tags.lower_bound(reinterpret_cast<tag *>(data)); iter != tags.begin() and (*--iter)->contains(data))
else if (auto iter = tags.lower_bound(reinterpret_cast<tag const*>(data)); iter != tags.begin() and (*--iter)->contains(data))
{
return *iter;
}
Expand All @@ -241,7 +241,7 @@ inline namespace memory
0x0000'0000'0000'0000 ~ 0x7FFF'FFFF'FFFF'FFFF
*/
template <typename T>
using pointer_set = integer_set<T *, 15, 16, 16>;
using pointer_set = integer_set<T const*, 15, 16, 16>;

private:
static inline tag * cache = nullptr;
Expand Down Expand Up @@ -305,7 +305,7 @@ inline namespace memory

static auto mark() noexcept -> pointer_set<tag>;

static auto mark(tag * const, pointer_set<tag> &) noexcept -> void;
static auto mark(tag const* const, pointer_set<tag> &) noexcept -> void;

static auto sweep(pointer_set<tag> &&) -> void;
};
Expand Down
18 changes: 7 additions & 11 deletions src/memory/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ inline namespace memory

auto collector::mark() noexcept -> pointer_set<tag>
{
auto is_root_object = [begin = tags.begin()](mutator * given)
auto is_root_object = [begin = tags.begin()](mutator const* given) // TODO INEFFICIENT!
{
/*
If the given mutator is a non-root object, then an object containing
Expand All @@ -125,7 +125,7 @@ inline namespace memory
base-address + object-size. The tag is present to keep track of the
base-address and size of the object needed here.
*/
auto iter = tags.lower_bound(reinterpret_cast<tag *>(given));
auto iter = tags.lower_bound(reinterpret_cast<tag const*>(given));

return iter == begin or not (*--iter)->contains(given);
};
Expand All @@ -146,7 +146,7 @@ inline namespace memory
return marked_tags;
}

auto collector::mark(tag * const object, pointer_set<tag> & marked_tags) noexcept -> void
auto collector::mark(tag const* const object, pointer_set<tag> & marked_tags) noexcept -> void
{
assert(object);

Expand All @@ -156,25 +156,21 @@ inline namespace memory
{
marked_tags.insert(object);

const auto lower_address = reinterpret_cast<mutator *>(object->lower_address());
const auto upper_address = reinterpret_cast<mutator *>(object->upper_address());

for (auto lower = mutators.lower_bound(lower_address),
upper = mutators.lower_bound(upper_address); lower != upper; ++lower)
for (auto each : *object)
{
mark((*lower)->object, marked_tags);
mark(each->object, marked_tags);
}
}
}

auto collector::sweep(pointer_set<tag> && marked_tags) -> void
{
for (auto&& marked_tag : marked_tags)
for (auto marked_tag : marked_tags)
{
tags.erase(marked_tag);
}

for (auto&& tag : tags)
for (auto tag : tags)
{
delete tag;
}
Expand Down

0 comments on commit 71598d9

Please sign in to comment.