BaseOperatingSystemImpl.java revision 13050:98f89fe2b722
1178476Sjb/* 2178476Sjb * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 3178476Sjb * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4178476Sjb * 5178476Sjb * This code is free software; you can redistribute it and/or modify it 6178476Sjb * under the terms of the GNU General Public License version 2 only, as 7178476Sjb * published by the Free Software Foundation. Oracle designates this 8178476Sjb * particular file as subject to the "Classpath" exception as provided 9178476Sjb * by Oracle in the LICENSE file that accompanied this code. 10178476Sjb * 11178476Sjb * This code is distributed in the hope that it will be useful, but WITHOUT 12178476Sjb * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13178476Sjb * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14178476Sjb * version 2 for more details (a copy is included in the LICENSE file that 15178476Sjb * accompanied this code). 16178476Sjb * 17178476Sjb * You should have received a copy of the GNU General Public License version 18178476Sjb * 2 along with this work; if not, write to the Free Software Foundation, 19178476Sjb * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20178476Sjb * 21178476Sjb * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22178476Sjb * or visit www.oracle.com if you need additional information or have any 23178476Sjb * questions. 24178476Sjb */ 25178476Sjb 26178476Sjbpackage sun.management; 27178476Sjb 28178476Sjbimport java.lang.management.OperatingSystemMXBean; 29178476Sjbimport java.lang.management.ManagementFactory; 30178476Sjbimport javax.management.ObjectName; 31178476Sjbimport jdk.internal.misc.Unsafe; 32178476Sjb 33178476Sjb/** 34178476Sjb * Implementation class for the operating system. 35178476Sjb * Standard and committed hotspot-specific metrics if any. 36178476Sjb * 37178476Sjb * ManagementFactory.getOperatingSystemMXBean() returns an instance 38178476Sjb * of this class. 39178476Sjb */ 40178476Sjbpublic class BaseOperatingSystemImpl implements OperatingSystemMXBean { 41178476Sjb 42178476Sjb private final VMManagement jvm; 43178476Sjb 44178476Sjb /** 45178476Sjb * Constructor of BaseOperatingSystemImpl class. 46178476Sjb */ 47178476Sjb protected BaseOperatingSystemImpl(VMManagement vm) { 48178476Sjb this.jvm = vm; 49178476Sjb } 50178476Sjb 51178476Sjb public String getName() { 52178476Sjb return jvm.getOsName(); 53178476Sjb } 54178476Sjb 55178476Sjb public String getArch() { 56178476Sjb return jvm.getOsArch(); 57178476Sjb } 58178476Sjb 59178476Sjb public String getVersion() { 60178476Sjb return jvm.getOsVersion(); 61178476Sjb } 62178476Sjb 63178476Sjb public int getAvailableProcessors() { 64178476Sjb return jvm.getAvailableProcessors(); 65178476Sjb } 66178476Sjb 67178476Sjb private static final Unsafe unsafe = Unsafe.getUnsafe(); 68178476Sjb private double[] loadavg = new double[1]; 69178476Sjb public double getSystemLoadAverage() { 70178476Sjb if (unsafe.getLoadAverage(loadavg, 1) == 1) { 71 return loadavg[0]; 72 } else { 73 return -1.0; 74 } 75 } 76 public ObjectName getObjectName() { 77 return Util.newObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME); 78 } 79 80} 81