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

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

    Details

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

      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.

          Issue Links

            Activity

            Hide
            martin Martin Buchholz added a comment -
            I'll make this part of jsr166 jdk9 integration Wave 2.
            Show
            martin Martin Buchholz added a comment - I'll make this part of jsr166 jdk9 integration Wave 2.
            Hide
            shade Aleksey Shipilev added a comment -
            Thanks Martin! I wonder if we should commit this patch separately, though, to ease the (possible) backport to 8u.
            Show
            shade Aleksey Shipilev added a comment - Thanks Martin! I wonder if we should commit this patch separately, though, to ease the (possible) backport to 8u.
            Hide
            martin Martin Buchholz added a comment -
            I do plan to split the integration up into many pieces. This change should be fairly self-contained. We'll see.
            Show
            martin Martin Buchholz added a comment - I do plan to split the integration up into many pieces. This change should be fairly self-contained. We'll see.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/e1a21828acc1
            User: martin
            Date: 2015-11-26 03:44:33 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/e1a21828acc1 User: martin Date: 2015-11-26 03:44:33 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/e1a21828acc1
            User: lana
            Date: 2015-12-10 00:27:01 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/e1a21828acc1 User: lana Date: 2015-12-10 00:27:01 +0000

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: