This method <strong>MUST</strong> only be called for {@link ByteBuffer}s that were allocated via
{@link #allocateDirectNoCleaner(int)}.
172577
public static void freeDirectNoCleaner(ByteBuffer buffer) {
        assert USE_DIRECT_BUFFER_NO_CLEANER;

        int capacity = buffer.capacity();
        PlatformDependent0.freeMemory(PlatformDependent0.directBufferAddress(buffer));
        decrementMemoryCounter(capacity);
    }
233866
void release(RichByteBufferImpl handler)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "release", handler);
      byteBufferWrapperPool.add(handler);
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "release");
   }
983916
protected synchronized void clear(int bufferType) {
        final String methodName = "clear()";
        if (bufferType == HTODInvalidationBuffer.EXPLICIT_BUFFER) {
            this.explicitBuffer.clear();
        } else if (bufferType == HTODInvalidationBuffer.SCAN_BUFFER) {
            this.scanBuffer.clear();
        } else if (bufferType == HTODInvalidationBuffer.GC_BUFFER) {
            // todo: return GC to pool?
            for (int i = 0; i < garbageCollectorBuffer.size(); i++) {
                EvictionTableEntry evt = (EvictionTableEntry) garbageCollectorBuffer.get(i);
                cod.htod.evictionEntryPool.add(evt);
            }
            this.garbageCollectorBuffer.clear();
        }
        traceDebug(methodName, "cacheName=" + this.cod.cacheName + " bufferType=" + bufferType);
    }
771541
@GuardedBy("evictionLock")
    void drainBuffers(int maxToDrain) {
        // A mostly strict ordering is achieved by observing that each buffer
        // contains tasks in a weakly sorted order starting from the last drain.
        // The buffers can be merged into a sorted list in O(n) time by using
        // counting sort and chaining on a collision.

        // The output is capped to the expected number of tasks plus additional
        // slack to optimistically handle the concurrent additions to the buffers.
        Task[] tasks = new Task[maxToDrain];

        // Moves the tasks into the output array, applies them, and updates the
        // marker for the starting order of the next drain.
        int maxTaskIndex = moveTasksFromBuffers(tasks);
        runTasks(tasks, maxTaskIndex);
        updateDrainedOrder(tasks, maxTaskIndex);
    }
791920
protected void reBuffer() {
        resetBuffer();

        try {
            if (bufferOffset >= fs.getFileStatus(inputPath).getLen()) // TODO: is this equivalent?
                return;

            input.seek(bufferOffset);

            int read = 0;

            while (read < buffer.length) {
                int n = input.read(buffer, read, buffer.length - read);
                if (n < 0)
                    break;
                read += n;
            }

            validBufferBytes = read;
            bytesSinceCacheFlush += read;
        } catch (IOException e) {
            throw new FSReadError(e, filePath);
        }
    }
1301846
private void flushBuffer() throws IOException {
    if (this.dirty_) {
      if (this.diskPos_ != this.lo_) {
        super.seek(this.lo_);
      }
      int len = (int) (this.curr_ - this.lo_);
      super.write(this.buff_, 0, len);
      this.diskPos_ = this.curr_;
      this.dirty_ = false;
    }
  }
1370366
public boolean getClearDigitBuffer() {
        String value = Optional.fromNullable(getParameter(SignalParameters.CLEAR_DIGIT_BUFFER.symbol())).or("false");
        return Boolean.parseBoolean(value);
    }
2614
void drainBuffers() {
        // A mostly strict ordering is achieved by observing that each buffer
        // contains tasks in a weakly sorted order starting from the last drain.
        // The buffers can be merged into a sorted array in O(n) time by using
        // counting sort and chaining on a collision.

        // Moves the tasks into the output array, applies them, and updates the
        // marker for the starting order of the next drain.
        int maxTaskIndex = moveTasksFromBuffers(tasks);
        updateDrainedOrder(tasks, maxTaskIndex);
        runTasks(tasks, maxTaskIndex);
    }
877399
private void removeBuffer(W buffer) {
        createdBufs.decrementAndGet();
        if (bufferMonitor.remove(buffer) == null) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.WARNING,
                    "Attempt to remove unknown buffer from pool.",
                    new Throwable());
            } else {
                logger.warning("Attempt to remove unknown buffer from pool.");
            }
        }
    }
