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 java.security.AccessController;
29 import java.security.PrivilegedAction;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.function.Function;
35
36 import jdk.internal.reflect.CallerSensitive;
37 import jdk.internal.reflect.Reflection;
38 import jdk.internal.vm.annotation.Stable;
39 import sun.invoke.empty.Empty;
40 import sun.invoke.util.ValueConversions;
41 import sun.invoke.util.VerifyType;
42 import sun.invoke.util.Wrapper;
43 import static java.lang.invoke.LambdaForm.*;
44 import static java.lang.invoke.MethodHandleStatics.*;
45 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
46
47 /**
1875 }
1876 }
1877
1878 // Indexes into constant method handles:
1879 static final int
1880 MH_cast = 0,
1881 MH_selectAlternative = 1,
1882 MH_copyAsPrimitiveArray = 2,
1883 MH_fillNewTypedArray = 3,
1884 MH_fillNewArray = 4,
1885 MH_arrayIdentity = 5,
1886 MH_looper = 6,
1887 MH_countedLoopPred = 7,
1888 MH_countedLoopStep = 8,
1889 MH_iteratePred = 9,
1890 MH_initIterator = 10,
1891 MH_iterateNext = 11,
1892 MH_tryFinallyExec = 12,
1893 MH_tryFinallyVoidExec = 13,
1894 MH_decrementCounter = 14,
1895 MH_LIMIT = 15;
1896
1897 static MethodHandle getConstantHandle(int idx) {
1898 MethodHandle handle = HANDLES[idx];
1899 if (handle != null) {
1900 return handle;
1901 }
1902 return setCachedHandle(idx, makeConstantHandle(idx));
1903 }
1904
1905 private static synchronized MethodHandle setCachedHandle(int idx, final MethodHandle method) {
1906 // Simulate a CAS, to avoid racy duplication of results.
1907 MethodHandle prev = HANDLES[idx];
1908 if (prev != null) {
1909 return prev;
1910 }
1911 HANDLES[idx] = method;
1912 return method;
1913 }
1914
1915 // Local constant method handles:
1948 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "countedLoopStep",
1949 MethodType.methodType(int.class, int.class, int.class));
1950 case MH_iteratePred:
1951 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iteratePredicate",
1952 MethodType.methodType(boolean.class, Iterator.class));
1953 case MH_initIterator:
1954 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "initIterator",
1955 MethodType.methodType(Iterator.class, Iterable.class));
1956 case MH_iterateNext:
1957 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iterateNext",
1958 MethodType.methodType(Object.class, Iterator.class));
1959 case MH_tryFinallyExec:
1960 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "tryFinallyExecutor",
1961 MethodType.methodType(Object.class, MethodHandle.class, MethodHandle.class, Object[].class));
1962 case MH_tryFinallyVoidExec:
1963 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "tryFinallyVoidExecutor",
1964 MethodType.methodType(void.class, MethodHandle.class, MethodHandle.class, Object[].class));
1965 case MH_decrementCounter:
1966 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "decrementCounter",
1967 MethodType.methodType(int.class, int.class));
1968 }
1969 } catch (ReflectiveOperationException ex) {
1970 throw newInternalError(ex);
1971 }
1972 throw newInternalError("Unknown function index: " + idx);
1973 }
1974 }
|
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 java.lang.reflect.Array;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.function.Function;
36
37 import jdk.internal.reflect.CallerSensitive;
38 import jdk.internal.reflect.Reflection;
39 import jdk.internal.vm.annotation.Stable;
40 import sun.invoke.empty.Empty;
41 import sun.invoke.util.ValueConversions;
42 import sun.invoke.util.VerifyType;
43 import sun.invoke.util.Wrapper;
44 import static java.lang.invoke.LambdaForm.*;
45 import static java.lang.invoke.MethodHandleStatics.*;
46 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
47
48 /**
1876 }
1877 }
1878
1879 // Indexes into constant method handles:
1880 static final int
1881 MH_cast = 0,
1882 MH_selectAlternative = 1,
1883 MH_copyAsPrimitiveArray = 2,
1884 MH_fillNewTypedArray = 3,
1885 MH_fillNewArray = 4,
1886 MH_arrayIdentity = 5,
1887 MH_looper = 6,
1888 MH_countedLoopPred = 7,
1889 MH_countedLoopStep = 8,
1890 MH_iteratePred = 9,
1891 MH_initIterator = 10,
1892 MH_iterateNext = 11,
1893 MH_tryFinallyExec = 12,
1894 MH_tryFinallyVoidExec = 13,
1895 MH_decrementCounter = 14,
1896 MH_Array_newInstance = 15,
1897 MH_LIMIT = 16;
1898
1899 static MethodHandle getConstantHandle(int idx) {
1900 MethodHandle handle = HANDLES[idx];
1901 if (handle != null) {
1902 return handle;
1903 }
1904 return setCachedHandle(idx, makeConstantHandle(idx));
1905 }
1906
1907 private static synchronized MethodHandle setCachedHandle(int idx, final MethodHandle method) {
1908 // Simulate a CAS, to avoid racy duplication of results.
1909 MethodHandle prev = HANDLES[idx];
1910 if (prev != null) {
1911 return prev;
1912 }
1913 HANDLES[idx] = method;
1914 return method;
1915 }
1916
1917 // Local constant method handles:
1950 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "countedLoopStep",
1951 MethodType.methodType(int.class, int.class, int.class));
1952 case MH_iteratePred:
1953 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iteratePredicate",
1954 MethodType.methodType(boolean.class, Iterator.class));
1955 case MH_initIterator:
1956 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "initIterator",
1957 MethodType.methodType(Iterator.class, Iterable.class));
1958 case MH_iterateNext:
1959 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iterateNext",
1960 MethodType.methodType(Object.class, Iterator.class));
1961 case MH_tryFinallyExec:
1962 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "tryFinallyExecutor",
1963 MethodType.methodType(Object.class, MethodHandle.class, MethodHandle.class, Object[].class));
1964 case MH_tryFinallyVoidExec:
1965 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "tryFinallyVoidExecutor",
1966 MethodType.methodType(void.class, MethodHandle.class, MethodHandle.class, Object[].class));
1967 case MH_decrementCounter:
1968 return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "decrementCounter",
1969 MethodType.methodType(int.class, int.class));
1970 case MH_Array_newInstance:
1971 return IMPL_LOOKUP.findStatic(Array.class, "newInstance",
1972 MethodType.methodType(Object.class, Class.class, int.class));
1973 }
1974 } catch (ReflectiveOperationException ex) {
1975 throw newInternalError(ex);
1976 }
1977 throw newInternalError("Unknown function index: " + idx);
1978 }
1979 }
|