public jweak NewWeakGlobalReference(jobject @object) { jweak result = RawInterface.NewWeakGlobalRef(this, @object); HandleException(); return(result); }
internal TaggedReferenceTypeId TrackLocalClassReference(jclass classHandle, JvmtiEnvironment environment, JniEnvironment nativeEnvironment, bool freeLocalReference) { if (classHandle == jclass.Null) { return(default(TaggedReferenceTypeId)); } bool isArrayClass; JvmtiErrorHandler.ThrowOnFailure(environment.IsArrayClass(classHandle, out isArrayClass)); bool isInterface; JvmtiErrorHandler.ThrowOnFailure(environment.IsInterface(classHandle, out isInterface)); TypeTag typeTag = isArrayClass ? TypeTag.Array : (isInterface ? TypeTag.Interface : TypeTag.Class); int hashCode; JvmtiErrorHandler.ThrowOnFailure(environment.GetObjectHashCode(classHandle, out hashCode)); ReferenceTypeId typeId = new ReferenceTypeId(hashCode); TaggedReferenceTypeId taggedTypeId = new TaggedReferenceTypeId(typeTag, typeId); lock (_classes) { if (!_classes.ContainsKey(typeId)) { jweak weak = nativeEnvironment.NewWeakGlobalReference(classHandle); bool added = false; if (!_classes.ContainsKey(typeId)) { _classes.Add(typeId, new jclass(weak.Handle)); added = true; } if (!added) { nativeEnvironment.DeleteWeakGlobalReference(weak); } } } if (freeLocalReference) { nativeEnvironment.DeleteLocalReference(classHandle); } return(taggedTypeId); }
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); }
public void DeleteWeakGlobalReference(jweak @object) { RawInterface.DeleteWeakGlobalRef(this, @object); HandleException(); }