BlobType.java revision 1373:c053f9a0aa72
1/*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25package sun.hotspot.code;
26
27import java.lang.management.ManagementFactory;
28import java.lang.management.MemoryPoolMXBean;
29import java.util.EnumSet;
30
31import sun.hotspot.WhiteBox;
32
33public enum BlobType {
34    // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
35    MethodNonProfiled(0, "CodeHeap 'non-profiled nmethods'", "NonProfiledCodeHeapSize") {
36        @Override
37        public boolean allowTypeWhenOverflow(BlobType type) {
38            return super.allowTypeWhenOverflow(type)
39                    || type == BlobType.MethodProfiled;
40        }
41    },
42    // Execution level 2 and 3 (profiled) nmethods
43    MethodProfiled(1, "CodeHeap 'profiled nmethods'", "ProfiledCodeHeapSize") {
44        @Override
45        public boolean allowTypeWhenOverflow(BlobType type) {
46            return super.allowTypeWhenOverflow(type)
47                    || type == BlobType.MethodNonProfiled;
48        }
49    },
50    // Non-nmethods like Buffers, Adapters and Runtime Stubs
51    NonNMethod(2, "CodeHeap 'non-nmethods'", "NonNMethodCodeHeapSize") {
52        @Override
53        public boolean allowTypeWhenOverflow(BlobType type) {
54            return super.allowTypeWhenOverflow(type)
55                    || type == BlobType.MethodNonProfiled
56                    || type == BlobType.MethodProfiled;
57        }
58    },
59    // All types (No code cache segmentation)
60    All(3, "CodeCache", "ReservedCodeCacheSize");
61
62    public final int id;
63    public final String sizeOptionName;
64    public final String beanName;
65
66    private BlobType(int id, String beanName, String sizeOptionName) {
67        this.id = id;
68        this.beanName = beanName;
69        this.sizeOptionName = sizeOptionName;
70    }
71
72    public MemoryPoolMXBean getMemoryPool() {
73        for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) {
74            String name = bean.getName();
75            if (beanName.equals(name)) {
76                return bean;
77            }
78        }
79        return null;
80    }
81
82    public boolean allowTypeWhenOverflow(BlobType type) {
83        return type == this;
84    }
85
86    public static EnumSet<BlobType> getAvailable() {
87        WhiteBox whiteBox = WhiteBox.getWhiteBox();
88        if (!whiteBox.getBooleanVMFlag("SegmentedCodeCache")) {
89            // only All for non segmented world
90            return EnumSet.of(All);
91        }
92        if (System.getProperty("java.vm.info").startsWith("interpreted ")) {
93            // only NonNMethod for -Xint
94            return EnumSet.of(NonNMethod);
95        }
96
97        EnumSet<BlobType> result = EnumSet.complementOf(EnumSet.of(All));
98        if (!whiteBox.getBooleanVMFlag("TieredCompilation")
99                || whiteBox.getIntxVMFlag("TieredStopAtLevel") <= 1) {
100            // there is no MethodProfiled in non tiered world or pure C1
101            result.remove(MethodProfiled);
102        }
103        return result;
104    }
105
106    public long getSize() {
107        return WhiteBox.getWhiteBox().getUintxVMFlag(sizeOptionName);
108    }
109}
110