~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/runtime/openjdk/sun.management.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2011 Jeroen Frijters
 
3
 
 
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.
 
7
 
 
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:
 
11
 
 
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.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
*/
 
24
#if !FIRST_PASS
 
25
using java.lang.management;
 
26
#endif
 
27
 
 
28
static class Java_sun_management_ClassLoadingImpl
 
29
{
 
30
        public static void setVerboseClass(bool value)
 
31
        {
 
32
        }
 
33
}
 
34
 
 
35
static class Java_sun_management_MemoryImpl
 
36
{
 
37
        public static object getMemoryPools0()
 
38
        {
 
39
#if FIRST_PASS
 
40
                return null;
 
41
#else
 
42
                return new MemoryPoolMXBean[0];
 
43
#endif
 
44
        }
 
45
 
 
46
        public static object getMemoryManagers0()
 
47
        {
 
48
#if FIRST_PASS
 
49
                return null;
 
50
#else
 
51
                return new MemoryManagerMXBean[0];
 
52
#endif
 
53
        }
 
54
 
 
55
        public static object getMemoryUsage0(object impl, bool heap)
 
56
        {
 
57
#if FIRST_PASS
 
58
                return null;
 
59
#else
 
60
                long mem = System.GC.GetTotalMemory(false);
 
61
                return new MemoryUsage(-1, mem, mem, -1);
 
62
#endif
 
63
        }
 
64
 
 
65
        public static void setVerboseGC(object impl, bool value)
 
66
        {
 
67
        }
 
68
}
 
69
 
 
70
static class Java_sun_management_ThreadImpl
 
71
{
 
72
        public static object getThreads()
 
73
        {
 
74
        return IKVM.NativeCode.java.lang.Thread.getThreads();
 
75
        }
 
76
 
 
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;
 
85
 
 
86
        public static void getThreadInfo1(long[] ids, int maxDepth, object result)
 
87
        {
 
88
#if !FIRST_PASS
 
89
 
 
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)
 
92
        {
 
93
            if (constructor.GetParameters().Length == 9)
 
94
            {
 
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++)
 
98
                {
 
99
                    long id = ids[i];
 
100
                    for (int t = 0; t < threads.Length; t++)
 
101
                    {
 
102
                        if (threads[t].getId() == id)
 
103
                        {
 
104
                            java.lang.Thread thread = threads[t];
 
105
 
 
106
                            int state;
 
107
                            // invers to sun.misc.VM.toThreadState
 
108
                            switch(thread.getState().ordinal())
 
109
                            {
 
110
                                case (int)java.lang.Thread.State.__Enum.RUNNABLE:
 
111
                                    state = JVMTI_THREAD_STATE_RUNNABLE;
 
112
                                    break;
 
113
                                case (int)java.lang.Thread.State.__Enum.BLOCKED:
 
114
                                    state = JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
 
115
                                    break;
 
116
                                case (int)java.lang.Thread.State.__Enum.WAITING:
 
117
                                    state = JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
 
118
                                    break;
 
119
                                case (int)java.lang.Thread.State.__Enum.TIMED_WAITING:
 
120
                                    state = JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
 
121
                                    break;
 
122
                                case (int)java.lang.Thread.State.__Enum.TERMINATED:
 
123
                                    state = JVMTI_THREAD_STATE_TERMINATED;
 
124
                                    break;
 
125
                                case (int)java.lang.Thread.State.__Enum.NEW:
 
126
                                    state = JVMTI_THREAD_STATE_ALIVE;
 
127
                                    break;
 
128
                                default:
 
129
                                    state = 0;
 
130
                                    break;
 
131
                            }
 
132
                            //TODO set in state JMM_THREAD_STATE_FLAG_SUSPENDED if the thread is suspended
 
133
 
 
134
                            java.lang.StackTraceElement[] stacktrace = thread.getStackTrace();
 
135
                            if (maxDepth >= 0 && maxDepth < stacktrace.Length)
 
136
                            {
 
137
                                java.lang.StackTraceElement[] temp = new java.lang.StackTraceElement[maxDepth];
 
138
                                System.Array.Copy(stacktrace, temp, temp.Length);
 
139
                                stacktrace = temp;
 
140
                            }
 
141
 
 
142
                            object[] parameters = new object[9];
 
143
                            parameters[0] = thread;                     // thread
 
144
                            parameters[1] = state;                      // state
 
145
                                                                        // lockObj
 
146
                                                                        // lockOwner
 
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);
 
153
                            break;
 
154
                        }
 
155
                    }
 
156
                }
 
157
                return;
 
158
            }
 
159
        }
 
160
        throw new java.lang.InternalError("Constructor for java.lang.management.ThreadInfo not find.");
 
161
#endif
 
162
    }
 
163
 
 
164
        public static long getThreadTotalCpuTime0(long id)
 
165
        {
 
166
                throw new System.NotImplementedException();
 
167
        }
 
168
 
 
169
        public static void getThreadTotalCpuTime1(long[] ids, long[] result)
 
170
        {
 
171
                throw new System.NotImplementedException();
 
172
        }
 
173
 
 
174
        public static long getThreadUserCpuTime0(long id)
 
175
        {
 
176
                throw new System.NotImplementedException();
 
177
        }
 
178
 
 
179
        public static void getThreadUserCpuTime1(long[] ids, long[] result)
 
180
        {
 
181
                throw new System.NotImplementedException();
 
182
        }
 
183
 
 
184
        public static void getThreadAllocatedMemory1(long[] ids, long[] result)
 
185
        {
 
186
                throw new System.NotImplementedException();
 
187
        }
 
188
 
 
189
        public static void setThreadCpuTimeEnabled0(bool enable)
 
190
        {
 
191
                throw new System.NotImplementedException();
 
192
        }
 
193
 
 
194
        public static void setThreadAllocatedMemoryEnabled0(bool enable)
 
195
        {
 
196
                throw new System.NotImplementedException();
 
197
        }
 
198
 
 
199
        public static void setThreadContentionMonitoringEnabled0(bool enable)
 
200
        {
 
201
                throw new System.NotImplementedException();
 
202
        }
 
203
 
 
204
        public static object findMonitorDeadlockedThreads0()
 
205
        {
 
206
                throw new System.NotImplementedException();
 
207
        }
 
208
 
 
209
        public static object findDeadlockedThreads0()
 
210
        {
 
211
                throw new System.NotImplementedException();
 
212
        }
 
213
 
 
214
        public static void resetPeakThreadCount0()
 
215
        {
 
216
                throw new System.NotImplementedException();
 
217
        }
 
218
 
 
219
        public static object dumpThreads0(long[] ids, bool lockedMonitors, bool lockedSynchronizers)
 
220
        {
 
221
                throw new System.NotImplementedException();
 
222
        }
 
223
 
 
224
        public static void resetContentionTimes0(long tid)
 
225
        {
 
226
                throw new System.NotImplementedException();
 
227
        }
 
228
}