1 /* 2 * Copyright (c) 2003, 2015, 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 26 package com.sun.management.internal; 27 28 import com.sun.management.OperatingSystemMXBean; 29 import sun.management.BaseOperatingSystemImpl; 30 import sun.management.VMManagement; 31 32 /** 33 * Implementation class for the operating system. 34 * Standard and committed hotspot-specific metrics if any. 35 * 36 * ManagementFactory.getOperatingSystemMXBean() returns an instance 37 * of this class. 38 */ 39 class OperatingSystemImpl extends BaseOperatingSystemImpl 40 implements OperatingSystemMXBean { 41 42 // psapiLock is a lock to make sure only one thread loading 43 // PSAPI DLL. 44 private static Object psapiLock = new Object(); 45 46 OperatingSystemImpl(VMManagement vm) { 47 super(vm); 48 } 49 50 @Override 51 public long getCommittedVirtualMemorySize() { 52 synchronized (psapiLock) { 53 return getCommittedVirtualMemorySize0(); 54 } 55 } 56 57 @Override 58 public long getTotalSwapSpaceSize() { 59 return getTotalSwapSpaceSize0(); 60 } 61 62 @Override 63 public long getFreeSwapSpaceSize() { 64 return getFreeSwapSpaceSize0(); 65 } 66 67 @Override 68 public long getProcessCpuTime() { 69 return getProcessCpuTime0(); 70 } 71 72 @Override 73 public long getFreePhysicalMemorySize() { 74 return getFreePhysicalMemorySize0(); 75 } 76 77 @Override 78 public long getTotalPhysicalMemorySize() { 79 return getTotalPhysicalMemorySize0(); 80 } 81 82 @Override 83 public double getSystemCpuLoad() { 84 return getSystemCpuLoad0(); 85 } 86 87 @Override 88 public double getProcessCpuLoad() { 89 return getProcessCpuLoad0(); 90 } 91 92 /* native methods */ 93 private native long getCommittedVirtualMemorySize0(); 94 private native long getFreePhysicalMemorySize0(); 95 private native long getFreeSwapSpaceSize0(); 96 private native double getProcessCpuLoad0(); 97 private native long getProcessCpuTime0(); 98 private native double getSystemCpuLoad0(); 99 private native long getTotalPhysicalMemorySize0(); 100 private native long getTotalSwapSpaceSize0(); 101 102 static { 103 initialize0(); 104 } 105 106 private static native void initialize0(); 107 }