/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "memory/allocation.hpp"
#include "services/memoryPool.hpp"
#include "services/memoryService.hpp"
// Low Memory Detection Support
// Two memory alarms in the JDK (we called them sensors).
// - Heap memory sensor
// - Non-heap memory sensor
// When the VM detects if the memory usage of a memory pool has reached
// or exceeded its threshold, it will trigger the sensor for the type
// of the memory pool (heap or nonheap or both).
//
// If threshold == -1, no low memory detection is supported and
// the threshold value is not allowed to be changed.
// If threshold == 0, no low memory detection is performed for
// that memory pool. The threshold can be set to any non-negative
// value.
//
// The default threshold of the Hotspot memory pools are:
// Eden space -1
// Survivor space 1 -1
// Survivor space 2 -1
// Old generation 0
// Perm generation 0
// CodeCache 0
//
// For heap memory, detection will be performed when GC finishes
// and also in the slow path allocation.
// For Code cache, detection will be performed in the allocation
// and deallocation.
//
// May need to deal with hysteresis effect.
//
// Memory detection code runs in the Service thread (serviceThread.hpp).
class OopClosure;
class MemoryPool;
private:
bool _support_high_threshold;
bool _support_low_threshold;
public:
_high_threshold = 0;
_low_threshold= 0;
}
if (_support_high_threshold && _high_threshold > 0) {
}
return false;
}
if (_support_low_threshold && _low_threshold > 0) {
}
return false;
}
return prev;
}
return prev;
}
};
private:
bool _sensor_on;
// before the actual sensor on flag and sensor count are set
// we maintain the number of pending triggers and clears.
// _pending_trigger_count means the number of pending triggers
// and the sensor count should be incremented by the same number.
// _pending_clear_count takes precedence if it's > 0 which
// indicates the resulting sensor will be off
// Sensor trigger requests will reset this clear count to
// indicate the resulting flag should be on.
int _pending_clear_count;
public:
SensorInfo();
}
bool has_pending_requests() {
return (_pending_trigger_count > 0 || _pending_clear_count > 0);
}
// When this method is used, the memory usage is monitored
// as a gauge attribute. High and low thresholds are designed
// to provide a hysteresis mechanism to avoid repeated triggering
// of notifications when the attribute value makes small oscillations
// around the high or low threshold value.
//
// The sensor will be triggered if:
// (1) the usage is crossing above the high threshold and
// the sensor is currently off and no pending
// trigger requests; or
// (2) the usage is crossing above the high threshold and
// the sensor will be off (i.e. sensor is currently on
// and has pending clear requests).
//
// Subsequent crossings of the high threshold value do not cause
// any triggers unless the usage becomes less than the low threshold.
//
// The sensor will be cleared if:
// (1) the usage is crossing below the low threshold and
// the sensor is currently on and no pending
// clear requests; or
// (2) the usage is crossing below the low threshold and
// the sensor will be on (i.e. sensor is currently off
// and has pending trigger requests).
//
// Subsequent crossings of the low threshold value do not cause
// any clears unless the usage becomes greater than or equal
// to the high threshold.
//
// If the current level is between high and low threhsold, no change.
//
// When this method is used, the memory usage is monitored as a
// simple counter attribute. The sensor will be triggered
// whenever the usage is crossing the threshold to keep track
// of the number of times the VM detects such a condition occurs.
//
// The sensor will be triggered if:
// - the usage is crossing above the high threshold regardless
// of the current sensor state.
//
// The sensor will be cleared if:
// (1) the usage is crossing below the low threshold and
// the sensor is currently on; or
// (2) the usage is crossing below the low threshold and
// the sensor will be on (i.e. sensor is currently off
// and has pending trigger requests).
//
void process_pending_requests(TRAPS);
void oops_do(OopClosure* f);
#ifndef PRODUCT
// printing on default output stream;
void print();
#endif // PRODUCT
};
friend class LowMemoryDetectorDisabler;
friend class ServiceThread;
private:
// true if any collected heap has low memory detection enabled
static volatile bool _enabled_for_collected_pools;
// > 0 if temporary disabed
static void check_memory_usage();
static bool has_pending_requests();
static void process_sensor_changes(TRAPS);
public:
static void detect_low_memory();
// low memory detection is enabled for collected memory pools
// iff one of the collected memory pool has a sensor and the
// threshold set non-zero
return false;
} else {
return (threshold_support->is_high_threshold_supported() ?
(threshold_support->high_threshold() > 0) : false);
}
}
// indicates if low memory detection is enabled for any collected
// memory pools
static inline bool is_enabled_for_collected_pools() {
return !temporary_disabled() && _enabled_for_collected_pools;
}
// recompute enabled flag
static void recompute_enabled_for_collected_pools();
// low memory detection for collected memory pools.
static inline void detect_low_memory_for_collected_pools() {
// no-op if low memory detection not enabled
if (!is_enabled_for_collected_pools()) {
return;
}
for (int i=0; i<num_memory_pools; i++) {
// if low memory detection is enabled then check if the
// current used exceeds the high threshold
}
}
}
}
};
public:
{
}
{
}
};
#endif // SHARE_VM_SERVICES_LOWMEMORYDETECTOR_HPP