Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/LockInfoCompositeData.java
38827 views
/*1* Copyright (c) 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.LockInfo;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 LockInfo 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 LockInfoCompositeData extends LazyCompositeData {39private final LockInfo lock;4041private LockInfoCompositeData(LockInfo li) {42this.lock = li;43}4445public LockInfo getLockInfo() {46return lock;47}4849public static CompositeData toCompositeData(LockInfo li) {50if (li == null) {51return null;52}5354LockInfoCompositeData licd = new LockInfoCompositeData(li);55return licd.getCompositeData();56}5758protected CompositeData getCompositeData() {59// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH60// lockInfoItemNames!61final Object[] lockInfoItemValues = {62new String(lock.getClassName()),63new Integer(lock.getIdentityHashCode()),64};6566try {67return new CompositeDataSupport(lockInfoCompositeType,68lockInfoItemNames,69lockInfoItemValues);70} catch (OpenDataException e) {71// Should never reach here72throw Util.newException(e);73}74}7576private static final CompositeType lockInfoCompositeType;77static {78try {79lockInfoCompositeType = (CompositeType)80MappedMXBeanType.toOpenType(LockInfo.class);81} catch (OpenDataException e) {82// Should never reach here83throw Util.newException(e);84}85}8687static CompositeType getLockInfoCompositeType() {88return lockInfoCompositeType;89}9091private static final String CLASS_NAME = "className";92private static final String IDENTITY_HASH_CODE = "identityHashCode";93private static final String[] lockInfoItemNames = {94CLASS_NAME,95IDENTITY_HASH_CODE,96};9798/*99* Returns a LockInfo object mapped from the given CompositeData.100*/101public static LockInfo toLockInfo(CompositeData cd) {102if (cd == null) {103throw new NullPointerException("Null CompositeData");104}105106if (!isTypeMatched(lockInfoCompositeType, cd.getCompositeType())) {107throw new IllegalArgumentException(108"Unexpected composite type for LockInfo");109}110111String className = getString(cd, CLASS_NAME);112int identityHashCode = getInt(cd, IDENTITY_HASH_CODE);113return new LockInfo(className, identityHashCode);114}115116private static final long serialVersionUID = -6374759159749014052L;117}118119120