src/java.management/share/classes/sun/management/MonitorInfoCompositeData.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.management/share/classes/sun/management/MonitorInfoCompositeData.java@3317bb8137f4
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
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13803
diff changeset
     2
 * Copyright (c) 2005, 2012, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A CompositeData for MonitorInfo for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class MonitorInfoCompositeData extends LazyCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private final MonitorInfo lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private MonitorInfoCompositeData(MonitorInfo mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        this.lock = mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public MonitorInfo getMonitorInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        return lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static CompositeData toCompositeData(MonitorInfo mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        return micd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        // monitorInfoItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        int len = monitorInfoItemNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Object[] values = new Object[len];
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    62
        CompositeData li = LockInfoCompositeData.toCompositeData(lock);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            String item = monitorInfoItemNames[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            if (item.equals(LOCKED_STACK_FRAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                StackTraceElement ste = lock.getLockedStackFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                values[i] = (ste != null ? StackTraceElementCompositeData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                               toCompositeData(ste)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                         : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            } else if (item.equals(LOCKED_STACK_DEPTH)) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
    72
                values[i] = lock.getLockedStackDepth();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                values[i] = li.get(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            return new CompositeDataSupport(monitorInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                            monitorInfoItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                            values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    84
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final CompositeType monitorInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final String[] monitorInfoItemNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            monitorInfoCompositeType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                MappedMXBeanType.toOpenType(MonitorInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            Set<String> s = monitorInfoCompositeType.keySet();
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    95
            monitorInfoItemNames =  s.toArray(new String[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    98
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static CompositeType getMonitorInfoCompositeType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return monitorInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static final String CLASS_NAME         = "className";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final String IDENTITY_HASH_CODE = "identityHashCode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final String LOCKED_STACK_FRAME = "lockedStackFrame";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static final String LOCKED_STACK_DEPTH = "lockedStackDepth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static String getClassName(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return getString(cd, CLASS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static int getIdentityHashCode(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return getInt(cd, IDENTITY_HASH_CODE);
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 StackTraceElement getLockedStackFrame(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (ste != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return StackTraceElementCompositeData.from(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static int getLockedStackDepth(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return getInt(cd, LOCKED_STACK_DEPTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (!isTypeMatched(monitorInfoCompositeType, cd.getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                "Unexpected composite type for MonitorInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   146
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   147
    private static final long serialVersionUID = -5825215591822908529L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}