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

Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Resolved In Build:
      b74
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Intrinsics are high optimized (mostly hand written assembler) code which are used instead of normal JIT compiled code.

        There is need to indicate java methods which are intrinsified by JVM:
         - If such methods are modified corresponding code in JVM should also be modified if needed (we had cases in the past when intrinsics stop working and we get performance regression because signature of java method was modified without notifying Hotspot group).
         - Intrinsics assume that all validation checks are done by java code. We want all calls to intrinsified methods precede by clearly related parameter validation function.
         - Intrinsified java method preferably should be 'private' (which is effectively 'final').
         - Intrinsified java method preferably should be 'static' (to discourage coupling of JVM to JDK-defined object layouts).
         - JVM can add restriction to intrinsify only annotated methods to enforce annotation and presence of validation checks in java code.

        For future maintainers, the above rules should be explained clearly in the javadoc for @HotSpotIntrinsicCandidate.

        Here are suggested changes:

        http://cr.openjdk.java.net/~kvn/AnnotationIntrinsic/webrev.jdk/
        http://cr.openjdk.java.net/~kvn/AnnotationIntrinsic/webrev.hotspot/

        The example of usage:

        diff -r dd8d2a336f90 src/java.base/share/classes/java/math/BigInteger.java
        --- a/src/java.base/share/classes/java/math/BigInteger.java Fri Mar 20 11:42:31 2015 -0700
        +++ b/src/java.base/share/classes/java/math/BigInteger.java Thu Mar 26 12:23:06 2015 -0700
        @@ -2857,6 +2857,33 @@
              * Multiply an array by one word k and add to result, return the carry
              */
             static int mulAdd(int[] out, int[] in, int offset, int len, int k) {
        + implMulAddCheck(out, in, offset, len, k);
        + return implMulAdd(out, in, offset, len, k);
        + }
        +
        + /**
        + * Parameters validation.
        + */
        + private static void implMulAddCheck(int[] out, int[] in, int offset, int len, int k) {
        + if (len > in.length) {
        + throw newIllegalArgumentException("input length is out of bound: " + len + " > " + in.length);
        + }
        + if (offset < 0) {
        + throw newIllegalArgumentException("input offset is invalid: " + offset);
        + }
        + if (offset > (out.length - 1)) {
        + throw newIllegalArgumentException("input offset is out of bound: " + offset + " > " + (out.length - 1));
        + }
        + if (len > (out.length - offset)) {
        + throw newIllegalArgumentException("input len is out of bound: " + len + " > " + (out.length - offset));
        + }
        + }
        +
        + /**
        + * Java Runtime may use intrinsic for this method.
        + */
        + @HotSpotIntrinsicCandidate
        + private static int implMulAdd(int[] out, int[] in, int offset, int len, int k) {
                 long kLong = k & LONG_MASK;
                 long carry = 0;
         

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  zmajo Zoltan Majo (Inactive)
                  Reporter:
                  kvn Vladimir Kozlov
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  13 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: