1 /*
   2  * Copyright (c) 2003, 2004, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.management.snmp.jvminstr;
  26 
  27 // java imports
  28 //
  29 import java.io.Serializable;
  30 import java.lang.management.ManagementFactory;
  31 import java.lang.management.CompilationMXBean;
  32 
  33 // jmx imports
  34 //
  35 import javax.management.MBeanServer;
  36 import com.sun.jmx.snmp.SnmpString;
  37 import com.sun.jmx.snmp.SnmpStatusException;
  38 
  39 // jdmk imports
  40 //
  41 import com.sun.jmx.snmp.agent.SnmpMib;
  42 
  43 import sun.management.snmp.jvmmib.JvmCompilationMBean;
  44 import sun.management.snmp.jvmmib.EnumJvmJITCompilerTimeMonitoring;
  45 import sun.management.snmp.util.MibLogger;
  46 
  47 /**
  48  * The class is used for implementing the "JvmCompilation" group.
  49  */
  50 public class JvmCompilationImpl implements JvmCompilationMBean {
  51 
  52     /**
  53      * Variable for storing the value of "JvmJITCompilerTimeMonitoring".
  54      *
  55      * "Indicates whether the Java virtual machine supports
  56      * compilation time monitoring.
  57      *
  58      * See java.management.CompilationMXBean.
  59      * isCompilationTimeMonitoringSupported()
  60      * "
  61      *
  62      */
  63     static final EnumJvmJITCompilerTimeMonitoring
  64         JvmJITCompilerTimeMonitoringSupported =
  65         new EnumJvmJITCompilerTimeMonitoring("supported");
  66     static final EnumJvmJITCompilerTimeMonitoring
  67         JvmJITCompilerTimeMonitoringUnsupported =
  68         new EnumJvmJITCompilerTimeMonitoring("unsupported");
  69 
  70 
  71     /**
  72      * Constructor for the "JvmCompilation" group.
  73      * If the group contains a table, the entries created through an SNMP SET
  74      * will not be registered in Java DMK.
  75      */
  76     public JvmCompilationImpl(SnmpMib myMib) {
  77     }
  78 
  79 
  80     /**
  81      * Constructor for the "JvmCompilation" group.
  82      * If the group contains a table, the entries created through an SNMP
  83      * SET will be AUTOMATICALLY REGISTERED in Java DMK.
  84      */
  85     public JvmCompilationImpl(SnmpMib myMib, MBeanServer server) {
  86     }
  87 
  88     private static CompilationMXBean getCompilationMXBean() {
  89         return ManagementFactory.getCompilationMXBean();
  90     }
  91 
  92     /**
  93      * Getter for the "JvmJITCompilerTimeMonitoring" variable.
  94      */
  95     public EnumJvmJITCompilerTimeMonitoring getJvmJITCompilerTimeMonitoring()
  96         throws SnmpStatusException {
  97 
  98         // If we reach this point, then we can safely assume that
  99         // getCompilationMXBean() will not return null, because this
 100         // object will not be instantiated when there is no compilation
 101         // system (see JVM_MANAGEMENT_MIB_IMPL).
 102         //
 103         if(getCompilationMXBean().isCompilationTimeMonitoringSupported())
 104             return JvmJITCompilerTimeMonitoringSupported;
 105         else
 106             return JvmJITCompilerTimeMonitoringUnsupported;
 107     }
 108 
 109     /**
 110      * Getter for the "JvmJITCompilerTimeMs" variable.
 111      */
 112     public Long getJvmJITCompilerTimeMs() throws SnmpStatusException {
 113         final long t;
 114         if(getCompilationMXBean().isCompilationTimeMonitoringSupported())
 115             t = getCompilationMXBean().getTotalCompilationTime();
 116         else
 117             t = 0;
 118         return new Long(t);
 119     }
 120 
 121     /**
 122      * Getter for the "JvmJITCompilerName" variable.
 123      */
 124     public String getJvmJITCompilerName() throws SnmpStatusException {
 125         return JVM_MANAGEMENT_MIB_IMPL.
 126             validJavaObjectNameTC(getCompilationMXBean().getName());
 127     }
 128 
 129 }