Timeout.smali 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. .class public Lokio/Timeout;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # static fields
  5. .field public static final NONE:Lokio/Timeout;
  6. # instance fields
  7. .field private deadlineNanoTime:J
  8. .field private hasDeadline:Z
  9. .field private timeoutNanos:J
  10. # direct methods
  11. .method static constructor <clinit>()V
  12. .locals 1
  13. new-instance v0, Lokio/Timeout$1;
  14. invoke-direct {v0}, Lokio/Timeout$1;-><init>()V
  15. sput-object v0, Lokio/Timeout;->NONE:Lokio/Timeout;
  16. return-void
  17. .end method
  18. .method public constructor <init>()V
  19. .locals 0
  20. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  21. return-void
  22. .end method
  23. # virtual methods
  24. .method public clearDeadline()Lokio/Timeout;
  25. .locals 1
  26. const/4 v0, 0x0
  27. iput-boolean v0, p0, Lokio/Timeout;->hasDeadline:Z
  28. return-object p0
  29. .end method
  30. .method public clearTimeout()Lokio/Timeout;
  31. .locals 2
  32. const-wide/16 v0, 0x0
  33. iput-wide v0, p0, Lokio/Timeout;->timeoutNanos:J
  34. return-object p0
  35. .end method
  36. .method public final deadline(JLjava/util/concurrent/TimeUnit;)Lokio/Timeout;
  37. .locals 3
  38. const-wide/16 v0, 0x0
  39. cmp-long v2, p1, v0
  40. if-lez v2, :cond_1
  41. if-eqz p3, :cond_0
  42. invoke-static {}, Ljava/lang/System;->nanoTime()J
  43. move-result-wide v0
  44. invoke-virtual {p3, p1, p2}, Ljava/util/concurrent/TimeUnit;->toNanos(J)J
  45. move-result-wide p1
  46. add-long/2addr v0, p1
  47. invoke-virtual {p0, v0, v1}, Lokio/Timeout;->deadlineNanoTime(J)Lokio/Timeout;
  48. move-result-object p1
  49. return-object p1
  50. :cond_0
  51. new-instance p1, Ljava/lang/IllegalArgumentException;
  52. const-string p2, "unit == null"
  53. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  54. throw p1
  55. :cond_1
  56. new-instance p3, Ljava/lang/IllegalArgumentException;
  57. new-instance v0, Ljava/lang/StringBuilder;
  58. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  59. const-string v1, "duration <= 0: "
  60. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  61. invoke-virtual {v0, p1, p2}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  62. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  63. move-result-object p1
  64. invoke-direct {p3, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  65. throw p3
  66. .end method
  67. .method public deadlineNanoTime()J
  68. .locals 2
  69. iget-boolean v0, p0, Lokio/Timeout;->hasDeadline:Z
  70. if-eqz v0, :cond_0
  71. iget-wide v0, p0, Lokio/Timeout;->deadlineNanoTime:J
  72. return-wide v0
  73. :cond_0
  74. new-instance v0, Ljava/lang/IllegalStateException;
  75. const-string v1, "No deadline"
  76. invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
  77. throw v0
  78. .end method
  79. .method public deadlineNanoTime(J)Lokio/Timeout;
  80. .locals 1
  81. const/4 v0, 0x1
  82. iput-boolean v0, p0, Lokio/Timeout;->hasDeadline:Z
  83. iput-wide p1, p0, Lokio/Timeout;->deadlineNanoTime:J
  84. return-object p0
  85. .end method
  86. .method public hasDeadline()Z
  87. .locals 1
  88. iget-boolean v0, p0, Lokio/Timeout;->hasDeadline:Z
  89. return v0
  90. .end method
  91. .method public throwIfReached()V
  92. .locals 5
  93. .annotation system Ldalvik/annotation/Throws;
  94. value = {
  95. Ljava/io/IOException;
  96. }
  97. .end annotation
  98. invoke-static {}, Ljava/lang/Thread;->interrupted()Z
  99. move-result v0
  100. if-nez v0, :cond_2
  101. iget-boolean v0, p0, Lokio/Timeout;->hasDeadline:Z
  102. if-eqz v0, :cond_1
  103. iget-wide v0, p0, Lokio/Timeout;->deadlineNanoTime:J
  104. invoke-static {}, Ljava/lang/System;->nanoTime()J
  105. move-result-wide v2
  106. sub-long/2addr v0, v2
  107. const-wide/16 v2, 0x0
  108. cmp-long v4, v0, v2
  109. if-lez v4, :cond_0
  110. goto :goto_0
  111. :cond_0
  112. new-instance v0, Ljava/io/InterruptedIOException;
  113. const-string v1, "deadline reached"
  114. invoke-direct {v0, v1}, Ljava/io/InterruptedIOException;-><init>(Ljava/lang/String;)V
  115. throw v0
  116. :cond_1
  117. :goto_0
  118. return-void
  119. :cond_2
  120. new-instance v0, Ljava/io/InterruptedIOException;
  121. const-string v1, "thread interrupted"
  122. invoke-direct {v0, v1}, Ljava/io/InterruptedIOException;-><init>(Ljava/lang/String;)V
  123. throw v0
  124. .end method
  125. .method public timeout(JLjava/util/concurrent/TimeUnit;)Lokio/Timeout;
  126. .locals 3
  127. const-wide/16 v0, 0x0
  128. cmp-long v2, p1, v0
  129. if-ltz v2, :cond_1
  130. if-eqz p3, :cond_0
  131. invoke-virtual {p3, p1, p2}, Ljava/util/concurrent/TimeUnit;->toNanos(J)J
  132. move-result-wide p1
  133. iput-wide p1, p0, Lokio/Timeout;->timeoutNanos:J
  134. return-object p0
  135. :cond_0
  136. new-instance p1, Ljava/lang/IllegalArgumentException;
  137. const-string p2, "unit == null"
  138. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  139. throw p1
  140. :cond_1
  141. new-instance p3, Ljava/lang/IllegalArgumentException;
  142. new-instance v0, Ljava/lang/StringBuilder;
  143. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  144. const-string v1, "timeout < 0: "
  145. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  146. invoke-virtual {v0, p1, p2}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  147. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  148. move-result-object p1
  149. invoke-direct {p3, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  150. throw p3
  151. .end method
  152. .method public timeoutNanos()J
  153. .locals 2
  154. iget-wide v0, p0, Lokio/Timeout;->timeoutNanos:J
  155. return-wide v0
  156. .end method
  157. .method public final waitUntilNotified(Ljava/lang/Object;)V
  158. .locals 9
  159. .annotation system Ldalvik/annotation/Throws;
  160. value = {
  161. Ljava/io/InterruptedIOException;
  162. }
  163. .end annotation
  164. :try_start_0
  165. invoke-virtual {p0}, Lokio/Timeout;->hasDeadline()Z
  166. move-result v0
  167. invoke-virtual {p0}, Lokio/Timeout;->timeoutNanos()J
  168. move-result-wide v1
  169. const-wide/16 v3, 0x0
  170. if-nez v0, :cond_0
  171. cmp-long v5, v1, v3
  172. if-nez v5, :cond_0
  173. invoke-virtual {p1}, Ljava/lang/Object;->wait()V
  174. return-void
  175. :cond_0
  176. invoke-static {}, Ljava/lang/System;->nanoTime()J
  177. move-result-wide v5
  178. if-eqz v0, :cond_1
  179. cmp-long v7, v1, v3
  180. if-eqz v7, :cond_1
  181. invoke-virtual {p0}, Lokio/Timeout;->deadlineNanoTime()J
  182. move-result-wide v7
  183. sub-long/2addr v7, v5
  184. invoke-static {v1, v2, v7, v8}, Ljava/lang/Math;->min(JJ)J
  185. move-result-wide v1
  186. goto :goto_0
  187. :cond_1
  188. if-eqz v0, :cond_2
  189. invoke-virtual {p0}, Lokio/Timeout;->deadlineNanoTime()J
  190. move-result-wide v0
  191. sub-long/2addr v0, v5
  192. move-wide v1, v0
  193. :cond_2
  194. :goto_0
  195. cmp-long v0, v1, v3
  196. if-lez v0, :cond_3
  197. const-wide/32 v3, 0xf4240
  198. div-long v7, v1, v3
  199. :try_end_0
  200. .catch Ljava/lang/InterruptedException; {:try_start_0 .. :try_end_0} :catch_0
  201. invoke-static {v7, v8}, Ljava/lang/Long;->signum(J)I
  202. mul-long v3, v3, v7
  203. sub-long v3, v1, v3
  204. long-to-int v0, v3
  205. :try_start_1
  206. invoke-virtual {p1, v7, v8, v0}, Ljava/lang/Object;->wait(JI)V
  207. invoke-static {}, Ljava/lang/System;->nanoTime()J
  208. move-result-wide v3
  209. sub-long/2addr v3, v5
  210. :cond_3
  211. cmp-long p1, v3, v1
  212. if-gez p1, :cond_4
  213. return-void
  214. :cond_4
  215. new-instance p1, Ljava/io/InterruptedIOException;
  216. const-string v0, "timeout"
  217. invoke-direct {p1, v0}, Ljava/io/InterruptedIOException;-><init>(Ljava/lang/String;)V
  218. throw p1
  219. :try_end_1
  220. .catch Ljava/lang/InterruptedException; {:try_start_1 .. :try_end_1} :catch_0
  221. :catch_0
  222. new-instance p1, Ljava/io/InterruptedIOException;
  223. const-string v0, "interrupted"
  224. invoke-direct {p1, v0}, Ljava/io/InterruptedIOException;-><init>(Ljava/lang/String;)V
  225. throw p1
  226. .end method