src/java.management/share/classes/sun/management/MonitorInfoCompositeData.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 52288 2b29df6dfa68
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52288
diff changeset
     2
 * Copyright (c) 2005, 2019, 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 java.lang.management.MonitorInfo;
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    29
import java.util.HashMap;
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    30
import java.util.Map;
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;
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    35
import javax.management.openmbean.OpenType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A CompositeData for MonitorInfo for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class MonitorInfoCompositeData extends LazyCompositeData {
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52288
diff changeset
    43
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final MonitorInfo lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private MonitorInfoCompositeData(MonitorInfo mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        this.lock = mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public MonitorInfo getMonitorInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        return lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static CompositeData toCompositeData(MonitorInfo mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return micd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected CompositeData getCompositeData() {
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    60
        StackTraceElement ste = lock.getLockedStackFrame();
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    61
        CompositeData steCData = ste != null ? StackTraceElementCompositeData.toCompositeData(ste)
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    62
                                             : null;
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    63
        // values may be null; can't use Map.of
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    64
        Map<String,Object> items = new HashMap<>();
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    65
        items.put(CLASS_NAME,         lock.getClassName());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    66
        items.put(IDENTITY_HASH_CODE, lock.getIdentityHashCode());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    67
        items.put(LOCKED_STACK_FRAME, steCData);
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    68
        items.put(LOCKED_STACK_DEPTH, lock.getLockedStackDepth());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        try {
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    71
            return new CompositeDataSupport(MONITOR_INFO_COMPOSITE_TYPE, items);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    74
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    78
    private static final String CLASS_NAME         = "className";
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    79
    private static final String IDENTITY_HASH_CODE = "identityHashCode";
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    80
    private static final String LOCKED_STACK_FRAME = "lockedStackFrame";
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    81
    private static final String LOCKED_STACK_DEPTH = "lockedStackDepth";
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    82
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    83
    private static final String[] MONITOR_INFO_ATTRIBUTES = {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    84
        CLASS_NAME,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    85
        IDENTITY_HASH_CODE,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    86
        LOCKED_STACK_FRAME,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    87
        LOCKED_STACK_DEPTH
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    88
    };
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    89
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    90
    private static final CompositeType MONITOR_INFO_COMPOSITE_TYPE;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    91
    private static final CompositeType V6_COMPOSITE_TYPE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        try {
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    94
            MONITOR_INFO_COMPOSITE_TYPE = (CompositeType)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                MappedMXBeanType.toOpenType(MonitorInfo.class);
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    96
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    97
            OpenType<?>[] types = new OpenType<?>[MONITOR_INFO_ATTRIBUTES.length];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    98
            for (int i = 0; i < MONITOR_INFO_ATTRIBUTES.length; i++) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    99
                String name = MONITOR_INFO_ATTRIBUTES[i];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   100
                types[i] = name.equals(LOCKED_STACK_FRAME)
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   101
                            ? StackTraceElementCompositeData.v5CompositeType()
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   102
                            : MONITOR_INFO_COMPOSITE_TYPE.getType(name);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   103
            }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   104
            V6_COMPOSITE_TYPE = new CompositeType("MonitorInfo",
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   105
                                                  "JDK 6 MonitorInfo",
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   106
                                                  MONITOR_INFO_ATTRIBUTES,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   107
                                                  MONITOR_INFO_ATTRIBUTES,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   108
                                                  types);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   111
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   115
    static CompositeType v6CompositeType() {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   116
        return V6_COMPOSITE_TYPE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static String getClassName(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return getString(cd, CLASS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static int getIdentityHashCode(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return getInt(cd, IDENTITY_HASH_CODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static StackTraceElement getLockedStackFrame(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (ste != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return StackTraceElementCompositeData.from(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public static int getLockedStackDepth(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return getInt(cd, LOCKED_STACK_DEPTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   149
        if (!isTypeMatched(MONITOR_INFO_COMPOSITE_TYPE, cd.getCompositeType()) &&
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   150
            !isTypeMatched(V6_COMPOSITE_TYPE, cd.getCompositeType())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                "Unexpected composite type for MonitorInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   155
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   156
    private static final long serialVersionUID = -5825215591822908529L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}