public LocalThreadReferenceHolder(JniEnvironment nativeEnvironment, jthread reference)
        {
            Contract.Requires <ArgumentNullException>(nativeEnvironment != null, "nativeEnvironment");

            _nativeEnvironment = nativeEnvironment;
            _reference         = (jthread)_nativeEnvironment.NewLocalReference(reference);
        }
Esempio n. 2
0
        internal jvmtiError GetThread(ThreadId threadId, out jthread thread)
        {
            lock (_threads)
            {
                if (!_threads.TryGetValue(threadId, out thread))
                {
                    return(jvmtiError.InvalidThread);
                }

                return(jvmtiError.None);
            }
        }
Esempio n. 3
0
        public jvmtiError GetLocalObject(JniEnvironment nativeEnvironment, jthread thread, int depth, int slot, out TaggedObjectId value)
        {
            value = default(TaggedObjectId);

            jobject    obj;
            jvmtiError error = RawInterface.GetLocalObject(this, thread, depth, slot, out obj);

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

            value = VirtualMachine.TrackLocalObjectReference(obj, this, nativeEnvironment, true);
            return(jvmtiError.None);
        }
Esempio n. 4
0
        internal ThreadId TrackLocalThreadReference(jthread thread, JvmtiEnvironment environment, JniEnvironment nativeEnvironment, bool freeLocalReference)
        {
            if (thread == jthread.Null)
            {
                return(default(ThreadId));
            }

            int hashCode;

            JvmtiErrorHandler.ThrowOnFailure(environment.RawInterface.GetObjectHashCode(environment, thread, out hashCode));

            ThreadId threadId = new ThreadId(hashCode);

            lock (_threads)
            {
                if (!_threads.ContainsKey(threadId))
                {
                    jweak weak  = nativeEnvironment.NewWeakGlobalReference(thread);
                    bool  added = false;
                    if (!_threads.ContainsKey(threadId))
                    {
                        _threads.Add(threadId, new jthread(weak.Handle));
                        added = true;
                    }

                    if (!added)
                    {
                        nativeEnvironment.DeleteWeakGlobalReference(weak);
                    }
                }
            }

            if (freeLocalReference)
            {
                nativeEnvironment.DeleteLocalReference(thread);
            }

            return(threadId);
        }
Esempio n. 5
0
 internal jvmtiError GetThreadInfo(jthread thread, out jvmtiThreadInfo threadInfo)
 {
     return(RawInterface.GetThreadInfo(this, thread, out threadInfo));
 }
Esempio n. 6
0
 public jvmtiError GetLocalObject(jthread thread, int depth, int slot, out jobject value)
 {
     return(RawInterface.GetLocalObject(this, thread, depth, slot, out value));
 }
Esempio n. 7
0
 public jvmtiError GetLocalDouble(jthread thread, int depth, int slot, out double value)
 {
     return(RawInterface.GetLocalDouble(this, thread, depth, slot, out value));
 }
Esempio n. 8
0
 public jvmtiError GetLocalLong(jthread thread, int depth, int slot, out long value)
 {
     return(RawInterface.GetLocalLong(this, thread, depth, slot, out value));
 }
Esempio n. 9
0
 public jvmtiError GetFrameLocation(jthread thread, int depth, out jmethodID method, out jlocation location)
 {
     return(RawInterface.GetFrameLocation(this, thread, depth, out method, out location));
 }
Esempio n. 10
0
 public jvmtiError GetFrameCount(jthread thread, out int frameCount)
 {
     return(RawInterface.GetFrameCount(this, thread, out frameCount));
 }
Esempio n. 11
0
        internal void HandleVMInit(JvmtiEnvironment environment, JniEnvironment nativeEnvironment, jthread thread)
        {
            jclass threadClass = nativeEnvironment.GetObjectClass(thread);

            _threadClass = FindBaseClass(environment, nativeEnvironment, threadClass, "Ljava/lang/Thread;");

            {
                jclass classClass = nativeEnvironment.GetObjectClass(threadClass);
                _classClass = FindBaseClass(environment, nativeEnvironment, classClass, "Ljava/lang/Class;");
                nativeEnvironment.DeleteLocalReference(classClass);
            }

            {
                jvmtiThreadInfo threadInfo;
                JvmtiErrorHandler.ThrowOnFailure(environment.GetThreadInfo(thread, out threadInfo));
                jclass threadGroupClass = nativeEnvironment.GetObjectClass(threadInfo._threadGroup);
                _threadGroupClass = FindBaseClass(environment, nativeEnvironment, threadGroupClass, "Ljava/lang/ThreadGroup;");

                jclass classLoaderClass = nativeEnvironment.GetObjectClass(threadInfo._contextClassLoader);
                _classLoaderClass = FindBaseClass(environment, nativeEnvironment, classLoaderClass, "Ljava/lang/ClassLoader;");
                nativeEnvironment.DeleteLocalReference(classLoaderClass);

                nativeEnvironment.DeleteLocalReference(threadGroupClass);
                nativeEnvironment.DeleteLocalReference(threadInfo._contextClassLoader);
                nativeEnvironment.DeleteLocalReference(threadInfo._threadGroup);
                environment.Deallocate(threadInfo._name);
            }

            nativeEnvironment.DeleteLocalReference(threadClass);

            jobject stringObject = nativeEnvironment.NewString(string.Empty);
            jclass  stringClass  = nativeEnvironment.GetObjectClass(stringObject);

            _stringClass = FindBaseClass(environment, nativeEnvironment, stringClass, "Ljava/lang/String;");
            nativeEnvironment.DeleteLocalReference(stringObject);
            nativeEnvironment.DeleteLocalReference(stringClass);
        }