private MapJoinKey internalPutRow(KeyValueHelper keyValueHelper,
          Writable currentKey, Writable currentValue) throws SerDeException, IOException {

    boolean putToSidefile = false; // by default we put row into partition in memory

    // Next, put row into corresponding hash partition
    int keyHash = keyValueHelper.getHashFromKey();
    int partitionId = keyHash & (hashPartitions.length - 1);
    HashPartition hashPartition = hashPartitions[partitionId];

    if (bloom1 != null) {
      bloom1.addLong(keyHash);
    }

    if (isOnDisk(partitionId) || isHashMapSpilledOnCreation(partitionId)) { // destination on disk
      putToSidefile = true;
    } else {  // destination in memory
      if (!lastPartitionInMem &&        // If this is the only partition in memory, proceed without check
          (hashPartition.size() == 0 || // Destination partition being empty indicates a write buffer
                                        // will be allocated, thus need to check if memory is full
           (totalInMemRowCount & (this.memoryCheckFrequency - 1)) == 0)) {  // check periodically
        if (isMemoryFull()) {
          if ((numPartitionsSpilled == hashPartitions.length - 1) ) {
            LOG.warn("This LAST partition in memory won't be spilled!");
            lastPartitionInMem = true;
          } else {
            if (nwayConf == null) { // binary join
              int biggest = biggestPartition();
              spillPartition(biggest);
              this.setSpill(true);
              if (partitionId == biggest) { // destination hash partition has just be spilled
                putToSidefile = true;
              }
            } else {                // n-way join
              LOG.info("N-way spilling: spill tail partition from previously loaded small tables");
              int biggest = nwayConf.getNextSpillPartition();
              memoryThreshold += nwayConf.spill();
              if (biggest != 0 && partitionId == biggest) { // destination hash partition has just be spilled
                putToSidefile = true;
              }
              LOG.info("Memory threshold has been increased to: " + memoryThreshold);
            }
            numPartitionsSpilled++;
          }
        }
      }
    }

    // Now we know where to put row
    if (putToSidefile) {
      KeyValueContainer kvContainer = hashPartition.getSidefileKVContainer();
      kvContainer.add((HiveKey) currentKey, (BytesWritable) currentValue);
    } else {
      hashPartition.hashMap.put(keyValueHelper, keyHash); // Pass along hashcode to avoid recalculation
      totalInMemRowCount++;
    }

    return null; // there's no key to return
  }
Get the current memory usage by recalculating it.
@return current memory usage
ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/HybridHashTableContainer.java