2
Copyright (C) 2011 Jeroen Frijters
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
25
using java.lang.management;
28
static class Java_sun_management_ClassLoadingImpl
30
public static void setVerboseClass(bool value)
35
static class Java_sun_management_MemoryImpl
37
public static object getMemoryPools0()
42
return new MemoryPoolMXBean[0];
46
public static object getMemoryManagers0()
51
return new MemoryManagerMXBean[0];
55
public static object getMemoryUsage0(object impl, bool heap)
60
long mem = System.GC.GetTotalMemory(false);
61
return new MemoryUsage(-1, mem, mem, -1);
65
public static void setVerboseGC(object impl, bool value)
70
static class Java_sun_management_ThreadImpl
72
public static object getThreads()
74
return IKVM.NativeCode.java.lang.Thread.getThreads();
77
private const int JVMTI_THREAD_STATE_ALIVE = 0x0001;
78
private const int JVMTI_THREAD_STATE_TERMINATED = 0x0002;
79
private const int JVMTI_THREAD_STATE_RUNNABLE = 0x0004;
80
private const int JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER = 0x0400;
81
private const int JVMTI_THREAD_STATE_WAITING_INDEFINITELY = 0x0010;
82
private const int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020;
83
private const int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000;
84
private const int JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000;
86
public static void getThreadInfo1(long[] ids, int maxDepth, object result)
90
System.Reflection.ConstructorInfo[] constructors = typeof(java.lang.management.ThreadInfo).GetConstructors( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
91
foreach (System.Reflection.ConstructorInfo constructor in constructors)
93
if (constructor.GetParameters().Length == 9)
95
java.lang.Thread[] threads = (java.lang.Thread[])getThreads();
96
java.lang.management.ThreadInfo[] threadInfos = (java.lang.management.ThreadInfo[])result;
97
for (int i = 0; i < ids.Length; i++)
100
for (int t = 0; t < threads.Length; t++)
102
if (threads[t].getId() == id)
104
java.lang.Thread thread = threads[t];
107
// invers to sun.misc.VM.toThreadState
108
switch(thread.getState().ordinal())
110
case (int)java.lang.Thread.State.__Enum.RUNNABLE:
111
state = JVMTI_THREAD_STATE_RUNNABLE;
113
case (int)java.lang.Thread.State.__Enum.BLOCKED:
114
state = JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
116
case (int)java.lang.Thread.State.__Enum.WAITING:
117
state = JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
119
case (int)java.lang.Thread.State.__Enum.TIMED_WAITING:
120
state = JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
122
case (int)java.lang.Thread.State.__Enum.TERMINATED:
123
state = JVMTI_THREAD_STATE_TERMINATED;
125
case (int)java.lang.Thread.State.__Enum.NEW:
126
state = JVMTI_THREAD_STATE_ALIVE;
132
//TODO set in state JMM_THREAD_STATE_FLAG_SUSPENDED if the thread is suspended
134
java.lang.StackTraceElement[] stacktrace = thread.getStackTrace();
135
if (maxDepth >= 0 && maxDepth < stacktrace.Length)
137
java.lang.StackTraceElement[] temp = new java.lang.StackTraceElement[maxDepth];
138
System.Array.Copy(stacktrace, temp, temp.Length);
142
object[] parameters = new object[9];
143
parameters[0] = thread; // thread
144
parameters[1] = state; // state
147
parameters[4] = 0; // blockedCount
148
parameters[5] = 0; // blockedTime
149
parameters[6] = -1; // waitedCount
150
parameters[7] = 0; // waitedTime
151
parameters[8] = stacktrace; // stackTrace
152
threadInfos[i] = (java.lang.management.ThreadInfo)constructor.Invoke(parameters);
160
throw new java.lang.InternalError("Constructor for java.lang.management.ThreadInfo not find.");
164
public static long getThreadTotalCpuTime0(long id)
166
throw new System.NotImplementedException();
169
public static void getThreadTotalCpuTime1(long[] ids, long[] result)
171
throw new System.NotImplementedException();
174
public static long getThreadUserCpuTime0(long id)
176
throw new System.NotImplementedException();
179
public static void getThreadUserCpuTime1(long[] ids, long[] result)
181
throw new System.NotImplementedException();
184
public static void getThreadAllocatedMemory1(long[] ids, long[] result)
186
throw new System.NotImplementedException();
189
public static void setThreadCpuTimeEnabled0(bool enable)
191
throw new System.NotImplementedException();
194
public static void setThreadAllocatedMemoryEnabled0(bool enable)
196
throw new System.NotImplementedException();
199
public static void setThreadContentionMonitoringEnabled0(bool enable)
201
throw new System.NotImplementedException();
204
public static object findMonitorDeadlockedThreads0()
206
throw new System.NotImplementedException();
209
public static object findDeadlockedThreads0()
211
throw new System.NotImplementedException();
214
public static void resetPeakThreadCount0()
216
throw new System.NotImplementedException();
219
public static object dumpThreads0(long[] ids, bool lockedMonitors, bool lockedSynchronizers)
221
throw new System.NotImplementedException();
224
public static void resetContentionTimes0(long tid)
226
throw new System.NotImplementedException();