Incorrect cmpxchg usage in MetaspaceGC::inc_capacity_until_GC

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 11
    • Affects Version/s: 11
    • Component/s: hotspot
    • None
    • gc
    • b16
    • generic
    • generic

        MetaspaceGC::inc_capacity_until_GC presently has

        2420 size_t capacity_until_GC = _capacity_until_GC;
        2421 size_t new_value = capacity_until_GC + v;
          ...
        2428 size_t expected = _capacity_until_GC;
        2429 size_t actual = Atomic::cmpxchg(new_value, &_capacity_until_GC, expected);

        If a different thread were to modify _capacity_until_GC between line 2420 and 2428, that modification could be quietly lost.

        The refetch of _capacity_until_GC at line 2428 is the culprit. It should be removed, and all uses of "expected" should be replaced with "capacity_until_GC" (which should perhaps be renamed "old_value").

              Assignee:
              Thomas Schatzl
              Reporter:
              Kim Barrett
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: