RFR: JDK-8272112: Arena code simplifications

Kim Barrett kbarrett at openjdk.java.net
Mon Aug 9 04:29:32 UTC 2021


On Sat, 7 Aug 2021 05:30:54 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> May I please have reviews for this small change. This is pure code cleanup, issues that were identified by code review when working on JDK-8270308. 
> 
> The patch results in less code (excluding the new gtest), bit easier to maintain. I have some smaller functional improvements in the pipeline and would like to get this code cleanup out of the way first.
> 
> Changes:
> 
> - Made `ChunkPool` an automatic object. We can remove `chunkpool_init()` and instead rely on automatic initialization.
> 
> - Instead of having four named pools that need to be handled individually and selected via awkward switch constructs (see the old `Chunk::operator new()` and `::operator delete()`), we replace it with an array and a static selector (`ChunkPool* get_pool_for_size(size_t size)`).
> 
> - Removed `ChunkPool::_num_used`. It was nowhere queried, and its usefulness was questionable since these numbers don't include chunks with "special" sizes. The easiest way to obtain the footprint of arena chunks is via NMT.
> 
> - Before, we had two places where the backing memory of Chunks was allocated: in `ChunkPool::allocate()` and in `Chunk::operator new()`. The former was unnecessary. I streamlined that: removed the ability to allocate from `ChunkPool::allocate()` and renamed it to `ChunkPool::remove_chunk()`. Now Chunks are only allocated in `Chunk::operator new() `and ChunkPool just serves as Chunk cache.
> 
> - Renamed `ChunkPool::free_all_but()` to `ChunkPool::prune()` and removed the argument, made it a method-local constant (it had been a constant before in the caller of that function).
> 
> - I added a new gtest to test Chunk allocation and pooling a little.
> 
> 
> Functionally, nothing should have changed with this patch, this is pure code grooming.
> 
> ----
> 
> Tests: 
> - GHA
> - I manually tested on 64-bit and 32-bit, with and without UseMallocOnly. I also manually checked that pool usage is as expected.

Mostly looks good.  One naming issue, and a couple of pre-existing things that could be cleaned up while we're here.

src/hotspot/share/memory/arena.cpp line 62:

> 60: 
> 61:   // Remove a chunk from the pool and return it; NULL if pool is empty.
> 62:   Chunk* remove_chunk() {

I think I prefer the old allocate/free nomenclature.  `remove_chunk` sounds like it should be discarding.  And `return_chunk` is confusing about "return".  I think allocate/free from a pool/free-list is well-understood naming.

src/hotspot/share/memory/arena.cpp line 92:

> 90:         // free chunks at end of queue, for better locality
> 91:         cur = _first;
> 92:         for (size_t i = 0; i < (blocksToKeep - 1) && cur != NULL; i++) {

[pre-existing] Unless there is a bug, `_num_chunks > blocksToKeep` implies `cur != NULL`.  Consider assert instead.

src/hotspot/share/memory/arena.cpp line 96:

> 94:         }
> 95: 
> 96:         if (cur != NULL) {

[pre-existing] This test shouldn't be needed because `_num_chunks > blocksToKeep`.

-------------

Changes requested by kbarrett (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5040


More information about the hotspot-dev mailing list