예제 #1
0
 private static CleanerHandles FindHandlesForOldCleaner(MethodHandles.Lookup lookup)
 {
     try
     {
         Type oldCleaner = Type.GetType("sun.misc.Cleaner");
         return(CleanerHandles.Of(FindCreationMethod("create", lookup, oldCleaner), FindCleanMethod(lookup, oldCleaner)));
     }
     catch (Exception oldCleanerException) when(oldCleanerException is ClassNotFoundException || oldCleanerException is NoSuchMethodException || oldCleanerException is IllegalAccessException)
     {
         throw new LinkageError("Unable to find cleaner methods.", oldCleanerException);
     }
 }
예제 #2
0
 /// <summary>
 /// Create a new GrabAllocator that will allocate the given amount of memory, to pointers that are aligned to the
 /// given alignment size. </summary>
 /// <param name="expectedMaxMemory"> The maximum amount of memory that this memory manager is expected to allocate. The
 /// actual amount of memory used can end up greater than this value, if some of it gets wasted on alignment padding. </param>
 /// <param name="memoryTracker"> memory usage tracker </param>
 internal GrabAllocator(long expectedMaxMemory, MemoryAllocationTracker memoryTracker)
 {
     this._grabs = new Grabs(expectedMaxMemory, memoryTracker);
     try
     {
         CleanerHandles handles = FindCleanerHandles();
         this._cleaner     = handles.Creator.invoke(this, new GrabsDeallocator(_grabs));
         this._cleanHandle = handles.Cleaner;
     }
     catch (Exception throwable)
     {
         throw new LinkageError("Unable to instantiate cleaner", throwable);
     }
 }
예제 #3
0
 private static CleanerHandles FindHandlesForNewCleaner(MethodHandles.Lookup lookup)
 {
     try
     {
         Objects.requireNonNull(_globalCleanerInstance);
         Type         newCleaner     = _globalCleanerInstance.GetType();
         Type         newCleanable   = Type.GetType("java.lang.ref.Cleaner$Cleanable");
         MethodHandle registerHandle = FindCreationMethod("register", lookup, newCleaner);
         registerHandle = registerHandle.bindTo(_globalCleanerInstance);
         return(CleanerHandles.Of(registerHandle, FindCleanMethod(lookup, newCleanable)));
     }
     catch (Exception newCleanerException) when(newCleanerException is ClassNotFoundException || newCleanerException is NoSuchMethodException || newCleanerException is IllegalAccessException)
     {
         throw new LinkageError("Unable to find cleaner methods.", newCleanerException);
     }
 }