250112
public final void freeBuffers()
    {
        /* 11-Apr-2005, TSa: Ok, we can release the buffer now, to be
         *   recycled by the next stream reader instantiated by this
         *   thread (if any).
         */
	if (mRecycleBuffer) {
	    byte[] buf = mByteBuffer;
	    if (buf != null) {
		mByteBuffer = null;
		if (mConfig != null) {
		    mConfig.freeFullBBuffer(buf);
		}
	    }
	}
    }
280445
public ByteBuffer reset(ByteBuffer input)
    {
        ByteBuffer old = this.input;
        this.input = checkNotNull(input, "input ByteBuffer is null").slice();
        isRead = false;
        return old;
    }
1208212
public void postProcessWriteBuffers(long dataWritten) {

        if (getByteBufferArrayDirect() == null) {
            try {
                // see if we should post process just the one buffer case
                if (((WsByteBufferImpl) getBuffer()).oWsBBDirect != null) {
                    ((WsByteBufferImpl) getBuffer()).setParmsFromDirectBuffer();
                }
            } catch (ClassCastException cce) {
                // Nothing to do here, already flagged this condition on the
                // pre-processing
            }
            return;
        }

        WsByteBuffer wsBuffArray[] = getBuffers();
        for (int i = 0; i < wsBuffArray.length; i++) {
            if (wsBuffArray[i] == null) {
                break;
            }
            try {
                ((WsByteBufferImpl) wsBuffArray[i]).setParmsFromDirectBuffer();
            } catch (ClassCastException cce) {
                // Nothing to do here, already flagged this condition on the
                // pre-processing
                return;
            }

        }
    }
1084350
public void setParmsToDirectBuffer() {

        if (oByteBuffer.isDirect()) {
            this.oWsBBDirect = this.oByteBuffer;
            return;
        }

        if (oWsBBDirect == null) {
            this.oWsBBDirect = ByteBuffer.allocateDirect(oByteBuffer.capacity());
        }

        // set the position and limit
        this.oWsBBDirect.limit(oByteBuffer.limit());
        this.oWsBBDirect.position(oByteBuffer.position());
    }
1034238
private void writeFullBuffer(ByteBuffer buffer) throws IOException {
        int iterationsCount = MAX_WRITE_ITERATIONS;
        int writeCount;
        
        while(buffer.remaining() > 0 && iterationsCount > 0) {
            writeCount = _channel.write(buffer);
            if(writeCount == 0) {
                // we decrement iterations count only when we could not write anything
                --iterationsCount;
            } else {
                // as long as we can write, we reset iterationsCount
                iterationsCount = MAX_WRITE_ITERATIONS;
            }
        }
        
        if(buffer.remaining() > 0)
            throw new IOException("couldn't write the buffer after " + MAX_WRITE_ITERATIONS + " tries");
    }
272617
@Override
    public void purgeBuffers() {
        log.info("Purging TAD buffers...");

        tadCache = new ArrayList<>();

        int numDevices = Nd4j.getAffinityManager().getNumberOfDevices();

        for (int i = 0; i < numDevices; i++) {
            log.info("Resetting device: [{}]", i);
            tadCache.add(i, new ConcurrentHashMap<TadDescriptor, Pair<DataBuffer, DataBuffer>>());
        }

        super.purgeBuffers();
    }
556762
static void offerLastTemporaryDirectBuffer(ByteBuffer buf) {
        assert buf != null;
        BufferCache cache = bufferCache.get();
        if (!cache.offerLast(buf)) {
            // cache is full
            free(buf);
        }
    }
948057
@Override
	public void recycle(MemorySegment segment) {
		int numAddedBuffers;

		synchronized (bufferQueue) {
			// Similar to notifyBufferAvailable(), make sure that we never add a buffer
			// after releaseAllResources() released all buffers (see below for details).
			if (isReleased.get()) {
				try {
					inputGate.returnExclusiveSegments(Collections.singletonList(segment));
					return;
				} catch (Throwable t) {
					ExceptionUtils.rethrow(t);
				}
			}
			numAddedBuffers = bufferQueue.addExclusiveBuffer(new NetworkBuffer(segment, this), numRequiredBuffers);
		}

		if (numAddedBuffers > 0 && unannouncedCredit.getAndAdd(numAddedBuffers) == 0) {
			notifyCreditAvailable();
		}
	}