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'"),
  36     // Execution level 2 and 3 (profiled) nmethods
  37     MethodProfiled(1, "CodeHeap 'profiled nmethods'"),
  38     // Non-nmethods like Buffers, Adapters and Runtime Stubs
  39     NonNMethod(2, "CodeHeap 'non-nmethods'"),
  40     // All types (No code cache segmentation)
  41     All(3, "CodeCache");
  42 
  43     public final int id;
  44     private final String beanName;
  45 
  46     private BlobType(int id, String beanName) {
  47         this.id = id;
  48         this.beanName = beanName;
  49     }
  50 
  51     public MemoryPoolMXBean getMemoryPool() {
  52         for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) {
  53             String name = bean.getName();
  54             if (beanName.equals(name)) {
  55                 return bean;
  56             }
  57         }
  58         return null;
  59     }
  60     public static EnumSet<BlobType> getAvailable() {
  61         WhiteBox whiteBox = WhiteBox.getWhiteBox();
  62         if (!whiteBox.getBooleanVMFlag("SegmentedCodeCache")) {
  63             // only All for non segmented world
  64             return EnumSet.of(All);
  65         }
  66 
  67         EnumSet<BlobType> result = EnumSet.complementOf(EnumSet.of(All));
  68         if (!whiteBox.getBooleanVMFlag("TieredCompilation")) {
  69             // there is no MethodProfiled in non tiered world
  70             result.remove(MethodProfiled);
  71         }
  72         return result;
  73     }
  74 }