1 /*
2 * Copyright (c) 2008, 2022, 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
857 NF_checkCast = 7,
858 NF_allocateInstance = 8,
859 NF_constructorMethod = 9,
860 NF_UNSAFE = 10,
861 NF_checkReceiver = 11,
862 NF_LIMIT = 12;
863
864 private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
865
866 private static NamedFunction getFunction(byte func) {
867 NamedFunction nf = NFS[func];
868 if (nf != null) {
869 return nf;
870 }
871 // Each nf must be statically invocable or we get tied up in our bootstraps.
872 nf = NFS[func] = createFunction(func);
873 assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
874 return nf;
875 }
876
877 private static final MethodType OBJ_OBJ_TYPE = MethodType.methodType(Object.class, Object.class);
878
879 private static final MethodType LONG_OBJ_TYPE = MethodType.methodType(long.class, Object.class);
880
881 private static NamedFunction createFunction(byte func) {
882 try {
883 switch (func) {
884 case NF_internalMemberName:
885 return getNamedFunction("internalMemberName", OBJ_OBJ_TYPE);
886 case NF_internalMemberNameEnsureInit:
887 return getNamedFunction("internalMemberNameEnsureInit", OBJ_OBJ_TYPE);
888 case NF_ensureInitialized:
889 return getNamedFunction("ensureInitialized", MethodType.methodType(void.class, Object.class));
890 case NF_fieldOffset:
891 return getNamedFunction("fieldOffset", LONG_OBJ_TYPE);
892 case NF_checkBase:
893 return getNamedFunction("checkBase", OBJ_OBJ_TYPE);
894 case NF_staticBase:
895 return getNamedFunction("staticBase", OBJ_OBJ_TYPE);
896 case NF_staticOffset:
897 return getNamedFunction("staticOffset", LONG_OBJ_TYPE);
898 case NF_checkCast:
899 return getNamedFunction("checkCast", MethodType.methodType(Object.class, Object.class, Object.class));
900 case NF_allocateInstance:
901 return getNamedFunction("allocateInstance", OBJ_OBJ_TYPE);
902 case NF_constructorMethod:
903 return getNamedFunction("constructorMethod", OBJ_OBJ_TYPE);
904 case NF_UNSAFE:
905 MemberName member = new MemberName(MethodHandleStatics.class, "UNSAFE", Unsafe.class, REF_getStatic);
906 return new NamedFunction(
907 MemberName.getFactory().resolveOrFail(REF_getStatic, member,
908 DirectMethodHandle.class, LM_TRUSTED,
909 NoSuchFieldException.class));
910 case NF_checkReceiver:
911 member = new MemberName(DirectMethodHandle.class, "checkReceiver", OBJ_OBJ_TYPE, REF_invokeVirtual);
912 return new NamedFunction(
913 MemberName.getFactory().resolveOrFail(REF_invokeVirtual, member,
914 DirectMethodHandle.class, LM_TRUSTED,
915 NoSuchMethodException.class));
916 default:
917 throw newInternalError("Unknown function: " + func);
918 }
919 } catch (ReflectiveOperationException ex) {
920 throw newInternalError(ex);
921 }
922 }
923
924 private static NamedFunction getNamedFunction(String name, MethodType type)
925 throws ReflectiveOperationException
926 {
927 MemberName member = new MemberName(DirectMethodHandle.class, name, type, REF_invokeStatic);
928 return new NamedFunction(
929 MemberName.getFactory().resolveOrFail(REF_invokeStatic, member,
930 DirectMethodHandle.class, LM_TRUSTED,
931 NoSuchMethodException.class));
|
1 /*
2 * Copyright (c) 2008, 2024, 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
857 NF_checkCast = 7,
858 NF_allocateInstance = 8,
859 NF_constructorMethod = 9,
860 NF_UNSAFE = 10,
861 NF_checkReceiver = 11,
862 NF_LIMIT = 12;
863
864 private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
865
866 private static NamedFunction getFunction(byte func) {
867 NamedFunction nf = NFS[func];
868 if (nf != null) {
869 return nf;
870 }
871 // Each nf must be statically invocable or we get tied up in our bootstraps.
872 nf = NFS[func] = createFunction(func);
873 assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
874 return nf;
875 }
876
877 static class AOTHolder {
878 private static final MethodType OBJ_OBJ_TYPE = MethodType.methodType(Object.class, Object.class);
879 private static final MethodType LONG_OBJ_TYPE = MethodType.methodType(long.class, Object.class);
880 }
881
882 private static NamedFunction createFunction(byte func) {
883 try {
884 switch (func) {
885 case NF_internalMemberName:
886 return getNamedFunction("internalMemberName", AOTHolder.OBJ_OBJ_TYPE);
887 case NF_internalMemberNameEnsureInit:
888 return getNamedFunction("internalMemberNameEnsureInit", AOTHolder.OBJ_OBJ_TYPE);
889 case NF_ensureInitialized:
890 return getNamedFunction("ensureInitialized", MethodType.methodType(void.class, Object.class));
891 case NF_fieldOffset:
892 return getNamedFunction("fieldOffset", AOTHolder.LONG_OBJ_TYPE);
893 case NF_checkBase:
894 return getNamedFunction("checkBase", AOTHolder.OBJ_OBJ_TYPE);
895 case NF_staticBase:
896 return getNamedFunction("staticBase", AOTHolder.OBJ_OBJ_TYPE);
897 case NF_staticOffset:
898 return getNamedFunction("staticOffset", AOTHolder.LONG_OBJ_TYPE);
899 case NF_checkCast:
900 return getNamedFunction("checkCast", MethodType.methodType(Object.class, Object.class, Object.class));
901 case NF_allocateInstance:
902 return getNamedFunction("allocateInstance", AOTHolder.OBJ_OBJ_TYPE);
903 case NF_constructorMethod:
904 return getNamedFunction("constructorMethod", AOTHolder.OBJ_OBJ_TYPE);
905 case NF_UNSAFE:
906 MemberName member = new MemberName(MethodHandleStatics.class, "UNSAFE", Unsafe.class, REF_getStatic);
907 return new NamedFunction(
908 MemberName.getFactory().resolveOrFail(REF_getStatic, member,
909 DirectMethodHandle.class, LM_TRUSTED,
910 NoSuchFieldException.class));
911 case NF_checkReceiver:
912 member = new MemberName(DirectMethodHandle.class, "checkReceiver", AOTHolder.OBJ_OBJ_TYPE, REF_invokeVirtual);
913 return new NamedFunction(
914 MemberName.getFactory().resolveOrFail(REF_invokeVirtual, member,
915 DirectMethodHandle.class, LM_TRUSTED,
916 NoSuchMethodException.class));
917 default:
918 throw newInternalError("Unknown function: " + func);
919 }
920 } catch (ReflectiveOperationException ex) {
921 throw newInternalError(ex);
922 }
923 }
924
925 private static NamedFunction getNamedFunction(String name, MethodType type)
926 throws ReflectiveOperationException
927 {
928 MemberName member = new MemberName(DirectMethodHandle.class, name, type, REF_invokeStatic);
929 return new NamedFunction(
930 MemberName.getFactory().resolveOrFail(REF_invokeStatic, member,
931 DirectMethodHandle.class, LM_TRUSTED,
932 NoSuchMethodException.class));
|