J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.lang.management; |
| 27 | |
| 28 | /** |
| 29 | * The management interface for a memory pool. A memory pool |
| 30 | * represents the memory resource managed by the Java virtual machine |
| 31 | * and is managed by one or more {@link MemoryManagerMXBean memory managers}. |
| 32 | * |
| 33 | * <p> A Java virtual machine has one or more instances of the |
| 34 | * implementation class of this interface. An instance |
| 35 | * implementing this interface is |
| 36 | * an <a href="ManagementFactory.html#MXBean">MXBean</a> |
| 37 | * that can be obtained by calling |
| 38 | * the {@link ManagementFactory#getMemoryPoolMXBeans} method or |
| 39 | * from the {@link ManagementFactory#getPlatformMBeanServer |
| 40 | * platform <tt>MBeanServer</tt>} method. |
| 41 | * |
| 42 | * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for |
| 43 | * a memory pool within an <tt>MBeanServer</tt> is: |
| 44 | * <blockquote> |
| 45 | * {@link ManagementFactory#MEMORY_POOL_MXBEAN_DOMAIN_TYPE |
| 46 | * <tt>java.lang:type=MemoryPool</tt>}<tt>,name=</tt><i>pool's name</i> |
| 47 | * </blockquote> |
| 48 | * |
| 49 | * <h4>Memory Type</h4> |
| 50 | * <p>The Java virtual machine has a heap for object allocation and also |
| 51 | * maintains non-heap memory for the method area and the Java virtual |
| 52 | * machine execution. The Java virtual machine can have one or more |
| 53 | * memory pools. Each memory pool represents a memory area |
| 54 | * of one of the following types: |
| 55 | * <ul> |
| 56 | * <li>{@link MemoryType#HEAP heap}</li> |
| 57 | * <li>{@link MemoryType#NON_HEAP non-heap}</li> |
| 58 | * </ul> |
| 59 | * |
| 60 | * <h4>Memory Usage Monitoring</h4> |
| 61 | * |
| 62 | * A memory pool has the following attributes: |
| 63 | * <ul> |
| 64 | * <li><a href="#Usage">Memory usage</a></li> |
| 65 | * <li><a href="#PeakUsage">Peak memory usage</a></li> |
| 66 | * <li><a href="#UsageThreshold">Usage Threshold</a></li> |
| 67 | * <li><a href="#CollectionThreshold">Collection Usage Threshold</a> |
| 68 | * (only supported by some <em>garbage-collected</em> memory pools)</li> |
| 69 | * </ul> |
| 70 | * |
| 71 | * <h4><a name="Usage">1. Memory Usage</a></h4> |
| 72 | * |
| 73 | * The {@link #getUsage} method provides an estimate |
| 74 | * of the current usage of a memory pool. |
| 75 | * For a garbage-collected memory pool, the amount of used memory |
| 76 | * includes the memory occupied by all objects in the pool |
| 77 | * including both <em>reachable</em> and <em>unreachable</em> objects. |
| 78 | * |
| 79 | * <p>In general, this method is a lightweight operation for getting |
| 80 | * an approximate memory usage. For some memory pools, for example, |
| 81 | * when objects are not packed contiguously, this method may be |
| 82 | * an expensive operation that requires some computation to determine |
| 83 | * the current memory usage. An implementation should document when |
| 84 | * this is the case. |
| 85 | * |
| 86 | * <h4><a name="PeakUsage">2. Peak Memory Usage</a></h4> |
| 87 | * |
| 88 | * The Java virtual machine maintains the peak memory usage of a memory |
| 89 | * pool since the virtual machine was started or the peak was reset. |
| 90 | * The peak memory usage is returned by the {@link #getPeakUsage} method |
| 91 | * and reset by calling the {@link #resetPeakUsage} method. |
| 92 | * |
| 93 | * <h4><a name="UsageThreshold">3. Usage Threshold</a></h4> |
| 94 | * |
| 95 | * Each memory pool has a manageable attribute |
| 96 | * called the <i>usage threshold</i> which has a default value supplied |
| 97 | * by the Java virtual machine. The default value is platform-dependent. |
| 98 | * The usage threshold can be set via the |
| 99 | * {@link #setUsageThreshold setUsageThreshold} method. |
| 100 | * If the threshold is set to a positive value, the usage threshold crossing |
| 101 | * checking is enabled in this memory pool. |
| 102 | * If the usage threshold is set to zero, usage |
| 103 | * threshold crossing checking on this memory pool is disabled. |
| 104 | * The {@link MemoryPoolMXBean#isUsageThresholdSupported} method can |
| 105 | * be used to determine if this functionality is supported. |
| 106 | * <p> |
| 107 | * A Java virtual machine performs usage threshold crossing checking on a |
| 108 | * memory pool basis at its best appropriate time, typically, |
| 109 | * at garbage collection time. |
| 110 | * Each memory pool maintains a {@link #getUsageThresholdCount |
| 111 | * usage threshold count} that will get incremented |
| 112 | * every time when the Java virtual machine |
| 113 | * detects that the memory pool usage is crossing the threshold. |
| 114 | * <p> |
| 115 | * This manageable usage threshold attribute is designed for monitoring the |
| 116 | * increasing trend of memory usage with low overhead. |
| 117 | * Usage threshold may not be appropriate for some memory pools. |
| 118 | * For example, a generational garbage collector, a common garbage collection |
| 119 | * algorithm used in many Java virtual machine implementations, |
| 120 | * manages two or more generations segregating objects by age. |
| 121 | * Most of the objects are allocated in |
| 122 | * the <em>youngest generation</em> (say a nursery memory pool). |
| 123 | * The nursery memory pool is designed to be filled up and |
| 124 | * collecting the nursery memory pool will free most of its memory space |
| 125 | * since it is expected to contain mostly short-lived objects |
| 126 | * and mostly are unreachable at garbage collection time. |
| 127 | * In this case, it is more appropriate for the nursery memory pool |
| 128 | * not to support a usage threshold. In addition, |
| 129 | * if the cost of an object allocation |
| 130 | * in one memory pool is very low (for example, just atomic pointer exchange), |
| 131 | * the Java virtual machine would probably not support the usage threshold |
| 132 | * for that memory pool since the overhead in comparing the usage with |
| 133 | * the threshold is higher than the cost of object allocation. |
| 134 | * |
| 135 | * <p> |
| 136 | * The memory usage of the system can be monitored using |
| 137 | * <a href="#Polling">polling</a> or |
| 138 | * <a href="#ThresholdNotification">threshold notification</a> mechanisms. |
| 139 | * |
| 140 | * <ol type="a"> |
| 141 | * <li><a name="Polling"><b>Polling</b></a> |
| 142 | * <p> |
| 143 | * An application can continuously monitor its memory usage |
| 144 | * by calling either the {@link #getUsage} method for all |
| 145 | * memory pools or the {@link #isUsageThresholdExceeded} method |
| 146 | * for those memory pools that support a usage threshold. |
| 147 | * Below is example code that has a thread delicated for |
| 148 | * task distribution and processing. At every interval, |
| 149 | * it will determine if it should receive and process new tasks based |
| 150 | * on its memory usage. If the memory usage exceeds its usage threshold, |
| 151 | * it will redistribute all outstanding tasks to other VMs and |
| 152 | * stop receiving new tasks until the memory usage returns |
| 153 | * below its usage threshold. |
| 154 | * |
| 155 | * <pre> |
| 156 | * // Assume the usage threshold is supported for this pool. |
| 157 | * // Set the threshold to myThreshold above which no new tasks |
| 158 | * // should be taken. |
| 159 | * pool.setUsageThreshold(myThreshold); |
| 160 | * .... |
| 161 | * |
| 162 | * boolean lowMemory = false; |
| 163 | * while (true) { |
| 164 | * if (pool.isUsageThresholdExceeded()) { |
| 165 | * // potential low memory, so redistribute tasks to other VMs |
| 166 | * lowMemory = true; |
| 167 | * redistributeTasks(); |
| 168 | * // stop receiving new tasks |
| 169 | * stopReceivingTasks(); |
| 170 | * } else { |
| 171 | * if (lowMemory) { |
| 172 | * // resume receiving tasks |
| 173 | * lowMemory = false; |
| 174 | * resumeReceivingTasks(); |
| 175 | * } |
| 176 | * // processing outstanding task |
| 177 | * ... |
| 178 | * } |
| 179 | * // sleep for sometime |
| 180 | * try { |
| 181 | * Thread.sleep(sometime); |
| 182 | * } catch (InterruptedException e) { |
| 183 | * ... |
| 184 | * } |
| 185 | * } |
| 186 | * </pre> |
| 187 | * |
| 188 | * <hr> |
| 189 | * The above example does not differentiate the case where |
| 190 | * the memory usage has temporarily dropped below the usage threshold |
| 191 | * from the case where the memory usage remains above the threshould |
| 192 | * between two iterations. The usage threshold count returned by |
| 193 | * the {@link #getUsageThresholdCount} method |
| 194 | * can be used to determine |
| 195 | * if the memory usage has returned below the threshold |
| 196 | * between two polls. |
| 197 | * <p> |
| 198 | * Below shows another example that takes some action if a |
| 199 | * memory pool is under low memory and ignores the memory usage |
| 200 | * changes during the action processing time. |
| 201 | * |
| 202 | * <pre> |
| 203 | * // Assume the usage threshold is supported for this pool. |
| 204 | * // Set the threshold to myThreshold which determines if |
| 205 | * // the application will take some action under low memory condition. |
| 206 | * pool.setUsageThreshold(myThreshold); |
| 207 | * |
| 208 | * int prevCrossingCount = 0; |
| 209 | * while (true) { |
| 210 | * // A busy loop to detect when the memory usage |
| 211 | * // has exceeded the threshold. |
| 212 | * while (!pool.isUsageThresholdExceeded() || |
| 213 | * pool.getUsageThresholdCount() == prevCrossingCount) { |
| 214 | * try { |
| 215 | * Thread.sleep(sometime) |
| 216 | * } catch (InterruptException e) { |
| 217 | * .... |
| 218 | * } |
| 219 | * } |
| 220 | * |
| 221 | * // Do some processing such as check for memory usage |
| 222 | * // and issue a warning |
| 223 | * .... |
| 224 | * |
| 225 | * // Gets the current threshold count. The busy loop will then |
| 226 | * // ignore any crossing of threshold happens during the processing. |
| 227 | * prevCrossingCount = pool.getUsageThresholdCount(); |
| 228 | * } |
| 229 | * </pre><hr> |
| 230 | * </li> |
| 231 | * <li><a name="ThresholdNotification"><b>Usage Threshold Notifications</b></a> |
| 232 | * <p> |
| 233 | * Usage threshold notification will be emitted by {@link MemoryMXBean}. |
| 234 | * When the Java virtual machine detects that the memory usage of |
| 235 | * a memory pool has reached or exceeded the usage threshold |
| 236 | * the virtual machine will trigger the <tt>MemoryMXBean</tt> to emit an |
| 237 | * {@link MemoryNotificationInfo#MEMORY_THRESHOLD_EXCEEDED |
| 238 | * usage threshold exceeded notification}. |
| 239 | * Another usage threshold exceeded notification will not be |
| 240 | * generated until the usage has fallen below the threshold and |
| 241 | * then exceeded it again. |
| 242 | * <p> |
| 243 | * Below is an example code implementing the same logic as the |
| 244 | * first example above but using the usage threshold notification |
| 245 | * mechanism to detect low memory conditions instead of polling. |
| 246 | * In this example code, upon receiving notification, the notification |
| 247 | * listener notifies another thread to perform the actual action |
| 248 | * such as to redistribute outstanding tasks, stop receiving tasks, |
| 249 | * or resume receiving tasks. |
| 250 | * The <tt>handleNotification</tt> method should be designed to |
| 251 | * do a very minimal amount of work and return without delay to avoid |
| 252 | * causing delay in delivering subsequent notifications. Time-consuming |
| 253 | * actions should be performed by a separate thread. |
| 254 | * The notification listener may be invoked by multiple threads |
| 255 | * concurrently; so the tasks performed by the listener |
| 256 | * should be properly synchronized. |
| 257 | * |
| 258 | * <pre> |
| 259 | * class MyListener implements javax.management.NotificationListener { |
| 260 | * public void handleNotification(Notification notification, Object handback) { |
| 261 | * String notifType = notification.getType(); |
| 262 | * if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) { |
| 263 | * // potential low memory, notify another thread |
| 264 | * // to redistribute outstanding tasks to other VMs |
| 265 | * // and stop receiving new tasks. |
| 266 | * lowMemory = true; |
| 267 | * notifyAnotherThread(lowMemory); |
| 268 | * } |
| 269 | * } |
| 270 | * } |
| 271 | * |
| 272 | * // Register MyListener with MemoryMXBean |
| 273 | * MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); |
| 274 | * NotificationEmitter emitter = (NotificationEmitter) mbean; |
| 275 | * MyListener listener = new MyListener(); |
| 276 | * emitter.addNotificationListener(listener, null, null); |
| 277 | * |
| 278 | * // Assume this pool supports a usage threshold. |
| 279 | * // Set the threshold to myThreshold above which no new tasks |
| 280 | * // should be taken. |
| 281 | * pool.setUsageThreshold(myThreshold); |
| 282 | * |
| 283 | * // Usage threshold detection is enabled and notification will be |
| 284 | * // handled by MyListener. Continue for other processing. |
| 285 | * .... |
| 286 | * |
| 287 | * </pre> |
| 288 | * <hr> |
| 289 | * <p> |
| 290 | * There is no guarantee about when the <tt>MemoryMXBean</tt> will emit |
| 291 | * a threshold notification and when the notification will be delivered. |
| 292 | * When a notification listener is invoked, the memory usage of |
| 293 | * the memory pool may have crossed the usage threshold more |
| 294 | * than once. |
| 295 | * The {@link MemoryNotificationInfo#getCount} method returns the number |
| 296 | * of times that the memory usage has crossed the usage threshold |
| 297 | * at the point in time when the notification was constructed. |
| 298 | * It can be compared with the current usage threshold count returned |
| 299 | * by the {@link #getUsageThresholdCount} method to determine if |
| 300 | * such situation has occurred. |
| 301 | * </li> |
| 302 | * </ol> |
| 303 | * |
| 304 | * <h4><a name="CollectionThreshold">4. Collection Usage Threshold</a></h4> |
| 305 | * |
| 306 | * Collection usage threshold is a manageable attribute only applicable |
| 307 | * to some garbage-collected memory pools. |
| 308 | * After a Java virtual machine has expended effort in reclaiming memory |
| 309 | * space by recycling unused objects in a memory pool at garbage collection |
| 310 | * time, some number of bytes in the memory pools that are garbaged |
| 311 | * collected will still be in use. The collection usage threshold |
| 312 | * allows a value to be set for this number of bytes such |
| 313 | * that if the threshold is exceeded, |
| 314 | * a {@link MemoryNotificationInfo#MEMORY_THRESHOLD_EXCEEDED |
| 315 | * collection usage threshold exceeded notification} |
| 316 | * will be emitted by the {@link MemoryMXBean}. |
| 317 | * In addition, the {@link #getCollectionUsageThresholdCount |
| 318 | * collection usage threshold count} will then be incremented. |
| 319 | * |
| 320 | * <p> |
| 321 | * The {@link MemoryPoolMXBean#isCollectionUsageThresholdSupported} method can |
| 322 | * be used to determine if this functionality is supported. |
| 323 | * |
| 324 | * <p> |
| 325 | * A Java virtual machine performs collection usage threshold checking |
| 326 | * on a memory pool basis. This checking is enabled if the collection |
| 327 | * usage threshold is set to a positive value. |
| 328 | * If the collection usage threshold is set to zero, this checking |
| 329 | * is disabled on this memory pool. Default value is zero. |
| 330 | * The Java virtual machine performs the collection usage threshold |
| 331 | * checking at garbage collection time. |
| 332 | * |
| 333 | * <p> |
| 334 | * Some garbage-collected memory pools may |
| 335 | * choose not to support the collection usage threshold. For example, |
| 336 | * a memory pool is only managed by a continuous concurrent garbage |
| 337 | * collector. Objects can be allocated in this memory pool by some thread |
| 338 | * while the unused objects are reclaimed by the concurrent garbage |
| 339 | * collector simultaneously. Unless there is a well-defined |
| 340 | * garbage collection time which is the best appropriate time |
| 341 | * to check the memory usage, the collection usage threshold should not |
| 342 | * be supported. |
| 343 | * |
| 344 | * <p> |
| 345 | * The collection usage threshold is designed for monitoring the memory usage |
| 346 | * after the Java virtual machine has expended effort in reclaiming |
| 347 | * memory space. The collection usage could also be monitored |
| 348 | * by the polling and threshold notification mechanism |
| 349 | * described above for the <a href="#UsageThreshold">usage threshold</a> |
| 350 | * in a similar fashion. |
| 351 | * |
| 352 | * @see <a href="../../../javax/management/package-summary.html"> |
| 353 | * JMX Specification.</a> |
| 354 | * @see <a href="package-summary.html#examples"> |
| 355 | * Ways to Access MXBeans</a> |
| 356 | * |
| 357 | * @author Mandy Chung |
| 358 | * @since 1.5 |
| 359 | */ |
| 360 | public interface MemoryPoolMXBean { |
| 361 | /** |
| 362 | * Returns the name representing this memory pool. |
| 363 | * |
| 364 | * @return the name of this memory pool. |
| 365 | */ |
| 366 | public String getName(); |
| 367 | |
| 368 | /** |
| 369 | * Returns the type of this memory pool. |
| 370 | * |
| 371 | * <p> |
| 372 | * <b>MBeanServer access</b>:<br> |
| 373 | * The mapped type of <tt>MemoryType</tt> is <tt>String</tt> |
| 374 | * and the value is the name of the <tt>MemoryType</tt>. |
| 375 | * |
| 376 | * @return the type of this memory pool. |
| 377 | */ |
| 378 | public MemoryType getType(); |
| 379 | |
| 380 | /** |
| 381 | * Returns an estimate of the memory usage of this memory pool. |
| 382 | * This method returns <tt>null</tt> |
| 383 | * if this memory pool is not valid (i.e. no longer exists). |
| 384 | * |
| 385 | * <p> |
| 386 | * This method requests the Java virtual machine to make |
| 387 | * a best-effort estimate of the current memory usage of this |
| 388 | * memory pool. For some memory pools, this method may be an |
| 389 | * expensive operation that requires some computation to determine |
| 390 | * the estimate. An implementation should document when |
| 391 | * this is the case. |
| 392 | * |
| 393 | * <p>This method is designed for use in monitoring system |
| 394 | * memory usage and detecting low memory condition. |
| 395 | * |
| 396 | * <p> |
| 397 | * <b>MBeanServer access</b>:<br> |
| 398 | * The mapped type of <tt>MemoryUsage</tt> is |
| 399 | * <tt>CompositeData</tt> with attributes as specified in |
| 400 | * {@link MemoryUsage#from MemoryUsage}. |
| 401 | * |
| 402 | * @return a {@link MemoryUsage} object; or <tt>null</tt> if |
| 403 | * this pool not valid. |
| 404 | */ |
| 405 | public MemoryUsage getUsage(); |
| 406 | |
| 407 | /** |
| 408 | * Returns the peak memory usage of this memory pool since the |
| 409 | * Java virtual machine was started or since the peak was reset. |
| 410 | * This method returns <tt>null</tt> |
| 411 | * if this memory pool is not valid (i.e. no longer exists). |
| 412 | * |
| 413 | * <p> |
| 414 | * <b>MBeanServer access</b>:<br> |
| 415 | * The mapped type of <tt>MemoryUsage</tt> is |
| 416 | * <tt>CompositeData</tt> with attributes as specified in |
| 417 | * {@link MemoryUsage#from MemoryUsage}. |
| 418 | * |
| 419 | * @return a {@link MemoryUsage} object representing the peak |
| 420 | * memory usage; or <tt>null</tt> if this pool is not valid. |
| 421 | * |
| 422 | */ |
| 423 | public MemoryUsage getPeakUsage(); |
| 424 | |
| 425 | /** |
| 426 | * Resets the peak memory usage statistic of this memory pool |
| 427 | * to the current memory usage. |
| 428 | * |
| 429 | * @throws java.lang.SecurityException if a security manager |
| 430 | * exists and the caller does not have |
| 431 | * ManagementPermission("control"). |
| 432 | */ |
| 433 | public void resetPeakUsage(); |
| 434 | |
| 435 | /** |
| 436 | * Tests if this memory pool is valid in the Java virtual |
| 437 | * machine. A memory pool becomes invalid once the Java virtual |
| 438 | * machine removes it from the memory system. |
| 439 | * |
| 440 | * @return <tt>true</tt> if the memory pool is valid in the running |
| 441 | * Java virtual machine; |
| 442 | * <tt>false</tt> otherwise. |
| 443 | */ |
| 444 | public boolean isValid(); |
| 445 | |
| 446 | /** |
| 447 | * Returns the name of memory managers that manages this memory pool. |
| 448 | * Each memory pool will be managed by at least one memory manager. |
| 449 | * |
| 450 | * @return an array of <tt>String</tt> objects, each is the name of |
| 451 | * a memory manager managing this memory pool. |
| 452 | */ |
| 453 | public String[] getMemoryManagerNames(); |
| 454 | |
| 455 | /** |
| 456 | * Returns the usage threshold value of this memory pool in bytes. |
| 457 | * Each memory pool has a platform-dependent default threshold value. |
| 458 | * The current usage threshold can be changed via the |
| 459 | * {@link #setUsageThreshold setUsageThreshold} method. |
| 460 | * |
| 461 | * @return the usage threshold value of this memory pool in bytes. |
| 462 | * |
| 463 | * @throws UnsupportedOperationException if this memory pool |
| 464 | * does not support a usage threshold. |
| 465 | * |
| 466 | * @see #isUsageThresholdSupported |
| 467 | */ |
| 468 | public long getUsageThreshold(); |
| 469 | |
| 470 | /** |
| 471 | * Sets the threshold of this memory pool to the given <tt>threshold</tt> |
| 472 | * value if this memory pool supports the usage threshold. |
| 473 | * The usage threshold crossing checking is enabled in this memory pool |
| 474 | * if the threshold is set to a positive value. |
| 475 | * The usage threshold crossing checking is disabled |
| 476 | * if it is set to zero. |
| 477 | * |
| 478 | * @param threshold the new threshold value in bytes. Must be non-negative. |
| 479 | * |
| 480 | * @throws IllegalArgumentException if <tt>threshold</tt> is negative |
| 481 | * or greater than the maximum amount of memory for |
| 482 | * this memory pool if defined. |
| 483 | * |
| 484 | * @throws UnsupportedOperationException if this memory pool |
| 485 | * does not support a usage threshold. |
| 486 | * |
| 487 | * @throws java.lang.SecurityException if a security manager |
| 488 | * exists and the caller does not have |
| 489 | * ManagementPermission("control"). |
| 490 | * |
| 491 | * @see #isUsageThresholdSupported |
| 492 | * @see <a href="#UsageThreshold">Usage threshold</a> |
| 493 | */ |
| 494 | public void setUsageThreshold(long threshold); |
| 495 | |
| 496 | /** |
| 497 | * Tests if the memory usage of this memory pool |
| 498 | * reaches or exceeds its usage threshold value. |
| 499 | * |
| 500 | * @return <tt>true</tt> if the memory usage of |
| 501 | * this memory pool reaches or exceeds the threshold value; |
| 502 | * <tt>false</tt> otherwise. |
| 503 | * |
| 504 | * @throws UnsupportedOperationException if this memory pool |
| 505 | * does not support a usage threshold. |
| 506 | */ |
| 507 | public boolean isUsageThresholdExceeded(); |
| 508 | |
| 509 | /** |
| 510 | * Returns the number of times that the memory usage has crossed |
| 511 | * the usage threshold. |
| 512 | * |
| 513 | * @return the number of times that the memory usage |
| 514 | * has crossed its usage threshold value. |
| 515 | * |
| 516 | * @throws UnsupportedOperationException if this memory pool |
| 517 | * does not support a usage threshold. |
| 518 | */ |
| 519 | public long getUsageThresholdCount(); |
| 520 | |
| 521 | /** |
| 522 | * Tests if this memory pool supports usage threshold. |
| 523 | * |
| 524 | * @return <tt>true</tt> if this memory pool supports usage threshold; |
| 525 | * <tt>false</tt> otherwise. |
| 526 | */ |
| 527 | public boolean isUsageThresholdSupported(); |
| 528 | |
| 529 | /** |
| 530 | * Returns the collection usage threshold value of this memory pool |
| 531 | * in bytes. The default value is zero. The collection usage |
| 532 | * threshold can be changed via the |
| 533 | * {@link #setCollectionUsageThreshold setCollectionUsageThreshold} method. |
| 534 | * |
| 535 | * @return the collection usage threshold of this memory pool in bytes. |
| 536 | * |
| 537 | * @throws UnsupportedOperationException if this memory pool |
| 538 | * does not support a collection usage threshold. |
| 539 | * |
| 540 | * @see #isCollectionUsageThresholdSupported |
| 541 | */ |
| 542 | public long getCollectionUsageThreshold(); |
| 543 | |
| 544 | /** |
| 545 | * Sets the collection usage threshold of this memory pool to |
| 546 | * the given <tt>threshold</tt> value. |
| 547 | * When this threshold is set to positive, the Java virtual machine |
| 548 | * will check the memory usage at its best appropriate time after it has |
| 549 | * expended effort in recycling unused objects in this memory pool. |
| 550 | * <p> |
| 551 | * The collection usage threshold crossing checking is enabled |
| 552 | * in this memory pool if the threshold is set to a positive value. |
| 553 | * The collection usage threshold crossing checking is disabled |
| 554 | * if it is set to zero. |
| 555 | * |
| 556 | * @param threshold the new collection usage threshold value in bytes. |
| 557 | * Must be non-negative. |
| 558 | * |
| 559 | * @throws IllegalArgumentException if <tt>threshold</tt> is negative |
| 560 | * or greater than the maximum amount of memory for |
| 561 | * this memory pool if defined. |
| 562 | * |
| 563 | * @throws UnsupportedOperationException if this memory pool |
| 564 | * does not support a collection usage threshold. |
| 565 | * |
| 566 | * @throws java.lang.SecurityException if a security manager |
| 567 | * exists and the caller does not have |
| 568 | * ManagementPermission("control"). |
| 569 | * |
| 570 | * @see #isCollectionUsageThresholdSupported |
| 571 | * @see <a href="#CollectionThreshold">Collection usage threshold</a> |
| 572 | */ |
| 573 | public void setCollectionUsageThreshold(long threshold); |
| 574 | |
| 575 | /** |
| 576 | * Tests if the memory usage of this memory pool after |
| 577 | * the most recent collection on which the Java virtual |
| 578 | * machine has expended effort has reached or |
| 579 | * exceeded its collection usage threshold. |
| 580 | * This method does not request the Java virtual |
| 581 | * machine to perform any garbage collection other than its normal |
| 582 | * automatic memory management. |
| 583 | * |
| 584 | * @return <tt>true</tt> if the memory usage of this memory pool |
| 585 | * reaches or exceeds the collection usage threshold value |
| 586 | * in the most recent collection; |
| 587 | * <tt>false</tt> otherwise. |
| 588 | * |
| 589 | * @throws UnsupportedOperationException if this memory pool |
| 590 | * does not support a usage threshold. |
| 591 | */ |
| 592 | public boolean isCollectionUsageThresholdExceeded(); |
| 593 | |
| 594 | /** |
| 595 | * Returns the number of times that the Java virtual machine |
| 596 | * has detected that the memory usage has reached or |
| 597 | * exceeded the collection usage threshold. |
| 598 | * |
| 599 | * @return the number of times that the memory |
| 600 | * usage has reached or exceeded the collection usage threshold. |
| 601 | * |
| 602 | * @throws UnsupportedOperationException if this memory pool |
| 603 | * does not support a collection usage threshold. |
| 604 | * |
| 605 | * @see #isCollectionUsageThresholdSupported |
| 606 | */ |
| 607 | public long getCollectionUsageThresholdCount(); |
| 608 | |
| 609 | /** |
| 610 | * Returns the memory usage after the Java virtual machine |
| 611 | * most recently expended effort in recycling unused objects |
| 612 | * in this memory pool. |
| 613 | * This method does not request the Java virtual |
| 614 | * machine to perform any garbage collection other than its normal |
| 615 | * automatic memory management. |
| 616 | * This method returns <tt>null</tt> if the Java virtual |
| 617 | * machine does not support this method. |
| 618 | * |
| 619 | * <p> |
| 620 | * <b>MBeanServer access</b>:<br> |
| 621 | * The mapped type of <tt>MemoryUsage</tt> is |
| 622 | * <tt>CompositeData</tt> with attributes as specified in |
| 623 | * {@link MemoryUsage#from MemoryUsage}. |
| 624 | * |
| 625 | * @return a {@link MemoryUsage} representing the memory usage of |
| 626 | * this memory pool after the Java virtual machine most recently |
| 627 | * expended effort in recycling unused objects; |
| 628 | * <tt>null</tt> if this method is not supported. |
| 629 | */ |
| 630 | public MemoryUsage getCollectionUsage(); |
| 631 | |
| 632 | /** |
| 633 | * Tests if this memory pool supports a collection usage threshold. |
| 634 | * |
| 635 | * @return <tt>true</tt> if this memory pool supports the |
| 636 | * collection usage threshold; <tt>false</tt> otherwise. |
| 637 | */ |
| 638 | public boolean isCollectionUsageThresholdSupported(); |
| 639 | } |