/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management;
/**
* Implementation class for a memory pool.
* Standard and committed hotspot-specific metrics if any.
*
* ManagementFactory.getMemoryPoolMXBeans() returns a list of
* instances of this class.
*/
private final boolean isHeap;
private final boolean isValid;
private final boolean collectionThresholdSupported;
private final boolean usageThresholdSupported;
private long usageThreshold;
private long collectionThreshold;
private boolean usageSensorRegistered;
private boolean gcSensorRegistered;
long gcThreshold) {
this.isValid = true;
this.usageThreshold = usageThreshold;
this.collectionThreshold = gcThreshold;
this.usageSensorRegistered = false;
this.gcSensorRegistered = false;
}
return name;
}
public boolean isValid() {
return isValid;
}
if (isHeap) {
return MemoryType.HEAP;
} else {
return MemoryType.NON_HEAP;
}
}
return getUsage0();
}
// synchronized since resetPeakUsage may be resetting the peak usage
return getPeakUsage0();
}
public synchronized long getUsageThreshold() {
if (!isUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"Usage threshold is not supported");
}
return usageThreshold;
}
if (!isUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"Usage threshold is not supported");
}
if (newThreshold < 0) {
throw new IllegalArgumentException(
"Invalid threshold: " + newThreshold);
}
throw new IllegalArgumentException(
"Invalid threshold: " + newThreshold +
" must be <= maxSize." +
}
synchronized (this) {
if (!usageSensorRegistered) {
// pass the sensor to VM to begin monitoring
usageSensorRegistered = true;
}
this.usageThreshold = newThreshold;
}
}
}
return managers;
}
}
return names;
}
public void resetPeakUsage() {
synchronized (this) {
// synchronized since getPeakUsage may be called concurrently
}
}
public boolean isUsageThresholdExceeded() {
if (!isUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"Usage threshold is not supported");
}
// return false if usage threshold crossing checking is disabled
if (usageThreshold == 0) {
return false;
}
MemoryUsage u = getUsage0();
return (u.getUsed() >= usageThreshold ||
usageSensor.isOn());
}
public long getUsageThresholdCount() {
if (!isUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"Usage threshold is not supported");
}
return usageSensor.getCount();
}
public boolean isUsageThresholdSupported() {
return usageThresholdSupported;
}
public synchronized long getCollectionUsageThreshold() {
if (!isCollectionUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"CollectionUsage threshold is not supported");
}
return collectionThreshold;
}
if (!isCollectionUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"CollectionUsage threshold is not supported");
}
if (newThreshold < 0) {
throw new IllegalArgumentException(
"Invalid threshold: " + newThreshold);
}
throw new IllegalArgumentException(
"Invalid threshold: " + newThreshold +
}
synchronized (this) {
if (!gcSensorRegistered) {
// pass the sensor to VM to begin monitoring
gcSensorRegistered = true;
}
this.collectionThreshold = newThreshold;
}
}
public boolean isCollectionUsageThresholdExceeded() {
if (!isCollectionUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"CollectionUsage threshold is not supported");
}
// return false if usage threshold crossing checking is disabled
if (collectionThreshold == 0) {
return false;
}
MemoryUsage u = getCollectionUsage0();
}
public long getCollectionUsageThresholdCount() {
if (!isCollectionUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"CollectionUsage threshold is not supported");
}
}
return getCollectionUsage0();
}
public boolean isCollectionUsageThresholdSupported() {
return collectionThresholdSupported;
}
// Native VM support
private native void resetPeakUsage0();
// package private
/**
* PoolSensor will be triggered by the VM when the memory
* usage of a memory pool is crossing the usage threshold.
* The VM will not trigger this sensor in subsequent crossing
* unless the memory usage has returned below the threshold.
*/
super(name);
}
// create and send notification
getCount());
}
void triggerAction() {
// Should not reach here
throw new AssertionError("Should not reach here");
}
void clearAction() {
// do nothing
}
}
/**
* CollectionSensor will be triggered and cleared by the VM
* when the memory usage of a memory pool after GC is crossing
* the collection threshold.
* The VM will trigger this sensor in subsequent crossing
* regardless if the memory usage has changed siince the previous GC.
*/
super(name);
}
}
void triggerAction() {
// Should not reach here
throw new AssertionError("Should not reach here");
}
void clearAction() {
// do nothing
}
}
}
}