Skip to content

Ensure retain(...) will always throw once it did once. - #8574

Closed
normanmaurer wants to merge 1 commit into
4.1from
ref_test
Closed

normanmaurer wants to merge 1 commit into
4.1from
ref_test

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

83a19d5 did make some optimizations which could lead to the situation that retain(...) may throw IllegalReferenceCountException once but may not throw it again when invoked concurrently.

Modification:

  • Change code be more robust and more correct in terms of how reference count issues are reported.
  • Add unit test.

Result:

Fixes #8563.

Before:

AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                           1  sample  33113962     648.130 ?  0.290  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00              1  sample                42.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50              1  sample               533.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90              1  sample              1258.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95              1  sample              1518.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99              1  sample              2168.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999             1  sample              3492.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999            1  sample             15296.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00              1  sample            367104.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                          10  sample  37599393     494.185 ?  0.170  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00             10  sample                56.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50             10  sample               427.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90             10  sample               821.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95             10  sample               992.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99             10  sample              1432.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999            10  sample              2472.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999           10  sample              7744.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00             10  sample            166656.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                         100  sample  38506222     514.284 ?  0.120  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00            100  sample               268.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50            100  sample               476.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90            100  sample               662.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95            100  sample               767.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99            100  sample              1052.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999           100  sample              1560.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999          100  sample              9040.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00            100  sample            168704.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                        1000  sample  25227982    2988.675 ?  0.469  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00           1000  sample              2404.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50           1000  sample              2748.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90           1000  sample              3616.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95           1000  sample              4264.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99           1000  sample              6136.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999          1000  sample              6408.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999         1000  sample             20480.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00           1000  sample            218368.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                       10000  sample  20740699   28886.175 ?  4.364  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00          10000  sample             23424.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50          10000  sample             26208.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90          10000  sample             35328.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95          10000  sample             41536.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99          10000  sample             58944.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999         10000  sample             59200.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999        10000  sample             74112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00          10000  sample            178688.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                         1  sample   6692625      55.262 ?  0.097  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00          1  sample                40.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50          1  sample                49.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90          1  sample                71.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95          1  sample                82.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99          1  sample               110.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999         1  sample               110.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999        1  sample              1617.475           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00          1  sample             19168.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                        10  sample   4794123      75.339 ?  0.143  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00         10  sample                62.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50         10  sample                66.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90         10  sample                98.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95         10  sample               115.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99         10  sample               147.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999        10  sample               150.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999       10  sample              2364.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00         10  sample             22048.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                       100  sample   5040621     343.582 ?  0.263  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00        100  sample               228.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50        100  sample               301.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90        100  sample               449.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95        100  sample               510.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99        100  sample               676.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999       100  sample               683.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999      100  sample              8135.502           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00        100  sample             26112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                      1000  sample   4150252    3032.540 ?  1.298  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00       1000  sample              2160.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50       1000  sample              2648.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90       1000  sample              3968.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95       1000  sample              4760.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99       1000  sample              5960.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999      1000  sample              6504.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999     1000  sample             19904.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00       1000  sample             52352.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                     10000  sample   3275578   30489.966 ? 14.050  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00      10000  sample             25952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50      10000  sample             26112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90      10000  sample             41472.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95      10000  sample             47040.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99      10000  sample             58752.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999     10000  sample             59008.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999    10000  sample             75520.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00      10000  sample            125056.000           ns/op

After:

Benchmark                                                                                           (delay)    Mode       Cnt       Score    Error  Units
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                           1  sample  31059953     690.194 ?  0.257  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00              1  sample                44.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50              1  sample               627.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90              1  sample              1148.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95              1  sample              1362.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99              1  sample              1926.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999             1  sample              3272.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999            1  sample             15792.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00              1  sample            178432.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                          10  sample  28862663     725.757 ?  0.277  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00             10  sample                55.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50             10  sample               652.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90             10  sample              1210.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95             10  sample              1432.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99             10  sample              2000.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999            10  sample              3528.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999           10  sample             15952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00             10  sample            213504.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                         100  sample  31823478     751.129 ?  0.187  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00            100  sample               273.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50            100  sample               699.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90            100  sample              1032.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95            100  sample              1188.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99            100  sample              1618.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999           100  sample              2508.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999          100  sample             15952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00            100  sample            168704.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                        1000  sample  25430205    2967.247 ?  0.474  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00           1000  sample              2396.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50           1000  sample              2700.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90           1000  sample              3628.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95           1000  sample              4248.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99           1000  sample              6056.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999          1000  sample              6464.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999         1000  sample             20640.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00           1000  sample            261632.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                       10000  sample  21113138   28377.341 ?  3.951  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00          10000  sample             23424.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50          10000  sample             26176.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90          10000  sample             33600.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95          10000  sample             37376.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99          10000  sample             58816.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999         10000  sample             59072.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999        10000  sample             73216.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00          10000  sample            245504.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                         1  sample   5966172      58.417 ?  0.095  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00          1  sample                37.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50          1  sample                52.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90          1  sample                74.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95          1  sample                86.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99          1  sample               117.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999         1  sample               120.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999        1  sample              1630.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00          1  sample             21952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                        10  sample   4535644      75.899 ?  0.165  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00         10  sample                54.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50         10  sample                66.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90         10  sample                98.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95         10  sample               116.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99         10  sample               147.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999        10  sample               200.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999       10  sample              2769.742           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00         10  sample             30528.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                       100  sample   5096864     340.189 ?  0.262  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00        100  sample               228.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50        100  sample               301.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90        100  sample               430.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95        100  sample               508.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99        100  sample               676.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999       100  sample               723.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999      100  sample              9430.224           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00        100  sample             22976.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                      1000  sample   4192970    3001.264 ?  1.275  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00       1000  sample              2096.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50       1000  sample              2648.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90       1000  sample              3964.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95       1000  sample              4472.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99       1000  sample              5952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999      1000  sample              6232.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999     1000  sample             19808.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00       1000  sample             69760.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                     10000  sample   3390281   29459.064 ? 12.376  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00      10000  sample             20704.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50      10000  sample             26112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90      10000  sample             39040.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95      10000  sample             44032.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99      10000  sample             58752.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999     10000  sample             58816.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999    10000  sample             74368.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00      10000  sample            123136.000           ns/op

Motivation:

Explain here the context, and why you're making that change.
What is the problem you're trying to solve.

Modification:

Describe the modifications you've done.

Result:

Fixes #.

If there is no issue then describe the changes introduced by this PR.

Motivation:

83a19d5 did make some optimizations which could lead to the situation that retain(...) may throw IllegalReferenceCountException once but may not throw it again when invoked concurrently.

Modification:

- Change code be more robust and more correct in terms of how reference count issues are reported.
- Add unit test.

Result:

Fixes #8563.

Before:

```
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                           1  sample  33113962     648.130 ?  0.290  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00              1  sample                42.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50              1  sample               533.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90              1  sample              1258.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95              1  sample              1518.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99              1  sample              2168.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999             1  sample              3492.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999            1  sample             15296.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00              1  sample            367104.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                          10  sample  37599393     494.185 ?  0.170  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00             10  sample                56.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50             10  sample               427.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90             10  sample               821.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95             10  sample               992.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99             10  sample              1432.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999            10  sample              2472.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999           10  sample              7744.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00             10  sample            166656.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                         100  sample  38506222     514.284 ?  0.120  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00            100  sample               268.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50            100  sample               476.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90            100  sample               662.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95            100  sample               767.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99            100  sample              1052.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999           100  sample              1560.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999          100  sample              9040.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00            100  sample            168704.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                        1000  sample  25227982    2988.675 ?  0.469  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00           1000  sample              2404.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50           1000  sample              2748.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90           1000  sample              3616.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95           1000  sample              4264.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99           1000  sample              6136.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999          1000  sample              6408.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999         1000  sample             20480.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00           1000  sample            218368.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                       10000  sample  20740699   28886.175 ?  4.364  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00          10000  sample             23424.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50          10000  sample             26208.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90          10000  sample             35328.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95          10000  sample             41536.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99          10000  sample             58944.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999         10000  sample             59200.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999        10000  sample             74112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00          10000  sample            178688.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                         1  sample   6692625      55.262 ?  0.097  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00          1  sample                40.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50          1  sample                49.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90          1  sample                71.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95          1  sample                82.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99          1  sample               110.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999         1  sample               110.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999        1  sample              1617.475           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00          1  sample             19168.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                        10  sample   4794123      75.339 ?  0.143  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00         10  sample                62.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50         10  sample                66.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90         10  sample                98.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95         10  sample               115.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99         10  sample               147.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999        10  sample               150.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999       10  sample              2364.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00         10  sample             22048.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                       100  sample   5040621     343.582 ?  0.263  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00        100  sample               228.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50        100  sample               301.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90        100  sample               449.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95        100  sample               510.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99        100  sample               676.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999       100  sample               683.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999      100  sample              8135.502           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00        100  sample             26112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                      1000  sample   4150252    3032.540 ?  1.298  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00       1000  sample              2160.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50       1000  sample              2648.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90       1000  sample              3968.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95       1000  sample              4760.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99       1000  sample              5960.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999      1000  sample              6504.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999     1000  sample             19904.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00       1000  sample             52352.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                     10000  sample   3275578   30489.966 ? 14.050  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00      10000  sample             25952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50      10000  sample             26112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90      10000  sample             41472.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95      10000  sample             47040.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99      10000  sample             58752.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999     10000  sample             59008.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999    10000  sample             75520.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00      10000  sample            125056.000           ns/op
```

After:

