19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "ci/ciMethodData.hpp"
28 #include "ci/ciReplay.hpp"
29 #include "ci/ciSymbol.hpp"
30 #include "ci/ciKlass.hpp"
31 #include "ci/ciUtilities.inline.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "memory/allocation.inline.hpp"
34 #include "memory/oopFactory.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/constantPool.hpp"
37 #include "oops/method.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/fieldDescriptor.inline.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "utilities/copy.hpp"
42 #include "utilities/macros.hpp"
43
44 #ifndef PRODUCT
45
46 // ciReplay
47
48 typedef struct _ciMethodDataRecord {
49 const char* _klass_name;
50 const char* _method_name;
51 const char* _signature;
52
53 int _state;
54 int _current_mileage;
55
56 intptr_t* _data;
57 char* _orig_data;
58 Klass** _classes;
691 ConstantPool* cp = k->constants();
692 if (length != cp->length()) {
693 report_error("constant pool length mismatch: wrong class files?");
694 return;
695 }
696
697 int parsed_two_word = 0;
698 for (int i = 1; i < length; i++) {
699 int tag = parse_int("tag");
700 if (had_error()) {
701 return;
702 }
703 switch (cp->tag_at(i).value()) {
704 case JVM_CONSTANT_UnresolvedClass: {
705 if (tag == JVM_CONSTANT_Class) {
706 tty->print_cr("Resolving klass %s at %d", cp->klass_name_at(i)->as_utf8(), i);
707 Klass* k = cp->klass_at(i, CHECK);
708 }
709 break;
710 }
711 case JVM_CONSTANT_Long:
712 case JVM_CONSTANT_Double:
713 parsed_two_word = i + 1;
714
715 case JVM_CONSTANT_ClassIndex:
716 case JVM_CONSTANT_StringIndex:
717 case JVM_CONSTANT_String:
718 case JVM_CONSTANT_UnresolvedClassInError:
719 case JVM_CONSTANT_Fieldref:
720 case JVM_CONSTANT_Methodref:
721 case JVM_CONSTANT_InterfaceMethodref:
722 case JVM_CONSTANT_NameAndType:
723 case JVM_CONSTANT_Utf8:
724 case JVM_CONSTANT_Integer:
725 case JVM_CONSTANT_Float:
726 case JVM_CONSTANT_MethodHandle:
727 case JVM_CONSTANT_MethodType:
728 case JVM_CONSTANT_Dynamic:
729 case JVM_CONSTANT_InvokeDynamic:
730 if (tag != cp->tag_at(i).value()) {
737 if (tag == JVM_CONSTANT_Class) {
738 } else if (tag == JVM_CONSTANT_UnresolvedClass) {
739 tty->print_cr("Warning: entry was unresolved in the replay data");
740 } else {
741 report_error("Unexpected tag");
742 return;
743 }
744 break;
745
746 case 0:
747 if (parsed_two_word == i) continue;
748
749 default:
750 fatal("Unexpected tag: %d", cp->tag_at(i).value());
751 break;
752 }
753
754 }
755 }
756
757 // Initialize a class and fill in the value for a static field.
758 // This is useful when the compile was dependent on the value of
759 // static fields but it's impossible to properly rerun the static
760 // initiailizer.
761 void process_staticfield(TRAPS) {
762 InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
763
764 if (k == NULL || ReplaySuppressInitializers == 0 ||
765 (ReplaySuppressInitializers == 2 && k->class_loader() == NULL)) {
766 return;
767 }
768
769 assert(k->is_initialized(), "must be");
770
771 const char* field_name = parse_escaped_string();
772 const char* field_signature = parse_string();
773 fieldDescriptor fd;
774 Symbol* name = SymbolTable::lookup(field_name, (int)strlen(field_name), CHECK);
775 Symbol* sig = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
776 if (!k->find_local_field(name, sig, &fd) ||
777 !fd.is_static() ||
778 fd.has_initial_value()) {
779 report_error(field_name);
780 return;
781 }
782
783 oop java_mirror = k->java_mirror();
784 if (field_signature[0] == '[') {
785 int length = parse_int("array length");
786 oop value = NULL;
787
788 if (field_signature[1] == '[') {
789 // multi dimensional array
790 ArrayKlass* kelem = (ArrayKlass *)parse_klass(CHECK);
791 if (kelem == NULL) {
792 return;
793 }
794 int rank = 0;
795 while (field_signature[rank] == '[') {
796 rank++;
797 }
798 jint* dims = NEW_RESOURCE_ARRAY(jint, rank);
799 dims[0] = length;
800 for (int i = 1; i < rank; i++) {
801 dims[i] = 1; // These aren't relevant to the compiler
802 }
803 value = kelem->multi_allocate(rank, dims, CHECK);
804 } else {
805 if (strcmp(field_signature, "[B") == 0) {
806 value = oopFactory::new_byteArray(length, CHECK);
807 } else if (strcmp(field_signature, "[Z") == 0) {
808 value = oopFactory::new_boolArray(length, CHECK);
809 } else if (strcmp(field_signature, "[C") == 0) {
810 value = oopFactory::new_charArray(length, CHECK);
811 } else if (strcmp(field_signature, "[S") == 0) {
812 value = oopFactory::new_shortArray(length, CHECK);
813 } else if (strcmp(field_signature, "[F") == 0) {
814 value = oopFactory::new_floatArray(length, CHECK);
815 } else if (strcmp(field_signature, "[D") == 0) {
816 value = oopFactory::new_doubleArray(length, CHECK);
817 } else if (strcmp(field_signature, "[I") == 0) {
818 value = oopFactory::new_intArray(length, CHECK);
819 } else if (strcmp(field_signature, "[J") == 0) {
820 value = oopFactory::new_longArray(length, CHECK);
821 } else if (field_signature[0] == '[' && field_signature[1] == 'L') {
822 Klass* kelem = resolve_klass(field_signature + 1, CHECK);
823 value = oopFactory::new_objArray(kelem, length, CHECK);
824 } else {
825 report_error("unhandled array staticfield");
826 }
827 }
828 java_mirror->obj_field_put(fd.offset(), value);
829 } else {
830 const char* string_value = parse_escaped_string();
831 if (strcmp(field_signature, "I") == 0) {
832 int value = atoi(string_value);
833 java_mirror->int_field_put(fd.offset(), value);
834 } else if (strcmp(field_signature, "B") == 0) {
835 int value = atoi(string_value);
836 java_mirror->byte_field_put(fd.offset(), value);
837 } else if (strcmp(field_signature, "C") == 0) {
838 int value = atoi(string_value);
839 java_mirror->char_field_put(fd.offset(), value);
840 } else if (strcmp(field_signature, "S") == 0) {
841 int value = atoi(string_value);
842 java_mirror->short_field_put(fd.offset(), value);
843 } else if (strcmp(field_signature, "Z") == 0) {
844 int value = atoi(string_value);
845 java_mirror->bool_field_put(fd.offset(), value);
846 } else if (strcmp(field_signature, "J") == 0) {
847 jlong value;
848 if (sscanf(string_value, JLONG_FORMAT, &value) != 1) {
849 fprintf(stderr, "Error parsing long: %s\n", string_value);
850 return;
851 }
852 java_mirror->long_field_put(fd.offset(), value);
853 } else if (strcmp(field_signature, "F") == 0) {
854 float value = atof(string_value);
855 java_mirror->float_field_put(fd.offset(), value);
856 } else if (strcmp(field_signature, "D") == 0) {
857 double value = atof(string_value);
858 java_mirror->double_field_put(fd.offset(), value);
859 } else if (strcmp(field_signature, "Ljava/lang/String;") == 0) {
860 Handle value = java_lang_String::create_from_str(string_value, CHECK);
861 java_mirror->obj_field_put(fd.offset(), value());
862 } else if (field_signature[0] == 'L') {
863 Klass* k = resolve_klass(string_value, CHECK);
864 oop value = InstanceKlass::cast(k)->allocate_instance(CHECK);
865 java_mirror->obj_field_put(fd.offset(), value);
866 } else {
867 report_error("unhandled staticfield");
868 }
869 }
870 }
871
872 #if INCLUDE_JVMTI
873 void process_JvmtiExport(TRAPS) {
874 const char* field = parse_string();
875 bool value = parse_int("JvmtiExport flag") != 0;
876 if (strcmp(field, "can_access_local_variables") == 0) {
877 JvmtiExport::set_can_access_local_variables(value);
878 } else if (strcmp(field, "can_hotswap_or_post_breakpoint") == 0) {
879 JvmtiExport::set_can_hotswap_or_post_breakpoint(value);
880 } else if (strcmp(field, "can_post_on_exceptions") == 0) {
881 JvmtiExport::set_can_post_on_exceptions(value);
882 } else {
883 report_error("Unrecognized JvmtiExport directive");
884 }
885 }
886 #endif // INCLUDE_JVMTI
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "ci/ciMethodData.hpp"
28 #include "ci/ciReplay.hpp"
29 #include "ci/ciSymbol.hpp"
30 #include "ci/ciKlass.hpp"
31 #include "ci/ciUtilities.inline.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "memory/allocation.inline.hpp"
34 #include "memory/oopFactory.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/constantPool.hpp"
37 #include "oops/method.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "oops/valueKlass.hpp"
40 #include "runtime/fieldDescriptor.inline.hpp"
41 #include "runtime/handles.inline.hpp"
42 #include "utilities/copy.hpp"
43 #include "utilities/macros.hpp"
44
45 #ifndef PRODUCT
46
47 // ciReplay
48
49 typedef struct _ciMethodDataRecord {
50 const char* _klass_name;
51 const char* _method_name;
52 const char* _signature;
53
54 int _state;
55 int _current_mileage;
56
57 intptr_t* _data;
58 char* _orig_data;
59 Klass** _classes;
692 ConstantPool* cp = k->constants();
693 if (length != cp->length()) {
694 report_error("constant pool length mismatch: wrong class files?");
695 return;
696 }
697
698 int parsed_two_word = 0;
699 for (int i = 1; i < length; i++) {
700 int tag = parse_int("tag");
701 if (had_error()) {
702 return;
703 }
704 switch (cp->tag_at(i).value()) {
705 case JVM_CONSTANT_UnresolvedClass: {
706 if (tag == JVM_CONSTANT_Class) {
707 tty->print_cr("Resolving klass %s at %d", cp->klass_name_at(i)->as_utf8(), i);
708 Klass* k = cp->klass_at(i, CHECK);
709 }
710 break;
711 }
712
713 case JVM_CONSTANT_Long:
714 case JVM_CONSTANT_Double:
715 parsed_two_word = i + 1;
716
717 case JVM_CONSTANT_ClassIndex:
718 case JVM_CONSTANT_StringIndex:
719 case JVM_CONSTANT_String:
720 case JVM_CONSTANT_UnresolvedClassInError:
721 case JVM_CONSTANT_Fieldref:
722 case JVM_CONSTANT_Methodref:
723 case JVM_CONSTANT_InterfaceMethodref:
724 case JVM_CONSTANT_NameAndType:
725 case JVM_CONSTANT_Utf8:
726 case JVM_CONSTANT_Integer:
727 case JVM_CONSTANT_Float:
728 case JVM_CONSTANT_MethodHandle:
729 case JVM_CONSTANT_MethodType:
730 case JVM_CONSTANT_Dynamic:
731 case JVM_CONSTANT_InvokeDynamic:
732 if (tag != cp->tag_at(i).value()) {
739 if (tag == JVM_CONSTANT_Class) {
740 } else if (tag == JVM_CONSTANT_UnresolvedClass) {
741 tty->print_cr("Warning: entry was unresolved in the replay data");
742 } else {
743 report_error("Unexpected tag");
744 return;
745 }
746 break;
747
748 case 0:
749 if (parsed_two_word == i) continue;
750
751 default:
752 fatal("Unexpected tag: %d", cp->tag_at(i).value());
753 break;
754 }
755
756 }
757 }
758
759 class ValueTypeFieldInitializer : public FieldClosure {
760 oop _vt;
761 CompileReplay* _replay;
762 public:
763 ValueTypeFieldInitializer(oop vt, CompileReplay* replay)
764 : _vt(vt), _replay(replay) {}
765
766 void do_field(fieldDescriptor* fd) {
767 BasicType bt = fd->field_type();
768 const char* string_value = bt != T_VALUETYPE ? _replay->parse_escaped_string() : NULL;
769 switch (bt) {
770 case T_BYTE: {
771 int value = atoi(string_value);
772 _vt->byte_field_put(fd->offset(), value);
773 break;
774 }
775 case T_BOOLEAN: {
776 int value = atoi(string_value);
777 _vt->bool_field_put(fd->offset(), value);
778 break;
779 }
780 case T_SHORT: {
781 int value = atoi(string_value);
782 _vt->short_field_put(fd->offset(), value);
783 break;
784 }
785 case T_CHAR: {
786 int value = atoi(string_value);
787 _vt->char_field_put(fd->offset(), value);
788 break;
789 }
790 case T_INT: {
791 int value = atoi(string_value);
792 _vt->int_field_put(fd->offset(), value);
793 break;
794 }
795 case T_LONG: {
796 jlong value;
797 if (sscanf(string_value, JLONG_FORMAT, &value) != 1) {
798 fprintf(stderr, "Error parsing long: %s\n", string_value);
799 break;
800 }
801 _vt->long_field_put(fd->offset(), value);
802 break;
803 }
804 case T_FLOAT: {
805 float value = atof(string_value);
806 _vt->float_field_put(fd->offset(), value);
807 break;
808 }
809 case T_DOUBLE: {
810 double value = atof(string_value);
811 _vt->double_field_put(fd->offset(), value);
812 break;
813 }
814 case T_ARRAY:
815 case T_OBJECT: {
816 Thread* THREAD = Thread::current();
817 bool res = _replay->process_staticfield_reference(string_value, _vt, fd, THREAD);
818 assert(res, "should succeed for arrays & objects");
819 break;
820 }
821 case T_VALUETYPE: {
822 Thread* THREAD = Thread::current();
823 SignatureStream ss(fd->signature(), false);
824 InstanceKlass* holder = fd->field_holder();
825 Klass* k = ss.as_klass(Handle(THREAD, holder->class_loader()),
826 Handle(THREAD, holder->protection_domain()),
827 SignatureStream::ReturnNull, THREAD);
828 assert(k != NULL && !HAS_PENDING_EXCEPTION, "can resolve klass?");
829 ValueKlass* vk = ValueKlass::cast(k);
830 if (fd->is_flattened()) {
831 int field_offset = fd->offset() - vk->first_field_offset();
832 oop obj = (oop)((address)_vt + field_offset);
833 ValueTypeFieldInitializer init_fields(obj, _replay);
834 vk->do_nonstatic_fields(&init_fields);
835 } else {
836 oop value = vk->allocate_instance(THREAD);
837 _vt->obj_field_put(fd->offset(), value);
838 }
839 break;
840 }
841 default: {
842 fatal("Unhandled type: %s", type2name(bt));
843 }
844 }
845 }
846 };
847
848 bool process_staticfield_reference(const char* field_signature, oop java_mirror, fieldDescriptor* fd, TRAPS) {
849 if (field_signature[0] == '[') {
850 int length = parse_int("array length");
851 oop value = NULL;
852
853 if (field_signature[1] == '[') {
854 // multi dimensional array
855 Klass* k = resolve_klass(field_signature, CHECK_(true));
856 ArrayKlass* kelem = (ArrayKlass *)k;
857 int rank = 0;
858 while (field_signature[rank] == '[') {
859 rank++;
860 }
861 jint* dims = NEW_RESOURCE_ARRAY(jint, rank);
862 dims[0] = length;
863 for (int i = 1; i < rank; i++) {
864 dims[i] = 1; // These aren't relevant to the compiler
865 }
866 value = kelem->multi_allocate(rank, dims, CHECK_(true));
867 } else {
868 if (strcmp(field_signature, "[B") == 0) {
869 value = oopFactory::new_byteArray(length, CHECK_(true));
870 } else if (strcmp(field_signature, "[Z") == 0) {
871 value = oopFactory::new_boolArray(length, CHECK_(true));
872 } else if (strcmp(field_signature, "[C") == 0) {
873 value = oopFactory::new_charArray(length, CHECK_(true));
874 } else if (strcmp(field_signature, "[S") == 0) {
875 value = oopFactory::new_shortArray(length, CHECK_(true));
876 } else if (strcmp(field_signature, "[F") == 0) {
877 value = oopFactory::new_floatArray(length, CHECK_(true));
878 } else if (strcmp(field_signature, "[D") == 0) {
879 value = oopFactory::new_doubleArray(length, CHECK_(true));
880 } else if (strcmp(field_signature, "[I") == 0) {
881 value = oopFactory::new_intArray(length, CHECK_(true));
882 } else if (strcmp(field_signature, "[J") == 0) {
883 value = oopFactory::new_longArray(length, CHECK_(true));
884 } else if (field_signature[0] == '[' && field_signature[1] == 'L') {
885 Klass* kelem = resolve_klass(field_signature + 1, CHECK_(true));
886 value = oopFactory::new_array(kelem, length, CHECK_(true));
887 } else {
888 report_error("unhandled array staticfield");
889 }
890 }
891 java_mirror->obj_field_put(fd->offset(), value);
892 return true;
893 } else if (strcmp(field_signature, "Ljava/lang/String;") == 0) {
894 const char* string_value = parse_escaped_string();
895 Handle value = java_lang_String::create_from_str(string_value, CHECK_(true));
896 java_mirror->obj_field_put(fd->offset(), value());
897 return true;
898 } else if (field_signature[0] == 'L') {
899 Klass* k = resolve_klass(field_signature, CHECK_(true));
900 oop value = InstanceKlass::cast(k)->allocate_instance(CHECK_(true));
901 java_mirror->obj_field_put(fd->offset(), value);
902 return true;
903 }
904 return false;
905 }
906
907 // Initialize a class and fill in the value for a static field.
908 // This is useful when the compile was dependent on the value of
909 // static fields but it's impossible to properly rerun the static
910 // initializer.
911 void process_staticfield(TRAPS) {
912 InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
913
914 if (k == NULL || ReplaySuppressInitializers == 0 ||
915 (ReplaySuppressInitializers == 2 && k->class_loader() == NULL)) {
916 return;
917 }
918
919 assert(k->is_initialized(), "must be");
920
921 const char* field_name = parse_escaped_string();
922 const char* field_signature = parse_string();
923 fieldDescriptor fd;
924 Symbol* name = SymbolTable::lookup(field_name, (int)strlen(field_name), CHECK);
925 Symbol* sig = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
926 if (!k->find_local_field(name, sig, &fd) ||
927 !fd.is_static() ||
928 fd.has_initial_value()) {
929 report_error(field_name);
930 return;
931 }
932
933 oop java_mirror = k->java_mirror();
934 if (strcmp(field_signature, "I") == 0) {
935 const char* string_value = parse_escaped_string();
936 int value = atoi(string_value);
937 java_mirror->int_field_put(fd.offset(), value);
938 } else if (strcmp(field_signature, "B") == 0) {
939 const char* string_value = parse_escaped_string();
940 int value = atoi(string_value);
941 java_mirror->byte_field_put(fd.offset(), value);
942 } else if (strcmp(field_signature, "C") == 0) {
943 const char* string_value = parse_escaped_string();
944 int value = atoi(string_value);
945 java_mirror->char_field_put(fd.offset(), value);
946 } else if (strcmp(field_signature, "S") == 0) {
947 const char* string_value = parse_escaped_string();
948 int value = atoi(string_value);
949 java_mirror->short_field_put(fd.offset(), value);
950 } else if (strcmp(field_signature, "Z") == 0) {
951 const char* string_value = parse_escaped_string();
952 int value = atoi(string_value);
953 java_mirror->bool_field_put(fd.offset(), value);
954 } else if (strcmp(field_signature, "J") == 0) {
955 const char* string_value = parse_escaped_string();
956 jlong value;
957 if (sscanf(string_value, JLONG_FORMAT, &value) != 1) {
958 fprintf(stderr, "Error parsing long: %s\n", string_value);
959 return;
960 }
961 java_mirror->long_field_put(fd.offset(), value);
962 } else if (strcmp(field_signature, "F") == 0) {
963 const char* string_value = parse_escaped_string();
964 float value = atof(string_value);
965 java_mirror->float_field_put(fd.offset(), value);
966 } else if (strcmp(field_signature, "D") == 0) {
967 const char* string_value = parse_escaped_string();
968 double value = atof(string_value);
969 java_mirror->double_field_put(fd.offset(), value);
970 } else if (field_signature[0] == 'Q') {
971 Klass* kelem = resolve_klass(field_signature, CHECK);
972 ValueKlass* vk = ValueKlass::cast(kelem);
973 oop value = vk->allocate_instance(CHECK);
974 ValueTypeFieldInitializer init_fields(value, this);
975 vk->do_nonstatic_fields(&init_fields);
976 java_mirror->obj_field_put(fd.offset(), value);
977 } else {
978 bool res = process_staticfield_reference(field_signature, java_mirror, &fd, CHECK);
979 if (!res) {
980 report_error("unhandled staticfield");
981 }
982 }
983 }
984
985 #if INCLUDE_JVMTI
986 void process_JvmtiExport(TRAPS) {
987 const char* field = parse_string();
988 bool value = parse_int("JvmtiExport flag") != 0;
989 if (strcmp(field, "can_access_local_variables") == 0) {
990 JvmtiExport::set_can_access_local_variables(value);
991 } else if (strcmp(field, "can_hotswap_or_post_breakpoint") == 0) {
992 JvmtiExport::set_can_hotswap_or_post_breakpoint(value);
993 } else if (strcmp(field, "can_post_on_exceptions") == 0) {
994 JvmtiExport::set_can_post_on_exceptions(value);
995 } else {
996 report_error("Unrecognized JvmtiExport directive");
997 }
998 }
999 #endif // INCLUDE_JVMTI
|