Linkage.java 4.8 KB
Newer Older
1
/*
O
ohair 已提交
2
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3 4 5 6
 * 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
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 12 13 14 15 16 17 18 19 20
 *
 * 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.
 *
21 22 23
 * 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.
24 25 26 27
 */

package java.dyn;

28
import sun.dyn.util.VerifyAccess;
29
import java.dyn.MethodHandles.Lookup;
30 31 32
import sun.reflect.Reflection;

/**
33 34 35
 * <em>CLASS WILL BE REMOVED FOR PFD:</em>
 * Static routines for controlling invokedynamic behavior.
 * Replaced by non-static APIs.
36
 * @author John Rose, JSR 292 EG
37
 * @deprecated This class will be removed in the Public Final Draft.
38 39 40 41 42
 */
public class Linkage {
    private Linkage() {}  // do not instantiate

    /**
43
     * <em>METHOD WILL BE REMOVED FOR PFD:</em>
44 45
     * Register a <em>bootstrap method</em> to use when linking dynamic call sites within
     * a given caller class.
46
     * @deprecated Use @{@link BootstrapMethod} annotations instead.
47 48
     */
    public static
49
    void registerBootstrapMethod(Class callerClass, MethodHandle bootstrapMethod) {
50
        Class callc = Reflection.getCallerClass(2);
51 52
        if (callc != null && !VerifyAccess.isSamePackage(callerClass, callc))
            throw new IllegalArgumentException("cannot set bootstrap method on "+callerClass);
53
        MethodHandleImpl.registerBootstrap(callerClass, bootstrapMethod);
54 55 56
    }

    /**
57
     * <em>METHOD WILL BE REMOVED FOR PFD:</em>
58
     * Simplified version of {@code registerBootstrapMethod} for self-registration,
59
     * to be called from a static initializer.
60
     * @deprecated Use @{@link BootstrapMethod} annotations instead.
61 62 63
     */
    public static
    void registerBootstrapMethod(Class<?> runtime, String name) {
64 65
        Class callerClass = Reflection.getCallerClass(2);
        registerBootstrapMethodLookup(callerClass, runtime, name);
66 67 68
    }

    /**
69
     * <em>METHOD WILL BE REMOVED FOR PFD:</em>
70
     * Simplified version of {@code registerBootstrapMethod} for self-registration,
71
     * @deprecated Use @{@link BootstrapMethod} annotations instead.
72 73 74
     */
    public static
    void registerBootstrapMethod(String name) {
75 76 77 78 79 80
        Class callerClass = Reflection.getCallerClass(2);
        registerBootstrapMethodLookup(callerClass, callerClass, name);
    }

    private static
    void registerBootstrapMethodLookup(Class<?> callerClass, Class<?> runtime, String name) {
81
        Lookup lookup = new Lookup(callerClass);
82 83
        MethodHandle bootstrapMethod;
        try {
84
            bootstrapMethod = lookup.findStatic(runtime, name, BOOTSTRAP_METHOD_TYPE);
85
        } catch (ReflectiveOperationException ex) {
86
            throw new IllegalArgumentException("no such bootstrap method in "+runtime+": "+name, ex);
87
        }
88
        MethodHandleImpl.registerBootstrap(callerClass, bootstrapMethod);
89 90
    }

91
    private static final MethodType BOOTSTRAP_METHOD_TYPE
92 93
            = MethodType.methodType(CallSite.class,
                                    Class.class, String.class, MethodType.class);
94 95

    /**
96
     * <em>METHOD WILL BE REMOVED FOR PFD:</em>
97
     * Invalidate all <code>invokedynamic</code> call sites everywhere.
98 99 100
     * @deprecated Use {@linkplain MutableCallSite#setTarget call site target setting},
     * {@link MutableCallSite#syncAll call site update pushing},
     * and {@link SwitchPoint#guardWithTest target switching} instead.
101 102 103
     */
    public static
    Object invalidateAll() {
104
        throw new UnsupportedOperationException();
105 106 107
    }

    /**
108
     * <em>METHOD WILL BE REMOVED FOR PFD:</em>
109
     * Invalidate all {@code invokedynamic} call sites in the bytecodes
110
     * of any methods of the given class.
111 112 113
     * @deprecated Use {@linkplain MutableCallSite#setTarget call site target setting},
     * {@link MutableCallSite#syncAll call site update pushing},
     * and {@link SwitchPoint#guardWithTest target switching} instead.
114 115 116
     */
    public static
    Object invalidateCallerClass(Class<?> callerClass) {
117
        throw new UnsupportedOperationException();
118 119
    }
}