Skip to content

Commit

Permalink
Remove bitfield member tag::marked
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 18, 2024
1 parent 658ea8e commit 98163b2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 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.147_amd64.deb
sudo apt install build/meevax_0.5.148_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.147.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.148.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.147_amd64.deb`
| `package` | Generate debian package `meevax_0.5.148_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.147
0.5.148
15 changes: 6 additions & 9 deletions include/meevax/memory/collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,15 @@ inline namespace memory

struct tag
{
bool marked : 1;

std::size_t size : 15;
std::size_t size : 16;

std::uintptr_t address : 48;

explicit tag(void const* const address, std::size_t size)
: marked { false }
, size { size }
: size { size }
, address { reinterpret_cast<std::uintptr_t>(address) }
{
assert(size < (1u << 15));
assert(size < (1u << 16));
}

virtual ~tag() = default;
Expand Down Expand Up @@ -306,11 +303,11 @@ inline namespace memory

static auto dlsym(std::string const&, void * const) -> void *;

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

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

static auto sweep() -> void;
static auto sweep(pointer_set<tag> &&) -> void;
};

static collector default_collector {};
Expand Down
5 changes: 5 additions & 0 deletions include/meevax/memory/integer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ inline namespace memory
{
return std::distance(begin(), end());
}

auto swap(integer_set & other)
{
std::swap(data, other.data);
}
};

template <typename T, std::size_t E>
Expand Down
49 changes: 26 additions & 23 deletions src/memory/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ inline namespace memory
{
allocation = 0;

return mark(), sweep();
return sweep(mark());
}

auto collector::count() noexcept -> std::size_t
{
return std::size(tags);
return tags.size();
}

auto collector::dlclose(void * const handle) -> void
Expand Down Expand Up @@ -112,7 +112,7 @@ inline namespace memory
}
}

auto collector::mark() noexcept -> void
auto collector::mark() noexcept -> pointer_set<tag>
{
auto is_root_object = [begin = tags.begin()](mutator * given)
{
Expand All @@ -130,53 +130,56 @@ inline namespace memory
return iter == begin or not (*--iter)->contains(given);
};

auto marked_tags = pointer_set<tag>();

for (auto&& mutator : mutators)
{
assert(mutator);
assert(mutator->object);

if (not mutator->object->marked and is_root_object(mutator))
if (not marked_tags.contains(mutator->object) and is_root_object(mutator))
{
mark(mutator->object);
mark(mutator->object, marked_tags);
}
}

return marked_tags;
}

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

assert(tags.contains(tag));
assert(tags.contains(object));

if (not tag->marked)
if (not marked_tags.contains(object))
{
tag->marked = true;
marked_tags.insert(object);

const auto lower_address = reinterpret_cast<mutator *>(tag->lower_address());
const auto upper_address = reinterpret_cast<mutator *>(tag->upper_address());
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)
{
mark((*lower)->object);
mark((*lower)->object, marked_tags);
}
}
}

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

for (auto&& tag : tags)
{
if (tag->marked)
{
tag->marked = false;
}
else
{
delete tag;
tags.erase(tag);
}
delete tag;
}

tags.swap(marked_tags);
}
} // namespace memory
} // namespace meevax

0 comments on commit 98163b2

Please sign in to comment.