src/share/classes/sun/management/ManagementFactoryHelper.java

Print this page




  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 
  26 package sun.management;
  27 
  28 import java.lang.management.*;
  29 
  30 import javax.management.InstanceAlreadyExistsException;
  31 import javax.management.InstanceNotFoundException;
  32 import javax.management.MBeanServer;
  33 import javax.management.MBeanRegistrationException;
  34 import javax.management.NotCompliantMBeanException;
  35 import javax.management.ObjectName;
  36 import javax.management.RuntimeOperationsException;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedActionException;
  39 import java.security.PrivilegedExceptionAction;
  40 import sun.security.action.LoadLibraryAction;
  41 
  42 import sun.util.logging.LoggingSupport;
  43 
  44 import java.util.ArrayList;
  45 import java.util.Collections;
  46 import java.util.List;
  47 import com.sun.management.OSMBeanFactory;
  48 import com.sun.management.HotSpotDiagnosticMXBean;
  49 
  50 import static java.lang.management.ManagementFactory.*;
  51 
  52 /**
  53  * ManagementFactoryHelper provides static factory methods to create
  54  * instances of the management interface.
  55  */
  56 public class ManagementFactoryHelper {
  57     private ManagementFactoryHelper() {};
  58 
  59     private static VMManagement jvm;
  60 


 405             });
 406         } catch (PrivilegedActionException e) {
 407             throw Util.newException(e.getException());
 408         }
 409     }
 410 
 411     static void unregisterInternalMBeans(MBeanServer mbs) {
 412         // unregister all internal MBeans
 413         unregisterMBean(mbs, HOTSPOT_CLASS_LOADING_MBEAN_NAME);
 414         unregisterMBean(mbs, HOTSPOT_MEMORY_MBEAN_NAME);
 415         unregisterMBean(mbs, HOTSPOT_RUNTIME_MBEAN_NAME);
 416         unregisterMBean(mbs, HOTSPOT_THREAD_MBEAN_NAME);
 417 
 418         // CompilationMBean may not exist
 419         if (getCompilationMXBean() != null) {
 420             unregisterMBean(mbs, HOTSPOT_COMPILATION_MBEAN_NAME);
 421         }
 422     }
 423 
 424     static {
 425         AccessController.doPrivileged(new LoadLibraryAction("management"));






 426         jvm = new VMManagementImpl();
 427     }
 428 
 429     public static boolean isThreadSuspended(int state) {
 430         return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0);
 431     }
 432 
 433     public static boolean isThreadRunningNative(int state) {
 434         return ((state & JMM_THREAD_STATE_FLAG_NATIVE) != 0);
 435     }
 436 
 437     public static Thread.State toThreadState(int state) {
 438         // suspended and native bits may be set in state
 439         int threadStatus = state & ~JMM_THREAD_STATE_FLAG_MASK;
 440         return sun.misc.VM.toThreadState(threadStatus);
 441     }
 442 
 443     // These values are defined in jmm.h
 444     private static final int JMM_THREAD_STATE_FLAG_MASK = 0xFFF00000;
 445     private static final int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000;


  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 
  26 package sun.management;
  27 
  28 import java.lang.management.*;
  29 
  30 import javax.management.InstanceAlreadyExistsException;
  31 import javax.management.InstanceNotFoundException;
  32 import javax.management.MBeanServer;
  33 import javax.management.MBeanRegistrationException;
  34 import javax.management.NotCompliantMBeanException;
  35 import javax.management.ObjectName;
  36 import javax.management.RuntimeOperationsException;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedActionException;
  39 import java.security.PrivilegedExceptionAction;

  40 
  41 import sun.util.logging.LoggingSupport;
  42 
  43 import java.util.ArrayList;
  44 import java.util.Collections;
  45 import java.util.List;
  46 import com.sun.management.OSMBeanFactory;
  47 import com.sun.management.HotSpotDiagnosticMXBean;
  48 
  49 import static java.lang.management.ManagementFactory.*;
  50 
  51 /**
  52  * ManagementFactoryHelper provides static factory methods to create
  53  * instances of the management interface.
  54  */
  55 public class ManagementFactoryHelper {
  56     private ManagementFactoryHelper() {};
  57 
  58     private static VMManagement jvm;
  59 


 404             });
 405         } catch (PrivilegedActionException e) {
 406             throw Util.newException(e.getException());
 407         }
 408     }
 409 
 410     static void unregisterInternalMBeans(MBeanServer mbs) {
 411         // unregister all internal MBeans
 412         unregisterMBean(mbs, HOTSPOT_CLASS_LOADING_MBEAN_NAME);
 413         unregisterMBean(mbs, HOTSPOT_MEMORY_MBEAN_NAME);
 414         unregisterMBean(mbs, HOTSPOT_RUNTIME_MBEAN_NAME);
 415         unregisterMBean(mbs, HOTSPOT_THREAD_MBEAN_NAME);
 416 
 417         // CompilationMBean may not exist
 418         if (getCompilationMXBean() != null) {
 419             unregisterMBean(mbs, HOTSPOT_COMPILATION_MBEAN_NAME);
 420         }
 421     }
 422 
 423     static {
 424         AccessController.doPrivileged(
 425             new java.security.PrivilegedAction<Void>() {
 426                 public Void run() {
 427                     System.loadLibrary("management");
 428                     return null;
 429                 }
 430             });
 431         jvm = new VMManagementImpl();
 432     }
 433 
 434     public static boolean isThreadSuspended(int state) {
 435         return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0);
 436     }
 437 
 438     public static boolean isThreadRunningNative(int state) {
 439         return ((state & JMM_THREAD_STATE_FLAG_NATIVE) != 0);
 440     }
 441 
 442     public static Thread.State toThreadState(int state) {
 443         // suspended and native bits may be set in state
 444         int threadStatus = state & ~JMM_THREAD_STATE_FLAG_MASK;
 445         return sun.misc.VM.toThreadState(threadStatus);
 446     }
 447 
 448     // These values are defined in jmm.h
 449     private static final int JMM_THREAD_STATE_FLAG_MASK = 0xFFF00000;
 450     private static final int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000;