1 /* MemoryPoolMXBeanImpl.java - VM interface for memory pool beans
2    Copyright (C) 2006, 2010  Free Software Foundation, Inc.
3 
4 This file is part of GNU Classpath.
5 
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20 
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25 
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37 
38 package gnu.java.lang.management;
39 
40 import java.lang.management.MemoryUsage;
41 
42 /**
43  * Provides access to information on the memory resources or
44  * pools used by the current invocation of the virtual machine.
45  *
46  * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
47  * @since 1.5
48  */
49 final class VMMemoryPoolMXBeanImpl
50 {
51 
VMMemoryPoolMXBeanImpl()52   private VMMemoryPoolMXBeanImpl() {} // Prohibits instantiation.
53 
54   /**
55    * Returns memory usage statistics for the specified pool
56    * just after a best-effort attempt to free memory.  This
57    * is valid only for certain garbage collectors.
58    *
59    * @param name the name of the pool to obtain statistics on.
60    * @return a {@link java.lang.management.MemoryUsage} object
61    *         containing the statistics or <code>null</code>
62    *         if this pool does not support such statistics.
63    */
getCollectionUsage(String name)64   static native MemoryUsage getCollectionUsage(String name);
65 
66   /**
67    * Returns the collection usage threshold for the specified pool.
68    * This is only called if this functionality is supported
69    * by the virtual machine (i.e. the appropriate property,
70    * <code>gnu.java.lang.management.CollectionUsageThresholdSupport</code>,
71    * is defined).  The value is initially zero.
72    *
73    * @param name the name of the pool to obtain statistics on.
74    * @return the collection usage threshold.
75    */
getCollectionUsageThreshold(String name)76   static native long getCollectionUsageThreshold(String name);
77 
78   /**
79    * Returns the number of times the collection usage threshold
80    * has been met or exceeded by the specified pool.
81    * This is only called if this functionality is supported
82    * by the virtual machine (i.e. the appropriate property,
83    * <code>gnu.java.lang.management.CollectionUsageThresholdSupport</code>,
84    * is defined).
85    *
86    * @param name the name of the pool to obtain statistics on.
87    * @return the collection usage threshold count.
88    */
getCollectionUsageThresholdCount(String name)89   static native long getCollectionUsageThresholdCount(String name);
90 
91   /**
92    * Returns an array of names of memory managers which manage
93    * the specified pool.
94    *
95    * @param name the name of the pool to obtain statistics on.
96    * @return a list of memory managers for the pool.
97    */
getMemoryManagerNames(String name)98   static native String[] getMemoryManagerNames(String name);
99 
100   /**
101    * Returns the peak usage level of the specified pool.
102    * This is only called if the pool is valid.
103    *
104    * @param name the name of the pool to obtain statistics on.
105    * @return a {@link java.lang.management.MemoryUsage} object
106    *         containing the statistics.
107    */
getPeakUsage(String name)108   static native MemoryUsage getPeakUsage(String name);
109 
110   /**
111    * Returns the type of memory used by the specified pool.
112    * The value must be either "HEAP" or "NON_HEAP".
113    *
114    * @param name the name of the pool to obtain statistics on.
115    * @return the type of the given pool.
116    */
getType(String name)117   static native String getType(String name);
118 
119   /**
120    * Returns the current usage level of the specified pool.
121    * This is only called if the pool is valid.
122    *
123    * @param name the name of the pool to obtain statistics on.
124    * @return a {@link java.lang.management.MemoryUsage} object
125    *         containing the statistics.
126    */
getUsage(String name)127   static native MemoryUsage getUsage(String name);
128 
129   /**
130    * Returns the usage threshold for the specified pool.
131    * This is only called if this functionality is supported
132    * by the virtual machine (i.e. the appropriate property,
133    * <code>gnu.java.lang.management.UsageThresholdSupport</code>,
134    * is defined).  The value is initially defined by the
135    * virtual machine.
136    *
137    * @param name the name of the pool to obtain statistics on.
138    * @return the usage threshold.
139    */
getUsageThreshold(String name)140   static native long getUsageThreshold(String name);
141 
142   /**
143    * Returns the number of times the usage threshold
144    * has been met or exceeded by the specified pool.
145    * This is only called if this functionality is supported
146    * by the virtual machine (i.e. the appropriate property,
147    * <code>gnu.java.lang.management.UsageThresholdSupport</code>,
148    * is defined).
149    *
150    * @param name the name of the pool to obtain statistics on.
151    * @return the usage threshold count.
152    */
getUsageThresholdCount(String name)153   static native long getUsageThresholdCount(String name);
154 
155   /**
156    * Returns true if the specified pool is still valid i.e.
157    * it is still in use by the virtual machine.
158    *
159    * @param name the name of the pool to check the validity of.
160    * @return true if the pool is valid.
161    */
isValid(String name)162   static native boolean isValid(String name);
163 
164   /**
165    * Resets the peak usage level to the current usage level for
166    * the specified pool.
167    *
168    * @param name the name of the pool to reset the peak usage of.
169    */
resetPeakUsage(String name)170   static native void resetPeakUsage(String name);
171 
172   /**
173    * Sets the collection usage threshold for the specified
174    * pool to the supplied value.
175    * This is only called if this functionality is supported
176    * by the virtual machine (i.e. the appropriate property,
177    * <code>gnu.java.lang.management.CollectionUsageThresholdSupport</code>,
178    * is defined).
179    *
180    * @param name the name of the pool to set the threshold of.
181    * @param threshold the new threshold level.
182    */
setCollectionUsageThreshold(String name, long threshold)183   static native void setCollectionUsageThreshold(String name, long threshold);
184 
185   /**
186    * Sets the usage threshold for the specified pool to the supplied value.
187    * This is only called if this functionality is supported
188    * by the virtual machine (i.e. the appropriate property,
189    * <code>gnu.java.lang.management.UsageThresholdSupport</code>,
190    * is defined).
191    *
192    * @param name the name of the pool to set the threshold of.
193    * @param threshold the new threshold level.
194    */
setUsageThreshold(String name, long threshold)195   static native void setUsageThreshold(String name, long threshold);
196 
197 }
198