@Stage("Segment")
 public long allocReturnCode(int chunks) {
   VanillaChronicleHash<?, ?, ?, ?> h = hh.h();
   if (chunks > h.maxChunksPerEntry) {
     throw new IllegalArgumentException(
         "Entry is too large: requires "
             + chunks
             + " chucks, "
             + h.maxChunksPerEntry
             + " is maximum.");
   }
   long lowestPossiblyFreeChunk = lowestPossiblyFreeChunk();
   if (lowestPossiblyFreeChunk + chunks > h.actualChunksPerSegmentTier) return -1;
   if (tierEntries() >= h.maxEntriesPerHashLookup) return -1;
   assert lowestPossiblyFreeChunk < h.actualChunksPerSegmentTier;
   long ret = freeList.setNextNContinuousClearBits(lowestPossiblyFreeChunk, chunks);
   if (ret == NOT_FOUND || ret + chunks > h.actualChunksPerSegmentTier) {
     if (ret + chunks > h.actualChunksPerSegmentTier) {
       assert ret != NOT_FOUND;
       freeList.clearRange(ret, ret + chunks);
     }
     return -1;
   } else {
     tierEntries(tierEntries() + 1);
     // if bit at lowestPossiblyFreeChunk is clear, it was skipped because
     // more than 1 chunk was requested. Don't move lowestPossiblyFreeChunk
     // in this case. chunks == 1 clause is just a fast path.
     if (chunks == 1 || freeList.isSet(lowestPossiblyFreeChunk)) {
       lowestPossiblyFreeChunk(ret + chunks);
     }
     return ret;
   }
 }