src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8076112 Sdiff src/java.base/share/classes/java/lang/invoke

src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.util.ArrayList;
  31 import java.util.Arrays;
  32 import java.util.Collections;
  33 import java.util.function.Function;
  34 
  35 import sun.invoke.empty.Empty;
  36 import sun.invoke.util.ValueConversions;
  37 import sun.invoke.util.VerifyType;
  38 import sun.invoke.util.Wrapper;

  39 import sun.reflect.CallerSensitive;
  40 import sun.reflect.Reflection;
  41 import static java.lang.invoke.LambdaForm.*;
  42 import static java.lang.invoke.MethodHandleStatics.*;
  43 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  44 
  45 /**
  46  * Trusted implementation code for MethodHandle.
  47  * @author jrose
  48  */
  49 /*non-public*/ abstract class MethodHandleImpl {
  50     // Do not adjust this except for special platforms:
  51     private static final int MAX_ARITY;
  52     static {
  53         final Object[] values = { 255 };
  54         AccessController.doPrivileged(new PrivilegedAction<>() {
  55             @Override
  56             public Void run() {
  57                 values[0] = Integer.getInteger(MethodHandleImpl.class.getName()+".MAX_ARITY", 255);
  58                 return null;


 692         System.arraycopy(names, inputArgPos, targetArgs, targetArgPos, chunk);
 693         assert(inputArgPos + chunk == collectNamePos);  // use of rest of input args also
 694         names[targetNamePos] = new Name(target, (Object[]) targetArgs);
 695 
 696         LambdaForm form = new LambdaForm("collect", lambdaType.parameterCount(), names);
 697         return SimpleMethodHandle.make(srcType, form);
 698     }
 699 
 700     @LambdaForm.Hidden
 701     static
 702     MethodHandle selectAlternative(boolean testResult, MethodHandle target, MethodHandle fallback) {
 703         if (testResult) {
 704             return target;
 705         } else {
 706             return fallback;
 707         }
 708     }
 709 
 710     // Intrinsified by C2. Counters are used during parsing to calculate branch frequencies.
 711     @LambdaForm.Hidden

 712     static
 713     boolean profileBoolean(boolean result, int[] counters) {
 714         // Profile is int[2] where [0] and [1] correspond to false and true occurrences respectively.
 715         int idx = result ? 1 : 0;
 716         try {
 717             counters[idx] = Math.addExact(counters[idx], 1);
 718         } catch (ArithmeticException e) {
 719             // Avoid continuous overflow by halving the problematic count.
 720             counters[idx] = counters[idx] / 2;
 721         }
 722         return result;
 723     }
 724 
 725     // Intrinsified by C2. Returns true if obj is a compile-time constant.
 726     @LambdaForm.Hidden

 727     static
 728     boolean isCompileConstant(Object obj) {
 729         return false;
 730     }
 731 
 732     static
 733     MethodHandle makeGuardWithTest(MethodHandle test,
 734                                    MethodHandle target,
 735                                    MethodHandle fallback) {
 736         MethodType type = target.type();
 737         assert(test.type().equals(type.changeReturnType(boolean.class)) && fallback.type().equals(type));
 738         MethodType basicType = type.basicType();
 739         LambdaForm form = makeGuardWithTestForm(basicType);
 740         BoundMethodHandle mh;
 741         try {
 742             if (PROFILE_GWT) {
 743                 int[] counts = new int[2];
 744                 mh = (BoundMethodHandle)
 745                         BoundMethodHandle.speciesData_LLLL().constructor().invokeBasic(type, form,
 746                                 (Object) test, (Object) profile(target), (Object) profile(fallback), counts);




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.util.ArrayList;
  31 import java.util.Arrays;
  32 import java.util.Collections;
  33 import java.util.function.Function;
  34 
  35 import sun.invoke.empty.Empty;
  36 import sun.invoke.util.ValueConversions;
  37 import sun.invoke.util.VerifyType;
  38 import sun.invoke.util.Wrapper;
  39 import jdk.internal.HotSpotIntrinsicCandidate;
  40 import sun.reflect.CallerSensitive;
  41 import sun.reflect.Reflection;
  42 import static java.lang.invoke.LambdaForm.*;
  43 import static java.lang.invoke.MethodHandleStatics.*;
  44 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  45 
  46 /**
  47  * Trusted implementation code for MethodHandle.
  48  * @author jrose
  49  */
  50 /*non-public*/ abstract class MethodHandleImpl {
  51     // Do not adjust this except for special platforms:
  52     private static final int MAX_ARITY;
  53     static {
  54         final Object[] values = { 255 };
  55         AccessController.doPrivileged(new PrivilegedAction<>() {
  56             @Override
  57             public Void run() {
  58                 values[0] = Integer.getInteger(MethodHandleImpl.class.getName()+".MAX_ARITY", 255);
  59                 return null;


 693         System.arraycopy(names, inputArgPos, targetArgs, targetArgPos, chunk);
 694         assert(inputArgPos + chunk == collectNamePos);  // use of rest of input args also
 695         names[targetNamePos] = new Name(target, (Object[]) targetArgs);
 696 
 697         LambdaForm form = new LambdaForm("collect", lambdaType.parameterCount(), names);
 698         return SimpleMethodHandle.make(srcType, form);
 699     }
 700 
 701     @LambdaForm.Hidden
 702     static
 703     MethodHandle selectAlternative(boolean testResult, MethodHandle target, MethodHandle fallback) {
 704         if (testResult) {
 705             return target;
 706         } else {
 707             return fallback;
 708         }
 709     }
 710 
 711     // Intrinsified by C2. Counters are used during parsing to calculate branch frequencies.
 712     @LambdaForm.Hidden
 713     @jdk.internal.HotSpotIntrinsicCandidate
 714     static
 715     boolean profileBoolean(boolean result, int[] counters) {
 716         // Profile is int[2] where [0] and [1] correspond to false and true occurrences respectively.
 717         int idx = result ? 1 : 0;
 718         try {
 719             counters[idx] = Math.addExact(counters[idx], 1);
 720         } catch (ArithmeticException e) {
 721             // Avoid continuous overflow by halving the problematic count.
 722             counters[idx] = counters[idx] / 2;
 723         }
 724         return result;
 725     }
 726 
 727     // Intrinsified by C2. Returns true if obj is a compile-time constant.
 728     @LambdaForm.Hidden
 729     @jdk.internal.HotSpotIntrinsicCandidate
 730     static
 731     boolean isCompileConstant(Object obj) {
 732         return false;
 733     }
 734 
 735     static
 736     MethodHandle makeGuardWithTest(MethodHandle test,
 737                                    MethodHandle target,
 738                                    MethodHandle fallback) {
 739         MethodType type = target.type();
 740         assert(test.type().equals(type.changeReturnType(boolean.class)) && fallback.type().equals(type));
 741         MethodType basicType = type.basicType();
 742         LambdaForm form = makeGuardWithTestForm(basicType);
 743         BoundMethodHandle mh;
 744         try {
 745             if (PROFILE_GWT) {
 746                 int[] counts = new int[2];
 747                 mh = (BoundMethodHandle)
 748                         BoundMethodHandle.speciesData_LLLL().constructor().invokeBasic(type, form,
 749                                 (Object) test, (Object) profile(target), (Object) profile(fallback), counts);


src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File