Atomic*FieldUpdaters should use Class.isInstance instead of direct class check

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: 9
    • Component/s: core-libs

        There is an anecdotal evidence that replacing direct class checks with Class.isInstance helps when "obj" has subclasses, and "obj.getClass() != tclass" could not be optimized. fullCheck() does Class.isInstance anyway, so it seems functionally correct to use it in the "quick" checks.

                public final int get(T obj) {
                    if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
                    return U.getIntVolatile(obj, offset);
                }

                private void fullCheck(T obj) {
                    if (!tclass.isInstance(obj))
                        throw new ClassCastException();
                    if (cclass != null)
                        ensureProtectedAccess(obj);
                }

        This should be checked after JDK-8140483 lands. C1 and C2 may disagree which pattern is faster.

              Assignee:
              Martin Buchholz
              Reporter:
              Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: