private int allocateWithExpand(
        int arenaIx, int freeListIx, MemoryBuffer[] dest, int ix, int size) {
      while (true) {
        int arenaCount = allocatedArenas.get(), allocArenaCount = arenaCount;
        if (arenaCount < 0)  {
          allocArenaCount = -arenaCount - 1; // Someone is allocating an arena.
        }
        if (allocArenaCount > arenaIx) {
          // Someone already allocated this arena; just do the usual thing.
          return allocateWithSplit(freeListIx, dest, null, ix, dest.length, size, -1);
        }
        if ((arenaIx + 1) == -arenaCount) {
          // Someone is allocating this arena. Wait a bit and recheck.
          try {
            synchronized (this) {
              this.wait(100);
            }
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // Restore interrupt, won't handle here.
          }
          continue;
        }
        // Either this arena is being allocated, or it is already allocated, or it is next. The
        // caller should not try to allocate another arena before waiting for the previous one.
        assert arenaCount == arenaIx :
          "Arena count " + arenaCount + " but " + arenaIx + " is not being allocated";
        if (!allocatedArenas.compareAndSet(arenaCount, -arenaCount - 1)) {
          continue; // CAS race, look again.
        }
        assert data == null;
        try {
          init(arenaIx);
          // if init did not throw interrupt exception then allocation succeeded and so increment and commit the arena
          boolean isCommited = allocatedArenas.compareAndSet(-arenaCount - 1, arenaCount + 1);
          assert isCommited;
          metrics.incrAllocatedArena();
        } catch (ClosedByInterruptException e) {
          LlapIoImpl.LOG.info("Received interrupt during arena {} allocation.. Ignoring..", arenaIx);
          // not doing the notify in finally() block as thread interruptions may not execute finally
          synchronized (this) {
            this.notifyAll();
          }
          continue;
        }

        synchronized (this) {
          this.notifyAll();
        }
        return allocateWithSplit(freeListIx, dest, null, ix, dest.length, size, -1);
      }
    }
Unsets the headers (meaning this does not refer to a buffer).
llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java