Made Remote deallocation work on 32bit

The design of Remote used the top bits of the allocator id to encode
the sizeclass of the deallocation.  On 32bit, or on a platform that uses all the bits
we cannot use these bits for a sizeclass.

This commit uses the bottom bit of the allocator id (which is
guaranteed to be 0), to indicate if the object is the minimum
allocation size.  If it is not the minimum allocation size the
subsequent byte is used to encode the sizeclass.

The code uses constexpr to decide which strategy to use.
This commit is contained in:
Matthew Parkinson
2019-01-16 14:33:58 +00:00
parent 272bebb927
commit 82595dc9cd
2 changed files with 54 additions and 25 deletions

View File

@@ -521,9 +521,7 @@ namespace snmalloc
this->size += sizeclass_to_size(sizeclass);
Remote* r = (Remote*)p;
r->set_sizeclass(sizeclass);
assert(r->sizeclass() == sizeclass);
r->set_target_id(target_id);
r->set_sizeclass_and_target_id(target_id, sizeclass);
assert(r->sizeclass() == sizeclass);
assert(r->target_id() == target_id);
@@ -588,10 +586,6 @@ namespace snmalloc
}
};
static_assert(
sizeof(Remote) <= MIN_ALLOC_SIZE,
"Need to be able to cast any small alloc to Remote");
SlabList small_classes[NUM_SMALL_CLASSES];
DLList<Mediumslab> medium_classes[NUM_MEDIUM_CLASSES];