From 438dec2d0ded101518043fdc222ad1669b6c0aff Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Wed, 3 Jun 2015 12:54:08 -0700 Subject: [PATCH 1/2] 8081778: Use Intel x64 CPU instructions for RSA acceleration Add intrinsics for BigInteger squareToLen and mulAdd methods. Reviewed-by: kvn, jrose, aph, ascarpino, fweimer --- .../share/classes/java/math/BigInteger.java | 66 ++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/math/BigInteger.java b/jdk/src/java.base/share/classes/java/math/BigInteger.java index 3690bea06b4..3b3cbf50739 100644 --- a/jdk/src/java.base/share/classes/java/math/BigInteger.java +++ b/jdk/src/java.base/share/classes/java/math/BigInteger.java @@ -1963,6 +1963,43 @@ public class BigInteger extends Number implements Comparable { * int array z. The contents of x are not changed. */ private static final int[] squareToLen(int[] x, int len, int[] z) { + int zlen = len << 1; + if (z == null || z.length < zlen) + z = new int[zlen]; + + // Execute checks before calling intrinsified method. + implSquareToLenChecks(x, len, z, zlen); + return implSquareToLen(x, len, z, zlen); + } + + /** + * Parameters validation. + */ + private static void implSquareToLenChecks(int[] x, int len, int[] z, int zlen) throws RuntimeException { + if (len < 1) { + throw new IllegalArgumentException("invalid input length: " + len); + } + if (len > x.length) { + throw new IllegalArgumentException("input length out of bound: " + + len + " > " + x.length); + } + if (len * 2 > z.length) { + throw new IllegalArgumentException("input length out of bound: " + + (len * 2) + " > " + z.length); + } + if (zlen < 1) { + throw new IllegalArgumentException("invalid input length: " + zlen); + } + if (zlen > z.length) { + throw new IllegalArgumentException("input length out of bound: " + + len + " > " + z.length); + } + } + + /** + * Java Runtime may use intrinsic for this method. + */ + private static final int[] implSquareToLen(int[] x, int len, int[] z, int zlen) { /* * The algorithm used here is adapted from Colin Plumb's C library. * Technique: Consider the partial products in the multiplication @@ -1997,9 +2034,6 @@ public class BigInteger extends Number implements Comparable { * again. The low bit is simply a copy of the low bit of the * input, so it doesn't need special care. */ - int zlen = len << 1; - if (z == null || z.length < zlen) - z = new int[zlen]; // Store the squares, right shifted one bit (i.e., divided by 2) int lastProductLowWord = 0; @@ -2857,6 +2891,32 @@ public class BigInteger extends Number implements Comparable { * 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 new IllegalArgumentException("input length is out of bound: " + len + " > " + in.length); + } + if (offset < 0) { + throw new IllegalArgumentException("input offset is invalid: " + offset); + } + if (offset > (out.length - 1)) { + throw new IllegalArgumentException("input offset is out of bound: " + offset + " > " + (out.length - 1)); + } + if (len > (out.length - offset)) { + throw new IllegalArgumentException("input len is out of bound: " + len + " > " + (out.length - offset)); + } + } + + /** + * Java Runtime may use intrinsic for this method. + */ + private static int implMulAdd(int[] out, int[] in, int offset, int len, int k) { long kLong = k & LONG_MASK; long carry = 0; From 8d568927076389d3c3c74299a5bf72ba9b3871a6 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Thu, 11 Jun 2015 14:20:01 +0300 Subject: [PATCH 2/2] 8074551: GWT can be marked non-compilable due to deopt count pollution Reviewed-by: kvn --- .../java/lang/invoke/InjectedProfile.java | 37 +++++++++++++++++++ .../lang/invoke/InvokerBytecodeGenerator.java | 5 +++ 2 files changed, 42 insertions(+) create mode 100644 jdk/src/java.base/share/classes/java/lang/invoke/InjectedProfile.java diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/InjectedProfile.java b/jdk/src/java.base/share/classes/java/lang/invoke/InjectedProfile.java new file mode 100644 index 00000000000..2680e57543b --- /dev/null +++ b/jdk/src/java.base/share/classes/java/lang/invoke/InjectedProfile.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang.invoke; + +import java.lang.annotation.*; + +/** + * Internal marker for some methods in the JSR 292 implementation. + */ +/*non-public*/ +@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) +@Retention(RetentionPolicy.RUNTIME) +@interface InjectedProfile { +} diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java index 225b998efb3..6698d9da36e 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java @@ -669,6 +669,11 @@ class InvokerBytecodeGenerator { switch (intr) { case SELECT_ALTERNATIVE: assert isSelectAlternative(i); + if (PROFILE_GWT) { + assert(name.arguments[0] instanceof Name && + nameRefersTo((Name)name.arguments[0], MethodHandleImpl.class, "profileBoolean")); + mv.visitAnnotation("Ljava/lang/invoke/InjectedProfile;", true); + } onStack = emitSelectAlternative(name, lambdaForm.names[i+1]); i++; // skip MH.invokeBasic of the selectAlternative result continue;