Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfrijters <jfrijters>2010-05-02 12:20:59 +0400
committerjfrijters <jfrijters>2010-05-02 12:20:59 +0400
commitc1b4c62675013fb1c62d3716a11473ceb274d537 (patch)
tree75f54b2697b5604ca0b5e28f785685b2c2d187bb /openjdk/com
parent0ec793d8434829d11c284ec793b7a38df1c6d3c6 (diff)
Implemented OperatingSystemMXBean.
Diffstat (limited to 'openjdk/com')
-rw-r--r--openjdk/com/sun/management/OperatingSystem.java143
1 files changed, 143 insertions, 0 deletions
diff --git a/openjdk/com/sun/management/OperatingSystem.java b/openjdk/com/sun/management/OperatingSystem.java
new file mode 100644
index 00000000..7357cef8
--- /dev/null
+++ b/openjdk/com/sun/management/OperatingSystem.java
@@ -0,0 +1,143 @@
+/*
+ Copyright (C) 2010 Jeroen Frijters
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jeroen Frijters
+ jeroen@frijters.net
+
+*/
+
+package com.sun.management;
+
+import cli.System.Activator;
+import cli.System.Diagnostics.Process;
+import cli.System.Reflection.Assembly;
+import cli.System.Reflection.PropertyInfo;
+import cli.System.Runtime.InteropServices.DllImportAttribute;
+import cli.System.Runtime.InteropServices.LayoutKind;
+import cli.System.Runtime.InteropServices.StructLayoutAttribute;
+import cli.System.Security.SecuritySafeCriticalAttribute;
+import cli.System.Type;
+import sun.management.OperatingSystemImpl;
+import sun.management.VMManagement;
+
+class OperatingSystem extends OperatingSystemImpl implements OperatingSystemMXBean
+{
+ OperatingSystem(VMManagement vmm)
+ {
+ super(vmm);
+ }
+
+ public long getProcessCpuTime()
+ {
+ return Process.GetCurrentProcess().get_TotalProcessorTime().get_Ticks() * 100;
+ }
+
+ public long getCommittedVirtualMemorySize()
+ {
+ return Process.GetCurrentProcess().get_PagedMemorySize64();
+ }
+
+ public long getTotalPhysicalMemorySize()
+ {
+ long value = get("TotalPhysicalMemory");
+ if (value != -1)
+ {
+ return value;
+ }
+ return GetMemoryStatusEx().ullTotalPhys;
+ }
+
+ public long getFreePhysicalMemorySize()
+ {
+ long value = get("AvailablePhysicalMemory");
+ if (value != -1)
+ {
+ return value;
+ }
+ return GetMemoryStatusEx().ullAvailPhys;
+ }
+
+ public long getTotalSwapSpaceSize()
+ {
+ return GetMemoryStatusEx().ullTotalPageFile;
+ }
+
+ public long getFreeSwapSpaceSize()
+ {
+ return GetMemoryStatusEx().ullAvailPageFile;
+ }
+
+ private static long get(String propertyName)
+ {
+ Assembly asm = Assembly.LoadWithPartialName("Microsoft.VisualBasic");
+ if (asm != null)
+ {
+ Type type = asm.GetType("Microsoft.VisualBasic.Devices.ComputerInfo");
+ if (type != null)
+ {
+ PropertyInfo property = type.GetProperty(propertyName);
+ if (property != null)
+ {
+ Object obj = Activator.CreateInstance(type);
+ try
+ {
+ if (false) throw new cli.System.NotImplementedException();
+ return ikvm.lang.CIL.unbox_ulong((cli.System.UInt64)property.GetValue(obj, null));
+ }
+ catch (cli.System.NotImplementedException _)
+ {
+ // Mono doesn't implement this property
+ }
+ }
+ }
+ }
+ return -1;
+ }
+
+ @SecuritySafeCriticalAttribute.Annotation
+ private static MEMORYSTATUSEX GetMemoryStatusEx()
+ {
+ if (ikvm.internal.Util.WINDOWS)
+ {
+ MEMORYSTATUSEX mem = new MEMORYSTATUSEX();
+ if (GlobalMemoryStatusEx(mem))
+ {
+ return mem;
+ }
+ }
+ throw new InternalError("Unsupported Platform");
+ }
+
+ @DllImportAttribute.Annotation("kernel32")
+ private static native boolean GlobalMemoryStatusEx(MEMORYSTATUSEX lpBuffer);
+}
+
+@StructLayoutAttribute.Annotation(LayoutKind.__Enum.Sequential)
+final class MEMORYSTATUSEX extends cli.System.Object
+{
+ int dwLength = 64;
+ int dwMemoryLoad;
+ long ullTotalPhys;
+ long ullAvailPhys;
+ long ullTotalPageFile;
+ long ullAvailPageFile;
+ long ullTotalVirtual;
+ long ullAvailVirtual;
+ long ullAvailExtendedVirtual;
+}