jdk/src/java.management/share/classes/sun/management/StackTraceElementCompositeData.java
author weijun
Thu, 11 Dec 2014 15:23:02 +0800
changeset 27957 24b4e6082f19
parent 25859 3317bb8137f4
child 36511 9d0388c6b336
permissions -rw-r--r--
8055723: Replace concat String to append in StringBuilder parameters (dev) Reviewed-by: redestad, ulfzibis, weijun, prappo, igerasim, alanb Contributed-by: Otavio Santana <otaviojava@java.net>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
     2
 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A CompositeData for StackTraceElement for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class StackTraceElementCompositeData extends LazyCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private final StackTraceElement ste;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private StackTraceElementCompositeData(StackTraceElement ste) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        this.ste = ste;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public StackTraceElement getStackTraceElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        return ste;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static StackTraceElement from(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        return new StackTraceElement(getString(cd, CLASS_NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                     getString(cd, METHOD_NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                     getString(cd, FILE_NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                     getInt(cd, LINE_NUMBER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static CompositeData toCompositeData(StackTraceElement ste) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        StackTraceElementCompositeData cd = new StackTraceElementCompositeData(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return cd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // stackTraceElementItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        final Object[] stackTraceElementItemValues = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            ste.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            ste.getMethodName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            ste.getFileName(),
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 24685
diff changeset
    70
            ste.getLineNumber(),
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
    71
            ste.isNativeMethod(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            return new CompositeDataSupport(stackTraceElementCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                            stackTraceElementItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                            stackTraceElementItemValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    79
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final CompositeType stackTraceElementCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            stackTraceElementCompositeType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                MappedMXBeanType.toOpenType(StackTraceElement.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    90
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // Attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final String CLASS_NAME      = "className";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static final String METHOD_NAME     = "methodName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final String FILE_NAME       = "fileName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final String LINE_NUMBER     = "lineNumber";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final String NATIVE_METHOD   = "nativeMethod";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static final String[] stackTraceElementItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        CLASS_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        METHOD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        FILE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        LINE_NUMBER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        NATIVE_METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (!isTypeMatched(stackTraceElementCompositeType, cd.getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                "Unexpected composite type for StackTraceElement");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   123
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   124
    private static final long serialVersionUID = -2704607706598396827L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}