Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/MonitorInfoCompositeData.java
38827 views
/*1* Copyright (c) 2005, 2012, 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.MonitorInfo;28import javax.management.openmbean.CompositeType;29import javax.management.openmbean.CompositeData;30import javax.management.openmbean.CompositeDataSupport;31import javax.management.openmbean.OpenDataException;32import java.util.Set;3334/**35* A CompositeData for MonitorInfo for the local management support.36* This class avoids the performance penalty paid to the37* construction of a CompositeData use in the local case.38*/39public class MonitorInfoCompositeData extends LazyCompositeData {40private final MonitorInfo lock;4142private MonitorInfoCompositeData(MonitorInfo mi) {43this.lock = mi;44}4546public MonitorInfo getMonitorInfo() {47return lock;48}4950public static CompositeData toCompositeData(MonitorInfo mi) {51MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi);52return micd.getCompositeData();53}5455protected CompositeData getCompositeData() {56// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH57// monitorInfoItemNames!5859int len = monitorInfoItemNames.length;60Object[] values = new Object[len];61CompositeData li = LockInfoCompositeData.toCompositeData(lock);6263for (int i = 0; i < len; i++) {64String item = monitorInfoItemNames[i];65if (item.equals(LOCKED_STACK_FRAME)) {66StackTraceElement ste = lock.getLockedStackFrame();67values[i] = (ste != null ? StackTraceElementCompositeData.68toCompositeData(ste)69: null);70} else if (item.equals(LOCKED_STACK_DEPTH)) {71values[i] = new Integer(lock.getLockedStackDepth());72} else {73values[i] = li.get(item);74}75}7677try {78return new CompositeDataSupport(monitorInfoCompositeType,79monitorInfoItemNames,80values);81} catch (OpenDataException e) {82// Should never reach here83throw new AssertionError(e);84}85}8687private static final CompositeType monitorInfoCompositeType;88private static final String[] monitorInfoItemNames;89static {90try {91monitorInfoCompositeType = (CompositeType)92MappedMXBeanType.toOpenType(MonitorInfo.class);93Set<String> s = monitorInfoCompositeType.keySet();94monitorInfoItemNames = s.toArray(new String[0]);95} catch (OpenDataException e) {96// Should never reach here97throw new AssertionError(e);98}99}100101static CompositeType getMonitorInfoCompositeType() {102return monitorInfoCompositeType;103}104105private static final String CLASS_NAME = "className";106private static final String IDENTITY_HASH_CODE = "identityHashCode";107private static final String LOCKED_STACK_FRAME = "lockedStackFrame";108private static final String LOCKED_STACK_DEPTH = "lockedStackDepth";109110public static String getClassName(CompositeData cd) {111return getString(cd, CLASS_NAME);112}113114public static int getIdentityHashCode(CompositeData cd) {115return getInt(cd, IDENTITY_HASH_CODE);116}117118public static StackTraceElement getLockedStackFrame(CompositeData cd) {119CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);120if (ste != null) {121return StackTraceElementCompositeData.from(ste);122} else {123return null;124}125}126127public static int getLockedStackDepth(CompositeData cd) {128return getInt(cd, LOCKED_STACK_DEPTH);129}130131/** Validate if the input CompositeData has the expected132* CompositeType (i.e. contain all attributes with expected133* names and types).134*/135public static void validateCompositeData(CompositeData cd) {136if (cd == null) {137throw new NullPointerException("Null CompositeData");138}139140if (!isTypeMatched(monitorInfoCompositeType, cd.getCompositeType())) {141throw new IllegalArgumentException(142"Unexpected composite type for MonitorInfo");143}144}145146private static final long serialVersionUID = -5825215591822908529L;147}148149150