Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/StackTraceElementCompositeData.java
38827 views
/*1* Copyright (c) 2005, 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 javax.management.openmbean.CompositeType;28import javax.management.openmbean.CompositeData;29import javax.management.openmbean.CompositeDataSupport;30import javax.management.openmbean.OpenDataException;3132/**33* A CompositeData for StackTraceElement for the local management support.34* This class avoids the performance penalty paid to the35* construction of a CompositeData use in the local case.36*/37public class StackTraceElementCompositeData extends LazyCompositeData {38private final StackTraceElement ste;3940private StackTraceElementCompositeData(StackTraceElement ste) {41this.ste = ste;42}4344public StackTraceElement getStackTraceElement() {45return ste;46}4748public static StackTraceElement from(CompositeData cd) {49validateCompositeData(cd);5051return new StackTraceElement(getString(cd, CLASS_NAME),52getString(cd, METHOD_NAME),53getString(cd, FILE_NAME),54getInt(cd, LINE_NUMBER));55}5657public static CompositeData toCompositeData(StackTraceElement ste) {58StackTraceElementCompositeData cd = new StackTraceElementCompositeData(ste);59return cd.getCompositeData();60}6162protected CompositeData getCompositeData() {63// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH64// stackTraceElementItemNames!65final Object[] stackTraceElementItemValues = {66ste.getClassName(),67ste.getMethodName(),68ste.getFileName(),69new Integer(ste.getLineNumber()),70new Boolean(ste.isNativeMethod()),71};72try {73return new CompositeDataSupport(stackTraceElementCompositeType,74stackTraceElementItemNames,75stackTraceElementItemValues);76} catch (OpenDataException e) {77// Should never reach here78throw new AssertionError(e);79}80}8182private static final CompositeType stackTraceElementCompositeType;83static {84try {85stackTraceElementCompositeType = (CompositeType)86MappedMXBeanType.toOpenType(StackTraceElement.class);87} catch (OpenDataException e) {88// Should never reach here89throw new AssertionError(e);90}91}9293// Attribute names94private static final String CLASS_NAME = "className";95private static final String METHOD_NAME = "methodName";96private static final String FILE_NAME = "fileName";97private static final String LINE_NUMBER = "lineNumber";98private static final String NATIVE_METHOD = "nativeMethod";99100private static final String[] stackTraceElementItemNames = {101CLASS_NAME,102METHOD_NAME,103FILE_NAME,104LINE_NUMBER,105NATIVE_METHOD,106};107108/** Validate if the input CompositeData has the expected109* CompositeType (i.e. contain all attributes with expected110* names and types).111*/112public static void validateCompositeData(CompositeData cd) {113if (cd == null) {114throw new NullPointerException("Null CompositeData");115}116117if (!isTypeMatched(stackTraceElementCompositeType, cd.getCompositeType())) {118throw new IllegalArgumentException(119"Unexpected composite type for StackTraceElement");120}121}122123private static final long serialVersionUID = -2704607706598396827L;124}125126127