Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GcInfoBuilder.java « management « sun « openjdk - github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: abe5082f5cc996e71aacca073e710b99c6f818e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package sun.management;

import ikvm.internal.NotYetImplementedError;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.MemoryUsage;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularType;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;
import com.sun.management.GcInfo;

/**
 * Helper class to build composite data.
 */
public class GcInfoBuilder {
    private final GarbageCollectorMXBean gc;
    private final String[] poolNames;
    private String[] allItemNames;

    // GC-specific composite type:
    // Each GarbageCollectorMXBean may have different GC-specific attributes
    // the CompositeType for the GcInfo could be different.
    private CompositeType gcInfoCompositeType;

    // GC-specific items
    private final int gcExtItemCount;
    private final String[] gcExtItemNames;
    private final String[] gcExtItemDescs;
    private final char[] gcExtItemTypes;

    GcInfoBuilder(GarbageCollectorMXBean gc, String[] poolNames) {
        this.gc = gc;
        this.poolNames = poolNames;
        this.gcExtItemCount = getNumGcExtAttributes(gc);
        this.gcExtItemNames = new String[gcExtItemCount];
        this.gcExtItemDescs = new String[gcExtItemCount];
        this.gcExtItemTypes = new char[gcExtItemCount];

        // Fill the information about extension attributes
        fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames,
                            gcExtItemTypes, gcExtItemDescs);

        // lazily build the CompositeType for the GcInfo
        // including the GC-specific extension attributes
        this.gcInfoCompositeType = null;
    }

    GcInfo getLastGcInfo() {
        MemoryUsage[] usageBeforeGC = new MemoryUsage[poolNames.length];
        MemoryUsage[] usageAfterGC = new MemoryUsage[poolNames.length];
        Object[] values = new Object[gcExtItemCount];

        return getLastGcInfo0(gc, gcExtItemCount, values, gcExtItemTypes,
                              usageBeforeGC, usageAfterGC);
    }

    public String[] getPoolNames() {
        return poolNames;
    }

    int getGcExtItemCount() {
        return gcExtItemCount;
    }

    // Returns the CompositeType for the GcInfo including
    // the extension attributes
    synchronized CompositeType getGcInfoCompositeType() {
        if (gcInfoCompositeType != null)
            return gcInfoCompositeType;

        // First, fill with the attributes in the GcInfo
        String[] gcInfoItemNames = GcInfoCompositeData.getBaseGcInfoItemNames();
        OpenType[] gcInfoItemTypes = GcInfoCompositeData.getBaseGcInfoItemTypes();
        int numGcInfoItems = gcInfoItemNames.length;

        int itemCount = numGcInfoItems + gcExtItemCount;
        allItemNames = new String[itemCount];
        String[] allItemDescs = new String[itemCount];
        OpenType[] allItemTypes = new OpenType[itemCount];

        System.arraycopy(gcInfoItemNames, 0, allItemNames, 0, numGcInfoItems);
        System.arraycopy(gcInfoItemNames, 0, allItemDescs, 0, numGcInfoItems);
        System.arraycopy(gcInfoItemTypes, 0, allItemTypes, 0, numGcInfoItems);

        // Then fill with the extension GC-specific attributes, if any.
        if (gcExtItemCount > 0) {
            fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames,
                                gcExtItemTypes, gcExtItemDescs);
            System.arraycopy(gcExtItemNames, 0, allItemNames,
                             numGcInfoItems, gcExtItemCount);
            System.arraycopy(gcExtItemDescs, 0, allItemDescs,
                             numGcInfoItems, gcExtItemCount);
            for (int i = numGcInfoItems, j = 0; j < gcExtItemCount; i++, j++) {
                switch (gcExtItemTypes[j]) {
                    case 'Z':
                        allItemTypes[i] = SimpleType.BOOLEAN;
                        break;
                    case 'B':
                        allItemTypes[i] = SimpleType.BYTE;
                        break;
                    case 'C':
                        allItemTypes[i] = SimpleType.CHARACTER;
                        break;
                    case 'S':
                        allItemTypes[i] = SimpleType.SHORT;
                        break;
                    case 'I':
                        allItemTypes[i] = SimpleType.INTEGER;
                        break;
                    case 'J':
                        allItemTypes[i] = SimpleType.LONG;
                        break;
                    case 'F':
                        allItemTypes[i] = SimpleType.FLOAT;
                        break;
                    case 'D':
                        allItemTypes[i] = SimpleType.DOUBLE;
                        break;
                    default:
                        throw new AssertionError(
                            "Unsupported type [" + gcExtItemTypes[i] + "]");
                }
            }
        }

        CompositeType gict = null;
        try {
            final String typeName =
                "sun.management." + gc.getName() + ".GcInfoCompositeType";

            gict = new CompositeType(typeName,
                                     "CompositeType for GC info for " +
                                         gc.getName(),
                                     allItemNames,
                                     allItemDescs,
                                     allItemTypes);
        } catch (OpenDataException e) {
            // shouldn't reach here
            throw Util.newException(e);
        }
        gcInfoCompositeType = gict;

        return gcInfoCompositeType;
    }

    synchronized String[] getItemNames() {
        if (allItemNames == null) {
            // initialize when forming the composite type
            getGcInfoCompositeType();
        }
        return allItemNames;
    }

    // Retrieve information about extension attributes
    private /*native*/ int getNumGcExtAttributes(GarbageCollectorMXBean gc){
    	throw new NotYetImplementedError();
    }
    
    private /*native*/ void fillGcAttributeInfo(GarbageCollectorMXBean gc,
                                            int numAttributes,
                                            String[] attributeNames,
                                            char[] types,
                                            String[] descriptions){
    	throw new NotYetImplementedError();
    }

    /**
     * Returns the last GcInfo
     *
     * @param gc GarbageCollectorMXBean that the gc info is associated with.
     * @param numExtAtts number of extension attributes
     * @param extAttValues Values of extension attributes to be filled.
     * @param before Memory usage before GC to be filled.
     * @param after Memory usage after GC to be filled.
     */
    private /*native*/ GcInfo getLastGcInfo0(GarbageCollectorMXBean gc,
                                         int numExtAtts,
                                         Object[] extAttValues,
                                         char[] extAttTypes,
                                         MemoryUsage[] before,
                                         MemoryUsage[] after){
    	throw new NotYetImplementedError();
    }
}