FinalizableReferenceQueue.java 6.23 KB
package com.google.common.base;

import com.google.common.annotations.VisibleForTesting;
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;

public class FinalizableReferenceQueue
  implements Closeable
{
  private static final Logger d;
  private static final Method e;
  final ReferenceQueue<Object> a = new ReferenceQueue();
  final PhantomReference<Object> b = new PhantomReference(this, this.a);
  final boolean c;
  
  static
  {
    int i = 0;
    d = Logger.getLogger(FinalizableReferenceQueue.class.getName());
    d locald = new d();
    a locala = new a();
    b localb = new b();
    while (i < 3)
    {
      Class localClass = new c[] { locald, locala, localb }[i].a();
      if (localClass != null)
      {
        e = a(localClass);
        return;
      }
      i += 1;
    }
    throw new AssertionError();
  }
  
  public FinalizableReferenceQueue()
  {
    try
    {
      e.invoke(null, new Object[] { FinalizableReference.class, this.a, this.b });
      this.c = bool;
      return;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      throw new AssertionError(localIllegalAccessException);
    }
    catch (Throwable localThrowable)
    {
      for (;;)
      {
        d.log(Level.INFO, "Failed to start reference finalizer thread. Reference cleanup will only occur when new references are created.", localThrowable);
        bool = false;
      }
    }
  }
  
  private static Method a(Class<?> paramClass)
  {
    try
    {
      paramClass = paramClass.getMethod("startFinalizer", new Class[] { Class.class, ReferenceQueue.class, PhantomReference.class });
      return paramClass;
    }
    catch (NoSuchMethodException paramClass)
    {
      throw new AssertionError(paramClass);
    }
  }
  
  final void a()
  {
    if (this.c) {
      return;
    }
    for (;;)
    {
      Reference localReference = this.a.poll();
      if (localReference == null) {
        break;
      }
      localReference.clear();
      try
      {
        ((FinalizableReference)localReference).finalizeReferent();
      }
      catch (Throwable localThrowable)
      {
        d.log(Level.SEVERE, "Error cleaning up after reference.", localThrowable);
      }
    }
  }
  
  public void close()
  {
    this.b.enqueue();
    a();
  }
  
  static final class a
    implements FinalizableReferenceQueue.c
  {
    public final Class<?> a()
    {
      URL localURL;
      try
      {
        String str1 = String.valueOf("com.google.common.base.internal.Finalizer".replace('.', '/')).concat(".class");
        localURL = getClass().getClassLoader().getResource(str1);
        if (localURL == null) {
          throw new FileNotFoundException(str1);
        }
      }
      catch (Exception localException)
      {
        FinalizableReferenceQueue.b().log(Level.WARNING, "Could not load Finalizer in its own class loader.Loading Finalizer in the current class loader instead. As a result, you will not be ableto garbage collect this class loader. To support reclaiming this class loader, eitherresolve the underlying issue, or move Google Collections to your system class path.", localException);
        return null;
      }
      String str2 = localURL.toString();
      if (!str2.endsWith(localException))
      {
        localObject = String.valueOf(str2);
        if (((String)localObject).length() != 0) {}
        for (localObject = "Unsupported path style: ".concat((String)localObject);; localObject = new String("Unsupported path style: ")) {
          throw new IOException((String)localObject);
        }
      }
      Object localObject = new URLClassLoader(new URL[] { new URL(localURL, str2.substring(0, str2.length() - ((String)localObject).length())) }, null).loadClass("com.google.common.base.internal.Finalizer");
      return (Class<?>)localObject;
    }
  }
  
  static final class b
    implements FinalizableReferenceQueue.c
  {
    public final Class<?> a()
    {
      try
      {
        Class localClass = Class.forName("com.google.common.base.internal.Finalizer");
        return localClass;
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        throw new AssertionError(localClassNotFoundException);
      }
    }
  }
  
  static abstract interface c
  {
    @Nullable
    public abstract Class<?> a();
  }
  
  static final class d
    implements FinalizableReferenceQueue.c
  {
    @VisibleForTesting
    static boolean a;
    
    /* Error */
    public final Class<?> a()
    {
      // Byte code:
      //   0: getstatic 24	com/google/common/base/FinalizableReferenceQueue$d:a	Z
      //   3: ifeq +5 -> 8
      //   6: aconst_null
      //   7: areturn
      //   8: invokestatic 30	java/lang/ClassLoader:getSystemClassLoader	()Ljava/lang/ClassLoader;
      //   11: astore_1
      //   12: aload_1
      //   13: ifnull -7 -> 6
      //   16: aload_1
      //   17: ldc 32
      //   19: invokevirtual 36	java/lang/ClassLoader:loadClass	(Ljava/lang/String;)Ljava/lang/Class;
      //   22: astore_1
      //   23: aload_1
      //   24: areturn
      //   25: astore_1
      //   26: invokestatic 40	com/google/common/base/FinalizableReferenceQueue:b	()Ljava/util/logging/Logger;
      //   29: ldc 42
      //   31: invokevirtual 48	java/util/logging/Logger:info	(Ljava/lang/String;)V
      //   34: aconst_null
      //   35: areturn
      //   36: astore_1
      //   37: aconst_null
      //   38: areturn
      // Local variable table:
      //   start	length	slot	name	signature
      //   0	39	0	this	d
      //   11	13	1	localObject	Object
      //   25	1	1	localSecurityException	SecurityException
      //   36	1	1	localClassNotFoundException	ClassNotFoundException
      // Exception table:
      //   from	to	target	type
      //   8	12	25	java/lang/SecurityException
      //   16	23	36	java/lang/ClassNotFoundException
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/base/FinalizableReferenceQueue.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */