ConnectionPool.smali
.class public final Lokhttp3/ConnectionPool;
.super Ljava/lang/Object;
.source "SourceFile"
# static fields
.field public static final synthetic $assertionsDisabled:Z
.field private static final executor:Ljava/util/concurrent/Executor;
# instance fields
.field private final cleanupRunnable:Ljava/lang/Runnable;
.field public cleanupRunning:Z
.field private final connections:Ljava/util/Deque;
.annotation system Ldalvik/annotation/Signature;
value = {
"Ljava/util/Deque<",
"Lokhttp3/internal/connection/RealConnection;",
">;"
}
.end annotation
.end field
.field private final keepAliveDurationNs:J
.field private final maxIdleConnections:I
.field public final routeDatabase:Lokhttp3/internal/connection/RouteDatabase;
# direct methods
.method public static constructor <clinit>()V
.registers 8
const/4 v0, 0x0
const v1, 0x7fffffff
const-wide/16 v2, 0x3c
.line 1
sget-object v4, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;
new-instance v5, Ljava/util/concurrent/SynchronousQueue;
invoke-direct {v5}, Ljava/util/concurrent/SynchronousQueue;-><init>()V
const/4 v6, 0x1
const-string v7, "OkHttp ConnectionPool"
.line 2
invoke-static {v7, v6}, Lokhttp3/internal/Util;->threadFactory(Ljava/lang/String;Z)Ljava/util/concurrent/ThreadFactory;
move-result-object v6
const-string v7, "okhttp3/ConnectionPool"
invoke-static/range {v0 .. v7}, Lcom/garena/android/appkit/logging/a;->R(IIJLjava/util/concurrent/TimeUnit;Ljava/util/concurrent/BlockingQueue;Ljava/util/concurrent/ThreadFactory;Ljava/lang/String;)Ljava/util/concurrent/ThreadPoolExecutor;
move-result-object v0
sput-object v0, Lokhttp3/ConnectionPool;->executor:Ljava/util/concurrent/Executor;
return-void
.end method
.method public constructor <init>()V
.registers 5
.line 1
sget-object v0, Ljava/util/concurrent/TimeUnit;->MINUTES:Ljava/util/concurrent/TimeUnit;
const/4 v1, 0x5
const-wide/16 v2, 0x5
invoke-direct {p0, v1, v2, v3, v0}, Lokhttp3/ConnectionPool;-><init>(IJLjava/util/concurrent/TimeUnit;)V
return-void
.end method
.method public constructor <init>(IJLjava/util/concurrent/TimeUnit;)V
.registers 7
.line 2
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 3
new-instance v0, Lokhttp3/ConnectionPool$1;
invoke-direct {v0, p0}, Lokhttp3/ConnectionPool$1;-><init>(Lokhttp3/ConnectionPool;)V
iput-object v0, p0, Lokhttp3/ConnectionPool;->cleanupRunnable:Ljava/lang/Runnable;
.line 4
new-instance v0, Ljava/util/ArrayDeque;
invoke-direct {v0}, Ljava/util/ArrayDeque;-><init>()V
iput-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
.line 5
new-instance v0, Lokhttp3/internal/connection/RouteDatabase;
invoke-direct {v0}, Lokhttp3/internal/connection/RouteDatabase;-><init>()V
iput-object v0, p0, Lokhttp3/ConnectionPool;->routeDatabase:Lokhttp3/internal/connection/RouteDatabase;
.line 6
iput p1, p0, Lokhttp3/ConnectionPool;->maxIdleConnections:I
.line 7
invoke-virtual {p4, p2, p3}, Ljava/util/concurrent/TimeUnit;->toNanos(J)J
move-result-wide v0
iput-wide v0, p0, Lokhttp3/ConnectionPool;->keepAliveDurationNs:J
const-wide/16 v0, 0x0
cmp-long p1, p2, v0
if-lez p1, :cond_27
return-void
.line 8
:cond_27
new-instance p1, Ljava/lang/IllegalArgumentException;
const-string p4, "keepAliveDuration <= 0: "
.line 9
invoke-static {p4, p2, p3}, Landroidx/biometric/h0;->c(Ljava/lang/String;J)Ljava/lang/String;
move-result-object p2
.line 10
invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw p1
.end method
.method public static INVOKEINTERFACE_okhttp3_ConnectionPool_com_shopee_app_asm_anr_threadpool_ExecutorProxy_execute(Ljava/util/concurrent/Executor;Ljava/lang/Runnable;)V
.registers 4
.line 1
invoke-static {}, Lcom/shopee/app/asm/anr/threadpool/c;->b()Z
move-result v0
if-eqz v0, :cond_3a
invoke-static {}, Lcom/shopee/app/asm/anr/threadpool/c;->a()Z
move-result v0
if-eqz v0, :cond_3a
.line 2
:try_start_c
sget-object v0, Lcom/shopee/app/asm/anr/threadpool/c;->a:Landroid/os/HandlerThread;
.line 3
sget-object v0, Lcom/shopee/app/asm/anr/threadpool/c;->b:Landroid/os/Handler;
new-instance v1, Lcom/shopee/app/asm/anr/threadpool/a$b;
invoke-direct {v1, p0, p1}, Lcom/shopee/app/asm/anr/threadpool/a$b;-><init>(Ljava/util/concurrent/Executor;Ljava/lang/Runnable;)V
invoke-virtual {v0, v1}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z
:try_end_18
.catchall {:try_start_c .. :try_end_18} :catchall_19
goto :goto_54
:catchall_19
move-exception v0
.line 4
invoke-virtual {v0}, Ljava/lang/Throwable;->getMessage()Ljava/lang/String;
sget-object v0, Lcom/shopee/app/asm/anr/threadpool/c;->a:Landroid/os/HandlerThread;
.line 5
:try_start_1f
invoke-static {p1, p0}, Lcom/shopee/app/asm/anr/threadpool/a;->a(Ljava/lang/Object;Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :cond_2b
.line 6
sget-object p0, Lcom/shopee/app/asm/fix/threadpool/global/i;->e:Lcom/shopee/app/asm/fix/threadpool/global/j;
.line 7
invoke-virtual {p0, p1}, Lcom/shopee/app/asm/anr/threadpool/b;->execute(Ljava/lang/Runnable;)V
return-void
.line 8
:cond_2b
invoke-interface {p0, p1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V
:try_end_2e
.catchall {:try_start_1f .. :try_end_2e} :catchall_2f
goto :goto_54
:catchall_2f
move-exception p0
.line 9
sget-object p1, Lcom/shopee/app/asm/anr/threadpool/c;->a:Landroid/os/HandlerThread;
.line 10
invoke-static {}, Lcom/shopee/app/apm/c;->d()Lcom/shopee/app/apm/nonfatal/a;
move-result-object p1
invoke-virtual {p1, p0}, Lcom/shopee/app/apm/nonfatal/a;->c(Ljava/lang/Throwable;)V
goto :goto_54
.line 11
:cond_3a
:try_start_3a
invoke-static {p1, p0}, Lcom/shopee/app/asm/anr/threadpool/a;->a(Ljava/lang/Object;Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :cond_46
.line 12
sget-object p0, Lcom/shopee/app/asm/fix/threadpool/global/i;->e:Lcom/shopee/app/asm/fix/threadpool/global/j;
.line 13
invoke-virtual {p0, p1}, Lcom/shopee/app/asm/anr/threadpool/b;->execute(Ljava/lang/Runnable;)V
return-void
.line 14
:cond_46
invoke-interface {p0, p1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V
:try_end_49
.catchall {:try_start_3a .. :try_end_49} :catchall_4a
goto :goto_54
:catchall_4a
move-exception p0
.line 15
sget-object p1, Lcom/shopee/app/asm/anr/threadpool/c;->a:Landroid/os/HandlerThread;
.line 16
invoke-static {}, Lcom/shopee/app/apm/c;->d()Lcom/shopee/app/apm/nonfatal/a;
move-result-object p1
invoke-virtual {p1, p0}, Lcom/shopee/app/apm/nonfatal/a;->c(Ljava/lang/Throwable;)V
:goto_54
return-void
.end method
.method private pruneAndGetAllocationCount(Lokhttp3/internal/connection/RealConnection;J)I
.registers 10
.line 1
iget-object v0, p1, Lokhttp3/internal/connection/RealConnection;->allocations:Ljava/util/List;
const/4 v1, 0x0
const/4 v2, 0x0
.line 2
:cond_4
:goto_4
invoke-interface {v0}, Ljava/util/List;->size()I
move-result v3
if-ge v2, v3, :cond_54
.line 3
invoke-interface {v0, v2}, Ljava/util/List;->get(I)Ljava/lang/Object;
move-result-object v3
check-cast v3, Ljava/lang/ref/Reference;
.line 4
invoke-virtual {v3}, Ljava/lang/ref/Reference;->get()Ljava/lang/Object;
move-result-object v4
if-eqz v4, :cond_19
add-int/lit8 v2, v2, 0x1
goto :goto_4
.line 5
:cond_19
check-cast v3, Lokhttp3/internal/connection/StreamAllocation$StreamAllocationReference;
const-string v4, "A connection to "
.line 6
invoke-static {v4}, Landroid/support/v4/media/c;->c(Ljava/lang/String;)Ljava/lang/StringBuilder;
move-result-object v4
.line 7
invoke-virtual {p1}, Lokhttp3/internal/connection/RealConnection;->route()Lokhttp3/Route;
move-result-object v5
invoke-virtual {v5}, Lokhttp3/Route;->address()Lokhttp3/Address;
move-result-object v5
invoke-virtual {v5}, Lokhttp3/Address;->url()Lokhttp3/HttpUrl;
move-result-object v5
invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
const-string v5, " was leaked. Did you forget to close a response body?"
invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v4
.line 8
invoke-static {}, Lokhttp3/internal/platform/Platform;->get()Lokhttp3/internal/platform/Platform;
move-result-object v5
iget-object v3, v3, Lokhttp3/internal/connection/StreamAllocation$StreamAllocationReference;->callStackTrace:Ljava/lang/Object;
invoke-virtual {v5, v4, v3}, Lokhttp3/internal/platform/Platform;->logCloseableLeak(Ljava/lang/String;Ljava/lang/Object;)V
.line 9
invoke-interface {v0, v2}, Ljava/util/List;->remove(I)Ljava/lang/Object;
const/4 v3, 0x1
.line 10
iput-boolean v3, p1, Lokhttp3/internal/connection/RealConnection;->noNewStreams:Z
.line 11
invoke-interface {v0}, Ljava/util/List;->isEmpty()Z
move-result v3
if-eqz v3, :cond_4
.line 12
iget-wide v2, p0, Lokhttp3/ConnectionPool;->keepAliveDurationNs:J
sub-long/2addr p2, v2
iput-wide p2, p1, Lokhttp3/internal/connection/RealConnection;->idleAtNanos:J
return v1
.line 13
:cond_54
invoke-interface {v0}, Ljava/util/List;->size()I
move-result p1
return p1
.end method
# virtual methods
.method public cleanup(J)J
.registers 14
.line 1
monitor-enter p0
.line 2
:try_start_1
iget-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v0}, Ljava/util/Deque;->iterator()Ljava/util/Iterator;
move-result-object v0
const/4 v1, 0x0
const/4 v2, 0x0
const-wide/high16 v3, -0x8000000000000000L
const/4 v5, 0x0
const/4 v6, 0x0
:cond_d
:goto_d
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v7
if-eqz v7, :cond_2f
.line 3
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v7
check-cast v7, Lokhttp3/internal/connection/RealConnection;
.line 4
invoke-direct {p0, v7, p1, p2}, Lokhttp3/ConnectionPool;->pruneAndGetAllocationCount(Lokhttp3/internal/connection/RealConnection;J)I
move-result v8
if-lez v8, :cond_22
add-int/lit8 v6, v6, 0x1
goto :goto_d
:cond_22
add-int/lit8 v5, v5, 0x1
.line 5
iget-wide v8, v7, Lokhttp3/internal/connection/RealConnection;->idleAtNanos:J
sub-long v8, p1, v8
cmp-long v10, v8, v3
if-lez v10, :cond_d
move-object v2, v7
move-wide v3, v8
goto :goto_d
.line 6
:cond_2f
iget-wide p1, p0, Lokhttp3/ConnectionPool;->keepAliveDurationNs:J
cmp-long v0, v3, p1
if-gez v0, :cond_49
iget v0, p0, Lokhttp3/ConnectionPool;->maxIdleConnections:I
if-le v5, v0, :cond_3a
goto :goto_49
:cond_3a
if-lez v5, :cond_3f
sub-long/2addr p1, v3
.line 7
monitor-exit p0
return-wide p1
:cond_3f
if-lez v6, :cond_43
.line 8
monitor-exit p0
return-wide p1
.line 9
:cond_43
iput-boolean v1, p0, Lokhttp3/ConnectionPool;->cleanupRunning:Z
const-wide/16 p1, -0x1
.line 10
monitor-exit p0
return-wide p1
.line 11
:cond_49
:goto_49
iget-object p1, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {p1, v2}, Ljava/util/Deque;->remove(Ljava/lang/Object;)Z
.line 12
monitor-exit p0
:try_end_4f
.catchall {:try_start_1 .. :try_end_4f} :catchall_59
.line 13
invoke-virtual {v2}, Lokhttp3/internal/connection/RealConnection;->socket()Ljava/net/Socket;
move-result-object p1
invoke-static {p1}, Lokhttp3/internal/Util;->closeQuietly(Ljava/net/Socket;)V
const-wide/16 p1, 0x0
return-wide p1
:catchall_59
move-exception p1
.line 14
:try_start_5a
monitor-exit p0
:try_end_5b
.catchall {:try_start_5a .. :try_end_5b} :catchall_59
throw p1
.end method
.method public connectionBecameIdle(Lokhttp3/internal/connection/RealConnection;)Z
.registers 3
.line 1
iget-boolean v0, p1, Lokhttp3/internal/connection/RealConnection;->noNewStreams:Z
if-nez v0, :cond_e
iget v0, p0, Lokhttp3/ConnectionPool;->maxIdleConnections:I
if-nez v0, :cond_9
goto :goto_e
.line 2
:cond_9
invoke-virtual {p0}, Ljava/lang/Object;->notifyAll()V
const/4 p1, 0x0
return p1
.line 3
:cond_e
:goto_e
iget-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v0, p1}, Ljava/util/Deque;->remove(Ljava/lang/Object;)Z
const/4 p1, 0x1
return p1
.end method
.method public declared-synchronized connectionCount()I
.registers 2
monitor-enter p0
:try_start_1
iget-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v0}, Ljava/util/Deque;->size()I
move-result v0
:try_end_7
.catchall {:try_start_1 .. :try_end_7} :catchall_9
monitor-exit p0
return v0
:catchall_9
move-exception v0
monitor-exit p0
throw v0
.end method
.method public deduplicate(Lokhttp3/Address;Lokhttp3/internal/connection/StreamAllocation;)Ljava/net/Socket;
.registers 6
.line 1
iget-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v0}, Ljava/util/Deque;->iterator()Ljava/util/Iterator;
move-result-object v0
:cond_6
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
const/4 v2, 0x0
if-eqz v1, :cond_2a
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Lokhttp3/internal/connection/RealConnection;
.line 2
invoke-virtual {v1, p1, v2}, Lokhttp3/internal/connection/RealConnection;->isEligible(Lokhttp3/Address;Lokhttp3/Route;)Z
move-result v2
if-eqz v2, :cond_6
.line 3
invoke-virtual {v1}, Lokhttp3/internal/connection/RealConnection;->isMultiplexed()Z
move-result v2
if-eqz v2, :cond_6
.line 4
invoke-virtual {p2}, Lokhttp3/internal/connection/StreamAllocation;->connection()Lokhttp3/internal/connection/RealConnection;
move-result-object v2
if-eq v1, v2, :cond_6
.line 5
invoke-virtual {p2, v1}, Lokhttp3/internal/connection/StreamAllocation;->releaseAndAcquire(Lokhttp3/internal/connection/RealConnection;)Ljava/net/Socket;
move-result-object p1
return-object p1
:cond_2a
return-object v2
.end method
.method public evictAll()V
.registers 5
.line 1
new-instance v0, Ljava/util/ArrayList;
invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
.line 2
monitor-enter p0
.line 3
:try_start_6
iget-object v1, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v1}, Ljava/util/Deque;->iterator()Ljava/util/Iterator;
move-result-object v1
:cond_c
:goto_c
invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z
move-result v2
if-eqz v2, :cond_2a
.line 4
invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v2
check-cast v2, Lokhttp3/internal/connection/RealConnection;
.line 5
iget-object v3, v2, Lokhttp3/internal/connection/RealConnection;->allocations:Ljava/util/List;
invoke-interface {v3}, Ljava/util/List;->isEmpty()Z
move-result v3
if-eqz v3, :cond_c
const/4 v3, 0x1
.line 6
iput-boolean v3, v2, Lokhttp3/internal/connection/RealConnection;->noNewStreams:Z
.line 7
invoke-virtual {v0, v2}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
.line 8
invoke-interface {v1}, Ljava/util/Iterator;->remove()V
goto :goto_c
.line 9
:cond_2a
monitor-exit p0
:try_end_2b
.catchall {:try_start_6 .. :try_end_2b} :catchall_44
.line 10
invoke-virtual {v0}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;
move-result-object v0
:goto_2f
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_43
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Lokhttp3/internal/connection/RealConnection;
.line 11
invoke-virtual {v1}, Lokhttp3/internal/connection/RealConnection;->socket()Ljava/net/Socket;
move-result-object v1
invoke-static {v1}, Lokhttp3/internal/Util;->closeQuietly(Ljava/net/Socket;)V
goto :goto_2f
:cond_43
return-void
:catchall_44
move-exception v0
.line 12
:try_start_45
monitor-exit p0
:try_end_46
.catchall {:try_start_45 .. :try_end_46} :catchall_44
throw v0
.end method
.method public get(Lokhttp3/Address;Lokhttp3/internal/connection/StreamAllocation;Lokhttp3/Route;)Lokhttp3/internal/connection/RealConnection;
.registers 7
.line 1
iget-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v0}, Ljava/util/Deque;->iterator()Ljava/util/Iterator;
move-result-object v0
:cond_6
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_1d
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Lokhttp3/internal/connection/RealConnection;
.line 2
invoke-virtual {v1, p1, p3}, Lokhttp3/internal/connection/RealConnection;->isEligible(Lokhttp3/Address;Lokhttp3/Route;)Z
move-result v2
if-eqz v2, :cond_6
const/4 p1, 0x1
.line 3
invoke-virtual {p2, v1, p1}, Lokhttp3/internal/connection/StreamAllocation;->acquire(Lokhttp3/internal/connection/RealConnection;Z)V
return-object v1
:cond_1d
const/4 p1, 0x0
return-object p1
.end method
.method public declared-synchronized idleConnectionCount()I
.registers 4
monitor-enter p0
const/4 v0, 0x0
.line 1
:try_start_2
iget-object v1, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v1}, Ljava/util/Deque;->iterator()Ljava/util/Iterator;
move-result-object v1
:cond_8
:goto_8
invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z
move-result v2
if-eqz v2, :cond_1f
invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v2
check-cast v2, Lokhttp3/internal/connection/RealConnection;
.line 2
iget-object v2, v2, Lokhttp3/internal/connection/RealConnection;->allocations:Ljava/util/List;
invoke-interface {v2}, Ljava/util/List;->isEmpty()Z
move-result v2
:try_end_1a
.catchall {:try_start_2 .. :try_end_1a} :catchall_21
if-eqz v2, :cond_8
add-int/lit8 v0, v0, 0x1
goto :goto_8
.line 3
:cond_1f
monitor-exit p0
return v0
:catchall_21
move-exception v0
monitor-exit p0
throw v0
.end method
.method public put(Lokhttp3/internal/connection/RealConnection;)V
.registers 4
.line 1
iget-boolean v0, p0, Lokhttp3/ConnectionPool;->cleanupRunning:Z
if-nez v0, :cond_e
const/4 v0, 0x1
.line 2
iput-boolean v0, p0, Lokhttp3/ConnectionPool;->cleanupRunning:Z
.line 3
sget-object v0, Lokhttp3/ConnectionPool;->executor:Ljava/util/concurrent/Executor;
iget-object v1, p0, Lokhttp3/ConnectionPool;->cleanupRunnable:Ljava/lang/Runnable;
invoke-static {v0, v1}, Lokhttp3/ConnectionPool;->INVOKEINTERFACE_okhttp3_ConnectionPool_com_shopee_app_asm_anr_threadpool_ExecutorProxy_execute(Ljava/util/concurrent/Executor;Ljava/lang/Runnable;)V
.line 4
:cond_e
iget-object v0, p0, Lokhttp3/ConnectionPool;->connections:Ljava/util/Deque;
invoke-interface {v0, p1}, Ljava/util/Deque;->add(Ljava/lang/Object;)Z
return-void
.end method