/** * Return the size of memory usage. */ @Override public long getMemorySize() { int numInMem = 0; synchronized (mContents) { numInMem = mContents.size(); // If we've already gotten the estimate // and the number of tuples hasn't changed, or was above // the sample size and is still above the sample size, we can // produce a new estimate without sampling the tuples again. if (sampled != 0 && (sampled == numInMem || sampled > SPILL_SAMPLE_SIZE && numInMem > SPILL_SAMPLE_SIZE)) { return totalSizeFromAvgTupleSize(aggSampleTupleSize/sampled, numInMem); } sampleContents(); int avgTupleSize; if (sampled != 0) { avgTupleSize = (int) (aggSampleTupleSize / sampled); } else { avgTupleSize = 0; } return totalSizeFromAvgTupleSize(avgTupleSize, numInMem); } }