jdk/src/share/classes/sun/management/GcInfoCompositeData.java
author mchung
Tue, 17 Jan 2012 15:55:40 -0800
changeset 11530 a9d059c15b80
parent 9698 8b66cd6c5ebc
child 14342 8435a30053c1
permissions -rw-r--r--
7117570: Warnings in sun.mangement.* and its subpackages Reviewed-by: mchung, dsamersoff Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
     2
 * Copyright (c) 2004, 2011, 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.MemoryUsage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    30
import java.lang.reflect.Field;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.openmbean.TabularData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.openmbean.SimpleType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.openmbean.OpenType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.management.GcInfo;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    45
import com.sun.management.GarbageCollectionNotificationInfo;
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    46
import java.security.AccessController;
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    47
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * A CompositeData for GcInfo for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class GcInfoCompositeData extends LazyCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private final GcInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private final GcInfoBuilder builder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private final Object[] gcExtItemValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public GcInfoCompositeData(GcInfo info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                        GcInfoBuilder builder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                        Object[] gcExtItemValues) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.builder = builder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.gcExtItemValues = gcExtItemValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public GcInfo getGcInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    71
    public static CompositeData toCompositeData(final GcInfo info) {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    72
        final GcInfoBuilder builder = AccessController.doPrivileged (new PrivilegedAction<GcInfoBuilder>() {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    73
                        public GcInfoBuilder run() {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    74
                            try {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    75
                                Class cl = Class.forName("com.sun.management.GcInfo");
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    76
                                Field f = cl.getDeclaredField("builder");
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    77
                                f.setAccessible(true);
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    78
                                return (GcInfoBuilder)f.get(info);
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 9698
diff changeset
    79
                            } catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    80
                                return null;
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    81
                            }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    82
                        }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    83
                    });
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    84
        final Object[] extAttr = AccessController.doPrivileged (new PrivilegedAction<Object[]>() {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    85
                        public Object[] run() {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    86
                            try {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    87
                                Class cl = Class.forName("com.sun.management.GcInfo");
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    88
                                Field f = cl.getDeclaredField("extAttributes");
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    89
                                f.setAccessible(true);
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    90
                                return (Object[])f.get(info);
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 9698
diff changeset
    91
                            } catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    92
                                return null;
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    93
                            }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    94
                        }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    95
                    });
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    96
        GcInfoCompositeData gcicd =
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    97
            new GcInfoCompositeData(info,builder,extAttr);
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    98
        return gcicd.getCompositeData();
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
    99
    }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
   100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // baseGcInfoItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        final Object[] baseGcInfoItemValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            baseGcInfoItemValues = new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                new Long(info.getId()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                new Long(info.getStartTime()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                new Long(info.getEndTime()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                new Long(info.getDuration()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                memoryUsageMapType.toOpenTypeData(info.getMemoryUsageBeforeGc()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                memoryUsageMapType.toOpenTypeData(info.getMemoryUsageAfterGc()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   117
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // Get the item values for the extension attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        final int gcExtItemCount = builder.getGcExtItemCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (gcExtItemCount == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            gcExtItemValues != null && gcExtItemValues.length != 0) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   124
            throw new AssertionError("Unexpected Gc Extension Item Values");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (gcExtItemCount > 0 && (gcExtItemValues == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
             gcExtItemCount != gcExtItemValues.length)) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   129
            throw new AssertionError("Unmatched Gc Extension Item Values");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Object[] values = new Object[baseGcInfoItemValues.length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                     gcExtItemCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        System.arraycopy(baseGcInfoItemValues, 0, values, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                         baseGcInfoItemValues.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (gcExtItemCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            System.arraycopy(gcExtItemValues, 0, values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                             baseGcInfoItemValues.length, gcExtItemCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return new CompositeDataSupport(builder.getGcInfoCompositeType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                            builder.getItemNames(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                            values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   148
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private static final String ID                     = "id";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static final String START_TIME             = "startTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private static final String END_TIME               = "endTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static final String DURATION               = "duration";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private static final String MEMORY_USAGE_BEFORE_GC = "memoryUsageBeforeGc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private static final String MEMORY_USAGE_AFTER_GC  = "memoryUsageAfterGc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private static final String[] baseGcInfoItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        START_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        END_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        DURATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        MEMORY_USAGE_BEFORE_GC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        MEMORY_USAGE_AFTER_GC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private static MappedMXBeanType memoryUsageMapType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            Method m = GcInfo.class.getMethod("getMemoryUsageBeforeGc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            memoryUsageMapType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                MappedMXBeanType.getMappedType(m.getGenericReturnType());
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 9698
diff changeset
   175
        } catch (NoSuchMethodException | OpenDataException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   177
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    static String[] getBaseGcInfoItemNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return baseGcInfoItemNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private static OpenType[] baseGcInfoItemTypes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    static synchronized OpenType[] getBaseGcInfoItemTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (baseGcInfoItemTypes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 9698
diff changeset
   189
            baseGcInfoItemTypes = new OpenType<?>[] {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                memoryUsageOpenType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                memoryUsageOpenType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return baseGcInfoItemTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static long getId(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return getLong(cd, ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public static long getStartTime(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return getLong(cd, START_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static long getEndTime(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return getLong(cd, END_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public static Map<String, MemoryUsage>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            getMemoryUsageBeforeGc(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            TabularData td = (TabularData) cd.get(MEMORY_USAGE_BEFORE_GC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return cast(memoryUsageMapType.toJavaTypeData(td));
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 9698
diff changeset
   217
        } catch (InvalidObjectException | OpenDataException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   219
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    @SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static Map<String, MemoryUsage> cast(Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return (Map<String, MemoryUsage>) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public static Map<String, MemoryUsage>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            getMemoryUsageAfterGc(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            TabularData td = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            //return (Map<String,MemoryUsage>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return cast(memoryUsageMapType.toJavaTypeData(td));
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 9698
diff changeset
   233
        } catch (InvalidObjectException | OpenDataException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   235
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Returns true if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * names and types).  Otherwise, return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (!isTypeMatched(getBaseGcInfoCompositeType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                           cd.getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
           throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                "Unexpected composite type for GcInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    // This is only used for validation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private static CompositeType baseGcInfoCompositeType = null;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 5506
diff changeset
   258
    static synchronized CompositeType getBaseGcInfoCompositeType() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (baseGcInfoCompositeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                baseGcInfoCompositeType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    new CompositeType("sun.management.BaseGcInfoCompositeType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                      "CompositeType for Base GcInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                      getBaseGcInfoItemNames(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                      getBaseGcInfoItemNames(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                      getBaseGcInfoItemTypes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                // shouldn't reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                throw Util.newException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return baseGcInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   275
    private static final long serialVersionUID = -5716428894085882742L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}