Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8140587

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

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 9
    • 9
    • core-libs

    Backports

      Description

        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.

        Attachments

          Issue Links

            Activity

              People

                martin Martin Buchholz
                shade Aleksey Shipilev
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: