AsyncTimeout.smali 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. .class public Lokio/AsyncTimeout;
  2. .super Lokio/Timeout;
  3. .source ""
  4. # annotations
  5. .annotation system Ldalvik/annotation/MemberClasses;
  6. value = {
  7. Lokio/AsyncTimeout$Watchdog;
  8. }
  9. .end annotation
  10. # static fields
  11. .field private static final IDLE_TIMEOUT_MILLIS:J
  12. .field private static final IDLE_TIMEOUT_NANOS:J
  13. .field private static final TIMEOUT_WRITE_SIZE:I = 0x10000
  14. .field static head:Lokio/AsyncTimeout;
  15. # instance fields
  16. .field private inQueue:Z
  17. .field private next:Lokio/AsyncTimeout;
  18. .field private timeoutAt:J
  19. # direct methods
  20. .method static constructor <clinit>()V
  21. .locals 3
  22. sget-object v0, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;
  23. const-wide/16 v1, 0x3c
  24. invoke-virtual {v0, v1, v2}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J
  25. move-result-wide v0
  26. sput-wide v0, Lokio/AsyncTimeout;->IDLE_TIMEOUT_MILLIS:J
  27. sget-object v0, Ljava/util/concurrent/TimeUnit;->MILLISECONDS:Ljava/util/concurrent/TimeUnit;
  28. sget-wide v1, Lokio/AsyncTimeout;->IDLE_TIMEOUT_MILLIS:J
  29. invoke-virtual {v0, v1, v2}, Ljava/util/concurrent/TimeUnit;->toNanos(J)J
  30. move-result-wide v0
  31. sput-wide v0, Lokio/AsyncTimeout;->IDLE_TIMEOUT_NANOS:J
  32. return-void
  33. .end method
  34. .method public constructor <init>()V
  35. .locals 0
  36. invoke-direct {p0}, Lokio/Timeout;-><init>()V
  37. return-void
  38. .end method
  39. .method static awaitTimeout()Lokio/AsyncTimeout;
  40. .locals 9
  41. .annotation system Ldalvik/annotation/Throws;
  42. value = {
  43. Ljava/lang/InterruptedException;
  44. }
  45. .end annotation
  46. const-class v0, Lokio/AsyncTimeout;
  47. sget-object v1, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  48. iget-object v1, v1, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  49. const/4 v2, 0x0
  50. invoke-static {}, Ljava/lang/System;->nanoTime()J
  51. move-result-wide v3
  52. if-nez v1, :cond_1
  53. sget-wide v5, Lokio/AsyncTimeout;->IDLE_TIMEOUT_MILLIS:J
  54. invoke-virtual {v0, v5, v6}, Ljava/lang/Object;->wait(J)V
  55. sget-object v0, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  56. iget-object v0, v0, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  57. if-nez v0, :cond_0
  58. invoke-static {}, Ljava/lang/System;->nanoTime()J
  59. move-result-wide v0
  60. sub-long/2addr v0, v3
  61. sget-wide v3, Lokio/AsyncTimeout;->IDLE_TIMEOUT_NANOS:J
  62. cmp-long v5, v0, v3
  63. if-ltz v5, :cond_0
  64. sget-object v2, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  65. :cond_0
  66. return-object v2
  67. :cond_1
  68. invoke-direct {v1, v3, v4}, Lokio/AsyncTimeout;->remainingNanos(J)J
  69. move-result-wide v3
  70. const-wide/16 v5, 0x0
  71. cmp-long v7, v3, v5
  72. if-lez v7, :cond_2
  73. const-wide/32 v5, 0xf4240
  74. div-long v7, v3, v5
  75. mul-long v5, v5, v7
  76. sub-long/2addr v3, v5
  77. long-to-int v1, v3
  78. invoke-virtual {v0, v7, v8, v1}, Ljava/lang/Object;->wait(JI)V
  79. return-object v2
  80. :cond_2
  81. sget-object v0, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  82. iget-object v3, v1, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  83. iput-object v3, v0, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  84. iput-object v2, v1, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  85. return-object v1
  86. .end method
  87. .method private static declared-synchronized cancelScheduledTimeout(Lokio/AsyncTimeout;)Z
  88. .locals 3
  89. const-class v0, Lokio/AsyncTimeout;
  90. monitor-enter v0
  91. :try_start_0
  92. sget-object v1, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  93. :goto_0
  94. if-eqz v1, :cond_1
  95. iget-object v2, v1, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  96. if-ne v2, p0, :cond_0
  97. iget-object v2, p0, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  98. iput-object v2, v1, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  99. const/4 v1, 0x0
  100. iput-object v1, p0, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  101. :try_end_0
  102. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  103. const/4 p0, 0x0
  104. :goto_1
  105. monitor-exit v0
  106. return p0
  107. :cond_0
  108. :try_start_1
  109. iget-object v1, v1, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  110. :try_end_1
  111. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  112. goto :goto_0
  113. :cond_1
  114. const/4 p0, 0x1
  115. goto :goto_1
  116. :catchall_0
  117. move-exception p0
  118. monitor-exit v0
  119. goto :goto_3
  120. :goto_2
  121. throw p0
  122. :goto_3
  123. goto :goto_2
  124. .end method
  125. .method private remainingNanos(J)J
  126. .locals 2
  127. iget-wide v0, p0, Lokio/AsyncTimeout;->timeoutAt:J
  128. sub-long/2addr v0, p1
  129. return-wide v0
  130. .end method
  131. .method private static declared-synchronized scheduleTimeout(Lokio/AsyncTimeout;JZ)V
  132. .locals 6
  133. const-class v0, Lokio/AsyncTimeout;
  134. monitor-enter v0
  135. :try_start_0
  136. sget-object v1, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  137. if-nez v1, :cond_0
  138. new-instance v1, Lokio/AsyncTimeout;
  139. invoke-direct {v1}, Lokio/AsyncTimeout;-><init>()V
  140. sput-object v1, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  141. new-instance v1, Lokio/AsyncTimeout$Watchdog;
  142. invoke-direct {v1}, Lokio/AsyncTimeout$Watchdog;-><init>()V
  143. invoke-virtual {v1}, Ljava/lang/Thread;->start()V
  144. :cond_0
  145. invoke-static {}, Ljava/lang/System;->nanoTime()J
  146. move-result-wide v1
  147. const-wide/16 v3, 0x0
  148. cmp-long v5, p1, v3
  149. if-eqz v5, :cond_1
  150. if-eqz p3, :cond_1
  151. invoke-virtual {p0}, Lokio/Timeout;->deadlineNanoTime()J
  152. move-result-wide v3
  153. sub-long/2addr v3, v1
  154. invoke-static {p1, p2, v3, v4}, Ljava/lang/Math;->min(JJ)J
  155. move-result-wide p1
  156. :goto_0
  157. add-long/2addr p1, v1
  158. iput-wide p1, p0, Lokio/AsyncTimeout;->timeoutAt:J
  159. goto :goto_1
  160. :cond_1
  161. cmp-long v5, p1, v3
  162. if-eqz v5, :cond_2
  163. goto :goto_0
  164. :cond_2
  165. if-eqz p3, :cond_6
  166. invoke-virtual {p0}, Lokio/Timeout;->deadlineNanoTime()J
  167. move-result-wide p1
  168. iput-wide p1, p0, Lokio/AsyncTimeout;->timeoutAt:J
  169. :goto_1
  170. invoke-direct {p0, v1, v2}, Lokio/AsyncTimeout;->remainingNanos(J)J
  171. move-result-wide p1
  172. sget-object p3, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  173. :goto_2
  174. iget-object v3, p3, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  175. if-eqz v3, :cond_4
  176. iget-object v3, p3, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  177. invoke-direct {v3, v1, v2}, Lokio/AsyncTimeout;->remainingNanos(J)J
  178. move-result-wide v3
  179. cmp-long v5, p1, v3
  180. if-gez v5, :cond_3
  181. goto :goto_3
  182. :cond_3
  183. iget-object p3, p3, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  184. goto :goto_2
  185. :cond_4
  186. :goto_3
  187. iget-object p1, p3, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  188. iput-object p1, p0, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  189. iput-object p0, p3, Lokio/AsyncTimeout;->next:Lokio/AsyncTimeout;
  190. sget-object p0, Lokio/AsyncTimeout;->head:Lokio/AsyncTimeout;
  191. if-ne p3, p0, :cond_5
  192. invoke-virtual {v0}, Ljava/lang/Object;->notify()V
  193. :try_end_0
  194. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  195. :cond_5
  196. monitor-exit v0
  197. return-void
  198. :cond_6
  199. :try_start_1
  200. new-instance p0, Ljava/lang/AssertionError;
  201. invoke-direct {p0}, Ljava/lang/AssertionError;-><init>()V
  202. throw p0
  203. :try_end_1
  204. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  205. :catchall_0
  206. move-exception p0
  207. monitor-exit v0
  208. goto :goto_5
  209. :goto_4
  210. throw p0
  211. :goto_5
  212. goto :goto_4
  213. .end method
  214. # virtual methods
  215. .method public final enter()V
  216. .locals 6
  217. iget-boolean v0, p0, Lokio/AsyncTimeout;->inQueue:Z
  218. if-nez v0, :cond_1
  219. invoke-virtual {p0}, Lokio/Timeout;->timeoutNanos()J
  220. move-result-wide v0
  221. invoke-virtual {p0}, Lokio/Timeout;->hasDeadline()Z
  222. move-result v2
  223. const-wide/16 v3, 0x0
  224. cmp-long v5, v0, v3
  225. if-nez v5, :cond_0
  226. if-nez v2, :cond_0
  227. return-void
  228. :cond_0
  229. const/4 v3, 0x1
  230. iput-boolean v3, p0, Lokio/AsyncTimeout;->inQueue:Z
  231. invoke-static {p0, v0, v1, v2}, Lokio/AsyncTimeout;->scheduleTimeout(Lokio/AsyncTimeout;JZ)V
  232. return-void
  233. :cond_1
  234. new-instance v0, Ljava/lang/IllegalStateException;
  235. const-string v1, "Unbalanced enter/exit"
  236. invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
  237. throw v0
  238. .end method
  239. .method final exit(Ljava/io/IOException;)Ljava/io/IOException;
  240. .locals 1
  241. .annotation system Ldalvik/annotation/Throws;
  242. value = {
  243. Ljava/io/IOException;
  244. }
  245. .end annotation
  246. invoke-virtual {p0}, Lokio/AsyncTimeout;->exit()Z
  247. move-result v0
  248. if-nez v0, :cond_0
  249. return-object p1
  250. :cond_0
  251. invoke-virtual {p0, p1}, Lokio/AsyncTimeout;->newTimeoutException(Ljava/io/IOException;)Ljava/io/IOException;
  252. move-result-object p1
  253. return-object p1
  254. .end method
  255. .method final exit(Z)V
  256. .locals 1
  257. .annotation system Ldalvik/annotation/Throws;
  258. value = {
  259. Ljava/io/IOException;
  260. }
  261. .end annotation
  262. invoke-virtual {p0}, Lokio/AsyncTimeout;->exit()Z
  263. move-result v0
  264. if-eqz v0, :cond_1
  265. if-nez p1, :cond_0
  266. goto :goto_0
  267. :cond_0
  268. const/4 p1, 0x0
  269. invoke-virtual {p0, p1}, Lokio/AsyncTimeout;->newTimeoutException(Ljava/io/IOException;)Ljava/io/IOException;
  270. move-result-object p1
  271. throw p1
  272. :cond_1
  273. :goto_0
  274. return-void
  275. .end method
  276. .method public final exit()Z
  277. .locals 2
  278. iget-boolean v0, p0, Lokio/AsyncTimeout;->inQueue:Z
  279. const/4 v1, 0x0
  280. if-nez v0, :cond_0
  281. return v1
  282. :cond_0
  283. iput-boolean v1, p0, Lokio/AsyncTimeout;->inQueue:Z
  284. invoke-static {p0}, Lokio/AsyncTimeout;->cancelScheduledTimeout(Lokio/AsyncTimeout;)Z
  285. move-result v0
  286. return v0
  287. .end method
  288. .method protected newTimeoutException(Ljava/io/IOException;)Ljava/io/IOException;
  289. .locals 2
  290. new-instance v0, Ljava/io/InterruptedIOException;
  291. const-string v1, "timeout"
  292. invoke-direct {v0, v1}, Ljava/io/InterruptedIOException;-><init>(Ljava/lang/String;)V
  293. if-eqz p1, :cond_0
  294. invoke-virtual {v0, p1}, Ljava/io/InterruptedIOException;->initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;
  295. :cond_0
  296. return-object v0
  297. .end method
  298. .method public final sink(Lokio/Sink;)Lokio/Sink;
  299. .locals 1
  300. new-instance v0, Lokio/AsyncTimeout$1;
  301. invoke-direct {v0, p0, p1}, Lokio/AsyncTimeout$1;-><init>(Lokio/AsyncTimeout;Lokio/Sink;)V
  302. return-object v0
  303. .end method
  304. .method public final source(Lokio/Source;)Lokio/Source;
  305. .locals 1
  306. new-instance v0, Lokio/AsyncTimeout$2;
  307. invoke-direct {v0, p0, p1}, Lokio/AsyncTimeout$2;-><init>(Lokio/AsyncTimeout;Lokio/Source;)V
  308. return-object v0
  309. .end method
  310. .method protected timedOut()V
  311. .locals 0
  312. return-void
  313. .end method