```
Benchmark                                                                                           (delay)    Mode       Cnt       Score    Error  Units
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                           1  sample  31059953     690.194 ?  0.257  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00              1  sample                44.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50              1  sample               627.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90              1  sample              1148.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95              1  sample              1362.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99              1  sample              1926.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999             1  sample              3272.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999            1  sample             15792.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00              1  sample            178432.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                          10  sample  28862663     725.757 ?  0.277  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00             10  sample                55.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50             10  sample               652.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90             10  sample              1210.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95             10  sample              1432.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99             10  sample              2000.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999            10  sample              3528.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999           10  sample             15952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00             10  sample            213504.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                         100  sample  31823478     751.129 ?  0.187  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00            100  sample               273.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50            100  sample               699.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90            100  sample              1032.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95            100  sample              1188.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99            100  sample              1618.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999           100  sample              2508.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999          100  sample             15952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00            100  sample            168704.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                        1000  sample  25430205    2967.247 ?  0.474  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00           1000  sample              2396.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50           1000  sample              2700.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90           1000  sample              3628.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95           1000  sample              4248.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99           1000  sample              6056.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999          1000  sample              6464.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999         1000  sample             20640.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00           1000  sample            261632.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended                                       10000  sample  21113138   28377.341 ?  3.951  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.00          10000  sample             23424.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.50          10000  sample             26176.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.90          10000  sample             33600.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.95          10000  sample             37376.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.99          10000  sample             58816.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.999         10000  sample             59072.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p0.9999        10000  sample             73216.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseContended:retainReleaseContended?p1.00          10000  sample            245504.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                         1  sample   5966172      58.417 ?  0.095  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00          1  sample                37.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50          1  sample                52.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90          1  sample                74.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95          1  sample                86.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99          1  sample               117.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999         1  sample               120.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999        1  sample              1630.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00          1  sample             21952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                        10  sample   4535644      75.899 ?  0.165  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00         10  sample                54.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50         10  sample                66.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90         10  sample                98.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95         10  sample               116.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99         10  sample               147.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999        10  sample               200.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999       10  sample              2769.742           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00         10  sample             30528.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                       100  sample   5096864     340.189 ?  0.262  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00        100  sample               228.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50        100  sample               301.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90        100  sample               430.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95        100  sample               508.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99        100  sample               676.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999       100  sample               723.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999      100  sample              9430.224           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00        100  sample             22976.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                      1000  sample   4192970    3001.264 ?  1.275  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00       1000  sample              2096.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50       1000  sample              2648.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90       1000  sample              3964.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95       1000  sample              4472.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99       1000  sample              5952.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999      1000  sample              6232.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999     1000  sample             19808.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00       1000  sample             69760.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended                                     10000  sample   3390281   29459.064 ? 12.376  ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.00      10000  sample             20704.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.50      10000  sample             26112.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.90      10000  sample             39040.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.95      10000  sample             44032.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.99      10000  sample             58752.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.999     10000  sample             58816.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p0.9999    10000  sample             74368.000           ns/op
AbstractReferenceCountedByteBufBenchmark.retainReleaseUncontended:retainReleaseUncontended?p1.00      10000  sample            123136.000           ns/op
```
@normanmaurer

Copy link
Copy Markdown
Member Author

@carl-mastrangelo @merlimat @njhill let me know what you think... it costs a bit of performance but I think it is still not so bad.

@njhill

njhill commented Nov 19, 2018

Copy link
Copy Markdown
Member

@normanmaurer I can see some potential issues with this approach:

  • I think there is still a race condition whereby subsequent calls could succeed following release() returning true:
    • refcount starts at 1. T1 calls retain() and passes the initial check on line 89
    • T2 calls release() which returns true, refcount is now 0
    • T2 calls release() again, refcount is decremented to -1 (does not yet reach line 104)
    • T1 performs addAndGet() which increments refcount to 0
    • T2 sets refcount to 0 on line 104 (it's already 0) and throws IRCE
    • T1 calls addAndGet() which "reverts" refcount to 1, throws IRCE
    • Subsequent retain()/release() will succeed; buffer will be deallocated a second time
  • The semantics change w.r.t. invalid releases - previously release(2) on a refcount of 1 would throw and leave the state unchanged. With this change, it would still throw but result in the refcount ending up as 0 without deallocate() being called, i.e. the buffer ends up in an un-releaseable state and never deallocated

The approach referenced in #8563 (comment) avoids these problems, but likely has a slightly bigger perf hit in high contention case. I can do the benchmarks but didn't want to waste time if it was a non-starter.

@njhill

njhill commented Nov 19, 2018

Copy link
Copy Markdown
Member

Similar example, maybe clearer:

  • Refcount starts at 1. T1 calls retain() and passes initial check
  • T2 calls release() which returns true, refcount now 0
  • T1 performs addAndGet() which increments refcount to 1
  • T2 calls release() again which returns true again

@normanmaurer

Copy link
Copy Markdown
Member Author

@njhill true... benchmark would be nice

@normanmaurer

Copy link
Copy Markdown
Member Author

Closing this one and waiting for @njhill to open a PR based on
0c0e092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants