why don't most JVM gcs use refcounts?

前端 未结 2 1047
生来不讨喜
生来不讨喜 2021-01-11 23:18

Why don\'t they need them, and if someone decided to implement a VM that used them, what problems might they face?

2条回答
  •  长发绾君心
    2021-01-12 00:05

    1. Counting references must be done outside the object.
    2. Counting references is slow. Even slower to deal w/ cyclic references but that's not impossible. Still slow.
    3. Counting references is actually very slow since it must use CAS + loop
    4. Not-Counting references is easier to implement and it's faster, esp. with some OS memory page tricks.
    5. Reference counting can be removed altogether by escape analysis, provided the object doesn't escape.

提交回复
热议问题