Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java
38827 views
/*1* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.management;2627import java.lang.management.MemoryUsage;28import javax.management.openmbean.CompositeType;29import javax.management.openmbean.CompositeData;30import javax.management.openmbean.CompositeDataSupport;31import javax.management.openmbean.OpenDataException;3233/**34* A CompositeData for MemoryUsage for the local management support.35* This class avoids the performance penalty paid to the36* construction of a CompositeData use in the local case.37*/38public class MemoryUsageCompositeData extends LazyCompositeData {39private final MemoryUsage usage;4041private MemoryUsageCompositeData(MemoryUsage u) {42this.usage = u;43}4445public MemoryUsage getMemoryUsage() {46return usage;47}4849public static CompositeData toCompositeData(MemoryUsage u) {50MemoryUsageCompositeData mucd = new MemoryUsageCompositeData(u);51return mucd.getCompositeData();52}5354protected CompositeData getCompositeData() {55// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH56// memoryUsageItemNames!57final Object[] memoryUsageItemValues = {58new Long(usage.getInit()),59new Long(usage.getUsed()),60new Long(usage.getCommitted()),61new Long(usage.getMax()),62};6364try {65return new CompositeDataSupport(memoryUsageCompositeType,66memoryUsageItemNames,67memoryUsageItemValues);68} catch (OpenDataException e) {69// Should never reach here70throw new AssertionError(e);71}72}7374private static final CompositeType memoryUsageCompositeType;75static {76try {77memoryUsageCompositeType = (CompositeType)78MappedMXBeanType.toOpenType(MemoryUsage.class);79} catch (OpenDataException e) {80// Should never reach here81throw new AssertionError(e);82}83}8485static CompositeType getMemoryUsageCompositeType() {86return memoryUsageCompositeType;87}8889private static final String INIT = "init";90private static final String USED = "used";91private static final String COMMITTED = "committed";92private static final String MAX = "max";9394private static final String[] memoryUsageItemNames = {95INIT,96USED,97COMMITTED,98MAX,99};100101public static long getInit(CompositeData cd) {102return getLong(cd, INIT);103}104public static long getUsed(CompositeData cd) {105return getLong(cd, USED);106}107public static long getCommitted(CompositeData cd) {108return getLong(cd, COMMITTED);109}110public static long getMax(CompositeData cd) {111return getLong(cd, MAX);112}113114/** Validate if the input CompositeData has the expected115* CompositeType (i.e. contain all attributes with expected116* names and types).117*/118public static void validateCompositeData(CompositeData cd) {119if (cd == null) {120throw new NullPointerException("Null CompositeData");121}122123if (!isTypeMatched(memoryUsageCompositeType, cd.getCompositeType())) {124throw new IllegalArgumentException(125"Unexpected composite type for MemoryUsage");126}127}128129private static final long serialVersionUID = -8504291541083874143L;130}131132133