src/java.management/share/classes/sun/management/LockInfoCompositeData.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:
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
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) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     4
 *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    10
 *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    15
 * accompanied this code).
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    16
 *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    20
 *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    23
 * questions.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    24
 */
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    25
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    26
package sun.management;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    27
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    28
import java.lang.management.LockInfo;
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    29
import java.util.Map;
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    30
import javax.management.openmbean.CompositeType;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    31
import javax.management.openmbean.CompositeData;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    32
import javax.management.openmbean.CompositeDataSupport;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    33
import javax.management.openmbean.OpenDataException;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    34
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    35
/**
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    36
 * A CompositeData for LockInfo for the local management support.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    37
 * This class avoids the performance penalty paid to the
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    38
 * construction of a CompositeData use in the local case.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    39
 */
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    40
public class LockInfoCompositeData extends LazyCompositeData {
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52288
diff changeset
    41
    @SuppressWarnings("serial") // Not statically typed as Serializable
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    42
    private final LockInfo lock;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    43
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    44
    private LockInfoCompositeData(LockInfo li) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    45
        this.lock = li;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    46
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    47
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    48
    public LockInfo getLockInfo() {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    49
        return lock;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    50
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    51
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    52
    public static CompositeData toCompositeData(LockInfo li) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    53
        if (li == null) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    54
            return null;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    55
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    56
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    57
        LockInfoCompositeData licd = new LockInfoCompositeData(li);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    58
        return licd.getCompositeData();
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    59
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    60
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    61
    protected CompositeData getCompositeData() {
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    62
        Map<String,Object> items = Map.of(
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    63
            CLASS_NAME,         lock.getClassName(),
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    64
            IDENTITY_HASH_CODE, lock.getIdentityHashCode()
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    65
        );
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    66
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    67
        try {
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    68
            return new CompositeDataSupport(LOCK_INFO_COMPOSITE_TYPE, items);
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    69
        } catch (OpenDataException e) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    70
            // Should never reach here
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    71
            throw Util.newException(e);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    72
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    73
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    74
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    75
    private static final CompositeType LOCK_INFO_COMPOSITE_TYPE;
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    76
    static {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    77
        try {
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    78
            LOCK_INFO_COMPOSITE_TYPE = (CompositeType)
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    79
                MappedMXBeanType.toOpenType(LockInfo.class);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    80
        } catch (OpenDataException e) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    81
            // Should never reach here
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    82
            throw Util.newException(e);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    83
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    84
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    85
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    86
    static CompositeType compositeType() {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    87
        return LOCK_INFO_COMPOSITE_TYPE;
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    88
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    89
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    90
    private static final String CLASS_NAME         = "className";
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    91
    private static final String IDENTITY_HASH_CODE = "identityHashCode";
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    92
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    93
    /*
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    94
     * Returns a LockInfo object mapped from the given CompositeData.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    95
     */
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    96
    public static LockInfo toLockInfo(CompositeData cd) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    97
        if (cd == null) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    98
            throw new NullPointerException("Null CompositeData");
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
    99
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   100
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   101
        if (!isTypeMatched(LOCK_INFO_COMPOSITE_TYPE, cd.getCompositeType())) {
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   102
            throw new IllegalArgumentException(
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   103
                "Unexpected composite type for LockInfo");
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   104
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   105
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   106
        String className = getString(cd, CLASS_NAME);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   107
        int identityHashCode = getInt(cd, IDENTITY_HASH_CODE);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   108
        return new LockInfo(className, identityHashCode);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   109
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   110
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   111
    private static final long serialVersionUID = -6374759159749014052L;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
diff changeset
   112
}