Mercurial > hg > graal-jvmci-8
comparison src/share/vm/classfile/javaClasses.hpp @ 710:e5b0439ef4ae
6655638: dynamic languages need method handles
Summary: initial implementation, with known omissions (x86/64, sparc, compiler optim., c-oops, C++ interp.)
Reviewed-by: kvn, twisti, never
author | jrose |
---|---|
date | Wed, 08 Apr 2009 10:56:49 -0700 |
parents | c89f86385056 |
children | be93aad57795 |
comparison
equal
deleted
inserted
replaced
709:1d037ecd7960 | 710:e5b0439ef4ae |
---|---|
149 static oop create_mirror(KlassHandle k, TRAPS); | 149 static oop create_mirror(KlassHandle k, TRAPS); |
150 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS); | 150 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS); |
151 // Conversion | 151 // Conversion |
152 static klassOop as_klassOop(oop java_class); | 152 static klassOop as_klassOop(oop java_class); |
153 static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL); | 153 static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL); |
154 static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) { | |
155 klassOop refk_oop = NULL; | |
156 BasicType result = as_BasicType(java_class, &refk_oop); | |
157 (*reference_klass) = KlassHandle(refk_oop); | |
158 return result; | |
159 } | |
154 static symbolOop as_signature(oop java_class, bool intern_if_not_found, TRAPS); | 160 static symbolOop as_signature(oop java_class, bool intern_if_not_found, TRAPS); |
155 static void print_signature(oop java_class, outputStream *st); | 161 static void print_signature(oop java_class, outputStream *st); |
156 // Testing | 162 // Testing |
157 static bool is_instance(oop obj) { | 163 static bool is_instance(oop obj) { |
158 return obj != NULL && obj->klass() == SystemDictionary::class_klass(); | 164 return obj != NULL && obj->klass() == SystemDictionary::class_klass(); |
776 static jlong clock(); | 782 static jlong clock(); |
777 static void set_clock(jlong value); | 783 static void set_clock(jlong value); |
778 }; | 784 }; |
779 | 785 |
780 | 786 |
787 // Interface to java.dyn.MethodHandle objects | |
788 | |
789 class MethodHandleEntry; | |
790 | |
791 class java_dyn_MethodHandle: AllStatic { | |
792 friend class JavaClasses; | |
793 | |
794 private: | |
795 static int _vmentry_offset; // assembly code trampoline for MH | |
796 static int _vmtarget_offset; // class-specific target reference | |
797 static int _type_offset; // the MethodType of this MH | |
798 static int _vmslots_offset; // OPTIONAL hoisted type.form.vmslots | |
799 | |
800 static void compute_offsets(); | |
801 | |
802 public: | |
803 // Accessors | |
804 static oop type(oop mh); | |
805 static void set_type(oop mh, oop mtype); | |
806 | |
807 static oop vmtarget(oop mh); | |
808 static void set_vmtarget(oop mh, oop target); | |
809 | |
810 static MethodHandleEntry* vmentry(oop mh); | |
811 static void set_vmentry(oop mh, MethodHandleEntry* data); | |
812 | |
813 static int vmslots(oop mh); | |
814 static void init_vmslots(oop mh); | |
815 static int compute_vmslots(oop mh); | |
816 | |
817 // Testers | |
818 static bool is_subclass(klassOop klass) { | |
819 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MethodHandle_klass()); | |
820 } | |
821 static bool is_instance(oop obj) { | |
822 return obj != NULL && is_subclass(obj->klass()); | |
823 } | |
824 | |
825 // Accessors for code generation: | |
826 static int type_offset_in_bytes() { return _type_offset; } | |
827 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; } | |
828 static int vmentry_offset_in_bytes() { return _vmentry_offset; } | |
829 static int vmslots_offset_in_bytes() { return _vmslots_offset; } | |
830 }; | |
831 | |
832 class sun_dyn_DirectMethodHandle: public java_dyn_MethodHandle { | |
833 friend class JavaClasses; | |
834 | |
835 private: | |
836 // _vmtarget_offset; // method or class or interface | |
837 static int _vmindex_offset; // negative or vtable idx or itable idx | |
838 static void compute_offsets(); | |
839 | |
840 public: | |
841 // Accessors | |
842 static int vmindex(oop mh); | |
843 static void set_vmindex(oop mh, int index); | |
844 | |
845 // Testers | |
846 static bool is_subclass(klassOop klass) { | |
847 return Klass::cast(klass)->is_subclass_of(SystemDictionary::DirectMethodHandle_klass()); | |
848 } | |
849 static bool is_instance(oop obj) { | |
850 return obj != NULL && is_subclass(obj->klass()); | |
851 } | |
852 | |
853 // Accessors for code generation: | |
854 static int vmindex_offset_in_bytes() { return _vmindex_offset; } | |
855 }; | |
856 | |
857 class sun_dyn_BoundMethodHandle: public java_dyn_MethodHandle { | |
858 friend class JavaClasses; | |
859 | |
860 private: | |
861 static int _argument_offset; // argument value bound into this MH | |
862 static int _vmargslot_offset; // relevant argument slot (<= vmslots) | |
863 static void compute_offsets(); | |
864 | |
865 public: | |
866 static oop argument(oop mh); | |
867 static void set_argument(oop mh, oop ref); | |
868 | |
869 static jint vmargslot(oop mh); | |
870 static void set_vmargslot(oop mh, jint slot); | |
871 | |
872 // Testers | |
873 static bool is_subclass(klassOop klass) { | |
874 return Klass::cast(klass)->is_subclass_of(SystemDictionary::BoundMethodHandle_klass()); | |
875 } | |
876 static bool is_instance(oop obj) { | |
877 return obj != NULL && is_subclass(obj->klass()); | |
878 } | |
879 | |
880 static int argument_offset_in_bytes() { return _argument_offset; } | |
881 static int vmargslot_offset_in_bytes() { return _vmargslot_offset; } | |
882 }; | |
883 | |
884 class sun_dyn_AdapterMethodHandle: public sun_dyn_BoundMethodHandle { | |
885 friend class JavaClasses; | |
886 | |
887 private: | |
888 static int _conversion_offset; // type of conversion to apply | |
889 static void compute_offsets(); | |
890 | |
891 public: | |
892 static int conversion(oop mh); | |
893 static void set_conversion(oop mh, int conv); | |
894 | |
895 // Testers | |
896 static bool is_subclass(klassOop klass) { | |
897 return Klass::cast(klass)->is_subclass_of(SystemDictionary::AdapterMethodHandle_klass()); | |
898 } | |
899 static bool is_instance(oop obj) { | |
900 return obj != NULL && is_subclass(obj->klass()); | |
901 } | |
902 | |
903 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants): | |
904 enum { | |
905 OP_RETYPE_ONLY = 0x0, // no argument changes; straight retype | |
906 OP_CHECK_CAST = 0x1, // ref-to-ref conversion; requires a Class argument | |
907 OP_PRIM_TO_PRIM = 0x2, // converts from one primitive to another | |
908 OP_REF_TO_PRIM = 0x3, // unboxes a wrapper to produce a primitive | |
909 OP_PRIM_TO_REF = 0x4, // boxes a primitive into a wrapper (NYI) | |
910 OP_SWAP_ARGS = 0x5, // swap arguments (vminfo is 2nd arg) | |
911 OP_ROT_ARGS = 0x6, // rotate arguments (vminfo is displaced arg) | |
912 OP_DUP_ARGS = 0x7, // duplicates one or more arguments (at TOS) | |
913 OP_DROP_ARGS = 0x8, // remove one or more argument slots | |
914 OP_COLLECT_ARGS = 0x9, // combine one or more arguments into a varargs (NYI) | |
915 OP_SPREAD_ARGS = 0xA, // expand in place a varargs array (of known size) | |
916 OP_FLYBY = 0xB, // operate first on reified argument list (NYI) | |
917 OP_RICOCHET = 0xC, // run an adapter chain on the return value (NYI) | |
918 CONV_OP_LIMIT = 0xD, // limit of CONV_OP enumeration | |
919 | |
920 CONV_OP_MASK = 0xF00, // this nybble contains the conversion op field | |
921 CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use | |
922 CONV_VMINFO_SHIFT = 0, // position of bits in CONV_VMINFO_MASK | |
923 CONV_OP_SHIFT = 8, // position of bits in CONV_OP_MASK | |
924 CONV_DEST_TYPE_SHIFT = 12, // byte 2 has the adapter BasicType (if needed) | |
925 CONV_SRC_TYPE_SHIFT = 16, // byte 2 has the source BasicType (if needed) | |
926 CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change | |
927 CONV_STACK_MOVE_MASK = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1 | |
928 }; | |
929 | |
930 static int conversion_offset_in_bytes() { return _conversion_offset; } | |
931 }; | |
932 | |
933 | |
934 // Interface to sun.dyn.MemberName objects | |
935 // (These are a private interface for Java code to query the class hierarchy.) | |
936 | |
937 class sun_dyn_MemberName: AllStatic { | |
938 friend class JavaClasses; | |
939 | |
940 private: | |
941 // From java.dyn.MemberName: | |
942 // private Class<?> clazz; // class in which the method is defined | |
943 // private String name; // may be null if not yet materialized | |
944 // private Object type; // may be null if not yet materialized | |
945 // private int flags; // modifier bits; see reflect.Modifier | |
946 // private Object vmtarget; // VM-specific target value | |
947 // private int vmindex; // method index within class or interface | |
948 static int _clazz_offset; | |
949 static int _name_offset; | |
950 static int _type_offset; | |
951 static int _flags_offset; | |
952 static int _vmtarget_offset; | |
953 static int _vmindex_offset; | |
954 | |
955 static void compute_offsets(); | |
956 | |
957 public: | |
958 // Accessors | |
959 static oop clazz(oop mname); | |
960 static void set_clazz(oop mname, oop clazz); | |
961 | |
962 static oop type(oop mname); | |
963 static void set_type(oop mname, oop type); | |
964 | |
965 static oop name(oop mname); | |
966 static void set_name(oop mname, oop name); | |
967 | |
968 static int flags(oop mname); | |
969 static void set_flags(oop mname, int flags); | |
970 | |
971 static int modifiers(oop mname) { return (u2) flags(mname); } | |
972 static void set_modifiers(oop mname, int mods) | |
973 { set_flags(mname, (flags(mname) &~ (u2)-1) | (u2)mods); } | |
974 | |
975 static oop vmtarget(oop mname); | |
976 static void set_vmtarget(oop mname, oop target); | |
977 | |
978 static int vmindex(oop mname); | |
979 static void set_vmindex(oop mname, int index); | |
980 | |
981 // Testers | |
982 static bool is_subclass(klassOop klass) { | |
983 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MemberName_klass()); | |
984 } | |
985 static bool is_instance(oop obj) { | |
986 return obj != NULL && is_subclass(obj->klass()); | |
987 } | |
988 | |
989 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants): | |
990 enum { | |
991 MN_IS_METHOD = 0x00010000, // method (not constructor) | |
992 MN_IS_CONSTRUCTOR = 0x00020000, // constructor | |
993 MN_IS_FIELD = 0x00040000, // field | |
994 MN_IS_TYPE = 0x00080000, // nested type | |
995 MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers | |
996 MN_SEARCH_INTERFACES = 0x00200000, // for MHN.getMembers | |
997 VM_INDEX_UNINITIALIZED = -99 | |
998 }; | |
999 | |
1000 // Accessors for code generation: | |
1001 static int clazz_offset_in_bytes() { return _clazz_offset; } | |
1002 static int type_offset_in_bytes() { return _type_offset; } | |
1003 static int name_offset_in_bytes() { return _name_offset; } | |
1004 static int flags_offset_in_bytes() { return _flags_offset; } | |
1005 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; } | |
1006 static int vmindex_offset_in_bytes() { return _vmindex_offset; } | |
1007 }; | |
1008 | |
1009 | |
1010 // Interface to java.dyn.MethodType objects | |
1011 | |
1012 class java_dyn_MethodType: AllStatic { | |
1013 friend class JavaClasses; | |
1014 | |
1015 private: | |
1016 static int _rtype_offset; | |
1017 static int _ptypes_offset; | |
1018 static int _form_offset; | |
1019 | |
1020 static void compute_offsets(); | |
1021 | |
1022 public: | |
1023 // Accessors | |
1024 static oop rtype(oop mt); | |
1025 static objArrayOop ptypes(oop mt); | |
1026 static oop form(oop mt); | |
1027 | |
1028 static oop ptype(oop mt, int index); | |
1029 | |
1030 static symbolOop as_signature(oop mt, bool intern_if_not_found, TRAPS); | |
1031 static void print_signature(oop mt, outputStream* st); | |
1032 | |
1033 static bool is_instance(oop obj) { | |
1034 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass(); | |
1035 } | |
1036 | |
1037 // Accessors for code generation: | |
1038 static int rtype_offset_in_bytes() { return _rtype_offset; } | |
1039 static int ptypes_offset_in_bytes() { return _ptypes_offset; } | |
1040 static int form_offset_in_bytes() { return _form_offset; } | |
1041 }; | |
1042 | |
1043 class java_dyn_MethodTypeForm: AllStatic { | |
1044 friend class JavaClasses; | |
1045 | |
1046 private: | |
1047 static int _vmslots_offset; // number of argument slots needed | |
1048 static int _erasedType_offset; // erasedType = canonical MethodType | |
1049 | |
1050 static void compute_offsets(); | |
1051 | |
1052 public: | |
1053 // Accessors | |
1054 static int vmslots(oop mtform); | |
1055 static oop erasedType(oop mtform); | |
1056 | |
1057 // Accessors for code generation: | |
1058 static int vmslots_offset_in_bytes() { return _vmslots_offset; } | |
1059 static int erasedType_offset_in_bytes() { return _erasedType_offset; } | |
1060 }; | |
1061 | |
1062 | |
1063 | |
1064 | |
781 // Interface to java.security.AccessControlContext objects | 1065 // Interface to java.security.AccessControlContext objects |
782 | 1066 |
783 class java_security_AccessControlContext: AllStatic { | 1067 class java_security_AccessControlContext: AllStatic { |
784 private: | 1068 private: |
785 // Note that for this class the layout changed between JDK1.2 and JDK1.3, | 1069 // Note that for this class the layout changed between JDK1.2 and JDK1.3, |