Beispiel #1
0
        public DisposableObjectCollection <JvmThreadReference> GetAllThreads(JvmNativeEnvironment nativeEnvironment)
        {
            DisposableObjectCollection <JvmThreadReference> result = new DisposableObjectCollection <JvmThreadReference>();

            int    threadsCount;
            IntPtr threads;

            ThrowOnFailure(_rawInterface.GetAllThreads(_env, out threadsCount, out threads));
            try
            {
                unsafe
                {
                    jthread *rawThreads = (jthread *)threads;
                    for (int i = 0; i < threadsCount; i++)
                    {
                        result.Add(new JvmThreadReference(this, nativeEnvironment, rawThreads[i], true));
                    }
                }

                return(result);
            }
            finally
            {
                if (threads != IntPtr.Zero)
                {
                    Deallocate(threads);
                }
            }
        }
Beispiel #2
0
        public jvmtiError GetAllThreads(JniEnvironment nativeEnvironment, out ThreadId[] threads)
        {
            threads = null;

            int        threadsCount;
            IntPtr     threadsPtr;
            jvmtiError error = RawInterface.GetAllThreads(this, out threadsCount, out threadsPtr);

            if (error != jvmtiError.None)
            {
                return(error);
            }

            try
            {
                HashSet <ThreadId> threadSet = new HashSet <ThreadId>();
                unsafe
                {
                    jthread *threadHandles = (jthread *)threadsPtr;
                    for (int i = 0; i < threadsCount; i++)
                    {
                        if (threadHandles[i] == jthread.Null)
                        {
                            continue;
                        }

                        threadSet.Add(VirtualMachine.TrackLocalThreadReference(threadHandles[i], this, nativeEnvironment, true));
                    }
                }

                threadSet.ExceptWith(_virtualMachine.AgentThreads);
                threads = threadSet.ToArray();
                return(jvmtiError.None);
            }
            finally
            {
                Deallocate(threadsPtr);
            }
        }