1 /*
2  * Copyright (c) 2008, 2012, 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
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 jdk.internal.vm.annotation.Stable;
29
30 import static java.lang.invoke.LambdaForm.BasicType.*;
31 import static java.lang.invoke.MethodHandleStatics.*;
32
33 /**
34  * A method handle whose behavior is determined only by its LambdaForm.
35  * @author jrose
36  */

37 final class SimpleMethodHandle extends BoundMethodHandle {
38
39     private SimpleMethodHandle(MethodType type, LambdaForm form) {
40         super(type, form);
41     }
42
43     /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) {
44         return new SimpleMethodHandle(type, form);
45     }
46
47     /*non-public*/ static @Stable BoundMethodHandle.SpeciesData BMH_SPECIES;
48
49     @Override
50     /*non-public*/ BoundMethodHandle.SpeciesData speciesData() {
51             return BMH_SPECIES;
52     }
53
54     @Override
55     /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
56         return make(mt, lf);
57     }
58
59     @Override
60     String internalProperties() {
61         return "\n& Class="+getClass().getSimpleName();
62     }
63
64     @Override
65     /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
66         return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
67     }
68     @Override
69     /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
70         try {
71             return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
72         } catch (Throwable ex) {
73             throw uncaughtException(ex);
74         }
75     }
76     @Override
77     /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
78         try {
79             return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
80         } catch (Throwable ex) {
81             throw uncaughtException(ex);
82         }
83     }
84     @Override
85     /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
86         try {
87             return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
88         } catch (Throwable ex) {
89             throw uncaughtException(ex);
90         }
91     }
92     @Override
93     /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
94         try {
95             return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
96         } catch (Throwable ex) {
97             throw uncaughtException(ex);
98         }
99     }
100 }
101