606 static hprofTag sig2tag(Symbol* sig); |
606 static hprofTag sig2tag(Symbol* sig); |
607 // returns hprof tag for the given basic type |
607 // returns hprof tag for the given basic type |
608 static hprofTag type2tag(BasicType type); |
608 static hprofTag type2tag(BasicType type); |
609 |
609 |
610 // returns the size of the instance of the given class |
610 // returns the size of the instance of the given class |
611 static u4 instance_size(klassOop k); |
611 static u4 instance_size(Klass* k); |
612 |
612 |
613 // dump a jfloat |
613 // dump a jfloat |
614 static void dump_float(DumpWriter* writer, jfloat f); |
614 static void dump_float(DumpWriter* writer, jfloat f); |
615 // dump a jdouble |
615 // dump a jdouble |
616 static void dump_double(DumpWriter* writer, jdouble d); |
616 static void dump_double(DumpWriter* writer, jdouble d); |
617 // dumps the raw value of the given field |
617 // dumps the raw value of the given field |
618 static void dump_field_value(DumpWriter* writer, char type, address addr); |
618 static void dump_field_value(DumpWriter* writer, char type, address addr); |
619 // dumps static fields of the given class |
619 // dumps static fields of the given class |
620 static void dump_static_fields(DumpWriter* writer, klassOop k); |
620 static void dump_static_fields(DumpWriter* writer, Klass* k); |
621 // dump the raw values of the instance fields of the given object |
621 // dump the raw values of the instance fields of the given object |
622 static void dump_instance_fields(DumpWriter* writer, oop o); |
622 static void dump_instance_fields(DumpWriter* writer, oop o); |
623 // dumps the definition of the instance fields for a given class |
623 // dumps the definition of the instance fields for a given class |
624 static void dump_instance_field_descriptors(DumpWriter* writer, klassOop k); |
624 static void dump_instance_field_descriptors(DumpWriter* writer, Klass* k); |
625 // creates HPROF_GC_INSTANCE_DUMP record for the given object |
625 // creates HPROF_GC_INSTANCE_DUMP record for the given object |
626 static void dump_instance(DumpWriter* writer, oop o); |
626 static void dump_instance(DumpWriter* writer, oop o); |
627 // creates HPROF_GC_CLASS_DUMP record for the given class and each of its |
627 // creates HPROF_GC_CLASS_DUMP record for the given class and each of its |
628 // array classes |
628 // array classes |
629 static void dump_class_and_array_classes(DumpWriter* writer, klassOop k); |
629 static void dump_class_and_array_classes(DumpWriter* writer, Klass* k); |
630 // creates HPROF_GC_CLASS_DUMP record for a given primitive array |
630 // creates HPROF_GC_CLASS_DUMP record for a given primitive array |
631 // class (and each multi-dimensional array class too) |
631 // class (and each multi-dimensional array class too) |
632 static void dump_basic_type_array_class(DumpWriter* writer, klassOop k); |
632 static void dump_basic_type_array_class(DumpWriter* writer, Klass* k); |
633 |
633 |
634 // creates HPROF_GC_OBJ_ARRAY_DUMP record for the given object array |
634 // creates HPROF_GC_OBJ_ARRAY_DUMP record for the given object array |
635 static void dump_object_array(DumpWriter* writer, objArrayOop array); |
635 static void dump_object_array(DumpWriter* writer, objArrayOop array); |
636 // creates HPROF_GC_PRIM_ARRAY_DUMP record for the given type array |
636 // creates HPROF_GC_PRIM_ARRAY_DUMP record for the given type array |
637 static void dump_prim_array(DumpWriter* writer, typeArrayOop array); |
637 static void dump_prim_array(DumpWriter* writer, typeArrayOop array); |
638 // create HPROF_FRAME record for the given method and bci |
638 // create HPROF_FRAME record for the given method and bci |
639 static void dump_stack_frame(DumpWriter* writer, int frame_serial_num, int class_serial_num, methodOop m, int bci); |
639 static void dump_stack_frame(DumpWriter* writer, int frame_serial_num, int class_serial_num, Method* m, int bci); |
640 }; |
640 }; |
641 |
641 |
642 // write a header of the given type |
642 // write a header of the given type |
643 void DumperSupport:: write_header(DumpWriter* writer, hprofTag tag, u4 len) { |
643 void DumperSupport:: write_header(DumpWriter* writer, hprofTag tag, u4 len) { |
644 writer->write_u1((u1)tag); |
644 writer->write_u1((u1)tag); |
717 } else { |
717 } else { |
718 o = oopDesc::load_decode_heap_oop((oop*)addr); |
718 o = oopDesc::load_decode_heap_oop((oop*)addr); |
719 } |
719 } |
720 |
720 |
721 // reflection and sun.misc.Unsafe classes may have a reference to a |
721 // reflection and sun.misc.Unsafe classes may have a reference to a |
722 // klassOop so filter it out. |
722 // Klass* so filter it out. |
723 if (o != NULL && o->is_klass()) { |
723 assert(o->is_oop_or_null(), "should always be an oop"); |
724 o = NULL; |
|
725 } |
|
726 |
|
727 // FIXME: When sharing is enabled we don't emit field references to objects |
|
728 // in shared spaces. We can remove this once we write records for the classes |
|
729 // and strings that are shared. |
|
730 if (o != NULL && o->is_shared()) { |
|
731 o = NULL; |
|
732 } |
|
733 writer->write_objectID(o); |
724 writer->write_objectID(o); |
734 break; |
725 break; |
735 } |
726 } |
736 case JVM_SIGNATURE_BYTE : { |
727 case JVM_SIGNATURE_BYTE : { |
737 jbyte* b = (jbyte*)addr; |
728 jbyte* b = (jbyte*)addr; |
897 dump_instance_fields(writer, o); |
888 dump_instance_fields(writer, o); |
898 } |
889 } |
899 |
890 |
900 // creates HPROF_GC_CLASS_DUMP record for the given class and each of |
891 // creates HPROF_GC_CLASS_DUMP record for the given class and each of |
901 // its array classes |
892 // its array classes |
902 void DumperSupport::dump_class_and_array_classes(DumpWriter* writer, klassOop k) { |
893 void DumperSupport::dump_class_and_array_classes(DumpWriter* writer, Klass* k) { |
903 Klass* klass = Klass::cast(k); |
894 Klass* klass = Klass::cast(k); |
904 assert(klass->oop_is_instance(), "not an instanceKlass"); |
895 assert(klass->oop_is_instance(), "not an InstanceKlass"); |
905 instanceKlass* ik = (instanceKlass*)klass; |
896 InstanceKlass* ik = (InstanceKlass*)klass; |
906 |
897 |
907 writer->write_u1(HPROF_GC_CLASS_DUMP); |
898 writer->write_u1(HPROF_GC_CLASS_DUMP); |
908 |
899 |
909 // class ID |
900 // class ID |
910 writer->write_classID(ik); |
901 writer->write_classID(ik); |
911 writer->write_u4(STACK_TRACE_ID); |
902 writer->write_u4(STACK_TRACE_ID); |
912 |
903 |
913 // super class ID |
904 // super class ID |
914 klassOop java_super = ik->java_super(); |
905 Klass* java_super = ik->java_super(); |
915 if (java_super == NULL) { |
906 if (java_super == NULL) { |
916 writer->write_objectID(NULL); |
907 writer->write_objectID(oop(NULL)); |
917 } else { |
908 } else { |
918 writer->write_classID(Klass::cast(java_super)); |
909 writer->write_classID(Klass::cast(java_super)); |
919 } |
910 } |
920 |
911 |
921 writer->write_objectID(ik->class_loader()); |
912 writer->write_objectID(ik->class_loader()); |
922 writer->write_objectID(ik->signers()); |
913 writer->write_objectID(ik->signers()); |
923 writer->write_objectID(ik->protection_domain()); |
914 writer->write_objectID(ik->protection_domain()); |
924 |
915 |
925 // reserved |
916 // reserved |
926 writer->write_objectID(NULL); |
917 writer->write_objectID(oop(NULL)); |
927 writer->write_objectID(NULL); |
918 writer->write_objectID(oop(NULL)); |
928 |
919 |
929 // instance size |
920 // instance size |
930 writer->write_u4(DumperSupport::instance_size(k)); |
921 writer->write_u4(DumperSupport::instance_size(k)); |
931 |
922 |
932 // size of constant pool - ignored by HAT 1.1 |
923 // size of constant pool - ignored by HAT 1.1 |
955 |
946 |
956 writer->write_objectID(ik->class_loader()); |
947 writer->write_objectID(ik->class_loader()); |
957 writer->write_objectID(ik->signers()); |
948 writer->write_objectID(ik->signers()); |
958 writer->write_objectID(ik->protection_domain()); |
949 writer->write_objectID(ik->protection_domain()); |
959 |
950 |
960 writer->write_objectID(NULL); // reserved |
951 writer->write_objectID(oop(NULL)); // reserved |
961 writer->write_objectID(NULL); |
952 writer->write_objectID(oop(NULL)); |
962 writer->write_u4(0); // instance size |
953 writer->write_u4(0); // instance size |
963 writer->write_u2(0); // constant pool |
954 writer->write_u2(0); // constant pool |
964 writer->write_u2(0); // static fields |
955 writer->write_u2(0); // static fields |
965 writer->write_u2(0); // instance fields |
956 writer->write_u2(0); // instance fields |
966 |
957 |
969 } |
960 } |
970 } |
961 } |
971 |
962 |
972 // creates HPROF_GC_CLASS_DUMP record for a given primitive array |
963 // creates HPROF_GC_CLASS_DUMP record for a given primitive array |
973 // class (and each multi-dimensional array class too) |
964 // class (and each multi-dimensional array class too) |
974 void DumperSupport::dump_basic_type_array_class(DumpWriter* writer, klassOop k) { |
965 void DumperSupport::dump_basic_type_array_class(DumpWriter* writer, Klass* k) { |
975 // array classes |
966 // array classes |
976 while (k != NULL) { |
967 while (k != NULL) { |
977 Klass* klass = Klass::cast(k); |
968 Klass* klass = Klass::cast(k); |
978 |
969 |
979 writer->write_u1(HPROF_GC_CLASS_DUMP); |
970 writer->write_u1(HPROF_GC_CLASS_DUMP); |
980 writer->write_classID(klass); |
971 writer->write_classID(klass); |
981 writer->write_u4(STACK_TRACE_ID); |
972 writer->write_u4(STACK_TRACE_ID); |
982 |
973 |
983 // super class of array classes is java.lang.Object |
974 // super class of array classes is java.lang.Object |
984 klassOop java_super = klass->java_super(); |
975 Klass* java_super = klass->java_super(); |
985 assert(java_super != NULL, "checking"); |
976 assert(java_super != NULL, "checking"); |
986 writer->write_classID(Klass::cast(java_super)); |
977 writer->write_classID(Klass::cast(java_super)); |
987 |
978 |
988 writer->write_objectID(NULL); // loader |
979 writer->write_objectID(oop(NULL)); // loader |
989 writer->write_objectID(NULL); // signers |
980 writer->write_objectID(oop(NULL)); // signers |
990 writer->write_objectID(NULL); // protection domain |
981 writer->write_objectID(oop(NULL)); // protection domain |
991 |
982 |
992 writer->write_objectID(NULL); // reserved |
983 writer->write_objectID(oop(NULL)); // reserved |
993 writer->write_objectID(NULL); |
984 writer->write_objectID(oop(NULL)); |
994 writer->write_u4(0); // instance size |
985 writer->write_u4(0); // instance size |
995 writer->write_u2(0); // constant pool |
986 writer->write_u2(0); // constant pool |
996 writer->write_u2(0); // static fields |
987 writer->write_u2(0); // static fields |
997 writer->write_u2(0); // instance fields |
988 writer->write_u2(0); // instance fields |
998 |
989 |
1127 write_header(writer, HPROF_FRAME, 4*oopSize + 2*sizeof(u4)); |
1115 write_header(writer, HPROF_FRAME, 4*oopSize + 2*sizeof(u4)); |
1128 writer->write_id(frame_serial_num); // frame serial number |
1116 writer->write_id(frame_serial_num); // frame serial number |
1129 writer->write_symbolID(m->name()); // method's name |
1117 writer->write_symbolID(m->name()); // method's name |
1130 writer->write_symbolID(m->signature()); // method's signature |
1118 writer->write_symbolID(m->signature()); // method's signature |
1131 |
1119 |
1132 assert(Klass::cast(m->method_holder())->oop_is_instance(), "not instanceKlass"); |
1120 assert(Klass::cast(m->method_holder())->oop_is_instance(), "not InstanceKlass"); |
1133 writer->write_symbolID(instanceKlass::cast(m->method_holder())->source_file_name()); // source file name |
1121 writer->write_symbolID(InstanceKlass::cast(m->method_holder())->source_file_name()); // source file name |
1134 writer->write_u4(class_serial_num); // class serial number |
1122 writer->write_u4(class_serial_num); // class serial number |
1135 writer->write_u4((u4) line_number); // line number |
1123 writer->write_u4((u4) line_number); // line number |
1136 } |
1124 } |
1137 |
1125 |
1138 |
1126 |
1240 }; |
1228 }; |
1241 |
1229 |
1242 |
1230 |
1243 // Support class used to generate HPROF_GC_ROOT_STICKY_CLASS records |
1231 // Support class used to generate HPROF_GC_ROOT_STICKY_CLASS records |
1244 |
1232 |
1245 class StickyClassDumper : public OopClosure { |
1233 class StickyClassDumper : public KlassClosure { |
1246 private: |
1234 private: |
1247 DumpWriter* _writer; |
1235 DumpWriter* _writer; |
1248 DumpWriter* writer() const { return _writer; } |
1236 DumpWriter* writer() const { return _writer; } |
1249 public: |
1237 public: |
1250 StickyClassDumper(DumpWriter* writer) { |
1238 StickyClassDumper(DumpWriter* writer) { |
1251 _writer = writer; |
1239 _writer = writer; |
1252 } |
1240 } |
1253 void do_oop(oop* obj_p); |
1241 void do_klass(Klass* k) { |
1254 void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); } |
1242 if (k->oop_is_instance()) { |
1255 }; |
1243 InstanceKlass* ik = InstanceKlass::cast(k); |
1256 |
|
1257 void StickyClassDumper::do_oop(oop* obj_p) { |
|
1258 if (*obj_p != NULL) { |
|
1259 oop o = *obj_p; |
|
1260 if (o->is_klass()) { |
|
1261 klassOop k = klassOop(o); |
|
1262 if (Klass::cast(k)->oop_is_instance()) { |
|
1263 instanceKlass* ik = instanceKlass::cast(k); |
|
1264 writer()->write_u1(HPROF_GC_ROOT_STICKY_CLASS); |
1244 writer()->write_u1(HPROF_GC_ROOT_STICKY_CLASS); |
1265 writer()->write_classID(ik); |
1245 writer()->write_classID(ik); |
1266 } |
1246 } |
1267 } |
1247 } |
1268 } |
1248 }; |
1269 } |
|
1270 |
1249 |
1271 |
1250 |
1272 class VM_HeapDumper; |
1251 class VM_HeapDumper; |
1273 |
1252 |
1274 // Support class using when iterating over the heap. |
1253 // Support class using when iterating over the heap. |
1362 void set_dump_start(jlong pos); |
1338 void set_dump_start(jlong pos); |
1363 |
1339 |
1364 bool skip_operation() const; |
1340 bool skip_operation() const; |
1365 |
1341 |
1366 // writes a HPROF_LOAD_CLASS record |
1342 // writes a HPROF_LOAD_CLASS record |
1367 static void do_load_class(klassOop k); |
1343 static void do_load_class(Klass* k); |
1368 |
1344 |
1369 // writes a HPROF_GC_CLASS_DUMP record for the given class |
1345 // writes a HPROF_GC_CLASS_DUMP record for the given class |
1370 // (and each array class too) |
1346 // (and each array class too) |
1371 static void do_class_dump(klassOop k); |
1347 static void do_class_dump(Klass* k); |
1372 |
1348 |
1373 // writes a HPROF_GC_CLASS_DUMP records for a given basic type |
1349 // writes a HPROF_GC_CLASS_DUMP records for a given basic type |
1374 // array (and each multi-dimensional array too) |
1350 // array (and each multi-dimensional array too) |
1375 static void do_basic_type_array_class_dump(klassOop k); |
1351 static void do_basic_type_array_class_dump(Klass* k); |
1376 |
1352 |
1377 // HPROF_GC_ROOT_THREAD_OBJ records |
1353 // HPROF_GC_ROOT_THREAD_OBJ records |
1378 int do_thread(JavaThread* thread, u4 thread_serial_num); |
1354 int do_thread(JavaThread* thread, u4 thread_serial_num); |
1379 void do_threads(); |
1355 void do_threads(); |
1380 |
1356 |
1409 _stack_traces = NULL; |
1385 _stack_traces = NULL; |
1410 _num_threads = 0; |
1386 _num_threads = 0; |
1411 if (oome) { |
1387 if (oome) { |
1412 assert(!Thread::current()->is_VM_thread(), "Dump from OutOfMemoryError cannot be called by the VMThread"); |
1388 assert(!Thread::current()->is_VM_thread(), "Dump from OutOfMemoryError cannot be called by the VMThread"); |
1413 // get OutOfMemoryError zero-parameter constructor |
1389 // get OutOfMemoryError zero-parameter constructor |
1414 instanceKlass* oome_ik = instanceKlass::cast(SystemDictionary::OutOfMemoryError_klass()); |
1390 InstanceKlass* oome_ik = InstanceKlass::cast(SystemDictionary::OutOfMemoryError_klass()); |
1415 _oome_constructor = oome_ik->find_method(vmSymbols::object_initializer_name(), |
1391 _oome_constructor = oome_ik->find_method(vmSymbols::object_initializer_name(), |
1416 vmSymbols::void_method_signature()); |
1392 vmSymbols::void_method_signature()); |
1417 // get thread throwing OOME when generating the heap dump at OOME |
1393 // get thread throwing OOME when generating the heap dump at OOME |
1418 _oome_thread = JavaThread::current(); |
1394 _oome_thread = JavaThread::current(); |
1419 } else { |
1395 } else { |
1565 k = klass->array_klass_or_null(); |
1541 k = klass->array_klass_or_null(); |
1566 } while (k != NULL); |
1542 } while (k != NULL); |
1567 } |
1543 } |
1568 |
1544 |
1569 // writes a HPROF_GC_CLASS_DUMP record for the given class |
1545 // writes a HPROF_GC_CLASS_DUMP record for the given class |
1570 void VM_HeapDumper::do_class_dump(klassOop k) { |
1546 void VM_HeapDumper::do_class_dump(Klass* k) { |
1571 DumperSupport::dump_class_and_array_classes(writer(), k); |
1547 DumperSupport::dump_class_and_array_classes(writer(), k); |
1572 } |
1548 } |
1573 |
1549 |
1574 // writes a HPROF_GC_CLASS_DUMP records for a given basic type |
1550 // writes a HPROF_GC_CLASS_DUMP records for a given basic type |
1575 // array (and each multi-dimensional array too) |
1551 // array (and each multi-dimensional array too) |
1576 void VM_HeapDumper::do_basic_type_array_class_dump(klassOop k) { |
1552 void VM_HeapDumper::do_basic_type_array_class_dump(Klass* k) { |
1577 DumperSupport::dump_basic_type_array_class(writer(), k); |
1553 DumperSupport::dump_basic_type_array_class(writer(), k); |
1578 } |
1554 } |
1579 |
1555 |
1580 // Walk the stack of the given thread. |
1556 // Walk the stack of the given thread. |
1581 // Dumps a HPROF_GC_ROOT_JAVA_FRAME record for each local |
1557 // Dumps a HPROF_GC_ROOT_JAVA_FRAME record for each local |
1827 _oome_constructor, 0); |
1803 _oome_constructor, 0); |
1828 extra_frames++; |
1804 extra_frames++; |
1829 } |
1805 } |
1830 for (int j=0; j < depth; j++) { |
1806 for (int j=0; j < depth; j++) { |
1831 StackFrameInfo* frame = stack_trace->stack_frame_at(j); |
1807 StackFrameInfo* frame = stack_trace->stack_frame_at(j); |
1832 methodOop m = frame->method(); |
1808 Method* m = frame->method(); |
1833 int class_serial_num = _klass_map->find(Klass::cast(m->method_holder())); |
1809 int class_serial_num = _klass_map->find(Klass::cast(m->method_holder())); |
1834 // the class serial number starts from 1 |
1810 // the class serial number starts from 1 |
1835 assert(class_serial_num > 0, "class not found"); |
1811 assert(class_serial_num > 0, "class not found"); |
1836 DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, class_serial_num, m, frame->bci()); |
1812 DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, class_serial_num, m, frame->bci()); |
1837 } |
1813 } |