annotate src/share/vm/services/lowMemoryDetector.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents bf8517f4e4d0
children 203f64878aab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2195
diff changeset
2 * Copyright (c) 2003, 2012, 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: 1142
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
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: 1142
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 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "classfile/vmSymbols.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "runtime/interfaceSupport.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/java.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/javaCalls.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/mutex.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "services/lowMemoryDetector.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "services/management.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 volatile bool LowMemoryDetector::_enabled_for_collected_pools = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 volatile jint LowMemoryDetector::_disabled_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 bool LowMemoryDetector::has_pending_requests() {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
41 assert(Service_lock->owned_by_self(), "Must own Service_lock");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
42 bool has_requests = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 int num_memory_pools = MemoryService::num_memory_pools();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 for (int i = 0; i < num_memory_pools; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 MemoryPool* pool = MemoryService::get_memory_pool(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 SensorInfo* sensor = pool->usage_sensor();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 if (sensor != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 has_requests = has_requests || sensor->has_pending_requests();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 SensorInfo* gc_sensor = pool->gc_usage_sensor();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 if (gc_sensor != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 has_requests = has_requests || gc_sensor->has_pending_requests();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 return has_requests;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
59 void LowMemoryDetector::process_sensor_changes(TRAPS) {
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
60 ResourceMark rm(THREAD);
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
61 HandleMark hm(THREAD);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
63 // No need to hold Service_lock to call out to Java
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
64 int num_memory_pools = MemoryService::num_memory_pools();
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
65 for (int i = 0; i < num_memory_pools; i++) {
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
66 MemoryPool* pool = MemoryService::get_memory_pool(i);
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
67 SensorInfo* sensor = pool->usage_sensor();
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
68 SensorInfo* gc_sensor = pool->gc_usage_sensor();
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
69 if (sensor != NULL && sensor->has_pending_requests()) {
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
70 sensor->process_pending_requests(CHECK);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
72 if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
73 gc_sensor->process_pending_requests(CHECK);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // This method could be called from any Java threads
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // and also VMThread.
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void LowMemoryDetector::detect_low_memory() {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
81 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 bool has_pending_requests = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int num_memory_pools = MemoryService::num_memory_pools();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 for (int i = 0; i < num_memory_pools; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 MemoryPool* pool = MemoryService::get_memory_pool(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 SensorInfo* sensor = pool->usage_sensor();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (sensor != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
89 pool->usage_threshold()->is_high_threshold_supported() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
90 pool->usage_threshold()->high_threshold() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 MemoryUsage usage = pool->get_memory_usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 sensor->set_gauge_sensor_level(usage,
a61af66fc99e Initial load
duke
parents:
diff changeset
93 pool->usage_threshold());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 has_pending_requests = has_pending_requests || sensor->has_pending_requests();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (has_pending_requests) {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
99 Service_lock->notify_all();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // This method could be called from any Java threads
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // and also VMThread.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void LowMemoryDetector::detect_low_memory(MemoryPool* pool) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 SensorInfo* sensor = pool->usage_sensor();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (sensor == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
108 !pool->usage_threshold()->is_high_threshold_supported() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
109 pool->usage_threshold()->high_threshold() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
114 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 MemoryUsage usage = pool->get_memory_usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 sensor->set_gauge_sensor_level(usage,
a61af66fc99e Initial load
duke
parents:
diff changeset
118 pool->usage_threshold());
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (sensor->has_pending_requests()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // notify sensor state update
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
121 Service_lock->notify_all();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Only called by VMThread at GC time
a61af66fc99e Initial load
duke
parents:
diff changeset
127 void LowMemoryDetector::detect_after_gc_memory(MemoryPool* pool) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 SensorInfo* sensor = pool->gc_usage_sensor();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (sensor == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
130 !pool->gc_usage_threshold()->is_high_threshold_supported() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
131 pool->gc_usage_threshold()->high_threshold() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
136 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 MemoryUsage usage = pool->get_last_collection_usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 sensor->set_counter_sensor_level(usage, pool->gc_usage_threshold());
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (sensor->has_pending_requests()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // notify sensor state update
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
143 Service_lock->notify_all();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // recompute enabled flag
a61af66fc99e Initial load
duke
parents:
diff changeset
149 void LowMemoryDetector::recompute_enabled_for_collected_pools() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 bool enabled = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 int num_memory_pools = MemoryService::num_memory_pools();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 for (int i=0; i<num_memory_pools; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 MemoryPool* pool = MemoryService::get_memory_pool(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (pool->is_collected_pool() && is_enabled(pool)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 enabled = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 _enabled_for_collected_pools = enabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 SensorInfo::SensorInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 _sensor_obj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 _sensor_on = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _sensor_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _pending_trigger_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 _pending_clear_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // When this method is used, the memory usage is monitored
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // as a gauge attribute. Sensor notifications (trigger or
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // clear) is only emitted at the first time it crosses
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // a threshold.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 //
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // High and low thresholds are designed to provide a
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // hysteresis mechanism to avoid repeated triggering
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // of notifications when the attribute value makes small oscillations
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // around the high or low threshold value.
a61af66fc99e Initial load
duke
parents:
diff changeset
179 //
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // The sensor will be triggered if:
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // (1) the usage is crossing above the high threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // the sensor is currently off and no pending
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // trigger requests; or
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // (2) the usage is crossing above the high threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // the sensor will be off (i.e. sensor is currently on
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // and has pending clear requests).
a61af66fc99e Initial load
duke
parents:
diff changeset
187 //
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Subsequent crossings of the high threshold value do not cause
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // any triggers unless the usage becomes less than the low threshold.
a61af66fc99e Initial load
duke
parents:
diff changeset
190 //
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // The sensor will be cleared if:
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // (1) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // the sensor is currently on and no pending
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // clear requests; or
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // (2) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // the sensor will be on (i.e. sensor is currently off
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // and has pending trigger requests).
a61af66fc99e Initial load
duke
parents:
diff changeset
198 //
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Subsequent crossings of the low threshold value do not cause
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // any clears unless the usage becomes greater than or equal
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // to the high threshold.
a61af66fc99e Initial load
duke
parents:
diff changeset
202 //
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // If the current level is between high and low threhsold, no change.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 //
a61af66fc99e Initial load
duke
parents:
diff changeset
205 void SensorInfo::set_gauge_sensor_level(MemoryUsage usage, ThresholdSupport* high_low_threshold) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 assert(high_low_threshold->is_high_threshold_supported(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 bool is_over_high = high_low_threshold->is_high_threshold_crossed(usage);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 bool is_below_low = high_low_threshold->is_low_threshold_crossed(usage);
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 assert(!(is_over_high && is_below_low), "Can't be both true");
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (is_over_high &&
a61af66fc99e Initial load
duke
parents:
diff changeset
214 ((!_sensor_on && _pending_trigger_count == 0) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
215 _pending_clear_count > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // low memory detected and need to increment the trigger pending count
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // if the sensor is off or will be off due to _pending_clear_ > 0
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Request to trigger the sensor
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _pending_trigger_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 _usage = usage;
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (_pending_clear_count > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // non-zero pending clear requests indicates that there are
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // pending requests to clear this sensor.
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // This trigger request needs to clear this clear count
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // since the resulting sensor flag should be on.
a61af66fc99e Initial load
duke
parents:
diff changeset
227 _pending_clear_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 } else if (is_below_low &&
a61af66fc99e Initial load
duke
parents:
diff changeset
230 ((_sensor_on && _pending_clear_count == 0) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
231 (_pending_trigger_count > 0 && _pending_clear_count == 0))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // memory usage returns below the threshold
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // Request to clear the sensor if the sensor is on or will be on due to
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // _pending_trigger_count > 0 and also no clear request
a61af66fc99e Initial load
duke
parents:
diff changeset
235 _pending_clear_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // When this method is used, the memory usage is monitored as a
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // simple counter attribute. The sensor will be triggered
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // whenever the usage is crossing the threshold to keep track
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // of the number of times the VM detects such a condition occurs.
a61af66fc99e Initial load
duke
parents:
diff changeset
243 //
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // High and low thresholds are designed to provide a
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // hysteresis mechanism to avoid repeated triggering
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // of notifications when the attribute value makes small oscillations
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // around the high or low threshold value.
a61af66fc99e Initial load
duke
parents:
diff changeset
248 //
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // The sensor will be triggered if:
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // - the usage is crossing above the high threshold regardless
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // of the current sensor state.
a61af66fc99e Initial load
duke
parents:
diff changeset
252 //
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // The sensor will be cleared if:
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // (1) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // the sensor is currently on; or
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // (2) the usage is crossing below the low threshold and
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // the sensor will be on (i.e. sensor is currently off
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // and has pending trigger requests).
a61af66fc99e Initial load
duke
parents:
diff changeset
259 void SensorInfo::set_counter_sensor_level(MemoryUsage usage, ThresholdSupport* counter_threshold) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 assert(counter_threshold->is_high_threshold_supported(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 bool is_over_high = counter_threshold->is_high_threshold_crossed(usage);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 bool is_below_low = counter_threshold->is_low_threshold_crossed(usage);
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 assert(!(is_over_high && is_below_low), "Can't be both true");
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (is_over_high) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 _pending_trigger_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 _usage = usage;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 _pending_clear_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 } else if (is_below_low && (_sensor_on || _pending_trigger_count > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 _pending_clear_count++;
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 void SensorInfo::oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 f->do_oop((oop*) &_sensor_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 void SensorInfo::process_pending_requests(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 if (!has_pending_requests()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 int pending_count = pending_trigger_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (pending_clear_count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 clear(pending_count, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
288 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 trigger(pending_count, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void SensorInfo::trigger(int count, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 assert(count <= _pending_trigger_count, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (_sensor_obj != NULL) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2195
diff changeset
298 Klass* k = Management::sun_management_Sensor_klass(CHECK);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
299 instanceKlassHandle sensorKlass (THREAD, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 Handle sensor_h(THREAD, _sensor_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 JavaValue result(T_VOID);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 JavaCallArguments args(sensor_h);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 args.push_int((int) count);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 args.push_oop(usage_h);
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 JavaCalls::call_virtual(&result,
a61af66fc99e Initial load
duke
parents:
diff changeset
309 sensorKlass,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
310 vmSymbols::trigger_name(),
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
311 vmSymbols::trigger_method_signature(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
312 &args,
a61af66fc99e Initial load
duke
parents:
diff changeset
313 CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
317 // Holds Service_lock and update the sensor state
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
318 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
319 _sensor_on = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 _sensor_count += count;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 _pending_trigger_count = _pending_trigger_count - count;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 }
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 void SensorInfo::clear(int count, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (_sensor_obj != NULL) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2195
diff changeset
327 Klass* k = Management::sun_management_Sensor_klass(CHECK);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
328 instanceKlassHandle sensorKlass (THREAD, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 Handle sensor(THREAD, _sensor_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 JavaValue result(T_VOID);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 JavaCallArguments args(sensor);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 args.push_int((int) count);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 JavaCalls::call_virtual(&result,
a61af66fc99e Initial load
duke
parents:
diff changeset
335 sensorKlass,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
336 vmSymbols::clear_name(),
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
337 vmSymbols::int_void_signature(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
338 &args,
a61af66fc99e Initial load
duke
parents:
diff changeset
339 CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 {
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
343 // Holds Service_lock and update the sensor state
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 2177
diff changeset
344 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
345 _sensor_on = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 _pending_clear_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 _pending_trigger_count = _pending_trigger_count - count;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 //--------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
355 void SensorInfo::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 tty->print_cr("%s count = %ld pending_triggers = %ld pending_clears = %ld",
a61af66fc99e Initial load
duke
parents:
diff changeset
357 (_sensor_on ? "on" : "off"),
a61af66fc99e Initial load
duke
parents:
diff changeset
358 _sensor_count, _pending_trigger_count, _pending_clear_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 #endif // PRODUCT