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 java.util.Arrays;
29 import static java.lang.invoke.LambdaForm.*;
30 import static java.lang.invoke.LambdaForm.Kind.*;
31 import static java.lang.invoke.MethodHandleStatics.*;
32
33 /**
34 * A method handle whose invocation behavior is determined by a target.
35 * The delegating MH itself can hold extra "intentions" beyond the simple behavior.
36 * @author jrose
37 */
38 /*non-public*/
39 abstract class DelegatingMethodHandle extends MethodHandle {
40 protected DelegatingMethodHandle(MethodHandle target) {
41 this(target.type(), target);
42 }
43
44 protected DelegatingMethodHandle(MethodType type, MethodHandle target) {
45 super(type, chooseDelegatingForm(target));
46 }
47
48 protected DelegatingMethodHandle(MethodType type, LambdaForm form) {
49 super(type, form);
50 }
141 names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs);
142 }
143 form = new LambdaForm(ARG_LIMIT, names, forceInline, kind);
144 if (!customized) {
145 form = mtype.form().setCachedLambdaForm(whichCache, form);
146 }
147 return form;
148 }
149
150 private static Kind whichKind(int whichCache) {
151 switch(whichCache) {
152 case MethodTypeForm.LF_REBIND: return BOUND_REINVOKER;
153 case MethodTypeForm.LF_DELEGATE: return DELEGATE;
154 default: return REINVOKER;
155 }
156 }
157
158 static final NamedFunction NF_getTarget;
159 static {
160 try {
161 NF_getTarget = new NamedFunction(DelegatingMethodHandle.class
162 .getDeclaredMethod("getTarget"));
163 } catch (ReflectiveOperationException ex) {
164 throw newInternalError(ex);
165 }
166 // The Holder class will contain pre-generated DelegatingMethodHandles resolved
167 // speculatively using MemberName.getFactory().resolveOrNull. However, that
168 // doesn't initialize the class, which subtly breaks inlining etc. By forcing
169 // initialization of the Holder class we avoid these issues.
170 UNSAFE.ensureClassInitialized(Holder.class);
171 }
172
173 /* Placeholder class for DelegatingMethodHandles generated ahead of time */
174 final class Holder {}
175 }
|
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 java.util.Arrays;
29 import static java.lang.invoke.LambdaForm.*;
30 import static java.lang.invoke.LambdaForm.Kind.*;
31 import static java.lang.invoke.MethodHandleNatives.Constants.REF_invokeVirtual;
32 import static java.lang.invoke.MethodHandleStatics.*;
33
34 /**
35 * A method handle whose invocation behavior is determined by a target.
36 * The delegating MH itself can hold extra "intentions" beyond the simple behavior.
37 * @author jrose
38 */
39 /*non-public*/
40 abstract class DelegatingMethodHandle extends MethodHandle {
41 protected DelegatingMethodHandle(MethodHandle target) {
42 this(target.type(), target);
43 }
44
45 protected DelegatingMethodHandle(MethodType type, MethodHandle target) {
46 super(type, chooseDelegatingForm(target));
47 }
48
49 protected DelegatingMethodHandle(MethodType type, LambdaForm form) {
50 super(type, form);
51 }
142 names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs);
143 }
144 form = new LambdaForm(ARG_LIMIT, names, forceInline, kind);
145 if (!customized) {
146 form = mtype.form().setCachedLambdaForm(whichCache, form);
147 }
148 return form;
149 }
150
151 private static Kind whichKind(int whichCache) {
152 switch(whichCache) {
153 case MethodTypeForm.LF_REBIND: return BOUND_REINVOKER;
154 case MethodTypeForm.LF_DELEGATE: return DELEGATE;
155 default: return REINVOKER;
156 }
157 }
158
159 static final NamedFunction NF_getTarget;
160 static {
161 try {
162 MemberName member = new MemberName(DelegatingMethodHandle.class, "getTarget",
163 MethodType.methodType(MethodHandle.class), REF_invokeVirtual);
164 NF_getTarget = new NamedFunction(
165 MemberName.getFactory()
166 .resolveOrFail(REF_invokeVirtual, member, DelegatingMethodHandle.class, NoSuchMethodException.class));
167 } catch (ReflectiveOperationException ex) {
168 throw newInternalError(ex);
169 }
170 // The Holder class will contain pre-generated DelegatingMethodHandles resolved
171 // speculatively using MemberName.getFactory().resolveOrNull. However, that
172 // doesn't initialize the class, which subtly breaks inlining etc. By forcing
173 // initialization of the Holder class we avoid these issues.
174 UNSAFE.ensureClassInitialized(Holder.class);
175 }
176
177 /* Placeholder class for DelegatingMethodHandles generated ahead of time */
178 final class Holder {}
179 }
|