annotate src/share/vm/services/lowMemoryDetector.hpp @ 2195:bf8517f4e4d0

6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread" Summary: Defer posting events from the compiler thread: use service thread Reviewed-by: coleenp, dholmes, never, dcubed
author kamg
date Wed, 02 Feb 2011 14:38:01 -0500
parents f95d63e2154a
children d2a62e0f25eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1972
diff changeset
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_SERVICES_LOWMEMORYDETECTOR_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_SERVICES_LOWMEMORYDETECTOR_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "services/memoryPool.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "services/memoryService.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Low Memory Detection Support
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Two memory alarms in the JDK (we called them sensors).
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // - Heap memory sensor
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // - Non-heap memory sensor
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // When the VM detects if the memory usage of a memory pool has reached
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // or exceeded its threshold, it will trigger the sensor for the type
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // of the memory pool (heap or nonheap or both).
a61af66fc99e Initial load
duke
parents:
diff changeset
39 //
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // If threshold == -1, no low memory detection is supported and
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // the threshold value is not allowed to be changed.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // If threshold == 0, no low memory detection is performed for
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // that memory pool. The threshold can be set to any non-negative
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // value.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // The default threshold of the Hotspot memory pools are:
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Eden space -1
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Survivor space 1 -1
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Survivor space 2 -1
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Old generation 0
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Perm generation 0
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // CodeCache 0
a61af66fc99e Initial load
duke
parents:
diff changeset
53 //
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // For heap memory, detection will be performed when GC finishes
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // and also in the slow path allocation.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // For Code cache, detection will be performed in the allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // and deallocation.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // May need to deal with hysteresis effect.
a61af66fc99e Initial load
duke
parents:
diff changeset
60 //
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1972
diff changeset
61 // Memory detection code runs in the Service thread (serviceThread.hpp).
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 class OopClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 class MemoryPool;
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 class ThresholdSupport : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
68 bool _support_high_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 bool _support_low_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 size_t _high_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 size_t _low_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 ThresholdSupport(bool support_high, bool support_low) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _support_high_threshold = support_high;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _support_low_threshold = support_low;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _high_threshold = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _low_threshold= 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 size_t high_threshold() const { return _high_threshold; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 size_t low_threshold() const { return _low_threshold; }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 bool is_high_threshold_supported() { return _support_high_threshold; }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 bool is_low_threshold_supported() { return _support_low_threshold; }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 bool is_high_threshold_crossed(MemoryUsage usage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (_support_high_threshold && _high_threshold > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return (usage.used() >= _high_threshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 bool is_low_threshold_crossed(MemoryUsage usage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (_support_low_threshold && _low_threshold > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return (usage.used() < _low_threshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 size_t set_high_threshold(size_t new_threshold) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 assert(_support_high_threshold, "can only be set if supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 assert(new_threshold >= _low_threshold, "new_threshold must be >= _low_threshold");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 size_t prev = _high_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _high_threshold = new_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 size_t set_low_threshold(size_t new_threshold) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(_support_low_threshold, "can only be set if supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 assert(new_threshold <= _high_threshold, "new_threshold must be <= _high_threshold");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 size_t prev = _low_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 _low_threshold = new_threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 };
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 class SensorInfo : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
117 instanceOop _sensor_obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 bool _sensor_on;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 size_t _sensor_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // before the actual sensor on flag and sensor count are set
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // we maintain the number of pending triggers and clears.
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // _pending_trigger_count means the number of pending triggers
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // and the sensor count should be incremented by the same number.
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 int _pending_trigger_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // _pending_clear_count takes precedence if it's > 0 which
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // indicates the resulting sensor will be off
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Sensor trigger requests will reset this clear count to
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // indicate the resulting flag should be on.
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 int _pending_clear_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 MemoryUsage _usage;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void clear(int count, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void trigger(int count, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
140 SensorInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 void set_sensor(instanceOop sensor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 assert(_sensor_obj == NULL, "Should be set only once");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _sensor_obj = sensor;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 bool has_pending_requests() {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return (_pending_trigger_count > 0 || _pending_clear_count > 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int pending_trigger_count() { return _pending_trigger_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 int pending_clear_count() { return _pending_clear_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // When this method is used, the memory usage is monitored
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // as a gauge attribute. High and low thresholds are designed
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // to provide a hysteresis mechanism to avoid repeated triggering
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // of notifications when the attribute value makes small oscillations
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // around the high or low threshold value.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 //
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // The sensor will be triggered if:
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // (1) the usage is crossing above the high threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // the sensor is currently off and no pending
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // trigger requests; or
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // (2) the usage is crossing above the high threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // the sensor will be off (i.e. sensor is currently on
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // and has pending clear requests).
a61af66fc99e Initial load
duke
parents:
diff changeset
166 //
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Subsequent crossings of the high threshold value do not cause
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // any triggers unless the usage becomes less than the low threshold.
a61af66fc99e Initial load
duke
parents:
diff changeset
169 //
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // The sensor will be cleared if:
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // (1) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // the sensor is currently on and no pending
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // clear requests; or
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // (2) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // the sensor will be on (i.e. sensor is currently off
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // and has pending trigger requests).
a61af66fc99e Initial load
duke
parents:
diff changeset
177 //
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Subsequent crossings of the low threshold value do not cause
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // any clears unless the usage becomes greater than or equal
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // to the high threshold.
a61af66fc99e Initial load
duke
parents:
diff changeset
181 //
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // If the current level is between high and low threhsold, no change.
a61af66fc99e Initial load
duke
parents:
diff changeset
183 //
a61af66fc99e Initial load
duke
parents:
diff changeset
184 void set_gauge_sensor_level(MemoryUsage usage, ThresholdSupport* high_low_threshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // When this method is used, the memory usage is monitored as a
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // simple counter attribute. The sensor will be triggered
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // whenever the usage is crossing the threshold to keep track
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // of the number of times the VM detects such a condition occurs.
a61af66fc99e Initial load
duke
parents:
diff changeset
190 //
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // The sensor will be triggered if:
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // - the usage is crossing above the high threshold regardless
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // of the current sensor state.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 //
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // The sensor will be cleared if:
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // (1) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // the sensor is currently on; or
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // (2) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // the sensor will be on (i.e. sensor is currently off
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // and has pending trigger requests).
a61af66fc99e Initial load
duke
parents:
diff changeset
201 //
a61af66fc99e Initial load
duke
parents:
diff changeset
202 void set_counter_sensor_level(MemoryUsage usage, ThresholdSupport* counter_threshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 void process_pending_requests(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // printing on default output stream;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
211 };
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 class LowMemoryDetector : public AllStatic {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1972
diff changeset
214 friend class LowMemoryDetectorDisabler;
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1972
diff changeset
215 friend class ServiceThread;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
216 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // true if any collected heap has low memory detection enabled
a61af66fc99e Initial load
duke
parents:
diff changeset
218 static volatile bool _enabled_for_collected_pools;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // > 0 if temporary disabed
a61af66fc99e Initial load
duke
parents:
diff changeset
220 static volatile jint _disabled_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 static void check_memory_usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
223 static bool has_pending_requests();
a61af66fc99e Initial load
duke
parents:
diff changeset
224 static bool temporary_disabled() { return _disabled_count > 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 static void disable() { Atomic::inc(&_disabled_count); }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 static void enable() { Atomic::dec(&_disabled_count); }
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1972
diff changeset
227 static void process_sensor_changes(TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
230 static void detect_low_memory();
a61af66fc99e Initial load
duke
parents:
diff changeset
231 static void detect_low_memory(MemoryPool* pool);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 static void detect_after_gc_memory(MemoryPool* pool);
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 static bool is_enabled(MemoryPool* pool) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // low memory detection is enabled for collected memory pools
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // iff one of the collected memory pool has a sensor and the
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // threshold set non-zero
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (pool->usage_sensor() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 ThresholdSupport* threshold_support = pool->usage_threshold();
a61af66fc99e Initial load
duke
parents:
diff changeset
242 return (threshold_support->is_high_threshold_supported() ?
a61af66fc99e Initial load
duke
parents:
diff changeset
243 (threshold_support->high_threshold() > 0) : false);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // indicates if low memory detection is enabled for any collected
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // memory pools
a61af66fc99e Initial load
duke
parents:
diff changeset
249 static inline bool is_enabled_for_collected_pools() {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 return !temporary_disabled() && _enabled_for_collected_pools;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // recompute enabled flag
a61af66fc99e Initial load
duke
parents:
diff changeset
254 static void recompute_enabled_for_collected_pools();
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // low memory detection for collected memory pools.
a61af66fc99e Initial load
duke
parents:
diff changeset
257 static inline void detect_low_memory_for_collected_pools() {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // no-op if low memory detection not enabled
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (!is_enabled_for_collected_pools()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 int num_memory_pools = MemoryService::num_memory_pools();
a61af66fc99e Initial load
duke
parents:
diff changeset
263 for (int i=0; i<num_memory_pools; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 MemoryPool* pool = MemoryService::get_memory_pool(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // if low memory detection is enabled then check if the
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // current used exceeds the high threshold
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (pool->is_collected_pool() && is_enabled(pool)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 size_t used = pool->used_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 size_t high = pool->usage_threshold()->high_threshold();
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if (used > high) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 detect_low_memory(pool);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 };
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 class LowMemoryDetectorDisabler: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
281 LowMemoryDetectorDisabler()
a61af66fc99e Initial load
duke
parents:
diff changeset
282 {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 LowMemoryDetector::disable();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 ~LowMemoryDetectorDisabler()
a61af66fc99e Initial load
duke
parents:
diff changeset
286 {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 assert(LowMemoryDetector::temporary_disabled(), "should be disabled!");
a61af66fc99e Initial load
duke
parents:
diff changeset
288 LowMemoryDetector::enable();
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
291
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
292 #endif // SHARE_VM_SERVICES_LOWMEMORYDETECTOR_HPP