diff --git a/mycpp/mark_sweep_heap.cc b/mycpp/mark_sweep_heap.cc index 0ada5d3bbf..9c5a0ae9c6 100644 --- a/mycpp/mark_sweep_heap.cc +++ b/mycpp/mark_sweep_heap.cc @@ -75,6 +75,10 @@ void* MarkSweepHeap::Allocate(size_t num_bytes, int* obj_id, int* pool_id) { *pool_id = 2; return pool2_.Allocate(obj_id); } + if (num_bytes <= pool3_.kMaxObjSize) { + *pool_id = 3; + return pool3_.Allocate(obj_id); + } *pool_id = 0; // malloc(), not a pool #endif @@ -148,6 +152,11 @@ void MarkSweepHeap::MaybeMarkAndPush(RawObject* obj) { return; } pool2_.Mark(obj_id); + } else if (header->pool_id == 3) { + if (pool3_.IsMarked(obj_id)) { + return; + } + pool3_.Mark(obj_id); } else #endif { @@ -215,6 +224,7 @@ void MarkSweepHeap::Sweep() { #ifndef NO_POOL_ALLOC pool1_.Sweep(); pool2_.Sweep(); + pool3_.Sweep(); #endif int last_live_index = 0; @@ -263,6 +273,7 @@ int MarkSweepHeap::Collect() { #ifndef NO_POOL_ALLOC pool1_.PrepareForGc(); pool2_.PrepareForGc(); + pool3_.PrepareForGc(); #endif // Mark roots. @@ -335,7 +346,7 @@ void MarkSweepHeap::PrintStats(int fd) { #ifndef NO_POOL_ALLOC dprintf(fd, " num allocated = %10d\n", - num_allocated_ + pool1_.num_allocated() + pool2_.num_allocated()); + num_allocated_ + pool1_.num_allocated() + pool2_.num_allocated() + pool3_.num_allocated()); dprintf(fd, " num in heap = %10d\n", num_allocated_); #else dprintf(fd, " num allocated = %10d\n", num_allocated_); @@ -344,9 +355,10 @@ void MarkSweepHeap::PrintStats(int fd) { #ifndef NO_POOL_ALLOC dprintf(fd, " num in pool 1 = %10d\n", pool1_.num_allocated()); dprintf(fd, " num in pool 2 = %10d\n", pool2_.num_allocated()); + dprintf(fd, " num in pool 3 = %10d\n", pool3_.num_allocated()); dprintf( fd, "bytes allocated = %10" PRId64 "\n", - bytes_allocated_ + pool1_.bytes_allocated() + pool2_.bytes_allocated()); + bytes_allocated_ + pool1_.bytes_allocated() + pool2_.bytes_allocated() + pool3_.bytes_allocated()); #else dprintf(fd, "bytes allocated = %10" PRId64 "\n", bytes_allocated_); #endif @@ -404,6 +416,7 @@ void MarkSweepHeap::FreeEverything() { #ifndef NO_POOL_ALLOC pool1_.Free(); pool2_.Free(); + pool3_.Free(); #endif } diff --git a/mycpp/mark_sweep_heap.h b/mycpp/mark_sweep_heap.h index 745851f2d4..57432dae95 100644 --- a/mycpp/mark_sweep_heap.h +++ b/mycpp/mark_sweep_heap.h @@ -231,7 +231,7 @@ class MarkSweepHeap { int num_live() { return num_live_ #ifndef NO_POOL_ALLOC - + pool1_.num_live() + pool2_.num_live() + + pool1_.num_live() + pool2_.num_live() + pool3_.num_live() #endif ; } @@ -265,10 +265,12 @@ class MarkSweepHeap { #ifndef NO_POOL_ALLOC // 16,384 / 24 bytes = 682 cells (rounded), 16,368 bytes // 16,384 / 48 bytes = 341 cells (rounded), 16,368 bytes + // 16,384 / 96 bytes = 171 cells (rounded), 16,368 bytes // Conveniently, the glibc malloc header is 16 bytes, giving exactly 16 Ki // differences Pool<682, 24> pool1_; Pool<341, 48> pool2_; + Pool<128, 128> pool3_; #endif std::vector roots_;