public static void set_goals( String msg, boolean oom , long bytes) {
    // Our best guess of free memory, as of the last GC cycle
    final long heapUsed = Boot.HEAP_USED_AT_LAST_GC;
    final long timeGC = Boot.TIME_AT_LAST_GC;
    final long freeHeap = MEM_MAX - heapUsed;
    assert freeHeap >= 0 : "I am really confused about the heap usage; MEM_MAX="+MEM_MAX+" heapUsed="+heapUsed;
    // Current memory held in the K/V store.
    final long cacheUsage = myHisto.histo(false)._cached;
    // Our best guess of POJO object usage: Heap_used minus cache used
    final long pojoUsedGC = Math.max(heapUsed - cacheUsage,0);

    // Block allocations if:
    // the cache is > 7/8 MEM_MAX, OR
    // we cannot allocate an equal amount of POJOs, pojoUsedGC > freeHeap.
    // Decay POJOS_USED by 1/8th every 5 sec: assume we got hit with a single
    // large allocation which is not repeating - so we do not need to have
    // double the POJO amount.
    // Keep at least 1/8th heap for caching.
    // Emergency-clean the cache down to the blocking level.
    long d = MEM_CRITICAL;
    // Decay POJO amount
    long p = pojoUsedGC;
    long age = (System.currentTimeMillis() - timeGC); // Age since last FullGC
    age = Math.min(age,10*60*1000 ); // Clip at 10mins
    while( (age-=5000) > 0 ) p = p-(p>>3); // Decay effective POJO by 1/8th every 5sec
    d -= 2*p - bytes; // Allow for the effective POJO, and again to throttle GC rate
    d = Math.max(d,MEM_MAX>>3); // Keep at least 1/8th heap
    H2O.Cleaner.DESIRED = d;

    String m="";
    if( cacheUsage > H2O.Cleaner.DESIRED ) {
      m = (CAN_ALLOC?"Blocking!  ":"blocked:   ");
      if( oom ) setMemLow(); // Stop allocations; trigger emergency clean
      Boot.kick_store_cleaner();
    } else { // Else we are not *emergency* cleaning, but may be lazily cleaning.
      setMemGood();             // Cache is as low as we'll go; unblock
      if( oom ) {               // But still have an OOM?
        m = "Unblock allocations; cache emptied but memory is low: ";
        // Means the heap is full of uncached POJO's - which cannot be spilled.
        // Here we enter the zone of possibly dieing for OOM.  There's no point
        // in blocking allocations, as no more memory can be freed by more
        // cache-flushing.  Might as well proceed on a "best effort" basis.
        Log.warn(Sys.CLEAN,m+" OOM but cache is emptied:  MEM_MAX = " + PrettyPrint.bytes(MEM_MAX) + ", DESIRED_CACHE = " + PrettyPrint.bytes(d) +", CACHE = " + PrettyPrint.bytes(cacheUsage) + ", POJO = " + PrettyPrint.bytes(p) + ", this request bytes = " + PrettyPrint.bytes(bytes));
      } else { 
        m = "MemGood:   ";
      }
    }

    // No logging if under memory pressure: can deadlock the cleaner thread
    if( Log.flag(Sys.CLEAN) ) {
      String s = m+msg+", HEAP_LAST_GC="+(heapUsed>>20)+"M, KV="+(cacheUsage>>20)+"M, POJO="+(pojoUsedGC>>20)+"M, free="+(freeHeap>>20)+"M, MAX="+(MEM_MAX>>20)+"M, DESIRED="+(H2O.Cleaner.DESIRED>>20)+"M"+(oom?" OOM!":" NO-OOM");
      if( CAN_ALLOC ) Log.debug(Sys.CLEAN ,s);
      else            Log.unwrap(System.err,s);
    }
  }
public static void set_goals ( String msg , boolean oom , long bytes ) { final long heapUsed = Boot . HEAP_USED_AT_LAST_GC ; final long timeGC = Boot . TIME_AT_LAST_GC ; final long freeHeap = MEM_MAX - heapUsed ; assert freeHeap >= 0 : "I am really confused about the heap usage; MEM_MAX=" + MEM_MAX + " heapUsed=" + heapUsed ; final long cacheUsage = myHisto . histo ( false ) . _cached ; final long pojoUsedGC = Math . max ( heapUsed - cacheUsage , 0 ) ; long d = MEM_CRITICAL ; long p = pojoUsedGC ; long age = ( System . currentTimeMillis ( ) - timeGC ) ; age = Math . min ( age , 10 * 60 * 1000 ) ; while ( ( age -= 5000 ) > 0 ) p = p - ( p > > 3 ) ; d -= 2 * p - bytes ; d = Math . max ( d , MEM_MAX > > 3 ) ; H2O . Cleaner . DESIRED = d ; String m = "" ; if ( cacheUsage > H2O . Cleaner . DESIRED ) { m = ( CAN_ALLOC ? "Blocking!  " : "blocked:   " ) ; if ( oom ) setMemLow ( ) ; Boot . kick_store_cleaner ( ) ; } else { setMemGood ( ) ; if ( oom ) { m = "Unblock allocations; cache emptied but memory is low: " ; Log . warn ( Sys . CLEAN , m + " OOM but cache is emptied:  MEM_MAX = " + PrettyPrint . bytes ( MEM_MAX ) + ", DESIRED_CACHE = " + PrettyPrint . bytes ( d ) + ", CACHE = " + PrettyPrint . bytes ( cacheUsage ) + ", POJO = " + PrettyPrint . bytes ( p ) + ", this request bytes = " + PrettyPrint . bytes ( bytes ) ) ; } else { m = "MemGood:   " ; } } if ( Log . flag ( Sys . CLEAN ) ) { String s = m + msg + ", HEAP_LAST_GC=" + ( heapUsed > > 20 ) + "M, KV=" + ( cacheUsage > > 20 ) + "M, POJO=" + ( pojoUsedGC > > 20 ) + "M, free=" + ( freeHeap > > 20 ) + "M, MAX=" + ( MEM_MAX > > 20 ) + "M, DESIRED=" + ( H2O . Cleaner . DESIRED > > 20 ) + "M" + ( oom ? " OOM!" : " NO-OOM" ) ; if ( CAN_ALLOC ) Log . debug ( Sys . CLEAN , s ) ; else Log . unwrap ( System . err , s ) ; } }
Called on any OOM allocation