IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Java.Externs.java.lang.Thread Class Reference

Implements the native mthods of 'java.lang.Thread'. More...

Static Public Member Functions

static object getMainThreadGroup ()
 Implements the native method 'getMainThreadGroup'.
 
static global::java.lang.StackTraceElement[] getStackTrace (StackTrace stack)
 Implements the native method 'getStackTrace'.
 
static object getThreads ()
 Implements the native method 'getThreads'.
 
static object dumpThreads (object[] threads)
 Implements the native method 'dumpThreads'.
 

Detailed Description

Implements the native mthods of 'java.lang.Thread'.

Definition at line 42 of file Thread.cs.

Member Function Documentation

◆ dumpThreads()

static object IKVM.Java.Externs.java.lang.Thread.dumpThreads ( object[] threads)
static

Implements the native method 'dumpThreads'.

Parameters
threads
Returns

Definition at line 135 of file Thread.cs.

136 {
137#if FIRST_PASS
138 throw new NotImplementedException();
139#else
140 var stacks = new global::java.lang.StackTraceElement[threads.Length][];
141 for (int i = 0; i < threads.Length; i++)
142 {
143 var nativeThread = ThreadAccessor.GetNativeThread(threads[i]);
144 if (nativeThread == null)
145 {
146 stacks[i] = Array.Empty<global::java.lang.StackTraceElement>();
147 }
148 else
149 {
150#if NETFRAMEWORK
151 try
152 {
153 var suspended = false;
154 if ((nativeThread.ThreadState & global::System.Threading.ThreadState.Suspended) == 0 && nativeThread != global::System.Threading.Thread.CurrentThread)
155 {
156 suspended = true;
157 nativeThread.Suspend();
158 }
159
160 StackTrace stack;
161 try
162 {
163 stack = new StackTrace(nativeThread, true);
164 }
165 finally
166 {
167 if (suspended)
168 nativeThread.Resume();
169 }
170
171 stacks[i] = getStackTrace(stack);
172 }
173 catch (ThreadStateException)
174 {
175 stacks[i] = Array.Empty<global::java.lang.StackTraceElement>();
176 }
177#else
178 if (nativeThread == global::System.Threading.Thread.CurrentThread)
179 {
180 stacks[i] = getStackTrace(new StackTrace(true));
181 }
182 else
183 {
184 stacks[i] = Array.Empty<global::java.lang.StackTraceElement>();
185 }
186#endif
187 }
188 }
189
190 return stacks;
191#endif
192 }
static global::java.lang.StackTraceElement[] getStackTrace(StackTrace stack)
Implements the native method 'getStackTrace'.
Definition Thread.cs:97

◆ getMainThreadGroup()

static object IKVM.Java.Externs.java.lang.Thread.getMainThreadGroup ( )
static

Implements the native method 'getMainThreadGroup'.

Returns

Definition at line 60 of file Thread.cs.

61 {
62#if FIRST_PASS
63 throw new NotImplementedException();
64#else
65 return JVM.MainThreadGroup;
66#endif
67 }
Main state of the running JVM.

◆ getStackTrace()

static global.java.lang.StackTraceElement[] IKVM.Java.Externs.java.lang.Thread.getStackTrace ( StackTrace stack)
static

Implements the native method 'getStackTrace'.

Parameters
stack
Returns

Definition at line 97 of file Thread.cs.

98 {
99#if FIRST_PASS
100 throw new NotImplementedException();
101#else
102 var stackTrace = new List<global::java.lang.StackTraceElement>();
103 ExceptionHelper.ExceptionInfoHelper.Append(JVM.Context.ExceptionHelper, stackTrace, stack, 0, true);
104 return stackTrace.ToArray();
105#endif
106 }
ExceptionHelper ExceptionHelper
Gets the ExceptionHelper associated with this instance of the runtime.

◆ getThreads()

static object IKVM.Java.Externs.java.lang.Thread.getThreads ( )
static

Implements the native method 'getThreads'.

Returns

Definition at line 112 of file Thread.cs.

113 {
114#if FIRST_PASS
115 throw new NotImplementedException();
116#else
117 return AccessControllerAccessor.InvokeDoPrivileged(new FuncPrivilegedAction<object[]>(() =>
118 {
119 var root = (global::java.lang.ThreadGroup)JVM.MainThreadGroup;
120 while (true)
121 {
122 var threads = new global::java.lang.Thread[root.activeCount()];
123 if (root.enumerate(threads) == threads.Length)
124 return threads;
125 }
126 }));
127#endif
128 }
Implementation of global::java.security.PrivilegedAction that invokes a delegate.

The documentation for this class was generated from the following file: