public static boolean tryReserveTaskMem ( long m ) { if ( ! CAN_ALLOC ) return false ; if ( m == 0 ) return true ; assert m >= 0 : "m < 0: " + m ; long current = _taskMem . addAndGet ( - m ) ; if ( current < 0 ) { _taskMem . addAndGet ( m ) ; return false ; } return true ; }
Try to reserve memory needed for task execution and return true if succeeded . Tasks have a shared pool of memory which they should ask for in advance before they even try to allocate it .