src/java.management/share/classes/sun/management/StackTraceElementCompositeData.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 41911 jdk/src/java.management/share/classes/sun/management/StackTraceElementCompositeData.java@b3bb62588635
child 49077 b1c42b3cd19b
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    28
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    29
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    30
import java.util.function.Predicate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A CompositeData for StackTraceElement for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class StackTraceElementCompositeData extends LazyCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private final StackTraceElement ste;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private StackTraceElementCompositeData(StackTraceElement ste) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        this.ste = ste;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public StackTraceElement getStackTraceElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        return ste;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static StackTraceElement from(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    55
        if (stackTraceElementV6CompositeType.equals(cd.getCompositeType())) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    56
            return new StackTraceElement(getString(cd, CLASS_NAME),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    57
                                         getString(cd, METHOD_NAME),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    58
                                         getString(cd, FILE_NAME),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    59
                                         getInt(cd, LINE_NUMBER));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    60
        } else {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
    61
            return new StackTraceElement(getString(cd, CLASS_LOADER_NAME),
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
    62
                                         getString(cd, MODULE_NAME),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    63
                                         getString(cd, MODULE_VERSION),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    64
                                         getString(cd, CLASS_NAME),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    65
                                         getString(cd, METHOD_NAME),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    66
                                         getString(cd, FILE_NAME),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    67
                                         getInt(cd, LINE_NUMBER));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    68
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static CompositeData toCompositeData(StackTraceElement ste) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        StackTraceElementCompositeData cd = new StackTraceElementCompositeData(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return cd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // stackTraceElementItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        final Object[] stackTraceElementItemValues = {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
    80
            ste.getClassLoaderName(),
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
    81
            ste.getModuleName(),
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
    82
            ste.getModuleVersion(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            ste.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            ste.getMethodName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            ste.getFileName(),
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 24685
diff changeset
    86
            ste.getLineNumber(),
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
    87
            ste.isNativeMethod(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return new CompositeDataSupport(stackTraceElementCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                            stackTraceElementItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                            stackTraceElementItemValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    95
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Attribute names
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   100
    private static final String CLASS_LOADER_NAME = "classLoaderName";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   101
    private static final String MODULE_NAME       = "moduleName";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   102
    private static final String MODULE_VERSION    = "moduleVersion";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   103
    private static final String CLASS_NAME        = "className";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   104
    private static final String METHOD_NAME       = "methodName";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   105
    private static final String FILE_NAME         = "fileName";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   106
    private static final String LINE_NUMBER       = "lineNumber";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   107
    private static final String NATIVE_METHOD     = "nativeMethod";
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   108
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static final String[] stackTraceElementItemNames = {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   111
        CLASS_LOADER_NAME,
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   112
        MODULE_NAME,
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   113
        MODULE_VERSION,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        CLASS_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        METHOD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        FILE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        LINE_NUMBER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        NATIVE_METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   121
    private static final String[] stackTraceElementV9ItemNames = {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 36511
diff changeset
   122
        CLASS_LOADER_NAME,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   123
        MODULE_NAME,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   124
        MODULE_VERSION,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   125
    };
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   126
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   127
    private static final CompositeType stackTraceElementCompositeType;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   128
    private static final CompositeType stackTraceElementV6CompositeType;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   129
    static {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   130
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   131
            stackTraceElementCompositeType = (CompositeType)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   132
                MappedMXBeanType.toOpenType(StackTraceElement.class);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   133
            stackTraceElementV6CompositeType =
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   134
                TypeVersionMapper.getInstance().getVersionedCompositeType(
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   135
                    stackTraceElementCompositeType,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   136
                    TypeVersionMapper.V6
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   137
                );
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   138
        } catch (OpenDataException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   139
            // Should never reach here
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   140
            throw new AssertionError(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   141
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   142
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   143
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   153
        CompositeType ct = cd.getCompositeType();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   154
        if (!isTypeMatched(stackTraceElementCompositeType, ct)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   155
            if (!isTypeMatched(stackTraceElementV6CompositeType, ct)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   156
                throw new IllegalArgumentException(
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   157
                    "Unexpected composite type for StackTraceElement");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   158
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   161
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   162
    static boolean isV6Attribute(String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   163
        for(String attrName : stackTraceElementV9ItemNames) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   164
            if (name.equals(attrName)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   165
                return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   166
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   167
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   168
        return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   169
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   170
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   171
    private static final long serialVersionUID = -2704607706598396827L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}