Throttler.smali
.class public final Lokio/Throttler;
.super Ljava/lang/Object;
.source "Throttler.kt"
# instance fields
.field private allocatedUntil:J
.field private bytesPerSecond:J
.field private maxByteCount:J
.field private waitByteCount:J
# direct methods
.method public constructor <init>()V
.registers 3
.line 4
invoke-static {}, Ljava/lang/System;->nanoTime()J
move-result-wide v0
invoke-direct {p0, v0, v1}, Lokio/Throttler;-><init>(J)V
return-void
.end method
.method public constructor <init>(J)V
.registers 3
.line 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
iput-wide p1, p0, Lokio/Throttler;->allocatedUntil:J
const-wide/16 p1, 0x2000
.line 2
iput-wide p1, p0, Lokio/Throttler;->waitByteCount:J
const-wide/32 p1, 0x40000
.line 3
iput-wide p1, p0, Lokio/Throttler;->maxByteCount:J
return-void
.end method
.method public static synthetic bytesPerSecond$default(Lokio/Throttler;JJJILjava/lang/Object;)V
.registers 16
and-int/lit8 p8, p7, 0x2
if-eqz p8, :cond_6
.line 1
iget-wide p3, p0, Lokio/Throttler;->waitByteCount:J
:cond_6
move-wide v3, p3
and-int/lit8 p3, p7, 0x4
if-eqz p3, :cond_d
.line 2
iget-wide p5, p0, Lokio/Throttler;->maxByteCount:J
:cond_d
move-wide v5, p5
move-object v0, p0
move-wide v1, p1
invoke-virtual/range {v0 .. v6}, Lokio/Throttler;->bytesPerSecond(JJJ)V
return-void
.end method
.method private final bytesToNanos(J)J
.registers 5
const-wide/32 v0, 0x3b9aca00
mul-long p1, p1, v0
.line 1
iget-wide v0, p0, Lokio/Throttler;->bytesPerSecond:J
div-long/2addr p1, v0
return-wide p1
.end method
.method private final nanosToBytes(J)J
.registers 5
.line 1
iget-wide v0, p0, Lokio/Throttler;->bytesPerSecond:J
mul-long p1, p1, v0
const-wide/32 v0, 0x3b9aca00
div-long/2addr p1, v0
return-wide p1
.end method
.method private final waitNanos(J)V
.registers 7
const-wide/32 v0, 0xf4240
.line 1
div-long v2, p1, v0
mul-long v0, v0, v2
sub-long/2addr p1, v0
long-to-int p2, p1
.line 2
invoke-virtual {p0, v2, v3, p2}, Ljava/lang/Object;->wait(JI)V
return-void
.end method
# virtual methods
.method public final byteCountOrWaitNanos$okio(JJ)J
.registers 14
.line 1
iget-wide v0, p0, Lokio/Throttler;->bytesPerSecond:J
const-wide/16 v2, 0x0
cmp-long v4, v0, v2
if-nez v4, :cond_9
return-wide p3
.line 2
:cond_9
iget-wide v0, p0, Lokio/Throttler;->allocatedUntil:J
sub-long/2addr v0, p1
invoke-static {v0, v1, v2, v3}, Ljava/lang/Math;->max(JJ)J
move-result-wide v0
.line 3
iget-wide v4, p0, Lokio/Throttler;->maxByteCount:J
invoke-direct {p0, v0, v1}, Lokio/Throttler;->nanosToBytes(J)J
move-result-wide v6
sub-long/2addr v4, v6
cmp-long v6, v4, p3
if-ltz v6, :cond_24
add-long/2addr p1, v0
.line 4
invoke-direct {p0, p3, p4}, Lokio/Throttler;->bytesToNanos(J)J
move-result-wide v0
add-long/2addr p1, v0
iput-wide p1, p0, Lokio/Throttler;->allocatedUntil:J
return-wide p3
.line 5
:cond_24
iget-wide v6, p0, Lokio/Throttler;->waitByteCount:J
cmp-long v8, v4, v6
if-ltz v8, :cond_34
.line 6
iget-wide p3, p0, Lokio/Throttler;->maxByteCount:J
invoke-direct {p0, p3, p4}, Lokio/Throttler;->bytesToNanos(J)J
move-result-wide p3
add-long/2addr p1, p3
iput-wide p1, p0, Lokio/Throttler;->allocatedUntil:J
return-wide v4
.line 7
:cond_34
invoke-static {v6, v7, p3, p4}, Ljava/lang/Math;->min(JJ)J
move-result-wide p3
.line 8
iget-wide v4, p0, Lokio/Throttler;->maxByteCount:J
sub-long v4, p3, v4
invoke-direct {p0, v4, v5}, Lokio/Throttler;->bytesToNanos(J)J
move-result-wide v4
add-long/2addr v0, v4
cmp-long v4, v0, v2
if-nez v4, :cond_4f
.line 9
iget-wide v0, p0, Lokio/Throttler;->maxByteCount:J
invoke-direct {p0, v0, v1}, Lokio/Throttler;->bytesToNanos(J)J
move-result-wide v0
add-long/2addr p1, v0
iput-wide p1, p0, Lokio/Throttler;->allocatedUntil:J
return-wide p3
:cond_4f
neg-long p1, v0
return-wide p1
.end method
.method public final bytesPerSecond(J)V
.registers 12
const-wide/16 v3, 0x0
const-wide/16 v5, 0x0
const/4 v7, 0x6
const/4 v8, 0x0
move-object v0, p0
move-wide v1, p1
invoke-static/range {v0 .. v8}, Lokio/Throttler;->bytesPerSecond$default(Lokio/Throttler;JJJILjava/lang/Object;)V
return-void
.end method
.method public final bytesPerSecond(JJ)V
.registers 14
const-wide/16 v5, 0x0
const/4 v7, 0x4
const/4 v8, 0x0
move-object v0, p0
move-wide v1, p1
move-wide v3, p3
invoke-static/range {v0 .. v8}, Lokio/Throttler;->bytesPerSecond$default(Lokio/Throttler;JJJILjava/lang/Object;)V
return-void
.end method
.method public final bytesPerSecond(JJJ)V
.registers 12
.line 1
monitor-enter p0
const-wide/16 v0, 0x0
const/4 v2, 0x1
const/4 v3, 0x0
cmp-long v4, p1, v0
if-ltz v4, :cond_b
const/4 v4, 0x1
goto :goto_c
:cond_b
const/4 v4, 0x0
:goto_c
if-eqz v4, :cond_3c
cmp-long v4, p3, v0
if-lez v4, :cond_14
const/4 v0, 0x1
goto :goto_15
:cond_14
const/4 v0, 0x0
:goto_15
if-eqz v0, :cond_34
cmp-long v0, p5, p3
if-ltz v0, :cond_1c
goto :goto_1d
:cond_1c
const/4 v2, 0x0
:goto_1d
if-eqz v2, :cond_2c
.line 2
:try_start_1f
iput-wide p1, p0, Lokio/Throttler;->bytesPerSecond:J
.line 3
iput-wide p3, p0, Lokio/Throttler;->waitByteCount:J
.line 4
iput-wide p5, p0, Lokio/Throttler;->maxByteCount:J
.line 5
invoke-virtual {p0}, Ljava/lang/Object;->notifyAll()V
.line 6
sget-object p1, Lkotlin/n;->a:Lkotlin/n;
:try_end_2a
.catchall {:try_start_1f .. :try_end_2a} :catchall_44
monitor-exit p0
return-void
:cond_2c
:try_start_2c
const-string p1, "Failed requirement."
.line 7
new-instance p2, Ljava/lang/IllegalArgumentException;
invoke-direct {p2, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw p2
:cond_34
const-string p1, "Failed requirement."
.line 8
new-instance p2, Ljava/lang/IllegalArgumentException;
invoke-direct {p2, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw p2
:cond_3c
const-string p1, "Failed requirement."
.line 9
new-instance p2, Ljava/lang/IllegalArgumentException;
invoke-direct {p2, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw p2
:try_end_44
.catchall {:try_start_2c .. :try_end_44} :catchall_44
:catchall_44
move-exception p1
.line 10
monitor-exit p0
throw p1
.end method
.method public final sink(Lokio/Sink;)Lokio/Sink;
.registers 3
const-string v0, "sink"
invoke-static {p1, v0}, Lkotlin/jvm/internal/i;->d(Ljava/lang/Object;Ljava/lang/String;)V
.line 1
new-instance v0, Lokio/Throttler$sink$1;
invoke-direct {v0, p0, p1, p1}, Lokio/Throttler$sink$1;-><init>(Lokio/Throttler;Lokio/Sink;Lokio/Sink;)V
return-object v0
.end method
.method public final source(Lokio/Source;)Lokio/Source;
.registers 3
const-string v0, "source"
invoke-static {p1, v0}, Lkotlin/jvm/internal/i;->d(Ljava/lang/Object;Ljava/lang/String;)V
.line 1
new-instance v0, Lokio/Throttler$source$1;
invoke-direct {v0, p0, p1, p1}, Lokio/Throttler$source$1;-><init>(Lokio/Throttler;Lokio/Source;Lokio/Source;)V
return-object v0
.end method
.method public final take$okio(J)J
.registers 8
const-wide/16 v0, 0x0
cmp-long v2, p1, v0
if-lez v2, :cond_8
const/4 v2, 0x1
goto :goto_9
:cond_8
const/4 v2, 0x0
:goto_9
if-eqz v2, :cond_22
.line 1
monitor-enter p0
.line 2
:goto_c
:try_start_c
invoke-static {}, Ljava/lang/System;->nanoTime()J
move-result-wide v2
.line 3
invoke-virtual {p0, v2, v3, p1, p2}, Lokio/Throttler;->byteCountOrWaitNanos$okio(JJ)J
move-result-wide v2
:try_end_14
.catchall {:try_start_c .. :try_end_14} :catchall_1f
cmp-long v4, v2, v0
if-ltz v4, :cond_1a
.line 4
monitor-exit p0
return-wide v2
:cond_1a
neg-long v2, v2
.line 5
:try_start_1b
invoke-direct {p0, v2, v3}, Lokio/Throttler;->waitNanos(J)V
:try_end_1e
.catchall {:try_start_1b .. :try_end_1e} :catchall_1f
goto :goto_c
:catchall_1f
move-exception p1
.line 6
monitor-exit p0
throw p1
.line 7
:cond_22
new-instance p1, Ljava/lang/IllegalArgumentException;
const-string p2, "Failed requirement."
invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
goto :goto_2b
:goto_2a
throw p1
:goto_2b
goto :goto_2a
.end method