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 25 package sun.hotspot.code; 26 27 import java.lang.management.ManagementFactory; 28 import java.lang.management.MemoryPoolMXBean; 29 import java.util.EnumSet; 30 31 import sun.hotspot.WhiteBox; 32 33 public enum BlobType { 34 // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods) 35 MethodNonProfiled(0, "CodeHeap 'non-profiled nmethods'", "NonProfiledCodeHeapSize"), 36 // Execution level 2 and 3 (profiled) nmethods 37 MethodProfiled(1, "CodeHeap 'profiled nmethods'", "ProfiledCodeHeapSize"), 38 // Non-nmethods like Buffers, Adapters and Runtime Stubs 39 NonNMethod(2, "CodeHeap 'non-nmethods'", "NonNMethodCodeHeapSize") { 40 @Override 41 public boolean allowTypeWhenOverflow(BlobType type) { 42 return super.allowTypeWhenOverflow(type) 43 || type == BlobType.MethodNonProfiled; 44 } 45 }, 46 // All types (No code cache segmentation) 47 All(3, "CodeCache", "ReservedCodeCacheSize"); 48 49 public final int id; 50 public final String sizeOptionName; 51 public final String beanName; 52 53 private BlobType(int id, String beanName, String sizeOptionName) { 54 this.id = id; 55 this.beanName = beanName; 56 this.sizeOptionName = sizeOptionName; 57 } 58 59 public MemoryPoolMXBean getMemoryPool() { 60 for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) { 61 String name = bean.getName(); 62 if (beanName.equals(name)) { 63 return bean; 64 } 65 } 66 return null; 67 } 68 69 public boolean allowTypeWhenOverflow(BlobType type) { 70 return type == this; 71 } 72 73 public static EnumSet<BlobType> getAvailable() { 74 WhiteBox whiteBox = WhiteBox.getWhiteBox(); 75 if (!whiteBox.getBooleanVMFlag("SegmentedCodeCache")) { 76 // only All for non segmented world 77 return EnumSet.of(All); 78 } 79 if (System.getProperty("java.vm.info").startsWith("interpreted ")) { 80 // only NonNMethod for -Xint 81 return EnumSet.of(NonNMethod); 82 } 83 84 EnumSet<BlobType> result = EnumSet.complementOf(EnumSet.of(All)); 85 if (!whiteBox.getBooleanVMFlag("TieredCompilation") 86 || whiteBox.getIntxVMFlag("TieredStopAtLevel") <= 1) { 87 // there is no MethodProfiled in non tiered world or pure C1 88 result.remove(MethodProfiled); 89 } 90 return result; 91 } 92 93 public long getSize() { 94 return WhiteBox.getWhiteBox().getUintxVMFlag(sizeOptionName); 95 } 96 }