hotspot/test/compiler/jsr292/patches/java.base/java/lang/invoke/MethodHandleHelper.java
changeset 36508 5f9eee6b383b
child 43885 209f829f05ef
child 43943 e2fdae30bbc1
equal deleted inserted replaced
36507:c80f6ecb0bb3 36508:5f9eee6b383b
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package java.lang.invoke;
       
    25 
       
    26 import java.lang.invoke.MethodHandles.Lookup;
       
    27 import jdk.internal.vm.annotation.DontInline;
       
    28 import jdk.internal.vm.annotation.ForceInline;
       
    29 /**
       
    30  * Helper class to inject into java.lang.invoke that provides access to
       
    31  * package-private methods in this package.
       
    32  */
       
    33 
       
    34 public class MethodHandleHelper {
       
    35 
       
    36     private MethodHandleHelper() { }
       
    37 
       
    38     public static final Lookup IMPL_LOOKUP = Lookup.IMPL_LOOKUP;
       
    39     public static final Class<?> MHN_CALL_SITE_CONTEXT_CLASS
       
    40             = MethodHandleNatives.CallSiteContext.class;
       
    41 
       
    42     public static void customize(MethodHandle mh) {
       
    43         mh.customize();
       
    44     }
       
    45 
       
    46     @ForceInline
       
    47     public static Object invokeBasicL(MethodHandle mh) throws Throwable {
       
    48         return mh.invokeBasic();
       
    49     }
       
    50 
       
    51     @ForceInline
       
    52     public static int invokeBasicI(MethodHandle mh) throws Throwable {
       
    53         return (int) mh.invokeBasic();
       
    54     }
       
    55 
       
    56     public static MethodHandle varargsArray(int nargs) {
       
    57         return MethodHandleImpl.varargsArray(nargs);
       
    58     }
       
    59 
       
    60     public static MethodHandle varargsArray(Class<?> arrayType, int nargs) {
       
    61         return MethodHandleImpl.varargsArray(arrayType, nargs);
       
    62     }
       
    63 
       
    64     public static LambdaForm getLambdaForm(MethodHandle mh) {
       
    65         return mh.form;
       
    66     }
       
    67 
       
    68     public static class NonInlinedReinvoker extends DelegatingMethodHandle {
       
    69         private final MethodHandle target;
       
    70 
       
    71         private NonInlinedReinvoker(MethodHandle target, LambdaForm lf) {
       
    72             super(target.type(), lf);
       
    73             this.target = target;
       
    74         }
       
    75         @Override
       
    76         public MethodHandle getTarget() {
       
    77             return target;
       
    78         }
       
    79 
       
    80         @Override
       
    81         public MethodHandle asTypeUncached(MethodType newType) {
       
    82             return asTypeCache = target.asType(newType);
       
    83         }
       
    84 
       
    85         public static MethodHandle make(MethodHandle target) {
       
    86             LambdaForm lform = DelegatingMethodHandle.makeReinvokerForm(
       
    87                     target, -1, DelegatingMethodHandle.class, "reinvoker.dontInline",
       
    88                 /*forceInline=*/false, DelegatingMethodHandle.NF_getTarget, null);
       
    89             return new NonInlinedReinvoker(target, lform);
       
    90         }
       
    91     }
       
    92 }