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.misc.Unsafe;
29 import jdk.internal.vm.annotation.ForceInline;
30 import jdk.internal.vm.annotation.Stable;
31 import sun.invoke.util.ValueConversions;
32 import sun.invoke.util.VerifyAccess;
33 import sun.invoke.util.Wrapper;
34
35 import java.util.Arrays;
36 import java.util.Objects;
37 import java.util.function.Function;
38
39 import static java.lang.invoke.LambdaForm.*;
40 import static java.lang.invoke.LambdaForm.Kind.*;
41 import static java.lang.invoke.MethodHandleNatives.Constants.*;
42 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
43 import static java.lang.invoke.MethodHandleStatics.newInternalError;
44 import static java.lang.invoke.MethodTypeForm.*;
45
46 /**
47 * The flavor of method handle which implements a constant reference
851 NF_checkCast = 7,
852 NF_allocateInstance = 8,
853 NF_constructorMethod = 9,
854 NF_UNSAFE = 10,
855 NF_checkReceiver = 11,
856 NF_LIMIT = 12;
857
858 private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
859
860 private static NamedFunction getFunction(byte func) {
861 NamedFunction nf = NFS[func];
862 if (nf != null) {
863 return nf;
864 }
865 // Each nf must be statically invocable or we get tied up in our bootstraps.
866 nf = NFS[func] = createFunction(func);
867 assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
868 return nf;
869 }
870
871 private static final MethodType OBJ_OBJ_TYPE = MethodType.methodType(Object.class, Object.class);
872
873 private static final MethodType LONG_OBJ_TYPE = MethodType.methodType(long.class, Object.class);
874
875 private static NamedFunction createFunction(byte func) {
876 try {
877 switch (func) {
878 case NF_internalMemberName:
879 return getNamedFunction("internalMemberName", OBJ_OBJ_TYPE);
880 case NF_internalMemberNameEnsureInit:
881 return getNamedFunction("internalMemberNameEnsureInit", OBJ_OBJ_TYPE);
882 case NF_ensureInitialized:
883 return getNamedFunction("ensureInitialized", MethodType.methodType(void.class, Object.class));
884 case NF_fieldOffset:
885 return getNamedFunction("fieldOffset", LONG_OBJ_TYPE);
886 case NF_checkBase:
887 return getNamedFunction("checkBase", OBJ_OBJ_TYPE);
888 case NF_staticBase:
889 return getNamedFunction("staticBase", OBJ_OBJ_TYPE);
890 case NF_staticOffset:
891 return getNamedFunction("staticOffset", LONG_OBJ_TYPE);
892 case NF_checkCast:
893 return getNamedFunction("checkCast", MethodType.methodType(Object.class, Object.class, Object.class));
|
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.misc.CDS;
29 import jdk.internal.misc.Unsafe;
30 import jdk.internal.vm.annotation.ForceInline;
31 import jdk.internal.vm.annotation.Stable;
32 import sun.invoke.util.ValueConversions;
33 import sun.invoke.util.VerifyAccess;
34 import sun.invoke.util.Wrapper;
35
36 import java.util.Arrays;
37 import java.util.Objects;
38 import java.util.function.Function;
39
40 import static java.lang.invoke.LambdaForm.*;
41 import static java.lang.invoke.LambdaForm.Kind.*;
42 import static java.lang.invoke.MethodHandleNatives.Constants.*;
43 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
44 import static java.lang.invoke.MethodHandleStatics.newInternalError;
45 import static java.lang.invoke.MethodTypeForm.*;
46
47 /**
48 * The flavor of method handle which implements a constant reference
852 NF_checkCast = 7,
853 NF_allocateInstance = 8,
854 NF_constructorMethod = 9,
855 NF_UNSAFE = 10,
856 NF_checkReceiver = 11,
857 NF_LIMIT = 12;
858
859 private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
860
861 private static NamedFunction getFunction(byte func) {
862 NamedFunction nf = NFS[func];
863 if (nf != null) {
864 return nf;
865 }
866 // Each nf must be statically invocable or we get tied up in our bootstraps.
867 nf = NFS[func] = createFunction(func);
868 assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
869 return nf;
870 }
871
872 private static final MethodType OBJ_OBJ_TYPE;
873 private static final MethodType LONG_OBJ_TYPE;
874 private static @Stable MethodType[] archivedObjects;
875
876 static {
877 CDS.initializeFromArchive(DirectMethodHandle.class);
878 if (archivedObjects != null) {
879 OBJ_OBJ_TYPE = archivedObjects[0];
880 LONG_OBJ_TYPE = archivedObjects[1];
881 } else {
882 OBJ_OBJ_TYPE = MethodType.methodType(Object.class, Object.class);
883 LONG_OBJ_TYPE = MethodType.methodType(long.class, Object.class);
884 }
885 }
886
887 static void dumpSharedArchive() {
888 archivedObjects = new MethodType[2];
889 archivedObjects[0] = OBJ_OBJ_TYPE;
890 archivedObjects[1] = LONG_OBJ_TYPE;
891 }
892
893 private static NamedFunction createFunction(byte func) {
894 try {
895 switch (func) {
896 case NF_internalMemberName:
897 return getNamedFunction("internalMemberName", OBJ_OBJ_TYPE);
898 case NF_internalMemberNameEnsureInit:
899 return getNamedFunction("internalMemberNameEnsureInit", OBJ_OBJ_TYPE);
900 case NF_ensureInitialized:
901 return getNamedFunction("ensureInitialized", MethodType.methodType(void.class, Object.class));
902 case NF_fieldOffset:
903 return getNamedFunction("fieldOffset", LONG_OBJ_TYPE);
904 case NF_checkBase:
905 return getNamedFunction("checkBase", OBJ_OBJ_TYPE);
906 case NF_staticBase:
907 return getNamedFunction("staticBase", OBJ_OBJ_TYPE);
908 case NF_staticOffset:
909 return getNamedFunction("staticOffset", LONG_OBJ_TYPE);
910 case NF_checkCast:
911 return getNamedFunction("checkCast", MethodType.methodType(Object.class, Object.class, Object.class));
|