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