42 // the threshold value is not allowed to be changed.
43 // If threshold == 0, no low memory detection is performed for
44 // that memory pool. The threshold can be set to any non-negative
45 // value.
46 //
47 // The default threshold of the Hotspot memory pools are:
48 // Eden space -1
49 // Survivor space 1 -1
50 // Survivor space 2 -1
51 // Old generation 0
52 // Perm generation 0
53 // CodeCache 0
54 //
55 // For heap memory, detection will be performed when GC finishes
56 // and also in the slow path allocation.
57 // For Code cache, detection will be performed in the allocation
58 // and deallocation.
59 //
60 // May need to deal with hysteresis effect.
61 //
62 // Memory detection code runs in the Service thread (serviceThread.hpp).
63
64 class OopClosure;
65 class MemoryPool;
66
67 class ThresholdSupport : public CHeapObj<mtInternal> {
68 private:
69 bool _support_high_threshold;
70 bool _support_low_threshold;
71 size_t _high_threshold;
72 size_t _low_threshold;
73 public:
74 ThresholdSupport(bool support_high, bool support_low) {
75 _support_high_threshold = support_high;
76 _support_low_threshold = support_low;
77 _high_threshold = 0;
78 _low_threshold= 0;
79 }
80
81 size_t high_threshold() const { return _high_threshold; }
82 size_t low_threshold() const { return _low_threshold; }
196 // The sensor will be cleared if:
197 // (1) the usage is crossing below the low threshold and
198 // the sensor is currently on; or
199 // (2) the usage is crossing below the low threshold and
200 // the sensor will be on (i.e. sensor is currently off
201 // and has pending trigger requests).
202 //
203 void set_counter_sensor_level(MemoryUsage usage, ThresholdSupport* counter_threshold);
204
205 void process_pending_requests(TRAPS);
206 void oops_do(OopClosure* f);
207
208 #ifndef PRODUCT
209 // printing on default output stream;
210 void print();
211 #endif // PRODUCT
212 };
213
214 class LowMemoryDetector : public AllStatic {
215 friend class LowMemoryDetectorDisabler;
216 friend class ServiceThread;
217 private:
218 // true if any collected heap has low memory detection enabled
219 static volatile bool _enabled_for_collected_pools;
220 // > 0 if temporary disabed
221 static volatile jint _disabled_count;
222
223 static void check_memory_usage();
224 static bool has_pending_requests();
225 static bool temporary_disabled() { return _disabled_count > 0; }
226 static void disable() { Atomic::inc(&_disabled_count); }
227 static void enable() { Atomic::dec(&_disabled_count); }
228 static void process_sensor_changes(TRAPS);
229
230 public:
231 static void detect_low_memory();
232 static void detect_low_memory(MemoryPool* pool);
233 static void detect_after_gc_memory(MemoryPool* pool);
234
235 static bool is_enabled(MemoryPool* pool) {
236 // low memory detection is enabled for collected memory pools
|
42 // the threshold value is not allowed to be changed.
43 // If threshold == 0, no low memory detection is performed for
44 // that memory pool. The threshold can be set to any non-negative
45 // value.
46 //
47 // The default threshold of the Hotspot memory pools are:
48 // Eden space -1
49 // Survivor space 1 -1
50 // Survivor space 2 -1
51 // Old generation 0
52 // Perm generation 0
53 // CodeCache 0
54 //
55 // For heap memory, detection will be performed when GC finishes
56 // and also in the slow path allocation.
57 // For Code cache, detection will be performed in the allocation
58 // and deallocation.
59 //
60 // May need to deal with hysteresis effect.
61 //
62 // Memory detection code runs in the Notification thread (notificationThread.hpp).
63
64 class OopClosure;
65 class MemoryPool;
66
67 class ThresholdSupport : public CHeapObj<mtInternal> {
68 private:
69 bool _support_high_threshold;
70 bool _support_low_threshold;
71 size_t _high_threshold;
72 size_t _low_threshold;
73 public:
74 ThresholdSupport(bool support_high, bool support_low) {
75 _support_high_threshold = support_high;
76 _support_low_threshold = support_low;
77 _high_threshold = 0;
78 _low_threshold= 0;
79 }
80
81 size_t high_threshold() const { return _high_threshold; }
82 size_t low_threshold() const { return _low_threshold; }
196 // The sensor will be cleared if:
197 // (1) the usage is crossing below the low threshold and
198 // the sensor is currently on; or
199 // (2) the usage is crossing below the low threshold and
200 // the sensor will be on (i.e. sensor is currently off
201 // and has pending trigger requests).
202 //
203 void set_counter_sensor_level(MemoryUsage usage, ThresholdSupport* counter_threshold);
204
205 void process_pending_requests(TRAPS);
206 void oops_do(OopClosure* f);
207
208 #ifndef PRODUCT
209 // printing on default output stream;
210 void print();
211 #endif // PRODUCT
212 };
213
214 class LowMemoryDetector : public AllStatic {
215 friend class LowMemoryDetectorDisabler;
216 friend class NotificationThread;
217 private:
218 // true if any collected heap has low memory detection enabled
219 static volatile bool _enabled_for_collected_pools;
220 // > 0 if temporary disabed
221 static volatile jint _disabled_count;
222
223 static void check_memory_usage();
224 static bool has_pending_requests();
225 static bool temporary_disabled() { return _disabled_count > 0; }
226 static void disable() { Atomic::inc(&_disabled_count); }
227 static void enable() { Atomic::dec(&_disabled_count); }
228 static void process_sensor_changes(TRAPS);
229
230 public:
231 static void detect_low_memory();
232 static void detect_low_memory(MemoryPool* pool);
233 static void detect_after_gc_memory(MemoryPool* pool);
234
235 static bool is_enabled(MemoryPool* pool) {
236 // low memory detection is enabled for collected memory pools
|